unidep.utils module¶
unidep - Unified Conda and Pip requirements management.
This module provides utility functions used throughout the package.
- class unidep.utils.LocalDependency(local: str, pypi: str | None = None)[source]¶
Bases:
NamedTupleA local dependency with optional PyPI alternative.
- class unidep.utils.ParsedPackageStr(name: str, pin: str | None = None, selector: str | None = None)[source]¶
Bases:
NamedTupleA package name and version pinning.
- class unidep.utils.PathWithExtras(path: Path, extras: list[str])[source]¶
Bases:
NamedTupleA dependency file and extras.
- exception unidep.utils.UnsupportedPlatformError[source]¶
Bases:
ExceptionRaised when the current platform is not supported.
- unidep.utils.add_comment_to_file(filename, extra_lines=None)[source]¶
Add a comment to the top of a file.
- Return type:
- unidep.utils.build_pep508_environment_marker(platforms)[source]¶
Generate a PEP 508 selector for a list of platforms.
- Return type:
- unidep.utils.change_directory(new_path)[source]¶
A context manager to change the current working directory.
- unidep.utils.defaultdict_to_dict(d)[source]¶
Convert (nested) defaultdict to (nested) dict.
- Return type:
- unidep.utils.get_package_version(package_name)[source]¶
Returns the version of the given package.
- Parameters:
package_name (
str) – The name of the package to find the version of.- Return type:
The version of the package, or None if the package is not found.
- unidep.utils.identify_current_platform()[source]¶
Detect the current platform.
- Return type:
Literal['linux-64','linux-aarch64','linux-ppc64le','osx-64','osx-arm64','win-64']
- unidep.utils.is_pip_installable(folder)[source]¶
Determine if the project is pip installable.
Checks for existence of setup.py or [build-system] in pyproject.toml. If the toml library is available, it is used to parse the pyproject.toml file. If the toml library is not available, the function checks for the existence of a line starting with “[build-system]”. This does not handle the case where [build-system] is inside of a multi-line literal string.
- Return type:
- unidep.utils.parse_folder_or_filename(folder_or_file)[source]¶
Get the path to requirements.yaml or pyproject.toml file.
- Return type:
- unidep.utils.parse_package_str(package_str)[source]¶
Splits a string into package name, version pinning, and platform selector.
- Return type:
- unidep.utils.remove_top_comments(filename)[source]¶
Removes the top comments (lines starting with ‘#’) from a file.
- Return type:
- unidep.utils.split_path_and_extras(input_str)[source]¶
Parse a string of the form path/to/file[extra1,extra2] into parts.
Returns a tuple of the
pathlib.Pathand a list of extras