thoth.python package

Submodules

thoth.python.aiosource module

Representation of source (index) for Python packages.

class thoth.python.aiosource.AIOSource(url: str, name: str = NOTHING, verify_ssl: bool = True, warehouse: bool = NOTHING, warehouse_api_url: Optional[str] = None)[source]

Bases: thoth.python.source.Source

Representation of source (Python index) for Python packages.

async get_package_artifacts(package_name: str, package_version: str)[source]

Return list of artifacts corresponding to package name and package version.

get_package_hashes(package_name: str, package_version: str, with_included_files: bool = False) List[source]

Get information about release hashes available in this source index.

get_package_versions(package_name: str) thoth.python.aiosource.AsyncIterableVersions[source]

Get listing of versions available for the given package.

async get_packages() Optional[thoth.python.aiosource.AsyncIterablePackages][source]

List packages available on the source package index.

class thoth.python.aiosource.AsyncIterableArtifacts(artifacts: List[Tuple[str, str]])[source]

Bases: object

Async Iterator for Artifacts.

async fetch_data() Optional[Tuple][source]

Fetch data.

class thoth.python.aiosource.AsyncIterablePackages(_packages: Set[str])[source]

Bases: object

Async Iterator for Packages.

async fetch_data() Optional[str][source]

Fetch data.

class thoth.python.aiosource.AsyncIterableVersions(_versions: Set[str])[source]

Bases: object

Async Iterator for Versions.

async fetch_data() Optional[str][source]

Fetch data.

thoth.python.artifact module

Representation a python module and all the files within.

class thoth.python.artifact.Artifact(artifact_name: str, artifact_url: str, compressed_file: Optional[str] = None, dir_name: Optional[str] = None, verify_ssl: bool = False, sha: Optional[str] = None)[source]

Bases: object

Python artifacts are compressed modules.

artifact_name
artifact_url
compressed_file
dir_name
gather_hashes() list[source]

Calculate checksums and gather hashes of all file in the given artifact.

get_versioned_symbols() dict[source]

Walk dir and get all dynamic symbols required from all files.

sha
verify_ssl

thoth.python.configuration module

Configuration used for computing recommendations.

thoth.python.constraints module

Implementation of an abstraction keeping constraints.

class thoth.python.constraints.Constraints(*, package_versions: Dict[str, thoth.python.package_version.PackageVersion] = NOTHING)[source]

Bases: object

Constraints manipulation.

classmethod from_dict(dict_: List[Dict[str, Any]]) thoth.python.constraints.Constraints[source]

Instantiate constraints from a dictionary representation.

classmethod from_file(constraints_file: str) thoth.python.constraints.Constraints[source]

Load constraints from a file.

classmethod from_package_versions(package_versions: List[thoth.python.package_version.PackageVersion]) thoth.python.constraints.Constraints[source]

Instantiate constraints from package versions, perform checks to verify correct instance.

classmethod from_string(content: str) thoth.python.constraints.Constraints[source]

Load constraints from a string.

package_versions
to_dict() List[Dict[str, Any]][source]

Serialize constraint instance to a dictionary representation.

thoth.python.digests_fetcher module

Fetching package artifact digests.

class thoth.python.digests_fetcher.DigestsFetcherBase[source]

Bases: object

A base class implementing digests fetching.

fetch_digests(package_name: str, package_version: str) dict[source]

Fetch digests for the given package in specified version from the given package index.

class thoth.python.digests_fetcher.PythonDigestsFetcher(sources: List[thoth.python.source.Source])[source]

Bases: thoth.python.digests_fetcher.DigestsFetcherBase

Fetch digests from the given PEP-503 compatible package source index.

fetch_digests(package_name: str, package_version: str) dict[source]

Fetch digests for the given package in specified version from the given package index.

thoth.python.exceptions module

Exceptions used in the thoth-python package.

exception thoth.python.exceptions.ConstraintsError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

An exception raised when an issue with constraints found.

exception thoth.python.exceptions.DirectDependencyRemovalError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

Raised if trying to remove direct dependency from application stack.

Or there is no option to remove the given dependency from application stack.

exception thoth.python.exceptions.FileLoadError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

Raised when failed to open or parse a file.

exception thoth.python.exceptions.InternalError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

An exception raised on bugs in the code base.

exception thoth.python.exceptions.NotFoundError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

Raised if the given artifact cannot be found.

exception thoth.python.exceptions.PackageVersionAlreadyPresentError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

An exception raised when adding a package in specific version that is already present.

exception thoth.python.exceptions.PipfileParseError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

An exception raised on invalid Pipfile or Pipfile.lock.

exception thoth.python.exceptions.SourceNotFoundError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

An exception raise when the given package source is not found.

exception thoth.python.exceptions.ThothPythonExceptionError[source]

Bases: Exception

A base class for thoth-python exceptions.

exception thoth.python.exceptions.UnableLockError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

Raised if trying to lock invalid application stack or resolution cannot be done.

exception thoth.python.exceptions.UnsupportedConfigurationError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

Raised on unsupported configuration options.

exception thoth.python.exceptions.VersionIdentifierError[source]

Bases: thoth.python.exceptions.ThothPythonExceptionError

An exception raised if the given version identifier is not a semver identifier.

thoth.python.helpers module

Helper functions and utilities.

thoth.python.helpers.fill_package_digests(generated_project: Project) Project[source]

Temporary fill package digests stated in Pipfile.lock.

thoth.python.helpers.parse_requirement_str(requirement_str: str) Dict[str, Any][source]

Parse a string representation of marker.

thoth.python.helpers.parse_requirements(file_path: str) Tuple[List[thoth.python.source.Source], List[thoth.python.package_version.PackageVersion]][source]

Parse requirements.{txt,in} file.

thoth.python.helpers.parse_requirements_str(requirements: str, _file_path: Optional[str] = None) Tuple[List[thoth.python.source.Source], List[thoth.python.package_version.PackageVersion]][source]

Parse content of requirements.{txt,in} file.

thoth.python.package_version module

Representation of packages in the application stack.

class thoth.python.package_version.PackageVersion(name: str, version: Optional[str], develop: bool, index: Optional[thoth.python.source.Source] = None, hashes=NOTHING, markers: Optional[str] = None, extras=NOTHING, semantic_version: Optional[thoth.python.package_version.Version] = None, locked_version: Optional[str] = None, package_tuple: Optional[Tuple[str, str, Optional[str]]] = None, package_tuple_locked: Optional[Tuple[str, str, Optional[str]]] = None)[source]

Bases: object

A package version as described in the Pipfile.lock entry.

develop
duplicate()[source]

Duplicate the given package safely when performing changes in resolution.

extras
classmethod from_model(model, *, develop: bool = False)[source]

Convert database model representation to object representation.

classmethod from_pipfile_entry(package_name: str, entry: Union[dict, str], develop: bool, meta: PipfileMeta)[source]

Construct PackageVersion instance from representation as stated in Pipfile.

classmethod from_pipfile_lock_entry(package_name: str, entry: dict, develop: bool, meta: PipfileMeta)[source]

Construct PackageVersion instance from representation as stated in Pipfile.lock.

hashes
index
is_locked()[source]

Check if the given package is locked to a specific version.

property locked_version: str

Retrieve locked version of the package.

markers
name
negate_version() None[source]

Negate version of a locked package version.

classmethod normalize_python_package_name(package_name: str) str[source]

Normalize Python package name based on PEP-0503.

https://www.python.org/dev/peps/pep-0503/#normalized-names

classmethod normalize_python_package_version(package_version: str) str[source]

Normalize Python package version based on PEP-440.

https://www.python.org/dev/peps/pep-0440/#normalization

static parse_semantic_version(version_identifier: str) thoth.python.package_version.Version[source]

Parse the given version identifier into a semver representation.

property semantic_version: thoth.python.package_version.Version

Get semantic version respecting version specified - package has to be locked to a specific version.

to_dict() dict[source]

Create a dictionary representation of parameters (useful for later constructor calls).

to_pipfile()[source]

Generate Pipfile entry for the given package.

to_pipfile_lock() dict[source]

Create an entry as stored in the Pipfile.lock.

to_tuple() Tuple[str, str, Optional[str]][source]

Return a tuple representing this Python package.

to_tuple_locked() Tuple[str, str, Optional[str]][source]

Return a tuple representing this Python package - used for locked packages.

version
class thoth.python.package_version.Version(version_identifier: str)[source]

Bases: object

A simple wrapper around packaging’s version to support seamless API for legacy and current version handling.

property base_version: str

Get version base.

property dev: Optional[int]

Get version dev.

property epoch: int

Get version epoch.

property is_devrelease: bool

Check if version is a dev-release.

property is_legacy_version: bool

Check if the given version is a legacy version identifier.

property is_postrelease: bool

Check if version is a post-release.

property is_prerelease: bool

Check if version is a pre-release.

property local: Optional[str]

Get version local.

property major: int

Get version major release.

property micro: int

Get version micro release.

property minor: int

Get version minor release.

property post: Optional[int]

Get version post.

property pre: Optional[Tuple[str, int]]

Get version pre.

property public: str

Get version public.

property release: Tuple[int, ...]

Get version release.

thoth.python.packages module

Representation of development and default packages as stated in Pipfile and Pipfile.lock.

class thoth.python.packages.Packages(develop: bool, packages: dict)[source]

Bases: object

Encapsulate logic on package manipulation.

add_package_version(package_version: thoth.python.package_version.PackageVersion, *, force: bool = False)[source]

Add the given package version to package list.

develop
classmethod from_package_versions(package_versions: List[thoth.python.package_version.PackageVersion], develop: bool)[source]

Create Packages instance from a list of packages in specific versions.

classmethod from_pipfile(packages, develop, meta)[source]

Parse Pipfile entry stating list of packages used.

classmethod from_pipfile_lock(packages, develop, meta)[source]

Parse Pipfile.lock entry stating list of packages used.

get(package_name: str) Optional[thoth.python.package_version.PackageVersion][source]

Get package by its name.

is_default()[source]

Check if packages provided by this instance are dependencies of application packages.

is_develop()[source]

Check if packages provided by this instance are development packages.

packages
to_pipfile() dict[source]

Convert packages representation as seen in Pipfile file.

to_pipfile_lock() dict[source]

Convert packages representation as seen in Pipfile.lock file.

