TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/alex-ber/AlexBerUtils/llms.txt
Use this file to discover all available pages before exploring further.
deploys module (alexber.utils.deploys) provides utilities for use in deployment scripts. It covers
two areas: building ZIP archives from directory trees, and loading YAML configuration files with profile merging.
The environment variable path utilities (fix_env, fix_retry_env, FixRelCwd, GuardedWorkerException) live in alexber.utils.mains but are frequently used together with deploys in deployment scripts, so they are documented here for convenience.
Installation
ZIP archive utilities
split_path(filename, split_dirname)
Splits a file path into two parts at the last occurrence of split_dirname.
first ends with split_dirname; second starts immediately after it. The
concatenation first / second reproduces the original absolute path.
Path to the file. May be relative or absolute; it is resolved to an absolute
path internally.
Directory name within
filename to split on. Must not be None. When
split_dirname appears more than once in the path the last occurrence is
used.(Path, Path) — (first_part, second_part).
Raises FileNotFoundError if split_dirname is None or is not found in filename.
add_to_zip_copy_function(split_dirname, zf)
Factory that returns a closure compatible with the copy_function parameter of
shutil.copytree(). Use it to write a directory tree directly into a ZIP archive
during a copy operation.
split_dirname, so
the archive entry for /home/user/project/src/module/file.py becomes
src/module/file.py.
The directory name used as the archive root (passed to
split_path internally).An open, writable
ZipFile instance.(src, dst) -> None callable suitable for shutil.copytree(copy_function=...).
YAML configuration loading
load_config(argumentParser=None, args=None)
Parses a YAML configuration file and merges command-line profile overrides into
it. This is a simplified alternative to alexber.utils.init_app_conf.parse_config().
A pre-configured
argparse.ArgumentParser instance. If None, a default
parser is constructed internally.Argument list to parse. If
None, sys.argv is used.(pathlib.Path, dict) — the resolved path to the configuration file
and the merged configuration dictionary.
Raises ValueError if ymlparsers.HiYaPyCo.jinja2ctx is None (the YAML
parsing context has not been initialised).
load_config depends on alexber.utils.ymlparsers, which is installed via
pip install alex-ber-utils[yml]. Profile values supplied on the command line
take precedence over defaults in the YAML file.Environment variable path utilities
These utilities fixos.environ entries that contain file system paths, making
deployment scripts work correctly regardless of where a package is installed or
which operating system is used.
fix_env(**kwargs)
Prepends the absolute installation prefix of a given package to each path listed
in one or more environment variables.
Comma-separated names of
os.environ keys to update.Python package name used to determine the absolute path prefix. The
function resolves the location of
ENV_MAIN_PCK/__init__.py and uses its
parent’s parent as the prefix.Separator used to split
ENV_KEYS.Path separator used inside each path value.
Delimiter used between multiple paths within a single environment variable
(e.g.
; on Windows, : on Unix).Implementation class (or its importable dotted string). Override to
customise the path-expansion logic.
fix_retry_env(**kwargs)
Makes path values in environment variables work on both Windows and Linux by
stripping the Windows drive prefix (e.g. C:\) when the path does not exist
as-is on the current OS.
Comma-separated environment variable names to process.
Separator used to split
ENV_KEYS.Path separator used inside each path value.
Delimiter between multiple paths within a single environment variable.
Implementation class or dotted import string.
Context managers
FixRelCwd(relPackage, logger=None)
Temporarily changes the working directory to the directory where relPackage is
installed, then restores it on exit. Useful when a package relies on relative
paths to locate configuration or resource files.
An imported Python module. Its
__file__ attribute is used to resolve the
target directory.Logger for debug messages. If
None, the module-level logger is used.GuardedWorkerException(logger=None, suppress=False, default_exc_message="Worker failed")
Surrounds worker-process code with exception handling to prevent
multiprocessing.Pool.join() from hanging indefinitely when a worker raises an
unpicklable exception.
Logger to record the caught exception. If
None, the traceback is printed
to sys.stderr.If
True, swallow the exception after logging. If False (default), re-raise
as a plain Exception(default_exc_message).Message for the replacement exception when
suppress=False.