Tools
NpEncoder
Bases: JSONEncoder
Custom encoder to serialize Numpy data types.
Source code in lume/tools.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
default(obj)
Source code in lume/tools.py
30 31 32 33 34 35 36 37 38 39 | |
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
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
execute2(cmd, timeout=None, cwd=None)
Execute with time limit (timeout) in seconds, catching run errors.
Source code in lume/tools.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
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
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 129 130 131 132 133 134 135 136 | |
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
keyed_data : dict dict with the keys to generate a fingerprint digest_size : int, optional Digest size for blake2b hash code, by default 16
Returns
str The hexadecimal digest
Source code in lume/tools.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
full_path(path)
Helper function to expand enviromental variables and return the absolute path
Parameters
path : str A path possibly containing environment variables and user (~) shortcut
Returns
str The expanded absolute path
Source code in lume/tools.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
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
93 94 95 96 97 98 99 100 101 | |
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
84 85 86 87 88 89 90 | |