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

Public Member Functions

 __init__ (self, location=None, metadata=None, project_name=None, version=None, py_version=PY_MAJOR, platform=None, precedence=EGG_DIST)
 
 from_location (cls, location, basename, metadata=None, **kw)
 
 hashcmp (self)
 
 __hash__ (self)
 
 __lt__ (self, other)
 
 __le__ (self, other)
 
 __gt__ (self, other)
 
 __ge__ (self, other)
 
 __eq__ (self, other)
 
 __ne__ (self, other)
 
 key (self)
 
 parsed_version (self)
 
 version (self)
 
 requires (self, extras=())
 
 activate (self, path=None, replace=False)
 
 egg_name (self)
 
 __repr__ (self)
 
 __str__ (self)
 
 __getattr__ (self, attr)
 
 __dir__ (self)
 
 from_filename (cls, filename, metadata=None, **kw)
 
 as_requirement (self)
 
 load_entry_point (self, group, name)
 
 get_entry_map (self, group=None)
 
 get_entry_info (self, group, name)
 
 insert_on (self, path, loc=None, replace=False)
 
 check_version_conflict (self)
 
 has_version (self)
 
 clone (self, **kw)
 
 extras (self)
 

Data Fields

 project_name
 
 py_version
 
 platform
 
 location
 
 precedence
 
 key
 
 hashcmp
 
 PKG_INFO
 
 version
 
 parsed_version
 

Static Public Attributes

str PKG_INFO = 'PKG-INFO'
 

Protected Member Functions

 _reload_version (self)
 
 _forgiving_parsed_version (self)
 
 _dep_map (self)
 
 _build_dep_map (self)
 
 _get_metadata_path_for_display (self, name)
 
 _get_metadata (self, name)
 
 _get_version (self)
 

Static Protected Member Functions

 _filter_extras (dm)
 

Protected Attributes

 _version
 
 _provider
 
 _forgiving_parsed_version
 
 _key
 
 _parsed_version
 

Detailed Description

Wrap an actual or potential sys.path entry w/metadata

Definition at line 2629 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  location = None,
  metadata = None,
  project_name = None,
  version = None,
  py_version = PY_MAJOR,
  platform = None,
  precedence = EGG_DIST 
)

Definition at line 2634 of file __init__.py.

2643 ):
2644 self.project_name = safe_name(project_name or 'Unknown')
2645 if version is not None:
2646 self._version = safe_version(version)
2647 self.py_version = py_version
2648 self.platform = platform
2649 self.location = location
2650 self.precedence = precedence
2651 self._provider = metadata or empty_provider
2652

Referenced by Protocol.__init_subclass__().

Here is the caller graph for this function:

Member Function Documentation

◆ __dir__()

__dir__ (   self)

Definition at line 2905 of file __init__.py.

2905 def __dir__(self):
2906 return list(
2907 set(super(Distribution, self).__dir__())
2908 | set(attr for attr in self._provider.__dir__() if not attr.startswith('_'))
2909 )
2910
for i

◆ __eq__()

__eq__ (   self,
  other 
)

Definition at line 2704 of file __init__.py.

2704 def __eq__(self, other):
2705 if not isinstance(other, self.__class__):
2706 # It's not a Distribution, so they are not equal
2707 return False
2708 return self.hashcmp == other.hashcmp
2709

Referenced by Version.__ge__(), Version.__gt__(), Version.__le__(), Version.__ne__(), Matcher.__ne__(), Timestamp.__ne__(), and HTTPHeaderDict.__ne__().

Here is the caller graph for this function:

◆ __ge__()

__ge__ (   self,
  other 
)

Definition at line 2701 of file __init__.py.

2701 def __ge__(self, other):
2702 return self.hashcmp >= other.hashcmp
2703

◆ __getattr__()

__getattr__ (   self,
  attr 
)
Delegate all unrecognized public attributes to .metadata provider

Definition at line 2899 of file __init__.py.

