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, use: LocalDependencyUse = 'local')[source]ΒΆ
Bases:
NamedTupleA local dependency with optional PyPI alternative and
usemode.
- 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.
- canonicalized()[source]ΒΆ
Resolve path and normalize extras for deterministic graph keys.
- Return type:
- 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.collect_selector_platforms(requirements, optional_dependencies=None)[source]ΒΆ
Collect all platforms referenced by dependency selectors.
- 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.package_name_from_path(path)[source]ΒΆ
Get the package name from
pyproject.toml,setup.cfg, orsetup.py.- Return type:
- unidep.utils.package_name_from_pyproject_toml(file_path)[source]ΒΆ
Read project name from
pyproject.toml(PEP 621 or Poetry).- Return type:
- unidep.utils.package_name_from_setup_cfg(file_path)[source]ΒΆ
Read the package name from
setup.cfgmetadata.- Return type:
- unidep.utils.package_name_from_setup_py(file_path)[source]ΒΆ
Read the package name from a simple
setup.pyAST.- 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.resolve_platforms(*, requested_platforms, declared_platforms=None, selector_platforms=None, default_current=True)[source]ΒΆ
Resolve effective platforms with a shared precedence policy.
Precedence is: 1) explicitly requested platforms 2) declared platforms from requirements files 3) selector-derived platforms from dependency specs 4) current platform fallback (optional)
- 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