thoth.python.pipfile module

Parse string representation of a Pipfile or Pipfile.lock and represent it in an object.

class thoth.python.pipfile.Pipfile(packages: thoth.python.packages.Packages, dev_packages: thoth.python.packages.Packages, meta: thoth.python.pipfile.PipfileMeta, thoth: thoth.python.pipfile.ThothPipfileSection = NOTHING)[source]

Bases: thoth.python.pipfile._PipfileBase

A Pipfile representation - representation of direct dependencies of an application.

add_requirement(requirement: str, *, is_dev: bool = False, index_url: Optional[str] = None, force: bool = False) None[source]

Parse and add a requirement to direct dependency listing.

construct_requirements_in() str[source]

Construct requirements.in file for the current project.

property data

Return data used to compute hash based on Pipfile stored in Pipfile.lock.

classmethod from_dict(dict_) thoth.python.pipfile.Pipfile[source]

Retrieve instance of Pipfile from its dictionary representation.

classmethod from_file(file_path: Optional[str] = None) thoth.python.pipfile.Pipfile[source]

Parse Pipfile file and return its Pipfile representation.

classmethod from_package_versions(packages: List[thoth.python.package_version.PackageVersion], meta: Optional[thoth.python.pipfile.PipfileMeta] = None) thoth.python.pipfile.Pipfile[source]

Construct Pipfile from provided PackageVersion instances.

classmethod from_string(pipfile_content: str) thoth.python.pipfile.Pipfile[source]

Parse Pipfile from its string representation.

hash()[source]

Compute hash of Pipfile.

thoth
to_dict(keep_thoth_section: bool = False) dict[source]

Return Pipfile representation as dict.

to_file(*, path: str = 'Pipfile', keep_thoth_section: bool = False) None[source]

Convert the current state of Pipfile to actual Pipfile file stored in CWD.

to_string(*, keep_thoth_section: bool = False) str[source]

Convert representation of Pipfile to actual Pipfile file content.

class thoth.python.pipfile.PipfileLock(packages: thoth.python.packages.Packages, dev_packages: thoth.python.packages.Packages, meta: thoth.python.pipfile.PipfileMeta, pipfile: Optional[thoth.python.pipfile.Pipfile])[source]

Bases: thoth.python.pipfile._PipfileBase

A Pipfile.lock representation - representation of fully pinned down stack with info such as hashes.

classmethod from_dict(dict_: dict, pipfile: Optional[thoth.python.pipfile.Pipfile] = None) thoth.python.pipfile.PipfileLock[source]

Construct PipfileLock class from a parsed JSON representation as stated in actual Pipfile.lock.

classmethod from_file(file_path: Optional[str] = None, pipfile: Optional[thoth.python.pipfile.Pipfile] = None) thoth.python.pipfile.PipfileLock[source]

Parse Pipfile.lock file and return its PipfileLock representation.

classmethod from_package_versions(pipfile: thoth.python.pipfile.Pipfile, packages: List[thoth.python.package_version.PackageVersion], meta: Optional[thoth.python.pipfile.PipfileMeta] = None) thoth.python.pipfile.PipfileLock[source]

Construct Pipfile from provided PackageVersion instances.

classmethod from_string(pipfile_content: str, pipfile: Optional[thoth.python.pipfile.Pipfile] = None) thoth.python.pipfile.PipfileLock[source]

Parse Pipfile.lock from its string content.

pipfile
to_dict(pipfile: Optional[thoth.python.pipfile.Pipfile] = None) dict[source]

Create a dict representation of Pipfile.lock content.

to_file(*, path: str = 'Pipfile.lock', pipfile: Optional[thoth.python.pipfile.Pipfile] = None) None[source]

Convert the current state of PipfileLock to actual Pipfile.lock file stored in CWD.

to_string(pipfile: Optional[thoth.python.pipfile.Pipfile] = None) str[source]

Convert the current state of PipfileLock to its Pipfile.lock file representation.

class thoth.python.pipfile.PipfileMeta(sources: Dict[str, thoth.python.source.Source], requires: Dict[str, Any] = NOTHING, pipenv: Optional[Dict[str, Any]] = None, hash: Optional[Dict[str, Any]] = None, pipfile_spec: int = 6)[source]

Bases: object

Parse meta information stored in Pipfile or Pipfile.lock.

add_source(source: thoth.python.source.Source)[source]

Add the given package source.

classmethod from_dict(dict_: dict)[source]

Parse sources from dict as stated in Pipfile/Pipfile.lock.

get_source_by_url(index_url) thoth.python.source.Source[source]

Get source registered by its index url.

get_sources_providing_package(package_name: str) list[source]

Get all source indexes providing the given package.

get_sources_providing_package_version(package_name: str, package_version: str) list[source]

Get all source indexes providing the given package in the specified value.

hash
pipenv
pipfile_spec
requires
set_hash(hash_: dict)[source]

Set hash of Pipfile to make sure pipenv uses correct parts..

sources
to_dict(is_lock: bool = False)[source]

Produce sources as a dict representation as stated in Pipfile/Pipfile.lock.

to_requirements_index_conf() str[source]

Add index configuration as would be stated in the requirements.txt file.

class thoth.python.pipfile.ThothPipfileSection(allow_prereleases: Dict[str, bool] = NOTHING, disable_index_adjustment: bool = False)[source]

Bases: object

Thoth specific section in Pipfile.

allow_prereleases
disable_index_adjustment
classmethod from_dict(dict_: Dict[str, Any]) thoth.python.pipfile.ThothPipfileSection[source]

Convert Thoth specific section in Pipfile to a dictionary representation.

to_dict(keep_defaults: bool = False) Dict[str, Any][source]

Get a dict representation of Thoth specific section in Pipfile.

thoth.python.project module

Project abstraction and operations on project dependencies.

class thoth.python.project.Project(pipfile: thoth.python.pipfile.Pipfile, pipfile_lock: Optional[thoth.python.pipfile.PipfileLock], runtime_environment: thoth.common.config.runtime_environment.RuntimeEnvironment = NOTHING, constraints: thoth.python.constraints.Constraints = NOTHING, graph_db=None, workdir=None)[source]

Bases: object

A representation of a Python project.

add_package(package_name: str, package_version: Optional[str] = None, *, source: Optional[thoth.python.source.Source] = None, develop: bool = False)[source]

Add the given package to project.

This method will add packages only to Pipfile, locking has to be explicitly done once package is added.

add_source(url: str, verify_ssl: bool = True, name: Optional[str] = None, warehouse: bool = False, warehouse_api_url: Optional[str] = None) thoth.python.source.Source[source]

Add a package source (index) to the project.

check_provenance(whitelisted_sources: Optional[list] = None, digests_fetcher: Optional[thoth.python.digests_fetcher.DigestsFetcherBase] = None) List[source]

Check provenance/origin of packages that are stated in the project.

constraints
construct_requirements_in() str[source]

Construct requirements.in file for the current project.

construct_requirements_txt() str[source]

Construct requirements.txt file for the current project - pip-tools compatible.

exclude_package(package_version: thoth.python.package_version.PackageVersion) None[source]

Exclude the given package from application stack.

classmethod from_dict(pipfile: Dict[str, Any], pipfile_lock: Dict[str, Any], runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None) thoth.python.project.Project[source]

Construct project out of a dict representation.

classmethod from_files(pipfile_path: str, pipfile_lock_path: Optional[str] = None, *, constraints: Optional[thoth.python.constraints.Constraints] = None, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, without_pipfile_lock: bool = False)[source]

Create project from Pipfile and Pipfile.lock files.

classmethod from_package_versions(packages: List[thoth.python.package_version.PackageVersion], packages_locked: Optional[List[thoth.python.package_version.PackageVersion]] = None, meta: Optional[thoth.python.pipfile.PipfileMeta] = None, *, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None)[source]

Create project from PackageVersion objects.

If locked packages are omitted, the lock has to be explicitly performed to generate in-memory Pipfile.lock representation.

classmethod from_pip_compile_files(requirements_path: str = 'requirements.in', requirements_lock_path: Optional[str] = None, allow_without_lock: bool = False, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None) thoth.python.project.Project[source]

Parse project from files compatible with pip/pip-tools.

classmethod from_strings(pipfile_str: str, pipfile_lock_str: Optional[str] = None, *, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None)[source]

Create project from Pipfile and Pipfile.lock loaded into strings.

get_configuration_check_report() Optional[Tuple[Optional[dict], List[dict]]][source]

Get a report on project configuration for the given runtime environment.

get_locked_package_version(package_name: str) Optional[thoth.python.package_version.PackageVersion][source]

Get locked version of the package.

get_outdated_package_versions(devel: bool = True) dict[source]

Get outdated packages in the lock file.

This function will check indexes configured and look for version of each package. If the given package package is not latest, it will add it to the resulting list with the newer version identifier found on package index.

get_package_version(package_name: str) Optional[thoth.python.package_version.PackageVersion][source]

Get locked version of the package.

is_direct_dependency(package_version: thoth.python.package_version.PackageVersion) bool[source]

Check whether the given package is a direct dependency.

iter_dependencies(with_devel: bool = True)[source]

Iterate through direct dependencies of this project (not locked dependencies).

iter_dependencies_locked(with_devel: bool = True)[source]

Iterate through locked dependencies of this project.

pipenv_lock()[source]

Perform pipenv lock on the current state of project.

pipfile
pipfile_lock
property prereleases_allowed: bool

Check if pre-releases are allowed for this project.

property python_version: Optional[str]

Get Python version used in this project.

runtime_environment
sanitize_source_indexes()[source]

Make sure all the indexes are correctly propagated to Pipfile and Pipfile.lock metadata.

set_allow_prereleases(allow_prereleases: bool = True) None[source]

Allow or disallow pre-releases for this project.

set_python_version(python_version: Optional[str] = None) None[source]

Set version of Python used in the project.

to_dict(*, keep_thoth_section: bool = False)[source]

Create a dictionary representation of this project.

to_files(pipfile_path: Optional[str] = None, pipfile_lock_path: Optional[str] = None, *, without_pipfile_lock: bool = False, keep_thoth_section: bool = False) None[source]

Write the current state of project into Pipfile and Pipfile.lock files.

to_pip_compile_files(requirements_path: str = 'requirements.in', requirements_lock_path: str = 'requirements.txt', without_lock: bool = False) None[source]

Write the current state of project into requirements.in and requirements.txt files.

Files created are compatible with pip/pip-tools. If no lock is specified, requirements.txt hold unpinned direct dependencies as in case of pip.

property workdir: str

Access working directory of project.

thoth.python.source module

Representation of source (index) for Python packages.

class thoth.python.source.Source(url: str, name: str = NOTHING, verify_ssl: bool = True, warehouse: bool = NOTHING, warehouse_api_url: Optional[str] = None)[source]

Bases: object

Representation of source (Python index) for Python packages.

default_name()[source]

Create a name for source based on url if not explicitly provided.

classmethod from_dict(dict_: dict)[source]

Parse source from its dictionary representation.

get_api_url()[source]

Construct URL to Warehouse instance.

get_latest_package_version(package_name: str, graceful: bool = False) Optional[Union[packaging.version.Version, packaging.version.LegacyVersion]][source]

Get the latest version for the given package.

get_package_artifacts(package_name: str, package_version: str)[source]

Return list of artifacts corresponding to package name and package version.

get_package_data(package_name: str, package_version: str, with_included_files: bool = False) list[source]

Get information about release hashes and symbols available in this source index.

get_package_hashes(package_name: str, package_version: str, with_included_files: bool = False) list[source]

Get information about release hashes available in this source index.

get_package_release_date(package_name: str, package_version: str) datetime.datetime[source]

Get time at which package was uploaded to package index.

get_package_versions(package_name: str) list[source]

Get listing of versions available for the given package.

get_packages() set[source]

List packages available on the source package index.

get_sorted_package_versions(package_name: str, graceful: bool = False, reverse: bool = True) Optional[List[Union[packaging.version.Version, packaging.version.LegacyVersion]]][source]

Get sorted versions for the given package.

classmethod is_normalized_python_package_name(package_name: str) bool[source]

Check if the given Python package name is normalized.

name
static normalize_package_name(package_name: str) str[source]

Normalize package name on index according to PEP-0503.

provides_package(package_name: str) bool[source]

Check if the given package is provided by this package source index.

provides_package_version(package_name: str, package_version: str) bool[source]

Check if the given source provides package in the given version.

to_dict(include_warehouse: bool = False) dict[source]

Convert source definition to its dict representation.

url
verify_ssl
warehouse
warehouse_api_url
warehouse_default()[source]

Check if the given url is registered in default warehouses.

thoth.python.source.normalize_url(url: str) str[source]

We normalize url to remove legacy urls.

Module contents

Python ecosystem specific routines.

class thoth.python.AIOSource(url: str, name: str = NOTHING, verify_ssl: bool = True, warehouse: bool = NOTHING, warehouse_api_url: Optional[str] = None)[source]

Bases: thoth.python.source.Source

Representation of source (Python index) for Python packages.

async get_package_artifacts(package_name: str, package_version: str)[source]

Return list of artifacts corresponding to package name and package version.

get_package_hashes(package_name: str, package_version: str, with_included_files: bool = False) List[source]

Get information about release hashes available in this source index.

get_package_versions(package_name: str) thoth.python.aiosource.AsyncIterableVersions[source]

Get listing of versions available for the given package.

async get_packages() Optional[thoth.python.aiosource.AsyncIterablePackages][source]

List packages available on the source package index.

class thoth.python.AsyncIterableArtifacts(artifacts: List[Tuple[str, str]])[source]

Bases: object

Async Iterator for Artifacts.

async fetch_data() Optional[Tuple][source]

Fetch data.

class thoth.python.AsyncIterablePackages(_packages: Set[str])[source]

Bases: object

Async Iterator for Packages.

async fetch_data() Optional[str][source]

Fetch data.

class thoth.python.AsyncIterableVersions(_versions: Set[str])[source]

Bases: object

Async Iterator for Versions.

async fetch_data() Optional[str][source]

Fetch data.

class thoth.python.Constraints(*, package_versions: Dict[str, thoth.python.package_version.PackageVersion] = NOTHING)[source]

Bases: object

Constraints manipulation.

classmethod from_dict(dict_: List[Dict[str, Any]]) thoth.python.constraints.Constraints[source]

Instantiate constraints from a dictionary representation.

classmethod from_file(constraints_file: str) thoth.python.constraints.Constraints[source]

Load constraints from a file.

classmethod from_package_versions(package_versions: List[thoth.python.package_version.PackageVersion]) thoth.python.constraints.Constraints[source]

Instantiate constraints from package versions, perform checks to verify correct instance.

classmethod from_string(content: str) thoth.python.constraints.Constraints[source]

Load constraints from a string.

package_versions
to_dict() List[Dict[str, Any]][source]

Serialize constraint instance to a dictionary representation.

class thoth.python.DigestsFetcherBase[source]

Bases: object

A base class implementing digests fetching.

fetch_digests(package_name: str, package_version: str) dict[source]

Fetch digests for the given package in specified version from the given package index.

class thoth.python.PackageVersion(name: str, version: Optional[str], develop: bool, index: Optional[thoth.python.source.Source] = None, hashes=NOTHING, markers: Optional[str] = None, extras=NOTHING, semantic_version: Optional[thoth.python.package_version.Version] = None, locked_version: Optional[str] = None, package_tuple: Optional[Tuple[str, str, Optional[str]]] = None, package_tuple_locked: Optional[Tuple[str, str, Optional[str]]] = None)[source]

