Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.metadata Namespace Reference

Namespaces

 
 
 
 

Data Structures

class  Backend
 

Functions

bool _should_use_importlib_metadata ()
 
Backend select_backend ()
 
BaseEnvironment get_default_environment ()
 
BaseEnvironment get_environment (Optional[List[str]] paths)
 
BaseDistribution get_directory_distribution (str directory)
 
BaseDistribution get_wheel_distribution (Wheel wheel, str canonical_name)
 
BaseDistribution get_metadata_distribution (bytes metadata_contents, str filename, str canonical_name)
 

Variables

 Protocol = object
 

Function Documentation

◆ _should_use_importlib_metadata()

bool _should_use_importlib_metadata ( )
protected
Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.

By default, pip uses ``importlib.metadata`` on Python 3.11+, and
``pkg_resourcess`` otherwise. This can be overridden by a couple of ways:

* If environment variable ``_PIP_USE_IMPORTLIB_METADATA`` is set, it
  dictates whether ``importlib.metadata`` is used, regardless of Python
  version.
* On Python 3.11+, Python distributors can patch ``importlib.metadata``
  to add a global constant ``_PIP_USE_IMPORTLIB_METADATA = False``. This
  makes pip use ``pkg_resources`` (unless the user set the aforementioned
  environment variable to *True*).

Definition at line 29 of file __init__.py.

29def _should_use_importlib_metadata() -> bool:
30 """Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.
31
32 By default, pip uses ``importlib.metadata`` on Python 3.11+, and
33 ``pkg_resourcess`` otherwise. This can be overridden by a couple of ways:
34
35 * If environment variable ``_PIP_USE_IMPORTLIB_METADATA`` is set, it
36 dictates whether ``importlib.metadata`` is used, regardless of Python
37 version.
38 * On Python 3.11+, Python distributors can patch ``importlib.metadata``
39 to add a global constant ``_PIP_USE_IMPORTLIB_METADATA = False``. This
40 makes pip use ``pkg_resources`` (unless the user set the aforementioned
41 environment variable to *True*).
42 """
43 with contextlib.suppress(KeyError, ValueError):
44 return bool(strtobool(os.environ["_PIP_USE_IMPORTLIB_METADATA"]))
45 if sys.version_info < (3, 11):
46 return False
48
49 return bool(getattr(importlib.metadata, "_PIP_USE_IMPORTLIB_METADATA", True))
50
51
for i

References i.

Referenced by pip._internal.metadata.select_backend().

Here is the caller graph for this function:

◆ get_default_environment()

BaseEnvironment get_default_environment ( )
Get the default representation for the current environment.

This returns an Environment instance from the chosen backend. The default
Environment instance should be built from ``sys.path`` and may use caching
to share instance state accorss calls.

Definition at line 68 of file __init__.py.

68def get_default_environment() -> BaseEnvironment:
69 """Get the default representation for the current environment.
70
71 This returns an Environment instance from the chosen backend. The default
72 Environment instance should be built from ``sys.path`` and may use caching
73 to share instance state accorss calls.
74 """
75 return select_backend().Environment.default()
76
77

References i, and pip._internal.metadata.select_backend().

Here is the call graph for this function:

◆ get_directory_distribution()

BaseDistribution get_directory_distribution ( str  directory)
Get the distribution metadata representation in the specified directory.

This returns a Distribution instance from the chosen backend based on
the given on-disk ``.dist-info`` directory.

Definition at line 88 of file __init__.py.

88def get_directory_distribution(directory: str) -> BaseDistribution:
89 """Get the distribution metadata representation in the specified directory.
90
91 This returns a Distribution instance from the chosen backend based on
92 the given on-disk ``.dist-info`` directory.
93 """
94 return select_backend().Distribution.from_directory(directory)
95
96

References i, and pip._internal.metadata.select_backend().

Here is the call graph for this function:

◆ get_environment()

BaseEnvironment get_environment ( Optional[List[str]]  paths)
Get a representation of the environment specified by ``paths``.

This returns an Environment instance from the chosen backend based on the
given import paths. The backend must build a fresh instance representing
the state of installed distributions when this function is called.

Definition at line 78 of file __init__.py.

78def get_environment(paths: Optional[List[str]]) -> BaseEnvironment:
79 """Get a representation of the environment specified by ``paths``.
80
81 This returns an Environment instance from the chosen backend based on the
82 given import paths. The backend must build a fresh instance representing
83 the state of installed distributions when this function is called.
84 """
85 return select_backend().Environment.from_paths(paths)
86
87

References i, and pip._internal.metadata.select_backend().

Here is the call graph for this function:

◆ get_metadata_distribution()

BaseDistribution get_metadata_distribution ( bytes  metadata_contents,
str  filename,
str  canonical_name 
)
Get the dist representation of the specified METADATA file contents.

This returns a Distribution instance from the chosen backend sourced from the data
in `metadata_contents`.

:param metadata_contents: Contents of a METADATA file within a dist, or one served
                          via PEP 658.
:param filename: Filename for the dist this metadata represents.
:param canonical_name: Normalized project name of the given dist.

Definition at line 108 of file __init__.py.

112) -> BaseDistribution:
113 """Get the dist representation of the specified METADATA file contents.
114
115 This returns a Distribution instance from the chosen backend sourced from the data
116 in `metadata_contents`.
117
118 :param metadata_contents: Contents of a METADATA file within a dist, or one served
119 via PEP 658.
120 :param filename: Filename for the dist this metadata represents.
121 :param canonical_name: Normalized project name of the given dist.
122 """
123 return select_backend().Distribution.from_metadata_file_contents(
124 metadata_contents,
125 filename,
126 canonical_name,
127 )

References i, and pip._internal.metadata.select_backend().

Here is the call graph for this function:

◆ get_wheel_distribution()

BaseDistribution get_wheel_distribution ( Wheel  wheel,
str  canonical_name 
)
Get the representation of the specified wheel's distribution metadata.

This returns a Distribution instance from the chosen backend based on
the given wheel's ``.dist-info`` directory.

:param canonical_name: Normalized project name of the given wheel.

Definition at line 97 of file __init__.py.

97def get_wheel_distribution(wheel: Wheel, canonical_name: str) -> BaseDistribution:
98 """Get the representation of the specified wheel's distribution metadata.
99
100 This returns a Distribution instance from the chosen backend based on
101 the given wheel's ``.dist-info`` directory.
102
103 :param canonical_name: Normalized project name of the given wheel.
104 """
105 return select_backend().Distribution.from_wheel(wheel, canonical_name)
106
107

References i, and pip._internal.metadata.select_backend().

Here is the call graph for this function:

◆ select_backend()

Backend select_backend ( )

Definition at line 58 of file __init__.py.

58def select_backend() -> Backend:
59 if _should_use_importlib_metadata():
60 from . import importlib
61
62 return cast(Backend, importlib)
63 from . import pkg_resources
64
65 return cast(Backend, pkg_resources)
66
67

References pip._internal.metadata._should_use_importlib_metadata().

Referenced by pip._internal.metadata.get_default_environment(), pip._internal.metadata.get_directory_distribution(), pip._internal.metadata.get_environment(), pip._internal.metadata.get_metadata_distribution(), and pip._internal.metadata.get_wheel_distribution().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ Protocol

Protocol = object

Definition at line 14 of file __init__.py.