unidep.utils module#

unidep - Unified Conda and Pip requirements management.

This module provides utility functions used throughout the package.

class unidep.utils.ParsedPackageStr(name: str, pin: str | None = None, selector: str | None = None)[source]#

Bases: NamedTuple

A package name and version pinning.

name: str#

Alias for field number 0

pin: Optional[str]#

Alias for field number 1

selector: Optional[str]#

Alias for field number 2

exception unidep.utils.UnsupportedPlatformError[source]#

Bases: Exception

Raised 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:

None

unidep.utils.build_pep508_environment_marker(platforms)[source]#

Generate a PEP 508 selector for a list of platforms.

Return type:

str

unidep.utils.dependencies_filename(folder_or_path)[source]#

Get the path to requirements.yaml or pyproject.toml file.

Return type:

Path

unidep.utils.escape_unicode(string)[source]#

Escape unicode characters.

Return type:

str

unidep.utils.extract_matching_platforms(comment)[source]#

Get all platforms matching a comment.

Return type:

list[Literal['linux-64', 'linux-aarch64', 'linux-ppc64le', 'osx-64', 'osx-arm64', 'win-64']]

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.

Return type:

bool

unidep.utils.parse_package_str(package_str)[source]#

Splits a string into package name, version pinning, and platform selector.

Return type:

ParsedPackageStr

unidep.utils.remove_top_comments(filename)[source]#

Removes the top comments (lines starting with ‘#’) from a file.

Return type:

None

unidep.utils.selector_from_comment(comment)[source]#

Extract a valid selector from a comment.

Return type:

Optional[str]

unidep.utils.unidep_configured_in_toml(path)[source]#

Check if dependencies are specified in pyproject.toml.

If a TOML parser is not available it finds [tool.unidep] in pyproject.toml.

Return type:

bool

unidep.utils.warn(message, category=<class 'UserWarning'>, stacklevel=1)[source]#

Emit a warning with a custom format specific to this package.

Return type:

None