:py:mod:`python.pypi` ===================== .. py:module:: python.pypi .. autoapi-nested-parse:: PyPI package dependency resolution and closure computation. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: python.pypi.PyPILink python.pypi.PyPILinksParser python.pypi.PyPI python.pypi.PyPICandidate python.pypi.PyPIProvider python.pypi.PyPIClosure Functions ~~~~~~~~~ .. autoapisummary:: python.pypi.get_pip_env python.pypi.fetch_from_registry Attributes ~~~~~~~~~~ .. autoapisummary:: python.pypi.logger python.pypi.HTTP_NOT_FOUND .. py:data:: logger .. py:data:: HTTP_NOT_FOUND :value: 404 .. py:exception:: PyPIError(message: str | list[str], origin: str | None = None) Bases: :py:obj:`e3.error.E3Error` Exception raised for PyPI operations errors. .. py:function:: get_pip_env(platform: str, python_version: packaging.version.Version) -> dict[str, str] Return an environment used by pip to match requirements markers. :param platform: a platform (e3 format) :param python_version: the Python version to consider .. py:class:: PyPILink(identifier: str, url: str, yanked: str | None, has_metadata: bool, require_python: str | None = None) Link returned by PyPI simple API. .. py:property:: is_yanked :type: bool Return True if the package is yanked. .. py:property:: metadata_url :type: str Return the metadata url. .. py:method:: as_dict() -> dict[str, None | bool | str] Serialize the a PyPILink into a Python dict that can be dump as json. .. py:method:: from_dict(data: dict) -> PyPILink :classmethod: Transform a generic dict into a PyPILink. :param data: the dict to read .. py:class:: PyPILinksParser(identifier: str, *, ignore_errors: bool = False) Bases: :py:obj:`html.parser.HTMLParser` HTML parser to parse links from the PyPI simple API. .. py:method:: handle_starttag(tag: str, attrs: list[tuple[str, str | None]]) -> None See HTMLParser doc. :param tag: the tag name :param attrs: the tag attributes .. py:class:: PyPI(pypi_url: str = 'https://pypi.org/', allowed_yanked: list[str] | None = None, allowed_prerelease: list[str] | None = None, cache_dir: str = 'pypi.cache') Interface to PyPI Simple API for package discovery and download. .. py:property:: pypi_cache_file :type: str Get location of file containing result of pypi requests. .. py:method:: fetch_project_links(name: str, *, ignore_errors: bool = False) -> list[PyPILink] Fetch list of resource for a given Python package. :param name: Python package name :param ignore_errors: If True, ignore errors while parsing PyPi link. :return: a list of dict containing the link to each resource along with some metadata .. py:method:: 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. :param identifier: a normalized python package name or internal identifier computed by the provider :param env: the pip environment required :param extras: set of needed extras .. py:method:: save_cache() -> None Dump cache to disk. .. py:method:: load_cache() -> None Load cache from disk. .. py:class:: PyPICandidate(identifier: str, link: PyPILink, extras: set[str], cache_dir: str) Represent a PyPI package candidate for installation. .. py:property:: is_wheel :type: bool Check if resource is a wheel. .. py:property:: is_generic_wheel :type: 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. .. py:method:: download() -> str Download the file in the PyPI cache. :return: the location of the file .. py:method:: requirements(env: dict[str, str]) -> set[packaging.requirements.Requirement] Return the list of requirements for the package. :param env: the environment used to evaluate requirements markers :return: a set of Requirement .. py:method:: is_compatible_with_platforms(platform_list: list[str]) -> bool Check if the package is compatible with a list of platform. :param platform_list: a list of platform name in e3 format (x86_64-linux, ...) :return: True if the package is compatible with any of the platform .. py:method:: is_compatible_with_cpython3(minor_version: int) -> bool Check whether the package is compatible with a given python 3 version. :param minor_version: to check compatibility with 3.10 set this param to 10 :return: True if compatible .. py:method:: __repr__() -> str Return representation of Python package. .. py:method:: __str__() -> str Return string representation of Python package. .. py:class:: PyPIProvider(env: dict[str, str], pypi: PyPI) Bases: :py:obj:`resolvelib.providers.AbstractProvider` Class that should declared to instanciate a resolver (see resolvelib doc). .. py:method:: identify(requirement_or_candidate: packaging.requirements.Requirement | PyPICandidate) -> str See resolvelib documentation. :param requirement_or_candidate: a requirement or candidate to identify .. py:method:: 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. :param identifier: package identifier :param resolutions: current resolved packages :param candidates: available candidates :param information: requirement information :param backtrack_causes: causes for backtracking .. py:method:: 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. :param identifier: package identifier :param requirements: requirements to satisfy :param incompatibilities: incompatible candidates .. py:method:: is_satisfied_by(requirement: packaging.requirements.Requirement, candidate: PyPICandidate) -> bool See resolvelib documentation. :param requirement: the requirement to check :param candidate: the candidate to check .. py:method:: get_dependencies(candidate: PyPICandidate) -> collections.abc.Iterable[packaging.requirements.Requirement] See resolvelib documentation. :param candidate: the candidate to get dependencies for .. py:class:: 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. .. py:method:: add_wheel(filename: str) -> None Introduce a local wheel into the closure. :param filename: path to the wheel file .. py:method:: add_requirement(req: str | packaging.requirements.Requirement) -> None Add a requirement in the closure. :param req: requirement to add .. py:method:: file_closure() -> list[str] File closure. .. py:method:: _requirements_closure() -> dict .. py:method:: requirements_closure() -> list[packaging.requirements.Requirement] Get the closure of requirements. :return: return a list of requirement that can be used as a lock file .. py:method:: __enter__() -> typing_extensions.Self Enter context manager for PyPI closure. .. py:method:: __exit__(_type: type[BaseException] | None, _val: BaseException | None, _tb: types.TracebackType | None) -> None Exit context manager. :param _type: exception type :param _val: exception value :param _tb: exception traceback .. py:function:: fetch_from_registry(packages: collections.abc.Iterable[str], registry_url: str, *, log_missing_packages: bool = False, sanitize_packages: collections.abc.Callable[[list[PyPILink]], list[PyPILink]] = lambda x: x) -> dict[str, PyPILink] Fetch packages currently in a registry. :param packages: The list of packages to look for. :param 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. :param log_missing_packages: if True, log missing packages as errors :param sanitize_packages: function to sanitize the list of package links :return: A filename to link mapping (dict).