Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
BaseDistribution Class Reference
Inheritance diagram for BaseDistribution:
Collaboration diagram for BaseDistribution:

Public Member Functions

"BaseDistribution" from_directory (cls, str directory)
 
"BaseDistribution" from_metadata_file_contents (cls, bytes metadata_contents, str filename, str project_name)
 
"BaseDistribution" from_wheel (cls, "Wheel" wheel, str name)
 
str __repr__ (self)
 
str __str__ (self)
 
Optional[str] location (self)
 
Optional[str] editable_project_location (self)
 
Optional[str] installed_location (self)
 
Optional[str] info_location (self)
 
bool installed_by_distutils (self)
 
bool installed_as_egg (self)
 
bool installed_with_setuptools_egg_info (self)
 
bool installed_with_dist_info (self)
 
NormalizedName canonical_name (self)
 
DistributionVersion version (self)
 
str setuptools_filename (self)
 
Optional[DirectUrldirect_url (self)
 
str installer (self)
 
bool requested (self)
 
bool editable (self)
 
bool local (self)
 
bool in_usersite (self)
 
bool in_site_packages (self)
 
bool is_file (self, InfoPath path)
 
Iterator[str] iter_distutils_script_names (self)
 
str read_text (self, InfoPath path)
 
Iterable[BaseEntryPointiter_entry_points (self)
 
email.message.Message metadata (self)
 
Dict[str, Any] metadata_dict (self)
 
Optional[str] metadata_version (self)
 
str raw_name (self)
 
SpecifierSet requires_python (self)
 
Iterable[Requirementiter_dependencies (self, Collection[str] extras=())
 
Iterable[str] iter_provided_extras (self)
 
Optional[Iterator[str]] iter_declared_entries (self)
 

Data Fields

 canonical_name
 
 editable_project_location
 
 installed_location
 
 metadata
 
 raw_name
 

Protected Member Functions

email.message.Message _metadata_impl (self)
 
email.message.Message _metadata_cached (self)
 
Optional[Iterator[str]] _iter_declared_entries_from_record (self)
 
Optional[Iterator[str]] _iter_declared_entries_from_legacy (self)
 
Iterator[RequiresEntry_iter_requires_txt_entries (self)
 
Iterable[str] _iter_egg_info_extras (self)
 
Iterable[str] _iter_egg_info_dependencies (self)
 
None _add_egg_info_requires (self, email.message.Message metadata)
 

Detailed Description

Definition at line 107 of file base.py.

Member Function Documentation

◆ __repr__()

str __repr__ (   self)

Definition at line 148 of file base.py.

148 def __repr__(self) -> str:
149 return f"{self.raw_name} {self.version} ({self.location})"
150

◆ __str__()

str __str__ (   self)

Definition at line 151 of file base.py.

151 def __str__(self) -> str:
152 return f"{self.raw_name} {self.version}"
153

◆ _add_egg_info_requires()

None _add_egg_info_requires (   self,
email.message.Message  metadata 
)
protected
Add egg-info requires.txt information to the metadata.

Definition at line 572 of file base.py.

572 def _add_egg_info_requires(self, metadata: email.message.Message) -> None:
573 """Add egg-info requires.txt information to the metadata."""
574 if not metadata.get_all("Requires-Dist"):
575 for dep in self._iter_egg_info_dependencies():
576 metadata["Requires-Dist"] = dep
577 if not metadata.get_all("Provides-Extra"):
578 for extra in self._iter_egg_info_extras():
579 metadata["Provides-Extra"] = extra
580
581
for i

References BaseDistribution._iter_egg_info_dependencies(), BaseDistribution._iter_egg_info_extras(), and i.

Referenced by BaseDistribution._metadata_cached().

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

◆ _iter_declared_entries_from_legacy()

Optional[Iterator[str]] _iter_declared_entries_from_legacy (   self)
protected

Definition at line 474 of file base.py.

474 def _iter_declared_entries_from_legacy(self) -> Optional[Iterator[str]]:
475 try:
476 text = self.read_text("installed-files.txt")
477 except FileNotFoundError:
478 return None
479 paths = (p for p in text.splitlines(keepends=False) if p)
480 root = self.location
481 info = self.info_location
482 if root is None or info is None:
483 return paths
484 try:
485 info_rel = pathlib.Path(info).relative_to(root)
486 except ValueError: # info is not relative to root.
487 return paths
488 if not info_rel.parts: # info *is* root.
489 return paths
490 return (
491 _convert_installed_files_path(pathlib.Path(p).parts, info_rel.parts)
492 for p in paths
493 )
494

References pip._internal.metadata.base._convert_installed_files_path(), i, BaseDistribution.info_location(), WheelDistribution.info_location, Distribution.info_location(), _PackageInfo.location, InvalidWheel.location, BaseDistribution.location(), Wheel.location, FilesystemWheel.location, MemoryWheel.location, Distribution.location(), Distribution.location, LocationParseError.location, BaseDistribution.read_text(), Distribution.read_text(), and WheelDistribution.read_text().

Referenced by BaseDistribution.iter_declared_entries().

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

◆ _iter_declared_entries_from_record()

Optional[Iterator[str]] _iter_declared_entries_from_record (   self)
protected

Definition at line 466 of file base.py.

466 def _iter_declared_entries_from_record(self) -> Optional[Iterator[str]]:
467 try:
468 text = self.read_text("RECORD")
469 except FileNotFoundError:
470 return None
471 # This extra Path-str cast normalizes entries.
472 return (str(pathlib.Path(row[0])) for row in csv.reader(text.splitlines()))
473

References i, BaseDistribution.read_text(), Distribution.read_text(), and WheelDistribution.read_text().

Referenced by BaseDistribution.iter_declared_entries().

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

◆ _iter_egg_info_dependencies()

Iterable[str] _iter_egg_info_dependencies (   self)
protected
Get distribution dependencies from the egg-info directory.

To ease parsing, this converts a legacy dependency entry into a PEP 508
requirement string. Like ``_iter_requires_txt_entries()``, there is code
in ``importlib.metadata`` that does mostly the same, but not do exactly
what we need.

Namely, ``importlib.metadata`` does not normalize the extra name before
putting it into the requirement string, which causes marker comparison
to fail because the dist-info format do normalize. This is consistent in
all currently available PEP 517 backends, although not standardized.

Definition at line 545 of file base.py.

545 def _iter_egg_info_dependencies(self) -> Iterable[str]:
546 """Get distribution dependencies from the egg-info directory.
547
548 To ease parsing, this converts a legacy dependency entry into a PEP 508
549 requirement string. Like ``_iter_requires_txt_entries()``, there is code
550 in ``importlib.metadata`` that does mostly the same, but not do exactly
551 what we need.
552
553 Namely, ``importlib.metadata`` does not normalize the extra name before
554 putting it into the requirement string, which causes marker comparison
555 to fail because the dist-info format do normalize. This is consistent in
556 all currently available PEP 517 backends, although not standardized.
557 """
558 for entry in self._iter_requires_txt_entries():
560 marker = f'({entry.marker}) and extra == "{safe_extra(entry.extra)}"'
561 elif entry.extra:
562 marker = f'extra == "{safe_extra(entry.extra)}"'
563 elif entry.marker:
564 marker = entry.marker
565 else:
566 marker = ""
567 if marker:
568 yield f"{entry.requirement} ; {marker}"
569 else:
571

References BaseDistribution._iter_requires_txt_entries(), and i.

Referenced by BaseDistribution._add_egg_info_requires().

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

◆ _iter_egg_info_extras()

Iterable[str] _iter_egg_info_extras (   self)
protected
Get extras from the egg-info directory.

Definition at line 536 of file base.py.

536 def _iter_egg_info_extras(self) -> Iterable[str]:
537 """Get extras from the egg-info directory."""
538 known_extras = {""}
539 for entry in self._iter_requires_txt_entries():
540 if entry.extra in known_extras:
541 continue
543 yield entry.extra
544

References BaseDistribution._iter_requires_txt_entries(), and i.

Referenced by BaseDistribution._add_egg_info_requires().

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

◆ _iter_requires_txt_entries()

Iterator[RequiresEntry] _iter_requires_txt_entries (   self)
protected
Parse a ``requires.txt`` in an egg-info directory.

This is an INI-ish format where an egg-info stores dependencies. A
section name describes extra other environment markers, while each entry
is an arbitrary string (not a key-value pair) representing a dependency
as a requirement string (no markers).

There is a construct in ``importlib.metadata`` called ``Sectioned`` that
does mostly the same, but the format is currently considered private.

Definition at line 511 of file base.py.

511 def _iter_requires_txt_entries(self) -> Iterator[RequiresEntry]:
512 """Parse a ``requires.txt`` in an egg-info directory.
513
514 This is an INI-ish format where an egg-info stores dependencies. A
515 section name describes extra other environment markers, while each entry
516 is an arbitrary string (not a key-value pair) representing a dependency
517 as a requirement string (no markers).
518
519 There is a construct in ``importlib.metadata`` called ``Sectioned`` that
520 does mostly the same, but the format is currently considered private.
521 """
522 try:
523 content = self.read_text("requires.txt")
524 except FileNotFoundError:
525 return
526 extra = marker = "" # Section-less entries don't have markers.
527 for line in content.splitlines():
528 line = line.strip()
529 if not line or line.startswith("#"): # Comment; ignored.
530 continue
531 if line.startswith("[") and line.endswith("]"): # A section header.
532 extra, _, marker = line.strip("[]").partition(":")
533 continue
534 yield RequiresEntry(requirement=line, extra=extra, marker=marker)
535

References i, BaseDistribution.read_text(), Distribution.read_text(), and WheelDistribution.read_text().

Referenced by BaseDistribution._iter_egg_info_dependencies(), and BaseDistribution._iter_egg_info_extras().

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

◆ _metadata_cached()

email.message.Message _metadata_cached (   self)
protected

Definition at line 390 of file base.py.

390 def _metadata_cached(self) -> email.message.Message:
391 # When we drop python 3.7 support, move this to the metadata property and use
392 # functools.cached_property instead of lru_cache.
393 metadata = self._metadata_impl()
394 self._add_egg_info_requires(metadata)
395 return metadata
396

References BaseDistribution._add_egg_info_requires(), BaseDistribution._metadata_impl(), and Distribution._metadata_impl().

Referenced by BaseDistribution.metadata().

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

◆ _metadata_impl()

email.message.Message _metadata_impl (   self)
protected

Reimplemented in Distribution, and Distribution.

Definition at line 386 of file base.py.

386 def _metadata_impl(self) -> email.message.Message:
387 raise NotImplementedError()
388

References i.

Referenced by BaseDistribution._metadata_cached().

Here is the caller graph for this function:

◆ canonical_name()

NormalizedName canonical_name (   self)

Reimplemented in Distribution, and Distribution.

Definition at line 279 of file base.py.

279 def canonical_name(self) -> NormalizedName:
280 raise NotImplementedError()
281

References i.

Referenced by BaseDistribution.raw_name().

Here is the caller graph for this function:

◆ direct_url()

Optional[DirectUrl] direct_url (   self)
Obtain a DirectUrl from this distribution.

Returns None if the distribution has no `direct_url.json` metadata,
or if `direct_url.json` is invalid.

Definition at line 295 of file base.py.

295 def direct_url(self) -> Optional[DirectUrl]:
296 """Obtain a DirectUrl from this distribution.
297
298 Returns None if the distribution has no `direct_url.json` metadata,
299 or if `direct_url.json` is invalid.
300 """
301 try:
302 content = self.read_text(DIRECT_URL_METADATA_NAME)
303 except FileNotFoundError:
304 return None
305 try:
306 return DirectUrl.from_json(content)
307 except (
308 UnicodeDecodeError,
310 DirectUrlValidationError,
311 ) as e:
313 "Error parsing %s for %s: %s",
314 DIRECT_URL_METADATA_NAME,
315 self.canonical_name,
316 e,
317 )
318 return None
319

References i, BaseDistribution.read_text(), Distribution.read_text(), and WheelDistribution.read_text().

Referenced by BaseDistribution.editable_project_location().

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

◆ editable()

bool editable (   self)

Definition at line 337 of file base.py.

337 def editable(self) -> bool:
338 return bool(self.editable_project_location)
339

Referenced by InstallRequirement.__repr__(), FrozenRequirement.__str__(), DirInfo._to_dict(), InstallRequirement.install(), InstallRequirement.isolated_editable_sanity_check(), InstallRequirement.prepare_metadata(), and InstallRequirement.update_editable().

Here is the caller graph for this function:

◆ editable_project_location()

Optional[str] editable_project_location (   self)
The project location for editable distributions.

This is the directory where pyproject.toml or setup.py is located.
None if the distribution is not installed in editable mode.

Definition at line 169 of file base.py.

169 def editable_project_location(self) -> Optional[str]:
170 """The project location for editable distributions.
171
172 This is the directory where pyproject.toml or setup.py is located.
173 None if the distribution is not installed in editable mode.
174 """
175 # TODO: this property is relatively costly to compute, memoize it ?
176 direct_url = self.direct_url
177 if direct_url:
179 return url_to_path(direct_url.url)
180 else:
181 # Search for an .egg-link file by walking sys.path, as it was
182 # done before by dist_is_editable().
183 egg_link_path = egg_link_path_from_sys_path(self.raw_name)
184 if egg_link_path:
185 # TODO: get project location from second line of egg_link file
186 # (https://github.com/pypa/pip/issues/10243)
187 return self.location
188 return None
189

References BaseDistribution.direct_url(), i, _PackageInfo.location, InvalidWheel.location, BaseDistribution.location(), Wheel.location, FilesystemWheel.location, MemoryWheel.location, Distribution.location(), Distribution.location, LocationParseError.location, BaseDistribution.raw_name(), and BaseDistribution.raw_name.

Here is the call graph for this function:

◆ from_directory()

"BaseDistribution" from_directory (   cls,
str  directory 
)
Load the distribution from a metadata directory.

:param directory: Path to a metadata directory, e.g. ``.dist-info``.

Reimplemented in Distribution, and Distribution.

Definition at line 109 of file base.py.

109 def from_directory(cls, directory: str) -> "BaseDistribution":
110 """Load the distribution from a metadata directory.
111
112 :param directory: Path to a metadata directory, e.g. ``.dist-info``.
113 """
114 raise NotImplementedError()
115

References i.

◆ from_metadata_file_contents()

"BaseDistribution" from_metadata_file_contents (   cls,
bytes  metadata_contents,
str  filename,
str  project_name 
)
Load the distribution from the contents of a METADATA file.

This is used to implement PEP 658 by generating a "shallow" dist object that can
be used for resolution without downloading or building the actual dist yet.

:param metadata_contents: The contents of a METADATA file.
:param filename: File name for the dist with this metadata.
:param project_name: Name of the project this dist represents.

Reimplemented in Distribution, and Distribution.

Definition at line 117 of file base.py.

122 ) -> "BaseDistribution":
123 """Load the distribution from the contents of a METADATA file.
124
125 This is used to implement PEP 658 by generating a "shallow" dist object that can
126 be used for resolution without downloading or building the actual dist yet.
127
128 :param metadata_contents: The contents of a METADATA file.
129 :param filename: File name for the dist with this metadata.
130 :param project_name: Name of the project this dist represents.
131 """
132 raise NotImplementedError()
133

References i.

◆ from_wheel()

"BaseDistribution" from_wheel (   cls,
"Wheel"  wheel,
str  name 
)
Load the distribution from a given wheel.

:param wheel: A concrete wheel definition.
:param name: File name of the wheel.

:raises InvalidWheel: Whenever loading of the wheel causes a
    :py:exc:`zipfile.BadZipFile` exception to be thrown.
:raises UnsupportedWheel: If the wheel is a valid zip, but malformed
    internally.

Reimplemented in Distribution, and Distribution.

Definition at line 135 of file base.py.

135 def from_wheel(cls, wheel: "Wheel", name: str) -> "BaseDistribution":
136 """Load the distribution from a given wheel.
137
138 :param wheel: A concrete wheel definition.
139 :param name: File name of the wheel.
140
141 :raises InvalidWheel: Whenever loading of the wheel causes a
142 :py:exc:`zipfile.BadZipFile` exception to be thrown.
143 :raises UnsupportedWheel: If the wheel is a valid zip, but malformed
144 internally.
145 """
146 raise NotImplementedError()
147

References i.

◆ in_site_packages()

bool in_site_packages (   self)

Definition at line 357 of file base.py.

357 def in_site_packages(self) -> bool:
358 if self.installed_location is None or site_packages is None:
359 return False
360 return self.installed_location.startswith(normalize_path(site_packages))
361

References i, BaseDistribution.installed_location(), BaseDistribution.installed_location, and Distribution.installed_location().

Here is the call graph for this function:

◆ in_usersite()

bool in_usersite (   self)

Definition at line 351 of file base.py.

351 def in_usersite(self) -> bool:
352 if self.installed_location is None or user_site is None:
353 return False
354 return self.installed_location.startswith(normalize_path(user_site))
355

References i, BaseDistribution.installed_location(), BaseDistribution.installed_location, and Distribution.installed_location().

Here is the call graph for this function:

◆ info_location()

Optional[str] info_location (   self)
Location of the .[egg|dist]-info directory or file.

Similarly to ``location``, a string value is not necessarily a
filesystem path. ``None`` means the distribution is created in-memory.

For a modern .dist-info installation on disk, this should be something
like ``{location}/{raw_name}-{version}.dist-info``.

Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
this is a symbolic link, we want to preserve the relative path between
it and other files in the distribution.

Reimplemented in Distribution, and Distribution.

Definition at line 204 of file base.py.

204 def info_location(self) -> Optional[str]:
205 """Location of the .[egg|dist]-info directory or file.
206
207 Similarly to ``location``, a string value is not necessarily a
208 filesystem path. ``None`` means the distribution is created in-memory.
209
210 For a modern .dist-info installation on disk, this should be something
211 like ``{location}/{raw_name}-{version}.dist-info``.
212
213 Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
214 this is a symbolic link, we want to preserve the relative path between
215 it and other files in the distribution.
216 """
217 raise NotImplementedError()
218

References i.

Referenced by BaseDistribution._iter_declared_entries_from_legacy(), BaseDistribution.installed_by_distutils(), BaseDistribution.installed_with_dist_info(), BaseDistribution.installed_with_setuptools_egg_info(), and WheelDistribution.read_text().

Here is the caller graph for this function:

◆ installed_as_egg()

bool installed_as_egg (   self)
Whether this distribution is installed as an egg.

This usually indicates the distribution was installed by (older versions
of) easy_install.

Definition at line 233 of file base.py.

233 def installed_as_egg(self) -> bool:
234 """Whether this distribution is installed as an egg.
235
236 This usually indicates the distribution was installed by (older versions
237 of) easy_install.
238 """
239 location = self.location
240 if not location:
241 return False
242 return location.endswith(".egg")
243

References i, _PackageInfo.location, InvalidWheel.location, BaseDistribution.location(), Wheel.location, FilesystemWheel.location, MemoryWheel.location, Distribution.location(), Distribution.location, and LocationParseError.location.

Here is the call graph for this function:

◆ installed_by_distutils()

bool installed_by_distutils (   self)
Whether this distribution is installed with legacy distutils format.

A distribution installed with "raw" distutils not patched by setuptools
uses one single file at ``info_location`` to store metadata. We need to
treat this specially on uninstallation.

Reimplemented in Distribution.

Definition at line 220 of file base.py.

220 def installed_by_distutils(self) -> bool:
221 """Whether this distribution is installed with legacy distutils format.
222
223 A distribution installed with "raw" distutils not patched by setuptools
224 uses one single file at ``info_location`` to store metadata. We need to
225 treat this specially on uninstallation.
226 """
227 info_location = self.info_location
228 if not info_location:
229 return False
230 return pathlib.Path(info_location).is_file()
231

References i, BaseDistribution.info_location(), WheelDistribution.info_location, Distribution.info_location(), and BaseDistribution.is_file().

Here is the call graph for this function:

◆ installed_location()

Optional[str] installed_location (   self)
The distribution's "installed" location.

This should generally be a ``site-packages`` directory. This is
usually ``dist.location``, except for legacy develop-installed packages,
where ``dist.location`` is the source code location, and this is where
the ``.egg-link`` file is.

The returned location is normalized (in particular, with symlinks removed).

Reimplemented in Distribution, and Distribution.

Definition at line 191 of file base.py.

191 def installed_location(self) -> Optional[str]:
192 """The distribution's "installed" location.
193
194 This should generally be a ``site-packages`` directory. This is
195 usually ``dist.location``, except for legacy develop-installed packages,
196 where ``dist.location`` is the source code location, and this is where
197 the ``.egg-link`` file is.
198
199 The returned location is normalized (in particular, with symlinks removed).
200 """
201 raise NotImplementedError()
202

References i.

Referenced by BaseDistribution.in_site_packages(), BaseDistribution.in_usersite(), and BaseDistribution.local().

Here is the caller graph for this function:

◆ installed_with_dist_info()

bool installed_with_dist_info (   self)
Whether this distribution is installed with the "modern format".

This indicates a "modern" installation, e.g. storing metadata in the
``.dist-info`` directory. This applies to installations made by
setuptools (but through pip, not directly), or anything using the
standardized build backend interface (PEP 517).

Definition at line 263 of file base.py.

263 def installed_with_dist_info(self) -> bool:
264 """Whether this distribution is installed with the "modern format".
265
266 This indicates a "modern" installation, e.g. storing metadata in the
267 ``.dist-info`` directory. This applies to installations made by
268 setuptools (but through pip, not directly), or anything using the
269 standardized build backend interface (PEP 517).
270 """
271 info_location = self.info_location
272 if not info_location:
273 return False
274 if not info_location.endswith(".dist-info"):
275 return False
276 return pathlib.Path(info_location).is_dir()
277

References i, BaseDistribution.info_location(), WheelDistribution.info_location, and Distribution.info_location().

Here is the call graph for this function:

◆ installed_with_setuptools_egg_info()

bool installed_with_setuptools_egg_info (   self)
Whether this distribution is installed with the ``.egg-info`` format.

This usually indicates the distribution was installed with setuptools
with an old pip version or with ``single-version-externally-managed``.

Note that this ensure the metadata store is a directory. distutils can
also installs an ``.egg-info``, but as a file, not a directory. This
property is *False* for that case. Also see ``installed_by_distutils``.

Definition at line 245 of file base.py.

245 def installed_with_setuptools_egg_info(self) -> bool:
246 """Whether this distribution is installed with the ``.egg-info`` format.
247
248 This usually indicates the distribution was installed with setuptools
249 with an old pip version or with ``single-version-externally-managed``.
250
251 Note that this ensure the metadata store is a directory. distutils can
252 also installs an ``.egg-info``, but as a file, not a directory. This
253 property is *False* for that case. Also see ``installed_by_distutils``.
254 """
255 info_location = self.info_location
256 if not info_location:
257 return False
258 if not info_location.endswith(".egg-info"):
259 return False
260 return pathlib.Path(info_location).is_dir()
261

References i, BaseDistribution.info_location(), WheelDistribution.info_location, and Distribution.info_location().

Here is the call graph for this function:

◆ installer()

str installer (   self)

Definition at line 321 of file base.py.

321 def installer(self) -> str:
322 try:
323 installer_text = self.read_text("INSTALLER")
324 except (OSError, ValueError, NoneMetadataError):
325 return "" # Fail silently if the installer file cannot be read.
326 for line in installer_text.splitlines():
327 cleaned_line = line.strip()
328 if cleaned_line:
329 return cleaned_line
330 return ""
331

References i, BaseDistribution.read_text(), Distribution.read_text(), and WheelDistribution.read_text().

Here is the call graph for this function:

◆ is_file()

bool is_file (   self,
InfoPath  path 
)
Check whether an entry in the info directory is a file.

Reimplemented in Distribution, and Distribution.

Definition at line 362 of file base.py.

362 def is_file(self, path: InfoPath) -> bool:
363 """Check whether an entry in the info directory is a file."""
364 raise NotImplementedError()
365

References i.

Referenced by BaseDistribution.installed_by_distutils(), and BaseDistribution.requested().

Here is the caller graph for this function:

◆ iter_declared_entries()

Optional[Iterator[str]] iter_declared_entries (   self)
Iterate through file entries declared in this distribution.

For modern .dist-info distributions, this is the files listed in the
``RECORD`` metadata file. For legacy setuptools distributions, this
comes from ``installed-files.txt``, with entries normalized to be
compatible with the format used by ``RECORD``.

:return: An iterator for listed entries, or None if the distribution
    contains neither ``RECORD`` nor ``installed-files.txt``.

Definition at line 495 of file base.py.

495 def iter_declared_entries(self) -> Optional[Iterator[str]]:
496 """Iterate through file entries declared in this distribution.
497
498 For modern .dist-info distributions, this is the files listed in the
499 ``RECORD`` metadata file. For legacy setuptools distributions, this
500 comes from ``installed-files.txt``, with entries normalized to be
501 compatible with the format used by ``RECORD``.
502
503 :return: An iterator for listed entries, or None if the distribution
504 contains neither ``RECORD`` nor ``installed-files.txt``.
505 """
506 return (
507 self._iter_declared_entries_from_record()
508 or self._iter_declared_entries_from_legacy()
509 )
510

References BaseDistribution._iter_declared_entries_from_legacy(), and BaseDistribution._iter_declared_entries_from_record().

Here is the call graph for this function:

◆ iter_dependencies()

Iterable[Requirement] iter_dependencies (   self,
Collection[str]   extras = () 
)
Dependencies of this distribution.

For modern .dist-info distributions, this is the collection of
"Requires-Dist:" entries in distribution metadata.

Reimplemented in Distribution, and Distribution.

Definition at line 450 of file base.py.

450 def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]:
451 """Dependencies of this distribution.
452
453 For modern .dist-info distributions, this is the collection of
454 "Requires-Dist:" entries in distribution metadata.
455 """
456 raise NotImplementedError()
457

References i.

◆ iter_distutils_script_names()

Iterator[str] iter_distutils_script_names (   self)
Find distutils 'scripts' entries metadata.

If 'scripts' is supplied in ``setup.py``, distutils records those in the
installed distribution's ``scripts`` directory, a file for each script.

Reimplemented in Distribution, and Distribution.

Definition at line 366 of file base.py.

366 def iter_distutils_script_names(self) -> Iterator[str]:
367 """Find distutils 'scripts' entries metadata.
368
369 If 'scripts' is supplied in ``setup.py``, distutils records those in the
370 installed distribution's ``scripts`` directory, a file for each script.
371 """
372 raise NotImplementedError()
373

References i.

◆ iter_entry_points()

Iterable[BaseEntryPoint] iter_entry_points (   self)

Reimplemented in Distribution, and Distribution.

Definition at line 383 of file base.py.

383 def iter_entry_points(self) -> Iterable[BaseEntryPoint]:
384 raise NotImplementedError()
385

References i.

◆ iter_provided_extras()

Iterable[str] iter_provided_extras (   self)
Extras provided by this distribution.

For modern .dist-info distributions, this is the collection of
"Provides-Extra:" entries in distribution metadata.

Reimplemented in Distribution, and Distribution.

Definition at line 458 of file base.py.

458 def iter_provided_extras(self) -> Iterable[str]:
459 """Extras provided by this distribution.
460
461 For modern .dist-info distributions, this is the collection of
462 "Provides-Extra:" entries in distribution metadata.
463 """
464 raise NotImplementedError()
465

References i.

◆ local()

bool local (   self)
If distribution is installed in the current virtual environment.

Always True if we're not in a virtualenv.

Definition at line 341 of file base.py.

341 def local(self) -> bool:
342 """If distribution is installed in the current virtual environment.
343
344 Always True if we're not in a virtualenv.
345 """
346 if self.installed_location is None:
347 return False
348 return is_local(self.installed_location)
349

References BaseDistribution.installed_location(), BaseDistribution.installed_location, and Distribution.installed_location().

Here is the call graph for this function:

◆ location()

Optional[str] location (   self)
Where the distribution is loaded from.

A string value is not necessarily a filesystem path, since distributions
can be loaded from other sources, e.g. arbitrary zip archives. ``None``
means the distribution is created in-memory.

Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
this is a symbolic link, we want to preserve the relative path between
it and files in the distribution.

Reimplemented in Distribution, and Distribution.

Definition at line 155 of file base.py.

155 def location(self) -> Optional[str]:
156 """Where the distribution is loaded from.
157
158 A string value is not necessarily a filesystem path, since distributions
159 can be loaded from other sources, e.g. arbitrary zip archives. ``None``
160 means the distribution is created in-memory.
161
162 Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
163 this is a symbolic link, we want to preserve the relative path between
164 it and files in the distribution.
165 """
166 raise NotImplementedError()
167

References i.

Referenced by BaseDistribution._iter_declared_entries_from_legacy(), Distribution._metadata_impl(), FilesystemWheel.as_zipfile(), BaseDistribution.editable_project_location(), BaseDistribution.installed_as_egg(), and Distribution.installed_location().

Here is the caller graph for this function:

◆ metadata()

email.message.Message metadata (   self)
Metadata of distribution parsed from e.g. METADATA or PKG-INFO.

This should return an empty message if the metadata file is unavailable.

:raises NoneMetadataError: If the metadata file is available, but does
    not contain valid metadata.

Definition at line 398 of file base.py.

398 def metadata(self) -> email.message.Message:
399 """Metadata of distribution parsed from e.g. METADATA or PKG-INFO.
400
401 This should return an empty message if the metadata file is unavailable.
402
403 :raises NoneMetadataError: If the metadata file is available, but does
404 not contain valid metadata.
405 """
406 return self._metadata_cached()
407

References BaseDistribution._metadata_cached().

Referenced by Distribution._get_requirements(), InstallRequirement._set_requirement(), InstallRequirement.archive(), InstallRequirement.assert_source_matches_version(), Distribution.iter_dependencies(), Distribution.iter_provided_extras(), Distribution.matches_requirement(), BaseDistribution.metadata_version(), Distribution.provides(), BaseDistribution.raw_name(), BaseDistribution.requires_python(), Distribution.source_url(), and InstallRequirement.warn_on_mismatching_name().

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

◆ metadata_dict()

Dict[str, Any] metadata_dict (   self)
PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO.

This should return an empty dict if the metadata file is unavailable.

:raises NoneMetadataError: If the metadata file is available, but does
    not contain valid metadata.

Definition at line 409 of file base.py.

409 def metadata_dict(self) -> Dict[str, Any]:
410 """PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO.
411
412 This should return an empty dict if the metadata file is unavailable.
413
414 :raises NoneMetadataError: If the metadata file is available, but does
415 not contain valid metadata.
416 """
417 return msg_to_json(self.metadata)
418

◆ metadata_version()

Optional[str] metadata_version (   self)
Value of "Metadata-Version:" in distribution metadata, if available.

Definition at line 420 of file base.py.

420 def metadata_version(self) -> Optional[str]:
421 """Value of "Metadata-Version:" in distribution metadata, if available."""
422 return self.metadata.get("Metadata-Version")
423

References BaseDistribution.metadata(), BaseDistribution.metadata, InstallRequirement.metadata(), Distribution.metadata, and Wheel.metadata().

Referenced by LegacyMetadata._remove_line_prefix(), and LegacyMetadata.write_file().

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

◆ raw_name()

str raw_name (   self)
Value of "Name:" in distribution metadata.

Definition at line 425 of file base.py.

425 def raw_name(self) -> str:
426 """Value of "Name:" in distribution metadata."""
427 # The metadata should NEVER be missing the Name: key, but if it somehow
428 # does, fall back to the known canonical name.
429 return self.metadata.get("Name", self.canonical_name)
430

References BaseDistribution.canonical_name(), BaseDistribution.canonical_name, Distribution.canonical_name(), FrozenRequirement.canonical_name, BaseDistribution.metadata(), BaseDistribution.metadata, InstallRequirement.metadata(), Distribution.metadata, and Wheel.metadata().

Referenced by BaseDistribution.editable_project_location(), Distribution.installed_location(), and BaseDistribution.setuptools_filename().

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

◆ read_text()

str read_text (   self,
InfoPath  path 
)
Read a file in the info directory.

:raise FileNotFoundError: If ``path`` does not exist in the directory.
:raise NoneMetadataError: If ``path`` exists in the info directory, but
    cannot be read.

Reimplemented in Distribution, and Distribution.

Definition at line 374 of file base.py.

374 def read_text(self, path: InfoPath) -> str:
375 """Read a file in the info directory.
376
377 :raise FileNotFoundError: If ``path`` does not exist in the directory.
378 :raise NoneMetadataError: If ``path`` exists in the info directory, but
379 cannot be read.
380 """
381 raise NotImplementedError()
382

References i.

Referenced by BaseDistribution._iter_declared_entries_from_legacy(), BaseDistribution._iter_declared_entries_from_record(), BaseDistribution._iter_requires_txt_entries(), Distribution._metadata_impl(), BaseDistribution.direct_url(), and BaseDistribution.installer().

Here is the caller graph for this function:

◆ requested()

bool requested (   self)

Definition at line 333 of file base.py.

333 def requested(self) -> bool:
334 return self.is_file("REQUESTED")
335

References Link.is_file(), BaseDistribution.is_file(), and Distribution.is_file().

Here is the call graph for this function:

◆ requires_python()

SpecifierSet requires_python (   self)
Value of "Requires-Python:" in distribution metadata.

If the key does not exist or contains an invalid value, an empty
SpecifierSet should be returned.

Definition at line 432 of file base.py.

432 def requires_python(self) -> SpecifierSet:
433 """Value of "Requires-Python:" in distribution metadata.
434
435 If the key does not exist or contains an invalid value, an empty
436 SpecifierSet should be returned.
437 """
438 value = self.metadata.get("Requires-Python")
439 if value is None:
440 return SpecifierSet()
441 try:
442 # Convert to str to satisfy the type checker; this can be a Header object.
443 spec = SpecifierSet(str(value))
444 except InvalidSpecifier as e:
445 message = "Package %r has an invalid Requires-Python: %s"
446 logger.warning(message, self.raw_name, e)
447 return SpecifierSet()
448 return spec
449

References BaseDistribution.metadata(), BaseDistribution.metadata, InstallRequirement.metadata(), Distribution.metadata, and Wheel.metadata().

Referenced by Link.__str__().

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

◆ setuptools_filename()

str setuptools_filename (   self)
Convert a project name to its setuptools-compatible filename.

This is a copy of ``pkg_resources.to_filename()`` for compatibility.

Definition at line 287 of file base.py.

287 def setuptools_filename(self) -> str:
288 """Convert a project name to its setuptools-compatible filename.
289
290 This is a copy of ``pkg_resources.to_filename()`` for compatibility.
291 """
292 return self.raw_name.replace("-", "_")
293

References BaseDistribution.raw_name(), and BaseDistribution.raw_name.

Here is the call graph for this function:

◆ version()

Field Documentation

◆ canonical_name

canonical_name

Reimplemented in Distribution, and Distribution.

Definition at line 315 of file base.py.

Referenced by BaseDistribution.raw_name().

◆ editable_project_location

editable_project_location

Definition at line 338 of file base.py.

◆ installed_location

installed_location

◆ metadata

◆ raw_name


The documentation for this class was generated from the following file: