MDFactoryMDFactory

utilities

General-purpose utility functions for mdfactory.

funcworking_directory(path, create=False, cleanup=False, exists_ok=True)

Change working directory and return to previous on exit.

parampathstr or Path

Target directory to change into.

paramcreatebool
= False

Create the directory if it does not exist. Default is False.

paramcleanupbool
= False

Remove the directory before creating it. Implies create=True. Default is False.

paramexists_okbool
= True

If False, raise FileExistsError when the directory already exists. Default is True.

Returns

None
functemporary_working_directory(prefix='temp_')

Create a temporary directory and change into it.

paramprefixstr
= 'temp_'

Prefix for the temporary directory name. Default is "temp_".

Returns

None
funcload_yaml_file(yaml_file_path)Dict[str, Any]

Load data from a YAML file.

paramyaml_file_pathstr

The path to the YAML file.

Returns

typing.Dict

The loaded data from the YAML file.

funclock_local_folder(folder, retries=120, wait=2.0, message='')

Acquire a file-based lock on a folder, blocking until available.

Create a \<folder>.lock sentinel file and yield. If the lock file already exists, retry up to retries times with wait seconds between attempts. The lock file is removed on exit.

paramfolderstr or Path

Path to the folder to lock.

paramretriesint
= 120

Maximum number of acquisition attempts. Default is 120.

paramwaitfloat
= 2.0

Seconds to sleep between retries. Default is 2.0.

parammessagestr
= ''

Informational message (currently unused, reserved for logging).

Returns

None