python.pypi

Attributes

logger

Classes

PyPIError

PyPILink

Link returned by PyPI simple API.

PyPILinksParser

HTML parser to parse links from the PyPI simple API.

PyPI

PyPICandidate

PyPIProvider

Class that should declared to instanciate a resolver (see resolvelib doc).

PyPIClosure

Represent a closure of Python package from PyPI.

Functions

get_pip_env(→ dict[str, str])

Return an environment used by pip to match requirements markers.

fetch_from_registry(→ dict[str, PyPILink])

Fetch packages currently in a registry.

Module Contents

python.pypi.logger
class python.pypi.PyPIError

Bases: e3.error.E3Error

python.pypi.get_pip_env(platform: str, python_version: packaging.version.Version) dict[str, str]

Return an environment used by pip to match requirements markers.

Parameters:
  • platform – a platform (e3 format)

  • python_version – the Python version to consider

Link returned by PyPI simple API.

identifier
url
yanked
require_python = None
has_metadata
_urlparse
checksum
filename
pkg_version
pkg_py_tags
pkg_abi_tags
pkg_platform_tags
property is_yanked: bool

Return True if the package is yanked.

property metadata_url: str

Return the metadata url.

as_dict() dict[str, None | bool | str]

Serialize the a PyPILink into a Python dict that can be dump as json.

classmethod from_dict(data: dict) PyPILink

Transform a generic dict into a PyPILink.

Parameters:

data – the dict to read

class python.pypi.PyPILinksParser(identifier: str)

Bases: html.parser.HTMLParser

HTML parser to parse links from the PyPI simple API.

identifier
handle_starttag(tag: str, attrs: list[tuple[str, str | None]]) None

See HTMLParser doc.

class python.pypi.PyPI(pypi_url: str = 'https://pypi.org/', allowed_yanked: list[str] | None = None, allowed_prerelease: list[str] | None = None, cache_dir: str = 'pypi.cache')
pypi_url = 'https://pypi.org/'
cache_dir = b'.'
cache: dict[str, list[PyPILink]]
candidate_cache: dict[str, list[PyPICandidate]]
property pypi_cache_file: str

Get location of file containing result of pypi requests.

Fetch list of resource for a given Python package.

Parameters:

name – Python package name

Returns:

a list of dict containing the link to each resource along with some metadata

fetch_candidates(identifier: str, env: dict[str, str], extras: set[str]) list[PyPICandidate]

Return a list of candidates for a given package, env and list of extras.

Parameters:
  • identifier – a normalized python package name or internal identifier computed by the provider

  • env – the pip environment required

  • extras – set of needed extras

save_cache() None

Dump cache to disk.

load_cache() None

Load cache from disk.

class python.pypi.PyPICandidate(identifier: str, link: PyPILink, extras: set[str], cache_dir: str)
name
url
is_yanked
has_direct_metadata
extras
cache_dir = b'.'
filename
version
py_tags
abi_tags
platform_tags
_reqs: None | set[packaging.requirements.Requirement] = None
property is_wheel: bool

Check if resource is a wheel.

download() str

Download the file in the PyPI cache.

Returns:

the location of the file

requirements(env: dict[str, str]) set[packaging.requirements.Requirement]

Return the list of requirements for the package.

Parameters:

env – the environment used to evaluate requirements markers

Returns:

a set of Requirement

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

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.

__repr__() str
__str__() str
class python.pypi.PyPIProvider(env: dict[str, str], pypi: PyPI)

Bases: resolvelib.providers.AbstractProvider

Class that should declared to instanciate a resolver (see resolvelib doc).

pypi
env
identify(requirement_or_candidate: packaging.requirements.Requirement | PyPICandidate) str

See resolvelib documentation.

get_preference(identifier: str, resolutions: collections.abc.Mapping[str, PyPICandidate], candidates: collections.abc.Mapping[str, collections.abc.Iterator[PyPICandidate]], information: collections.abc.Mapping[Any, collections.abc.Iterator[resolvelib.resolvers.RequirementInformation[Any, Any]]], backtrack_causes: collections.abc.Sequence[resolvelib.resolvers.RequirementInformation]) resolvelib.providers.Preference

See resolvelib documentation.

find_matches(identifier: str, requirements: collections.abc.Mapping[str, collections.abc.Iterator[packaging.requirements.Requirement]], incompatibilities: collections.abc.Mapping[str, collections.abc.Iterator[PyPICandidate]]) resolvelib.structs.Matches

Return the list of candidates that match a given list of requirements.

is_satisfied_by(requirement: packaging.requirements.Requirement, candidate: PyPICandidate) bool

See resolvelib documentation.

get_dependencies(candidate: PyPICandidate) collections.abc.Iterable[packaging.requirements.Requirement]

See resolvelib documentation.

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

Represent a closure of Python package from PyPI.

pypi
requirements: set[packaging.requirements.Requirement]
allowed_prerelease = []
allowed_yanked = []
platforms
python3_version
add_wheel(filename: str) None

Introduce a local wheel into the closure.

add_requirement(req: str | packaging.requirements.Requirement) None

Add a requirement in the closure.

file_closure() list[str]
_requirements_closure() dict
requirements_closure() list[packaging.requirements.Requirement]

Get the closure of requirements.

Returns:

return a list of requirement that can be used as a lock file

__enter__() PyPIClosure
__exit__(_type: type[BaseException] | None, _val: BaseException | None, _tb: types.TracebackType | None) None
python.pypi.fetch_from_registry(packages: collections.abc.Iterable[str], registry_url: str, *, log_missing_packages: bool = False) dict[str, PyPILink]

Fetch packages currently in a registry.

Parameters:
  • packages – The list of packages to look for.

  • registry_url – The URL to a python registry to use. If the protocol is not defined on the URL, https will be used by default.

Returns:

A filename to link mapping (dict).