Python module#

Overview#

conda_envfile.parse_file(*args)

Parse one or more files and return the raw result.

conda_envfile.remove(dependencies, *args)

Remove dependencies.

conda_envfile.unique(*args)

Return a list of 'unique' dependencies.

conda_envfile#

class conda_envfile.PackageSpecifier(interpret: str = None)#

Interpret a package specifier, e.g.:

foo
foo *
foo =1.*
for >1.0
for <2.0
for >=1.0
for <=1.0
foo >=1.0, <2.0

To combine multiple specifiers in the most restrictive one:

>>> print(PackageSpecifier("foo") + PackageSpecifier("foo >1.0, <2.0"))
"foo >1.0, <2.0"

>>> print(PackageSpecifier("foo =1.*") + PackageSpecifier("foo >1.0, <2.0"))
"foo >1.0, <2.0"

>>> print(PackageSpecifier("foo =1.*") + PackageSpecifier("foo"))
"foo *"
property version: str#

The version specification, e.g. =1.0, =1.0.*, >=1.0, >=1.0, <2.0.

class conda_envfile.VersionRange(equal: str = None, less: str = None, less_equal: str = None, greater: str = None, greater_equal: str = None)#

Specify the most restrictive version range.

  • Modification of properties only leads to a change if the new value is more restrictive. For example:

    >>> vr = VersionRange(less="2.0")
    >>> vr.less_equal = "1.0"
    >>> print(vr)
    "<=1.0"
    

    while:

    >>> vr = VersionRange(less="2.0")
    >>> vr.less_equal = "3.0"
    >>> print(vr)
    "<2.0"
    
  • Merging two ranges to the most restrictive is done using +:

    >>> a = VersionRange(less="2.0")
    >>> b = VersionRange(greater="1.0")
    >>> print(a + b)
    ">1.0, <2.0"
    
same(other) bool#

Return True if the two VersionSpecs point to the same range, ignoring the string representation.

conda_envfile.apply_selector(text: str) str#

Apply platform selector:

sel(linux): ...
sel(osx): ...
sel(win): ...

based on current platform.

Parameters:

text – Package specifier with optional selector.

Returns:

Package specifier. Returns None is excluded by selector.

conda_envfile.conda_envfile_diff(args: list[str])#

Command-line tool, see --help.

Parameters:

args – Command-line arguments (should be all strings).

conda_envfile.conda_envfile_merge(args: list[str])#

Command-line tool, see --help.

Parameters:

args – Command-line arguments (should be all strings).

conda_envfile.conda_envfile_parse(args: list[str])#

Command-line tool, see --help.

Parameters:

args – Command-line arguments (should be all strings).

conda_envfile.conda_envfile_pyproject(args: list[str])#

Command-line tool, see --help.

Parameters:

args – Command-line arguments.

conda_envfile.conda_envfile_restrict(args: list[str])#

Command-line tool, see --help.

Parameters:

args – Command-line arguments (should be all strings).

conda_envfile.condaforge_dependencies(text: str, name: str = None, flatten: bool = True, selectors: list[str] = [], target_platform: str = 'myplatform') list[str]#

Get the dependencies from a conda-forge feedstock.

Parameters:
  • name – Name of the recipe to select (use to select one of multi-outputs).

  • flatten – Flatten the dependencies, otherwise keep as "host", "run", "build".

  • selectors – List of selectors to keep (all non-selected selectors are removed).

  • target_platform – Target platform to use to substitute {{ target_platform }}.

conda_envfile.contains(requirements: list[PackageSpecifier], installed: list[PackageSpecifier]) bool#

Check if all dependencies in requirements are satisfied by installed.

Parameters:
  • requirements – List of requirements.

  • installed – List of ‘installed’ dependencies.

Returns:

True if all requirements are satisfied, False otherwise.

conda_envfile.filter_selectors(deps: list[str]) list[str]#

Filter selectors from dependencies.

Parameters:

deps – List of dependencies (text).

Returns:

List of dependencies (text) without selectors, and dependencies excluded by selectors.

conda_envfile.parse_file(*args: list[str]) dict#

Parse one or more files and return the raw result.

Parameters:

args – List of filenames to parse.

Returns:

Raw result: {"name": [...], "channels": [...], "dependencies": [...]}

conda_envfile.parse_github_action(text: str) dict#

Parse a GitHub action. Currently very basic. Looks for the first occurrence of mamba-org/provision-with-micromamba.

Parameters:

filename – Filename to parse.

Returns:

Raw result: {"name": [...], "channels": [...], "dependencies": [...]}

conda_envfile.print_diff(a: list[PackageSpecifier], b: list[PackageSpecifier], silent: bool = False) PrettyTable#

Print differences between a and b.

Parameters:
  • a – List of dependencies.

  • b – List of dependencies.

  • silent – Do not print the table.

Returns:

PrettyTable object.

conda_envfile.remove(dependencies: list[str], *args: list[str]) list[str]#

Remove dependencies.

Parameters:
  • dependencies – List of dependencies.

  • args – List of dependencies to remove (version specification is ignored).

Returns:

List of dependencies.

conda_envfile.restrict(source, other: list[str] = None) list[PackageSpecifier]#

Restrict all dependencies in source to the most restrictive version specification in source and other. All dependencies that are in other but not in source are ignored. In instead you want to integrate them, use unique():

merged = unique(*source, *other)
Parameters:
  • source – List of dependencies.

  • other – List of other dependencies.

Returns:

List of dependencies.

conda_envfile.unique(*args) list[PackageSpecifier]#

Return a list of ‘unique’ dependencies. If multiple dependencies with the same name are given, the most restrictive version specification is returned.

Parameters:

args – Dependencies to merge.

Returns:

List of unique dependencies (convert to strings: list(map(str, unique(*args))))