Common Utility Functions¶
-
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- items – (
-
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 collapseReturns: ( 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- items – (
-
solidbyte.common.utils.
get_filename_and_ext
(filename)[source]¶ Return the filename and extension as a tuple
Parameters: filename – ( pathlib.Path
) of fileReturns: ( 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 hashReturns: ( str
) hex sha1 hash of the given file
-
solidbyte.common.utils.
keys_with
(thedict, term)[source]¶ Return any keys from
thedict
that haveterm
in their valueParameters: - thedict – (
dict
) The dict to search - term – (
Any
) The value to look for
Returns: (
list
) List of keys that match- thedict – (
-
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- d – (
-
solidbyte.common.utils.
source_filename_to_name
(filename)[source]¶ Change a source filename to a plain name
Parameters: filename – ( pathlib.Path
) of fileReturns: ( 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 fileReturns: ( 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
orpathlib.Path
)Returns: ( pathlib.Path
)