2899 def __getattr__(self, attr):
2900 """Delegate all unrecognized public attributes to .metadata provider"""
2901 if attr.startswith('_'):
2902 raise AttributeError(attr)
2903 return getattr(self._provider, attr)
2904

◆ __gt__()

__gt__ (   self,
  other 
)

Definition at line 2698 of file __init__.py.

2698 def __gt__(self, other):
2699 return self.hashcmp > other.hashcmp
2700

Referenced by Version.__ge__().

Here is the caller graph for this function:

◆ __hash__()

__hash__ (   self)

Definition at line 2689 of file __init__.py.

2689 def __hash__(self):
2690 return hash(self.hashcmp)
2691

Referenced by Style.__eq__(), and Style.__ne__().

Here is the caller graph for this function:

◆ __le__()

__le__ (   self,
  other 
)

Definition at line 2695 of file __init__.py.

2695 def __le__(self, other):
2696 return self.hashcmp <= other.hashcmp
2697

◆ __lt__()

__lt__ (   self,
  other 
)

Definition at line 2692 of file __init__.py.

2692 def __lt__(self, other):
2693 return self.hashcmp < other.hashcmp
2694

Referenced by Version.__gt__(), and Version.__le__().

Here is the caller graph for this function:

◆ __ne__()

__ne__ (   self,
  other 
)

Definition at line 2710 of file __init__.py.

2710 def __ne__(self, other):
2711 return not self == other
2712

◆ __repr__()

__repr__ (   self)

Definition at line 2885 of file __init__.py.

2885 def __repr__(self):
2886 if self.location:
2887 return "%s (%s)" % (self, self.location)
2888 else:
2889 return str(self)
2890

◆ __str__()

__str__ (   self)

Definition at line 2891 of file __init__.py.

2891 def __str__(self):
2892 try:
2893 version = getattr(self, 'version', None)
2894 except ValueError:
2895 version = None
2896 version = version or "[unknown version]"
2897 return "%s %s" % (self.project_name, version)
2898

◆ _build_dep_map()

_build_dep_map (   self)
protected

Definition at line 2813 of file __init__.py.

2813 def _build_dep_map(self):
2814 dm = {}
2815 for name in 'requires.txt', 'depends.txt':
2816 for extra, reqs in split_sections(self._get_metadata(name)):
2817 dm.setdefault(extra, []).extend(parse_requirements(reqs))
2818 return dm
2819

◆ _dep_map()

_dep_map (   self)
protected
A map of extra to its list of (direct) requirements
for this distribution, including the null extra.

Reimplemented in DistInfoDistribution.

Definition at line 2781 of file __init__.py.

2781 def _dep_map(self):
2782 """
2783 A map of extra to its list of (direct) requirements
2784 for this distribution, including the null extra.
2785 """
2786 try:
2787 return self.__dep_map
2788 except AttributeError:
2789 self.__dep_map = self._filter_extras(self._build_dep_map())
2790 return self.__dep_map
2791

◆ _filter_extras()

_filter_extras (   dm)
staticprotected
Given a mapping of extras to dependencies, strip off
environment markers and filter out any dependencies
not matching the markers.

Definition at line 2793 of file __init__.py.

2793 def _filter_extras(dm):
2794 """
2795 Given a mapping of extras to dependencies, strip off
2796 environment markers and filter out any dependencies
2797 not matching the markers.
2798 """
2799 for extra in list(filter(None, dm)):
2800 new_extra = extra
2801 reqs = dm.pop(extra)
2802 new_extra, _, marker = extra.partition(':')
2803 fails_marker = marker and (
2804 invalid_marker(marker) or not evaluate_marker(marker)
2805 )
2806 if fails_marker:
2807 reqs = []
2808 new_extra = safe_extra(new_extra) or None
2809
2810 dm.setdefault(new_extra, []).extend(reqs)
2811 return dm
2812

◆ _forgiving_parsed_version()

_forgiving_parsed_version (   self)
protected

Definition at line 2740 of file __init__.py.