Bases: object

A package version as described in the Pipfile.lock entry.

develop
duplicate()[source]

Duplicate the given package safely when performing changes in resolution.

extras
classmethod from_model(model, *, develop: bool = False)[source]

Convert database model representation to object representation.

classmethod from_pipfile_entry(package_name: str, entry: Union[dict, str], develop: bool, meta: PipfileMeta)[source]

Construct PackageVersion instance from representation as stated in Pipfile.

classmethod from_pipfile_lock_entry(package_name: str, entry: dict, develop: bool, meta: PipfileMeta)[source]

Construct PackageVersion instance from representation as stated in Pipfile.lock.

hashes
index
is_locked()[source]

Check if the given package is locked to a specific version.

property locked_version: str

Retrieve locked version of the package.

markers
name
negate_version() None[source]

Negate version of a locked package version.

classmethod normalize_python_package_name(package_name: str) str[source]

Normalize Python package name based on PEP-0503.

https://www.python.org/dev/peps/pep-0503/#normalized-names

classmethod normalize_python_package_version(package_version: str) str[source]

Normalize Python package version based on PEP-440.

https://www.python.org/dev/peps/pep-0440/#normalization

static parse_semantic_version(version_identifier: str) thoth.python.package_version.Version[source]

Parse the given version identifier into a semver representation.

property semantic_version: thoth.python.package_version.Version

Get semantic version respecting version specified - package has to be locked to a specific version.

to_dict() dict[source]

Create a dictionary representation of parameters (useful for later constructor calls).

to_pipfile()[source]

Generate Pipfile entry for the given package.

to_pipfile_lock() dict[source]

Create an entry as stored in the Pipfile.lock.

to_tuple() Tuple[str, str, Optional[str]][source]

Return a tuple representing this Python package.

to_tuple_locked() Tuple[str, str, Optional[str]][source]

Return a tuple representing this Python package - used for locked packages.

version
class thoth.python.Packages(develop: bool, packages: dict)[source]

Bases: object

Encapsulate logic on package manipulation.

add_package_version(package_version: thoth.python.package_version.PackageVersion, *, force: bool = False)[source]

Add the given package version to package list.

develop
classmethod from_package_versions(package_versions: List[thoth.python.package_version.PackageVersion], develop: bool)[source]

Create Packages instance from a list of packages in specific versions.

classmethod from_pipfile(packages, develop, meta)[source]

Parse Pipfile entry stating list of packages used.

classmethod from_pipfile_lock(packages, develop, meta)[source]

Parse Pipfile.lock entry stating list of packages used.

get(package_name: str) Optional[thoth.python.package_version.PackageVersion][source]

Get package by its name.

is_default()[source]

Check if packages provided by this instance are dependencies of application packages.

is_develop()[source]

Check if packages provided by this instance are development packages.

packages
to_pipfile() dict[source]

Convert packages representation as seen in Pipfile file.

to_pipfile_lock() dict[source]

Convert packages representation as seen in Pipfile.lock file.

class thoth.python.Pipfile(packages: thoth.python.packages.Packages, dev_packages: thoth.python.packages.Packages, meta: thoth.python.pipfile.PipfileMeta, thoth: thoth.python.pipfile.ThothPipfileSection = NOTHING)[source]

Bases: thoth.python.pipfile._PipfileBase

A Pipfile representation - representation of direct dependencies of an application.

add_requirement(requirement: str, *, is_dev: bool = False, index_url: Optional[str] = None, force: bool = False) None[source]

Parse and add a requirement to direct dependency listing.

construct_requirements_in() str[source]

Construct requirements.in file for the current project.

property data

Return data used to compute hash based on Pipfile stored in Pipfile.lock.

classmethod from_dict(dict_) thoth.python.pipfile.Pipfile[source]

Retrieve instance of Pipfile from its dictionary representation.

classmethod from_file(file_path: Optional[str] = None) thoth.python.pipfile.Pipfile[source]

Parse Pipfile file and return its Pipfile representation.

classmethod from_package_versions(packages: List[thoth.python.package_version.PackageVersion], meta: Optional[thoth.python.pipfile.PipfileMeta] = None) thoth.python.pipfile.Pipfile[source]

Construct Pipfile from provided PackageVersion instances.

classmethod from_string(pipfile_content: str) thoth.python.pipfile.Pipfile[source]

Parse Pipfile from its string representation.

hash()[source]

Compute hash of Pipfile.

thoth
to_dict(keep_thoth_section: bool = False) dict[source]

Return Pipfile representation as dict.

to_file(*, path: str = 'Pipfile', keep_thoth_section: bool = False) None[source]

Convert the current state of Pipfile to actual Pipfile file stored in CWD.

to_string(*, keep_thoth_section: bool = False) str[source]

Convert representation of Pipfile to actual Pipfile file content.

class thoth.python.PipfileLock(packages: thoth.python.packages.Packages, dev_packages: thoth.python.packages.Packages, meta: thoth.python.pipfile.PipfileMeta, pipfile: Optional[thoth.python.pipfile.Pipfile])[source]

