Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- lib/python3.11/site-packages/_distutils_hack/__init__.py +239 -0
- lib/python3.11/site-packages/_distutils_hack/__pycache__/__init__.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/_distutils_hack/__pycache__/override.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/_distutils_hack/override.py +1 -0
- lib/python3.11/site-packages/pkg_resources/__init__.py +0 -0
- lib/python3.11/site-packages/pkg_resources/api_tests.txt +424 -0
- lib/python3.11/site-packages/pkg_resources/py.typed +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__init__.py +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_find_distributions.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_integration_zope_interface.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_markers.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_pkg_resources.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_resources.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_working_set.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package-source/__pycache__/setup.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package-source/setup.cfg +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package-source/setup.py +7 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/PKG-INFO +10 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/SOURCES.txt +7 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/dependency_links.txt +1 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/top_level.txt +1 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/zip-safe +1 -0
- lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_zipped-egg/my_test_package-1.0-py3.7.egg +0 -0
- lib/python3.11/site-packages/pkg_resources/tests/test_find_distributions.py +56 -0
- lib/python3.11/site-packages/pkg_resources/tests/test_integration_zope_interface.py +54 -0
- lib/python3.11/site-packages/pkg_resources/tests/test_markers.py +8 -0
- lib/python3.11/site-packages/pkg_resources/tests/test_pkg_resources.py +485 -0
- lib/python3.11/site-packages/pkg_resources/tests/test_resources.py +869 -0
- lib/python3.11/site-packages/pkg_resources/tests/test_working_set.py +505 -0
- lib/python3.11/site-packages/setuptools/__init__.py +256 -0
- lib/python3.11/site-packages/setuptools/_core_metadata.py +337 -0
- lib/python3.11/site-packages/setuptools/_discovery.py +33 -0
- lib/python3.11/site-packages/setuptools/_distutils/__init__.py +14 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/__init__.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_log.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_macos_compat.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_modified.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/__pycache__/debug.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/setuptools/_distutils/_log.py +3 -0
- lib/python3.11/site-packages/setuptools/_distutils/_macos_compat.py +12 -0
- lib/python3.11/site-packages/setuptools/_distutils/_modified.py +95 -0
- lib/python3.11/site-packages/setuptools/_distutils/_msvccompiler.py +16 -0
- lib/python3.11/site-packages/setuptools/_distutils/archive_util.py +284 -0
- lib/python3.11/site-packages/setuptools/_distutils/ccompiler.py +26 -0
- lib/python3.11/site-packages/setuptools/_distutils/cmd.py +535 -0
lib/python3.11/site-packages/_distutils_hack/__init__.py
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# don't import any costly modules
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
report_url = (
|
| 6 |
+
"https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def warn_distutils_present():
|
| 11 |
+
if 'distutils' not in sys.modules:
|
| 12 |
+
return
|
| 13 |
+
import warnings
|
| 14 |
+
|
| 15 |
+
warnings.warn(
|
| 16 |
+
"Distutils was imported before Setuptools, but importing Setuptools "
|
| 17 |
+
"also replaces the `distutils` module in `sys.modules`. This may lead "
|
| 18 |
+
"to undesirable behaviors or errors. To avoid these issues, avoid "
|
| 19 |
+
"using distutils directly, ensure that setuptools is installed in the "
|
| 20 |
+
"traditional way (e.g. not an editable install), and/or make sure "
|
| 21 |
+
"that setuptools is always imported before distutils."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def clear_distutils():
|
| 26 |
+
if 'distutils' not in sys.modules:
|
| 27 |
+
return
|
| 28 |
+
import warnings
|
| 29 |
+
|
| 30 |
+
warnings.warn(
|
| 31 |
+
"Setuptools is replacing distutils. Support for replacing "
|
| 32 |
+
"an already imported distutils is deprecated. In the future, "
|
| 33 |
+
"this condition will fail. "
|
| 34 |
+
f"Register concerns at {report_url}"
|
| 35 |
+
)
|
| 36 |
+
mods = [
|
| 37 |
+
name
|
| 38 |
+
for name in sys.modules
|
| 39 |
+
if name == "distutils" or name.startswith("distutils.")
|
| 40 |
+
]
|
| 41 |
+
for name in mods:
|
| 42 |
+
del sys.modules[name]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def enabled():
|
| 46 |
+
"""
|
| 47 |
+
Allow selection of distutils by environment variable.
|
| 48 |
+
"""
|
| 49 |
+
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
|
| 50 |
+
if which == 'stdlib':
|
| 51 |
+
import warnings
|
| 52 |
+
|
| 53 |
+
warnings.warn(
|
| 54 |
+
"Reliance on distutils from stdlib is deprecated. Users "
|
| 55 |
+
"must rely on setuptools to provide the distutils module. "
|
| 56 |
+
"Avoid importing distutils or import setuptools first, "
|
| 57 |
+
"and avoid setting SETUPTOOLS_USE_DISTUTILS=stdlib. "
|
| 58 |
+
f"Register concerns at {report_url}"
|
| 59 |
+
)
|
| 60 |
+
return which == 'local'
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def ensure_local_distutils():
|
| 64 |
+
import importlib
|
| 65 |
+
|
| 66 |
+
clear_distutils()
|
| 67 |
+
|
| 68 |
+
# With the DistutilsMetaFinder in place,
|
| 69 |
+
# perform an import to cause distutils to be
|
| 70 |
+
# loaded from setuptools._distutils. Ref #2906.
|
| 71 |
+
with shim():
|
| 72 |
+
importlib.import_module('distutils')
|
| 73 |
+
|
| 74 |
+
# check that submodules load as expected
|
| 75 |
+
core = importlib.import_module('distutils.core')
|
| 76 |
+
assert '_distutils' in core.__file__, core.__file__
|
| 77 |
+
assert 'setuptools._distutils.log' not in sys.modules
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def do_override():
|
| 81 |
+
"""
|
| 82 |
+
Ensure that the local copy of distutils is preferred over stdlib.
|
| 83 |
+
|
| 84 |
+
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
|
| 85 |
+
for more motivation.
|
| 86 |
+
"""
|
| 87 |
+
if enabled():
|
| 88 |
+
warn_distutils_present()
|
| 89 |
+
ensure_local_distutils()
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class _TrivialRe:
|
| 93 |
+
def __init__(self, *patterns) -> None:
|
| 94 |
+
self._patterns = patterns
|
| 95 |
+
|
| 96 |
+
def match(self, string):
|
| 97 |
+
return all(pat in string for pat in self._patterns)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class DistutilsMetaFinder:
|
| 101 |
+
def find_spec(self, fullname, path, target=None):
|
| 102 |
+
# optimization: only consider top level modules and those
|
| 103 |
+
# found in the CPython test suite.
|
| 104 |
+
if path is not None and not fullname.startswith('test.'):
|
| 105 |
+
return None
|
| 106 |
+
|
| 107 |
+
method_name = 'spec_for_{fullname}'.format(**locals())
|
| 108 |
+
method = getattr(self, method_name, lambda: None)
|
| 109 |
+
return method()
|
| 110 |
+
|
| 111 |
+
def spec_for_distutils(self):
|
| 112 |
+
if self.is_cpython():
|
| 113 |
+
return None
|
| 114 |
+
|
| 115 |
+
import importlib
|
| 116 |
+
import importlib.abc
|
| 117 |
+
import importlib.util
|
| 118 |
+
|
| 119 |
+
try:
|
| 120 |
+
mod = importlib.import_module('setuptools._distutils')
|
| 121 |
+
except Exception:
|
| 122 |
+
# There are a couple of cases where setuptools._distutils
|
| 123 |
+
# may not be present:
|
| 124 |
+
# - An older Setuptools without a local distutils is
|
| 125 |
+
# taking precedence. Ref #2957.
|
| 126 |
+
# - Path manipulation during sitecustomize removes
|
| 127 |
+
# setuptools from the path but only after the hook
|
| 128 |
+
# has been loaded. Ref #2980.
|
| 129 |
+
# In either case, fall back to stdlib behavior.
|
| 130 |
+
return None
|
| 131 |
+
|
| 132 |
+
class DistutilsLoader(importlib.abc.Loader):
|
| 133 |
+
def create_module(self, spec):
|
| 134 |
+
mod.__name__ = 'distutils'
|
| 135 |
+
return mod
|
| 136 |
+
|
| 137 |
+
def exec_module(self, module):
|
| 138 |
+
pass
|
| 139 |
+
|
| 140 |
+
return importlib.util.spec_from_loader(
|
| 141 |
+
'distutils', DistutilsLoader(), origin=mod.__file__
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
@staticmethod
|
| 145 |
+
def is_cpython():
|
| 146 |
+
"""
|
| 147 |
+
Suppress supplying distutils for CPython (build and tests).
|
| 148 |
+
Ref #2965 and #3007.
|
| 149 |
+
"""
|
| 150 |
+
return os.path.isfile('pybuilddir.txt')
|
| 151 |
+
|
| 152 |
+
def spec_for_pip(self):
|
| 153 |
+
"""
|
| 154 |
+
Ensure stdlib distutils when running under pip.
|
| 155 |
+
See pypa/pip#8761 for rationale.
|
| 156 |
+
"""
|
| 157 |
+
if sys.version_info >= (3, 12) or self.pip_imported_during_build():
|
| 158 |
+
return
|
| 159 |
+
clear_distutils()
|
| 160 |
+
self.spec_for_distutils = lambda: None
|
| 161 |
+
|
| 162 |
+
@classmethod
|
| 163 |
+
def pip_imported_during_build(cls):
|
| 164 |
+
"""
|
| 165 |
+
Detect if pip is being imported in a build script. Ref #2355.
|
| 166 |
+
"""
|
| 167 |
+
import traceback
|
| 168 |
+
|
| 169 |
+
return any(
|
| 170 |
+
cls.frame_file_is_setup(frame) for frame, line in traceback.walk_stack(None)
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
@staticmethod
|
| 174 |
+
def frame_file_is_setup(frame):
|
| 175 |
+
"""
|
| 176 |
+
Return True if the indicated frame suggests a setup.py file.
|
| 177 |
+
"""
|
| 178 |
+
# some frames may not have __file__ (#2940)
|
| 179 |
+
return frame.f_globals.get('__file__', '').endswith('setup.py')
|
| 180 |
+
|
| 181 |
+
def spec_for_sensitive_tests(self):
|
| 182 |
+
"""
|
| 183 |
+
Ensure stdlib distutils when running select tests under CPython.
|
| 184 |
+
|
| 185 |
+
python/cpython#91169
|
| 186 |
+
"""
|
| 187 |
+
clear_distutils()
|
| 188 |
+
self.spec_for_distutils = lambda: None
|
| 189 |
+
|
| 190 |
+
sensitive_tests = (
|
| 191 |
+
[
|
| 192 |
+
'test.test_distutils',
|
| 193 |
+
'test.test_peg_generator',
|
| 194 |
+
'test.test_importlib',
|
| 195 |
+
]
|
| 196 |
+
if sys.version_info < (3, 10)
|
| 197 |
+
else [
|
| 198 |
+
'test.test_distutils',
|
| 199 |
+
]
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
for name in DistutilsMetaFinder.sensitive_tests:
|
| 204 |
+
setattr(
|
| 205 |
+
DistutilsMetaFinder,
|
| 206 |
+
f'spec_for_{name}',
|
| 207 |
+
DistutilsMetaFinder.spec_for_sensitive_tests,
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
DISTUTILS_FINDER = DistutilsMetaFinder()
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def add_shim():
|
| 215 |
+
DISTUTILS_FINDER in sys.meta_path or insert_shim()
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
class shim:
|
| 219 |
+
def __enter__(self) -> None:
|
| 220 |
+
insert_shim()
|
| 221 |
+
|
| 222 |
+
def __exit__(self, exc: object, value: object, tb: object) -> None:
|
| 223 |
+
_remove_shim()
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def insert_shim():
|
| 227 |
+
sys.meta_path.insert(0, DISTUTILS_FINDER)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def _remove_shim():
|
| 231 |
+
try:
|
| 232 |
+
sys.meta_path.remove(DISTUTILS_FINDER)
|
| 233 |
+
except ValueError:
|
| 234 |
+
pass
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
if sys.version_info < (3, 12):
|
| 238 |
+
# DistutilsMetaFinder can only be disabled in Python < 3.12 (PEP 632)
|
| 239 |
+
remove_shim = _remove_shim
|
lib/python3.11/site-packages/_distutils_hack/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (12 kB). View file
|
|
|
lib/python3.11/site-packages/_distutils_hack/__pycache__/override.cpython-311.pyc
ADDED
|
Binary file (322 Bytes). View file
|
|
|
lib/python3.11/site-packages/_distutils_hack/override.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__import__('_distutils_hack').do_override()
|
lib/python3.11/site-packages/pkg_resources/__init__.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
lib/python3.11/site-packages/pkg_resources/api_tests.txt
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Pluggable Distributions of Python Software
|
| 2 |
+
==========================================
|
| 3 |
+
|
| 4 |
+
Distributions
|
| 5 |
+
-------------
|
| 6 |
+
|
| 7 |
+
A "Distribution" is a collection of files that represent a "Release" of a
|
| 8 |
+
"Project" as of a particular point in time, denoted by a
|
| 9 |
+
"Version"::
|
| 10 |
+
|
| 11 |
+
>>> import sys, pkg_resources
|
| 12 |
+
>>> from pkg_resources import Distribution
|
| 13 |
+
>>> Distribution(project_name="Foo", version="1.2")
|
| 14 |
+
Foo 1.2
|
| 15 |
+
|
| 16 |
+
Distributions have a location, which can be a filename, URL, or really anything
|
| 17 |
+
else you care to use::
|
| 18 |
+
|
| 19 |
+
>>> dist = Distribution(
|
| 20 |
+
... location="http://example.com/something",
|
| 21 |
+
... project_name="Bar", version="0.9"
|
| 22 |
+
... )
|
| 23 |
+
|
| 24 |
+
>>> dist
|
| 25 |
+
Bar 0.9 (http://example.com/something)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Distributions have various introspectable attributes::
|
| 29 |
+
|
| 30 |
+
>>> dist.location
|
| 31 |
+
'http://example.com/something'
|
| 32 |
+
|
| 33 |
+
>>> dist.project_name
|
| 34 |
+
'Bar'
|
| 35 |
+
|
| 36 |
+
>>> dist.version
|
| 37 |
+
'0.9'
|
| 38 |
+
|
| 39 |
+
>>> dist.py_version == '{}.{}'.format(*sys.version_info)
|
| 40 |
+
True
|
| 41 |
+
|
| 42 |
+
>>> print(dist.platform)
|
| 43 |
+
None
|
| 44 |
+
|
| 45 |
+
Including various computed attributes::
|
| 46 |
+
|
| 47 |
+
>>> from pkg_resources import parse_version
|
| 48 |
+
>>> dist.parsed_version == parse_version(dist.version)
|
| 49 |
+
True
|
| 50 |
+
|
| 51 |
+
>>> dist.key # case-insensitive form of the project name
|
| 52 |
+
'bar'
|
| 53 |
+
|
| 54 |
+
Distributions are compared (and hashed) by version first::
|
| 55 |
+
|
| 56 |
+
>>> Distribution(version='1.0') == Distribution(version='1.0')
|
| 57 |
+
True
|
| 58 |
+
>>> Distribution(version='1.0') == Distribution(version='1.1')
|
| 59 |
+
False
|
| 60 |
+
>>> Distribution(version='1.0') < Distribution(version='1.1')
|
| 61 |
+
True
|
| 62 |
+
|
| 63 |
+
but also by project name (case-insensitive), platform, Python version,
|
| 64 |
+
location, etc.::
|
| 65 |
+
|
| 66 |
+
>>> Distribution(project_name="Foo",version="1.0") == \
|
| 67 |
+
... Distribution(project_name="Foo",version="1.0")
|
| 68 |
+
True
|
| 69 |
+
|
| 70 |
+
>>> Distribution(project_name="Foo",version="1.0") == \
|
| 71 |
+
... Distribution(project_name="foo",version="1.0")
|
| 72 |
+
True
|
| 73 |
+
|
| 74 |
+
>>> Distribution(project_name="Foo",version="1.0") == \
|
| 75 |
+
... Distribution(project_name="Foo",version="1.1")
|
| 76 |
+
False
|
| 77 |
+
|
| 78 |
+
>>> Distribution(project_name="Foo",py_version="2.3",version="1.0") == \
|
| 79 |
+
... Distribution(project_name="Foo",py_version="2.4",version="1.0")
|
| 80 |
+
False
|
| 81 |
+
|
| 82 |
+
>>> Distribution(location="spam",version="1.0") == \
|
| 83 |
+
... Distribution(location="spam",version="1.0")
|
| 84 |
+
True
|
| 85 |
+
|
| 86 |
+
>>> Distribution(location="spam",version="1.0") == \
|
| 87 |
+
... Distribution(location="baz",version="1.0")
|
| 88 |
+
False
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
Hash and compare distribution by prio/plat
|
| 93 |
+
|
| 94 |
+
Get version from metadata
|
| 95 |
+
provider capabilities
|
| 96 |
+
egg_name()
|
| 97 |
+
as_requirement()
|
| 98 |
+
from_location, from_filename (w/path normalization)
|
| 99 |
+
|
| 100 |
+
Releases may have zero or more "Requirements", which indicate
|
| 101 |
+
what releases of another project the release requires in order to
|
| 102 |
+
function. A Requirement names the other project, expresses some criteria
|
| 103 |
+
as to what releases of that project are acceptable, and lists any "Extras"
|
| 104 |
+
that the requiring release may need from that project. (An Extra is an
|
| 105 |
+
optional feature of a Release, that can only be used if its additional
|
| 106 |
+
Requirements are satisfied.)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
The Working Set
|
| 111 |
+
---------------
|
| 112 |
+
|
| 113 |
+
A collection of active distributions is called a Working Set. Note that a
|
| 114 |
+
Working Set can contain any importable distribution, not just pluggable ones.
|
| 115 |
+
For example, the Python standard library is an importable distribution that
|
| 116 |
+
will usually be part of the Working Set, even though it is not pluggable.
|
| 117 |
+
Similarly, when you are doing development work on a project, the files you are
|
| 118 |
+
editing are also a Distribution. (And, with a little attention to the
|
| 119 |
+
directory names used, and including some additional metadata, such a
|
| 120 |
+
"development distribution" can be made pluggable as well.)
|
| 121 |
+
|
| 122 |
+
>>> from pkg_resources import WorkingSet
|
| 123 |
+
|
| 124 |
+
A working set's entries are the sys.path entries that correspond to the active
|
| 125 |
+
distributions. By default, the working set's entries are the items on
|
| 126 |
+
``sys.path``::
|
| 127 |
+
|
| 128 |
+
>>> ws = WorkingSet()
|
| 129 |
+
>>> ws.entries == sys.path
|
| 130 |
+
True
|
| 131 |
+
|
| 132 |
+
But you can also create an empty working set explicitly, and add distributions
|
| 133 |
+
to it::
|
| 134 |
+
|
| 135 |
+
>>> ws = WorkingSet([])
|
| 136 |
+
>>> ws.add(dist)
|
| 137 |
+
>>> ws.entries
|
| 138 |
+
['http://example.com/something']
|
| 139 |
+
>>> dist in ws
|
| 140 |
+
True
|
| 141 |
+
>>> Distribution('foo',version="") in ws
|
| 142 |
+
False
|
| 143 |
+
|
| 144 |
+
And you can iterate over its distributions::
|
| 145 |
+
|
| 146 |
+
>>> list(ws)
|
| 147 |
+
[Bar 0.9 (http://example.com/something)]
|
| 148 |
+
|
| 149 |
+
Adding the same distribution more than once is a no-op::
|
| 150 |
+
|
| 151 |
+
>>> ws.add(dist)
|
| 152 |
+
>>> list(ws)
|
| 153 |
+
[Bar 0.9 (http://example.com/something)]
|
| 154 |
+
|
| 155 |
+
For that matter, adding multiple distributions for the same project also does
|
| 156 |
+
nothing, because a working set can only hold one active distribution per
|
| 157 |
+
project -- the first one added to it::
|
| 158 |
+
|
| 159 |
+
>>> ws.add(
|
| 160 |
+
... Distribution(
|
| 161 |
+
... 'http://example.com/something', project_name="Bar",
|
| 162 |
+
... version="7.2"
|
| 163 |
+
... )
|
| 164 |
+
... )
|
| 165 |
+
>>> list(ws)
|
| 166 |
+
[Bar 0.9 (http://example.com/something)]
|
| 167 |
+
|
| 168 |
+
You can append a path entry to a working set using ``add_entry()``::
|
| 169 |
+
|
| 170 |
+
>>> ws.entries
|
| 171 |
+
['http://example.com/something']
|
| 172 |
+
>>> ws.add_entry(pkg_resources.__file__)
|
| 173 |
+
>>> ws.entries
|
| 174 |
+
['http://example.com/something', '...pkg_resources...']
|
| 175 |
+
|
| 176 |
+
Multiple additions result in multiple entries, even if the entry is already in
|
| 177 |
+
the working set (because ``sys.path`` can contain the same entry more than
|
| 178 |
+
once)::
|
| 179 |
+
|
| 180 |
+
>>> ws.add_entry(pkg_resources.__file__)
|
| 181 |
+
>>> ws.entries
|
| 182 |
+
['...example.com...', '...pkg_resources...', '...pkg_resources...']
|
| 183 |
+
|
| 184 |
+
And you can specify the path entry a distribution was found under, using the
|
| 185 |
+
optional second parameter to ``add()``::
|
| 186 |
+
|
| 187 |
+
>>> ws = WorkingSet([])
|
| 188 |
+
>>> ws.add(dist,"foo")
|
| 189 |
+
>>> ws.entries
|
| 190 |
+
['foo']
|
| 191 |
+
|
| 192 |
+
But even if a distribution is found under multiple path entries, it still only
|
| 193 |
+
shows up once when iterating the working set:
|
| 194 |
+
|
| 195 |
+
>>> ws.add_entry(ws.entries[0])
|
| 196 |
+
>>> list(ws)
|
| 197 |
+
[Bar 0.9 (http://example.com/something)]
|
| 198 |
+
|
| 199 |
+
You can ask a WorkingSet to ``find()`` a distribution matching a requirement::
|
| 200 |
+
|
| 201 |
+
>>> from pkg_resources import Requirement
|
| 202 |
+
>>> print(ws.find(Requirement.parse("Foo==1.0"))) # no match, return None
|
| 203 |
+
None
|
| 204 |
+
|
| 205 |
+
>>> ws.find(Requirement.parse("Bar==0.9")) # match, return distribution
|
| 206 |
+
Bar 0.9 (http://example.com/something)
|
| 207 |
+
|
| 208 |
+
Note that asking for a conflicting version of a distribution already in a
|
| 209 |
+
working set triggers a ``pkg_resources.VersionConflict`` error:
|
| 210 |
+
|
| 211 |
+
>>> try:
|
| 212 |
+
... ws.find(Requirement.parse("Bar==1.0"))
|
| 213 |
+
... except pkg_resources.VersionConflict as exc:
|
| 214 |
+
... print(str(exc))
|
| 215 |
+
... else:
|
| 216 |
+
... raise AssertionError("VersionConflict was not raised")
|
| 217 |
+
(Bar 0.9 (http://example.com/something), Requirement.parse('Bar==1.0'))
|
| 218 |
+
|
| 219 |
+
You can subscribe a callback function to receive notifications whenever a new
|
| 220 |
+
distribution is added to a working set. The callback is immediately invoked
|
| 221 |
+
once for each existing distribution in the working set, and then is called
|
| 222 |
+
again for new distributions added thereafter::
|
| 223 |
+
|
| 224 |
+
>>> def added(dist): print("Added %s" % dist)
|
| 225 |
+
>>> ws.subscribe(added)
|
| 226 |
+
Added Bar 0.9
|
| 227 |
+
>>> foo12 = Distribution(project_name="Foo", version="1.2", location="f12")
|
| 228 |
+
>>> ws.add(foo12)
|
| 229 |
+
Added Foo 1.2
|
| 230 |
+
|
| 231 |
+
Note, however, that only the first distribution added for a given project name
|
| 232 |
+
will trigger a callback, even during the initial ``subscribe()`` callback::
|
| 233 |
+
|
| 234 |
+
>>> foo14 = Distribution(project_name="Foo", version="1.4", location="f14")
|
| 235 |
+
>>> ws.add(foo14) # no callback, because Foo 1.2 is already active
|
| 236 |
+
|
| 237 |
+
>>> ws = WorkingSet([])
|
| 238 |
+
>>> ws.add(foo12)
|
| 239 |
+
>>> ws.add(foo14)
|
| 240 |
+
>>> ws.subscribe(added)
|
| 241 |
+
Added Foo 1.2
|
| 242 |
+
|
| 243 |
+
And adding a callback more than once has no effect, either::
|
| 244 |
+
|
| 245 |
+
>>> ws.subscribe(added) # no callbacks
|
| 246 |
+
|
| 247 |
+
# and no double-callbacks on subsequent additions, either
|
| 248 |
+
>>> just_a_test = Distribution(project_name="JustATest", version="0.99")
|
| 249 |
+
>>> ws.add(just_a_test)
|
| 250 |
+
Added JustATest 0.99
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
Finding Plugins
|
| 254 |
+
---------------
|
| 255 |
+
|
| 256 |
+
``WorkingSet`` objects can be used to figure out what plugins in an
|
| 257 |
+
``Environment`` can be loaded without any resolution errors::
|
| 258 |
+
|
| 259 |
+
>>> from pkg_resources import Environment
|
| 260 |
+
|
| 261 |
+
>>> plugins = Environment([]) # normally, a list of plugin directories
|
| 262 |
+
>>> plugins.add(foo12)
|
| 263 |
+
>>> plugins.add(foo14)
|
| 264 |
+
>>> plugins.add(just_a_test)
|
| 265 |
+
|
| 266 |
+
In the simplest case, we just get the newest version of each distribution in
|
| 267 |
+
the plugin environment::
|
| 268 |
+
|
| 269 |
+
>>> ws = WorkingSet([])
|
| 270 |
+
>>> ws.find_plugins(plugins)
|
| 271 |
+
([JustATest 0.99, Foo 1.4 (f14)], {})
|
| 272 |
+
|
| 273 |
+
But if there's a problem with a version conflict or missing requirements, the
|
| 274 |
+
method falls back to older versions, and the error info dict will contain an
|
| 275 |
+
exception instance for each unloadable plugin::
|
| 276 |
+
|
| 277 |
+
>>> ws.add(foo12) # this will conflict with Foo 1.4
|
| 278 |
+
>>> ws.find_plugins(plugins)
|
| 279 |
+
([JustATest 0.99, Foo 1.2 (f12)], {Foo 1.4 (f14): VersionConflict(...)})
|
| 280 |
+
|
| 281 |
+
But if you disallow fallbacks, the failed plugin will be skipped instead of
|
| 282 |
+
trying older versions::
|
| 283 |
+
|
| 284 |
+
>>> ws.find_plugins(plugins, fallback=False)
|
| 285 |
+
([JustATest 0.99], {Foo 1.4 (f14): VersionConflict(...)})
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
Platform Compatibility Rules
|
| 290 |
+
----------------------------
|
| 291 |
+
|
| 292 |
+
On the Mac, there are potential compatibility issues for modules compiled
|
| 293 |
+
on newer versions of macOS than what the user is running. Additionally,
|
| 294 |
+
macOS will soon have two platforms to contend with: Intel and PowerPC.
|
| 295 |
+
|
| 296 |
+
Basic equality works as on other platforms::
|
| 297 |
+
|
| 298 |
+
>>> from pkg_resources import compatible_platforms as cp
|
| 299 |
+
>>> reqd = 'macosx-10.4-ppc'
|
| 300 |
+
>>> cp(reqd, reqd)
|
| 301 |
+
True
|
| 302 |
+
>>> cp("win32", reqd)
|
| 303 |
+
False
|
| 304 |
+
|
| 305 |
+
Distributions made on other machine types are not compatible::
|
| 306 |
+
|
| 307 |
+
>>> cp("macosx-10.4-i386", reqd)
|
| 308 |
+
False
|
| 309 |
+
|
| 310 |
+
Distributions made on earlier versions of the OS are compatible, as
|
| 311 |
+
long as they are from the same top-level version. The patchlevel version
|
| 312 |
+
number does not matter::
|
| 313 |
+
|
| 314 |
+
>>> cp("macosx-10.4-ppc", reqd)
|
| 315 |
+
True
|
| 316 |
+
>>> cp("macosx-10.3-ppc", reqd)
|
| 317 |
+
True
|
| 318 |
+
>>> cp("macosx-10.5-ppc", reqd)
|
| 319 |
+
False
|
| 320 |
+
>>> cp("macosx-9.5-ppc", reqd)
|
| 321 |
+
False
|
| 322 |
+
|
| 323 |
+
Backwards compatibility for packages made via earlier versions of
|
| 324 |
+
setuptools is provided as well::
|
| 325 |
+
|
| 326 |
+
>>> cp("darwin-8.2.0-Power_Macintosh", reqd)
|
| 327 |
+
True
|
| 328 |
+
>>> cp("darwin-7.2.0-Power_Macintosh", reqd)
|
| 329 |
+
True
|
| 330 |
+
>>> cp("darwin-8.2.0-Power_Macintosh", "macosx-10.3-ppc")
|
| 331 |
+
False
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
Environment Markers
|
| 335 |
+
-------------------
|
| 336 |
+
|
| 337 |
+
>>> from pkg_resources import invalid_marker as im, evaluate_marker as em
|
| 338 |
+
>>> import os
|
| 339 |
+
|
| 340 |
+
>>> print(im("sys_platform"))
|
| 341 |
+
Expected marker operator, one of <=, <, !=, ==, >=, >, ~=, ===, in, not in
|
| 342 |
+
sys_platform
|
| 343 |
+
^
|
| 344 |
+
|
| 345 |
+
>>> print(im("sys_platform=="))
|
| 346 |
+
Expected a marker variable or quoted string
|
| 347 |
+
sys_platform==
|
| 348 |
+
^
|
| 349 |
+
|
| 350 |
+
>>> print(im("sys_platform=='win32'"))
|
| 351 |
+
False
|
| 352 |
+
|
| 353 |
+
>>> print(im("sys=='x'"))
|
| 354 |
+
Expected a marker variable or quoted string
|
| 355 |
+
sys=='x'
|
| 356 |
+
^
|
| 357 |
+
|
| 358 |
+
>>> print(im("(extra)"))
|
| 359 |
+
Expected marker operator, one of <=, <, !=, ==, >=, >, ~=, ===, in, not in
|
| 360 |
+
(extra)
|
| 361 |
+
^
|
| 362 |
+
|
| 363 |
+
>>> print(im("(extra"))
|
| 364 |
+
Expected marker operator, one of <=, <, !=, ==, >=, >, ~=, ===, in, not in
|
| 365 |
+
(extra
|
| 366 |
+
^
|
| 367 |
+
|
| 368 |
+
>>> print(im("os.open('foo')=='y'"))
|
| 369 |
+
Expected a marker variable or quoted string
|
| 370 |
+
os.open('foo')=='y'
|
| 371 |
+
^
|
| 372 |
+
|
| 373 |
+
>>> print(im("'x'=='y' and os.open('foo')=='y'")) # no short-circuit!
|
| 374 |
+
Expected a marker variable or quoted string
|
| 375 |
+
'x'=='y' and os.open('foo')=='y'
|
| 376 |
+
^
|
| 377 |
+
|
| 378 |
+
>>> print(im("'x'=='x' or os.open('foo')=='y'")) # no short-circuit!
|
| 379 |
+
Expected a marker variable or quoted string
|
| 380 |
+
'x'=='x' or os.open('foo')=='y'
|
| 381 |
+
^
|
| 382 |
+
|
| 383 |
+
>>> print(im("r'x'=='x'"))
|
| 384 |
+
Expected a marker variable or quoted string
|
| 385 |
+
r'x'=='x'
|
| 386 |
+
^
|
| 387 |
+
|
| 388 |
+
>>> print(im("'''x'''=='x'"))
|
| 389 |
+
Expected marker operator, one of <=, <, !=, ==, >=, >, ~=, ===, in, not in
|
| 390 |
+
'''x'''=='x'
|
| 391 |
+
^
|
| 392 |
+
|
| 393 |
+
>>> print(im('"""x"""=="x"'))
|
| 394 |
+
Expected marker operator, one of <=, <, !=, ==, >=, >, ~=, ===, in, not in
|
| 395 |
+
"""x"""=="x"
|
| 396 |
+
^
|
| 397 |
+
|
| 398 |
+
>>> print(im(r"x\n=='x'"))
|
| 399 |
+
Expected a marker variable or quoted string
|
| 400 |
+
x\n=='x'
|
| 401 |
+
^
|
| 402 |
+
|
| 403 |
+
>>> print(im("os.open=='y'"))
|
| 404 |
+
Expected a marker variable or quoted string
|
| 405 |
+
os.open=='y'
|
| 406 |
+
^
|
| 407 |
+
|
| 408 |
+
>>> em("sys_platform=='win32'") == (sys.platform=='win32')
|
| 409 |
+
True
|
| 410 |
+
|
| 411 |
+
>>> em("python_version >= '2.7'")
|
| 412 |
+
True
|
| 413 |
+
|
| 414 |
+
>>> em("python_version > '2.6'")
|
| 415 |
+
True
|
| 416 |
+
|
| 417 |
+
>>> im("implementation_name=='cpython'")
|
| 418 |
+
False
|
| 419 |
+
|
| 420 |
+
>>> im("platform_python_implementation=='CPython'")
|
| 421 |
+
False
|
| 422 |
+
|
| 423 |
+
>>> im("implementation_version=='3.5.1'")
|
| 424 |
+
False
|
lib/python3.11/site-packages/pkg_resources/py.typed
ADDED
|
File without changes
|
lib/python3.11/site-packages/pkg_resources/tests/__init__.py
ADDED
|
File without changes
|
lib/python3.11/site-packages/pkg_resources/tests/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (204 Bytes). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_find_distributions.cpython-311.pyc
ADDED
|
Binary file (4.04 kB). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_integration_zope_interface.cpython-311.pyc
ADDED
|
Binary file (2.12 kB). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_markers.cpython-311.pyc
ADDED
|
Binary file (710 Bytes). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_pkg_resources.cpython-311.pyc
ADDED
|
Binary file (27.9 kB). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_resources.cpython-311.pyc
ADDED
|
Binary file (54.8 kB). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/__pycache__/test_working_set.cpython-311.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package-source/__pycache__/setup.cpython-311.pyc
ADDED
|
Binary file (395 Bytes). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package-source/setup.cfg
ADDED
|
File without changes
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package-source/setup.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import setuptools
|
| 2 |
+
|
| 3 |
+
setuptools.setup(
|
| 4 |
+
name="my-test-package",
|
| 5 |
+
version="1.0",
|
| 6 |
+
zip_safe=True,
|
| 7 |
+
)
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/PKG-INFO
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 1.0
|
| 2 |
+
Name: my-test-package
|
| 3 |
+
Version: 1.0
|
| 4 |
+
Summary: UNKNOWN
|
| 5 |
+
Home-page: UNKNOWN
|
| 6 |
+
Author: UNKNOWN
|
| 7 |
+
Author-email: UNKNOWN
|
| 8 |
+
License: UNKNOWN
|
| 9 |
+
Description: UNKNOWN
|
| 10 |
+
Platform: UNKNOWN
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/SOURCES.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
setup.cfg
|
| 2 |
+
setup.py
|
| 3 |
+
my_test_package.egg-info/PKG-INFO
|
| 4 |
+
my_test_package.egg-info/SOURCES.txt
|
| 5 |
+
my_test_package.egg-info/dependency_links.txt
|
| 6 |
+
my_test_package.egg-info/top_level.txt
|
| 7 |
+
my_test_package.egg-info/zip-safe
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/dependency_links.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_unpacked-egg/my_test_package-1.0-py3.7.egg/EGG-INFO/zip-safe
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
lib/python3.11/site-packages/pkg_resources/tests/data/my-test-package_zipped-egg/my_test_package-1.0-py3.7.egg
ADDED
|
Binary file (843 Bytes). View file
|
|
|
lib/python3.11/site-packages/pkg_resources/tests/test_find_distributions.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import shutil
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import pkg_resources
|
| 7 |
+
|
| 8 |
+
TESTS_DATA_DIR = Path(__file__).parent / 'data'
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestFindDistributions:
|
| 12 |
+
@pytest.fixture
|
| 13 |
+
def target_dir(self, tmpdir):
|
| 14 |
+
target_dir = tmpdir.mkdir('target')
|
| 15 |
+
# place a .egg named directory in the target that is not an egg:
|
| 16 |
+
target_dir.mkdir('not.an.egg')
|
| 17 |
+
return target_dir
|
| 18 |
+
|
| 19 |
+
def test_non_egg_dir_named_egg(self, target_dir):
|
| 20 |
+
dists = pkg_resources.find_distributions(str(target_dir))
|
| 21 |
+
assert not list(dists)
|
| 22 |
+
|
| 23 |
+
def test_standalone_egg_directory(self, target_dir):
|
| 24 |
+
shutil.copytree(
|
| 25 |
+
TESTS_DATA_DIR / 'my-test-package_unpacked-egg',
|
| 26 |
+
target_dir,
|
| 27 |
+
dirs_exist_ok=True,
|
| 28 |
+
)
|
| 29 |
+
dists = pkg_resources.find_distributions(str(target_dir))
|
| 30 |
+
assert [dist.project_name for dist in dists] == ['my-test-package']
|
| 31 |
+
dists = pkg_resources.find_distributions(str(target_dir), only=True)
|
| 32 |
+
assert not list(dists)
|
| 33 |
+
|
| 34 |
+
def test_zipped_egg(self, target_dir):
|
| 35 |
+
shutil.copytree(
|
| 36 |
+
TESTS_DATA_DIR / 'my-test-package_zipped-egg',
|
| 37 |
+
target_dir,
|
| 38 |
+
dirs_exist_ok=True,
|
| 39 |
+
)
|
| 40 |
+
dists = pkg_resources.find_distributions(str(target_dir))
|
| 41 |
+
assert [dist.project_name for dist in dists] == ['my-test-package']
|
| 42 |
+
dists = pkg_resources.find_distributions(str(target_dir), only=True)
|
| 43 |
+
assert not list(dists)
|
| 44 |
+
|
| 45 |
+
def test_zipped_sdist_one_level_removed(self, target_dir):
|
| 46 |
+
shutil.copytree(
|
| 47 |
+
TESTS_DATA_DIR / 'my-test-package-zip', target_dir, dirs_exist_ok=True
|
| 48 |
+
)
|
| 49 |
+
dists = pkg_resources.find_distributions(
|
| 50 |
+
str(target_dir / "my-test-package.zip")
|
| 51 |
+
)
|
| 52 |
+
assert [dist.project_name for dist in dists] == ['my-test-package']
|
| 53 |
+
dists = pkg_resources.find_distributions(
|
| 54 |
+
str(target_dir / "my-test-package.zip"), only=True
|
| 55 |
+
)
|
| 56 |
+
assert not list(dists)
|
lib/python3.11/site-packages/pkg_resources/tests/test_integration_zope_interface.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import platform
|
| 2 |
+
from inspect import cleandoc
|
| 3 |
+
|
| 4 |
+
import jaraco.path
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
pytestmark = pytest.mark.integration
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# For the sake of simplicity this test uses fixtures defined in
|
| 11 |
+
# `setuptools.test.fixtures`,
|
| 12 |
+
# and it also exercise conditions considered deprecated...
|
| 13 |
+
# So if needed this test can be deleted.
|
| 14 |
+
@pytest.mark.skipif(
|
| 15 |
+
platform.system() != "Linux",
|
| 16 |
+
reason="only demonstrated to fail on Linux in #4399",
|
| 17 |
+
)
|
| 18 |
+
def test_interop_pkg_resources_iter_entry_points(tmp_path, venv):
|
| 19 |
+
"""
|
| 20 |
+
Importing pkg_resources.iter_entry_points on console_scripts
|
| 21 |
+
seems to cause trouble with zope-interface, when deprecates installation method
|
| 22 |
+
is used. See #4399.
|
| 23 |
+
"""
|
| 24 |
+
project = {
|
| 25 |
+
"pkg": {
|
| 26 |
+
"foo.py": cleandoc(
|
| 27 |
+
"""
|
| 28 |
+
from pkg_resources import iter_entry_points
|
| 29 |
+
|
| 30 |
+
def bar():
|
| 31 |
+
print("Print me if you can")
|
| 32 |
+
"""
|
| 33 |
+
),
|
| 34 |
+
"setup.py": cleandoc(
|
| 35 |
+
"""
|
| 36 |
+
from setuptools import setup, find_packages
|
| 37 |
+
|
| 38 |
+
setup(
|
| 39 |
+
install_requires=["zope-interface==6.4.post2"],
|
| 40 |
+
entry_points={
|
| 41 |
+
"console_scripts": [
|
| 42 |
+
"foo=foo:bar",
|
| 43 |
+
],
|
| 44 |
+
},
|
| 45 |
+
)
|
| 46 |
+
"""
|
| 47 |
+
),
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
jaraco.path.build(project, prefix=tmp_path)
|
| 51 |
+
cmd = ["pip", "install", "-e", ".", "--no-use-pep517"]
|
| 52 |
+
venv.run(cmd, cwd=tmp_path / "pkg") # Needs this version of pkg_resources installed
|
| 53 |
+
out = venv.run(["foo"])
|
| 54 |
+
assert "Print me if you can" in out
|
lib/python3.11/site-packages/pkg_resources/tests/test_markers.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from unittest import mock
|
| 2 |
+
|
| 3 |
+
from pkg_resources import evaluate_marker
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@mock.patch('platform.python_version', return_value='2.7.10')
|
| 7 |
+
def test_ordering(python_version_mock):
|
| 8 |
+
assert evaluate_marker("python_full_version > '2.7.3'") is True
|
lib/python3.11/site-packages/pkg_resources/tests/test_pkg_resources.py
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import builtins
|
| 4 |
+
import datetime
|
| 5 |
+
import inspect
|
| 6 |
+
import os
|
| 7 |
+
import plistlib
|
| 8 |
+
import stat
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
import tempfile
|
| 12 |
+
import zipfile
|
| 13 |
+
from unittest import mock
|
| 14 |
+
|
| 15 |
+
import pytest
|
| 16 |
+
|
| 17 |
+
import pkg_resources
|
| 18 |
+
from pkg_resources import DistInfoDistribution, Distribution, EggInfoDistribution
|
| 19 |
+
|
| 20 |
+
import distutils.command.install_egg_info
|
| 21 |
+
import distutils.dist
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class EggRemover(str):
|
| 25 |
+
def __call__(self):
|
| 26 |
+
if self in sys.path:
|
| 27 |
+
sys.path.remove(self)
|
| 28 |
+
if os.path.exists(self):
|
| 29 |
+
os.remove(self)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class TestZipProvider:
|
| 33 |
+
finalizers: list[EggRemover] = []
|
| 34 |
+
|
| 35 |
+
ref_time = datetime.datetime(2013, 5, 12, 13, 25, 0)
|
| 36 |
+
"A reference time for a file modification"
|
| 37 |
+
|
| 38 |
+
@classmethod
|
| 39 |
+
def setup_class(cls):
|
| 40 |
+
"create a zip egg and add it to sys.path"
|
| 41 |
+
egg = tempfile.NamedTemporaryFile(suffix='.egg', delete=False)
|
| 42 |
+
zip_egg = zipfile.ZipFile(egg, 'w')
|
| 43 |
+
zip_info = zipfile.ZipInfo()
|
| 44 |
+
zip_info.filename = 'mod.py'
|
| 45 |
+
zip_info.date_time = cls.ref_time.timetuple()
|
| 46 |
+
zip_egg.writestr(zip_info, 'x = 3\n')
|
| 47 |
+
zip_info = zipfile.ZipInfo()
|
| 48 |
+
zip_info.filename = 'data.dat'
|
| 49 |
+
zip_info.date_time = cls.ref_time.timetuple()
|
| 50 |
+
zip_egg.writestr(zip_info, 'hello, world!')
|
| 51 |
+
zip_info = zipfile.ZipInfo()
|
| 52 |
+
zip_info.filename = 'subdir/mod2.py'
|
| 53 |
+
zip_info.date_time = cls.ref_time.timetuple()
|
| 54 |
+
zip_egg.writestr(zip_info, 'x = 6\n')
|
| 55 |
+
zip_info = zipfile.ZipInfo()
|
| 56 |
+
zip_info.filename = 'subdir/data2.dat'
|
| 57 |
+
zip_info.date_time = cls.ref_time.timetuple()
|
| 58 |
+
zip_egg.writestr(zip_info, 'goodbye, world!')
|
| 59 |
+
zip_egg.close()
|
| 60 |
+
egg.close()
|
| 61 |
+
|
| 62 |
+
sys.path.append(egg.name)
|
| 63 |
+
subdir = os.path.join(egg.name, 'subdir')
|
| 64 |
+
sys.path.append(subdir)
|
| 65 |
+
cls.finalizers.append(EggRemover(subdir))
|
| 66 |
+
cls.finalizers.append(EggRemover(egg.name))
|
| 67 |
+
|
| 68 |
+
@classmethod
|
| 69 |
+
def teardown_class(cls):
|
| 70 |
+
for finalizer in cls.finalizers:
|
| 71 |
+
finalizer()
|
| 72 |
+
|
| 73 |
+
def test_resource_listdir(self):
|
| 74 |
+
import mod # pyright: ignore[reportMissingImports] # Temporary package for test
|
| 75 |
+
|
| 76 |
+
zp = pkg_resources.ZipProvider(mod)
|
| 77 |
+
|
| 78 |
+
expected_root = ['data.dat', 'mod.py', 'subdir']
|
| 79 |
+
assert sorted(zp.resource_listdir('')) == expected_root
|
| 80 |
+
|
| 81 |
+
expected_subdir = ['data2.dat', 'mod2.py']
|
| 82 |
+
assert sorted(zp.resource_listdir('subdir')) == expected_subdir
|
| 83 |
+
assert sorted(zp.resource_listdir('subdir/')) == expected_subdir
|
| 84 |
+
|
| 85 |
+
assert zp.resource_listdir('nonexistent') == []
|
| 86 |
+
assert zp.resource_listdir('nonexistent/') == []
|
| 87 |
+
|
| 88 |
+
import mod2 # pyright: ignore[reportMissingImports] # Temporary package for test
|
| 89 |
+
|
| 90 |
+
zp2 = pkg_resources.ZipProvider(mod2)
|
| 91 |
+
|
| 92 |
+
assert sorted(zp2.resource_listdir('')) == expected_subdir
|
| 93 |
+
|
| 94 |
+
assert zp2.resource_listdir('subdir') == []
|
| 95 |
+
assert zp2.resource_listdir('subdir/') == []
|
| 96 |
+
|
| 97 |
+
def test_resource_filename_rewrites_on_change(self):
|
| 98 |
+
"""
|
| 99 |
+
If a previous call to get_resource_filename has saved the file, but
|
| 100 |
+
the file has been subsequently mutated with different file of the
|
| 101 |
+
same size and modification time, it should not be overwritten on a
|
| 102 |
+
subsequent call to get_resource_filename.
|
| 103 |
+
"""
|
| 104 |
+
import mod # pyright: ignore[reportMissingImports] # Temporary package for test
|
| 105 |
+
|
| 106 |
+
manager = pkg_resources.ResourceManager()
|
| 107 |
+
zp = pkg_resources.ZipProvider(mod)
|
| 108 |
+
filename = zp.get_resource_filename(manager, 'data.dat')
|
| 109 |
+
actual = datetime.datetime.fromtimestamp(os.stat(filename).st_mtime)
|
| 110 |
+
assert actual == self.ref_time
|
| 111 |
+
f = open(filename, 'w', encoding="utf-8")
|
| 112 |
+
f.write('hello, world?')
|
| 113 |
+
f.close()
|
| 114 |
+
ts = self.ref_time.timestamp()
|
| 115 |
+
os.utime(filename, (ts, ts))
|
| 116 |
+
filename = zp.get_resource_filename(manager, 'data.dat')
|
| 117 |
+
with open(filename, encoding="utf-8") as f:
|
| 118 |
+
assert f.read() == 'hello, world!'
|
| 119 |
+
manager.cleanup_resources()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class TestResourceManager:
|
| 123 |
+
def test_get_cache_path(self):
|
| 124 |
+
mgr = pkg_resources.ResourceManager()
|
| 125 |
+
path = mgr.get_cache_path('foo')
|
| 126 |
+
type_ = str(type(path))
|
| 127 |
+
message = "Unexpected type from get_cache_path: " + type_
|
| 128 |
+
assert isinstance(path, str), message
|
| 129 |
+
|
| 130 |
+
def test_get_cache_path_race(self, tmpdir):
|
| 131 |
+
# Patch to os.path.isdir to create a race condition
|
| 132 |
+
def patched_isdir(dirname, unpatched_isdir=pkg_resources.isdir):
|
| 133 |
+
patched_isdir.dirnames.append(dirname)
|
| 134 |
+
|
| 135 |
+
was_dir = unpatched_isdir(dirname)
|
| 136 |
+
if not was_dir:
|
| 137 |
+
os.makedirs(dirname)
|
| 138 |
+
return was_dir
|
| 139 |
+
|
| 140 |
+
patched_isdir.dirnames = []
|
| 141 |
+
|
| 142 |
+
# Get a cache path with a "race condition"
|
| 143 |
+
mgr = pkg_resources.ResourceManager()
|
| 144 |
+
mgr.set_extraction_path(str(tmpdir))
|
| 145 |
+
|
| 146 |
+
archive_name = os.sep.join(('foo', 'bar', 'baz'))
|
| 147 |
+
with mock.patch.object(pkg_resources, 'isdir', new=patched_isdir):
|
| 148 |
+
mgr.get_cache_path(archive_name)
|
| 149 |
+
|
| 150 |
+
# Because this test relies on the implementation details of this
|
| 151 |
+
# function, these assertions are a sentinel to ensure that the
|
| 152 |
+
# test suite will not fail silently if the implementation changes.
|
| 153 |
+
called_dirnames = patched_isdir.dirnames
|
| 154 |
+
assert len(called_dirnames) == 2
|
| 155 |
+
assert called_dirnames[0].split(os.sep)[-2:] == ['foo', 'bar']
|
| 156 |
+
assert called_dirnames[1].split(os.sep)[-1:] == ['foo']
|
| 157 |
+
|
| 158 |
+
"""
|
| 159 |
+
Tests to ensure that pkg_resources runs independently from setuptools.
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
def test_setuptools_not_imported(self):
|
| 163 |
+
"""
|
| 164 |
+
In a separate Python environment, import pkg_resources and assert
|
| 165 |
+
that action doesn't cause setuptools to be imported.
|
| 166 |
+
"""
|
| 167 |
+
lines = (
|
| 168 |
+
'import pkg_resources',
|
| 169 |
+
'import sys',
|
| 170 |
+
('assert "setuptools" not in sys.modules, "setuptools was imported"'),
|
| 171 |
+
)
|
| 172 |
+
cmd = [sys.executable, '-c', '; '.join(lines)]
|
| 173 |
+
subprocess.check_call(cmd)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def make_test_distribution(metadata_path, metadata):
|
| 177 |
+
"""
|
| 178 |
+
Make a test Distribution object, and return it.
|
| 179 |
+
|
| 180 |
+
:param metadata_path: the path to the metadata file that should be
|
| 181 |
+
created. This should be inside a distribution directory that should
|
| 182 |
+
also be created. For example, an argument value might end with
|
| 183 |
+
"<project>.dist-info/METADATA".
|
| 184 |
+
:param metadata: the desired contents of the metadata file, as bytes.
|
| 185 |
+
"""
|
| 186 |
+
dist_dir = os.path.dirname(metadata_path)
|
| 187 |
+
os.mkdir(dist_dir)
|
| 188 |
+
with open(metadata_path, 'wb') as f:
|
| 189 |
+
f.write(metadata)
|
| 190 |
+
dists = list(pkg_resources.distributions_from_metadata(dist_dir))
|
| 191 |
+
(dist,) = dists
|
| 192 |
+
|
| 193 |
+
return dist
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def test_get_metadata__bad_utf8(tmpdir):
|
| 197 |
+
"""
|
| 198 |
+
Test a metadata file with bytes that can't be decoded as utf-8.
|
| 199 |
+
"""
|
| 200 |
+
filename = 'METADATA'
|
| 201 |
+
# Convert the tmpdir LocalPath object to a string before joining.
|
| 202 |
+
metadata_path = os.path.join(str(tmpdir), 'foo.dist-info', filename)
|
| 203 |
+
# Encode a non-ascii string with the wrong encoding (not utf-8).
|
| 204 |
+
metadata = 'née'.encode('iso-8859-1')
|
| 205 |
+
dist = make_test_distribution(metadata_path, metadata=metadata)
|
| 206 |
+
|
| 207 |
+
with pytest.raises(UnicodeDecodeError) as excinfo:
|
| 208 |
+
dist.get_metadata(filename)
|
| 209 |
+
|
| 210 |
+
exc = excinfo.value
|
| 211 |
+
actual = str(exc)
|
| 212 |
+
expected = (
|
| 213 |
+
# The error message starts with "'utf-8' codec ..." However, the
|
| 214 |
+
# spelling of "utf-8" can vary (e.g. "utf8") so we don't include it
|
| 215 |
+
"codec can't decode byte 0xe9 in position 1: "
|
| 216 |
+
'invalid continuation byte in METADATA file at path: '
|
| 217 |
+
)
|
| 218 |
+
assert expected in actual, f'actual: {actual}'
|
| 219 |
+
assert actual.endswith(metadata_path), f'actual: {actual}'
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def make_distribution_no_version(tmpdir, basename):
|
| 223 |
+
"""
|
| 224 |
+
Create a distribution directory with no file containing the version.
|
| 225 |
+
"""
|
| 226 |
+
dist_dir = tmpdir / basename
|
| 227 |
+
dist_dir.ensure_dir()
|
| 228 |
+
# Make the directory non-empty so distributions_from_metadata()
|
| 229 |
+
# will detect it and yield it.
|
| 230 |
+
dist_dir.join('temp.txt').ensure()
|
| 231 |
+
|
| 232 |
+
dists = list(pkg_resources.distributions_from_metadata(dist_dir))
|
| 233 |
+
assert len(dists) == 1
|
| 234 |
+
(dist,) = dists
|
| 235 |
+
|
| 236 |
+
return dist, dist_dir
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
@pytest.mark.parametrize(
|
| 240 |
+
("suffix", "expected_filename", "expected_dist_type"),
|
| 241 |
+
[
|
| 242 |
+
('egg-info', 'PKG-INFO', EggInfoDistribution),
|
| 243 |
+
('dist-info', 'METADATA', DistInfoDistribution),
|
| 244 |
+
],
|
| 245 |
+
)
|
| 246 |
+
@pytest.mark.xfail(
|
| 247 |
+
sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
|
| 248 |
+
reason="https://github.com/python/cpython/issues/103632",
|
| 249 |
+
)
|
| 250 |
+
def test_distribution_version_missing(
|
| 251 |
+
tmpdir, suffix, expected_filename, expected_dist_type
|
| 252 |
+
):
|
| 253 |
+
"""
|
| 254 |
+
Test Distribution.version when the "Version" header is missing.
|
| 255 |
+
"""
|
| 256 |
+
basename = f'foo.{suffix}'
|
| 257 |
+
dist, dist_dir = make_distribution_no_version(tmpdir, basename)
|
| 258 |
+
|
| 259 |
+
expected_text = (
|
| 260 |
+
f"Missing 'Version:' header and/or {expected_filename} file at path: "
|
| 261 |
+
)
|
| 262 |
+
metadata_path = os.path.join(dist_dir, expected_filename)
|
| 263 |
+
|
| 264 |
+
# Now check the exception raised when the "version" attribute is accessed.
|
| 265 |
+
with pytest.raises(ValueError) as excinfo:
|
| 266 |
+
dist.version
|
| 267 |
+
|
| 268 |
+
err = str(excinfo.value)
|
| 269 |
+
# Include a string expression after the assert so the full strings
|
| 270 |
+
# will be visible for inspection on failure.
|
| 271 |
+
assert expected_text in err, str((expected_text, err))
|
| 272 |
+
|
| 273 |
+
# Also check the args passed to the ValueError.
|
| 274 |
+
msg, dist = excinfo.value.args
|
| 275 |
+
assert expected_text in msg
|
| 276 |
+
# Check that the message portion contains the path.
|
| 277 |
+
assert metadata_path in msg, str((metadata_path, msg))
|
| 278 |
+
assert type(dist) is expected_dist_type
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
@pytest.mark.xfail(
|
| 282 |
+
sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
|
| 283 |
+
reason="https://github.com/python/cpython/issues/103632",
|
| 284 |
+
)
|
| 285 |
+
def test_distribution_version_missing_undetected_path():
|
| 286 |
+
"""
|
| 287 |
+
Test Distribution.version when the "Version" header is missing and
|
| 288 |
+
the path can't be detected.
|
| 289 |
+
"""
|
| 290 |
+
# Create a Distribution object with no metadata argument, which results
|
| 291 |
+
# in an empty metadata provider.
|
| 292 |
+
dist = Distribution('/foo')
|
| 293 |
+
with pytest.raises(ValueError) as excinfo:
|
| 294 |
+
dist.version
|
| 295 |
+
|
| 296 |
+
msg, dist = excinfo.value.args
|
| 297 |
+
expected = (
|
| 298 |
+
"Missing 'Version:' header and/or PKG-INFO file at path: [could not detect]"
|
| 299 |
+
)
|
| 300 |
+
assert msg == expected
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
@pytest.mark.parametrize('only', [False, True])
|
| 304 |
+
def test_dist_info_is_not_dir(tmp_path, only):
|
| 305 |
+
"""Test path containing a file with dist-info extension."""
|
| 306 |
+
dist_info = tmp_path / 'foobar.dist-info'
|
| 307 |
+
dist_info.touch()
|
| 308 |
+
assert not pkg_resources.dist_factory(str(tmp_path), str(dist_info), only)
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
def test_macos_vers_fallback(monkeypatch, tmp_path):
|
| 312 |
+
"""Regression test for pkg_resources._macos_vers"""
|
| 313 |
+
orig_open = builtins.open
|
| 314 |
+
|
| 315 |
+
# Pretend we need to use the plist file
|
| 316 |
+
monkeypatch.setattr('platform.mac_ver', mock.Mock(return_value=('', (), '')))
|
| 317 |
+
|
| 318 |
+
# Create fake content for the fake plist file
|
| 319 |
+
with open(tmp_path / 'fake.plist', 'wb') as fake_file:
|
| 320 |
+
plistlib.dump({"ProductVersion": "11.4"}, fake_file)
|
| 321 |
+
|
| 322 |
+
# Pretend the fake file exists
|
| 323 |
+
monkeypatch.setattr('os.path.exists', mock.Mock(return_value=True))
|
| 324 |
+
|
| 325 |
+
def fake_open(file, *args, **kwargs):
|
| 326 |
+
return orig_open(tmp_path / 'fake.plist', *args, **kwargs)
|
| 327 |
+
|
| 328 |
+
# Ensure that the _macos_vers works correctly
|
| 329 |
+
with mock.patch('builtins.open', mock.Mock(side_effect=fake_open)) as m:
|
| 330 |
+
pkg_resources._macos_vers.cache_clear()
|
| 331 |
+
assert pkg_resources._macos_vers() == ["11", "4"]
|
| 332 |
+
pkg_resources._macos_vers.cache_clear()
|
| 333 |
+
|
| 334 |
+
m.assert_called()
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
class TestDeepVersionLookupDistutils:
|
| 338 |
+
@pytest.fixture
|
| 339 |
+
def env(self, tmpdir):
|
| 340 |
+
"""
|
| 341 |
+
Create a package environment, similar to a virtualenv,
|
| 342 |
+
in which packages are installed.
|
| 343 |
+
"""
|
| 344 |
+
|
| 345 |
+
class Environment(str):
|
| 346 |
+
pass
|
| 347 |
+
|
| 348 |
+
env = Environment(tmpdir)
|
| 349 |
+
tmpdir.chmod(stat.S_IRWXU)
|
| 350 |
+
subs = 'home', 'lib', 'scripts', 'data', 'egg-base'
|
| 351 |
+
env.paths = dict((dirname, str(tmpdir / dirname)) for dirname in subs)
|
| 352 |
+
list(map(os.mkdir, env.paths.values()))
|
| 353 |
+
return env
|
| 354 |
+
|
| 355 |
+
def create_foo_pkg(self, env, version):
|
| 356 |
+
"""
|
| 357 |
+
Create a foo package installed (distutils-style) to env.paths['lib']
|
| 358 |
+
as version.
|
| 359 |
+
"""
|
| 360 |
+
ld = "This package has unicode metadata! ❄"
|
| 361 |
+
attrs = dict(name='foo', version=version, long_description=ld)
|
| 362 |
+
dist = distutils.dist.Distribution(attrs)
|
| 363 |
+
iei_cmd = distutils.command.install_egg_info.install_egg_info(dist)
|
| 364 |
+
iei_cmd.initialize_options()
|
| 365 |
+
iei_cmd.install_dir = env.paths['lib']
|
| 366 |
+
iei_cmd.finalize_options()
|
| 367 |
+
iei_cmd.run()
|
| 368 |
+
|
| 369 |
+
def test_version_resolved_from_egg_info(self, env):
|
| 370 |
+
version = '1.11.0.dev0+2329eae'
|
| 371 |
+
self.create_foo_pkg(env, version)
|
| 372 |
+
|
| 373 |
+
# this requirement parsing will raise a VersionConflict unless the
|
| 374 |
+
# .egg-info file is parsed (see #419 on BitBucket)
|
| 375 |
+
req = pkg_resources.Requirement.parse('foo>=1.9')
|
| 376 |
+
dist = pkg_resources.WorkingSet([env.paths['lib']]).find(req)
|
| 377 |
+
assert dist.version == version
|
| 378 |
+
|
| 379 |
+
@pytest.mark.parametrize(
|
| 380 |
+
("unnormalized", "normalized"),
|
| 381 |
+
[
|
| 382 |
+
('foo', 'foo'),
|
| 383 |
+
('foo/', 'foo'),
|
| 384 |
+
('foo/bar', 'foo/bar'),
|
| 385 |
+
('foo/bar/', 'foo/bar'),
|
| 386 |
+
],
|
| 387 |
+
)
|
| 388 |
+
def test_normalize_path_trailing_sep(self, unnormalized, normalized):
|
| 389 |
+
"""Ensure the trailing slash is cleaned for path comparison.
|
| 390 |
+
|
| 391 |
+
See pypa/setuptools#1519.
|
| 392 |
+
"""
|
| 393 |
+
result_from_unnormalized = pkg_resources.normalize_path(unnormalized)
|
| 394 |
+
result_from_normalized = pkg_resources.normalize_path(normalized)
|
| 395 |
+
assert result_from_unnormalized == result_from_normalized
|
| 396 |
+
|
| 397 |
+
@pytest.mark.skipif(
|
| 398 |
+
os.path.normcase('A') != os.path.normcase('a'),
|
| 399 |
+
reason='Testing case-insensitive filesystems.',
|
| 400 |
+
)
|
| 401 |
+
@pytest.mark.parametrize(
|
| 402 |
+
("unnormalized", "normalized"),
|
| 403 |
+
[
|
| 404 |
+
('MiXeD/CasE', 'mixed/case'),
|
| 405 |
+
],
|
| 406 |
+
)
|
| 407 |
+
def test_normalize_path_normcase(self, unnormalized, normalized):
|
| 408 |
+
"""Ensure mixed case is normalized on case-insensitive filesystems."""
|
| 409 |
+
result_from_unnormalized = pkg_resources.normalize_path(unnormalized)
|
| 410 |
+
result_from_normalized = pkg_resources.normalize_path(normalized)
|
| 411 |
+
assert result_from_unnormalized == result_from_normalized
|
| 412 |
+
|
| 413 |
+
@pytest.mark.skipif(
|
| 414 |
+
os.path.sep != '\\',
|
| 415 |
+
reason='Testing systems using backslashes as path separators.',
|
| 416 |
+
)
|
| 417 |
+
@pytest.mark.parametrize(
|
| 418 |
+
("unnormalized", "expected"),
|
| 419 |
+
[
|
| 420 |
+
('forward/slash', 'forward\\slash'),
|
| 421 |
+
('forward/slash/', 'forward\\slash'),
|
| 422 |
+
('backward\\slash\\', 'backward\\slash'),
|
| 423 |
+
],
|
| 424 |
+
)
|
| 425 |
+
def test_normalize_path_backslash_sep(self, unnormalized, expected):
|
| 426 |
+
"""Ensure path seps are cleaned on backslash path sep systems."""
|
| 427 |
+
result = pkg_resources.normalize_path(unnormalized)
|
| 428 |
+
assert result.endswith(expected)
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
class TestWorkdirRequire:
|
| 432 |
+
def fake_site_packages(self, tmp_path, monkeypatch, dist_files):
|
| 433 |
+
site_packages = tmp_path / "site-packages"
|
| 434 |
+
site_packages.mkdir()
|
| 435 |
+
for file, content in self.FILES.items():
|
| 436 |
+
path = site_packages / file
|
| 437 |
+
path.parent.mkdir(exist_ok=True, parents=True)
|
| 438 |
+
path.write_text(inspect.cleandoc(content), encoding="utf-8")
|
| 439 |
+
|
| 440 |
+
monkeypatch.setattr(sys, "path", [site_packages])
|
| 441 |
+
return os.fspath(site_packages)
|
| 442 |
+
|
| 443 |
+
FILES = {
|
| 444 |
+
"pkg1_mod-1.2.3.dist-info/METADATA": """
|
| 445 |
+
Metadata-Version: 2.4
|
| 446 |
+
Name: pkg1.mod
|
| 447 |
+
Version: 1.2.3
|
| 448 |
+
""",
|
| 449 |
+
"pkg2.mod-0.42.dist-info/METADATA": """
|
| 450 |
+
Metadata-Version: 2.1
|
| 451 |
+
Name: pkg2.mod
|
| 452 |
+
Version: 0.42
|
| 453 |
+
""",
|
| 454 |
+
"pkg3_mod.egg-info/PKG-INFO": """
|
| 455 |
+
Name: pkg3.mod
|
| 456 |
+
Version: 1.2.3.4
|
| 457 |
+
""",
|
| 458 |
+
"pkg4.mod.egg-info/PKG-INFO": """
|
| 459 |
+
Name: pkg4.mod
|
| 460 |
+
Version: 0.42.1
|
| 461 |
+
""",
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
@pytest.mark.parametrize(
|
| 465 |
+
("version", "requirement"),
|
| 466 |
+
[
|
| 467 |
+
("1.2.3", "pkg1.mod>=1"),
|
| 468 |
+
("0.42", "pkg2.mod>=0.4"),
|
| 469 |
+
("1.2.3.4", "pkg3.mod<=2"),
|
| 470 |
+
("0.42.1", "pkg4.mod>0.2,<1"),
|
| 471 |
+
],
|
| 472 |
+
)
|
| 473 |
+
def test_require_non_normalised_name(
|
| 474 |
+
self, tmp_path, monkeypatch, version, requirement
|
| 475 |
+
):
|
| 476 |
+
# https://github.com/pypa/setuptools/issues/4853
|
| 477 |
+
site_packages = self.fake_site_packages(tmp_path, monkeypatch, self.FILES)
|
| 478 |
+
ws = pkg_resources.WorkingSet([site_packages])
|
| 479 |
+
|
| 480 |
+
for req in [requirement, requirement.replace(".", "-")]:
|
| 481 |
+
[dist] = ws.require(req)
|
| 482 |
+
assert dist.version == version
|
| 483 |
+
assert os.path.samefile(
|
| 484 |
+
os.path.commonpath([dist.location, site_packages]), site_packages
|
| 485 |
+
)
|
lib/python3.11/site-packages/pkg_resources/tests/test_resources.py
ADDED
|
@@ -0,0 +1,869 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
import os
|
| 3 |
+
import platform
|
| 4 |
+
import string
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
from packaging.specifiers import SpecifierSet
|
| 9 |
+
|
| 10 |
+
import pkg_resources
|
| 11 |
+
from pkg_resources import (
|
| 12 |
+
Distribution,
|
| 13 |
+
EntryPoint,
|
| 14 |
+
Requirement,
|
| 15 |
+
VersionConflict,
|
| 16 |
+
WorkingSet,
|
| 17 |
+
parse_requirements,
|
| 18 |
+
parse_version,
|
| 19 |
+
safe_name,
|
| 20 |
+
safe_version,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# from Python 3.6 docs. Available from itertools on Python 3.10
|
| 25 |
+
def pairwise(iterable):
|
| 26 |
+
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
|
| 27 |
+
a, b = itertools.tee(iterable)
|
| 28 |
+
next(b, None)
|
| 29 |
+
return zip(a, b)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Metadata(pkg_resources.EmptyProvider):
|
| 33 |
+
"""Mock object to return metadata as if from an on-disk distribution"""
|
| 34 |
+
|
| 35 |
+
def __init__(self, *pairs) -> None:
|
| 36 |
+
self.metadata = dict(pairs)
|
| 37 |
+
|
| 38 |
+
def has_metadata(self, name) -> bool:
|
| 39 |
+
return name in self.metadata
|
| 40 |
+
|
| 41 |
+
def get_metadata(self, name):
|
| 42 |
+
return self.metadata[name]
|
| 43 |
+
|
| 44 |
+
def get_metadata_lines(self, name):
|
| 45 |
+
return pkg_resources.yield_lines(self.get_metadata(name))
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
dist_from_fn = pkg_resources.Distribution.from_filename
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class TestDistro:
|
| 52 |
+
def testCollection(self):
|
| 53 |
+
# empty path should produce no distributions
|
| 54 |
+
ad = pkg_resources.Environment([], platform=None, python=None)
|
| 55 |
+
assert list(ad) == []
|
| 56 |
+
assert ad['FooPkg'] == []
|
| 57 |
+
ad.add(dist_from_fn("FooPkg-1.3_1.egg"))
|
| 58 |
+
ad.add(dist_from_fn("FooPkg-1.4-py2.4-win32.egg"))
|
| 59 |
+
ad.add(dist_from_fn("FooPkg-1.2-py2.4.egg"))
|
| 60 |
+
|
| 61 |
+
# Name is in there now
|
| 62 |
+
assert ad['FooPkg']
|
| 63 |
+
# But only 1 package
|
| 64 |
+
assert list(ad) == ['foopkg']
|
| 65 |
+
|
| 66 |
+
# Distributions sort by version
|
| 67 |
+
expected = ['1.4', '1.3-1', '1.2']
|
| 68 |
+
assert [dist.version for dist in ad['FooPkg']] == expected
|
| 69 |
+
|
| 70 |
+
# Removing a distribution leaves sequence alone
|
| 71 |
+
ad.remove(ad['FooPkg'][1])
|
| 72 |
+
assert [dist.version for dist in ad['FooPkg']] == ['1.4', '1.2']
|
| 73 |
+
|
| 74 |
+
# And inserting adds them in order
|
| 75 |
+
ad.add(dist_from_fn("FooPkg-1.9.egg"))
|
| 76 |
+
assert [dist.version for dist in ad['FooPkg']] == ['1.9', '1.4', '1.2']
|
| 77 |
+
|
| 78 |
+
ws = WorkingSet([])
|
| 79 |
+
foo12 = dist_from_fn("FooPkg-1.2-py2.4.egg")
|
| 80 |
+
foo14 = dist_from_fn("FooPkg-1.4-py2.4-win32.egg")
|
| 81 |
+
(req,) = parse_requirements("FooPkg>=1.3")
|
| 82 |
+
|
| 83 |
+
# Nominal case: no distros on path, should yield all applicable
|
| 84 |
+
assert ad.best_match(req, ws).version == '1.9'
|
| 85 |
+
# If a matching distro is already installed, should return only that
|
| 86 |
+
ws.add(foo14)
|
| 87 |
+
assert ad.best_match(req, ws).version == '1.4'
|
| 88 |
+
|
| 89 |
+
# If the first matching distro is unsuitable, it's a version conflict
|
| 90 |
+
ws = WorkingSet([])
|
| 91 |
+
ws.add(foo12)
|
| 92 |
+
ws.add(foo14)
|
| 93 |
+
with pytest.raises(VersionConflict):
|
| 94 |
+
ad.best_match(req, ws)
|
| 95 |
+
|
| 96 |
+
# If more than one match on the path, the first one takes precedence
|
| 97 |
+
ws = WorkingSet([])
|
| 98 |
+
ws.add(foo14)
|
| 99 |
+
ws.add(foo12)
|
| 100 |
+
ws.add(foo14)
|
| 101 |
+
assert ad.best_match(req, ws).version == '1.4'
|
| 102 |
+
|
| 103 |
+
def checkFooPkg(self, d):
|
| 104 |
+
assert d.project_name == "FooPkg"
|
| 105 |
+
assert d.key == "foopkg"
|
| 106 |
+
assert d.version == "1.3.post1"
|
| 107 |
+
assert d.py_version == "2.4"
|
| 108 |
+
assert d.platform == "win32"
|
| 109 |
+
assert d.parsed_version == parse_version("1.3-1")
|
| 110 |
+
|
| 111 |
+
def testDistroBasics(self):
|
| 112 |
+
d = Distribution(
|
| 113 |
+
"/some/path",
|
| 114 |
+
project_name="FooPkg",
|
| 115 |
+
version="1.3-1",
|
| 116 |
+
py_version="2.4",
|
| 117 |
+
platform="win32",
|
| 118 |
+
)
|
| 119 |
+
self.checkFooPkg(d)
|
| 120 |
+
|
| 121 |
+
d = Distribution("/some/path")
|
| 122 |
+
assert d.py_version == f'{sys.version_info.major}.{sys.version_info.minor}'
|
| 123 |
+
assert d.platform is None
|
| 124 |
+
|
| 125 |
+
def testDistroParse(self):
|
| 126 |
+
d = dist_from_fn("FooPkg-1.3.post1-py2.4-win32.egg")
|
| 127 |
+
self.checkFooPkg(d)
|
| 128 |
+
d = dist_from_fn("FooPkg-1.3.post1-py2.4-win32.egg-info")
|
| 129 |
+
self.checkFooPkg(d)
|
| 130 |
+
|
| 131 |
+
def testDistroMetadata(self):
|
| 132 |
+
d = Distribution(
|
| 133 |
+
"/some/path",
|
| 134 |
+
project_name="FooPkg",
|
| 135 |
+
py_version="2.4",
|
| 136 |
+
platform="win32",
|
| 137 |
+
metadata=Metadata(('PKG-INFO', "Metadata-Version: 1.0\nVersion: 1.3-1\n")),
|
| 138 |
+
)
|
| 139 |
+
self.checkFooPkg(d)
|
| 140 |
+
|
| 141 |
+
def distRequires(self, txt):
|
| 142 |
+
return Distribution("/foo", metadata=Metadata(('depends.txt', txt)))
|
| 143 |
+
|
| 144 |
+
def checkRequires(self, dist, txt, extras=()):
|
| 145 |
+
assert list(dist.requires(extras)) == list(parse_requirements(txt))
|
| 146 |
+
|
| 147 |
+
def testDistroDependsSimple(self):
|
| 148 |
+
for v in "Twisted>=1.5", "Twisted>=1.5\nZConfig>=2.0":
|
| 149 |
+
self.checkRequires(self.distRequires(v), v)
|
| 150 |
+
|
| 151 |
+
needs_object_dir = pytest.mark.skipif(
|
| 152 |
+
not hasattr(object, '__dir__'),
|
| 153 |
+
reason='object.__dir__ necessary for self.__dir__ implementation',
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
def test_distribution_dir(self):
|
| 157 |
+
d = pkg_resources.Distribution()
|
| 158 |
+
dir(d)
|
| 159 |
+
|
| 160 |
+
@needs_object_dir
|
| 161 |
+
def test_distribution_dir_includes_provider_dir(self):
|
| 162 |
+
d = pkg_resources.Distribution()
|
| 163 |
+
before = d.__dir__()
|
| 164 |
+
assert 'test_attr' not in before
|
| 165 |
+
d._provider.test_attr = None
|
| 166 |
+
after = d.__dir__()
|
| 167 |
+
assert len(after) == len(before) + 1
|
| 168 |
+
assert 'test_attr' in after
|
| 169 |
+
|
| 170 |
+
@needs_object_dir
|
| 171 |
+
def test_distribution_dir_ignores_provider_dir_leading_underscore(self):
|
| 172 |
+
d = pkg_resources.Distribution()
|
| 173 |
+
before = d.__dir__()
|
| 174 |
+
assert '_test_attr' not in before
|
| 175 |
+
d._provider._test_attr = None
|
| 176 |
+
after = d.__dir__()
|
| 177 |
+
assert len(after) == len(before)
|
| 178 |
+
assert '_test_attr' not in after
|
| 179 |
+
|
| 180 |
+
def testResolve(self):
|
| 181 |
+
ad = pkg_resources.Environment([])
|
| 182 |
+
ws = WorkingSet([])
|
| 183 |
+
# Resolving no requirements -> nothing to install
|
| 184 |
+
assert list(ws.resolve([], ad)) == []
|
| 185 |
+
# Request something not in the collection -> DistributionNotFound
|
| 186 |
+
with pytest.raises(pkg_resources.DistributionNotFound):
|
| 187 |
+
ws.resolve(parse_requirements("Foo"), ad)
|
| 188 |
+
|
| 189 |
+
Foo = Distribution.from_filename(
|
| 190 |
+
"/foo_dir/Foo-1.2.egg",
|
| 191 |
+
metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0")),
|
| 192 |
+
)
|
| 193 |
+
ad.add(Foo)
|
| 194 |
+
ad.add(Distribution.from_filename("Foo-0.9.egg"))
|
| 195 |
+
|
| 196 |
+
# Request thing(s) that are available -> list to activate
|
| 197 |
+
for i in range(3):
|
| 198 |
+
targets = list(ws.resolve(parse_requirements("Foo"), ad))
|
| 199 |
+
assert targets == [Foo]
|
| 200 |
+
list(map(ws.add, targets))
|
| 201 |
+
with pytest.raises(VersionConflict):
|
| 202 |
+
ws.resolve(parse_requirements("Foo==0.9"), ad)
|
| 203 |
+
ws = WorkingSet([]) # reset
|
| 204 |
+
|
| 205 |
+
# Request an extra that causes an unresolved dependency for "Baz"
|
| 206 |
+
with pytest.raises(pkg_resources.DistributionNotFound):
|
| 207 |
+
ws.resolve(parse_requirements("Foo[bar]"), ad)
|
| 208 |
+
Baz = Distribution.from_filename(
|
| 209 |
+
"/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
|
| 210 |
+
)
|
| 211 |
+
ad.add(Baz)
|
| 212 |
+
|
| 213 |
+
# Activation list now includes resolved dependency
|
| 214 |
+
assert list(ws.resolve(parse_requirements("Foo[bar]"), ad)) == [Foo, Baz]
|
| 215 |
+
# Requests for conflicting versions produce VersionConflict
|
| 216 |
+
with pytest.raises(VersionConflict) as vc:
|
| 217 |
+
ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
|
| 218 |
+
|
| 219 |
+
msg = 'Foo 0.9 is installed but Foo==1.2 is required'
|
| 220 |
+
assert vc.value.report() == msg
|
| 221 |
+
|
| 222 |
+
def test_environment_marker_evaluation_negative(self):
|
| 223 |
+
"""Environment markers are evaluated at resolution time."""
|
| 224 |
+
ad = pkg_resources.Environment([])
|
| 225 |
+
ws = WorkingSet([])
|
| 226 |
+
res = ws.resolve(parse_requirements("Foo;python_version<'2'"), ad)
|
| 227 |
+
assert list(res) == []
|
| 228 |
+
|
| 229 |
+
def test_environment_marker_evaluation_positive(self):
|
| 230 |
+
ad = pkg_resources.Environment([])
|
| 231 |
+
ws = WorkingSet([])
|
| 232 |
+
Foo = Distribution.from_filename("/foo_dir/Foo-1.2.dist-info")
|
| 233 |
+
ad.add(Foo)
|
| 234 |
+
res = ws.resolve(parse_requirements("Foo;python_version>='2'"), ad)
|
| 235 |
+
assert list(res) == [Foo]
|
| 236 |
+
|
| 237 |
+
def test_environment_marker_evaluation_called(self):
|
| 238 |
+
"""
|
| 239 |
+
If one package foo requires bar without any extras,
|
| 240 |
+
markers should pass for bar without extras.
|
| 241 |
+
"""
|
| 242 |
+
(parent_req,) = parse_requirements("foo")
|
| 243 |
+
(req,) = parse_requirements("bar;python_version>='2'")
|
| 244 |
+
req_extras = pkg_resources._ReqExtras({req: parent_req.extras})
|
| 245 |
+
assert req_extras.markers_pass(req)
|
| 246 |
+
|
| 247 |
+
(parent_req,) = parse_requirements("foo[]")
|
| 248 |
+
(req,) = parse_requirements("bar;python_version>='2'")
|
| 249 |
+
req_extras = pkg_resources._ReqExtras({req: parent_req.extras})
|
| 250 |
+
assert req_extras.markers_pass(req)
|
| 251 |
+
|
| 252 |
+
def test_marker_evaluation_with_extras(self):
|
| 253 |
+
"""Extras are also evaluated as markers at resolution time."""
|
| 254 |
+
ad = pkg_resources.Environment([])
|
| 255 |
+
ws = WorkingSet([])
|
| 256 |
+
Foo = Distribution.from_filename(
|
| 257 |
+
"/foo_dir/Foo-1.2.dist-info",
|
| 258 |
+
metadata=Metadata((
|
| 259 |
+
"METADATA",
|
| 260 |
+
"Provides-Extra: baz\nRequires-Dist: quux; extra=='baz'",
|
| 261 |
+
)),
|
| 262 |
+
)
|
| 263 |
+
ad.add(Foo)
|
| 264 |
+
assert list(ws.resolve(parse_requirements("Foo"), ad)) == [Foo]
|
| 265 |
+
quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
|
| 266 |
+
ad.add(quux)
|
| 267 |
+
res = list(ws.resolve(parse_requirements("Foo[baz]"), ad))
|
| 268 |
+
assert res == [Foo, quux]
|
| 269 |
+
|
| 270 |
+
def test_marker_evaluation_with_extras_normlized(self):
|
| 271 |
+
"""Extras are also evaluated as markers at resolution time."""
|
| 272 |
+
ad = pkg_resources.Environment([])
|
| 273 |
+
ws = WorkingSet([])
|
| 274 |
+
Foo = Distribution.from_filename(
|
| 275 |
+
"/foo_dir/Foo-1.2.dist-info",
|
| 276 |
+
metadata=Metadata((
|
| 277 |
+
"METADATA",
|
| 278 |
+
"Provides-Extra: baz-lightyear\n"
|
| 279 |
+
"Requires-Dist: quux; extra=='baz-lightyear'",
|
| 280 |
+
)),
|
| 281 |
+
)
|
| 282 |
+
ad.add(Foo)
|
| 283 |
+
assert list(ws.resolve(parse_requirements("Foo"), ad)) == [Foo]
|
| 284 |
+
quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
|
| 285 |
+
ad.add(quux)
|
| 286 |
+
res = list(ws.resolve(parse_requirements("Foo[baz-lightyear]"), ad))
|
| 287 |
+
assert res == [Foo, quux]
|
| 288 |
+
|
| 289 |
+
def test_marker_evaluation_with_multiple_extras(self):
|
| 290 |
+
ad = pkg_resources.Environment([])
|
| 291 |
+
ws = WorkingSet([])
|
| 292 |
+
Foo = Distribution.from_filename(
|
| 293 |
+
"/foo_dir/Foo-1.2.dist-info",
|
| 294 |
+
metadata=Metadata((
|
| 295 |
+
"METADATA",
|
| 296 |
+
"Provides-Extra: baz\n"
|
| 297 |
+
"Requires-Dist: quux; extra=='baz'\n"
|
| 298 |
+
"Provides-Extra: bar\n"
|
| 299 |
+
"Requires-Dist: fred; extra=='bar'\n",
|
| 300 |
+
)),
|
| 301 |
+
)
|
| 302 |
+
ad.add(Foo)
|
| 303 |
+
quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
|
| 304 |
+
ad.add(quux)
|
| 305 |
+
fred = Distribution.from_filename("/foo_dir/fred-0.1.dist-info")
|
| 306 |
+
ad.add(fred)
|
| 307 |
+
res = list(ws.resolve(parse_requirements("Foo[baz,bar]"), ad))
|
| 308 |
+
assert sorted(res) == [fred, quux, Foo]
|
| 309 |
+
|
| 310 |
+
def test_marker_evaluation_with_extras_loop(self):
|
| 311 |
+
ad = pkg_resources.Environment([])
|
| 312 |
+
ws = WorkingSet([])
|
| 313 |
+
a = Distribution.from_filename(
|
| 314 |
+
"/foo_dir/a-0.2.dist-info",
|
| 315 |
+
metadata=Metadata(("METADATA", "Requires-Dist: c[a]")),
|
| 316 |
+
)
|
| 317 |
+
b = Distribution.from_filename(
|
| 318 |
+
"/foo_dir/b-0.3.dist-info",
|
| 319 |
+
metadata=Metadata(("METADATA", "Requires-Dist: c[b]")),
|
| 320 |
+
)
|
| 321 |
+
c = Distribution.from_filename(
|
| 322 |
+
"/foo_dir/c-1.0.dist-info",
|
| 323 |
+
metadata=Metadata((
|
| 324 |
+
"METADATA",
|
| 325 |
+
"Provides-Extra: a\n"
|
| 326 |
+
"Requires-Dist: b;extra=='a'\n"
|
| 327 |
+
"Provides-Extra: b\n"
|
| 328 |
+
"Requires-Dist: foo;extra=='b'",
|
| 329 |
+
)),
|
| 330 |
+
)
|
| 331 |
+
foo = Distribution.from_filename("/foo_dir/foo-0.1.dist-info")
|
| 332 |
+
for dist in (a, b, c, foo):
|
| 333 |
+
ad.add(dist)
|
| 334 |
+
res = list(ws.resolve(parse_requirements("a"), ad))
|
| 335 |
+
assert res == [a, c, b, foo]
|
| 336 |
+
|
| 337 |
+
@pytest.mark.xfail(
|
| 338 |
+
sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
|
| 339 |
+
reason="https://github.com/python/cpython/issues/103632",
|
| 340 |
+
)
|
| 341 |
+
def testDistroDependsOptions(self):
|
| 342 |
+
d = self.distRequires(
|
| 343 |
+
"""
|
| 344 |
+
Twisted>=1.5
|
| 345 |
+
[docgen]
|
| 346 |
+
ZConfig>=2.0
|
| 347 |
+
docutils>=0.3
|
| 348 |
+
[fastcgi]
|
| 349 |
+
fcgiapp>=0.1"""
|
| 350 |
+
)
|
| 351 |
+
self.checkRequires(d, "Twisted>=1.5")
|
| 352 |
+
self.checkRequires(
|
| 353 |
+
d, "Twisted>=1.5 ZConfig>=2.0 docutils>=0.3".split(), ["docgen"]
|
| 354 |
+
)
|
| 355 |
+
self.checkRequires(d, "Twisted>=1.5 fcgiapp>=0.1".split(), ["fastcgi"])
|
| 356 |
+
self.checkRequires(
|
| 357 |
+
d,
|
| 358 |
+
"Twisted>=1.5 ZConfig>=2.0 docutils>=0.3 fcgiapp>=0.1".split(),
|
| 359 |
+
["docgen", "fastcgi"],
|
| 360 |
+
)
|
| 361 |
+
self.checkRequires(
|
| 362 |
+
d,
|
| 363 |
+
"Twisted>=1.5 fcgiapp>=0.1 ZConfig>=2.0 docutils>=0.3".split(),
|
| 364 |
+
["fastcgi", "docgen"],
|
| 365 |
+
)
|
| 366 |
+
with pytest.raises(pkg_resources.UnknownExtra):
|
| 367 |
+
d.requires(["foo"])
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
class TestWorkingSet:
|
| 371 |
+
def test_find_conflicting(self):
|
| 372 |
+
ws = WorkingSet([])
|
| 373 |
+
Foo = Distribution.from_filename("/foo_dir/Foo-1.2.egg")
|
| 374 |
+
ws.add(Foo)
|
| 375 |
+
|
| 376 |
+
# create a requirement that conflicts with Foo 1.2
|
| 377 |
+
req = next(parse_requirements("Foo<1.2"))
|
| 378 |
+
|
| 379 |
+
with pytest.raises(VersionConflict) as vc:
|
| 380 |
+
ws.find(req)
|
| 381 |
+
|
| 382 |
+
msg = 'Foo 1.2 is installed but Foo<1.2 is required'
|
| 383 |
+
assert vc.value.report() == msg
|
| 384 |
+
|
| 385 |
+
def test_resolve_conflicts_with_prior(self):
|
| 386 |
+
"""
|
| 387 |
+
A ContextualVersionConflict should be raised when a requirement
|
| 388 |
+
conflicts with a prior requirement for a different package.
|
| 389 |
+
"""
|
| 390 |
+
# Create installation where Foo depends on Baz 1.0 and Bar depends on
|
| 391 |
+
# Baz 2.0.
|
| 392 |
+
ws = WorkingSet([])
|
| 393 |
+
md = Metadata(('depends.txt', "Baz==1.0"))
|
| 394 |
+
Foo = Distribution.from_filename("/foo_dir/Foo-1.0.egg", metadata=md)
|
| 395 |
+
ws.add(Foo)
|
| 396 |
+
md = Metadata(('depends.txt', "Baz==2.0"))
|
| 397 |
+
Bar = Distribution.from_filename("/foo_dir/Bar-1.0.egg", metadata=md)
|
| 398 |
+
ws.add(Bar)
|
| 399 |
+
Baz = Distribution.from_filename("/foo_dir/Baz-1.0.egg")
|
| 400 |
+
ws.add(Baz)
|
| 401 |
+
Baz = Distribution.from_filename("/foo_dir/Baz-2.0.egg")
|
| 402 |
+
ws.add(Baz)
|
| 403 |
+
|
| 404 |
+
with pytest.raises(VersionConflict) as vc:
|
| 405 |
+
ws.resolve(parse_requirements("Foo\nBar\n"))
|
| 406 |
+
|
| 407 |
+
msg = "Baz 1.0 is installed but Baz==2.0 is required by "
|
| 408 |
+
msg += repr(set(['Bar']))
|
| 409 |
+
assert vc.value.report() == msg
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
class TestEntryPoints:
|
| 413 |
+
def assertfields(self, ep):
|
| 414 |
+
assert ep.name == "foo"
|
| 415 |
+
assert ep.module_name == "pkg_resources.tests.test_resources"
|
| 416 |
+
assert ep.attrs == ("TestEntryPoints",)
|
| 417 |
+
assert ep.extras == ("x",)
|
| 418 |
+
assert ep.load() is TestEntryPoints
|
| 419 |
+
expect = "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]"
|
| 420 |
+
assert str(ep) == expect
|
| 421 |
+
|
| 422 |
+
def setup_method(self, method):
|
| 423 |
+
self.dist = Distribution.from_filename(
|
| 424 |
+
"FooPkg-1.2-py2.4.egg", metadata=Metadata(('requires.txt', '[x]'))
|
| 425 |
+
)
|
| 426 |
+
|
| 427 |
+
def testBasics(self):
|
| 428 |
+
ep = EntryPoint(
|
| 429 |
+
"foo",
|
| 430 |
+
"pkg_resources.tests.test_resources",
|
| 431 |
+
["TestEntryPoints"],
|
| 432 |
+
["x"],
|
| 433 |
+
self.dist,
|
| 434 |
+
)
|
| 435 |
+
self.assertfields(ep)
|
| 436 |
+
|
| 437 |
+
def testParse(self):
|
| 438 |
+
s = "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]"
|
| 439 |
+
ep = EntryPoint.parse(s, self.dist)
|
| 440 |
+
self.assertfields(ep)
|
| 441 |
+
|
| 442 |
+
ep = EntryPoint.parse("bar baz= spammity[PING]")
|
| 443 |
+
assert ep.name == "bar baz"
|
| 444 |
+
assert ep.module_name == "spammity"
|
| 445 |
+
assert ep.attrs == ()
|
| 446 |
+
assert ep.extras == ("ping",)
|
| 447 |
+
|
| 448 |
+
ep = EntryPoint.parse(" fizzly = wocka:foo")
|
| 449 |
+
assert ep.name == "fizzly"
|
| 450 |
+
assert ep.module_name == "wocka"
|
| 451 |
+
assert ep.attrs == ("foo",)
|
| 452 |
+
assert ep.extras == ()
|
| 453 |
+
|
| 454 |
+
# plus in the name
|
| 455 |
+
spec = "html+mako = mako.ext.pygmentplugin:MakoHtmlLexer"
|
| 456 |
+
ep = EntryPoint.parse(spec)
|
| 457 |
+
assert ep.name == 'html+mako'
|
| 458 |
+
|
| 459 |
+
reject_specs = "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2"
|
| 460 |
+
|
| 461 |
+
@pytest.mark.parametrize("reject_spec", reject_specs)
|
| 462 |
+
def test_reject_spec(self, reject_spec):
|
| 463 |
+
with pytest.raises(ValueError):
|
| 464 |
+
EntryPoint.parse(reject_spec)
|
| 465 |
+
|
| 466 |
+
def test_printable_name(self):
|
| 467 |
+
"""
|
| 468 |
+
Allow any printable character in the name.
|
| 469 |
+
"""
|
| 470 |
+
# Create a name with all printable characters; strip the whitespace.
|
| 471 |
+
name = string.printable.strip()
|
| 472 |
+
spec = "{name} = module:attr".format(**locals())
|
| 473 |
+
ep = EntryPoint.parse(spec)
|
| 474 |
+
assert ep.name == name
|
| 475 |
+
|
| 476 |
+
def checkSubMap(self, m):
|
| 477 |
+
assert len(m) == len(self.submap_expect)
|
| 478 |
+
for key, ep in self.submap_expect.items():
|
| 479 |
+
assert m.get(key).name == ep.name
|
| 480 |
+
assert m.get(key).module_name == ep.module_name
|
| 481 |
+
assert sorted(m.get(key).attrs) == sorted(ep.attrs)
|
| 482 |
+
assert sorted(m.get(key).extras) == sorted(ep.extras)
|
| 483 |
+
|
| 484 |
+
submap_expect = dict(
|
| 485 |
+
feature1=EntryPoint('feature1', 'somemodule', ['somefunction']),
|
| 486 |
+
feature2=EntryPoint(
|
| 487 |
+
'feature2', 'another.module', ['SomeClass'], ['extra1', 'extra2']
|
| 488 |
+
),
|
| 489 |
+
feature3=EntryPoint('feature3', 'this.module', extras=['something']),
|
| 490 |
+
)
|
| 491 |
+
submap_str = """
|
| 492 |
+
# define features for blah blah
|
| 493 |
+
feature1 = somemodule:somefunction
|
| 494 |
+
feature2 = another.module:SomeClass [extra1,extra2]
|
| 495 |
+
feature3 = this.module [something]
|
| 496 |
+
"""
|
| 497 |
+
|
| 498 |
+
def testParseList(self):
|
| 499 |
+
self.checkSubMap(EntryPoint.parse_group("xyz", self.submap_str))
|
| 500 |
+
with pytest.raises(ValueError):
|
| 501 |
+
EntryPoint.parse_group("x a", "foo=bar")
|
| 502 |
+
with pytest.raises(ValueError):
|
| 503 |
+
EntryPoint.parse_group("x", ["foo=baz", "foo=bar"])
|
| 504 |
+
|
| 505 |
+
def testParseMap(self):
|
| 506 |
+
m = EntryPoint.parse_map({'xyz': self.submap_str})
|
| 507 |
+
self.checkSubMap(m['xyz'])
|
| 508 |
+
assert list(m.keys()) == ['xyz']
|
| 509 |
+
m = EntryPoint.parse_map("[xyz]\n" + self.submap_str)
|
| 510 |
+
self.checkSubMap(m['xyz'])
|
| 511 |
+
assert list(m.keys()) == ['xyz']
|
| 512 |
+
with pytest.raises(ValueError):
|
| 513 |
+
EntryPoint.parse_map(["[xyz]", "[xyz]"])
|
| 514 |
+
with pytest.raises(ValueError):
|
| 515 |
+
EntryPoint.parse_map(self.submap_str)
|
| 516 |
+
|
| 517 |
+
def testDeprecationWarnings(self):
|
| 518 |
+
ep = EntryPoint(
|
| 519 |
+
"foo", "pkg_resources.tests.test_resources", ["TestEntryPoints"], ["x"]
|
| 520 |
+
)
|
| 521 |
+
with pytest.warns(pkg_resources.PkgResourcesDeprecationWarning):
|
| 522 |
+
ep.load(require=False)
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
class TestRequirements:
|
| 526 |
+
def testBasics(self):
|
| 527 |
+
r = Requirement.parse("Twisted>=1.2")
|
| 528 |
+
assert str(r) == "Twisted>=1.2"
|
| 529 |
+
assert repr(r) == "Requirement.parse('Twisted>=1.2')"
|
| 530 |
+
assert r == Requirement("Twisted>=1.2")
|
| 531 |
+
assert r == Requirement("twisTed>=1.2")
|
| 532 |
+
assert r != Requirement("Twisted>=2.0")
|
| 533 |
+
assert r != Requirement("Zope>=1.2")
|
| 534 |
+
assert r != Requirement("Zope>=3.0")
|
| 535 |
+
assert r != Requirement("Twisted[extras]>=1.2")
|
| 536 |
+
|
| 537 |
+
def testOrdering(self):
|
| 538 |
+
r1 = Requirement("Twisted==1.2c1,>=1.2")
|
| 539 |
+
r2 = Requirement("Twisted>=1.2,==1.2c1")
|
| 540 |
+
assert r1 == r2
|
| 541 |
+
assert str(r1) == str(r2)
|
| 542 |
+
assert str(r2) == "Twisted==1.2c1,>=1.2"
|
| 543 |
+
assert Requirement("Twisted") != Requirement(
|
| 544 |
+
"Twisted @ https://localhost/twisted.zip"
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
def testBasicContains(self):
|
| 548 |
+
r = Requirement("Twisted>=1.2")
|
| 549 |
+
foo_dist = Distribution.from_filename("FooPkg-1.3_1.egg")
|
| 550 |
+
twist11 = Distribution.from_filename("Twisted-1.1.egg")
|
| 551 |
+
twist12 = Distribution.from_filename("Twisted-1.2.egg")
|
| 552 |
+
assert parse_version('1.2') in r
|
| 553 |
+
assert parse_version('1.1') not in r
|
| 554 |
+
assert '1.2' in r
|
| 555 |
+
assert '1.1' not in r
|
| 556 |
+
assert foo_dist not in r
|
| 557 |
+
assert twist11 not in r
|
| 558 |
+
assert twist12 in r
|
| 559 |
+
|
| 560 |
+
def testOptionsAndHashing(self):
|
| 561 |
+
r1 = Requirement.parse("Twisted[foo,bar]>=1.2")
|
| 562 |
+
r2 = Requirement.parse("Twisted[bar,FOO]>=1.2")
|
| 563 |
+
assert r1 == r2
|
| 564 |
+
assert set(r1.extras) == set(("foo", "bar"))
|
| 565 |
+
assert set(r2.extras) == set(("foo", "bar"))
|
| 566 |
+
assert hash(r1) == hash(r2)
|
| 567 |
+
assert hash(r1) == hash((
|
| 568 |
+
"twisted",
|
| 569 |
+
None,
|
| 570 |
+
SpecifierSet(">=1.2"),
|
| 571 |
+
frozenset(["foo", "bar"]),
|
| 572 |
+
None,
|
| 573 |
+
))
|
| 574 |
+
assert hash(
|
| 575 |
+
Requirement.parse("Twisted @ https://localhost/twisted.zip")
|
| 576 |
+
) == hash((
|
| 577 |
+
"twisted",
|
| 578 |
+
"https://localhost/twisted.zip",
|
| 579 |
+
SpecifierSet(),
|
| 580 |
+
frozenset(),
|
| 581 |
+
None,
|
| 582 |
+
))
|
| 583 |
+
|
| 584 |
+
def testVersionEquality(self):
|
| 585 |
+
r1 = Requirement.parse("foo==0.3a2")
|
| 586 |
+
r2 = Requirement.parse("foo!=0.3a4")
|
| 587 |
+
d = Distribution.from_filename
|
| 588 |
+
|
| 589 |
+
assert d("foo-0.3a4.egg") not in r1
|
| 590 |
+
assert d("foo-0.3a1.egg") not in r1
|
| 591 |
+
assert d("foo-0.3a4.egg") not in r2
|
| 592 |
+
|
| 593 |
+
assert d("foo-0.3a2.egg") in r1
|
| 594 |
+
assert d("foo-0.3a2.egg") in r2
|
| 595 |
+
assert d("foo-0.3a3.egg") in r2
|
| 596 |
+
assert d("foo-0.3a5.egg") in r2
|
| 597 |
+
|
| 598 |
+
def testSetuptoolsProjectName(self):
|
| 599 |
+
"""
|
| 600 |
+
The setuptools project should implement the setuptools package.
|
| 601 |
+
"""
|
| 602 |
+
|
| 603 |
+
assert Requirement.parse('setuptools').project_name == 'setuptools'
|
| 604 |
+
# setuptools 0.7 and higher means setuptools.
|
| 605 |
+
assert Requirement.parse('setuptools == 0.7').project_name == 'setuptools'
|
| 606 |
+
assert Requirement.parse('setuptools == 0.7a1').project_name == 'setuptools'
|
| 607 |
+
assert Requirement.parse('setuptools >= 0.7').project_name == 'setuptools'
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
class TestParsing:
|
| 611 |
+
def testEmptyParse(self):
|
| 612 |
+
assert list(parse_requirements('')) == []
|
| 613 |
+
|
| 614 |
+
def testYielding(self):
|
| 615 |
+
for inp, out in [
|
| 616 |
+
([], []),
|
| 617 |
+
('x', ['x']),
|
| 618 |
+
([[]], []),
|
| 619 |
+
(' x\n y', ['x', 'y']),
|
| 620 |
+
(['x\n\n', 'y'], ['x', 'y']),
|
| 621 |
+
]:
|
| 622 |
+
assert list(pkg_resources.yield_lines(inp)) == out
|
| 623 |
+
|
| 624 |
+
def testSplitting(self):
|
| 625 |
+
sample = """
|
| 626 |
+
x
|
| 627 |
+
[Y]
|
| 628 |
+
z
|
| 629 |
+
|
| 630 |
+
a
|
| 631 |
+
[b ]
|
| 632 |
+
# foo
|
| 633 |
+
c
|
| 634 |
+
[ d]
|
| 635 |
+
[q]
|
| 636 |
+
v
|
| 637 |
+
"""
|
| 638 |
+
assert list(pkg_resources.split_sections(sample)) == [
|
| 639 |
+
(None, ["x"]),
|
| 640 |
+
("Y", ["z", "a"]),
|
| 641 |
+
("b", ["c"]),
|
| 642 |
+
("d", []),
|
| 643 |
+
("q", ["v"]),
|
| 644 |
+
]
|
| 645 |
+
with pytest.raises(ValueError):
|
| 646 |
+
list(pkg_resources.split_sections("[foo"))
|
| 647 |
+
|
| 648 |
+
def testSafeName(self):
|
| 649 |
+
assert safe_name("adns-python") == "adns-python"
|
| 650 |
+
assert safe_name("WSGI Utils") == "WSGI-Utils"
|
| 651 |
+
assert safe_name("WSGI Utils") == "WSGI-Utils"
|
| 652 |
+
assert safe_name("Money$$$Maker") == "Money-Maker"
|
| 653 |
+
assert safe_name("peak.web") != "peak-web"
|
| 654 |
+
|
| 655 |
+
def testSafeVersion(self):
|
| 656 |
+
assert safe_version("1.2-1") == "1.2.post1"
|
| 657 |
+
assert safe_version("1.2 alpha") == "1.2.alpha"
|
| 658 |
+
assert safe_version("2.3.4 20050521") == "2.3.4.20050521"
|
| 659 |
+
assert safe_version("Money$$$Maker") == "Money-Maker"
|
| 660 |
+
assert safe_version("peak.web") == "peak.web"
|
| 661 |
+
|
| 662 |
+
def testSimpleRequirements(self):
|
| 663 |
+
assert list(parse_requirements('Twis-Ted>=1.2-1')) == [
|
| 664 |
+
Requirement('Twis-Ted>=1.2-1')
|
| 665 |
+
]
|
| 666 |
+
assert list(parse_requirements('Twisted >=1.2, \\ # more\n<2.0')) == [
|
| 667 |
+
Requirement('Twisted>=1.2,<2.0')
|
| 668 |
+
]
|
| 669 |
+
assert Requirement.parse("FooBar==1.99a3") == Requirement("FooBar==1.99a3")
|
| 670 |
+
with pytest.raises(ValueError):
|
| 671 |
+
Requirement.parse(">=2.3")
|
| 672 |
+
with pytest.raises(ValueError):
|
| 673 |
+
Requirement.parse("x\\")
|
| 674 |
+
with pytest.raises(ValueError):
|
| 675 |
+
Requirement.parse("x==2 q")
|
| 676 |
+
with pytest.raises(ValueError):
|
| 677 |
+
Requirement.parse("X==1\nY==2")
|
| 678 |
+
with pytest.raises(ValueError):
|
| 679 |
+
Requirement.parse("#")
|
| 680 |
+
|
| 681 |
+
def test_requirements_with_markers(self):
|
| 682 |
+
assert Requirement.parse("foobar;os_name=='a'") == Requirement.parse(
|
| 683 |
+
"foobar;os_name=='a'"
|
| 684 |
+
)
|
| 685 |
+
assert Requirement.parse(
|
| 686 |
+
"name==1.1;python_version=='2.7'"
|
| 687 |
+
) != Requirement.parse("name==1.1;python_version=='3.6'")
|
| 688 |
+
assert Requirement.parse(
|
| 689 |
+
"name==1.0;python_version=='2.7'"
|
| 690 |
+
) != Requirement.parse("name==1.2;python_version=='2.7'")
|
| 691 |
+
assert Requirement.parse(
|
| 692 |
+
"name[foo]==1.0;python_version=='3.6'"
|
| 693 |
+
) != Requirement.parse("name[foo,bar]==1.0;python_version=='3.6'")
|
| 694 |
+
|
| 695 |
+
def test_local_version(self):
|
| 696 |
+
parse_requirements('foo==1.0+org1')
|
| 697 |
+
|
| 698 |
+
def test_spaces_between_multiple_versions(self):
|
| 699 |
+
parse_requirements('foo>=1.0, <3')
|
| 700 |
+
parse_requirements('foo >= 1.0, < 3')
|
| 701 |
+
|
| 702 |
+
@pytest.mark.parametrize(
|
| 703 |
+
("lower", "upper"),
|
| 704 |
+
[
|
| 705 |
+
('1.2-rc1', '1.2rc1'),
|
| 706 |
+
('0.4', '0.4.0'),
|
| 707 |
+
('0.4.0.0', '0.4.0'),
|
| 708 |
+
('0.4.0-0', '0.4-0'),
|
| 709 |
+
('0post1', '0.0post1'),
|
| 710 |
+
('0pre1', '0.0c1'),
|
| 711 |
+
('0.0.0preview1', '0c1'),
|
| 712 |
+
('0.0c1', '0-rc1'),
|
| 713 |
+
('1.2a1', '1.2.a.1'),
|
| 714 |
+
('1.2.a', '1.2a'),
|
| 715 |
+
],
|
| 716 |
+
)
|
| 717 |
+
def testVersionEquality(self, lower, upper):
|
| 718 |
+
assert parse_version(lower) == parse_version(upper)
|
| 719 |
+
|
| 720 |
+
torture = """
|
| 721 |
+
0.80.1-3 0.80.1-2 0.80.1-1 0.79.9999+0.80.0pre4-1
|
| 722 |
+
0.79.9999+0.80.0pre2-3 0.79.9999+0.80.0pre2-2
|
| 723 |
+
0.77.2-1 0.77.1-1 0.77.0-1
|
| 724 |
+
"""
|
| 725 |
+
|
| 726 |
+
@pytest.mark.parametrize(
|
| 727 |
+
("lower", "upper"),
|
| 728 |
+
[
|
| 729 |
+
('2.1', '2.1.1'),
|
| 730 |
+
('2a1', '2b0'),
|
| 731 |
+
('2a1', '2.1'),
|
| 732 |
+
('2.3a1', '2.3'),
|
| 733 |
+
('2.1-1', '2.1-2'),
|
| 734 |
+
('2.1-1', '2.1.1'),
|
| 735 |
+
('2.1', '2.1post4'),
|
| 736 |
+
('2.1a0-20040501', '2.1'),
|
| 737 |
+
('1.1', '02.1'),
|
| 738 |
+
('3.2', '3.2.post0'),
|
| 739 |
+
('3.2post1', '3.2post2'),
|
| 740 |
+
('0.4', '4.0'),
|
| 741 |
+
('0.0.4', '0.4.0'),
|
| 742 |
+
('0post1', '0.4post1'),
|
| 743 |
+
('2.1.0-rc1', '2.1.0'),
|
| 744 |
+
('2.1dev', '2.1a0'),
|
| 745 |
+
]
|
| 746 |
+
+ list(pairwise(reversed(torture.split()))),
|
| 747 |
+
)
|
| 748 |
+
def testVersionOrdering(self, lower, upper):
|
| 749 |
+
assert parse_version(lower) < parse_version(upper)
|
| 750 |
+
|
| 751 |
+
def testVersionHashable(self):
|
| 752 |
+
"""
|
| 753 |
+
Ensure that our versions stay hashable even though we've subclassed
|
| 754 |
+
them and added some shim code to them.
|
| 755 |
+
"""
|
| 756 |
+
assert hash(parse_version("1.0")) == hash(parse_version("1.0"))
|
| 757 |
+
|
| 758 |
+
|
| 759 |
+
class TestNamespaces:
|
| 760 |
+
ns_str = "__import__('pkg_resources').declare_namespace(__name__)\n"
|
| 761 |
+
|
| 762 |
+
@pytest.fixture
|
| 763 |
+
def symlinked_tmpdir(self, tmpdir):
|
| 764 |
+
"""
|
| 765 |
+
Where available, return the tempdir as a symlink,
|
| 766 |
+
which as revealed in #231 is more fragile than
|
| 767 |
+
a natural tempdir.
|
| 768 |
+
"""
|
| 769 |
+
if not hasattr(os, 'symlink'):
|
| 770 |
+
yield str(tmpdir)
|
| 771 |
+
return
|
| 772 |
+
|
| 773 |
+
link_name = str(tmpdir) + '-linked'
|
| 774 |
+
os.symlink(str(tmpdir), link_name)
|
| 775 |
+
try:
|
| 776 |
+
yield type(tmpdir)(link_name)
|
| 777 |
+
finally:
|
| 778 |
+
os.unlink(link_name)
|
| 779 |
+
|
| 780 |
+
@pytest.fixture(autouse=True)
|
| 781 |
+
def patched_path(self, tmpdir):
|
| 782 |
+
"""
|
| 783 |
+
Patch sys.path to include the 'site-pkgs' dir. Also
|
| 784 |
+
restore pkg_resources._namespace_packages to its
|
| 785 |
+
former state.
|
| 786 |
+
"""
|
| 787 |
+
saved_ns_pkgs = pkg_resources._namespace_packages.copy()
|
| 788 |
+
saved_sys_path = sys.path[:]
|
| 789 |
+
site_pkgs = tmpdir.mkdir('site-pkgs')
|
| 790 |
+
sys.path.append(str(site_pkgs))
|
| 791 |
+
try:
|
| 792 |
+
yield
|
| 793 |
+
finally:
|
| 794 |
+
pkg_resources._namespace_packages = saved_ns_pkgs
|
| 795 |
+
sys.path = saved_sys_path
|
| 796 |
+
|
| 797 |
+
issue591 = pytest.mark.xfail(platform.system() == 'Windows', reason="#591")
|
| 798 |
+
|
| 799 |
+
@issue591
|
| 800 |
+
def test_two_levels_deep(self, symlinked_tmpdir):
|
| 801 |
+
"""
|
| 802 |
+
Test nested namespace packages
|
| 803 |
+
Create namespace packages in the following tree :
|
| 804 |
+
site-packages-1/pkg1/pkg2
|
| 805 |
+
site-packages-2/pkg1/pkg2
|
| 806 |
+
Check both are in the _namespace_packages dict and that their __path__
|
| 807 |
+
is correct
|
| 808 |
+
"""
|
| 809 |
+
real_tmpdir = symlinked_tmpdir.realpath()
|
| 810 |
+
tmpdir = symlinked_tmpdir
|
| 811 |
+
sys.path.append(str(tmpdir / 'site-pkgs2'))
|
| 812 |
+
site_dirs = tmpdir / 'site-pkgs', tmpdir / 'site-pkgs2'
|
| 813 |
+
for site in site_dirs:
|
| 814 |
+
pkg1 = site / 'pkg1'
|
| 815 |
+
pkg2 = pkg1 / 'pkg2'
|
| 816 |
+
pkg2.ensure_dir()
|
| 817 |
+
(pkg1 / '__init__.py').write_text(self.ns_str, encoding='utf-8')
|
| 818 |
+
(pkg2 / '__init__.py').write_text(self.ns_str, encoding='utf-8')
|
| 819 |
+
with pytest.warns(DeprecationWarning, match="pkg_resources.declare_namespace"):
|
| 820 |
+
import pkg1 # pyright: ignore[reportMissingImports] # Temporary package for test
|
| 821 |
+
assert "pkg1" in pkg_resources._namespace_packages
|
| 822 |
+
# attempt to import pkg2 from site-pkgs2
|
| 823 |
+
with pytest.warns(DeprecationWarning, match="pkg_resources.declare_namespace"):
|
| 824 |
+
import pkg1.pkg2 # pyright: ignore[reportMissingImports] # Temporary package for test
|
| 825 |
+
# check the _namespace_packages dict
|
| 826 |
+
assert "pkg1.pkg2" in pkg_resources._namespace_packages
|
| 827 |
+
assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"]
|
| 828 |
+
# check the __path__ attribute contains both paths
|
| 829 |
+
expected = [
|
| 830 |
+
str(real_tmpdir / "site-pkgs" / "pkg1" / "pkg2"),
|
| 831 |
+
str(real_tmpdir / "site-pkgs2" / "pkg1" / "pkg2"),
|
| 832 |
+
]
|
| 833 |
+
assert pkg1.pkg2.__path__ == expected
|
| 834 |
+
|
| 835 |
+
@issue591
|
| 836 |
+
def test_path_order(self, symlinked_tmpdir):
|
| 837 |
+
"""
|
| 838 |
+
Test that if multiple versions of the same namespace package subpackage
|
| 839 |
+
are on different sys.path entries, that only the one earliest on
|
| 840 |
+
sys.path is imported, and that the namespace package's __path__ is in
|
| 841 |
+
the correct order.
|
| 842 |
+
|
| 843 |
+
Regression test for https://github.com/pypa/setuptools/issues/207
|
| 844 |
+
"""
|
| 845 |
+
|
| 846 |
+
tmpdir = symlinked_tmpdir
|
| 847 |
+
site_dirs = (
|
| 848 |
+
tmpdir / "site-pkgs",
|
| 849 |
+
tmpdir / "site-pkgs2",
|
| 850 |
+
tmpdir / "site-pkgs3",
|
| 851 |
+
)
|
| 852 |
+
|
| 853 |
+
vers_str = "__version__ = %r"
|
| 854 |
+
|
| 855 |
+
for number, site in enumerate(site_dirs, 1):
|
| 856 |
+
if number > 1:
|
| 857 |
+
sys.path.append(str(site))
|
| 858 |
+
nspkg = site / 'nspkg'
|
| 859 |
+
subpkg = nspkg / 'subpkg'
|
| 860 |
+
subpkg.ensure_dir()
|
| 861 |
+
(nspkg / '__init__.py').write_text(self.ns_str, encoding='utf-8')
|
| 862 |
+
(subpkg / '__init__.py').write_text(vers_str % number, encoding='utf-8')
|
| 863 |
+
|
| 864 |
+
with pytest.warns(DeprecationWarning, match="pkg_resources.declare_namespace"):
|
| 865 |
+
import nspkg # pyright: ignore[reportMissingImports] # Temporary package for test
|
| 866 |
+
import nspkg.subpkg # pyright: ignore[reportMissingImports] # Temporary package for test
|
| 867 |
+
expected = [str(site.realpath() / 'nspkg') for site in site_dirs]
|
| 868 |
+
assert nspkg.__path__ == expected
|
| 869 |
+
assert nspkg.subpkg.__version__ == 1
|
lib/python3.11/site-packages/pkg_resources/tests/test_working_set.py
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
import pkg_resources
|
| 9 |
+
|
| 10 |
+
from .test_resources import Metadata
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def strip_comments(s):
|
| 14 |
+
return '\n'.join(
|
| 15 |
+
line
|
| 16 |
+
for line in s.split('\n')
|
| 17 |
+
if line.strip() and not line.strip().startswith('#')
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def parse_distributions(s):
|
| 22 |
+
"""
|
| 23 |
+
Parse a series of distribution specs of the form:
|
| 24 |
+
{project_name}-{version}
|
| 25 |
+
[optional, indented requirements specification]
|
| 26 |
+
|
| 27 |
+
Example:
|
| 28 |
+
|
| 29 |
+
foo-0.2
|
| 30 |
+
bar-1.0
|
| 31 |
+
foo>=3.0
|
| 32 |
+
[feature]
|
| 33 |
+
baz
|
| 34 |
+
|
| 35 |
+
yield 2 distributions:
|
| 36 |
+
- project_name=foo, version=0.2
|
| 37 |
+
- project_name=bar, version=1.0,
|
| 38 |
+
requires=['foo>=3.0', 'baz; extra=="feature"']
|
| 39 |
+
"""
|
| 40 |
+
s = s.strip()
|
| 41 |
+
for spec in re.split(r'\n(?=[^\s])', s):
|
| 42 |
+
if not spec:
|
| 43 |
+
continue
|
| 44 |
+
fields = spec.split('\n', 1)
|
| 45 |
+
assert 1 <= len(fields) <= 2
|
| 46 |
+
name, version = fields.pop(0).rsplit('-', 1)
|
| 47 |
+
if fields:
|
| 48 |
+
requires = textwrap.dedent(fields.pop(0))
|
| 49 |
+
metadata = Metadata(('requires.txt', requires))
|
| 50 |
+
else:
|
| 51 |
+
metadata = None
|
| 52 |
+
dist = pkg_resources.Distribution(
|
| 53 |
+
project_name=name, version=version, metadata=metadata
|
| 54 |
+
)
|
| 55 |
+
yield dist
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class FakeInstaller:
|
| 59 |
+
def __init__(self, installable_dists) -> None:
|
| 60 |
+
self._installable_dists = installable_dists
|
| 61 |
+
|
| 62 |
+
def __call__(self, req):
|
| 63 |
+
return next(
|
| 64 |
+
iter(filter(lambda dist: dist in req, self._installable_dists)), None
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def parametrize_test_working_set_resolve(*test_list):
|
| 69 |
+
idlist = []
|
| 70 |
+
argvalues = []
|
| 71 |
+
for test in test_list:
|
| 72 |
+
(
|
| 73 |
+
name,
|
| 74 |
+
installed_dists,
|
| 75 |
+
installable_dists,
|
| 76 |
+
requirements,
|
| 77 |
+
expected1,
|
| 78 |
+
expected2,
|
| 79 |
+
) = (
|
| 80 |
+
strip_comments(s.lstrip())
|
| 81 |
+
for s in textwrap.dedent(test).lstrip().split('\n\n', 5)
|
| 82 |
+
)
|
| 83 |
+
installed_dists = list(parse_distributions(installed_dists))
|
| 84 |
+
installable_dists = list(parse_distributions(installable_dists))
|
| 85 |
+
requirements = list(pkg_resources.parse_requirements(requirements))
|
| 86 |
+
for id_, replace_conflicting, expected in (
|
| 87 |
+
(name, False, expected1),
|
| 88 |
+
(name + '_replace_conflicting', True, expected2),
|
| 89 |
+
):
|
| 90 |
+
idlist.append(id_)
|
| 91 |
+
expected = strip_comments(expected.strip())
|
| 92 |
+
if re.match(r'\w+$', expected):
|
| 93 |
+
expected = getattr(pkg_resources, expected)
|
| 94 |
+
assert issubclass(expected, Exception)
|
| 95 |
+
else:
|
| 96 |
+
expected = list(parse_distributions(expected))
|
| 97 |
+
argvalues.append(
|
| 98 |
+
pytest.param(
|
| 99 |
+
installed_dists,
|
| 100 |
+
installable_dists,
|
| 101 |
+
requirements,
|
| 102 |
+
replace_conflicting,
|
| 103 |
+
expected,
|
| 104 |
+
)
|
| 105 |
+
)
|
| 106 |
+
return pytest.mark.parametrize(
|
| 107 |
+
(
|
| 108 |
+
"installed_dists",
|
| 109 |
+
"installable_dists",
|
| 110 |
+
"requirements",
|
| 111 |
+
"replace_conflicting",
|
| 112 |
+
"resolved_dists_or_exception",
|
| 113 |
+
),
|
| 114 |
+
argvalues,
|
| 115 |
+
ids=idlist,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
@parametrize_test_working_set_resolve(
|
| 120 |
+
"""
|
| 121 |
+
# id
|
| 122 |
+
noop
|
| 123 |
+
|
| 124 |
+
# installed
|
| 125 |
+
|
| 126 |
+
# installable
|
| 127 |
+
|
| 128 |
+
# wanted
|
| 129 |
+
|
| 130 |
+
# resolved
|
| 131 |
+
|
| 132 |
+
# resolved [replace conflicting]
|
| 133 |
+
""",
|
| 134 |
+
"""
|
| 135 |
+
# id
|
| 136 |
+
already_installed
|
| 137 |
+
|
| 138 |
+
# installed
|
| 139 |
+
foo-3.0
|
| 140 |
+
|
| 141 |
+
# installable
|
| 142 |
+
|
| 143 |
+
# wanted
|
| 144 |
+
foo>=2.1,!=3.1,<4
|
| 145 |
+
|
| 146 |
+
# resolved
|
| 147 |
+
foo-3.0
|
| 148 |
+
|
| 149 |
+
# resolved [replace conflicting]
|
| 150 |
+
foo-3.0
|
| 151 |
+
""",
|
| 152 |
+
"""
|
| 153 |
+
# id
|
| 154 |
+
installable_not_installed
|
| 155 |
+
|
| 156 |
+
# installed
|
| 157 |
+
|
| 158 |
+
# installable
|
| 159 |
+
foo-3.0
|
| 160 |
+
foo-4.0
|
| 161 |
+
|
| 162 |
+
# wanted
|
| 163 |
+
foo>=2.1,!=3.1,<4
|
| 164 |
+
|
| 165 |
+
# resolved
|
| 166 |
+
foo-3.0
|
| 167 |
+
|
| 168 |
+
# resolved [replace conflicting]
|
| 169 |
+
foo-3.0
|
| 170 |
+
""",
|
| 171 |
+
"""
|
| 172 |
+
# id
|
| 173 |
+
not_installable
|
| 174 |
+
|
| 175 |
+
# installed
|
| 176 |
+
|
| 177 |
+
# installable
|
| 178 |
+
|
| 179 |
+
# wanted
|
| 180 |
+
foo>=2.1,!=3.1,<4
|
| 181 |
+
|
| 182 |
+
# resolved
|
| 183 |
+
DistributionNotFound
|
| 184 |
+
|
| 185 |
+
# resolved [replace conflicting]
|
| 186 |
+
DistributionNotFound
|
| 187 |
+
""",
|
| 188 |
+
"""
|
| 189 |
+
# id
|
| 190 |
+
no_matching_version
|
| 191 |
+
|
| 192 |
+
# installed
|
| 193 |
+
|
| 194 |
+
# installable
|
| 195 |
+
foo-3.1
|
| 196 |
+
|
| 197 |
+
# wanted
|
| 198 |
+
foo>=2.1,!=3.1,<4
|
| 199 |
+
|
| 200 |
+
# resolved
|
| 201 |
+
DistributionNotFound
|
| 202 |
+
|
| 203 |
+
# resolved [replace conflicting]
|
| 204 |
+
DistributionNotFound
|
| 205 |
+
""",
|
| 206 |
+
"""
|
| 207 |
+
# id
|
| 208 |
+
installable_with_installed_conflict
|
| 209 |
+
|
| 210 |
+
# installed
|
| 211 |
+
foo-3.1
|
| 212 |
+
|
| 213 |
+
# installable
|
| 214 |
+
foo-3.5
|
| 215 |
+
|
| 216 |
+
# wanted
|
| 217 |
+
foo>=2.1,!=3.1,<4
|
| 218 |
+
|
| 219 |
+
# resolved
|
| 220 |
+
VersionConflict
|
| 221 |
+
|
| 222 |
+
# resolved [replace conflicting]
|
| 223 |
+
foo-3.5
|
| 224 |
+
""",
|
| 225 |
+
"""
|
| 226 |
+
# id
|
| 227 |
+
not_installable_with_installed_conflict
|
| 228 |
+
|
| 229 |
+
# installed
|
| 230 |
+
foo-3.1
|
| 231 |
+
|
| 232 |
+
# installable
|
| 233 |
+
|
| 234 |
+
# wanted
|
| 235 |
+
foo>=2.1,!=3.1,<4
|
| 236 |
+
|
| 237 |
+
# resolved
|
| 238 |
+
VersionConflict
|
| 239 |
+
|
| 240 |
+
# resolved [replace conflicting]
|
| 241 |
+
DistributionNotFound
|
| 242 |
+
""",
|
| 243 |
+
"""
|
| 244 |
+
# id
|
| 245 |
+
installed_with_installed_require
|
| 246 |
+
|
| 247 |
+
# installed
|
| 248 |
+
foo-3.9
|
| 249 |
+
baz-0.1
|
| 250 |
+
foo>=2.1,!=3.1,<4
|
| 251 |
+
|
| 252 |
+
# installable
|
| 253 |
+
|
| 254 |
+
# wanted
|
| 255 |
+
baz
|
| 256 |
+
|
| 257 |
+
# resolved
|
| 258 |
+
foo-3.9
|
| 259 |
+
baz-0.1
|
| 260 |
+
|
| 261 |
+
# resolved [replace conflicting]
|
| 262 |
+
foo-3.9
|
| 263 |
+
baz-0.1
|
| 264 |
+
""",
|
| 265 |
+
"""
|
| 266 |
+
# id
|
| 267 |
+
installed_with_conflicting_installed_require
|
| 268 |
+
|
| 269 |
+
# installed
|
| 270 |
+
foo-5
|
| 271 |
+
baz-0.1
|
| 272 |
+
foo>=2.1,!=3.1,<4
|
| 273 |
+
|
| 274 |
+
# installable
|
| 275 |
+
|
| 276 |
+
# wanted
|
| 277 |
+
baz
|
| 278 |
+
|
| 279 |
+
# resolved
|
| 280 |
+
VersionConflict
|
| 281 |
+
|
| 282 |
+
# resolved [replace conflicting]
|
| 283 |
+
DistributionNotFound
|
| 284 |
+
""",
|
| 285 |
+
"""
|
| 286 |
+
# id
|
| 287 |
+
installed_with_installable_conflicting_require
|
| 288 |
+
|
| 289 |
+
# installed
|
| 290 |
+
foo-5
|
| 291 |
+
baz-0.1
|
| 292 |
+
foo>=2.1,!=3.1,<4
|
| 293 |
+
|
| 294 |
+
# installable
|
| 295 |
+
foo-2.9
|
| 296 |
+
|
| 297 |
+
# wanted
|
| 298 |
+
baz
|
| 299 |
+
|
| 300 |
+
# resolved
|
| 301 |
+
VersionConflict
|
| 302 |
+
|
| 303 |
+
# resolved [replace conflicting]
|
| 304 |
+
baz-0.1
|
| 305 |
+
foo-2.9
|
| 306 |
+
""",
|
| 307 |
+
"""
|
| 308 |
+
# id
|
| 309 |
+
installed_with_installable_require
|
| 310 |
+
|
| 311 |
+
# installed
|
| 312 |
+
baz-0.1
|
| 313 |
+
foo>=2.1,!=3.1,<4
|
| 314 |
+
|
| 315 |
+
# installable
|
| 316 |
+
foo-3.9
|
| 317 |
+
|
| 318 |
+
# wanted
|
| 319 |
+
baz
|
| 320 |
+
|
| 321 |
+
# resolved
|
| 322 |
+
foo-3.9
|
| 323 |
+
baz-0.1
|
| 324 |
+
|
| 325 |
+
# resolved [replace conflicting]
|
| 326 |
+
foo-3.9
|
| 327 |
+
baz-0.1
|
| 328 |
+
""",
|
| 329 |
+
"""
|
| 330 |
+
# id
|
| 331 |
+
installable_with_installed_require
|
| 332 |
+
|
| 333 |
+
# installed
|
| 334 |
+
foo-3.9
|
| 335 |
+
|
| 336 |
+
# installable
|
| 337 |
+
baz-0.1
|
| 338 |
+
foo>=2.1,!=3.1,<4
|
| 339 |
+
|
| 340 |
+
# wanted
|
| 341 |
+
baz
|
| 342 |
+
|
| 343 |
+
# resolved
|
| 344 |
+
foo-3.9
|
| 345 |
+
baz-0.1
|
| 346 |
+
|
| 347 |
+
# resolved [replace conflicting]
|
| 348 |
+
foo-3.9
|
| 349 |
+
baz-0.1
|
| 350 |
+
""",
|
| 351 |
+
"""
|
| 352 |
+
# id
|
| 353 |
+
installable_with_installable_require
|
| 354 |
+
|
| 355 |
+
# installed
|
| 356 |
+
|
| 357 |
+
# installable
|
| 358 |
+
foo-3.9
|
| 359 |
+
baz-0.1
|
| 360 |
+
foo>=2.1,!=3.1,<4
|
| 361 |
+
|
| 362 |
+
# wanted
|
| 363 |
+
baz
|
| 364 |
+
|
| 365 |
+
# resolved
|
| 366 |
+
foo-3.9
|
| 367 |
+
baz-0.1
|
| 368 |
+
|
| 369 |
+
# resolved [replace conflicting]
|
| 370 |
+
foo-3.9
|
| 371 |
+
baz-0.1
|
| 372 |
+
""",
|
| 373 |
+
"""
|
| 374 |
+
# id
|
| 375 |
+
installable_with_conflicting_installable_require
|
| 376 |
+
|
| 377 |
+
# installed
|
| 378 |
+
foo-5
|
| 379 |
+
|
| 380 |
+
# installable
|
| 381 |
+
foo-2.9
|
| 382 |
+
baz-0.1
|
| 383 |
+
foo>=2.1,!=3.1,<4
|
| 384 |
+
|
| 385 |
+
# wanted
|
| 386 |
+
baz
|
| 387 |
+
|
| 388 |
+
# resolved
|
| 389 |
+
VersionConflict
|
| 390 |
+
|
| 391 |
+
# resolved [replace conflicting]
|
| 392 |
+
baz-0.1
|
| 393 |
+
foo-2.9
|
| 394 |
+
""",
|
| 395 |
+
"""
|
| 396 |
+
# id
|
| 397 |
+
conflicting_installables
|
| 398 |
+
|
| 399 |
+
# installed
|
| 400 |
+
|
| 401 |
+
# installable
|
| 402 |
+
foo-2.9
|
| 403 |
+
foo-5.0
|
| 404 |
+
|
| 405 |
+
# wanted
|
| 406 |
+
foo>=2.1,!=3.1,<4
|
| 407 |
+
foo>=4
|
| 408 |
+
|
| 409 |
+
# resolved
|
| 410 |
+
VersionConflict
|
| 411 |
+
|
| 412 |
+
# resolved [replace conflicting]
|
| 413 |
+
VersionConflict
|
| 414 |
+
""",
|
| 415 |
+
"""
|
| 416 |
+
# id
|
| 417 |
+
installables_with_conflicting_requires
|
| 418 |
+
|
| 419 |
+
# installed
|
| 420 |
+
|
| 421 |
+
# installable
|
| 422 |
+
foo-2.9
|
| 423 |
+
dep==1.0
|
| 424 |
+
baz-5.0
|
| 425 |
+
dep==2.0
|
| 426 |
+
dep-1.0
|
| 427 |
+
dep-2.0
|
| 428 |
+
|
| 429 |
+
# wanted
|
| 430 |
+
foo
|
| 431 |
+
baz
|
| 432 |
+
|
| 433 |
+
# resolved
|
| 434 |
+
VersionConflict
|
| 435 |
+
|
| 436 |
+
# resolved [replace conflicting]
|
| 437 |
+
VersionConflict
|
| 438 |
+
""",
|
| 439 |
+
"""
|
| 440 |
+
# id
|
| 441 |
+
installables_with_conflicting_nested_requires
|
| 442 |
+
|
| 443 |
+
# installed
|
| 444 |
+
|
| 445 |
+
# installable
|
| 446 |
+
foo-2.9
|
| 447 |
+
dep1
|
| 448 |
+
dep1-1.0
|
| 449 |
+
subdep<1.0
|
| 450 |
+
baz-5.0
|
| 451 |
+
dep2
|
| 452 |
+
dep2-1.0
|
| 453 |
+
subdep>1.0
|
| 454 |
+
subdep-0.9
|
| 455 |
+
subdep-1.1
|
| 456 |
+
|
| 457 |
+
# wanted
|
| 458 |
+
foo
|
| 459 |
+
baz
|
| 460 |
+
|
| 461 |
+
# resolved
|
| 462 |
+
VersionConflict
|
| 463 |
+
|
| 464 |
+
# resolved [replace conflicting]
|
| 465 |
+
VersionConflict
|
| 466 |
+
""",
|
| 467 |
+
"""
|
| 468 |
+
# id
|
| 469 |
+
wanted_normalized_name_installed_canonical
|
| 470 |
+
|
| 471 |
+
# installed
|
| 472 |
+
foo.bar-3.6
|
| 473 |
+
|
| 474 |
+
# installable
|
| 475 |
+
|
| 476 |
+
# wanted
|
| 477 |
+
foo-bar==3.6
|
| 478 |
+
|
| 479 |
+
# resolved
|
| 480 |
+
foo.bar-3.6
|
| 481 |
+
|
| 482 |
+
# resolved [replace conflicting]
|
| 483 |
+
foo.bar-3.6
|
| 484 |
+
""",
|
| 485 |
+
)
|
| 486 |
+
def test_working_set_resolve(
|
| 487 |
+
installed_dists,
|
| 488 |
+
installable_dists,
|
| 489 |
+
requirements,
|
| 490 |
+
replace_conflicting,
|
| 491 |
+
resolved_dists_or_exception,
|
| 492 |
+
):
|
| 493 |
+
ws = pkg_resources.WorkingSet([])
|
| 494 |
+
list(map(ws.add, installed_dists))
|
| 495 |
+
resolve_call = functools.partial(
|
| 496 |
+
ws.resolve,
|
| 497 |
+
requirements,
|
| 498 |
+
installer=FakeInstaller(installable_dists),
|
| 499 |
+
replace_conflicting=replace_conflicting,
|
| 500 |
+
)
|
| 501 |
+
if inspect.isclass(resolved_dists_or_exception):
|
| 502 |
+
with pytest.raises(resolved_dists_or_exception):
|
| 503 |
+
resolve_call()
|
| 504 |
+
else:
|
| 505 |
+
assert sorted(resolve_call()) == sorted(resolved_dists_or_exception)
|
lib/python3.11/site-packages/setuptools/__init__.py
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Extensions to the 'distutils' for large or complex distributions"""
|
| 2 |
+
# mypy: disable_error_code=override
|
| 3 |
+
# Command.reinitialize_command has an extra **kw param that distutils doesn't have
|
| 4 |
+
# Can't disable on the exact line because distutils doesn't exists on Python 3.12
|
| 5 |
+
# and mypy isn't aware of distutils_hack, causing distutils.core.Command to be Any,
|
| 6 |
+
# and a [unused-ignore] to be raised on 3.12+
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import functools
|
| 11 |
+
import os
|
| 12 |
+
import sys
|
| 13 |
+
from abc import abstractmethod
|
| 14 |
+
from collections.abc import Mapping
|
| 15 |
+
from typing import TYPE_CHECKING, TypeVar, overload
|
| 16 |
+
|
| 17 |
+
sys.path.extend(((vendor_path := os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setuptools', '_vendor')) not in sys.path) * [vendor_path]) # fmt: skip
|
| 18 |
+
# workaround for #4476
|
| 19 |
+
sys.modules.pop('backports', None)
|
| 20 |
+
|
| 21 |
+
import _distutils_hack.override # noqa: F401
|
| 22 |
+
|
| 23 |
+
from . import logging, monkey
|
| 24 |
+
from .depends import Require
|
| 25 |
+
from .discovery import PackageFinder, PEP420PackageFinder
|
| 26 |
+
from .dist import Distribution
|
| 27 |
+
from .extension import Extension
|
| 28 |
+
from .version import __version__ as __version__
|
| 29 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 30 |
+
|
| 31 |
+
import distutils.core
|
| 32 |
+
|
| 33 |
+
__all__ = [
|
| 34 |
+
'setup',
|
| 35 |
+
'Distribution',
|
| 36 |
+
'Command',
|
| 37 |
+
'Extension',
|
| 38 |
+
'Require',
|
| 39 |
+
'SetuptoolsDeprecationWarning',
|
| 40 |
+
'find_packages',
|
| 41 |
+
'find_namespace_packages',
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
_CommandT = TypeVar("_CommandT", bound="_Command")
|
| 45 |
+
|
| 46 |
+
bootstrap_install_from = None
|
| 47 |
+
|
| 48 |
+
find_packages = PackageFinder.find
|
| 49 |
+
find_namespace_packages = PEP420PackageFinder.find
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _install_setup_requires(attrs):
|
| 53 |
+
# Note: do not use `setuptools.Distribution` directly, as
|
| 54 |
+
# our PEP 517 backend patch `distutils.core.Distribution`.
|
| 55 |
+
class MinimalDistribution(distutils.core.Distribution):
|
| 56 |
+
"""
|
| 57 |
+
A minimal version of a distribution for supporting the
|
| 58 |
+
fetch_build_eggs interface.
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
def __init__(self, attrs: Mapping[str, object]) -> None:
|
| 62 |
+
_incl = 'dependency_links', 'setup_requires'
|
| 63 |
+
filtered = {k: attrs[k] for k in set(_incl) & set(attrs)}
|
| 64 |
+
super().__init__(filtered)
|
| 65 |
+
# Prevent accidentally triggering discovery with incomplete set of attrs
|
| 66 |
+
self.set_defaults._disable()
|
| 67 |
+
|
| 68 |
+
def _get_project_config_files(self, filenames=None):
|
| 69 |
+
"""Ignore ``pyproject.toml``, they are not related to setup_requires"""
|
| 70 |
+
try:
|
| 71 |
+
cfg, _toml = super()._split_standard_project_metadata(filenames)
|
| 72 |
+
except Exception:
|
| 73 |
+
return filenames, ()
|
| 74 |
+
return cfg, ()
|
| 75 |
+
|
| 76 |
+
def finalize_options(self):
|
| 77 |
+
"""
|
| 78 |
+
Disable finalize_options to avoid building the working set.
|
| 79 |
+
Ref #2158.
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
dist = MinimalDistribution(attrs)
|
| 83 |
+
|
| 84 |
+
# Honor setup.cfg's options.
|
| 85 |
+
dist.parse_config_files(ignore_option_errors=True)
|
| 86 |
+
if dist.setup_requires:
|
| 87 |
+
_fetch_build_eggs(dist)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _fetch_build_eggs(dist: Distribution):
|
| 91 |
+
try:
|
| 92 |
+
dist.fetch_build_eggs(dist.setup_requires)
|
| 93 |
+
except Exception as ex:
|
| 94 |
+
msg = """
|
| 95 |
+
It is possible a package already installed in your system
|
| 96 |
+
contains an version that is invalid according to PEP 440.
|
| 97 |
+
You can try `pip install --use-pep517` as a workaround for this problem,
|
| 98 |
+
or rely on a new virtual environment.
|
| 99 |
+
|
| 100 |
+
If the problem refers to a package that is not installed yet,
|
| 101 |
+
please contact that package's maintainers or distributors.
|
| 102 |
+
"""
|
| 103 |
+
if "InvalidVersion" in ex.__class__.__name__:
|
| 104 |
+
if hasattr(ex, "add_note"):
|
| 105 |
+
ex.add_note(msg) # PEP 678
|
| 106 |
+
else:
|
| 107 |
+
dist.announce(f"\n{msg}\n")
|
| 108 |
+
raise
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def setup(**attrs) -> Distribution:
|
| 112 |
+
logging.configure()
|
| 113 |
+
# Make sure we have any requirements needed to interpret 'attrs'.
|
| 114 |
+
_install_setup_requires(attrs)
|
| 115 |
+
# Override return type of distutils.core.Distribution with setuptools.dist.Distribution
|
| 116 |
+
# (implicitly implemented via `setuptools.monkey.patch_all`).
|
| 117 |
+
return distutils.core.setup(**attrs) # type: ignore[return-value]
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
setup.__doc__ = distutils.core.setup.__doc__
|
| 121 |
+
|
| 122 |
+
if TYPE_CHECKING:
|
| 123 |
+
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962
|
| 124 |
+
from distutils.core import Command as _Command
|
| 125 |
+
else:
|
| 126 |
+
_Command = monkey.get_unpatched(distutils.core.Command)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class Command(_Command):
|
| 130 |
+
"""
|
| 131 |
+
Setuptools internal actions are organized using a *command design pattern*.
|
| 132 |
+
This means that each action (or group of closely related actions) executed during
|
| 133 |
+
the build should be implemented as a ``Command`` subclass.
|
| 134 |
+
|
| 135 |
+
These commands are abstractions and do not necessarily correspond to a command that
|
| 136 |
+
can (or should) be executed via a terminal, in a CLI fashion (although historically
|
| 137 |
+
they would).
|
| 138 |
+
|
| 139 |
+
When creating a new command from scratch, custom defined classes **SHOULD** inherit
|
| 140 |
+
from ``setuptools.Command`` and implement a few mandatory methods.
|
| 141 |
+
Between these mandatory methods, are listed:
|
| 142 |
+
:meth:`initialize_options`, :meth:`finalize_options` and :meth:`run`.
|
| 143 |
+
|
| 144 |
+
A useful analogy for command classes is to think of them as subroutines with local
|
| 145 |
+
variables called "options". The options are "declared" in :meth:`initialize_options`
|
| 146 |
+
and "defined" (given their final values, aka "finalized") in :meth:`finalize_options`,
|
| 147 |
+
both of which must be defined by every command class. The "body" of the subroutine,
|
| 148 |
+
(where it does all the work) is the :meth:`run` method.
|
| 149 |
+
Between :meth:`initialize_options` and :meth:`finalize_options`, ``setuptools`` may set
|
| 150 |
+
the values for options/attributes based on user's input (or circumstance),
|
| 151 |
+
which means that the implementation should be careful to not overwrite values in
|
| 152 |
+
:meth:`finalize_options` unless necessary.
|
| 153 |
+
|
| 154 |
+
Please note that other commands (or other parts of setuptools) may also overwrite
|
| 155 |
+
the values of the command's options/attributes multiple times during the build
|
| 156 |
+
process.
|
| 157 |
+
Therefore it is important to consistently implement :meth:`initialize_options` and
|
| 158 |
+
:meth:`finalize_options`. For example, all derived attributes (or attributes that
|
| 159 |
+
depend on the value of other attributes) **SHOULD** be recomputed in
|
| 160 |
+
:meth:`finalize_options`.
|
| 161 |
+
|
| 162 |
+
When overwriting existing commands, custom defined classes **MUST** abide by the
|
| 163 |
+
same APIs implemented by the original class. They also **SHOULD** inherit from the
|
| 164 |
+
original class.
|
| 165 |
+
"""
|
| 166 |
+
|
| 167 |
+
command_consumes_arguments = False
|
| 168 |
+
distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution
|
| 169 |
+
|
| 170 |
+
dry_run = False # type: ignore[assignment] # pyright: ignore[reportAssignmentType] (until #4689; see #4872)
|
| 171 |
+
"""
|
| 172 |
+
For compatibility with vendored bdist_wheel.
|
| 173 |
+
https://github.com/pypa/setuptools/pull/4872/files#r1986395142
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
def __init__(self, dist: Distribution, **kw) -> None:
|
| 177 |
+
"""
|
| 178 |
+
Construct the command for dist, updating
|
| 179 |
+
vars(self) with any keyword parameters.
|
| 180 |
+
"""
|
| 181 |
+
super().__init__(dist)
|
| 182 |
+
vars(self).update(kw)
|
| 183 |
+
|
| 184 |
+
@overload
|
| 185 |
+
def reinitialize_command(
|
| 186 |
+
self, command: str, reinit_subcommands: bool = False, **kw
|
| 187 |
+
) -> Command: ... # override distutils.cmd.Command with setuptools.Command
|
| 188 |
+
@overload
|
| 189 |
+
def reinitialize_command(
|
| 190 |
+
self, command: _CommandT, reinit_subcommands: bool = False, **kw
|
| 191 |
+
) -> _CommandT: ...
|
| 192 |
+
def reinitialize_command(
|
| 193 |
+
self, command: str | _Command, reinit_subcommands: bool = False, **kw
|
| 194 |
+
) -> Command | _Command:
|
| 195 |
+
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
|
| 196 |
+
vars(cmd).update(kw)
|
| 197 |
+
return cmd # pyright: ignore[reportReturnType] # pypa/distutils#307
|
| 198 |
+
|
| 199 |
+
@abstractmethod
|
| 200 |
+
def initialize_options(self) -> None:
|
| 201 |
+
"""
|
| 202 |
+
Set or (reset) all options/attributes/caches used by the command
|
| 203 |
+
to their default values. Note that these values may be overwritten during
|
| 204 |
+
the build.
|
| 205 |
+
"""
|
| 206 |
+
raise NotImplementedError
|
| 207 |
+
|
| 208 |
+
@abstractmethod
|
| 209 |
+
def finalize_options(self) -> None:
|
| 210 |
+
"""
|
| 211 |
+
Set final values for all options/attributes used by the command.
|
| 212 |
+
Most of the time, each option/attribute/cache should only be set if it does not
|
| 213 |
+
have any value yet (e.g. ``if self.attr is None: self.attr = val``).
|
| 214 |
+
"""
|
| 215 |
+
raise NotImplementedError
|
| 216 |
+
|
| 217 |
+
@abstractmethod
|
| 218 |
+
def run(self) -> None:
|
| 219 |
+
"""
|
| 220 |
+
Execute the actions intended by the command.
|
| 221 |
+
(Side effects **SHOULD** only take place when :meth:`run` is executed,
|
| 222 |
+
for example, creating new files or writing to the terminal output).
|
| 223 |
+
"""
|
| 224 |
+
raise NotImplementedError
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def _find_all_simple(path):
|
| 228 |
+
"""
|
| 229 |
+
Find all files under 'path'
|
| 230 |
+
"""
|
| 231 |
+
results = (
|
| 232 |
+
os.path.join(base, file)
|
| 233 |
+
for base, dirs, files in os.walk(path, followlinks=True)
|
| 234 |
+
for file in files
|
| 235 |
+
)
|
| 236 |
+
return filter(os.path.isfile, results)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def findall(dir=os.curdir):
|
| 240 |
+
"""
|
| 241 |
+
Find all files under 'dir' and return the list of full filenames.
|
| 242 |
+
Unless dir is '.', return full filenames with dir prepended.
|
| 243 |
+
"""
|
| 244 |
+
files = _find_all_simple(dir)
|
| 245 |
+
if dir == os.curdir:
|
| 246 |
+
make_rel = functools.partial(os.path.relpath, start=dir)
|
| 247 |
+
files = map(make_rel, files)
|
| 248 |
+
return list(files)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class sic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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Handling of Core Metadata for Python packages (including reading and writing).
|
| 3 |
+
|
| 4 |
+
See: https://packaging.python.org/en/latest/specifications/core-metadata/
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import stat
|
| 11 |
+
import textwrap
|
| 12 |
+
from email import message_from_file
|
| 13 |
+
from email.message import Message
|
| 14 |
+
from tempfile import NamedTemporaryFile
|
| 15 |
+
|
| 16 |
+
from packaging.markers import Marker
|
| 17 |
+
from packaging.requirements import Requirement
|
| 18 |
+
from packaging.utils import canonicalize_name, canonicalize_version
|
| 19 |
+
from packaging.version import Version
|
| 20 |
+
|
| 21 |
+
from . import _normalization, _reqs
|
| 22 |
+
from ._static import is_static
|
| 23 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 24 |
+
|
| 25 |
+
from distutils.util import rfc822_escape
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def get_metadata_version(self):
|
| 29 |
+
mv = getattr(self, 'metadata_version', None)
|
| 30 |
+
if mv is None:
|
| 31 |
+
mv = Version('2.4')
|
| 32 |
+
self.metadata_version = mv
|
| 33 |
+
return mv
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def rfc822_unescape(content: str) -> str:
|
| 37 |
+
"""Reverse RFC-822 escaping by removing leading whitespaces from content."""
|
| 38 |
+
lines = content.splitlines()
|
| 39 |
+
if len(lines) == 1:
|
| 40 |
+
return lines[0].lstrip()
|
| 41 |
+
return '\n'.join((lines[0].lstrip(), textwrap.dedent('\n'.join(lines[1:]))))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _read_field_from_msg(msg: Message, field: str) -> str | None:
|
| 45 |
+
"""Read Message header field."""
|
| 46 |
+
value = msg[field]
|
| 47 |
+
if value == 'UNKNOWN':
|
| 48 |
+
return None
|
| 49 |
+
return value
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _read_field_unescaped_from_msg(msg: Message, field: str) -> str | None:
|
| 53 |
+
"""Read Message header field and apply rfc822_unescape."""
|
| 54 |
+
value = _read_field_from_msg(msg, field)
|
| 55 |
+
if value is None:
|
| 56 |
+
return value
|
| 57 |
+
return rfc822_unescape(value)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _read_list_from_msg(msg: Message, field: str) -> list[str] | None:
|
| 61 |
+
"""Read Message header field and return all results as list."""
|
| 62 |
+
values = msg.get_all(field, None)
|
| 63 |
+
if values == []:
|
| 64 |
+
return None
|
| 65 |
+
return values
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _read_payload_from_msg(msg: Message) -> str | None:
|
| 69 |
+
value = str(msg.get_payload()).strip()
|
| 70 |
+
if value == 'UNKNOWN' or not value:
|
| 71 |
+
return None
|
| 72 |
+
return value
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def read_pkg_file(self, file):
|
| 76 |
+
"""Reads the metadata values from a file object."""
|
| 77 |
+
msg = message_from_file(file)
|
| 78 |
+
|
| 79 |
+
self.metadata_version = Version(msg['metadata-version'])
|
| 80 |
+
self.name = _read_field_from_msg(msg, 'name')
|
| 81 |
+
self.version = _read_field_from_msg(msg, 'version')
|
| 82 |
+
self.description = _read_field_from_msg(msg, 'summary')
|
| 83 |
+
# we are filling author only.
|
| 84 |
+
self.author = _read_field_from_msg(msg, 'author')
|
| 85 |
+
self.maintainer = None
|
| 86 |
+
self.author_email = _read_field_from_msg(msg, 'author-email')
|
| 87 |
+
self.maintainer_email = None
|
| 88 |
+
self.url = _read_field_from_msg(msg, 'home-page')
|
| 89 |
+
self.download_url = _read_field_from_msg(msg, 'download-url')
|
| 90 |
+
self.license = _read_field_unescaped_from_msg(msg, 'license')
|
| 91 |
+
self.license_expression = _read_field_unescaped_from_msg(msg, 'license-expression')
|
| 92 |
+
|
| 93 |
+
self.long_description = _read_field_unescaped_from_msg(msg, 'description')
|
| 94 |
+
if self.long_description is None and self.metadata_version >= Version('2.1'):
|
| 95 |
+
self.long_description = _read_payload_from_msg(msg)
|
| 96 |
+
self.description = _read_field_from_msg(msg, 'summary')
|
| 97 |
+
|
| 98 |
+
if 'keywords' in msg:
|
| 99 |
+
self.keywords = _read_field_from_msg(msg, 'keywords').split(',')
|
| 100 |
+
|
| 101 |
+
self.platforms = _read_list_from_msg(msg, 'platform')
|
| 102 |
+
self.classifiers = _read_list_from_msg(msg, 'classifier')
|
| 103 |
+
|
| 104 |
+
# PEP 314 - these fields only exist in 1.1
|
| 105 |
+
if self.metadata_version == Version('1.1'):
|
| 106 |
+
self.requires = _read_list_from_msg(msg, 'requires')
|
| 107 |
+
self.provides = _read_list_from_msg(msg, 'provides')
|
| 108 |
+
self.obsoletes = _read_list_from_msg(msg, 'obsoletes')
|
| 109 |
+
else:
|
| 110 |
+
self.requires = None
|
| 111 |
+
self.provides = None
|
| 112 |
+
self.obsoletes = None
|
| 113 |
+
|
| 114 |
+
self.license_files = _read_list_from_msg(msg, 'license-file')
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def single_line(val):
|
| 118 |
+
"""
|
| 119 |
+
Quick and dirty validation for Summary pypa/setuptools#1390.
|
| 120 |
+
"""
|
| 121 |
+
if '\n' in val:
|
| 122 |
+
# TODO: Replace with `raise ValueError("newlines not allowed")`
|
| 123 |
+
# after reviewing #2893.
|
| 124 |
+
msg = "newlines are not allowed in `summary` and will break in the future"
|
| 125 |
+
SetuptoolsDeprecationWarning.emit("Invalid config.", msg)
|
| 126 |
+
# due_date is undefined. Controversial change, there was a lot of push back.
|
| 127 |
+
val = val.strip().split('\n')[0]
|
| 128 |
+
return val
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def write_pkg_info(self, base_dir):
|
| 132 |
+
"""Write the PKG-INFO file into the release tree."""
|
| 133 |
+
temp = ""
|
| 134 |
+
final = os.path.join(base_dir, 'PKG-INFO')
|
| 135 |
+
try:
|
| 136 |
+
# Use a temporary file while writing to avoid race conditions
|
| 137 |
+
# (e.g. `importlib.metadata` reading `.egg-info/PKG-INFO`):
|
| 138 |
+
with NamedTemporaryFile("w", encoding="utf-8", dir=base_dir, delete=False) as f:
|
| 139 |
+
temp = f.name
|
| 140 |
+
self.write_pkg_file(f)
|
| 141 |
+
permissions = stat.S_IMODE(os.lstat(temp).st_mode)
|
| 142 |
+
os.chmod(temp, permissions | stat.S_IRGRP | stat.S_IROTH)
|
| 143 |
+
os.replace(temp, final) # atomic operation.
|
| 144 |
+
finally:
|
| 145 |
+
if temp and os.path.exists(temp):
|
| 146 |
+
os.remove(temp)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# Based on Python 3.5 version
|
| 150 |
+
def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
|
| 151 |
+
"""Write the PKG-INFO format data to a file object."""
|
| 152 |
+
version = self.get_metadata_version()
|
| 153 |
+
|
| 154 |
+
def write_field(key, value):
|
| 155 |
+
file.write(f"{key}: {value}\n")
|
| 156 |
+
|
| 157 |
+
write_field('Metadata-Version', str(version))
|
| 158 |
+
write_field('Name', self.get_name())
|
| 159 |
+
write_field('Version', self.get_version())
|
| 160 |
+
|
| 161 |
+
summary = self.get_description()
|
| 162 |
+
if summary:
|
| 163 |
+
write_field('Summary', single_line(summary))
|
| 164 |
+
|
| 165 |
+
optional_fields = (
|
| 166 |
+
('Home-page', 'url'),
|
| 167 |
+
('Download-URL', 'download_url'),
|
| 168 |
+
('Author', 'author'),
|
| 169 |
+
('Author-email', 'author_email'),
|
| 170 |
+
('Maintainer', 'maintainer'),
|
| 171 |
+
('Maintainer-email', 'maintainer_email'),
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
for field, attr in optional_fields:
|
| 175 |
+
attr_val = getattr(self, attr, None)
|
| 176 |
+
if attr_val is not None:
|
| 177 |
+
write_field(field, attr_val)
|
| 178 |
+
|
| 179 |
+
if license_expression := self.license_expression:
|
| 180 |
+
write_field('License-Expression', license_expression)
|
| 181 |
+
elif license := self.get_license():
|
| 182 |
+
write_field('License', rfc822_escape(license))
|
| 183 |
+
|
| 184 |
+
for label, url in self.project_urls.items():
|
| 185 |
+
write_field('Project-URL', f'{label}, {url}')
|
| 186 |
+
|
| 187 |
+
keywords = ','.join(self.get_keywords())
|
| 188 |
+
if keywords:
|
| 189 |
+
write_field('Keywords', keywords)
|
| 190 |
+
|
| 191 |
+
platforms = self.get_platforms() or []
|
| 192 |
+
for platform in platforms:
|
| 193 |
+
write_field('Platform', platform)
|
| 194 |
+
|
| 195 |
+
self._write_list(file, 'Classifier', self.get_classifiers())
|
| 196 |
+
|
| 197 |
+
# PEP 314
|
| 198 |
+
self._write_list(file, 'Requires', self.get_requires())
|
| 199 |
+
self._write_list(file, 'Provides', self.get_provides())
|
| 200 |
+
self._write_list(file, 'Obsoletes', self.get_obsoletes())
|
| 201 |
+
|
| 202 |
+
# Setuptools specific for PEP 345
|
| 203 |
+
if hasattr(self, 'python_requires'):
|
| 204 |
+
write_field('Requires-Python', self.python_requires)
|
| 205 |
+
|
| 206 |
+
# PEP 566
|
| 207 |
+
if self.long_description_content_type:
|
| 208 |
+
write_field('Description-Content-Type', self.long_description_content_type)
|
| 209 |
+
|
| 210 |
+
safe_license_files = map(_safe_license_file, self.license_files or [])
|
| 211 |
+
self._write_list(file, 'License-File', safe_license_files)
|
| 212 |
+
_write_requirements(self, file)
|
| 213 |
+
|
| 214 |
+
for field, attr in _POSSIBLE_DYNAMIC_FIELDS.items():
|
| 215 |
+
if (val := getattr(self, attr, None)) and not is_static(val):
|
| 216 |
+
write_field('Dynamic', field)
|
| 217 |
+
|
| 218 |
+
long_description = self.get_long_description()
|
| 219 |
+
if long_description:
|
| 220 |
+
file.write(f"\n{long_description}")
|
| 221 |
+
if not long_description.endswith("\n"):
|
| 222 |
+
file.write("\n")
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def _write_requirements(self, file):
|
| 226 |
+
for req in _reqs.parse(self.install_requires):
|
| 227 |
+
file.write(f"Requires-Dist: {req}\n")
|
| 228 |
+
|
| 229 |
+
processed_extras = {}
|
| 230 |
+
for augmented_extra, reqs in self.extras_require.items():
|
| 231 |
+
# Historically, setuptools allows "augmented extras": `<extra>:<condition>`
|
| 232 |
+
unsafe_extra, _, condition = augmented_extra.partition(":")
|
| 233 |
+
unsafe_extra = unsafe_extra.strip()
|
| 234 |
+
extra = _normalization.safe_extra(unsafe_extra)
|
| 235 |
+
|
| 236 |
+
if extra:
|
| 237 |
+
_write_provides_extra(file, processed_extras, extra, unsafe_extra)
|
| 238 |
+
for req in _reqs.parse_strings(reqs):
|
| 239 |
+
r = _include_extra(req, extra, condition.strip())
|
| 240 |
+
file.write(f"Requires-Dist: {r}\n")
|
| 241 |
+
|
| 242 |
+
return processed_extras
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def _include_extra(req: str, extra: str, condition: str) -> Requirement:
|
| 246 |
+
r = Requirement(req) # create a fresh object that can be modified
|
| 247 |
+
parts = (
|
| 248 |
+
f"({r.marker})" if r.marker else None,
|
| 249 |
+
f"({condition})" if condition else None,
|
| 250 |
+
f"extra == {extra!r}" if extra else None,
|
| 251 |
+
)
|
| 252 |
+
r.marker = Marker(" and ".join(x for x in parts if x))
|
| 253 |
+
return r
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def _write_provides_extra(file, processed_extras, safe, unsafe):
|
| 257 |
+
previous = processed_extras.get(safe)
|
| 258 |
+
if previous == unsafe:
|
| 259 |
+
SetuptoolsDeprecationWarning.emit(
|
| 260 |
+
'Ambiguity during "extra" normalization for dependencies.',
|
| 261 |
+
f"""
|
| 262 |
+
{previous!r} and {unsafe!r} normalize to the same value:\n
|
| 263 |
+
{safe!r}\n
|
| 264 |
+
In future versions, setuptools might halt the build process.
|
| 265 |
+
""",
|
| 266 |
+
see_url="https://peps.python.org/pep-0685/",
|
| 267 |
+
)
|
| 268 |
+
else:
|
| 269 |
+
processed_extras[safe] = unsafe
|
| 270 |
+
file.write(f"Provides-Extra: {safe}\n")
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
# from pypa/distutils#244; needed only until that logic is always available
|
| 274 |
+
def get_fullname(self):
|
| 275 |
+
return _distribution_fullname(self.get_name(), self.get_version())
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def _distribution_fullname(name: str, version: str) -> str:
|
| 279 |
+
"""
|
| 280 |
+
>>> _distribution_fullname('setup.tools', '1.0-2')
|
| 281 |
+
'setup_tools-1.0.post2'
|
| 282 |
+
>>> _distribution_fullname('setup-tools', '1.2post2')
|
| 283 |
+
'setup_tools-1.2.post2'
|
| 284 |
+
>>> _distribution_fullname('setup-tools', '1.0-r2')
|
| 285 |
+
'setup_tools-1.0.post2'
|
| 286 |
+
>>> _distribution_fullname('setup.tools', '1.0.post')
|
| 287 |
+
'setup_tools-1.0.post0'
|
| 288 |
+
>>> _distribution_fullname('setup.tools', '1.0+ubuntu-1')
|
| 289 |
+
'setup_tools-1.0+ubuntu.1'
|
| 290 |
+
"""
|
| 291 |
+
return "{}-{}".format(
|
| 292 |
+
canonicalize_name(name).replace('-', '_'),
|
| 293 |
+
canonicalize_version(version, strip_trailing_zero=False),
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
def _safe_license_file(file):
|
| 298 |
+
# XXX: Do we need this after the deprecation discussed in #4892, #4896??
|
| 299 |
+
normalized = os.path.normpath(file).replace(os.sep, "/")
|
| 300 |
+
if "../" in normalized:
|
| 301 |
+
return os.path.basename(normalized) # Temporarily restore pre PEP639 behaviour
|
| 302 |
+
return normalized
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
_POSSIBLE_DYNAMIC_FIELDS = {
|
| 306 |
+
# Core Metadata Field x related Distribution attribute
|
| 307 |
+
"author": "author",
|
| 308 |
+
"author-email": "author_email",
|
| 309 |
+
"classifier": "classifiers",
|
| 310 |
+
"description": "long_description",
|
| 311 |
+
"description-content-type": "long_description_content_type",
|
| 312 |
+
"download-url": "download_url",
|
| 313 |
+
"home-page": "url",
|
| 314 |
+
"keywords": "keywords",
|
| 315 |
+
"license": "license",
|
| 316 |
+
# XXX: License-File is complicated because the user gives globs that are expanded
|
| 317 |
+
# during the build. Without special handling it is likely always
|
| 318 |
+
# marked as Dynamic, which is an acceptable outcome according to:
|
| 319 |
+
# https://github.com/pypa/setuptools/issues/4629#issuecomment-2331233677
|
| 320 |
+
"license-file": "license_files",
|
| 321 |
+
"license-expression": "license_expression", # PEP 639
|
| 322 |
+
"maintainer": "maintainer",
|
| 323 |
+
"maintainer-email": "maintainer_email",
|
| 324 |
+
"obsoletes": "obsoletes",
|
| 325 |
+
# "obsoletes-dist": "obsoletes_dist", # NOT USED
|
| 326 |
+
"platform": "platforms",
|
| 327 |
+
"project-url": "project_urls",
|
| 328 |
+
"provides": "provides",
|
| 329 |
+
# "provides-dist": "provides_dist", # NOT USED
|
| 330 |
+
"provides-extra": "extras_require",
|
| 331 |
+
"requires": "requires",
|
| 332 |
+
"requires-dist": "install_requires",
|
| 333 |
+
# "requires-external": "requires_external", # NOT USED
|
| 334 |
+
"requires-python": "python_requires",
|
| 335 |
+
"summary": "description",
|
| 336 |
+
# "supported-platform": "supported_platforms", # NOT USED
|
| 337 |
+
}
|
lib/python3.11/site-packages/setuptools/_discovery.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import operator
|
| 3 |
+
|
| 4 |
+
import packaging.requirements
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# from coherent.build.discovery
|
| 8 |
+
def extras_from_dep(dep):
|
| 9 |
+
try:
|
| 10 |
+
markers = packaging.requirements.Requirement(dep).marker._markers
|
| 11 |
+
except AttributeError:
|
| 12 |
+
markers = ()
|
| 13 |
+
return set(
|
| 14 |
+
marker[2].value
|
| 15 |
+
for marker in markers
|
| 16 |
+
if isinstance(marker, tuple) and marker[0].value == 'extra'
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def extras_from_deps(deps):
|
| 21 |
+
"""
|
| 22 |
+
>>> extras_from_deps(['requests'])
|
| 23 |
+
set()
|
| 24 |
+
>>> extras_from_deps(['pytest; extra == "test"'])
|
| 25 |
+
{'test'}
|
| 26 |
+
>>> sorted(extras_from_deps([
|
| 27 |
+
... 'requests',
|
| 28 |
+
... 'pytest; extra == "test"',
|
| 29 |
+
... 'pytest-cov; extra == "test"',
|
| 30 |
+
... 'sphinx; extra=="doc"']))
|
| 31 |
+
['doc', 'test']
|
| 32 |
+
"""
|
| 33 |
+
return functools.reduce(operator.or_, map(extras_from_dep, deps), set())
|
lib/python3.11/site-packages/setuptools/_distutils/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
__version__, _, _ = sys.version.partition(' ')
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
# Allow Debian and pkgsrc (only) to customize system
|
| 9 |
+
# behavior. Ref pypa/distutils#2 and pypa/distutils#16.
|
| 10 |
+
# This hook is deprecated and no other environments
|
| 11 |
+
# should use it.
|
| 12 |
+
importlib.import_module('_distutils_system_mod')
|
| 13 |
+
except ImportError:
|
| 14 |
+
pass
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (569 Bytes). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_log.cpython-311.pyc
ADDED
|
Binary file (286 Bytes). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_macos_compat.cpython-311.pyc
ADDED
|
Binary file (580 Bytes). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_modified.cpython-311.pyc
ADDED
|
Binary file (5.15 kB). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-311.pyc
ADDED
|
Binary file (767 Bytes). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-311.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-311.pyc
ADDED
|
Binary file (829 Bytes). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-311.pyc
ADDED
|
Binary file (22.9 kB). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/__pycache__/debug.cpython-311.pyc
ADDED
|
Binary file (332 Bytes). View file
|
|
|
lib/python3.11/site-packages/setuptools/_distutils/_log.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
+
log = logging.getLogger()
|
lib/python3.11/site-packages/setuptools/_distutils/_macos_compat.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def bypass_compiler_fixup(cmd, args):
|
| 6 |
+
return cmd
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
if sys.platform == 'darwin':
|
| 10 |
+
compiler_fixup = importlib.import_module('_osx_support').compiler_fixup
|
| 11 |
+
else:
|
| 12 |
+
compiler_fixup = bypass_compiler_fixup
|
lib/python3.11/site-packages/setuptools/_distutils/_modified.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Timestamp comparison of files and groups of files."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import functools
|
| 6 |
+
import os.path
|
| 7 |
+
from collections.abc import Callable, Iterable
|
| 8 |
+
from typing import Literal, TypeVar
|
| 9 |
+
|
| 10 |
+
from jaraco.functools import splat
|
| 11 |
+
|
| 12 |
+
from .compat.py39 import zip_strict
|
| 13 |
+
from .errors import DistutilsFileError
|
| 14 |
+
|
| 15 |
+
_SourcesT = TypeVar(
|
| 16 |
+
"_SourcesT", bound="str | bytes | os.PathLike[str] | os.PathLike[bytes]"
|
| 17 |
+
)
|
| 18 |
+
_TargetsT = TypeVar(
|
| 19 |
+
"_TargetsT", bound="str | bytes | os.PathLike[str] | os.PathLike[bytes]"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _newer(source, target):
|
| 24 |
+
return not os.path.exists(target) or (
|
| 25 |
+
os.path.getmtime(source) > os.path.getmtime(target)
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def newer(
|
| 30 |
+
source: str | bytes | os.PathLike[str] | os.PathLike[bytes],
|
| 31 |
+
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
|
| 32 |
+
) -> bool:
|
| 33 |
+
"""
|
| 34 |
+
Is source modified more recently than target.
|
| 35 |
+
|
| 36 |
+
Returns True if 'source' is modified more recently than
|
| 37 |
+
'target' or if 'target' does not exist.
|
| 38 |
+
|
| 39 |
+
Raises DistutilsFileError if 'source' does not exist.
|
| 40 |
+
"""
|
| 41 |
+
if not os.path.exists(source):
|
| 42 |
+
raise DistutilsFileError(f"file {os.path.abspath(source)!r} does not exist")
|
| 43 |
+
|
| 44 |
+
return _newer(source, target)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def newer_pairwise(
|
| 48 |
+
sources: Iterable[_SourcesT],
|
| 49 |
+
targets: Iterable[_TargetsT],
|
| 50 |
+
newer: Callable[[_SourcesT, _TargetsT], bool] = newer,
|
| 51 |
+
) -> tuple[list[_SourcesT], list[_TargetsT]]:
|
| 52 |
+
"""
|
| 53 |
+
Filter filenames where sources are newer than targets.
|
| 54 |
+
|
| 55 |
+
Walk two filename iterables in parallel, testing if each source is newer
|
| 56 |
+
than its corresponding target. Returns a pair of lists (sources,
|
| 57 |
+
targets) where source is newer than target, according to the semantics
|
| 58 |
+
of 'newer()'.
|
| 59 |
+
"""
|
| 60 |
+
newer_pairs = filter(splat(newer), zip_strict(sources, targets))
|
| 61 |
+
return tuple(map(list, zip(*newer_pairs))) or ([], [])
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def newer_group(
|
| 65 |
+
sources: Iterable[str | bytes | os.PathLike[str] | os.PathLike[bytes]],
|
| 66 |
+
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
|
| 67 |
+
missing: Literal["error", "ignore", "newer"] = "error",
|
| 68 |
+
) -> bool:
|
| 69 |
+
"""
|
| 70 |
+
Is target out-of-date with respect to any file in sources.
|
| 71 |
+
|
| 72 |
+
Return True if 'target' is out-of-date with respect to any file
|
| 73 |
+
listed in 'sources'. In other words, if 'target' exists and is newer
|
| 74 |
+
than every file in 'sources', return False; otherwise return True.
|
| 75 |
+
``missing`` controls how to handle a missing source file:
|
| 76 |
+
|
| 77 |
+
- error (default): allow the ``stat()`` call to fail.
|
| 78 |
+
- ignore: silently disregard any missing source files.
|
| 79 |
+
- newer: treat missing source files as "target out of date". This
|
| 80 |
+
mode is handy in "dry-run" mode: it will pretend to carry out
|
| 81 |
+
commands that wouldn't work because inputs are missing, but
|
| 82 |
+
that doesn't matter because dry-run won't run the commands.
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
def missing_as_newer(source):
|
| 86 |
+
return missing == 'newer' and not os.path.exists(source)
|
| 87 |
+
|
| 88 |
+
ignored = os.path.exists if missing == 'ignore' else None
|
| 89 |
+
return not os.path.exists(target) or any(
|
| 90 |
+
missing_as_newer(source) or _newer(source, target)
|
| 91 |
+
for source in filter(ignored, sources)
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
newer_pairwise_group = functools.partial(newer_pairwise, newer=newer_group)
|
lib/python3.11/site-packages/setuptools/_distutils/_msvccompiler.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
|
| 3 |
+
from .compilers.C import msvc
|
| 4 |
+
|
| 5 |
+
__all__ = ["MSVCCompiler"]
|
| 6 |
+
|
| 7 |
+
MSVCCompiler = msvc.Compiler
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def __getattr__(name):
|
| 11 |
+
if name == '_get_vc_env':
|
| 12 |
+
warnings.warn(
|
| 13 |
+
"_get_vc_env is private; find an alternative (pypa/distutils#340)"
|
| 14 |
+
)
|
| 15 |
+
return msvc._get_vc_env
|
| 16 |
+
raise AttributeError(name)
|
lib/python3.11/site-packages/setuptools/_distutils/archive_util.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 2 |
+
|
| 3 |
+
Utility functions for creating archive files (tarballs, zip files,
|
| 4 |
+
that sort of thing)."""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
from typing import Literal, overload
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
import zipfile
|
| 13 |
+
except ImportError:
|
| 14 |
+
zipfile = None
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
from ._log import log
|
| 18 |
+
from .dir_util import mkpath
|
| 19 |
+
from .errors import DistutilsExecError
|
| 20 |
+
from .spawn import spawn
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
from pwd import getpwnam
|
| 24 |
+
except ImportError:
|
| 25 |
+
getpwnam = None
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
from grp import getgrnam
|
| 29 |
+
except ImportError:
|
| 30 |
+
getgrnam = None
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _get_gid(name):
|
| 34 |
+
"""Returns a gid, given a group name."""
|
| 35 |
+
if getgrnam is None or name is None:
|
| 36 |
+
return None
|
| 37 |
+
try:
|
| 38 |
+
result = getgrnam(name)
|
| 39 |
+
except KeyError:
|
| 40 |
+
result = None
|
| 41 |
+
if result is not None:
|
| 42 |
+
return result[2]
|
| 43 |
+
return None
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _get_uid(name):
|
| 47 |
+
"""Returns an uid, given a user name."""
|
| 48 |
+
if getpwnam is None or name is None:
|
| 49 |
+
return None
|
| 50 |
+
try:
|
| 51 |
+
result = getpwnam(name)
|
| 52 |
+
except KeyError:
|
| 53 |
+
result = None
|
| 54 |
+
if result is not None:
|
| 55 |
+
return result[2]
|
| 56 |
+
return None
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def make_tarball(
|
| 60 |
+
base_name: str,
|
| 61 |
+
base_dir: str | os.PathLike[str],
|
| 62 |
+
compress: Literal["gzip", "bzip2", "xz"] | None = "gzip",
|
| 63 |
+
verbose: bool = False,
|
| 64 |
+
owner: str | None = None,
|
| 65 |
+
group: str | None = None,
|
| 66 |
+
) -> str:
|
| 67 |
+
"""Create a (possibly compressed) tar file from all the files under
|
| 68 |
+
'base_dir'.
|
| 69 |
+
|
| 70 |
+
'compress' must be "gzip" (the default), "bzip2", "xz", or None.
|
| 71 |
+
|
| 72 |
+
'owner' and 'group' can be used to define an owner and a group for the
|
| 73 |
+
archive that is being built. If not provided, the current owner and group
|
| 74 |
+
will be used.
|
| 75 |
+
|
| 76 |
+
The output tar file will be named 'base_dir' + ".tar", possibly plus
|
| 77 |
+
the appropriate compression extension (".gz", ".bz2", ".xz" or ".Z").
|
| 78 |
+
|
| 79 |
+
Returns the output filename.
|
| 80 |
+
"""
|
| 81 |
+
tar_compression = {
|
| 82 |
+
'gzip': 'gz',
|
| 83 |
+
'bzip2': 'bz2',
|
| 84 |
+
'xz': 'xz',
|
| 85 |
+
None: '',
|
| 86 |
+
}
|
| 87 |
+
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz'}
|
| 88 |
+
|
| 89 |
+
# flags for compression program, each element of list will be an argument
|
| 90 |
+
if compress is not None and compress not in compress_ext.keys():
|
| 91 |
+
raise ValueError(
|
| 92 |
+
"bad value for 'compress': must be None, 'gzip', 'bzip2', 'xz'"
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
archive_name = base_name + '.tar'
|
| 96 |
+
archive_name += compress_ext.get(compress, '')
|
| 97 |
+
|
| 98 |
+
mkpath(os.path.dirname(archive_name))
|
| 99 |
+
|
| 100 |
+
# creating the tarball
|
| 101 |
+
import tarfile # late import so Python build itself doesn't break
|
| 102 |
+
|
| 103 |
+
log.info('Creating tar archive')
|
| 104 |
+
|
| 105 |
+
uid = _get_uid(owner)
|
| 106 |
+
gid = _get_gid(group)
|
| 107 |
+
|
| 108 |
+
def _set_uid_gid(tarinfo):
|
| 109 |
+
if gid is not None:
|
| 110 |
+
tarinfo.gid = gid
|
| 111 |
+
tarinfo.gname = group
|
| 112 |
+
if uid is not None:
|
| 113 |
+
tarinfo.uid = uid
|
| 114 |
+
tarinfo.uname = owner
|
| 115 |
+
return tarinfo
|
| 116 |
+
|
| 117 |
+
tar = tarfile.open(archive_name, f'w|{tar_compression[compress]}')
|
| 118 |
+
try:
|
| 119 |
+
tar.add(base_dir, filter=_set_uid_gid)
|
| 120 |
+
finally:
|
| 121 |
+
tar.close()
|
| 122 |
+
|
| 123 |
+
return archive_name
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def make_zipfile(
|
| 127 |
+
base_name: str,
|
| 128 |
+
base_dir: str | os.PathLike[str],
|
| 129 |
+
verbose: bool = False,
|
| 130 |
+
) -> str:
|
| 131 |
+
"""Create a zip file from all the files under 'base_dir'.
|
| 132 |
+
|
| 133 |
+
The output zip file will be named 'base_name' + ".zip". Uses either the
|
| 134 |
+
"zipfile" Python module (if available) or the InfoZIP "zip" utility
|
| 135 |
+
(if installed and found on the default search path). If neither tool is
|
| 136 |
+
available, raises DistutilsExecError. Returns the name of the output zip
|
| 137 |
+
file.
|
| 138 |
+
"""
|
| 139 |
+
zip_filename = base_name + ".zip"
|
| 140 |
+
mkpath(os.path.dirname(zip_filename))
|
| 141 |
+
|
| 142 |
+
# If zipfile module is not available, try spawning an external
|
| 143 |
+
# 'zip' command.
|
| 144 |
+
if zipfile is None:
|
| 145 |
+
if verbose:
|
| 146 |
+
zipoptions = "-r"
|
| 147 |
+
else:
|
| 148 |
+
zipoptions = "-rq"
|
| 149 |
+
|
| 150 |
+
try:
|
| 151 |
+
spawn(["zip", zipoptions, zip_filename, base_dir])
|
| 152 |
+
except DistutilsExecError:
|
| 153 |
+
# XXX really should distinguish between "couldn't find
|
| 154 |
+
# external 'zip' command" and "zip failed".
|
| 155 |
+
raise DistutilsExecError(
|
| 156 |
+
f"unable to create zip file '{zip_filename}': "
|
| 157 |
+
"could neither import the 'zipfile' module nor "
|
| 158 |
+
"find a standalone zip utility"
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
else:
|
| 162 |
+
log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir)
|
| 163 |
+
|
| 164 |
+
try:
|
| 165 |
+
zip = zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_DEFLATED)
|
| 166 |
+
except RuntimeError:
|
| 167 |
+
zip = zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_STORED)
|
| 168 |
+
|
| 169 |
+
with zip:
|
| 170 |
+
if base_dir != os.curdir:
|
| 171 |
+
path = os.path.normpath(os.path.join(base_dir, ''))
|
| 172 |
+
zip.write(path, path)
|
| 173 |
+
log.info("adding '%s'", path)
|
| 174 |
+
for dirpath, dirnames, filenames in os.walk(base_dir):
|
| 175 |
+
for name in dirnames:
|
| 176 |
+
path = os.path.normpath(os.path.join(dirpath, name, ''))
|
| 177 |
+
zip.write(path, path)
|
| 178 |
+
log.info("adding '%s'", path)
|
| 179 |
+
for name in filenames:
|
| 180 |
+
path = os.path.normpath(os.path.join(dirpath, name))
|
| 181 |
+
if os.path.isfile(path):
|
| 182 |
+
zip.write(path, path)
|
| 183 |
+
log.info("adding '%s'", path)
|
| 184 |
+
|
| 185 |
+
return zip_filename
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
ARCHIVE_FORMATS = {
|
| 189 |
+
'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
|
| 190 |
+
'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
|
| 191 |
+
'xztar': (make_tarball, [('compress', 'xz')], "xz'ed tar-file"),
|
| 192 |
+
'ztar': (make_tarball, [('compress', 'compress')], "compressed tar file"),
|
| 193 |
+
'tar': (make_tarball, [('compress', None)], "uncompressed tar file"),
|
| 194 |
+
'zip': (make_zipfile, [], "ZIP file"),
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def check_archive_formats(formats):
|
| 199 |
+
"""Returns the first format from the 'format' list that is unknown.
|
| 200 |
+
|
| 201 |
+
If all formats are known, returns None
|
| 202 |
+
"""
|
| 203 |
+
for format in formats:
|
| 204 |
+
if format not in ARCHIVE_FORMATS:
|
| 205 |
+
return format
|
| 206 |
+
return None
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
@overload
|
| 210 |
+
def make_archive(
|
| 211 |
+
base_name: str,
|
| 212 |
+
format: str,
|
| 213 |
+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
|
| 214 |
+
base_dir: str | None = None,
|
| 215 |
+
verbose: bool = False,
|
| 216 |
+
owner: str | None = None,
|
| 217 |
+
group: str | None = None,
|
| 218 |
+
) -> str: ...
|
| 219 |
+
@overload
|
| 220 |
+
def make_archive(
|
| 221 |
+
base_name: str | os.PathLike[str],
|
| 222 |
+
format: str,
|
| 223 |
+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 224 |
+
base_dir: str | None = None,
|
| 225 |
+
verbose: bool = False,
|
| 226 |
+
owner: str | None = None,
|
| 227 |
+
group: str | None = None,
|
| 228 |
+
) -> str: ...
|
| 229 |
+
def make_archive(
|
| 230 |
+
base_name: str | os.PathLike[str],
|
| 231 |
+
format: str,
|
| 232 |
+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
|
| 233 |
+
base_dir: str | None = None,
|
| 234 |
+
verbose: bool = False,
|
| 235 |
+
owner: str | None = None,
|
| 236 |
+
group: str | None = None,
|
| 237 |
+
) -> str:
|
| 238 |
+
"""Create an archive file (eg. zip or tar).
|
| 239 |
+
|
| 240 |
+
'base_name' is the name of the file to create, minus any format-specific
|
| 241 |
+
extension; 'format' is the archive format: one of "zip", "tar", "gztar",
|
| 242 |
+
"bztar", "xztar", or "ztar".
|
| 243 |
+
|
| 244 |
+
'root_dir' is a directory that will be the root directory of the
|
| 245 |
+
archive; ie. we typically chdir into 'root_dir' before creating the
|
| 246 |
+
archive. 'base_dir' is the directory where we start archiving from;
|
| 247 |
+
ie. 'base_dir' will be the common prefix of all files and
|
| 248 |
+
directories in the archive. 'root_dir' and 'base_dir' both default
|
| 249 |
+
to the current directory. Returns the name of the archive file.
|
| 250 |
+
|
| 251 |
+
'owner' and 'group' are used when creating a tar archive. By default,
|
| 252 |
+
uses the current owner and group.
|
| 253 |
+
"""
|
| 254 |
+
save_cwd = os.getcwd()
|
| 255 |
+
if root_dir is not None:
|
| 256 |
+
log.debug("changing into '%s'", root_dir)
|
| 257 |
+
base_name = os.path.abspath(base_name)
|
| 258 |
+
os.chdir(root_dir)
|
| 259 |
+
|
| 260 |
+
if base_dir is None:
|
| 261 |
+
base_dir = os.curdir
|
| 262 |
+
|
| 263 |
+
kwargs: dict[str, bool | None] = {}
|
| 264 |
+
|
| 265 |
+
try:
|
| 266 |
+
format_info = ARCHIVE_FORMATS[format]
|
| 267 |
+
except KeyError:
|
| 268 |
+
raise ValueError(f"unknown archive format '{format}'")
|
| 269 |
+
|
| 270 |
+
func = format_info[0]
|
| 271 |
+
kwargs.update(format_info[1])
|
| 272 |
+
|
| 273 |
+
if format != 'zip':
|
| 274 |
+
kwargs['owner'] = owner
|
| 275 |
+
kwargs['group'] = group
|
| 276 |
+
|
| 277 |
+
try:
|
| 278 |
+
filename = func(base_name, base_dir, **kwargs)
|
| 279 |
+
finally:
|
| 280 |
+
if root_dir is not None:
|
| 281 |
+
log.debug("changing back to '%s'", save_cwd)
|
| 282 |
+
os.chdir(save_cwd)
|
| 283 |
+
|
| 284 |
+
return filename
|
lib/python3.11/site-packages/setuptools/_distutils/ccompiler.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .compat.numpy import ( # noqa: F401
|
| 2 |
+
_default_compilers,
|
| 3 |
+
compiler_class,
|
| 4 |
+
)
|
| 5 |
+
from .compilers.C import base
|
| 6 |
+
from .compilers.C.base import (
|
| 7 |
+
gen_lib_options,
|
| 8 |
+
gen_preprocess_options,
|
| 9 |
+
get_default_compiler,
|
| 10 |
+
new_compiler,
|
| 11 |
+
show_compilers,
|
| 12 |
+
)
|
| 13 |
+
from .compilers.C.errors import CompileError, LinkError
|
| 14 |
+
|
| 15 |
+
__all__ = [
|
| 16 |
+
'CompileError',
|
| 17 |
+
'LinkError',
|
| 18 |
+
'gen_lib_options',
|
| 19 |
+
'gen_preprocess_options',
|
| 20 |
+
'get_default_compiler',
|
| 21 |
+
'new_compiler',
|
| 22 |
+
'show_compilers',
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
CCompiler = base.Compiler
|
lib/python3.11/site-packages/setuptools/_distutils/cmd.py
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.cmd
|
| 2 |
+
|
| 3 |
+
Provides the Command class, the base class for the command classes
|
| 4 |
+
in the distutils.command package.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import logging
|
| 10 |
+
import os
|
| 11 |
+
import re
|
| 12 |
+
import sys
|
| 13 |
+
from abc import abstractmethod
|
| 14 |
+
from collections.abc import Callable, MutableSequence
|
| 15 |
+
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, overload
|
| 16 |
+
|
| 17 |
+
from . import _modified, archive_util, dir_util, file_util, util
|
| 18 |
+
from ._log import log
|
| 19 |
+
from .errors import DistutilsOptionError
|
| 20 |
+
|
| 21 |
+
if TYPE_CHECKING:
|
| 22 |
+
# type-only import because of mutual dependence between these classes
|
| 23 |
+
from distutils.dist import Distribution
|
| 24 |
+
|
| 25 |
+
from typing_extensions import TypeVarTuple, Unpack
|
| 26 |
+
|
| 27 |
+
_Ts = TypeVarTuple("_Ts")
|
| 28 |
+
|
| 29 |
+
_StrPathT = TypeVar("_StrPathT", bound="str | os.PathLike[str]")
|
| 30 |
+
_BytesPathT = TypeVar("_BytesPathT", bound="bytes | os.PathLike[bytes]")
|
| 31 |
+
_CommandT = TypeVar("_CommandT", bound="Command")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Command:
|
| 35 |
+
"""Abstract base class for defining command classes, the "worker bees"
|
| 36 |
+
of the Distutils. A useful analogy for command classes is to think of
|
| 37 |
+
them as subroutines with local variables called "options". The options
|
| 38 |
+
are "declared" in 'initialize_options()' and "defined" (given their
|
| 39 |
+
final values, aka "finalized") in 'finalize_options()', both of which
|
| 40 |
+
must be defined by every command class. The distinction between the
|
| 41 |
+
two is necessary because option values might come from the outside
|
| 42 |
+
world (command line, config file, ...), and any options dependent on
|
| 43 |
+
other options must be computed *after* these outside influences have
|
| 44 |
+
been processed -- hence 'finalize_options()'. The "body" of the
|
| 45 |
+
subroutine, where it does all its work based on the values of its
|
| 46 |
+
options, is the 'run()' method, which must also be implemented by every
|
| 47 |
+
command class.
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
# 'sub_commands' formalizes the notion of a "family" of commands,
|
| 51 |
+
# eg. "install" as the parent with sub-commands "install_lib",
|
| 52 |
+
# "install_headers", etc. The parent of a family of commands
|
| 53 |
+
# defines 'sub_commands' as a class attribute; it's a list of
|
| 54 |
+
# (command_name : string, predicate : unbound_method | string | None)
|
| 55 |
+
# tuples, where 'predicate' is a method of the parent command that
|
| 56 |
+
# determines whether the corresponding command is applicable in the
|
| 57 |
+
# current situation. (Eg. we "install_headers" is only applicable if
|
| 58 |
+
# we have any C header files to install.) If 'predicate' is None,
|
| 59 |
+
# that command is always applicable.
|
| 60 |
+
#
|
| 61 |
+
# 'sub_commands' is usually defined at the *end* of a class, because
|
| 62 |
+
# predicates can be unbound methods, so they must already have been
|
| 63 |
+
# defined. The canonical example is the "install" command.
|
| 64 |
+
sub_commands: ClassVar[ # Any to work around variance issues
|
| 65 |
+
list[tuple[str, Callable[[Any], bool] | None]]
|
| 66 |
+
] = []
|
| 67 |
+
|
| 68 |
+
user_options: ClassVar[
|
| 69 |
+
# Specifying both because list is invariant. Avoids mypy override assignment issues
|
| 70 |
+
list[tuple[str, str, str]] | list[tuple[str, str | None, str]]
|
| 71 |
+
] = []
|
| 72 |
+
|
| 73 |
+
# -- Creation/initialization methods -------------------------------
|
| 74 |
+
|
| 75 |
+
def __init__(self, dist: Distribution) -> None:
|
| 76 |
+
"""Create and initialize a new Command object. Most importantly,
|
| 77 |
+
invokes the 'initialize_options()' method, which is the real
|
| 78 |
+
initializer and depends on the actual command being
|
| 79 |
+
instantiated.
|
| 80 |
+
"""
|
| 81 |
+
# late import because of mutual dependence between these classes
|
| 82 |
+
from distutils.dist import Distribution
|
| 83 |
+
|
| 84 |
+
if not isinstance(dist, Distribution):
|
| 85 |
+
raise TypeError("dist must be a Distribution instance")
|
| 86 |
+
if self.__class__ is Command:
|
| 87 |
+
raise RuntimeError("Command is an abstract class")
|
| 88 |
+
|
| 89 |
+
self.distribution = dist
|
| 90 |
+
self.initialize_options()
|
| 91 |
+
|
| 92 |
+
# Per-command versions of the global flags, so that the user can
|
| 93 |
+
# customize Distutils' behaviour command-by-command and let some
|
| 94 |
+
# commands fall back on the Distribution's behaviour. None means
|
| 95 |
+
# "not defined, check self.distribution's copy".
|
| 96 |
+
|
| 97 |
+
# verbose is largely ignored, but needs to be set for
|
| 98 |
+
# backwards compatibility (I think)?
|
| 99 |
+
self.verbose = dist.verbose
|
| 100 |
+
|
| 101 |
+
# Some commands define a 'self.force' option to ignore file
|
| 102 |
+
# timestamps, but methods defined *here* assume that
|
| 103 |
+
# 'self.force' exists for all commands. So define it here
|
| 104 |
+
# just to be safe.
|
| 105 |
+
self.force = None
|
| 106 |
+
|
| 107 |
+
# The 'help' flag is just used for command-line parsing, so
|
| 108 |
+
# none of that complicated bureaucracy is needed.
|
| 109 |
+
self.help = False
|
| 110 |
+
|
| 111 |
+
# 'finalized' records whether or not 'finalize_options()' has been
|
| 112 |
+
# called. 'finalize_options()' itself should not pay attention to
|
| 113 |
+
# this flag: it is the business of 'ensure_finalized()', which
|
| 114 |
+
# always calls 'finalize_options()', to respect/update it.
|
| 115 |
+
self.finalized = False
|
| 116 |
+
|
| 117 |
+
def ensure_finalized(self) -> None:
|
| 118 |
+
if not self.finalized:
|
| 119 |
+
self.finalize_options()
|
| 120 |
+
self.finalized = True
|
| 121 |
+
|
| 122 |
+
# Subclasses must define:
|
| 123 |
+
# initialize_options()
|
| 124 |
+
# provide default values for all options; may be customized by
|
| 125 |
+
# setup script, by options from config file(s), or by command-line
|
| 126 |
+
# options
|
| 127 |
+
# finalize_options()
|
| 128 |
+
# decide on the final values for all options; this is called
|
| 129 |
+
# after all possible intervention from the outside world
|
| 130 |
+
# (command-line, option file, etc.) has been processed
|
| 131 |
+
# run()
|
| 132 |
+
# run the command: do whatever it is we're here to do,
|
| 133 |
+
# controlled by the command's various option values
|
| 134 |
+
|
| 135 |
+
@abstractmethod
|
| 136 |
+
def initialize_options(self) -> None:
|
| 137 |
+
"""Set default values for all the options that this command
|
| 138 |
+
supports. Note that these defaults may be overridden by other
|
| 139 |
+
commands, by the setup script, by config files, or by the
|
| 140 |
+
command-line. Thus, this is not the place to code dependencies
|
| 141 |
+
between options; generally, 'initialize_options()' implementations
|
| 142 |
+
are just a bunch of "self.foo = None" assignments.
|
| 143 |
+
|
| 144 |
+
This method must be implemented by all command classes.
|
| 145 |
+
"""
|
| 146 |
+
raise RuntimeError(
|
| 147 |
+
f"abstract method -- subclass {self.__class__} must override"
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
@abstractmethod
|
| 151 |
+
def finalize_options(self) -> None:
|
| 152 |
+
"""Set final values for all the options that this command supports.
|
| 153 |
+
This is always called as late as possible, ie. after any option
|
| 154 |
+
assignments from the command-line or from other commands have been
|
| 155 |
+
done. Thus, this is the place to code option dependencies: if
|
| 156 |
+
'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as
|
| 157 |
+
long as 'foo' still has the same value it was assigned in
|
| 158 |
+
'initialize_options()'.
|
| 159 |
+
|
| 160 |
+
This method must be implemented by all command classes.
|
| 161 |
+
"""
|
| 162 |
+
raise RuntimeError(
|
| 163 |
+
f"abstract method -- subclass {self.__class__} must override"
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
def dump_options(self, header=None, indent=""):
|
| 167 |
+
from distutils.fancy_getopt import longopt_xlate
|
| 168 |
+
|
| 169 |
+
if header is None:
|
| 170 |
+
header = f"command options for '{self.get_command_name()}':"
|
| 171 |
+
self.announce(indent + header, level=logging.INFO)
|
| 172 |
+
indent = indent + " "
|
| 173 |
+
for option, _, _ in self.user_options:
|
| 174 |
+
option = option.translate(longopt_xlate)
|
| 175 |
+
if option[-1] == "=":
|
| 176 |
+
option = option[:-1]
|
| 177 |
+
value = getattr(self, option)
|
| 178 |
+
self.announce(indent + f"{option} = {value}", level=logging.INFO)
|
| 179 |
+
|
| 180 |
+
@abstractmethod
|
| 181 |
+
def run(self) -> None:
|
| 182 |
+
"""A command's raison d'etre: carry out the action it exists to
|
| 183 |
+
perform, controlled by the options initialized in
|
| 184 |
+
'initialize_options()', customized by other commands, the setup
|
| 185 |
+
script, the command-line, and config files, and finalized in
|
| 186 |
+
'finalize_options()'. All terminal output and filesystem
|
| 187 |
+
interaction should be done by 'run()'.
|
| 188 |
+
|
| 189 |
+
This method must be implemented by all command classes.
|
| 190 |
+
"""
|
| 191 |
+
raise RuntimeError(
|
| 192 |
+
f"abstract method -- subclass {self.__class__} must override"
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
def announce(self, msg: object, level: int = logging.DEBUG) -> None:
|
| 196 |
+
log.log(level, msg)
|
| 197 |
+
|
| 198 |
+
def debug_print(self, msg: object) -> None:
|
| 199 |
+
"""Print 'msg' to stdout if the global DEBUG (taken from the
|
| 200 |
+
DISTUTILS_DEBUG environment variable) flag is true.
|
| 201 |
+
"""
|
| 202 |
+
from distutils.debug import DEBUG
|
| 203 |
+
|
| 204 |
+
if DEBUG:
|
| 205 |
+
print(msg)
|
| 206 |
+
sys.stdout.flush()
|
| 207 |
+
|
| 208 |
+
# -- Option validation methods -------------------------------------
|
| 209 |
+
# (these are very handy in writing the 'finalize_options()' method)
|
| 210 |
+
#
|
| 211 |
+
# NB. the general philosophy here is to ensure that a particular option
|
| 212 |
+
# value meets certain type and value constraints. If not, we try to
|
| 213 |
+
# force it into conformance (eg. if we expect a list but have a string,
|
| 214 |
+
# split the string on comma and/or whitespace). If we can't force the
|
| 215 |
+
# option into conformance, raise DistutilsOptionError. Thus, command
|
| 216 |
+
# classes need do nothing more than (eg.)
|
| 217 |
+
# self.ensure_string_list('foo')
|
| 218 |
+
# and they can be guaranteed that thereafter, self.foo will be
|
| 219 |
+
# a list of strings.
|
| 220 |
+
|
| 221 |
+
def _ensure_stringlike(self, option, what, default=None):
|
| 222 |
+
val = getattr(self, option)
|
| 223 |
+
if val is None:
|
| 224 |
+
setattr(self, option, default)
|
| 225 |
+
return default
|
| 226 |
+
elif not isinstance(val, str):
|
| 227 |
+
raise DistutilsOptionError(f"'{option}' must be a {what} (got `{val}`)")
|
| 228 |
+
return val
|
| 229 |
+
|
| 230 |
+
def ensure_string(self, option: str, default: str | None = None) -> None:
|
| 231 |
+
"""Ensure that 'option' is a string; if not defined, set it to
|
| 232 |
+
'default'.
|
| 233 |
+
"""
|
| 234 |
+
self._ensure_stringlike(option, "string", default)
|
| 235 |
+
|
| 236 |
+
def ensure_string_list(self, option: str) -> None:
|
| 237 |
+
r"""Ensure that 'option' is a list of strings. If 'option' is
|
| 238 |
+
currently a string, we split it either on /,\s*/ or /\s+/, so
|
| 239 |
+
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
|
| 240 |
+
["foo", "bar", "baz"].
|
| 241 |
+
"""
|
| 242 |
+
val = getattr(self, option)
|
| 243 |
+
if val is None:
|
| 244 |
+
return
|
| 245 |
+
elif isinstance(val, str):
|
| 246 |
+
setattr(self, option, re.split(r',\s*|\s+', val))
|
| 247 |
+
else:
|
| 248 |
+
if isinstance(val, list):
|
| 249 |
+
ok = all(isinstance(v, str) for v in val)
|
| 250 |
+
else:
|
| 251 |
+
ok = False
|
| 252 |
+
if not ok:
|
| 253 |
+
raise DistutilsOptionError(
|
| 254 |
+
f"'{option}' must be a list of strings (got {val!r})"
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
def _ensure_tested_string(self, option, tester, what, error_fmt, default=None):
|
| 258 |
+
val = self._ensure_stringlike(option, what, default)
|
| 259 |
+
if val is not None and not tester(val):
|
| 260 |
+
raise DistutilsOptionError(
|
| 261 |
+
("error in '%s' option: " + error_fmt) % (option, val)
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
def ensure_filename(self, option: str) -> None:
|
| 265 |
+
"""Ensure that 'option' is the name of an existing file."""
|
| 266 |
+
self._ensure_tested_string(
|
| 267 |
+
option, os.path.isfile, "filename", "'%s' does not exist or is not a file"
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
def ensure_dirname(self, option: str) -> None:
|
| 271 |
+
self._ensure_tested_string(
|
| 272 |
+
option,
|
| 273 |
+
os.path.isdir,
|
| 274 |
+
"directory name",
|
| 275 |
+
"'%s' does not exist or is not a directory",
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
# -- Convenience methods for commands ------------------------------
|
| 279 |
+
|
| 280 |
+
def get_command_name(self) -> str:
|
| 281 |
+
if hasattr(self, 'command_name'):
|
| 282 |
+
return self.command_name
|
| 283 |
+
else:
|
| 284 |
+
return self.__class__.__name__
|
| 285 |
+
|
| 286 |
+
def set_undefined_options(
|
| 287 |
+
self, src_cmd: str, *option_pairs: tuple[str, str]
|
| 288 |
+
) -> None:
|
| 289 |
+
"""Set the values of any "undefined" options from corresponding
|
| 290 |
+
option values in some other command object. "Undefined" here means
|
| 291 |
+
"is None", which is the convention used to indicate that an option
|
| 292 |
+
has not been changed between 'initialize_options()' and
|
| 293 |
+
'finalize_options()'. Usually called from 'finalize_options()' for
|
| 294 |
+
options that depend on some other command rather than another
|
| 295 |
+
option of the same command. 'src_cmd' is the other command from
|
| 296 |
+
which option values will be taken (a command object will be created
|
| 297 |
+
for it if necessary); the remaining arguments are
|
| 298 |
+
'(src_option,dst_option)' tuples which mean "take the value of
|
| 299 |
+
'src_option' in the 'src_cmd' command object, and copy it to
|
| 300 |
+
'dst_option' in the current command object".
|
| 301 |
+
"""
|
| 302 |
+
# Option_pairs: list of (src_option, dst_option) tuples
|
| 303 |
+
src_cmd_obj = self.distribution.get_command_obj(src_cmd)
|
| 304 |
+
src_cmd_obj.ensure_finalized()
|
| 305 |
+
for src_option, dst_option in option_pairs:
|
| 306 |
+
if getattr(self, dst_option) is None:
|
| 307 |
+
setattr(self, dst_option, getattr(src_cmd_obj, src_option))
|
| 308 |
+
|
| 309 |
+
# NOTE: Because distutils is private to Setuptools and not all commands are exposed here,
|
| 310 |
+
# not every possible command is enumerated in the signature.
|
| 311 |
+
def get_finalized_command(self, command: str, create: bool = True) -> Command:
|
| 312 |
+
"""Wrapper around Distribution's 'get_command_obj()' method: find
|
| 313 |
+
(create if necessary and 'create' is true) the command object for
|
| 314 |
+
'command', call its 'ensure_finalized()' method, and return the
|
| 315 |
+
finalized command object.
|
| 316 |
+
"""
|
| 317 |
+
cmd_obj = self.distribution.get_command_obj(command, create)
|
| 318 |
+
cmd_obj.ensure_finalized()
|
| 319 |
+
return cmd_obj
|
| 320 |
+
|
| 321 |
+
# XXX rename to 'get_reinitialized_command()'? (should do the
|
| 322 |
+
# same in dist.py, if so)
|
| 323 |
+
@overload
|
| 324 |
+
def reinitialize_command(
|
| 325 |
+
self, command: str, reinit_subcommands: bool = False
|
| 326 |
+
) -> Command: ...
|
| 327 |
+
@overload
|
| 328 |
+
def reinitialize_command(
|
| 329 |
+
self, command: _CommandT, reinit_subcommands: bool = False
|
| 330 |
+
) -> _CommandT: ...
|
| 331 |
+
def reinitialize_command(
|
| 332 |
+
self, command: str | Command, reinit_subcommands=False
|
| 333 |
+
) -> Command:
|
| 334 |
+
return self.distribution.reinitialize_command(command, reinit_subcommands)
|
| 335 |
+
|
| 336 |
+
def run_command(self, command: str) -> None:
|
| 337 |
+
"""Run some other command: uses the 'run_command()' method of
|
| 338 |
+
Distribution, which creates and finalizes the command object if
|
| 339 |
+
necessary and then invokes its 'run()' method.
|
| 340 |
+
"""
|
| 341 |
+
self.distribution.run_command(command)
|
| 342 |
+
|
| 343 |
+
def get_sub_commands(self) -> list[str]:
|
| 344 |
+
"""Determine the sub-commands that are relevant in the current
|
| 345 |
+
distribution (ie., that need to be run). This is based on the
|
| 346 |
+
'sub_commands' class attribute: each tuple in that list may include
|
| 347 |
+
a method that we call to determine if the subcommand needs to be
|
| 348 |
+
run for the current distribution. Return a list of command names.
|
| 349 |
+
"""
|
| 350 |
+
commands = []
|
| 351 |
+
for cmd_name, method in self.sub_commands:
|
| 352 |
+
if method is None or method(self):
|
| 353 |
+
commands.append(cmd_name)
|
| 354 |
+
return commands
|
| 355 |
+
|
| 356 |
+
# -- External world manipulation -----------------------------------
|
| 357 |
+
|
| 358 |
+
def warn(self, msg: object) -> None:
|
| 359 |
+
log.warning("warning: %s: %s\n", self.get_command_name(), msg)
|
| 360 |
+
|
| 361 |
+
def execute(
|
| 362 |
+
self,
|
| 363 |
+
func: Callable[[Unpack[_Ts]], object],
|
| 364 |
+
args: tuple[Unpack[_Ts]],
|
| 365 |
+
msg: object = None,
|
| 366 |
+
level: int = 1,
|
| 367 |
+
) -> None:
|
| 368 |
+
util.execute(func, args, msg)
|
| 369 |
+
|
| 370 |
+
def mkpath(self, name: str, mode: int = 0o777) -> None:
|
| 371 |
+
dir_util.mkpath(name, mode)
|
| 372 |
+
|
| 373 |
+
@overload
|
| 374 |
+
def copy_file(
|
| 375 |
+
self,
|
| 376 |
+
infile: str | os.PathLike[str],
|
| 377 |
+
outfile: _StrPathT,
|
| 378 |
+
preserve_mode: bool = True,
|
| 379 |
+
preserve_times: bool = True,
|
| 380 |
+
link: str | None = None,
|
| 381 |
+
level: int = 1,
|
| 382 |
+
) -> tuple[_StrPathT | str, bool]: ...
|
| 383 |
+
@overload
|
| 384 |
+
def copy_file(
|
| 385 |
+
self,
|
| 386 |
+
infile: bytes | os.PathLike[bytes],
|
| 387 |
+
outfile: _BytesPathT,
|
| 388 |
+
preserve_mode: bool = True,
|
| 389 |
+
preserve_times: bool = True,
|
| 390 |
+
link: str | None = None,
|
| 391 |
+
level: int = 1,
|
| 392 |
+
) -> tuple[_BytesPathT | bytes, bool]: ...
|
| 393 |
+
def copy_file(
|
| 394 |
+
self,
|
| 395 |
+
infile: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 396 |
+
outfile: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 397 |
+
preserve_mode: bool = True,
|
| 398 |
+
preserve_times: bool = True,
|
| 399 |
+
link: str | None = None,
|
| 400 |
+
level: int = 1,
|
| 401 |
+
) -> tuple[str | os.PathLike[str] | bytes | os.PathLike[bytes], bool]:
|
| 402 |
+
"""Copy a file respecting verbose, dry-run and force flags. (The
|
| 403 |
+
former two default to whatever is in the Distribution object, and
|
| 404 |
+
the latter defaults to false for commands that don't define it.)"""
|
| 405 |
+
return file_util.copy_file(
|
| 406 |
+
infile,
|
| 407 |
+
outfile,
|
| 408 |
+
preserve_mode,
|
| 409 |
+
preserve_times,
|
| 410 |
+
not self.force,
|
| 411 |
+
link,
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
def copy_tree(
|
| 415 |
+
self,
|
| 416 |
+
infile: str | os.PathLike[str],
|
| 417 |
+
outfile: str,
|
| 418 |
+
preserve_mode: bool = True,
|
| 419 |
+
preserve_times: bool = True,
|
| 420 |
+
preserve_symlinks: bool = False,
|
| 421 |
+
level: int = 1,
|
| 422 |
+
) -> list[str]:
|
| 423 |
+
"""Copy an entire directory tree respecting verbose, dry-run,
|
| 424 |
+
and force flags.
|
| 425 |
+
"""
|
| 426 |
+
return dir_util.copy_tree(
|
| 427 |
+
infile,
|
| 428 |
+
outfile,
|
| 429 |
+
preserve_mode,
|
| 430 |
+
preserve_times,
|
| 431 |
+
preserve_symlinks,
|
| 432 |
+
not self.force,
|
| 433 |
+
)
|
| 434 |
+
|
| 435 |
+
@overload
|
| 436 |
+
def move_file(
|
| 437 |
+
self, src: str | os.PathLike[str], dst: _StrPathT, level: int = 1
|
| 438 |
+
) -> _StrPathT | str: ...
|
| 439 |
+
@overload
|
| 440 |
+
def move_file(
|
| 441 |
+
self, src: bytes | os.PathLike[bytes], dst: _BytesPathT, level: int = 1
|
| 442 |
+
) -> _BytesPathT | bytes: ...
|
| 443 |
+
def move_file(
|
| 444 |
+
self,
|
| 445 |
+
src: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 446 |
+
dst: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 447 |
+
level: int = 1,
|
| 448 |
+
) -> str | os.PathLike[str] | bytes | os.PathLike[bytes]:
|
| 449 |
+
"""Move a file respecting dry-run flag."""
|
| 450 |
+
return file_util.move_file(src, dst)
|
| 451 |
+
|
| 452 |
+
def spawn(
|
| 453 |
+
self, cmd: MutableSequence[str], search_path: bool = True, level: int = 1
|
| 454 |
+
) -> None:
|
| 455 |
+
"""Spawn an external command respecting dry-run flag."""
|
| 456 |
+
from distutils.spawn import spawn
|
| 457 |
+
|
| 458 |
+
spawn(cmd, search_path)
|
| 459 |
+
|
| 460 |
+
@overload
|
| 461 |
+
def make_archive(
|
| 462 |
+
self,
|
| 463 |
+
base_name: str,
|
| 464 |
+
format: str,
|
| 465 |
+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
|
| 466 |
+
base_dir: str | None = None,
|
| 467 |
+
owner: str | None = None,
|
| 468 |
+
group: str | None = None,
|
| 469 |
+
) -> str: ...
|
| 470 |
+
@overload
|
| 471 |
+
def make_archive(
|
| 472 |
+
self,
|
| 473 |
+
base_name: str | os.PathLike[str],
|
| 474 |
+
format: str,
|
| 475 |
+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 476 |
+
base_dir: str | None = None,
|
| 477 |
+
owner: str | None = None,
|
| 478 |
+
group: str | None = None,
|
| 479 |
+
) -> str: ...
|
| 480 |
+
def make_archive(
|
| 481 |
+
self,
|
| 482 |
+
base_name: str | os.PathLike[str],
|
| 483 |
+
format: str,
|
| 484 |
+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
|
| 485 |
+
base_dir: str | None = None,
|
| 486 |
+
owner: str | None = None,
|
| 487 |
+
group: str | None = None,
|
| 488 |
+
) -> str:
|
| 489 |
+
return archive_util.make_archive(
|
| 490 |
+
base_name,
|
| 491 |
+
format,
|
| 492 |
+
root_dir,
|
| 493 |
+
base_dir,
|
| 494 |
+
owner=owner,
|
| 495 |
+
group=group,
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
def make_file(
|
| 499 |
+
self,
|
| 500 |
+
infiles: str | list[str] | tuple[str, ...],
|
| 501 |
+
outfile: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 502 |
+
func: Callable[[Unpack[_Ts]], object],
|
| 503 |
+
args: tuple[Unpack[_Ts]],
|
| 504 |
+
exec_msg: object = None,
|
| 505 |
+
skip_msg: object = None,
|
| 506 |
+
level: int = 1,
|
| 507 |
+
) -> None:
|
| 508 |
+
"""Special case of 'execute()' for operations that process one or
|
| 509 |
+
more input files and generate one output file. Works just like
|
| 510 |
+
'execute()', except the operation is skipped and a different
|
| 511 |
+
message printed if 'outfile' already exists and is newer than all
|
| 512 |
+
files listed in 'infiles'. If the command defined 'self.force',
|
| 513 |
+
and it is true, then the command is unconditionally run -- does no
|
| 514 |
+
timestamp checks.
|
| 515 |
+
"""
|
| 516 |
+
if skip_msg is None:
|
| 517 |
+
skip_msg = f"skipping {outfile} (inputs unchanged)"
|
| 518 |
+
|
| 519 |
+
# Allow 'infiles' to be a single string
|
| 520 |
+
if isinstance(infiles, str):
|
| 521 |
+
infiles = (infiles,)
|
| 522 |
+
elif not isinstance(infiles, (list, tuple)):
|
| 523 |
+
raise TypeError("'infiles' must be a string, or a list or tuple of strings")
|
| 524 |
+
|
| 525 |
+
if exec_msg is None:
|
| 526 |
+
exec_msg = "generating {} from {}".format(outfile, ', '.join(infiles))
|
| 527 |
+
|
| 528 |
+
# If 'outfile' must be regenerated (either because it doesn't
|
| 529 |
+
# exist, is out-of-date, or the 'force' flag is true) then
|
| 530 |
+
# perform the action that presumably regenerates it
|
| 531 |
+
if self.force or _modified.newer_group(infiles, outfile):
|
| 532 |
+
self.execute(func, args, exec_msg, level)
|
| 533 |
+
# Otherwise, print the "skip" message
|
| 534 |
+
else:
|
| 535 |
+
log.debug(skip_msg)
|