2740 def _forgiving_parsed_version(self):
2741 try:
2742 return self.parsed_version
2744 self._parsed_version = parse_version(_forgiving_version(self.version))
2745
2746 notes = "\n".join(getattr(ex, "__notes__", [])) # PEP 678
2747 msg = f"""!!\n\n
2748 *************************************************************************
2749 {str(ex)}\n{notes}
2750
2751 This is a long overdue deprecation.
2752 For the time being, `pkg_resources` will use `{self._parsed_version}`
2753 as a replacement to avoid breaking existing environments,
2754 but no future compatibility is guaranteed.
2755
2756 If you maintain package {self.project_name} you should implement
2757 the relevant changes to adequate the project to PEP 440 immediately.
2758 *************************************************************************
2759 \n\n!!
2760 """
2761 warnings.warn(msg, DeprecationWarning)
2762
2763 return self._parsed_version
2764

◆ _get_metadata()

_get_metadata (   self,
  name 
)
protected

Definition at line 2851 of file __init__.py.

2851 def _get_metadata(self, name):
2852 if self.has_metadata(name):
2853 for line in self.get_metadata_lines(name):
2854 yield line
2855

◆ _get_metadata_path_for_display()

_get_metadata_path_for_display (   self,
  name 
)
protected
Return the path to the given metadata file, if available.

Definition at line 2834 of file __init__.py.

2834 def _get_metadata_path_for_display(self, name):
2835 """
2836 Return the path to the given metadata file, if available.
2837 """
2838 try:
2839 # We need to access _get_metadata_path() on the provider object
2840 # directly rather than through this class's __getattr__()
2841 # since _get_metadata_path() is marked private.
2842 path = self._provider._get_metadata_path(name)
2843
2844 # Handle exceptions e.g. in case the distribution's metadata
2845 # provider doesn't support _get_metadata_path().
2846 except Exception:
2847 return '[could not detect]'
2848
2849 return path
2850

◆ _get_version()

_get_version (   self)
protected

Definition at line 2856 of file __init__.py.

2856 def _get_version(self):
2857 lines = self._get_metadata(self.PKG_INFO)
2858 version = _version_from_file(lines)
2859
2860 return version
2861

◆ _reload_version()

_reload_version (   self)
protected

Reimplemented in EggInfoDistribution.

Definition at line 2675 of file __init__.py.

2675 def _reload_version(self):
2676 return self
2677

◆ activate()

activate (   self,
  path = None,
  replace = False 
)
Ensure distribution is importable on `path` (default=sys.path)

Definition at line 2862 of file __init__.py.

2862 def activate(self, path=None, replace=False):
2863 """Ensure distribution is importable on `path` (default=sys.path)"""
2864 if path is None:
2865 path = sys.path
2866 self.insert_on(path, replace=replace)
2867 if path is sys.path:
2868 fixup_namespace_packages(self.location)
2869 for pkg in self._get_metadata('namespace_packages.txt'):
2870 if pkg in sys.modules:
2871 declare_namespace(pkg)
2872

◆ as_requirement()

as_requirement (   self)
Return a ``Requirement`` that matches this distribution exactly

Definition at line 2917 of file __init__.py.

2917 def as_requirement(self):
2918 """Return a ``Requirement`` that matches this distribution exactly"""
2919 if isinstance(self.parsed_version, packaging.version.Version):
2920 spec = "%s==%s" % (self.project_name, self.parsed_version)
2921 else:
2922 spec = "%s===%s" % (self.project_name, self.parsed_version)
2923
2924 return Requirement.parse(spec)
2925

◆ check_version_conflict()

check_version_conflict (   self)

Definition at line 3018 of file __init__.py.

