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.
-
class
thoth.python.aiosource.
AsyncIterableArtifacts
(artifacts: List[Tuple[str, str]])[source]¶ Bases:
object
Async Iterator for Artifacts.
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.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
¶
-
classmethod
thoth.python.digests_fetcher module¶
Fetching package artifact digests.
-
class
thoth.python.digests_fetcher.
DigestsFetcherBase
[source]¶ Bases:
object
A base class implementing digests fetching.
-
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.
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.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: 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
¶
-
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
¶
-
property
locked_version
¶ Retrieve locked version of the package.
-
markers
¶
-
name
¶
-
classmethod
normalize_python_package_name
(package_name: str) → str[source]¶ Normalize Python package name based on PEP-0503.
-
classmethod
normalize_python_package_version
(package_version: str) → str[source]¶ Normalize Python package version based on PEP-440.
-
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
¶ 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_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
¶ Get version base.
-
property
dev
¶ Get version dev.
-
property
epoch
¶ Get version epoch.
-
property
is_devrelease
¶ Check if version is a dev-release.
-
property
is_legacy_version
¶ Check if the given version is a legacy version identifier.
-
property
is_postrelease
¶ Check if version is a post-release.
-
property
is_prerelease
¶ Check if version is a pre-release.
-
property
local
¶ Get version local.
-
property
major
¶ Get version major release.
-
property
micro
¶ Get version micro release.
-
property
minor
¶ Get version minor release.
-
property
post
¶ Get version post.
-
property
pre
¶ Get version pre.
-
property
public
¶ Get version public.
-
property
release
¶ Get version release.
-
property
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.
-
packages
¶
-
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.
-
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: 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.
-
thoth
¶
-
-
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: 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: thoth.python.pipfile.Pipfile = None) → dict[source]¶ Create a dict representation of Pipfile.lock content.
-
classmethod
-
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.
-
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
¶
-
sources
¶
-
classmethod
-
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
¶
-
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: 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) → List[source]¶ Check provenance/origin of packages that are stated in the project.
-
constraints
¶
-
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: 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: 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.
-
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.
-
to_dict
(*, keep_thoth_section: bool = False)[source]¶ Create a dictionary representation of this project.
-
to_files
(pipfile_path: str = None, pipfile_lock_path: 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
¶ 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.
-
get_latest_package_version
(package_name: str, graceful: bool = False) → Union[packaging.version.Version, packaging.version.LegacyVersion, None][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_release_date
(package_name: str, package_version: str) → datetime.datetime[source]¶ Get time at which package was uploaded to 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
¶
-
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.
-
class
thoth.python.
AsyncIterableArtifacts
(artifacts: List[Tuple[str, str]])[source]¶ Bases:
object
Async Iterator for Artifacts.
-
class
thoth.python.
AsyncIterablePackages
(_packages: Set[str])[source]¶ Bases:
object
Async Iterator for Packages.
-
class
thoth.python.
AsyncIterableVersions
(_versions: Set[str])[source]¶ Bases:
object
Async Iterator for Versions.
-
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
¶
-
classmethod
-
class
thoth.python.
DigestsFetcherBase
[source]¶ Bases:
object
A base class implementing digests fetching.
-
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.
-
packages
¶
-
-
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: 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
¶
-
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
¶
-
property
locked_version
¶ Retrieve locked version of the package.
-
markers
¶
-
name
¶
-
classmethod
normalize_python_package_name
(package_name: str) → str[source]¶ Normalize Python package name based on PEP-0503.
-
classmethod
normalize_python_package_version
(package_version: str) → str[source]¶ Normalize Python package version based on PEP-440.
-
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
¶ 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_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.
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.
-
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: 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.
-
thoth
¶
-
-
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: 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: thoth.python.pipfile.Pipfile = None) → dict[source]¶ Create a dict representation of Pipfile.lock content.
-
classmethod
-
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.
-
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
¶
-
sources
¶
-
classmethod
-
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: 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) → List[source]¶ Check provenance/origin of packages that are stated in the project.
-
constraints
¶
-
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: 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: 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.
-
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.
-
to_dict
(*, keep_thoth_section: bool = False)[source]¶ Create a dictionary representation of this project.
-
to_files
(pipfile_path: str = None, pipfile_lock_path: 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
¶ 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.
-
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.
-
get_latest_package_version
(package_name: str, graceful: bool = False) → Union[packaging.version.Version, packaging.version.LegacyVersion, None][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_release_date
(package_name: str, package_version: str) → datetime.datetime[source]¶ Get time at which package was uploaded to 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
¶
-