MCPcopy Index your code
hub / github.com/python/cpython / Distribution

Class Distribution

Lib/importlib/metadata/__init__.py:399–739  ·  view source on GitHub ↗

An abstract Python distribution package. Custom providers may derive from this class and define the abstract methods to provide a concrete implementation for their environment. Some providers may opt to override the default implementation of some properties to bypass the fi

Source from the content-addressed store, hash-verified

397
398
399class Distribution(metaclass=abc.ABCMeta):
400 """
401 An abstract Python distribution package.
402
403 Custom providers may derive from this class and define
404 the abstract methods to provide a concrete implementation
405 for their environment. Some providers may opt to override
406 the default implementation of some properties to bypass
407 the file-reading mechanism.
408 """
409
410 @abc.abstractmethod
411 def read_text(self, filename) -> str | None:
412 """Attempt to load metadata file given by the name.
413
414 Python distribution metadata is organized by blobs of text
415 typically represented as "files" in the metadata directory
416 (e.g. package-1.0.dist-info). These files include things
417 like:
418
419 - METADATA: The distribution metadata including fields
420 like Name and Version and Description.
421 - entry_points.txt: A series of entry points as defined in
422 `the entry points spec <https://packaging.python.org/en/latest/specifications/entry-points/#file-format>`_.
423 - RECORD: A record of files according to
424 `this recording spec <https://packaging.python.org/en/latest/specifications/recording-installed-packages/#the-record-file>`_.
425
426 A package may provide any set of files, including those
427 not listed here or none at all.
428
429 :param filename: The name of the file in the distribution info.
430 :return: The text if found, otherwise None.
431 """
432
433 @abc.abstractmethod
434 def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
435 """
436 Given a path to a file in this distribution, return a SimplePath
437 to it.
438
439 This method is used by callers of ``Distribution.files()`` to
440 locate files within the distribution. If it&#x27;s possible for a
441 Distribution to represent files in the distribution as
442 ``SimplePath`` objects, it should implement this method
443 to resolve such objects.
444
445 Some Distribution providers may elect not to resolve SimplePath
446 objects within the distribution by raising a
447 NotImplementedError, but consumers of such a Distribution would
448 be unable to invoke ``Distribution.files()``.
449 """
450
451 @classmethod
452 def from_name(cls, name: str) -> Distribution:
453 """Return the Distribution for the given package name.
454
455 :param name: The name of the distribution package to search for.
456 :return: The Distribution instance (or subclass thereof) for the named

Callers 1

compile_c_extensionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…