3018 def check_version_conflict(self):
3019 if self.key == 'setuptools':
3020 # ignore the inevitable setuptools self-conflicts :(
3021 return
3022
3023 nsp = dict.fromkeys(self._get_metadata('namespace_packages.txt'))
3024 loc = normalize_path(self.location)
3025 for modname in self._get_metadata('top_level.txt'):
3026 if (
3027 modname not in sys.modules
3028 or modname in nsp
3029 or modname in _namespace_packages
3030 ):
3031 continue
3032 if modname in ('pkg_resources', 'setuptools', 'site'):
3033 continue
3034 fn = getattr(sys.modules[modname], '__file__', None)
3035 if fn and (
3036 normalize_path(fn).startswith(loc) or fn.startswith(self.location)
3037 ):
3038 continue
3039 issue_warning(
3040 "Module %s was already imported from %s, but %s is being added"
3041 " to sys.path" % (modname, fn, self.location),
3042 )
3043

◆ clone()

clone (   self,
**  kw 
)
Copy this distribution, substituting in any changed keyword args

Definition at line 3055 of file __init__.py.

3055 def clone(self, **kw):
3056 """Copy this distribution, substituting in any changed keyword args"""
3057 names = 'project_name version py_version platform location precedence'
3058 for attr in names.split():
3059 kw.setdefault(attr, getattr(self, attr, None))
3060 kw.setdefault('metadata', self._provider)
3061 return self.__class__(**kw)
3062

◆ egg_name()

egg_name (   self)
Return what this distribution's standard .egg filename should be

Definition at line 2873 of file __init__.py.

2873 def egg_name(self):
2874 """Return what this distribution's standard .egg filename should be"""
2875 filename = "%s-%s-py%s" % (
2876 to_filename(self.project_name),
2877 to_filename(self.version),
2878 self.py_version or PY_MAJOR,
2879 )
2880
2881 if self.platform:
2882 filename += '-' + self.platform
2883 return filename
2884

◆ extras()

extras (   self)

◆ from_filename()

from_filename (   cls,
  filename,
  metadata = None,
**  kw 
)

Definition at line 2912 of file __init__.py.

2912 def from_filename(cls, filename, metadata=None, **kw):
2913 return cls.from_location(
2914 _normalize_cached(filename), os.path.basename(filename), metadata, **kw
2915 )
2916

◆ from_location()

from_location (   cls,
  location,
  basename,
  metadata = None,
**  kw 
)

Definition at line 2654 of file __init__.py.

2654 def from_location(cls, location, basename, metadata=None, **kw):
2655 project_name, version, py_version, platform = [None] * 4
2656 basename, ext = os.path.splitext(basename)
2657 if ext.lower() in _distributionImpl:
2658 cls = _distributionImpl[ext.lower()]
2659
2660 match = EGG_NAME(basename)
2661 if match:
2662 project_name, version, py_version, platform = match.group(
2663 'name', 'ver', 'pyver', 'plat'
2664 )
2665 return cls(
2666 location,
2667 metadata,
2668 project_name=project_name,
2669 version=version,
2670 py_version=py_version,
2671 platform=platform,
2672 **kw,
2673 )._reload_version()
2674

◆ get_entry_info()

get_entry_info (   self,
  group,
  name 
)
Return the EntryPoint object for `group`+`name`, or ``None``

Definition at line 2945 of file __init__.py.

2945 def get_entry_info(self, group, name):
2946 """Return the EntryPoint object for `group`+`name`, or ``None``"""
2947 return self.get_entry_map(group).get(name)
2948

◆ get_entry_map()

get_entry_map (   self,
  group = None 
)
Return the entry point map for `group`, or the full entry map

Definition at line 2933 of file __init__.py.

2933 def get_entry_map(self, group=None):
2934 """Return the entry point map for `group`, or the full entry map"""
2935 try:
2936 ep_map = self._ep_map
2937 except AttributeError:
2938 ep_map = self._ep_map = EntryPoint.parse_map(
2939 self._get_metadata('entry_points.txt'), self
2940 )
2941 if group is not None:
2942 return ep_map.get(group, {})
2943 return ep_map
2944

◆ has_version()

has_version (   self)

Definition at line 3044 of file __init__.py.

