Documentation 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.
fixabscwd
Changes the process working directory to the directory containing the__main__ module’s file. This makes relative file paths in the main script resolve correctly regardless of where the process was started from.
No-op when running inside a REPL, IPython notebook, or a frozen/bundled executable.
Returns: None
path
Returns thepath callable from the appropriate importlib.resources API — built-in for Python ≥ 3.7, falling back to the importlib_resources backport for older versions.
Returns: The importlib.resources.path (or backport equivalent) context-manager factory.
Raises:
ImportWarning+ re-raisesImportError— if the backport is required but not installed.
load_env
Loads environment variables from a.env file, with support for packaged resources (eggs, wheels, zips).
Python package that contains the
.env file. When provided (and dotenv_path / stream are absent), importlib.resources is used to resolve the file path.Name of the
.env file inside ENV_PCK.Absolute or relative path to a
.env file. When given, ENV_PCK is ignored.In-memory
.env content. When given, ENV_PCK is ignored.All remaining kwargs are forwarded directly to
python-dotenv’s load_dotenv().None
Raises:
ImportWarning+ImportError— ifpython-dotenvis not installed.ValueError— ifENV_PCKis empty when it is the only resolution path.
BaseOsEnvrion
Base class foros.environ fixup helpers. Parses separator configuration and the list of environment variable keys to operate on.
Comma-separated (by default) list of
os.environ key names to process.Separator used between key names in
ENV_KEYS.Path separator used within path values (e.g.
/ on POSIX).Delimiter separating multiple paths inside a single environment variable value (e.g.
: on POSIX, ; on Windows).ValueError— ifENV_KEYSis missing or empty.
OsEnvrionPathExpender
ExtendsBaseOsEnvrion to prepend the absolute path of a reference package’s root to relative paths stored in environment variables.
Inherits all BaseOsEnvrion parameters, plus:
The installed Python package whose
__init__.py location is used to compute the absolute prefix.ValueError— ifENV_MAIN_PCKis missing.
OsEnvrionPathExpender.fix_abs_path
Iterates over every key inENV_KEYS, splits its value into individual relative paths, prepends the computed absolute prefix, and writes the result back to os.environ.
Returns: None
OsEnvrionPathRetry
ExtendsBaseOsEnvrion to make Windows-style paths (e.g. C:\foo\bar) work on Linux by stripping the drive letter when the path does not exist on the current filesystem.
Inherits all BaseOsEnvrion parameters.
OsEnvrionPathRetry.fix_retry_path
For each path value under everyENV_KEYS key: if the path does not exist and has a Windows drive prefix (e.g. C:), the drive is stripped and the POSIX remainder is used instead.
Returns: None
fix_env
Convenience function that constructs anOsEnvrionPathExpender (or a custom subclass) and calls fix_abs_path().
Forwarded to the expander class.
Forwarded to the expander class.
Implementation class or its fully-qualified import string. Resolved via
importer() when a string is given.All remaining kwargs are forwarded to the class constructor.
None
fix_retry_env
Convenience function that constructs anOsEnvrionPathRetry (or a custom subclass) and calls fix_retry_path().
Forwarded to the retry class.
Implementation class or its fully-qualified import string.
All remaining kwargs are forwarded to the class constructor.
None
FixRelCwd
Context manager that temporarily changes the working directory to the directory containingrelPackage.__file__, then restores the original directory on exit.
Useful when calling a module that uses relative file paths from a different working directory.
An imported Python package/module. The CWD is set to the directory of its
__file__ attribute.Logger instance. When
None, the module-level logger is used.str) to the directory.
Raises: Propagates any exception from the with block after restoring the CWD.
GuardedWorkerException
Context manager that catches exceptions in multiprocessing worker functions, preventingpool.join() from hanging forever due to unpicklable exceptions.
Logger to record the caught exception. When
None, the traceback is printed to sys.stderr.When
True, the exception is swallowed. When False (default), a plain Exception with default_exc_message is raised instead.Message for the replacement exception when
suppress=False.None
Raises:
Exception(default_exc_message)— whensuppress=Falseand the worker raises.
is_iterable
ReturnsTrue if value supports iteration, excluding None, str, and bytes.
The value to test.
bool
is_mapping
ReturnsTrue if value has a callable items attribute (i.e. behaves like a dict).
The value to test.
bool
make_hashable
Recursively converts an object into a hashable representation so it can be used as a dict key or set element.- Mappings →
frozensetof(make_hashable(k), make_hashable(v))pairs - Iterables (non-str, non-bytes) →
tupleof recursively converted elements - Natively hashable objects → returned as-is
- Everything else → wrapped in
HashableWrapper
The object to convert.
frozenset, tuple, the original object, or HashableWrapper).
HashableWrapper
Fallback wrapper that makes any object hashable by delegating__hash__ to hash(str(obj)).
The non-hashable object to wrap.
HashableWrapper.__hash__
Returns:int — hash(str(self.obj)).
HashableWrapper.__eq__
TwoHashableWrapper instances are equal if both wrap equal underlying objects.
Returns: bool
HashableWrapper.__repr__
Returns:str — "HashableWrapper(<repr of obj>)".
