smarts.core.utils.file module

smarts.core.utils.file.copy_tree(from_path, to_path, overwrite=False)[source]

Copy a directory tree (including files) to another location. :param from_path: The directory to copy. :param to_path: The output directory. :param overwrite: If to overwrite the output directory.

smarts.core.utils.file.file_in_folder(filename: str, path: str) bool[source]

Checks to see if a file exists :param filename: The name of the file. :param path: The path to the directory of the file.

Returns:

If the file exists.

smarts.core.utils.file.file_md5_hash(file_path: str) str[source]

Converts file contents to a hash value. Useful for doing a file diff.

smarts.core.utils.file.isdataclass(x)[source]

Check if an object is a dataclass.

smarts.core.utils.file.isnamedtupleinstance(x)[source]

Check to see if an object is a named tuple.

smarts.core.utils.file.make_dir_in_smarts_log_dir(dir)[source]

Return a new directory location in the smarts logging directory.

smarts.core.utils.file.path2hash(file_path: str)[source]

Converts a file path to a hash value.

smarts.core.utils.file.pickle_hash(obj, include_version=False) str[source]

Converts a Python object to a hash value. NOTE: NOT stable across different Python versions.

smarts.core.utils.file.pickle_hash_int(obj) int[source]

Converts a Python object to a hash value. NOTE: NOT stable across different Python versions.

smarts.core.utils.file.read_tfrecord_file(path: str) Generator[bytes, None, None][source]

Iterate over the records in a TFRecord file and return the bytes of each record.

path: The path to the TFRecord file

smarts.core.utils.file.replace(obj: Any, **kwargs)[source]

Replace dataclasses and named tuples with the same interface.

smarts.core.utils.file.smarts_global_user_dir() str[source]

Retrieves the smarts global user directory.

Returns:

The smarts global user directory path.

Return type:

str

smarts.core.utils.file.smarts_local_user_dir() str[source]

Retrieves the smarts logging directory.

Returns:

The smarts local user directory path.

Return type:

str

smarts.core.utils.file.suppress_pkg_resources()[source]

A context manager that injects an ImportError into the pkg_resources module to force package fallbacks in imports that can use alternatives to pkg_resources.

smarts.core.utils.file.unpack(obj)[source]

A helper that can be used to print nested data objects (tuple, dataclass, namedtuple, …). For example, `python pprint(unpack(obs), indent=1, width=80, compact=True) `