thoth.python package

Submodules

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: str = None, dir_name: str = None, verify_ssl: bool = False, sha: 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.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.DirectDependencyRemoval[source]

Bases: thoth.python.exceptions.ThothPythonException

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.InternalError[source]

Bases: thoth.python.exceptions.ThothPythonException

An exception raised on bugs in the code base.

exception thoth.python.exceptions.NotFound[source]

Bases: thoth.python.exceptions.ThothPythonException

Raised if the given artifact cannot be found.

exception thoth.python.exceptions.PipfileParseError[source]

Bases: thoth.python.exceptions.ThothPythonException

An exception raised on invalid Pipfile or Pipfile.lock.

exception thoth.python.exceptions.ThothPythonException[source]

Bases: Exception

A base class for thoth-python exceptions.

exception thoth.python.exceptions.UnableLock[source]

Bases: thoth.python.exceptions.ThothPythonException

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

exception thoth.python.exceptions.UnsupportedConfiguration[source]

Bases: thoth.python.exceptions.ThothPythonException

Raised on unsupported configuration options.

exception thoth.python.exceptions.VersionIdentifierError[source]

Bases: thoth.python.exceptions.ThothPythonException

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: thoth.python.project.Project) → thoth.python.project.Project[source]

Temporary fill package digests stated in Pipfile.lock.

thoth.python.package_version module

Representation of packages in the application stack.

class thoth.python.package_version.PackageVersion(name, version: str, develop: bool, index: thoth.python.source.Source = None, hashes=NOTHING, markers: str = None, semantic_version: semantic_version.base.Version = None, version_spec: semantic_version.base.Spec = 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.

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

Convert database model representation to object representation.

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

Construct PackageVersion instance from representation as stated in Pipfile.

classmethod from_pipfile_lock_entry(package_name: str, entry: dict, develop: bool, meta: PipenvMeta)[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

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

static parse_semantic_version(version_identifier: str, _package_name: str = None) → semantic_version.base.Version[source]

Parse the given version identifier into a semver representation.

property semantic_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[source]

Return a tuple representing this Python package.

to_tuple_locked() → tuple[source]

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

version
property version_specification

Retrieve version specification based on specified version.

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)[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: dict, dev_packages: dict, meta: thoth.python.pipfile.PipfileMeta)[source]

Bases: thoth.python.pipfile._PipfileBase

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

property data

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

classmethod from_dict(dict_)[source]

Retrieve instance of Pipfile from its dictionary representation.

classmethod from_file(file_path: str = None)[source]

Parse Pipfile file and return its Pipfile representation.

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

Construct Pipfile from provided PackageVersion instances.

classmethod from_string(pipfile_content: str)[source]

Parse Pipfile from its string representation.

hash()[source]

Compute hash of Pipifile.

to_dict() → dict[source]

Return Pipfile representation as dict.

to_file() → None[source]

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

to_string() → str[source]

Convert representation of Pipfile to actual Pipfile file content.

class thoth.python.pipfile.PipfileLock(packages: dict, dev_packages: dict, meta: thoth.python.pipfile.PipfileMeta, pipfile: 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: thoth.python.pipfile.Pipfile)[source]

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

classmethod from_file(file_path: str = None, pipfile: thoth.python.pipfile.Pipfile = None)[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: thoth.python.pipfile.PipfileMeta = None)[source]

Construct Pipfile from provided PackageVersion instances.

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

Parse Pipfile.lock from its string content.

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

Create a dict representation of Pipfile.lock content.

to_file(pipfile: thoth.python.pipfile.Pipfile = None) → None[source]

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

to_string(pipfile: 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, requires: dict, pipenv: dict, hash: dict, pipfile_spec: int)[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_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.

thoth.python.project module

Project abstraction and operations on project dependencies.

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

Bases: object

A representation of a Python project.

add_package(package_name: str, package_version: str = None, *, source: 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: str = None, warehouse: bool = False, warehouse_api_url: str = None) → thoth.python.source.Source[source]

Add a package source (index) to the project.

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

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

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

Exclude the given package from application stack.

classmethod from_files(pipfile_path: str = None, pipfile_lock_path: str = None, *, runtime_environment: 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: List[thoth.python.package_version.PackageVersion] = None, meta: thoth.python.pipfile.PipfileMeta = 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_strings(pipfile_str: str, pipfile_lock_str: str = None, *, runtime_environment: thoth.common.config.runtime_environment.RuntimeEnvironment = None)[source]

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

get_configuration_check_report() → Optional[Tuple[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

Check if pre-releases are allowed for this project.

property python_version

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: str = None) → None[source]

Set version of Python used in the project.

test_indexes_in_meta()[source]

Check indexes being adjusted when inserting a new package.

to_dict()[source]

Create a dictionary representation of this project.

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

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

property workdir

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: 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[semantic_version.base.Version][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[source]

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

get_package_hashes[source]

Get information about release hashes available in this source index.

get_package_versions[source]

Get listing of versions available for the given package.

get_packages[source]

List packages available on the source package index.

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_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.

Module contents

Python ecosystem specific routines.