thoth.solver.python package

Submodules

thoth.solver.python.base module

Classes for resolving dependencies as specified in each ecosystem.

class thoth.solver.python.base.Dependency(name, spec)[source]

Bases: object

A Dependency consists of (package) name and version spec.

check(version)[source]

Check if version fits into our dependency specification.

Parameters

version – str

Returns

bool

property name

Get name property.

property spec

Get version spec property.

class thoth.solver.python.base.DependencyParser(**parser_kwargs)[source]

Bases: object

Base class for Dependency parsing.

static compose_sep(deps, separator)[source]

Opposite of parse().

Parameters
  • deps – list of Dependency()

  • separator – when joining dependencies, use this separator

Returns

dict of {name: version spec}

parse(specs)[source]

Abstract method for Dependency parsing.

class thoth.solver.python.base.NoOpDependencyParser(**parser_kwargs)[source]

Bases: thoth.solver.python.base.DependencyParser

Dummy dependency parser for ecosystems that don’t support version ranges.

static compose(deps)[source]

Opposite of parse().

parse(specs)[source]

Transform list of dependencies (strings) to list of Dependency.

static restrict_versions(deps)[source]

Not implemented.

exception thoth.solver.python.base.NoReleasesFound[source]

Bases: thoth.solver.python.base.SolverException

Exception raised if no releases were found for the given package.

class thoth.solver.python.base.ReleasesFetcher[source]

Bases: object

Base class for fetching releases.

fetch_releases(package)[source]

Abstract method for getting list of releases versions.

property index_url

Get URL to index from where releases are fetched.

class thoth.solver.python.base.Solver(dep_parser=None, fetcher=None, highest_dependency_version=True)[source]

Bases: object

Base class for resolving dependencies.

property dependency_parser

Return DependencyParser instance used by this solver.

property release_fetcher

Return ReleasesFetcher instance used by this solver.

solve(dependencies, graceful=True, all_versions=False)[source]

Solve dependencies against upstream repository.

Parameters
  • dependencies – List, List of dependencies in native format

  • graceful – bool, Print info output to stdout

  • all_versions – bool, Return all matched versions instead of the latest

Returns

Dict[str, str], Matched versions

exception thoth.solver.python.base.SolverException[source]

Bases: Exception

Exception to be raised in Solver.

class thoth.solver.python.base.Tokens[source]

Bases: object

Comparison token representation.

EQ1 = 2
EQ2 = 5
GT = 3
GTE = 0
LT = 4
LTE = 1
NEQ = 6
operators = ['>=', '<=', '==', '>', '<', '=', '!=']
thoth.solver.python.base.compare_version(a, b)[source]

Compare two version strings.

Parameters
  • a – str

  • b – str

Returns

-1 / 0 / 1

thoth.solver.python.base.get_ecosystem_solver(ecosystem_name, parser_kwargs=None, fetcher_kwargs=None)[source]

Get Solver subclass instance for particular ecosystem.

Parameters
  • ecosystem_name – name of ecosystem for which solver should be get

  • parser_kwargs – parser key-value arguments for constructor

  • fetcher_kwargs – fetcher key-value arguments for constructor

Returns

Solver

thoth.solver.python.instrument module

Functions which are executed inside virtual environment.

These functions are used to gather characteristics about installed packages which are analyzed.

All the functions are executed in a virtualenv - they should print information to stdout, if any error occurs they should print error messages to stderr and call sys.exit with non-zero value. All necessary functions should be either from standard virtualenv packages or from standard library to remove any dependency inference.

thoth.solver.python.instrument.execute_env_function(python_bin, function, *, env=None, raise_on_error=True, is_json=False, **function_arguments)[source]

Execute the given function in Python interpreter.

thoth.solver.python.instrument.find_distribution_name(python_bin, package_name)[source]

Find distribution name based on the package name.

thoth.solver.python.instrument.get_package_metadata(python_bin, package_name)[source]

Get metadata information from the installed package.

thoth.solver.python.python module

Dependency requirements solving for Python ecosystem.

thoth.solver.python.python.extract_metadata(metadata: dict, index_url: str) → dict[source]

Extract and enhance information from metadata.

thoth.solver.python.python.get_environment_packages(python_bin: str) → list[source]

Get information about packages in environment where packages get installed.

thoth.solver.python.python.parse_requirement_str(requirement_str: str)[source]

Parse a string representation of marker.

thoth.solver.python.python.pipdeptree(python_bin, package_name: str = None, warn: bool = False) → Optional[dict][source]

Get pip dependency tree by executing pipdeptree tool.

thoth.solver.python.python.resolve(requirements: List[str], index_urls: list = None, python_version: int = 3, exclude_packages: set = None, transitive: bool = True) → dict[source]

Resolve given requirements for the given Python version.

thoth.solver.python.python_solver module

Classes for resolving dependencies as specified in each ecosystem.

class thoth.solver.python.python_solver.PythonDependencyParser(**parser_kwargs)[source]

Bases: thoth.solver.python.base.DependencyParser

Python Dependency parsing.

static compose(deps)[source]

Compose deps.

parse(specs)[source]

Parse specs.

static parse_python(spec)[source]

Parse PyPI specification of a single dependency.

Parameters

spec – str, for example “Django>=1.5,<1.8”

Returns

[Django [[(‘>=’, ‘1.5’), (‘<’, ‘1.8’)]]]

static restrict_versions(deps)[source]

Not implemented.

class thoth.solver.python.python_solver.PythonReleasesFetcher(source: thoth.python.source.Source)[source]

Bases: thoth.solver.python.base.ReleasesFetcher

A releases fetcher based on PEP compatible simple API (also supporting Warehouse API).

fetch_releases(package_name)[source]

Fetch package and index_url for a package_name.

property index_url

Get URL to package source index from where releases are fetched.

class thoth.solver.python.python_solver.PythonSolver(parser_kwargs=None, fetcher_kwargs=None, solver_kwargs=None)[source]

Bases: thoth.solver.python.base.Solver

Pypi dependencies solver.

Module contents

Implementation of ecosystem specific solvers.