Bases: thoth.python.pipfile._PipfileBase

A Pipfile.lock representation - representation of fully pinned down stack with info such as hashes.

classmethod from_dict(dict_: dict, pipfile: Optional[thoth.python.pipfile.Pipfile] = None) thoth.python.pipfile.PipfileLock[source]

Construct PipfileLock class from a parsed JSON representation as stated in actual Pipfile.lock.

classmethod from_file(file_path: Optional[str] = None, pipfile: Optional[thoth.python.pipfile.Pipfile] = None) thoth.python.pipfile.PipfileLock[source]

Parse Pipfile.lock file and return its PipfileLock representation.

classmethod from_package_versions(pipfile: thoth.python.pipfile.Pipfile, packages: List[thoth.python.package_version.PackageVersion], meta: Optional[thoth.python.pipfile.PipfileMeta] = None) thoth.python.pipfile.PipfileLock[source]

Construct Pipfile from provided PackageVersion instances.

classmethod from_string(pipfile_content: str, pipfile: Optional[thoth.python.pipfile.Pipfile] = None) thoth.python.pipfile.PipfileLock[source]

Parse Pipfile.lock from its string content.

pipfile
to_dict(pipfile: Optional[thoth.python.pipfile.Pipfile] = None) dict[source]

Create a dict representation of Pipfile.lock content.

to_file(*, path: str = 'Pipfile.lock', pipfile: Optional[thoth.python.pipfile.Pipfile] = None) None[source]

Convert the current state of PipfileLock to actual Pipfile.lock file stored in CWD.

to_string(pipfile: Optional[thoth.python.pipfile.Pipfile] = None) str[source]

Convert the current state of PipfileLock to its Pipfile.lock file representation.

class thoth.python.PipfileMeta(sources: Dict[str, thoth.python.source.Source], requires: Dict[str, Any] = NOTHING, pipenv: Optional[Dict[str, Any]] = None, hash: Optional[Dict[str, Any]] = None, pipfile_spec: int = 6)[source]

Bases: object

Parse meta information stored in Pipfile or Pipfile.lock.

add_source(source: thoth.python.source.Source)[source]

Add the given package source.

classmethod from_dict(dict_: dict)[source]

Parse sources from dict as stated in Pipfile/Pipfile.lock.

get_source_by_url(index_url) thoth.python.source.Source[source]

Get source registered by its index url.

get_sources_providing_package(package_name: str) list[source]

Get all source indexes providing the given package.

get_sources_providing_package_version(package_name: str, package_version: str) list[source]

Get all source indexes providing the given package in the specified value.

hash
pipenv
pipfile_spec
requires
set_hash(hash_: dict)[source]

Set hash of Pipfile to make sure pipenv uses correct parts..

sources
to_dict(is_lock: bool = False)[source]

Produce sources as a dict representation as stated in Pipfile/Pipfile.lock.

to_requirements_index_conf() str[source]

Add index configuration as would be stated in the requirements.txt file.

class thoth.python.Project(pipfile: thoth.python.pipfile.Pipfile, pipfile_lock: Optional[thoth.python.pipfile.PipfileLock], runtime_environment: thoth.common.config.runtime_environment.RuntimeEnvironment = NOTHING, constraints: thoth.python.constraints.Constraints = NOTHING, graph_db=None, workdir=None)[source]

Bases: object

A representation of a Python project.

add_package(package_name: str, package_version: Optional[str] = None, *, source: Optional[thoth.python.source.Source] = None, develop: bool = False)[source]

Add the given package to project.

This method will add packages only to Pipfile, locking has to be explicitly done once package is added.

add_source(url: str, verify_ssl: bool = True, name: Optional[str] = None, warehouse: bool = False, warehouse_api_url: Optional[str] = None) thoth.python.source.Source[source]

Add a package source (index) to the project.

check_provenance(whitelisted_sources: Optional[list] = None, digests_fetcher: Optional[thoth.python.digests_fetcher.DigestsFetcherBase] = None) List[source]

Check provenance/origin of packages that are stated in the project.

constraints
construct_requirements_in() str[source]

Construct requirements.in file for the current project.

construct_requirements_txt() str[source]

Construct requirements.txt file for the current project - pip-tools compatible.

exclude_package(package_version: thoth.python.package_version.PackageVersion) None[source]

Exclude the given package from application stack.

classmethod from_dict(pipfile: Dict[str, Any], pipfile_lock: Dict[str, Any], runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None) thoth.python.project.Project[source]

Construct project out of a dict representation.

classmethod from_files(pipfile_path: str, pipfile_lock_path: Optional[str] = None, *, constraints: Optional[thoth.python.constraints.Constraints] = None, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, without_pipfile_lock: bool = False)[source]

Create project from Pipfile and Pipfile.lock files.

classmethod from_package_versions(packages: List[thoth.python.package_version.PackageVersion], packages_locked: Optional[List[thoth.python.package_version.PackageVersion]] = None, meta: Optional[thoth.python.pipfile.PipfileMeta] = None, *, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None)[source]

Create project from PackageVersion objects.

If locked packages are omitted, the lock has to be explicitly performed to generate in-memory Pipfile.lock representation.