3044 def has_version(self):
3045 try:
3046 self.version
3047 except ValueError:
3048 issue_warning("Unbuilt egg for " + repr(self))
3049 return False
3050 except SystemError:
3051 # TODO: remove this except clause when python/cpython#103632 is fixed.
3052 return False
3053 return True
3054

◆ hashcmp()

hashcmp (   self)

Definition at line 2679 of file __init__.py.

2679 def hashcmp(self):
2680 return (
2681 self._forgiving_parsed_version,
2682 self.precedence,
2683 self.key,
2684 self.location,
2685 self.py_version or '',
2686 self.platform or '',
2687 )
2688

◆ insert_on()

insert_on (   self,
  path,
  loc = None,
  replace = False 
)
Ensure self.location is on path

If replace=False (default):
    - If location is already in path anywhere, do nothing.
    - Else:
      - If it's an egg and its parent directory is on path,
        insert just ahead of the parent.
      - Else: add to the end of path.
If replace=True:
    - If location is already on path anywhere (not eggs)
      or higher priority than its parent (eggs)
      do nothing.
    - Else:
      - If it's an egg and its parent directory is on path,
        insert just ahead of the parent,
        removing any lower-priority entries.
      - Else: add it to the front of path.

Definition at line 2950 of file __init__.py.

2950 def insert_on(self, path, loc=None, replace=False): # noqa: C901
2951 """Ensure self.location is on path
2952
2953 If replace=False (default):
2954 - If location is already in path anywhere, do nothing.
2955 - Else:
2956 - If it's an egg and its parent directory is on path,
2957 insert just ahead of the parent.
2958 - Else: add to the end of path.
2959 If replace=True:
2960 - If location is already on path anywhere (not eggs)
2961 or higher priority than its parent (eggs)
2962 do nothing.
2963 - Else:
2964 - If it's an egg and its parent directory is on path,
2965 insert just ahead of the parent,
2966 removing any lower-priority entries.
2967 - Else: add it to the front of path.
2968 """
2969
2970 loc = loc or self.location
2971 if not loc:
2972 return
2973
2974 nloc = _normalize_cached(loc)
2975 bdir = os.path.dirname(nloc)
2976 npath = [(p and _normalize_cached(p) or p) for p in path]
2977
2978 for p, item in enumerate(npath):
2979 if item == nloc:
2980 if replace:
2981 break
2982 else:
2983 # don't modify path (even removing duplicates) if
2984 # found and not replace
2985 return
2986 elif item == bdir and self.precedence == EGG_DIST:
2987 # if it's an .egg, give it precedence over its directory
2988 # UNLESS it's already been added to sys.path and replace=False
2989 if (not replace) and nloc in npath[p:]:
2990 return
2991 if path is sys.path:
2992 self.check_version_conflict()
2993 path.insert(p, loc)
2994 npath.insert(p, nloc)
2995 break
2996 else:
2997 if path is sys.path:
2998 self.check_version_conflict()
2999 if replace:
3000 path.insert(0, loc)
3001 else:
3002 path.append(loc)
3003 return
3004
3005 # p is the spot where we found or inserted loc; now remove duplicates
3006 while True:
3007 try:
3008 np = npath.index(nloc, p + 1)
3009 except ValueError:
3010 break
3011 else:
3012 del npath[np], path[np]
3013 # ha!
3014 p = np
3015
3016 return
3017

◆ key()

key (   self)

Definition at line 2718 of file __init__.py.

2718 def key(self):
2719 try:
2720 return self._key
2721 except AttributeError:
2722 self._key = key = self.project_name.lower()
2723 return key
2724

Referenced by Matcher.__eq__(), Matcher.__hash__(), and SelfCheckState.set().

Here is the caller graph for this function:

◆ load_entry_point()

load_entry_point (   self,
  group,
  name 
)
Return the `name` entry point of `group` or raise ImportError

Definition at line 2926 of file __init__.py.

