utils¶
Utilities and helper scripts.
Functions
|
Assert that a given path exists. |
|
Copy a file or directory to the cache and return the cache path. |
|
Set the file extension of the given path. |
|
Finds a particular binary on this system. |
|
Get the given directory, creating it if it doesn't already exist. |
|
Get the given file, creating it if it doesn't already exist. |
|
Compute the cryptographic hash of the given bytes. |
|
A decorator that runs the given function in a subprocess. |
|
Generate a timestamp string in the standard format. |
|
Write parquet to the given path. |
Exceptions
|
A wrapper around an exception raised by a remote process. |
- undertale.utils.timestamp(time: datetime | None = None) str¶
Generate a timestamp string in the standard format.
- Parameters:
time – An optional datetime for which to generate a timestamp. If not provided the current date and time will be used.
- Returns:
A string timestamp in the standard format.
- undertale.utils.assert_path_exists(path: str) str¶
Assert that a given path exists.
- Parameters:
path – The path to check.
- Returns:
The absolute version of the given path.
- Raises:
PathDoesNotExist – If the given path does not exist.
- undertale.utils.cache_path(path: str) str¶
Copy a file or directory to the cache and return the cache path.
Checks the
UNDERTALE_CACHEenvironment variable. If set, copiespathto$UNDERTALE_CACHE/{md5(dirname(path))[:8]}-{basename(path)}, logging each file copied. The 8-character MD5 hex prefix of the parent directory prevents basename collisions between paths that share the same leaf name. If the destination already exists, verifies each file’s size and modification time (similar to rsync) and re-copies stale files. IfUNDERTALE_CACHEis not set, logs a warning and returns the originalpathunchanged.- Parameters:
path – Path to the file or directory to cache.
- Returns:
The cache path if
UNDERTALE_CACHEis set, otherwisepath.
- undertale.utils.get_or_create_file(path: str) Tuple[str, bool]¶
Get the given file, creating it if it doesn’t already exist.
- Parameters:
path – The path to the file to get or create.
- Returns:
The absolute version of the given path and a boolean indicating if it was created by this function.
- undertale.utils.get_or_create_directory(path: str) Tuple[str, bool]¶
Get the given directory, creating it if it doesn’t already exist.
- Parameters:
path – The path to the directory to get or create.
- Returns:
The absolute version of the given path and a boolean indicating if it was created by this function.
- undertale.utils.find(name: str, environment: str | None = None, guesses: Iterable[str] | None = None) str¶
Finds a particular binary on this system.
Attempts to find the binary given by
name, first checking the value of the environment variable namedenvironment(if provided), then by checking the system path, then finally checking hardcoded paths inguesses(if provided). This function is cross-platform compatible - it works on Windows, Linux, and Mac. If there are spaces in the path found, this function will wrap its return value in double quotes.- Parameters:
name – Binary name.
environment – An optional environment variable to check.
guesses – An optional list of hardcoded paths to check.
- Returns:
A string with the absolute path to the binary if found, otherwise
None.
- undertale.utils.write_parquet(frame, path: str, **kwargs) None¶
Write parquet to the given path.
This helper method enforces some defaults on a typical
frame.to_parquet()operation.- Parameters:
frame – A
DataFrame-like object to write (e.g.,pandas.DataFrame,polars.DataFrame, etc.)path – The path where the parquet file should be written.
**kargs – Additional kwargs to pass to the underlying
to_parquetmethod, or override from defaults.
- Raises:
ValueError – If the given
frameobject does not support.to_parquet()` –
- undertale.utils.subprocess(function: Callable | None = None, timeout: float | None = None) Callable¶
A decorator that runs the given function in a subprocess.
- Parameters:
timeout – A timeout (seconds) after which to raise an exception. If
None, then the subprocess will be allowed to run indefinitely.- Raises:
TimeoutError – If
timeoutseconds have passed andfunctionhas not returned.Exception – If an exception is raised by the decorated function.
- exception undertale.utils.RemoteException(type: str, representation: str, traceback: str)¶
Bases:
ExceptionA wrapper around an exception raised by a remote process.
Modules
Dataset-relevant utilities. |