python.pypi

Module Contents

Classes

PackageFile

A release package file as represented in PyPI.

Package

PyPIClosure

Represent a closure of Python package from PyPI.

Attributes

logger

PLATFORM_SYSTEMS

python.pypi.logger
python.pypi.PLATFORM_SYSTEMS
exception python.pypi.PyPIError(message: str | list[str], origin: str | None = None)

Bases: e3.error.E3Error

Exception raised by functions defined in E3.

class python.pypi.PackageFile(pypi: PyPIClosure, *, data: dict[str, Any])

A release package file as represented in PyPI.

property kind: str

Return the package kind.

property filename: str

Return the package filename.

property url: str

Return the download url.

property is_yanked: bool

Return whether the package is yanked.

property is_wheel: bool

Return whether the package is a wheel.

property is_generic_wheel: bool

Return whether the package is a generic package.

If True then the wheel can be used on any Python 3.x version and on any platform.

property requirements: set[pkg_resources.Requirement]

Return the list of requirements for the package.

Only dependencies for wheels can be tracked.

is_compatible_with_platforms(platform_list: list[str]) bool

Check if the package is compatible with a list of platform.

Parameters:

platform_list – a list of platform name in e3 format (x86_64-linux, …)

Returns:

True if the package is compatible with any of the platform

is_compatible_with_cpython3(minor_version: int) bool

Check whether the package is compatible with a given python 3 version.

Parameters:

minor_version – to check compatibility with 3.10 set this param to 10

Returns:

True if compatible

download() str

Download the file in the PyPI cache.

Returns:

the location of the file

class python.pypi.Package(pypi: PyPIClosure, *, data: dict[str, Any])
property as_requirement: list[pkg_resources.Requirement]

Return a list of requirement string for the package.

property name: str

Name of the package.

property latest_release: list[PackageFile]

Return the latest release files.

property has_generic_wheel: bool

Return whether a generic wheel exists.

property latest_release_requirements: set[pkg_resources.Requirement]

Return the requirements for the latest release.

property latest_version: str

Return the latest version as str.

__eq__(other: Any) bool

Return self==value.

__hash__() int

Return hash(self).

closure(state: set[Package] | None = None) set[Package]

Return package closure.

Parameters:

state – an initial set of packages (internal parameter)

Returns:

the closure of Packages associated with the most recent suitable release.

file_closure() set[str]

Return file closure for the package.

add_constraint(requirement: pkg_resources.Requirement) None

Apply a new constraint to this package.

The effect is mainly to remove versions of the current package that do not match the constraint. PyPIError is raised in case no version is available

Parameters:

requirement – a requirement to apply

__str__() str

Return str(self).

class python.pypi.PyPIClosure(*, python3_version: int, platforms: list[str], cache_dir: str, cache_file: str | None = None, pypi_url: str = 'https://pypi.org/pypi', allowed_prerelease: list[str] | None = None, allowed_yanked: list[str] | None = None)

Represent a closure of Python package from PyPI.

__enter__() PyPIClosure
__exit__(_type: type[BaseException] | None, _val: BaseException | None, _tb: types.TracebackType | None) None
pkg(pkg: str, extras: list[str] | None = None) Package

Fetch all metadata from PyPI for a given package.

Parameters:
  • pkg – the package name

  • extras – list of extras to consider for the package. For example if you need e3-core[test] extras should be set to [“test”]. None all extras for a given package are ignored.

Returns:

a Package object

add_wheel(filename: str) None

Add manually a wheel to the local PyPI database.

Parameters:

filename – path to the wheel

closure() set[Package]

Return the full Package closure.

Returns:

a set of Package object.

file_closure() set[str]

Return the file closure.

Returns:

a list of paths

closure_as_requirements() list[pkg_resources.Requirement]

Return the list of frozen requirements for the closure.

Returns:

a list of Requirements

add_requirement(req: pkg_resources.Requirement | str, explicit: bool = True) Package

Add a requirement to the closure.

Parameters:
  • req – a python requirement

  • explicit – whether it is an explicit requirement or not (False value is used only internally)

Returns:

a Package

load_cache_file() None

Load cache information.

save_cache_file() None

Save cache to file.