Tools
lume.tools
NpEncoder
Bases: json.JSONEncoder
Custom encoder to serialize Numpy data types.
Source code in lume/tools.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
execute(cmd, cwd=None)
Constantly print Subprocess output while process is running from: https://stackoverflow.com/questions/4417546/constantly-print-subprocess-output-while-process-is-running
Example usage:
for path in execute(["locate", "a"]):
print(path, end="")
Useful in Jupyter notebook
Source code in lume/tools.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
execute2(cmd, timeout=None, cwd=None)
Execute with time limit (timeout) in seconds, catching run errors.
Source code in lume/tools.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
find_executable(exename=None, envname=None)
Finds an executable from a given name or environmental variable.
If neither are files, the path will be searched for exename
Source code in lume/tools.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
fingerprint(keyed_data, digest_size=16)
Creates a cryptographic fingerprint from keyed data. Used JSON dumps to form strings, and the blake2b algorithm to hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keyed_data |
dict
|
dict with the keys to generate a fingerprint |
required |
digest_size |
int, optional
|
Digest size for blake2b hash code, by default 16 |
16
|
Returns:
Type | Description |
---|---|
str
|
The hexadecimal digest |
Source code in lume/tools.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
full_path(path)
Helper function to expand enviromental variables and return the absolute path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
A path possibly containing environment variables and user (~) shortcut |
required |
Returns:
Type | Description |
---|---|
str
|
The expanded absolute path |
Source code in lume/tools.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
make_executable(path)
Makes a file executable.
https://stackoverflow.com/questions/12791997/how-do-you-do-a-simple-chmod-x-from-within-python
Source code in lume/tools.py
85 86 87 88 89 90 91 92 93 |
|
native_type(value)
Converts a numpy type to a native python type. See: https://stackoverflow.com/questions/9452775/converting-numpy-dtypes-to-native-python-types/11389998
Source code in lume/tools.py
77 78 79 80 81 82 83 |
|