Common Utility Functions

class solidbyte.common.utils.Py36Datetime[source]

Monkeypatch datetime for python<3.7

fromisoformat()[source]

Load an datetime.isoformat() date string as a datetime object

solidbyte.common.utils.all_defs_in(items: Iterable[T_co], di: dict) → bool[source]

Check if all defs(tuple of name/placeholder) are in di

Parameters:
  • items – (Iterable) to check against di
  • di – (dict) the dict to check against
Returns:

(bool) if all defs are in the dict

solidbyte.common.utils.builddir(loc=None)[source]

Get (and create if necessary) the temporary build dir

Parameters:loc – (pathlib.Path) to workdir (default: pwd)
Returns:(pathlib.Path) to build dir
solidbyte.common.utils.collapse_oel(lst)[source]

Collapse a one-element list to a single var

Parameters:filename – (list) with one element to collapse
Returns:(Any) the single element
solidbyte.common.utils.defs_not_in(items: Iterable[T_co], di: dict) → set[source]

Find defs (tuple of name/placeholder) that aren’t keys in a dict

Parameters:
  • items – (Iterable) to check against di
  • di – (dict) the dict to check against
Returns:

(set) any defs not in di

solidbyte.common.utils.find_vyper()[source]

Get the path to vyper. DEPRECIATED

solidbyte.common.utils.get_filename_and_ext(filename)[source]

Return the filename and extension as a tuple

Parameters:filename – (pathlib.Path) of file
Returns:(tuple) of (name, extension)
solidbyte.common.utils.hash_file(_file: pathlib.Path) → str[source]

Get an sha1 hash of a file

Parameters:_file – (pathlib.Path) the file to hash
Returns:(str) hex sha1 hash of the given file
solidbyte.common.utils.keys_with(thedict, term)[source]

Return any keys from thedict that have term in their value

Parameters:
  • thedict – (dict) The dict to search
  • term – (Any) The value to look for
Returns:

(list) List of keys that match

solidbyte.common.utils.pop_key_from_dict(d, key)[source]

Remove and return an element from a dict and the modded dict without throwing an exception if a key does not exist.

Parameters:
  • d – (dict) the original dict
  • key – (str) they key to pop
Returns:

(T) The value of the key or None

solidbyte.common.utils.source_filename_to_name(filename)[source]

Change a source filename to a plain name

Parameters:filename – (pathlib.Path) of file
Returns:(str) name of file without extension
solidbyte.common.utils.supported_extension(filename)[source]

Check if the provided filename has a supported source code extension

Parameters:filename – (pathlib.Path) of file
Returns:(bool) if it’s supported
solidbyte.common.utils.to_path(v) → pathlib.Path[source]

Given a Path or str, return a Path

Parameters:v – (str or pathlib.Path)
Returns:(pathlib.Path)
solidbyte.common.utils.to_path_or_cwd(v) → pathlib.Path[source]

Given a Path, str, or None, return a Path of the given path or the current working directory

Parameters:v – (str or pathlib.Path)
Returns:(pathlib.Path)
solidbyte.common.utils.unescape_newlines(s)[source]

Unescape newlines in a text string

Parameters:s – (str) String to search and replace against
Returns:(str) String with unescaped newlines