MCPcopy
hub / github.com/pex-tool/pex / _site_packages_dirs

Method _site_packages_dirs

pex/interpreter.py:172–226  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170
171 @staticmethod
172 def _site_packages_dirs():
173 # type: () -> Iterable[SitePackagesDir]
174
175 # N.B.: The paths returned by site.getsitepackages are un-differentiated; so we let any
176 # purelib or platlib directories discovered below trump for a given path so that we pick up
177 # the extra bit of information about the site packages directory type.
178
179 site_packages = OrderedDict() # type: OrderedDict[str, SitePackagesDir]
180 try:
181 from site import getsitepackages
182
183 for path in getsitepackages():
184 entry = SitePackagesDir(path)
185 site_packages[entry.path] = entry
186 except ImportError as e:
187 # The site.py provided by old virtualenv (which we use to create some venvs) does not
188 # include a getsitepackages function.
189 TRACER.log("The site module does not define getsitepackages: {err}".format(err=e))
190
191 # The distutils package was deprecated in 3.10 and removed in 3.12. The sysconfig module was
192 # introduced in 3.2 but is not usable for our purposes until 3.11. We need
193 # `get_default_scheme` to get the current interpreter's installation scheme, which was made
194 # public in 3.10, but not made correct for venv interpreters until 3.11.
195 try:
196 import sysconfig
197
198 get_default_scheme = getattr(sysconfig, "get_default_scheme", None)
199 if get_default_scheme and sys.version_info[:2] >= (3, 11):
200 scheme = get_default_scheme()
201
202 purelib = Purelib(sysconfig.get_path("purelib", scheme))
203 site_packages[purelib.path] = purelib
204
205 platlib = Platlib(sysconfig.get_path("platlib", scheme))
206 site_packages[platlib.path] = platlib
207
208 return site_packages.values()
209 except ImportError:
210 pass
211
212 # The distutils.sysconfig module is deprecated in Python 3.10 but still around. It goes away
213 # in 3.12 with viable replacements in sysconfig starting in Python 3.11. See above where we
214 # use those replacements preferentially, when available.
215 try:
216 from distutils.sysconfig import get_python_lib
217
218 purelib = Purelib(get_python_lib(plat_specific=False))
219 site_packages[purelib.path] = purelib
220
221 platlib = Platlib(get_python_lib(plat_specific=True))
222 site_packages[platlib.path] = platlib
223 except ImportError:
224 pass
225
226 return site_packages.values()
227
228 @staticmethod
229 def _iter_extras_paths(site_packages):

Callers 1

getMethod · 0.80

Calls 5

SitePackagesDirClass · 0.85
PurelibClass · 0.85
PlatlibClass · 0.85
logMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected