Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
Environment Class Reference

Public Member Functions

 __init__ (self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR)
 
 can_add (self, dist)
 
 remove (self, dist)
 
 scan (self, search_path=None)
 
 __getitem__ (self, project_name)
 
 add (self, dist)
 
 best_match (self, req, working_set, installer=None, replace_conflicting=False)
 
 obtain (self, requirement, installer=None)
 
 __iter__ (self)
 
 __iadd__ (self, other)
 
 __add__ (self, other)
 

Data Fields

 platform
 
 python
 

Protected Attributes

 _distmap
 

Detailed Description

Searchable snapshot of distributions on a search path

Definition at line 1031 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  search_path = None,
  platform = get_supported_platform(),
  python = PY_MAJOR 
)
Snapshot distributions available on a search path

Any distributions found on `search_path` are added to the environment.
`search_path` should be a sequence of ``sys.path`` items.  If not
supplied, ``sys.path`` is used.

`platform` is an optional string specifying the name of the platform
that platform-specific distributions must be compatible with.  If
unspecified, it defaults to the current platform.  `python` is an
optional string naming the desired version of Python (e.g. ``'3.6'``);
it defaults to the current version.

You may explicitly set `platform` (and/or `python`) to ``None`` if you
wish to map *all* distributions, not just those compatible with the
running platform or Python version.

Definition at line 1034 of file __init__.py.

1036 ):
1037 """Snapshot distributions available on a search path
1038
1039 Any distributions found on `search_path` are added to the environment.
1040 `search_path` should be a sequence of ``sys.path`` items. If not
1041 supplied, ``sys.path`` is used.
1042
1043 `platform` is an optional string specifying the name of the platform
1044 that platform-specific distributions must be compatible with. If
1045 unspecified, it defaults to the current platform. `python` is an
1046 optional string naming the desired version of Python (e.g. ``'3.6'``);
1047 it defaults to the current version.
1048
1049 You may explicitly set `platform` (and/or `python`) to ``None`` if you
1050 wish to map *all* distributions, not just those compatible with the
1051 running platform or Python version.
1052 """
1053 self._distmap = {}
1054 self.platform = platform
1055 self.python = python
1056 self.scan(search_path)
1057

Referenced by Protocol.__init_subclass__().

Here is the caller graph for this function:

Member Function Documentation

◆ __add__()

__add__ (   self,
  other 
)
Add an environment or distribution to an environment

Definition at line 1167 of file __init__.py.

1167 def __add__(self, other):
1168 """Add an environment or distribution to an environment"""
1169 new = self.__class__([], platform=None, python=None)
1170 for env in self, other:
1171 new += env
1172 return new
1173
1174
1175# XXX backward compatibility

Referenced by wait_base.__radd__().

Here is the caller graph for this function:

◆ __getitem__()

__getitem__ (   self,
  project_name 
)
Return a newest-to-oldest list of distributions for `project_name`

Uses case-insensitive `project_name` comparison, assuming all the
project's distributions use their project's name converted to all
lowercase as their key.

Definition at line 1091 of file __init__.py.

1091 def __getitem__(self, project_name):
1092 """Return a newest-to-oldest list of distributions for `project_name`
1093
1094 Uses case-insensitive `project_name` comparison, assuming all the
1095 project's distributions use their project's name converted to all
1096 lowercase as their key.
1097
1098 """
1099 distribution_key = project_name.lower()
1100 return self._distmap.get(distribution_key, [])
1101
for i

◆ __iadd__()

__iadd__ (   self,
  other 
)
In-place addition of a distribution or environment

Definition at line 1155 of file __init__.py.

1155 def __iadd__(self, other):
1156 """In-place addition of a distribution or environment"""
1157 if isinstance(other, Distribution):
1158 self.add(other)
1159 elif isinstance(other, Environment):
1160 for project in other:
1161 for dist in other[project]:
1162 self.add(dist)
1163 else:
1164 raise TypeError("Can't add %r to environment" % (other,))
1165 return self
1166

Referenced by ParseResults.extend().

Here is the caller graph for this function:

◆ __iter__()

__iter__ (   self)
Yield the unique project names of the available distributions

Definition at line 1149 of file __init__.py.

1149 def __iter__(self):
1150 """Yield the unique project names of the available distributions"""
1151 for key in self._distmap.keys():
1152 if self[key]:
1153 yield key
1154

◆ add()

add (   self,
  dist 
)
Add `dist` if we ``can_add()`` it and it has not already been added

Definition at line 1102 of file __init__.py.

1102 def add(self, dist):
1103 """Add `dist` if we ``can_add()`` it and it has not already been added"""
1104 if self.can_add(dist) and dist.has_version():
1105 dists = self._distmap.setdefault(dist.key, [])
1106 if dist not in dists:
1107 dists.append(dist)
1108 dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
1109

Referenced by UninstallPathSet.add(), Manifest.add_many(), HTTPHeaderDict.extend(), and BuildTracker.track().

Here is the caller graph for this function:

◆ best_match()