classmethod from_pip_compile_files(requirements_path: str = 'requirements.in', requirements_lock_path: Optional[str] = None, allow_without_lock: bool = False, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None) thoth.python.project.Project[source]

Parse project from files compatible with pip/pip-tools.

classmethod from_strings(pipfile_str: str, pipfile_lock_str: Optional[str] = None, *, runtime_environment: Optional[thoth.common.config.runtime_environment.RuntimeEnvironment] = None, constraints: Optional[thoth.python.constraints.Constraints] = None)[source]

Create project from Pipfile and Pipfile.lock loaded into strings.

get_configuration_check_report() Optional[Tuple[Optional[dict], List[dict]]][source]

Get a report on project configuration for the given runtime environment.

get_locked_package_version(package_name: str) Optional[thoth.python.package_version.PackageVersion][source]

Get locked version of the package.

get_outdated_package_versions(devel: bool = True) dict[source]

Get outdated packages in the lock file.

This function will check indexes configured and look for version of each package. If the given package package is not latest, it will add it to the resulting list with the newer version identifier found on package index.

get_package_version(package_name: str) Optional[thoth.python.package_version.PackageVersion][source]

Get locked version of the package.

is_direct_dependency(package_version: thoth.python.package_version.PackageVersion) bool[source]

Check whether the given package is a direct dependency.

iter_dependencies(with_devel: bool = True)[source]

Iterate through direct dependencies of this project (not locked dependencies).

iter_dependencies_locked(with_devel: bool = True)[source]

Iterate through locked dependencies of this project.

pipenv_lock()[source]

Perform pipenv lock on the current state of project.

pipfile
pipfile_lock
property prereleases_allowed: bool

Check if pre-releases are allowed for this project.

property python_version: Optional[str]

Get Python version used in this project.

runtime_environment
sanitize_source_indexes()[source]

Make sure all the indexes are correctly propagated to Pipfile and Pipfile.lock metadata.

set_allow_prereleases(allow_prereleases: bool = True) None[source]

Allow or disallow pre-releases for this project.

set_python_version(python_version: Optional[str] = None) None[source]

Set version of Python used in the project.

to_dict(*, keep_thoth_section: bool = False)[source]

Create a dictionary representation of this project.

to_files(pipfile_path: Optional[str] = None, pipfile_lock_path: Optional[str] = None, *, without_pipfile_lock: bool = False, keep_thoth_section: bool = False) None[source]

Write the current state of project into Pipfile and Pipfile.lock files.

to_pip_compile_files(requirements_path: str = 'requirements.in', requirements_lock_path: str = 'requirements.txt', without_lock: bool = False) None[source]

Write the current state of project into requirements.in and requirements.txt files.

Files created are compatible with pip/pip-tools. If no lock is specified, requirements.txt hold unpinned direct dependencies as in case of pip.

property workdir: str

Access working directory of project.

class thoth.python.PythonDigestsFetcher(sources: List[thoth.python.source.Source])[source]

Bases: thoth.python.digests_fetcher.DigestsFetcherBase

Fetch digests from the given PEP-503 compatible package source index.

fetch_digests(package_name: str, package_version: str) dict[source]

Fetch digests for the given package in specified version from the given package index.

class thoth.python.Source(url: str, name: str = NOTHING, verify_ssl: bool = True, warehouse: bool = NOTHING, warehouse_api_url: Optional[str] = None)[source]

Bases: object

Representation of source (Python index) for Python packages.

default_name()[source]

Create a name for source based on url if not explicitly provided.

classmethod from_dict(dict_: dict)[source]

Parse source from its dictionary representation.

get_api_url()[source]

Construct URL to Warehouse instance.

get_latest_package_version(package_name: str, graceful: bool = False) Optional[Union[packaging.version.Version, packaging.version.LegacyVersion]][source]

Get the latest version for the given package.

get_package_artifacts(package_name: str, package_version: str)[source]

Return list of artifacts corresponding to package name and package version.

get_package_data(package_name: str, package_version: str, with_included_files: bool = False) list[source]

Get information about release hashes and symbols available in this source index.

get_package_hashes(package_name: str, package_version: str, with_included_files: bool = False) list[source]

Get information about release hashes available in this source index.

get_package_release_date(package_name: str, package_version: str) datetime.datetime[source]

Get time at which package was uploaded to package index.

get_package_versions(package_name: str) list[source]

Get listing of versions available for the given package.

get_packages() set[source]

List packages available on the source package index.

get_sorted_package_versions(package_name: str, graceful: bool = False, reverse: bool = True) Optional[List[Union[packaging.version.Version, packaging.version.LegacyVersion]]][source]

Get sorted versions for the given package.

classmethod is_normalized_python_package_name(package_name: str) bool[source]

Check if the given Python package name is normalized.

name
static normalize_package_name(package_name: str) str[source]

Normalize package name on index according to PEP-0503.

provides_package(package_name: str) bool[source]

Check if the given package is provided by this package source index.

provides_package_version(package_name: str, package_version: str) bool[source]

Check if the given source provides package in the given version.

to_dict(include_warehouse: bool = False) dict[source]

Convert source definition to its dict representation.

url
verify_ssl
warehouse
warehouse_api_url
warehouse_default()[source]

Check if the given url is registered in default warehouses.