2926 def load_entry_point(self, group, name):
2927 """Return the `name` entry point of `group` or raise ImportError"""
2928 ep = self.get_entry_info(group, name)
2929 if ep is None:
2930 raise ImportError("Entry point %r not found" % ((group, name),))
2931 return ep.load()
2932

◆ parsed_version()

parsed_version (   self)

Definition at line 2726 of file __init__.py.

2726 def parsed_version(self):
2727 if not hasattr(self, "_parsed_version"):
2728 try:
2729 self._parsed_version = parse_version(self.version)
2731 info = f"(package: {self.project_name})"
2732 if hasattr(ex, "add_note"):
2733 ex.add_note(info) # PEP 678
2734 raise
2735 raise packaging.version.InvalidVersion(f"{str(ex)} {info}") from None
2736
2737 return self._parsed_version
2738

◆ requires()

requires (   self,
  extras = () 
)
List of Requirements needed for this distro if `extras` are used

Definition at line 2820 of file __init__.py.

2820 def requires(self, extras=()):
2821 """List of Requirements needed for this distro if `extras` are used"""
2822 dm = self._dep_map
2823 deps = []
2824 deps.extend(dm.get(None, ()))
2825 for ext in extras:
2826 try:
2827 deps.extend(dm[safe_extra(ext)])
2828 except KeyError as e:
2829 raise UnknownExtra(
2830 "%s has no such extra feature %r" % (self, ext)
2831 ) from e
2832 return deps
2833

◆ version()

version (   self)

Definition at line 2766 of file __init__.py.

2766 def version(self):
2767 try:
2768 return self._version
2769 except AttributeError as e:
2770 version = self._get_version()
2771 if version is None:
2772 path = self._get_metadata_path_for_display(self.PKG_INFO)
2773 msg = ("Missing 'Version:' header and/or {} file at path: {}").format(
2774 self.PKG_INFO, path
2775 )
2776 raise ValueError(msg, self) from e
2777
2778 return version
2779

Referenced by AlreadyInstalledCandidate.__eq__(), Distribution.__eq__(), Distribution.__hash__(), InstallationCandidate.__repr__(), Distribution.__repr__(), Metadata.__repr__(), InstallationCandidate.__str__(), InstalledDistribution.__str__(), EggInfoDistribution.__str__(), PlatformDirsABC._append_app_name_and_version(), WrappedSocket._custom_validate(), Wheel._get_extensions(), Wheel.build(), Wheel.filename(), InstalledDistribution.get_distinfo_file(), Wheel.get_wheel_metadata(), LinuxDistribution.info(), Wheel.install(), LinuxDistribution.linux_distribution(), Wheel.metadata(), LinuxDistribution.name(), Distribution.name_and_version(), Distribution.provides(), Metadata.provides(), Wheel.update(), Wheel.verify(), and LinuxDistribution.version_parts().

Here is the caller graph for this function:

Field Documentation

◆ _forgiving_parsed_version

_forgiving_parsed_version
protected

Definition at line 2681 of file __init__.py.

◆ _key

◆ _parsed_version

_parsed_version
protected

Definition at line 2729 of file __init__.py.

◆ _provider

_provider
protected

Definition at line 2651 of file __init__.py.

◆ _version

◆ hashcmp

hashcmp

Definition at line 2690 of file __init__.py.

◆ key

key

Definition at line 2683 of file __init__.py.

Referenced by Matcher.__eq__(), Matcher.__hash__(), and SelfCheckState.set().

◆ location

◆ parsed_version

parsed_version

Definition at line 2919 of file __init__.py.

◆ PKG_INFO [1/2]

str PKG_INFO = 'PKG-INFO'
static

Definition at line 2632 of file __init__.py.

◆ PKG_INFO [2/2]

PKG_INFO

Definition at line 2774 of file __init__.py.

◆ platform

platform

Definition at line 2648 of file __init__.py.

◆ precedence

precedence

Definition at line 2650 of file __init__.py.

◆ project_name

◆ py_version

py_version

Definition at line 2647 of file __init__.py.

◆ version


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