best_match (   self,
  req,
  working_set,
  installer = None,
  replace_conflicting = False 
)
Find distribution best matching `req` and usable on `working_set`

This calls the ``find(req)`` method of the `working_set` to see if a
suitable distribution is already active.  (This may raise
``VersionConflict`` if an unsuitable version of the project is already
active in the specified `working_set`.)  If a suitable distribution
isn't active, this method returns the newest distribution in the
environment that meets the ``Requirement`` in `req`.  If no suitable
distribution is found, and `installer` is supplied, then the result of
calling the environment's ``obtain(req, installer)`` method will be
returned.

Definition at line 1110 of file __init__.py.

1110 def best_match(self, req, working_set, installer=None, replace_conflicting=False):
1111 """Find distribution best matching `req` and usable on `working_set`
1112
1113 This calls the ``find(req)`` method of the `working_set` to see if a
1114 suitable distribution is already active. (This may raise
1115 ``VersionConflict`` if an unsuitable version of the project is already
1116 active in the specified `working_set`.) If a suitable distribution
1117 isn't active, this method returns the newest distribution in the
1118 environment that meets the ``Requirement`` in `req`. If no suitable
1119 distribution is found, and `installer` is supplied, then the result of
1120 calling the environment's ``obtain(req, installer)`` method will be
1121 returned.
1122 """
1123 try:
1124 dist = working_set.find(req)
1125 except VersionConflict:
1126 if not replace_conflicting:
1127 raise
1128 dist = None
1129 if dist is not None:
1130 return dist
1131 for dist in self[req.key]:
1132 if dist in req:
1133 return dist
1134 # try to download/install
1135 return self.obtain(req, installer)
1136

Referenced by Terminal256Formatter._color_index().

Here is the caller graph for this function:

◆ can_add()

can_add (   self,
  dist 
)
Is distribution `dist` acceptable for this environment?

The distribution must match the platform and python version
requirements specified when this environment was created, or False
is returned.

Definition at line 1058 of file __init__.py.

1058 def can_add(self, dist):
1059 """Is distribution `dist` acceptable for this environment?
1060
1061 The distribution must match the platform and python version
1062 requirements specified when this environment was created, or False
1063 is returned.
1064 """
1065 py_compat = (
1066 self.python is None
1067 or dist.py_version is None
1068 or dist.py_version == self.python
1069 )
1070 return py_compat and compatible_platforms(dist.platform, self.platform)
1071

◆ obtain()

obtain (   self,
  requirement,
  installer = None 
)
Obtain a distribution matching `requirement` (e.g. via download)

Obtain a distro that matches requirement (e.g. via download).  In the
base ``Environment`` class, this routine just returns
``installer(requirement)``, unless `installer` is None, in which case
None is returned instead.  This method is a hook that allows subclasses
to attempt other ways of obtaining a distribution before falling back
to the `installer` argument.

Definition at line 1137 of file __init__.py.

1137 def obtain(self, requirement, installer=None):
1138 """Obtain a distribution matching `requirement` (e.g. via download)
1139
1140 Obtain a distro that matches requirement (e.g. via download). In the
1141 base ``Environment`` class, this routine just returns
1142 ``installer(requirement)``, unless `installer` is None, in which case
1143 None is returned instead. This method is a hook that allows subclasses
1144 to attempt other ways of obtaining a distribution before falling back
1145 to the `installer` argument."""
1146 if installer is not None:
1147 return installer(requirement)
1148

Referenced by VersionControl.unpack().

Here is the caller graph for this function:

◆ remove()

remove (   self,
  dist 
)
Remove `dist` from the environment

Definition at line 1072 of file __init__.py.

1072 def remove(self, dist):
1073 """Remove `dist` from the environment"""
1074 self._distmap[dist.key].remove(dist)
1075

Referenced by Sequencer.remove_node(), and BuildTracker.track().

Here is the caller graph for this function:

◆ scan()

scan (   self,
  search_path = None 
)
Scan `search_path` for distributions usable in this environment

Any distributions found are added to the environment.
`search_path` should be a sequence of ``sys.path`` items.  If not
supplied, ``sys.path`` is used.  Only distributions conforming to
the platform/python version defined at initialization are added.

Definition at line 1076 of file __init__.py.

1076 def scan(self, search_path=None):
1077 """Scan `search_path` for distributions usable in this environment
1078
1079 Any distributions found are added to the environment.
1080 `search_path` should be a sequence of ``sys.path`` items. If not
1081 supplied, ``sys.path`` is used. Only distributions conforming to
1082 the platform/python version defined at initialization are added.
1083 """
1084 if search_path is None:
1085 search_path = sys.path
1086
1087 for item in search_path:
1088 for dist in find_distributions(item):
1089 self.add(dist)
1090

Referenced by Scanner.get_char().

Here is the caller graph for this function:

Field Documentation

◆ _distmap

_distmap
protected

Definition at line 1053 of file __init__.py.

◆ platform

platform

Definition at line 1054 of file __init__.py.

◆ python

python

Definition at line 1055 of file __init__.py.


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