Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- valley/lib/python3.10/site-packages/setuptools/__init__.py +286 -0
- valley/lib/python3.10/site-packages/setuptools/_core_metadata.py +321 -0
- valley/lib/python3.10/site-packages/setuptools/_entry_points.py +90 -0
- valley/lib/python3.10/site-packages/setuptools/_importlib.py +9 -0
- valley/lib/python3.10/site-packages/setuptools/_path.py +84 -0
- valley/lib/python3.10/site-packages/setuptools/_static.py +188 -0
- valley/lib/python3.10/site-packages/setuptools/cli-arm64.exe +0 -0
- valley/lib/python3.10/site-packages/setuptools/cli.exe +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/NOTICE +10 -0
- valley/lib/python3.10/site-packages/setuptools/config/__pycache__/__init__.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/__pycache__/_apply_pyprojecttoml.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/__pycache__/expand.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/__pycache__/pyprojecttoml.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/__pycache__/setupcfg.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/__init__.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/error_reporting.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/extra_validations.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_exceptions.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/formats.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/extra_validations.py +52 -0
- valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_validations.py +0 -0
- valley/lib/python3.10/site-packages/setuptools/glob.py +185 -0
- valley/lib/python3.10/site-packages/setuptools/installer.py +150 -0
- valley/lib/python3.10/site-packages/setuptools/logging.py +40 -0
- valley/lib/python3.10/site-packages/setuptools/modified.py +18 -0
- valley/lib/python3.10/site-packages/setuptools/script (dev).tmpl +6 -0
- valley/lib/python3.10/site-packages/setuptools/script.tmpl +3 -0
- valley/lib/python3.10/site-packages/setuptools/tests/__init__.py +13 -0
- valley/lib/python3.10/site-packages/setuptools/tests/config/setupcfg_examples.txt +22 -0
- valley/lib/python3.10/site-packages/setuptools/tests/config/test_apply_pyprojecttoml.py +539 -0
- valley/lib/python3.10/site-packages/setuptools/tests/config/test_pyprojecttoml_dynamic_deps.py +109 -0
- valley/lib/python3.10/site-packages/setuptools/tests/environment.py +95 -0
- valley/lib/python3.10/site-packages/setuptools/tests/fixtures.py +157 -0
- valley/lib/python3.10/site-packages/setuptools/tests/mod_with_constant.py +1 -0
- valley/lib/python3.10/site-packages/setuptools/tests/namespaces.py +90 -0
- valley/lib/python3.10/site-packages/setuptools/tests/script-with-bom.py +1 -0
- valley/lib/python3.10/site-packages/setuptools/tests/server.py +86 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_archive_util.py +36 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_bdist_deprecations.py +28 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_bdist_egg.py +73 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_build.py +33 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_build_clib.py +84 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_build_ext.py +293 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_build_meta.py +970 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_build_py.py +480 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_core_metadata.py +577 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_depends.py +15 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_develop.py +175 -0
- valley/lib/python3.10/site-packages/setuptools/tests/test_dist.py +278 -0
valley/lib/python3.10/site-packages/setuptools/__init__.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 re
|
| 13 |
+
import sys
|
| 14 |
+
from abc import abstractmethod
|
| 15 |
+
from collections.abc import Mapping
|
| 16 |
+
from typing import TYPE_CHECKING, TypeVar, overload
|
| 17 |
+
|
| 18 |
+
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
|
| 19 |
+
# workaround for #4476
|
| 20 |
+
sys.modules.pop('backports', None)
|
| 21 |
+
|
| 22 |
+
import _distutils_hack.override # noqa: F401
|
| 23 |
+
|
| 24 |
+
from . import logging, monkey
|
| 25 |
+
from .depends import Require
|
| 26 |
+
from .discovery import PackageFinder, PEP420PackageFinder
|
| 27 |
+
from .dist import Distribution
|
| 28 |
+
from .extension import Extension
|
| 29 |
+
from .version import __version__ as __version__
|
| 30 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 31 |
+
|
| 32 |
+
import distutils.core
|
| 33 |
+
from distutils.errors import DistutilsOptionError
|
| 34 |
+
|
| 35 |
+
__all__ = [
|
| 36 |
+
'setup',
|
| 37 |
+
'Distribution',
|
| 38 |
+
'Command',
|
| 39 |
+
'Extension',
|
| 40 |
+
'Require',
|
| 41 |
+
'SetuptoolsDeprecationWarning',
|
| 42 |
+
'find_packages',
|
| 43 |
+
'find_namespace_packages',
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
_CommandT = TypeVar("_CommandT", bound="_Command")
|
| 47 |
+
|
| 48 |
+
bootstrap_install_from = None
|
| 49 |
+
|
| 50 |
+
find_packages = PackageFinder.find
|
| 51 |
+
find_namespace_packages = PEP420PackageFinder.find
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _install_setup_requires(attrs):
|
| 55 |
+
# Note: do not use `setuptools.Distribution` directly, as
|
| 56 |
+
# our PEP 517 backend patch `distutils.core.Distribution`.
|
| 57 |
+
class MinimalDistribution(distutils.core.Distribution):
|
| 58 |
+
"""
|
| 59 |
+
A minimal version of a distribution for supporting the
|
| 60 |
+
fetch_build_eggs interface.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
def __init__(self, attrs: Mapping[str, object]) -> None:
|
| 64 |
+
_incl = 'dependency_links', 'setup_requires'
|
| 65 |
+
filtered = {k: attrs[k] for k in set(_incl) & set(attrs)}
|
| 66 |
+
super().__init__(filtered)
|
| 67 |
+
# Prevent accidentally triggering discovery with incomplete set of attrs
|
| 68 |
+
self.set_defaults._disable()
|
| 69 |
+
|
| 70 |
+
def _get_project_config_files(self, filenames=None):
|
| 71 |
+
"""Ignore ``pyproject.toml``, they are not related to setup_requires"""
|
| 72 |
+
try:
|
| 73 |
+
cfg, _toml = super()._split_standard_project_metadata(filenames)
|
| 74 |
+
except Exception:
|
| 75 |
+
return filenames, ()
|
| 76 |
+
return cfg, ()
|
| 77 |
+
|
| 78 |
+
def finalize_options(self):
|
| 79 |
+
"""
|
| 80 |
+
Disable finalize_options to avoid building the working set.
|
| 81 |
+
Ref #2158.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
dist = MinimalDistribution(attrs)
|
| 85 |
+
|
| 86 |
+
# Honor setup.cfg's options.
|
| 87 |
+
dist.parse_config_files(ignore_option_errors=True)
|
| 88 |
+
if dist.setup_requires:
|
| 89 |
+
_fetch_build_eggs(dist)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def _fetch_build_eggs(dist: Distribution):
|
| 93 |
+
try:
|
| 94 |
+
dist.fetch_build_eggs(dist.setup_requires)
|
| 95 |
+
except Exception as ex:
|
| 96 |
+
msg = """
|
| 97 |
+
It is possible a package already installed in your system
|
| 98 |
+
contains an version that is invalid according to PEP 440.
|
| 99 |
+
You can try `pip install --use-pep517` as a workaround for this problem,
|
| 100 |
+
or rely on a new virtual environment.
|
| 101 |
+
|
| 102 |
+
If the problem refers to a package that is not installed yet,
|
| 103 |
+
please contact that package's maintainers or distributors.
|
| 104 |
+
"""
|
| 105 |
+
if "InvalidVersion" in ex.__class__.__name__:
|
| 106 |
+
if hasattr(ex, "add_note"):
|
| 107 |
+
ex.add_note(msg) # PEP 678
|
| 108 |
+
else:
|
| 109 |
+
dist.announce(f"\n{msg}\n")
|
| 110 |
+
raise
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def setup(**attrs):
|
| 114 |
+
logging.configure()
|
| 115 |
+
# Make sure we have any requirements needed to interpret 'attrs'.
|
| 116 |
+
_install_setup_requires(attrs)
|
| 117 |
+
return distutils.core.setup(**attrs)
|
| 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 |
+
def __init__(self, dist: Distribution, **kw) -> None:
|
| 171 |
+
"""
|
| 172 |
+
Construct the command for dist, updating
|
| 173 |
+
vars(self) with any keyword parameters.
|
| 174 |
+
"""
|
| 175 |
+
super().__init__(dist)
|
| 176 |
+
vars(self).update(kw)
|
| 177 |
+
|
| 178 |
+
def _ensure_stringlike(self, option, what, default=None):
|
| 179 |
+
val = getattr(self, option)
|
| 180 |
+
if val is None:
|
| 181 |
+
setattr(self, option, default)
|
| 182 |
+
return default
|
| 183 |
+
elif not isinstance(val, str):
|
| 184 |
+
raise DistutilsOptionError(f"'{option}' must be a {what} (got `{val}`)")
|
| 185 |
+
return val
|
| 186 |
+
|
| 187 |
+
def ensure_string_list(self, option: str) -> None:
|
| 188 |
+
r"""Ensure that 'option' is a list of strings. If 'option' is
|
| 189 |
+
currently a string, we split it either on /,\s*/ or /\s+/, so
|
| 190 |
+
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
|
| 191 |
+
["foo", "bar", "baz"].
|
| 192 |
+
|
| 193 |
+
..
|
| 194 |
+
TODO: This method seems to be similar to the one in ``distutils.cmd``
|
| 195 |
+
Probably it is just here for backward compatibility with old Python versions?
|
| 196 |
+
|
| 197 |
+
:meta private:
|
| 198 |
+
"""
|
| 199 |
+
val = getattr(self, option)
|
| 200 |
+
if val is None:
|
| 201 |
+
return
|
| 202 |
+
elif isinstance(val, str):
|
| 203 |
+
setattr(self, option, re.split(r',\s*|\s+', val))
|
| 204 |
+
else:
|
| 205 |
+
if isinstance(val, list):
|
| 206 |
+
ok = all(isinstance(v, str) for v in val)
|
| 207 |
+
else:
|
| 208 |
+
ok = False
|
| 209 |
+
if not ok:
|
| 210 |
+
raise DistutilsOptionError(
|
| 211 |
+
f"'{option}' must be a list of strings (got {val!r})"
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
@overload
|
| 215 |
+
def reinitialize_command(
|
| 216 |
+
self, command: str, reinit_subcommands: bool = False, **kw
|
| 217 |
+
) -> _Command: ...
|
| 218 |
+
@overload
|
| 219 |
+
def reinitialize_command(
|
| 220 |
+
self, command: _CommandT, reinit_subcommands: bool = False, **kw
|
| 221 |
+
) -> _CommandT: ...
|
| 222 |
+
def reinitialize_command(
|
| 223 |
+
self, command: str | _Command, reinit_subcommands: bool = False, **kw
|
| 224 |
+
) -> _Command:
|
| 225 |
+
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
|
| 226 |
+
vars(cmd).update(kw)
|
| 227 |
+
return cmd # pyright: ignore[reportReturnType] # pypa/distutils#307
|
| 228 |
+
|
| 229 |
+
@abstractmethod
|
| 230 |
+
def initialize_options(self) -> None:
|
| 231 |
+
"""
|
| 232 |
+
Set or (reset) all options/attributes/caches used by the command
|
| 233 |
+
to their default values. Note that these values may be overwritten during
|
| 234 |
+
the build.
|
| 235 |
+
"""
|
| 236 |
+
raise NotImplementedError
|
| 237 |
+
|
| 238 |
+
@abstractmethod
|
| 239 |
+
def finalize_options(self) -> None:
|
| 240 |
+
"""
|
| 241 |
+
Set final values for all options/attributes used by the command.
|
| 242 |
+
Most of the time, each option/attribute/cache should only be set if it does not
|
| 243 |
+
have any value yet (e.g. ``if self.attr is None: self.attr = val``).
|
| 244 |
+
"""
|
| 245 |
+
raise NotImplementedError
|
| 246 |
+
|
| 247 |
+
@abstractmethod
|
| 248 |
+
def run(self) -> None:
|
| 249 |
+
"""
|
| 250 |
+
Execute the actions intended by the command.
|
| 251 |
+
(Side effects **SHOULD** only take place when :meth:`run` is executed,
|
| 252 |
+
for example, creating new files or writing to the terminal output).
|
| 253 |
+
"""
|
| 254 |
+
raise NotImplementedError
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def _find_all_simple(path):
|
| 258 |
+
"""
|
| 259 |
+
Find all files under 'path'
|
| 260 |
+
"""
|
| 261 |
+
results = (
|
| 262 |
+
os.path.join(base, file)
|
| 263 |
+
for base, dirs, files in os.walk(path, followlinks=True)
|
| 264 |
+
for file in files
|
| 265 |
+
)
|
| 266 |
+
return filter(os.path.isfile, results)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def findall(dir=os.curdir):
|
| 270 |
+
"""
|
| 271 |
+
Find all files under 'dir' and return the list of full filenames.
|
| 272 |
+
Unless dir is '.', return full filenames with dir prepended.
|
| 273 |
+
"""
|
| 274 |
+
files = _find_all_simple(dir)
|
| 275 |
+
if dir == os.curdir:
|
| 276 |
+
make_rel = functools.partial(os.path.relpath, start=dir)
|
| 277 |
+
files = map(make_rel, files)
|
| 278 |
+
return list(files)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
class sic(str):
|
| 282 |
+
"""Treat this string as-is (https://en.wikipedia.org/wiki/Sic)"""
|
| 283 |
+
|
| 284 |
+
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+
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.2')
|
| 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 |
+
|
| 92 |
+
self.long_description = _read_field_unescaped_from_msg(msg, 'description')
|
| 93 |
+
if self.long_description is None and self.metadata_version >= Version('2.1'):
|
| 94 |
+
self.long_description = _read_payload_from_msg(msg)
|
| 95 |
+
self.description = _read_field_from_msg(msg, 'summary')
|
| 96 |
+
|
| 97 |
+
if 'keywords' in msg:
|
| 98 |
+
self.keywords = _read_field_from_msg(msg, 'keywords').split(',')
|
| 99 |
+
|
| 100 |
+
self.platforms = _read_list_from_msg(msg, 'platform')
|
| 101 |
+
self.classifiers = _read_list_from_msg(msg, 'classifier')
|
| 102 |
+
|
| 103 |
+
# PEP 314 - these fields only exist in 1.1
|
| 104 |
+
if self.metadata_version == Version('1.1'):
|
| 105 |
+
self.requires = _read_list_from_msg(msg, 'requires')
|
| 106 |
+
self.provides = _read_list_from_msg(msg, 'provides')
|
| 107 |
+
self.obsoletes = _read_list_from_msg(msg, 'obsoletes')
|
| 108 |
+
else:
|
| 109 |
+
self.requires = None
|
| 110 |
+
self.provides = None
|
| 111 |
+
self.obsoletes = None
|
| 112 |
+
|
| 113 |
+
self.license_files = _read_list_from_msg(msg, 'license-file')
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def single_line(val):
|
| 117 |
+
"""
|
| 118 |
+
Quick and dirty validation for Summary pypa/setuptools#1390.
|
| 119 |
+
"""
|
| 120 |
+
if '\n' in val:
|
| 121 |
+
# TODO: Replace with `raise ValueError("newlines not allowed")`
|
| 122 |
+
# after reviewing #2893.
|
| 123 |
+
msg = "newlines are not allowed in `summary` and will break in the future"
|
| 124 |
+
SetuptoolsDeprecationWarning.emit("Invalid config.", msg)
|
| 125 |
+
# due_date is undefined. Controversial change, there was a lot of push back.
|
| 126 |
+
val = val.strip().split('\n')[0]
|
| 127 |
+
return val
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def write_pkg_info(self, base_dir):
|
| 131 |
+
"""Write the PKG-INFO file into the release tree."""
|
| 132 |
+
temp = ""
|
| 133 |
+
final = os.path.join(base_dir, 'PKG-INFO')
|
| 134 |
+
try:
|
| 135 |
+
# Use a temporary file while writing to avoid race conditions
|
| 136 |
+
# (e.g. `importlib.metadata` reading `.egg-info/PKG-INFO`):
|
| 137 |
+
with NamedTemporaryFile("w", encoding="utf-8", dir=base_dir, delete=False) as f:
|
| 138 |
+
temp = f.name
|
| 139 |
+
self.write_pkg_file(f)
|
| 140 |
+
permissions = stat.S_IMODE(os.lstat(temp).st_mode)
|
| 141 |
+
os.chmod(temp, permissions | stat.S_IRGRP | stat.S_IROTH)
|
| 142 |
+
os.replace(temp, final) # atomic operation.
|
| 143 |
+
finally:
|
| 144 |
+
if temp and os.path.exists(temp):
|
| 145 |
+
os.remove(temp)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
# Based on Python 3.5 version
|
| 149 |
+
def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
|
| 150 |
+
"""Write the PKG-INFO format data to a file object."""
|
| 151 |
+
version = self.get_metadata_version()
|
| 152 |
+
|
| 153 |
+
def write_field(key, value):
|
| 154 |
+
file.write(f"{key}: {value}\n")
|
| 155 |
+
|
| 156 |
+
write_field('Metadata-Version', str(version))
|
| 157 |
+
write_field('Name', self.get_name())
|
| 158 |
+
write_field('Version', self.get_version())
|
| 159 |
+
|
| 160 |
+
summary = self.get_description()
|
| 161 |
+
if summary:
|
| 162 |
+
write_field('Summary', single_line(summary))
|
| 163 |
+
|
| 164 |
+
optional_fields = (
|
| 165 |
+
('Home-page', 'url'),
|
| 166 |
+
('Download-URL', 'download_url'),
|
| 167 |
+
('Author', 'author'),
|
| 168 |
+
('Author-email', 'author_email'),
|
| 169 |
+
('Maintainer', 'maintainer'),
|
| 170 |
+
('Maintainer-email', 'maintainer_email'),
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
for field, attr in optional_fields:
|
| 174 |
+
attr_val = getattr(self, attr, None)
|
| 175 |
+
if attr_val is not None:
|
| 176 |
+
write_field(field, attr_val)
|
| 177 |
+
|
| 178 |
+
license = self.get_license()
|
| 179 |
+
if license:
|
| 180 |
+
write_field('License', rfc822_escape(license))
|
| 181 |
+
|
| 182 |
+
for label, url in self.project_urls.items():
|
| 183 |
+
write_field('Project-URL', f'{label}, {url}')
|
| 184 |
+
|
| 185 |
+
keywords = ','.join(self.get_keywords())
|
| 186 |
+
if keywords:
|
| 187 |
+
write_field('Keywords', keywords)
|
| 188 |
+
|
| 189 |
+
platforms = self.get_platforms() or []
|
| 190 |
+
for platform in platforms:
|
| 191 |
+
write_field('Platform', platform)
|
| 192 |
+
|
| 193 |
+
self._write_list(file, 'Classifier', self.get_classifiers())
|
| 194 |
+
|
| 195 |
+
# PEP 314
|
| 196 |
+
self._write_list(file, 'Requires', self.get_requires())
|
| 197 |
+
self._write_list(file, 'Provides', self.get_provides())
|
| 198 |
+
self._write_list(file, 'Obsoletes', self.get_obsoletes())
|
| 199 |
+
|
| 200 |
+
# Setuptools specific for PEP 345
|
| 201 |
+
if hasattr(self, 'python_requires'):
|
| 202 |
+
write_field('Requires-Python', self.python_requires)
|
| 203 |
+
|
| 204 |
+
# PEP 566
|
| 205 |
+
if self.long_description_content_type:
|
| 206 |
+
write_field('Description-Content-Type', self.long_description_content_type)
|
| 207 |
+
|
| 208 |
+
self._write_list(file, 'License-File', self.license_files or [])
|
| 209 |
+
_write_requirements(self, file)
|
| 210 |
+
|
| 211 |
+
for field, attr in _POSSIBLE_DYNAMIC_FIELDS.items():
|
| 212 |
+
if (val := getattr(self, attr, None)) and not is_static(val):
|
| 213 |
+
write_field('Dynamic', field)
|
| 214 |
+
|
| 215 |
+
long_description = self.get_long_description()
|
| 216 |
+
if long_description:
|
| 217 |
+
file.write(f"\n{long_description}")
|
| 218 |
+
if not long_description.endswith("\n"):
|
| 219 |
+
file.write("\n")
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def _write_requirements(self, file):
|
| 223 |
+
for req in _reqs.parse(self.install_requires):
|
| 224 |
+
file.write(f"Requires-Dist: {req}\n")
|
| 225 |
+
|
| 226 |
+
processed_extras = {}
|
| 227 |
+
for augmented_extra, reqs in self.extras_require.items():
|
| 228 |
+
# Historically, setuptools allows "augmented extras": `<extra>:<condition>`
|
| 229 |
+
unsafe_extra, _, condition = augmented_extra.partition(":")
|
| 230 |
+
unsafe_extra = unsafe_extra.strip()
|
| 231 |
+
extra = _normalization.safe_extra(unsafe_extra)
|
| 232 |
+
|
| 233 |
+
if extra:
|
| 234 |
+
_write_provides_extra(file, processed_extras, extra, unsafe_extra)
|
| 235 |
+
for req in _reqs.parse_strings(reqs):
|
| 236 |
+
r = _include_extra(req, extra, condition.strip())
|
| 237 |
+
file.write(f"Requires-Dist: {r}\n")
|
| 238 |
+
|
| 239 |
+
return processed_extras
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def _include_extra(req: str, extra: str, condition: str) -> Requirement:
|
| 243 |
+
r = Requirement(req) # create a fresh object that can be modified
|
| 244 |
+
parts = (
|
| 245 |
+
f"({r.marker})" if r.marker else None,
|
| 246 |
+
f"({condition})" if condition else None,
|
| 247 |
+
f"extra == {extra!r}" if extra else None,
|
| 248 |
+
)
|
| 249 |
+
r.marker = Marker(" and ".join(x for x in parts if x))
|
| 250 |
+
return r
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def _write_provides_extra(file, processed_extras, safe, unsafe):
|
| 254 |
+
previous = processed_extras.get(safe)
|
| 255 |
+
if previous == unsafe:
|
| 256 |
+
SetuptoolsDeprecationWarning.emit(
|
| 257 |
+
'Ambiguity during "extra" normalization for dependencies.',
|
| 258 |
+
f"""
|
| 259 |
+
{previous!r} and {unsafe!r} normalize to the same value:\n
|
| 260 |
+
{safe!r}\n
|
| 261 |
+
In future versions, setuptools might halt the build process.
|
| 262 |
+
""",
|
| 263 |
+
see_url="https://peps.python.org/pep-0685/",
|
| 264 |
+
)
|
| 265 |
+
else:
|
| 266 |
+
processed_extras[safe] = unsafe
|
| 267 |
+
file.write(f"Provides-Extra: {safe}\n")
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
# from pypa/distutils#244; needed only until that logic is always available
|
| 271 |
+
def get_fullname(self):
|
| 272 |
+
return _distribution_fullname(self.get_name(), self.get_version())
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def _distribution_fullname(name: str, version: str) -> str:
|
| 276 |
+
"""
|
| 277 |
+
>>> _distribution_fullname('setup.tools', '1.0-2')
|
| 278 |
+
'setup_tools-1.0.post2'
|
| 279 |
+
>>> _distribution_fullname('setup-tools', '1.2post2')
|
| 280 |
+
'setup_tools-1.2.post2'
|
| 281 |
+
>>> _distribution_fullname('setup-tools', '1.0-r2')
|
| 282 |
+
'setup_tools-1.0.post2'
|
| 283 |
+
>>> _distribution_fullname('setup.tools', '1.0.post')
|
| 284 |
+
'setup_tools-1.0.post0'
|
| 285 |
+
>>> _distribution_fullname('setup.tools', '1.0+ubuntu-1')
|
| 286 |
+
'setup_tools-1.0+ubuntu.1'
|
| 287 |
+
"""
|
| 288 |
+
return "{}-{}".format(
|
| 289 |
+
canonicalize_name(name).replace('-', '_'),
|
| 290 |
+
canonicalize_version(version, strip_trailing_zero=False),
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
_POSSIBLE_DYNAMIC_FIELDS = {
|
| 295 |
+
# Core Metadata Field x related Distribution attribute
|
| 296 |
+
"author": "author",
|
| 297 |
+
"author-email": "author_email",
|
| 298 |
+
"classifier": "classifiers",
|
| 299 |
+
"description": "long_description",
|
| 300 |
+
"description-content-type": "long_description_content_type",
|
| 301 |
+
"download-url": "download_url",
|
| 302 |
+
"home-page": "url",
|
| 303 |
+
"keywords": "keywords",
|
| 304 |
+
"license": "license",
|
| 305 |
+
# "license-file": "license_files", # XXX: does PEP 639 exempt Dynamic ??
|
| 306 |
+
"maintainer": "maintainer",
|
| 307 |
+
"maintainer-email": "maintainer_email",
|
| 308 |
+
"obsoletes": "obsoletes",
|
| 309 |
+
# "obsoletes-dist": "obsoletes_dist", # NOT USED
|
| 310 |
+
"platform": "platforms",
|
| 311 |
+
"project-url": "project_urls",
|
| 312 |
+
"provides": "provides",
|
| 313 |
+
# "provides-dist": "provides_dist", # NOT USED
|
| 314 |
+
"provides-extra": "extras_require",
|
| 315 |
+
"requires": "requires",
|
| 316 |
+
"requires-dist": "install_requires",
|
| 317 |
+
# "requires-external": "requires_external", # NOT USED
|
| 318 |
+
"requires-python": "python_requires",
|
| 319 |
+
"summary": "description",
|
| 320 |
+
# "supported-platform": "supported_platforms", # NOT USED
|
| 321 |
+
}
|
valley/lib/python3.10/site-packages/setuptools/_entry_points.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import itertools
|
| 3 |
+
import operator
|
| 4 |
+
|
| 5 |
+
from jaraco.functools import pass_none
|
| 6 |
+
from jaraco.text import yield_lines
|
| 7 |
+
from more_itertools import consume
|
| 8 |
+
|
| 9 |
+
from ._importlib import metadata
|
| 10 |
+
from ._itertools import ensure_unique
|
| 11 |
+
from .errors import OptionError
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def ensure_valid(ep):
|
| 15 |
+
"""
|
| 16 |
+
Exercise one of the dynamic properties to trigger
|
| 17 |
+
the pattern match.
|
| 18 |
+
"""
|
| 19 |
+
try:
|
| 20 |
+
ep.extras
|
| 21 |
+
except (AttributeError, AssertionError) as ex:
|
| 22 |
+
# Why both? See https://github.com/python/importlib_metadata/issues/488
|
| 23 |
+
msg = (
|
| 24 |
+
f"Problems to parse {ep}.\nPlease ensure entry-point follows the spec: "
|
| 25 |
+
"https://packaging.python.org/en/latest/specifications/entry-points/"
|
| 26 |
+
)
|
| 27 |
+
raise OptionError(msg) from ex
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def load_group(value, group):
|
| 31 |
+
"""
|
| 32 |
+
Given a value of an entry point or series of entry points,
|
| 33 |
+
return each as an EntryPoint.
|
| 34 |
+
"""
|
| 35 |
+
# normalize to a single sequence of lines
|
| 36 |
+
lines = yield_lines(value)
|
| 37 |
+
text = f'[{group}]\n' + '\n'.join(lines)
|
| 38 |
+
return metadata.EntryPoints._from_text(text)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def by_group_and_name(ep):
|
| 42 |
+
return ep.group, ep.name
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def validate(eps: metadata.EntryPoints):
|
| 46 |
+
"""
|
| 47 |
+
Ensure entry points are unique by group and name and validate each.
|
| 48 |
+
"""
|
| 49 |
+
consume(map(ensure_valid, ensure_unique(eps, key=by_group_and_name)))
|
| 50 |
+
return eps
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@functools.singledispatch
|
| 54 |
+
def load(eps):
|
| 55 |
+
"""
|
| 56 |
+
Given a Distribution.entry_points, produce EntryPoints.
|
| 57 |
+
"""
|
| 58 |
+
groups = itertools.chain.from_iterable(
|
| 59 |
+
load_group(value, group) for group, value in eps.items()
|
| 60 |
+
)
|
| 61 |
+
return validate(metadata.EntryPoints(groups))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@load.register(str)
|
| 65 |
+
def _(eps):
|
| 66 |
+
r"""
|
| 67 |
+
>>> ep, = load('[console_scripts]\nfoo=bar')
|
| 68 |
+
>>> ep.group
|
| 69 |
+
'console_scripts'
|
| 70 |
+
>>> ep.name
|
| 71 |
+
'foo'
|
| 72 |
+
>>> ep.value
|
| 73 |
+
'bar'
|
| 74 |
+
"""
|
| 75 |
+
return validate(metadata.EntryPoints(metadata.EntryPoints._from_text(eps)))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
load.register(type(None), lambda x: x)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@pass_none
|
| 82 |
+
def render(eps: metadata.EntryPoints):
|
| 83 |
+
by_group = operator.attrgetter('group')
|
| 84 |
+
groups = itertools.groupby(sorted(eps, key=by_group), by_group)
|
| 85 |
+
|
| 86 |
+
return '\n'.join(f'[{group}]\n{render_items(items)}\n' for group, items in groups)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def render_items(eps):
|
| 90 |
+
return '\n'.join(f'{ep.name} = {ep.value}' for ep in sorted(eps))
|
valley/lib/python3.10/site-packages/setuptools/_importlib.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
if sys.version_info < (3, 10):
|
| 4 |
+
import importlib_metadata as metadata # pragma: no cover
|
| 5 |
+
else:
|
| 6 |
+
import importlib.metadata as metadata # noqa: F401
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
import importlib.resources as resources # noqa: F401
|
valley/lib/python3.10/site-packages/setuptools/_path.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
from typing import TYPE_CHECKING, TypeVar, Union
|
| 7 |
+
|
| 8 |
+
from more_itertools import unique_everseen
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from typing_extensions import TypeAlias
|
| 12 |
+
|
| 13 |
+
StrPath: TypeAlias = Union[str, os.PathLike[str]] # Same as _typeshed.StrPath
|
| 14 |
+
StrPathT = TypeVar("StrPathT", bound=Union[str, os.PathLike[str]])
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def ensure_directory(path):
|
| 18 |
+
"""Ensure that the parent directory of `path` exists"""
|
| 19 |
+
dirname = os.path.dirname(path)
|
| 20 |
+
os.makedirs(dirname, exist_ok=True)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def same_path(p1: StrPath, p2: StrPath) -> bool:
|
| 24 |
+
"""Differs from os.path.samefile because it does not require paths to exist.
|
| 25 |
+
Purely string based (no comparison between i-nodes).
|
| 26 |
+
>>> same_path("a/b", "./a/b")
|
| 27 |
+
True
|
| 28 |
+
>>> same_path("a/b", "a/./b")
|
| 29 |
+
True
|
| 30 |
+
>>> same_path("a/b", "././a/b")
|
| 31 |
+
True
|
| 32 |
+
>>> same_path("a/b", "./a/b/c/..")
|
| 33 |
+
True
|
| 34 |
+
>>> same_path("a/b", "../a/b/c")
|
| 35 |
+
False
|
| 36 |
+
>>> same_path("a", "a/b")
|
| 37 |
+
False
|
| 38 |
+
"""
|
| 39 |
+
return normpath(p1) == normpath(p2)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def normpath(filename: StrPath) -> str:
|
| 43 |
+
"""Normalize a file/dir name for comparison purposes."""
|
| 44 |
+
# See pkg_resources.normalize_path for notes about cygwin
|
| 45 |
+
file = os.path.abspath(filename) if sys.platform == 'cygwin' else filename
|
| 46 |
+
return os.path.normcase(os.path.realpath(os.path.normpath(file)))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
@contextlib.contextmanager
|
| 50 |
+
def paths_on_pythonpath(paths):
|
| 51 |
+
"""
|
| 52 |
+
Add the indicated paths to the head of the PYTHONPATH environment
|
| 53 |
+
variable so that subprocesses will also see the packages at
|
| 54 |
+
these paths.
|
| 55 |
+
|
| 56 |
+
Do this in a context that restores the value on exit.
|
| 57 |
+
|
| 58 |
+
>>> getfixture('monkeypatch').setenv('PYTHONPATH', 'anything')
|
| 59 |
+
>>> with paths_on_pythonpath(['foo', 'bar']):
|
| 60 |
+
... assert 'foo' in os.environ['PYTHONPATH']
|
| 61 |
+
... assert 'anything' in os.environ['PYTHONPATH']
|
| 62 |
+
>>> os.environ['PYTHONPATH']
|
| 63 |
+
'anything'
|
| 64 |
+
|
| 65 |
+
>>> getfixture('monkeypatch').delenv('PYTHONPATH')
|
| 66 |
+
>>> with paths_on_pythonpath(['foo', 'bar']):
|
| 67 |
+
... assert 'foo' in os.environ['PYTHONPATH']
|
| 68 |
+
>>> os.environ.get('PYTHONPATH')
|
| 69 |
+
"""
|
| 70 |
+
nothing = object()
|
| 71 |
+
orig_pythonpath = os.environ.get('PYTHONPATH', nothing)
|
| 72 |
+
current_pythonpath = os.environ.get('PYTHONPATH', '')
|
| 73 |
+
try:
|
| 74 |
+
prefix = os.pathsep.join(unique_everseen(paths))
|
| 75 |
+
to_join = filter(None, [prefix, current_pythonpath])
|
| 76 |
+
new_path = os.pathsep.join(to_join)
|
| 77 |
+
if new_path:
|
| 78 |
+
os.environ['PYTHONPATH'] = new_path
|
| 79 |
+
yield
|
| 80 |
+
finally:
|
| 81 |
+
if orig_pythonpath is nothing:
|
| 82 |
+
os.environ.pop('PYTHONPATH', None)
|
| 83 |
+
else:
|
| 84 |
+
os.environ['PYTHONPATH'] = orig_pythonpath
|
valley/lib/python3.10/site-packages/setuptools/_static.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import wraps
|
| 2 |
+
from typing import TypeVar
|
| 3 |
+
|
| 4 |
+
import packaging.specifiers
|
| 5 |
+
|
| 6 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Static:
|
| 10 |
+
"""
|
| 11 |
+
Wrapper for built-in object types that are allow setuptools to identify
|
| 12 |
+
static core metadata (in opposition to ``Dynamic``, as defined :pep:`643`).
|
| 13 |
+
|
| 14 |
+
The trick is to mark values with :class:`Static` when they come from
|
| 15 |
+
``pyproject.toml`` or ``setup.cfg``, so if any plugin overwrite the value
|
| 16 |
+
with a built-in, setuptools will be able to recognise the change.
|
| 17 |
+
|
| 18 |
+
We inherit from built-in classes, so that we don't need to change the existing
|
| 19 |
+
code base to deal with the new types.
|
| 20 |
+
We also should strive for immutability objects to avoid changes after the
|
| 21 |
+
initial parsing.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
_mutated_: bool = False # TODO: Remove after deprecation warning is solved
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _prevent_modification(target: type, method: str, copying: str) -> None:
|
| 28 |
+
"""
|
| 29 |
+
Because setuptools is very flexible we cannot fully prevent
|
| 30 |
+
plugins and user customisations from modifying static values that were
|
| 31 |
+
parsed from config files.
|
| 32 |
+
But we can attempt to block "in-place" mutations and identify when they
|
| 33 |
+
were done.
|
| 34 |
+
"""
|
| 35 |
+
fn = getattr(target, method, None)
|
| 36 |
+
if fn is None:
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
@wraps(fn)
|
| 40 |
+
def _replacement(self: Static, *args, **kwargs):
|
| 41 |
+
# TODO: After deprecation period raise NotImplementedError instead of warning
|
| 42 |
+
# which obviated the existence and checks of the `_mutated_` attribute.
|
| 43 |
+
self._mutated_ = True
|
| 44 |
+
SetuptoolsDeprecationWarning.emit(
|
| 45 |
+
"Direct modification of value will be disallowed",
|
| 46 |
+
f"""
|
| 47 |
+
In an effort to implement PEP 643, direct/in-place changes of static values
|
| 48 |
+
that come from configuration files are deprecated.
|
| 49 |
+
If you need to modify this value, please first create a copy with {copying}
|
| 50 |
+
and make sure conform to all relevant standards when overriding setuptools
|
| 51 |
+
functionality (https://packaging.python.org/en/latest/specifications/).
|
| 52 |
+
""",
|
| 53 |
+
due_date=(2025, 10, 10), # Initially introduced in 2024-09-06
|
| 54 |
+
)
|
| 55 |
+
return fn(self, *args, **kwargs)
|
| 56 |
+
|
| 57 |
+
_replacement.__doc__ = "" # otherwise doctest may fail.
|
| 58 |
+
setattr(target, method, _replacement)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class Str(str, Static):
|
| 62 |
+
pass
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class Tuple(tuple, Static):
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class List(list, Static):
|
| 70 |
+
"""
|
| 71 |
+
:meta private:
|
| 72 |
+
>>> x = List([1, 2, 3])
|
| 73 |
+
>>> is_static(x)
|
| 74 |
+
True
|
| 75 |
+
>>> x += [0] # doctest: +IGNORE_EXCEPTION_DETAIL
|
| 76 |
+
Traceback (most recent call last):
|
| 77 |
+
SetuptoolsDeprecationWarning: Direct modification ...
|
| 78 |
+
>>> is_static(x) # no longer static after modification
|
| 79 |
+
False
|
| 80 |
+
>>> y = list(x)
|
| 81 |
+
>>> y.clear()
|
| 82 |
+
>>> y
|
| 83 |
+
[]
|
| 84 |
+
>>> y == x
|
| 85 |
+
False
|
| 86 |
+
>>> is_static(List(y))
|
| 87 |
+
True
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# Make `List` immutable-ish
|
| 92 |
+
# (certain places of setuptools/distutils issue a warn if we use tuple instead of list)
|
| 93 |
+
for _method in (
|
| 94 |
+
'__delitem__',
|
| 95 |
+
'__iadd__',
|
| 96 |
+
'__setitem__',
|
| 97 |
+
'append',
|
| 98 |
+
'clear',
|
| 99 |
+
'extend',
|
| 100 |
+
'insert',
|
| 101 |
+
'remove',
|
| 102 |
+
'reverse',
|
| 103 |
+
'pop',
|
| 104 |
+
):
|
| 105 |
+
_prevent_modification(List, _method, "`list(value)`")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class Dict(dict, Static):
|
| 109 |
+
"""
|
| 110 |
+
:meta private:
|
| 111 |
+
>>> x = Dict({'a': 1, 'b': 2})
|
| 112 |
+
>>> is_static(x)
|
| 113 |
+
True
|
| 114 |
+
>>> x['c'] = 0 # doctest: +IGNORE_EXCEPTION_DETAIL
|
| 115 |
+
Traceback (most recent call last):
|
| 116 |
+
SetuptoolsDeprecationWarning: Direct modification ...
|
| 117 |
+
>>> x._mutated_
|
| 118 |
+
True
|
| 119 |
+
>>> is_static(x) # no longer static after modification
|
| 120 |
+
False
|
| 121 |
+
>>> y = dict(x)
|
| 122 |
+
>>> y.popitem()
|
| 123 |
+
('b', 2)
|
| 124 |
+
>>> y == x
|
| 125 |
+
False
|
| 126 |
+
>>> is_static(Dict(y))
|
| 127 |
+
True
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
# Make `Dict` immutable-ish (we cannot inherit from types.MappingProxyType):
|
| 132 |
+
for _method in (
|
| 133 |
+
'__delitem__',
|
| 134 |
+
'__ior__',
|
| 135 |
+
'__setitem__',
|
| 136 |
+
'clear',
|
| 137 |
+
'pop',
|
| 138 |
+
'popitem',
|
| 139 |
+
'setdefault',
|
| 140 |
+
'update',
|
| 141 |
+
):
|
| 142 |
+
_prevent_modification(Dict, _method, "`dict(value)`")
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class SpecifierSet(packaging.specifiers.SpecifierSet, Static):
|
| 146 |
+
"""Not exactly a built-in type but useful for ``requires-python``"""
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
T = TypeVar("T")
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def noop(value: T) -> T:
|
| 153 |
+
"""
|
| 154 |
+
>>> noop(42)
|
| 155 |
+
42
|
| 156 |
+
"""
|
| 157 |
+
return value
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
_CONVERSIONS = {str: Str, tuple: Tuple, list: List, dict: Dict}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def attempt_conversion(value: T) -> T:
|
| 164 |
+
"""
|
| 165 |
+
>>> is_static(attempt_conversion("hello"))
|
| 166 |
+
True
|
| 167 |
+
>>> is_static(object())
|
| 168 |
+
False
|
| 169 |
+
"""
|
| 170 |
+
return _CONVERSIONS.get(type(value), noop)(value) # type: ignore[call-overload]
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def is_static(value: object) -> bool:
|
| 174 |
+
"""
|
| 175 |
+
>>> is_static(a := Dict({'a': 1}))
|
| 176 |
+
True
|
| 177 |
+
>>> is_static(dict(a))
|
| 178 |
+
False
|
| 179 |
+
>>> is_static(b := List([1, 2, 3]))
|
| 180 |
+
True
|
| 181 |
+
>>> is_static(list(b))
|
| 182 |
+
False
|
| 183 |
+
"""
|
| 184 |
+
return isinstance(value, Static) and not value._mutated_
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
EMPTY_LIST = List()
|
| 188 |
+
EMPTY_DICT = Dict()
|
valley/lib/python3.10/site-packages/setuptools/cli-arm64.exe
ADDED
|
Binary file (13.8 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/cli.exe
ADDED
|
Binary file (11.8 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The following files include code from opensource projects
|
| 2 |
+
(either as direct copies or modified versions):
|
| 3 |
+
|
| 4 |
+
- `setuptools.schema.json`, `distutils.schema.json`:
|
| 5 |
+
- project: `validate-pyproject` - licensed under MPL-2.0
|
| 6 |
+
(https://github.com/abravalheri/validate-pyproject):
|
| 7 |
+
|
| 8 |
+
This Source Code Form is subject to the terms of the Mozilla Public
|
| 9 |
+
License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
| 10 |
+
You can obtain one at https://mozilla.org/MPL/2.0/.
|
valley/lib/python3.10/site-packages/setuptools/config/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.61 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/__pycache__/_apply_pyprojecttoml.cpython-310.pyc
ADDED
|
Binary file (16.9 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/__pycache__/expand.cpython-310.pyc
ADDED
|
Binary file (18.2 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/__pycache__/pyprojecttoml.cpython-310.pyc
ADDED
|
Binary file (16 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/__pycache__/setupcfg.cpython-310.pyc
ADDED
|
Binary file (24.2 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/error_reporting.cpython-310.pyc
ADDED
|
Binary file (12 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/extra_validations.cpython-310.pyc
ADDED
|
Binary file (1.58 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_exceptions.cpython-310.pyc
ADDED
|
Binary file (2.42 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-310.pyc
ADDED
|
Binary file (85.8 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/formats.cpython-310.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/extra_validations.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The purpose of this module is implement PEP 621 validations that are
|
| 2 |
+
difficult to express as a JSON Schema (or that are not supported by the current
|
| 3 |
+
JSON Schema library).
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from inspect import cleandoc
|
| 7 |
+
from typing import Mapping, TypeVar
|
| 8 |
+
|
| 9 |
+
from .error_reporting import ValidationError
|
| 10 |
+
|
| 11 |
+
T = TypeVar("T", bound=Mapping)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class RedefiningStaticFieldAsDynamic(ValidationError):
|
| 15 |
+
_DESC = """According to PEP 621:
|
| 16 |
+
|
| 17 |
+
Build back-ends MUST raise an error if the metadata specifies a field
|
| 18 |
+
statically as well as being listed in dynamic.
|
| 19 |
+
"""
|
| 20 |
+
__doc__ = _DESC
|
| 21 |
+
_URL = (
|
| 22 |
+
"https://packaging.python.org/en/latest/specifications/"
|
| 23 |
+
"pyproject-toml/#dynamic"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def validate_project_dynamic(pyproject: T) -> T:
|
| 28 |
+
project_table = pyproject.get("project", {})
|
| 29 |
+
dynamic = project_table.get("dynamic", [])
|
| 30 |
+
|
| 31 |
+
for field in dynamic:
|
| 32 |
+
if field in project_table:
|
| 33 |
+
raise RedefiningStaticFieldAsDynamic(
|
| 34 |
+
message=f"You cannot provide a value for `project.{field}` and "
|
| 35 |
+
"list it under `project.dynamic` at the same time",
|
| 36 |
+
value={
|
| 37 |
+
field: project_table[field],
|
| 38 |
+
"...": " # ...",
|
| 39 |
+
"dynamic": dynamic,
|
| 40 |
+
},
|
| 41 |
+
name=f"data.project.{field}",
|
| 42 |
+
definition={
|
| 43 |
+
"description": cleandoc(RedefiningStaticFieldAsDynamic._DESC),
|
| 44 |
+
"see": RedefiningStaticFieldAsDynamic._URL,
|
| 45 |
+
},
|
| 46 |
+
rule="PEP 621",
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
return pyproject
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
EXTRA_VALIDATIONS = (validate_project_dynamic,)
|
valley/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_validations.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
valley/lib/python3.10/site-packages/setuptools/glob.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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and PEP3102 `*` removed.
|
| 6 |
+
* Hidden files are not ignored.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import fnmatch
|
| 12 |
+
import os
|
| 13 |
+
import re
|
| 14 |
+
from collections.abc import Iterable, Iterator
|
| 15 |
+
from typing import TYPE_CHECKING, AnyStr, overload
|
| 16 |
+
|
| 17 |
+
if TYPE_CHECKING:
|
| 18 |
+
from _typeshed import BytesPath, StrOrBytesPath, StrPath
|
| 19 |
+
|
| 20 |
+
__all__ = ["glob", "iglob", "escape"]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def glob(pathname: AnyStr, recursive: bool = False) -> list[AnyStr]:
|
| 24 |
+
"""Return a list of paths matching a pathname pattern.
|
| 25 |
+
|
| 26 |
+
The pattern may contain simple shell-style wildcards a la
|
| 27 |
+
fnmatch. However, unlike fnmatch, filenames starting with a
|
| 28 |
+
dot are special cases that are not matched by '*' and '?'
|
| 29 |
+
patterns.
|
| 30 |
+
|
| 31 |
+
If recursive is true, the pattern '**' will match any files and
|
| 32 |
+
zero or more directories and subdirectories.
|
| 33 |
+
"""
|
| 34 |
+
return list(iglob(pathname, recursive=recursive))
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def iglob(pathname: AnyStr, recursive: bool = False) -> Iterator[AnyStr]:
|
| 38 |
+
"""Return an iterator which yields the paths matching a pathname pattern.
|
| 39 |
+
|
| 40 |
+
The pattern may contain simple shell-style wildcards a la
|
| 41 |
+
fnmatch. However, unlike fnmatch, filenames starting with a
|
| 42 |
+
dot are special cases that are not matched by '*' and '?'
|
| 43 |
+
patterns.
|
| 44 |
+
|
| 45 |
+
If recursive is true, the pattern '**' will match any files and
|
| 46 |
+
zero or more directories and subdirectories.
|
| 47 |
+
"""
|
| 48 |
+
it = _iglob(pathname, recursive)
|
| 49 |
+
if recursive and _isrecursive(pathname):
|
| 50 |
+
s = next(it) # skip empty string
|
| 51 |
+
assert not s
|
| 52 |
+
return it
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _iglob(pathname: AnyStr, recursive: bool) -> Iterator[AnyStr]:
|
| 56 |
+
dirname, basename = os.path.split(pathname)
|
| 57 |
+
glob_in_dir = glob2 if recursive and _isrecursive(basename) else glob1
|
| 58 |
+
|
| 59 |
+
if not has_magic(pathname):
|
| 60 |
+
if basename:
|
| 61 |
+
if os.path.lexists(pathname):
|
| 62 |
+
yield pathname
|
| 63 |
+
else:
|
| 64 |
+
# Patterns ending with a slash should match only directories
|
| 65 |
+
if os.path.isdir(dirname):
|
| 66 |
+
yield pathname
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
if not dirname:
|
| 70 |
+
yield from glob_in_dir(dirname, basename)
|
| 71 |
+
return
|
| 72 |
+
# `os.path.split()` returns the argument itself as a dirname if it is a
|
| 73 |
+
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
|
| 74 |
+
# contains magic characters (i.e. r'\\?\C:').
|
| 75 |
+
if dirname != pathname and has_magic(dirname):
|
| 76 |
+
dirs: Iterable[AnyStr] = _iglob(dirname, recursive)
|
| 77 |
+
else:
|
| 78 |
+
dirs = [dirname]
|
| 79 |
+
if not has_magic(basename):
|
| 80 |
+
glob_in_dir = glob0
|
| 81 |
+
for dirname in dirs:
|
| 82 |
+
for name in glob_in_dir(dirname, basename):
|
| 83 |
+
yield os.path.join(dirname, name)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# These 2 helper functions non-recursively glob inside a literal directory.
|
| 87 |
+
# They return a list of basenames. `glob1` accepts a pattern while `glob0`
|
| 88 |
+
# takes a literal basename (so it only has to check for its existence).
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@overload
|
| 92 |
+
def glob1(dirname: StrPath, pattern: str) -> list[str]: ...
|
| 93 |
+
@overload
|
| 94 |
+
def glob1(dirname: BytesPath, pattern: bytes) -> list[bytes]: ...
|
| 95 |
+
def glob1(dirname: StrOrBytesPath, pattern: str | bytes) -> list[str] | list[bytes]:
|
| 96 |
+
if not dirname:
|
| 97 |
+
if isinstance(pattern, bytes):
|
| 98 |
+
dirname = os.curdir.encode('ASCII')
|
| 99 |
+
else:
|
| 100 |
+
dirname = os.curdir
|
| 101 |
+
try:
|
| 102 |
+
names = os.listdir(dirname)
|
| 103 |
+
except OSError:
|
| 104 |
+
return []
|
| 105 |
+
# mypy false-positives: str or bytes type possibility is always kept in sync
|
| 106 |
+
return fnmatch.filter(names, pattern) # type: ignore[type-var, return-value]
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def glob0(dirname, basename):
|
| 110 |
+
if not basename:
|
| 111 |
+
# `os.path.split()` returns an empty basename for paths ending with a
|
| 112 |
+
# directory separator. 'q*x/' should match only directories.
|
| 113 |
+
if os.path.isdir(dirname):
|
| 114 |
+
return [basename]
|
| 115 |
+
else:
|
| 116 |
+
if os.path.lexists(os.path.join(dirname, basename)):
|
| 117 |
+
return [basename]
|
| 118 |
+
return []
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
# This helper function recursively yields relative pathnames inside a literal
|
| 122 |
+
# directory.
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
@overload
|
| 126 |
+
def glob2(dirname: StrPath, pattern: str) -> Iterator[str]: ...
|
| 127 |
+
@overload
|
| 128 |
+
def glob2(dirname: BytesPath, pattern: bytes) -> Iterator[bytes]: ...
|
| 129 |
+
def glob2(dirname: StrOrBytesPath, pattern: str | bytes) -> Iterator[str | bytes]:
|
| 130 |
+
assert _isrecursive(pattern)
|
| 131 |
+
yield pattern[:0]
|
| 132 |
+
yield from _rlistdir(dirname)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# Recursively yields relative pathnames inside a literal directory.
|
| 136 |
+
@overload
|
| 137 |
+
def _rlistdir(dirname: StrPath) -> Iterator[str]: ...
|
| 138 |
+
@overload
|
| 139 |
+
def _rlistdir(dirname: BytesPath) -> Iterator[bytes]: ...
|
| 140 |
+
def _rlistdir(dirname: StrOrBytesPath) -> Iterator[str | bytes]:
|
| 141 |
+
if not dirname:
|
| 142 |
+
if isinstance(dirname, bytes):
|
| 143 |
+
dirname = os.curdir.encode('ASCII')
|
| 144 |
+
else:
|
| 145 |
+
dirname = os.curdir
|
| 146 |
+
try:
|
| 147 |
+
names = os.listdir(dirname)
|
| 148 |
+
except OSError:
|
| 149 |
+
return
|
| 150 |
+
for x in names:
|
| 151 |
+
yield x
|
| 152 |
+
# mypy false-positives: str or bytes type possibility is always kept in sync
|
| 153 |
+
path = os.path.join(dirname, x) if dirname else x # type: ignore[arg-type]
|
| 154 |
+
for y in _rlistdir(path):
|
| 155 |
+
yield os.path.join(x, y) # type: ignore[arg-type]
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
magic_check = re.compile('([*?[])')
|
| 159 |
+
magic_check_bytes = re.compile(b'([*?[])')
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def has_magic(s: str | bytes) -> bool:
|
| 163 |
+
if isinstance(s, bytes):
|
| 164 |
+
return magic_check_bytes.search(s) is not None
|
| 165 |
+
else:
|
| 166 |
+
return magic_check.search(s) is not None
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def _isrecursive(pattern: str | bytes) -> bool:
|
| 170 |
+
if isinstance(pattern, bytes):
|
| 171 |
+
return pattern == b'**'
|
| 172 |
+
else:
|
| 173 |
+
return pattern == '**'
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def escape(pathname):
|
| 177 |
+
"""Escape all special characters."""
|
| 178 |
+
# Escaping is done by wrapping any of "*?[" between square brackets.
|
| 179 |
+
# Metacharacters do not work in the drive part and shouldn't be escaped.
|
| 180 |
+
drive, pathname = os.path.splitdrive(pathname)
|
| 181 |
+
if isinstance(pathname, bytes):
|
| 182 |
+
pathname = magic_check_bytes.sub(rb'[\1]', pathname)
|
| 183 |
+
else:
|
| 184 |
+
pathname = magic_check.sub(r'[\1]', pathname)
|
| 185 |
+
return drive + pathname
|
valley/lib/python3.10/site-packages/setuptools/installer.py
ADDED
|
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
|
| 8 |
+
from functools import partial
|
| 9 |
+
|
| 10 |
+
from pkg_resources import Distribution
|
| 11 |
+
|
| 12 |
+
from . import _reqs
|
| 13 |
+
from ._reqs import _StrOrIter
|
| 14 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 15 |
+
from .wheel import Wheel
|
| 16 |
+
|
| 17 |
+
from distutils import log
|
| 18 |
+
from distutils.errors import DistutilsError
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _fixup_find_links(find_links):
|
| 22 |
+
"""Ensure find-links option end-up being a list of strings."""
|
| 23 |
+
if isinstance(find_links, str):
|
| 24 |
+
return find_links.split()
|
| 25 |
+
assert isinstance(find_links, (tuple, list))
|
| 26 |
+
return find_links
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def fetch_build_egg(dist, req):
|
| 30 |
+
"""Fetch an egg needed for building.
|
| 31 |
+
|
| 32 |
+
Use pip/wheel to fetch/build a wheel."""
|
| 33 |
+
_DeprecatedInstaller.emit()
|
| 34 |
+
_warn_wheel_not_available(dist)
|
| 35 |
+
return _fetch_build_egg_no_warn(dist, req)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _fetch_build_eggs(dist, requires: _StrOrIter) -> list[Distribution]:
|
| 39 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 40 |
+
|
| 41 |
+
_DeprecatedInstaller.emit(stacklevel=3)
|
| 42 |
+
_warn_wheel_not_available(dist)
|
| 43 |
+
|
| 44 |
+
resolved_dists = pkg_resources.working_set.resolve(
|
| 45 |
+
_reqs.parse(requires, pkg_resources.Requirement), # required for compatibility
|
| 46 |
+
installer=partial(_fetch_build_egg_no_warn, dist), # avoid warning twice
|
| 47 |
+
replace_conflicting=True,
|
| 48 |
+
)
|
| 49 |
+
for dist in resolved_dists:
|
| 50 |
+
pkg_resources.working_set.add(dist, replace=True)
|
| 51 |
+
return resolved_dists
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _fetch_build_egg_no_warn(dist, req): # noqa: C901 # is too complex (16) # FIXME
|
| 55 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 56 |
+
|
| 57 |
+
# Ignore environment markers; if supplied, it is required.
|
| 58 |
+
req = strip_marker(req)
|
| 59 |
+
# Take easy_install options into account, but do not override relevant
|
| 60 |
+
# pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll
|
| 61 |
+
# take precedence.
|
| 62 |
+
opts = dist.get_option_dict('easy_install')
|
| 63 |
+
if 'allow_hosts' in opts:
|
| 64 |
+
raise DistutilsError(
|
| 65 |
+
'the `allow-hosts` option is not supported '
|
| 66 |
+
'when using pip to install requirements.'
|
| 67 |
+
)
|
| 68 |
+
quiet = 'PIP_QUIET' not in os.environ and 'PIP_VERBOSE' not in os.environ
|
| 69 |
+
if 'PIP_INDEX_URL' in os.environ:
|
| 70 |
+
index_url = None
|
| 71 |
+
elif 'index_url' in opts:
|
| 72 |
+
index_url = opts['index_url'][1]
|
| 73 |
+
else:
|
| 74 |
+
index_url = None
|
| 75 |
+
find_links = (
|
| 76 |
+
_fixup_find_links(opts['find_links'][1])[:] if 'find_links' in opts else []
|
| 77 |
+
)
|
| 78 |
+
if dist.dependency_links:
|
| 79 |
+
find_links.extend(dist.dependency_links)
|
| 80 |
+
eggs_dir = os.path.realpath(dist.get_egg_cache_dir())
|
| 81 |
+
environment = pkg_resources.Environment()
|
| 82 |
+
for egg_dist in pkg_resources.find_distributions(eggs_dir):
|
| 83 |
+
if egg_dist in req and environment.can_add(egg_dist):
|
| 84 |
+
return egg_dist
|
| 85 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 86 |
+
cmd = [
|
| 87 |
+
sys.executable,
|
| 88 |
+
'-m',
|
| 89 |
+
'pip',
|
| 90 |
+
'--disable-pip-version-check',
|
| 91 |
+
'wheel',
|
| 92 |
+
'--no-deps',
|
| 93 |
+
'-w',
|
| 94 |
+
tmpdir,
|
| 95 |
+
]
|
| 96 |
+
if quiet:
|
| 97 |
+
cmd.append('--quiet')
|
| 98 |
+
if index_url is not None:
|
| 99 |
+
cmd.extend(('--index-url', index_url))
|
| 100 |
+
for link in find_links or []:
|
| 101 |
+
cmd.extend(('--find-links', link))
|
| 102 |
+
# If requirement is a PEP 508 direct URL, directly pass
|
| 103 |
+
# the URL to pip, as `req @ url` does not work on the
|
| 104 |
+
# command line.
|
| 105 |
+
cmd.append(req.url or str(req))
|
| 106 |
+
try:
|
| 107 |
+
subprocess.check_call(cmd)
|
| 108 |
+
except subprocess.CalledProcessError as e:
|
| 109 |
+
raise DistutilsError(str(e)) from e
|
| 110 |
+
wheel = Wheel(glob.glob(os.path.join(tmpdir, '*.whl'))[0])
|
| 111 |
+
dist_location = os.path.join(eggs_dir, wheel.egg_name())
|
| 112 |
+
wheel.install_as_egg(dist_location)
|
| 113 |
+
dist_metadata = pkg_resources.PathMetadata(
|
| 114 |
+
dist_location, os.path.join(dist_location, 'EGG-INFO')
|
| 115 |
+
)
|
| 116 |
+
return pkg_resources.Distribution.from_filename(
|
| 117 |
+
dist_location, metadata=dist_metadata
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def strip_marker(req):
|
| 122 |
+
"""
|
| 123 |
+
Return a new requirement without the environment marker to avoid
|
| 124 |
+
calling pip with something like `babel; extra == "i18n"`, which
|
| 125 |
+
would always be ignored.
|
| 126 |
+
"""
|
| 127 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 128 |
+
|
| 129 |
+
# create a copy to avoid mutating the input
|
| 130 |
+
req = pkg_resources.Requirement.parse(str(req))
|
| 131 |
+
req.marker = None
|
| 132 |
+
return req
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _warn_wheel_not_available(dist):
|
| 136 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 137 |
+
|
| 138 |
+
try:
|
| 139 |
+
pkg_resources.get_distribution('wheel')
|
| 140 |
+
except pkg_resources.DistributionNotFound:
|
| 141 |
+
dist.announce('WARNING: The wheel package is not available.', log.WARN)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class _DeprecatedInstaller(SetuptoolsDeprecationWarning):
|
| 145 |
+
_SUMMARY = "setuptools.installer and fetch_build_eggs are deprecated."
|
| 146 |
+
_DETAILS = """
|
| 147 |
+
Requirements should be satisfied by a PEP 517 installer.
|
| 148 |
+
If you are using pip, you can try `pip install --use-pep517`.
|
| 149 |
+
"""
|
| 150 |
+
# _DUE_DATE not decided yet
|
valley/lib/python3.10/site-packages/setuptools/logging.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
import logging
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
from . import monkey
|
| 6 |
+
|
| 7 |
+
import distutils.log
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _not_warning(record):
|
| 11 |
+
return record.levelno < logging.WARNING
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def configure() -> None:
|
| 15 |
+
"""
|
| 16 |
+
Configure logging to emit warning and above to stderr
|
| 17 |
+
and everything else to stdout. This behavior is provided
|
| 18 |
+
for compatibility with distutils.log but may change in
|
| 19 |
+
the future.
|
| 20 |
+
"""
|
| 21 |
+
err_handler = logging.StreamHandler()
|
| 22 |
+
err_handler.setLevel(logging.WARNING)
|
| 23 |
+
out_handler = logging.StreamHandler(sys.stdout)
|
| 24 |
+
out_handler.addFilter(_not_warning)
|
| 25 |
+
handlers = err_handler, out_handler
|
| 26 |
+
logging.basicConfig(
|
| 27 |
+
format="{message}", style='{', handlers=handlers, level=logging.DEBUG
|
| 28 |
+
)
|
| 29 |
+
if inspect.ismodule(distutils.dist.log):
|
| 30 |
+
monkey.patch_func(set_threshold, distutils.log, 'set_threshold')
|
| 31 |
+
# For some reason `distutils.log` module is getting cached in `distutils.dist`
|
| 32 |
+
# and then loaded again when patched,
|
| 33 |
+
# implying: id(distutils.log) != id(distutils.dist.log).
|
| 34 |
+
# Make sure the same module object is used everywhere:
|
| 35 |
+
distutils.dist.log = distutils.log
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def set_threshold(level: int) -> int:
|
| 39 |
+
logging.root.setLevel(level * 10)
|
| 40 |
+
return set_threshold.unpatched(level)
|
valley/lib/python3.10/site-packages/setuptools/modified.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
# Ensure a DistutilsError raised by these methods is the same as distutils.errors.DistutilsError
|
| 3 |
+
from distutils._modified import (
|
| 4 |
+
newer,
|
| 5 |
+
newer_group,
|
| 6 |
+
newer_pairwise,
|
| 7 |
+
newer_pairwise_group,
|
| 8 |
+
)
|
| 9 |
+
except ImportError:
|
| 10 |
+
# fallback for SETUPTOOLS_USE_DISTUTILS=stdlib, because _modified never existed in stdlib
|
| 11 |
+
from ._distutils._modified import (
|
| 12 |
+
newer,
|
| 13 |
+
newer_group,
|
| 14 |
+
newer_pairwise,
|
| 15 |
+
newer_pairwise_group,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
__all__ = ['newer', 'newer_pairwise', 'newer_group', 'newer_pairwise_group']
|
valley/lib/python3.10/site-packages/setuptools/script (dev).tmpl
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# EASY-INSTALL-DEV-SCRIPT: %(spec)r,%(script_name)r
|
| 2 |
+
__requires__ = %(spec)r
|
| 3 |
+
__import__('pkg_resources').require(%(spec)r)
|
| 4 |
+
__file__ = %(dev_path)r
|
| 5 |
+
with open(__file__) as f:
|
| 6 |
+
exec(compile(f.read(), __file__, 'exec'))
|
valley/lib/python3.10/site-packages/setuptools/script.tmpl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r
|
| 2 |
+
__requires__ = %(spec)r
|
| 3 |
+
__import__('pkg_resources').run_script(%(spec)r, %(script_name)r)
|
valley/lib/python3.10/site-packages/setuptools/tests/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import locale
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
__all__ = ['fail_on_ascii']
|
| 7 |
+
|
| 8 |
+
if sys.version_info >= (3, 11):
|
| 9 |
+
locale_encoding = locale.getencoding()
|
| 10 |
+
else:
|
| 11 |
+
locale_encoding = locale.getpreferredencoding(False)
|
| 12 |
+
is_ascii = locale_encoding == 'ANSI_X3.4-1968'
|
| 13 |
+
fail_on_ascii = pytest.mark.xfail(is_ascii, reason="Test fails in this locale")
|
valley/lib/python3.10/site-packages/setuptools/tests/config/setupcfg_examples.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ====================================================================
|
| 2 |
+
# Some popular packages that use setup.cfg (and others not so popular)
|
| 3 |
+
# Reference: https://hugovk.github.io/top-pypi-packages/
|
| 4 |
+
# ====================================================================
|
| 5 |
+
https://github.com/pypa/setuptools/raw/52c990172fec37766b3566679724aa8bf70ae06d/setup.cfg
|
| 6 |
+
https://github.com/pypa/wheel/raw/0acd203cd896afec7f715aa2ff5980a403459a3b/setup.cfg
|
| 7 |
+
https://github.com/python/importlib_metadata/raw/2f05392ca980952a6960d82b2f2d2ea10aa53239/setup.cfg
|
| 8 |
+
https://github.com/jaraco/skeleton/raw/d9008b5c510cd6969127a6a2ab6f832edddef296/setup.cfg
|
| 9 |
+
https://github.com/jaraco/zipp/raw/700d3a96390e970b6b962823bfea78b4f7e1c537/setup.cfg
|
| 10 |
+
https://github.com/pallets/jinja/raw/7d72eb7fefb7dce065193967f31f805180508448/setup.cfg
|
| 11 |
+
https://github.com/tkem/cachetools/raw/2fd87a94b8d3861d80e9e4236cd480bfdd21c90d/setup.cfg
|
| 12 |
+
https://github.com/aio-libs/aiohttp/raw/5e0e6b7080f2408d5f1dd544c0e1cf88378b7b10/setup.cfg
|
| 13 |
+
https://github.com/pallets/flask/raw/9486b6cf57bd6a8a261f67091aca8ca78eeec1e3/setup.cfg
|
| 14 |
+
https://github.com/pallets/click/raw/6411f425fae545f42795665af4162006b36c5e4a/setup.cfg
|
| 15 |
+
https://github.com/sqlalchemy/sqlalchemy/raw/533f5718904b620be8d63f2474229945d6f8ba5d/setup.cfg
|
| 16 |
+
https://github.com/pytest-dev/pluggy/raw/461ef63291d13589c4e21aa182cd1529257e9a0a/setup.cfg
|
| 17 |
+
https://github.com/pytest-dev/pytest/raw/c7be96dae487edbd2f55b561b31b68afac1dabe6/setup.cfg
|
| 18 |
+
https://github.com/platformdirs/platformdirs/raw/7b7852128dd6f07511b618d6edea35046bd0c6ff/setup.cfg
|
| 19 |
+
https://github.com/pandas-dev/pandas/raw/bc17343f934a33dc231c8c74be95d8365537c376/setup.cfg
|
| 20 |
+
https://github.com/django/django/raw/4e249d11a6e56ca8feb4b055b681cec457ef3a3d/setup.cfg
|
| 21 |
+
https://github.com/pyscaffold/pyscaffold/raw/de7aa5dc059fbd04307419c667cc4961bc9df4b8/setup.cfg
|
| 22 |
+
https://github.com/pypa/virtualenv/raw/f92eda6e3da26a4d28c2663ffb85c4960bdb990c/setup.cfg
|
valley/lib/python3.10/site-packages/setuptools/tests/config/test_apply_pyprojecttoml.py
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Make sure that applying the configuration from pyproject.toml is equivalent to
|
| 2 |
+
applying a similar configuration from setup.cfg
|
| 3 |
+
|
| 4 |
+
To run these tests offline, please have a look on ``./downloads/preload.py``
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import io
|
| 10 |
+
import re
|
| 11 |
+
import tarfile
|
| 12 |
+
from inspect import cleandoc
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from unittest.mock import Mock
|
| 15 |
+
|
| 16 |
+
import pytest
|
| 17 |
+
from ini2toml.api import LiteTranslator
|
| 18 |
+
from packaging.metadata import Metadata
|
| 19 |
+
|
| 20 |
+
import setuptools # noqa: F401 # ensure monkey patch to metadata
|
| 21 |
+
from setuptools._static import is_static
|
| 22 |
+
from setuptools.command.egg_info import write_requirements
|
| 23 |
+
from setuptools.config import expand, pyprojecttoml, setupcfg
|
| 24 |
+
from setuptools.config._apply_pyprojecttoml import _MissingDynamic, _some_attrgetter
|
| 25 |
+
from setuptools.dist import Distribution
|
| 26 |
+
from setuptools.errors import RemovedConfigError
|
| 27 |
+
|
| 28 |
+
from .downloads import retrieve_file, urls_from_file
|
| 29 |
+
|
| 30 |
+
HERE = Path(__file__).parent
|
| 31 |
+
EXAMPLES_FILE = "setupcfg_examples.txt"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def makedist(path, **attrs):
|
| 35 |
+
return Distribution({"src_root": path, **attrs})
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@pytest.mark.parametrize("url", urls_from_file(HERE / EXAMPLES_FILE))
|
| 39 |
+
@pytest.mark.filterwarnings("ignore")
|
| 40 |
+
@pytest.mark.uses_network
|
| 41 |
+
def test_apply_pyproject_equivalent_to_setupcfg(url, monkeypatch, tmp_path):
|
| 42 |
+
monkeypatch.setattr(expand, "read_attr", Mock(return_value="0.0.1"))
|
| 43 |
+
setupcfg_example = retrieve_file(url)
|
| 44 |
+
pyproject_example = Path(tmp_path, "pyproject.toml")
|
| 45 |
+
setupcfg_text = setupcfg_example.read_text(encoding="utf-8")
|
| 46 |
+
toml_config = LiteTranslator().translate(setupcfg_text, "setup.cfg")
|
| 47 |
+
pyproject_example.write_text(toml_config, encoding="utf-8")
|
| 48 |
+
|
| 49 |
+
dist_toml = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject_example)
|
| 50 |
+
dist_cfg = setupcfg.apply_configuration(makedist(tmp_path), setupcfg_example)
|
| 51 |
+
|
| 52 |
+
pkg_info_toml = core_metadata(dist_toml)
|
| 53 |
+
pkg_info_cfg = core_metadata(dist_cfg)
|
| 54 |
+
assert pkg_info_toml == pkg_info_cfg
|
| 55 |
+
|
| 56 |
+
if any(getattr(d, "license_files", None) for d in (dist_toml, dist_cfg)):
|
| 57 |
+
assert set(dist_toml.license_files) == set(dist_cfg.license_files)
|
| 58 |
+
|
| 59 |
+
if any(getattr(d, "entry_points", None) for d in (dist_toml, dist_cfg)):
|
| 60 |
+
print(dist_cfg.entry_points)
|
| 61 |
+
ep_toml = {
|
| 62 |
+
(k, *sorted(i.replace(" ", "") for i in v))
|
| 63 |
+
for k, v in dist_toml.entry_points.items()
|
| 64 |
+
}
|
| 65 |
+
ep_cfg = {
|
| 66 |
+
(k, *sorted(i.replace(" ", "") for i in v))
|
| 67 |
+
for k, v in dist_cfg.entry_points.items()
|
| 68 |
+
}
|
| 69 |
+
assert ep_toml == ep_cfg
|
| 70 |
+
|
| 71 |
+
if any(getattr(d, "package_data", None) for d in (dist_toml, dist_cfg)):
|
| 72 |
+
pkg_data_toml = {(k, *sorted(v)) for k, v in dist_toml.package_data.items()}
|
| 73 |
+
pkg_data_cfg = {(k, *sorted(v)) for k, v in dist_cfg.package_data.items()}
|
| 74 |
+
assert pkg_data_toml == pkg_data_cfg
|
| 75 |
+
|
| 76 |
+
if any(getattr(d, "data_files", None) for d in (dist_toml, dist_cfg)):
|
| 77 |
+
data_files_toml = {(k, *sorted(v)) for k, v in dist_toml.data_files}
|
| 78 |
+
data_files_cfg = {(k, *sorted(v)) for k, v in dist_cfg.data_files}
|
| 79 |
+
assert data_files_toml == data_files_cfg
|
| 80 |
+
|
| 81 |
+
assert set(dist_toml.install_requires) == set(dist_cfg.install_requires)
|
| 82 |
+
if any(getattr(d, "extras_require", None) for d in (dist_toml, dist_cfg)):
|
| 83 |
+
extra_req_toml = {(k, *sorted(v)) for k, v in dist_toml.extras_require.items()}
|
| 84 |
+
extra_req_cfg = {(k, *sorted(v)) for k, v in dist_cfg.extras_require.items()}
|
| 85 |
+
assert extra_req_toml == extra_req_cfg
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
PEP621_EXAMPLE = """\
|
| 89 |
+
[project]
|
| 90 |
+
name = "spam"
|
| 91 |
+
version = "2020.0.0"
|
| 92 |
+
description = "Lovely Spam! Wonderful Spam!"
|
| 93 |
+
readme = "README.rst"
|
| 94 |
+
requires-python = ">=3.8"
|
| 95 |
+
license = {file = "LICENSE.txt"}
|
| 96 |
+
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
|
| 97 |
+
authors = [
|
| 98 |
+
{email = "hi@pradyunsg.me"},
|
| 99 |
+
{name = "Tzu-Ping Chung"}
|
| 100 |
+
]
|
| 101 |
+
maintainers = [
|
| 102 |
+
{name = "Brett Cannon", email = "brett@python.org"},
|
| 103 |
+
{name = "John X. Ãørçeč", email = "john@utf8.org"},
|
| 104 |
+
{name = "Γαμα קּ 東", email = "gama@utf8.org"},
|
| 105 |
+
]
|
| 106 |
+
classifiers = [
|
| 107 |
+
"Development Status :: 4 - Beta",
|
| 108 |
+
"Programming Language :: Python"
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
dependencies = [
|
| 112 |
+
"httpx",
|
| 113 |
+
"gidgethub[httpx]>4.0.0",
|
| 114 |
+
"django>2.1; os_name != 'nt'",
|
| 115 |
+
"django>2.0; os_name == 'nt'"
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
+
[project.optional-dependencies]
|
| 119 |
+
test = [
|
| 120 |
+
"pytest < 5.0.0",
|
| 121 |
+
"pytest-cov[all]"
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
[project.urls]
|
| 125 |
+
homepage = "http://example.com"
|
| 126 |
+
documentation = "http://readthedocs.org"
|
| 127 |
+
repository = "http://github.com"
|
| 128 |
+
changelog = "http://github.com/me/spam/blob/master/CHANGELOG.md"
|
| 129 |
+
|
| 130 |
+
[project.scripts]
|
| 131 |
+
spam-cli = "spam:main_cli"
|
| 132 |
+
|
| 133 |
+
[project.gui-scripts]
|
| 134 |
+
spam-gui = "spam:main_gui"
|
| 135 |
+
|
| 136 |
+
[project.entry-points."spam.magical"]
|
| 137 |
+
tomatoes = "spam:main_tomatoes"
|
| 138 |
+
"""
|
| 139 |
+
|
| 140 |
+
PEP621_INTERNATIONAL_EMAIL_EXAMPLE = """\
|
| 141 |
+
[project]
|
| 142 |
+
name = "spam"
|
| 143 |
+
version = "2020.0.0"
|
| 144 |
+
authors = [
|
| 145 |
+
{email = "hi@pradyunsg.me"},
|
| 146 |
+
{name = "Tzu-Ping Chung"}
|
| 147 |
+
]
|
| 148 |
+
maintainers = [
|
| 149 |
+
{name = "Степан Бандера", email = "криївка@оун-упа.укр"},
|
| 150 |
+
]
|
| 151 |
+
"""
|
| 152 |
+
|
| 153 |
+
PEP621_EXAMPLE_SCRIPT = """
|
| 154 |
+
def main_cli(): pass
|
| 155 |
+
def main_gui(): pass
|
| 156 |
+
def main_tomatoes(): pass
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _pep621_example_project(
|
| 161 |
+
tmp_path,
|
| 162 |
+
readme="README.rst",
|
| 163 |
+
pyproject_text=PEP621_EXAMPLE,
|
| 164 |
+
):
|
| 165 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 166 |
+
text = pyproject_text
|
| 167 |
+
replacements = {'readme = "README.rst"': f'readme = "{readme}"'}
|
| 168 |
+
for orig, subst in replacements.items():
|
| 169 |
+
text = text.replace(orig, subst)
|
| 170 |
+
pyproject.write_text(text, encoding="utf-8")
|
| 171 |
+
|
| 172 |
+
(tmp_path / readme).write_text("hello world", encoding="utf-8")
|
| 173 |
+
(tmp_path / "LICENSE.txt").write_text("--- LICENSE stub ---", encoding="utf-8")
|
| 174 |
+
(tmp_path / "spam.py").write_text(PEP621_EXAMPLE_SCRIPT, encoding="utf-8")
|
| 175 |
+
return pyproject
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def test_pep621_example(tmp_path):
|
| 179 |
+
"""Make sure the example in PEP 621 works"""
|
| 180 |
+
pyproject = _pep621_example_project(tmp_path)
|
| 181 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 182 |
+
assert dist.metadata.license == "--- LICENSE stub ---"
|
| 183 |
+
assert set(dist.metadata.license_files) == {"LICENSE.txt"}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
@pytest.mark.parametrize(
|
| 187 |
+
("readme", "ctype"),
|
| 188 |
+
[
|
| 189 |
+
("Readme.txt", "text/plain"),
|
| 190 |
+
("readme.md", "text/markdown"),
|
| 191 |
+
("text.rst", "text/x-rst"),
|
| 192 |
+
],
|
| 193 |
+
)
|
| 194 |
+
def test_readme_content_type(tmp_path, readme, ctype):
|
| 195 |
+
pyproject = _pep621_example_project(tmp_path, readme)
|
| 196 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 197 |
+
assert dist.metadata.long_description_content_type == ctype
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def test_undefined_content_type(tmp_path):
|
| 201 |
+
pyproject = _pep621_example_project(tmp_path, "README.tex")
|
| 202 |
+
with pytest.raises(ValueError, match="Undefined content type for README.tex"):
|
| 203 |
+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def test_no_explicit_content_type_for_missing_extension(tmp_path):
|
| 207 |
+
pyproject = _pep621_example_project(tmp_path, "README")
|
| 208 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 209 |
+
assert dist.metadata.long_description_content_type is None
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
@pytest.mark.parametrize(
|
| 213 |
+
("pyproject_text", "expected_maintainers_meta_value"),
|
| 214 |
+
(
|
| 215 |
+
pytest.param(
|
| 216 |
+
PEP621_EXAMPLE,
|
| 217 |
+
(
|
| 218 |
+
'Brett Cannon <brett@python.org>, "John X. Ãørçeč" <john@utf8.org>, '
|
| 219 |
+
'Γαμα קּ 東 <gama@utf8.org>'
|
| 220 |
+
),
|
| 221 |
+
id='non-international-emails',
|
| 222 |
+
),
|
| 223 |
+
pytest.param(
|
| 224 |
+
PEP621_INTERNATIONAL_EMAIL_EXAMPLE,
|
| 225 |
+
'Степан Бандера <криївка@оун-упа.укр>',
|
| 226 |
+
marks=pytest.mark.xfail(
|
| 227 |
+
reason="CPython's `email.headerregistry.Address` only supports "
|
| 228 |
+
'RFC 5322, as of Nov 10, 2022 and latest Python 3.11.0',
|
| 229 |
+
strict=True,
|
| 230 |
+
),
|
| 231 |
+
id='international-email',
|
| 232 |
+
),
|
| 233 |
+
),
|
| 234 |
+
)
|
| 235 |
+
def test_utf8_maintainer_in_metadata( # issue-3663
|
| 236 |
+
expected_maintainers_meta_value,
|
| 237 |
+
pyproject_text,
|
| 238 |
+
tmp_path,
|
| 239 |
+
):
|
| 240 |
+
pyproject = _pep621_example_project(
|
| 241 |
+
tmp_path,
|
| 242 |
+
"README",
|
| 243 |
+
pyproject_text=pyproject_text,
|
| 244 |
+
)
|
| 245 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 246 |
+
assert dist.metadata.maintainer_email == expected_maintainers_meta_value
|
| 247 |
+
pkg_file = tmp_path / "PKG-FILE"
|
| 248 |
+
with open(pkg_file, "w", encoding="utf-8") as fh:
|
| 249 |
+
dist.metadata.write_pkg_file(fh)
|
| 250 |
+
content = pkg_file.read_text(encoding="utf-8")
|
| 251 |
+
assert f"Maintainer-email: {expected_maintainers_meta_value}" in content
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
class TestLicenseFiles:
|
| 255 |
+
# TODO: After PEP 639 is accepted, we have to move the license-files
|
| 256 |
+
# to the `project` table instead of `tool.setuptools`
|
| 257 |
+
|
| 258 |
+
def base_pyproject(self, tmp_path, additional_text):
|
| 259 |
+
pyproject = _pep621_example_project(tmp_path, "README")
|
| 260 |
+
text = pyproject.read_text(encoding="utf-8")
|
| 261 |
+
|
| 262 |
+
# Sanity-check
|
| 263 |
+
assert 'license = {file = "LICENSE.txt"}' in text
|
| 264 |
+
assert "[tool.setuptools]" not in text
|
| 265 |
+
|
| 266 |
+
text = f"{text}\n{additional_text}\n"
|
| 267 |
+
pyproject.write_text(text, encoding="utf-8")
|
| 268 |
+
return pyproject
|
| 269 |
+
|
| 270 |
+
def test_both_license_and_license_files_defined(self, tmp_path):
|
| 271 |
+
setuptools_config = '[tool.setuptools]\nlicense-files = ["_FILE*"]'
|
| 272 |
+
pyproject = self.base_pyproject(tmp_path, setuptools_config)
|
| 273 |
+
|
| 274 |
+
(tmp_path / "_FILE.txt").touch()
|
| 275 |
+
(tmp_path / "_FILE.rst").touch()
|
| 276 |
+
|
| 277 |
+
# Would normally match the `license_files` patterns, but we want to exclude it
|
| 278 |
+
# by being explicit. On the other hand, contents should be added to `license`
|
| 279 |
+
license = tmp_path / "LICENSE.txt"
|
| 280 |
+
license.write_text("LicenseRef-Proprietary\n", encoding="utf-8")
|
| 281 |
+
|
| 282 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 283 |
+
assert set(dist.metadata.license_files) == {"_FILE.rst", "_FILE.txt"}
|
| 284 |
+
assert dist.metadata.license == "LicenseRef-Proprietary\n"
|
| 285 |
+
|
| 286 |
+
def test_default_patterns(self, tmp_path):
|
| 287 |
+
setuptools_config = '[tool.setuptools]\nzip-safe = false'
|
| 288 |
+
# ^ used just to trigger section validation
|
| 289 |
+
pyproject = self.base_pyproject(tmp_path, setuptools_config)
|
| 290 |
+
|
| 291 |
+
license_files = "LICENCE-a.html COPYING-abc.txt AUTHORS-xyz NOTICE,def".split()
|
| 292 |
+
|
| 293 |
+
for fname in license_files:
|
| 294 |
+
(tmp_path / fname).write_text(f"{fname}\n", encoding="utf-8")
|
| 295 |
+
|
| 296 |
+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 297 |
+
assert (tmp_path / "LICENSE.txt").exists() # from base example
|
| 298 |
+
assert set(dist.metadata.license_files) == {*license_files, "LICENSE.txt"}
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
class TestPyModules:
|
| 302 |
+
# https://github.com/pypa/setuptools/issues/4316
|
| 303 |
+
|
| 304 |
+
def dist(self, name):
|
| 305 |
+
toml_config = f"""
|
| 306 |
+
[project]
|
| 307 |
+
name = "test"
|
| 308 |
+
version = "42.0"
|
| 309 |
+
[tool.setuptools]
|
| 310 |
+
py-modules = [{name!r}]
|
| 311 |
+
"""
|
| 312 |
+
pyproject = Path("pyproject.toml")
|
| 313 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 314 |
+
return pyprojecttoml.apply_configuration(Distribution({}), pyproject)
|
| 315 |
+
|
| 316 |
+
@pytest.mark.parametrize("module", ["pip-run", "abc-d.λ-xyz-e"])
|
| 317 |
+
def test_valid_module_name(self, tmp_path, monkeypatch, module):
|
| 318 |
+
monkeypatch.chdir(tmp_path)
|
| 319 |
+
assert module in self.dist(module).py_modules
|
| 320 |
+
|
| 321 |
+
@pytest.mark.parametrize("module", ["pip run", "-pip-run", "pip-run-stubs"])
|
| 322 |
+
def test_invalid_module_name(self, tmp_path, monkeypatch, module):
|
| 323 |
+
monkeypatch.chdir(tmp_path)
|
| 324 |
+
with pytest.raises(ValueError, match="py-modules"):
|
| 325 |
+
self.dist(module).py_modules
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
class TestExtModules:
|
| 329 |
+
def test_pyproject_sets_attribute(self, tmp_path, monkeypatch):
|
| 330 |
+
monkeypatch.chdir(tmp_path)
|
| 331 |
+
pyproject = Path("pyproject.toml")
|
| 332 |
+
toml_config = """
|
| 333 |
+
[project]
|
| 334 |
+
name = "test"
|
| 335 |
+
version = "42.0"
|
| 336 |
+
[tool.setuptools]
|
| 337 |
+
ext-modules = [
|
| 338 |
+
{name = "my.ext", sources = ["hello.c", "world.c"]}
|
| 339 |
+
]
|
| 340 |
+
"""
|
| 341 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 342 |
+
with pytest.warns(pyprojecttoml._ExperimentalConfiguration):
|
| 343 |
+
dist = pyprojecttoml.apply_configuration(Distribution({}), pyproject)
|
| 344 |
+
assert len(dist.ext_modules) == 1
|
| 345 |
+
assert dist.ext_modules[0].name == "my.ext"
|
| 346 |
+
assert set(dist.ext_modules[0].sources) == {"hello.c", "world.c"}
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
class TestDeprecatedFields:
|
| 350 |
+
def test_namespace_packages(self, tmp_path):
|
| 351 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 352 |
+
config = """
|
| 353 |
+
[project]
|
| 354 |
+
name = "myproj"
|
| 355 |
+
version = "42"
|
| 356 |
+
[tool.setuptools]
|
| 357 |
+
namespace-packages = ["myproj.pkg"]
|
| 358 |
+
"""
|
| 359 |
+
pyproject.write_text(cleandoc(config), encoding="utf-8")
|
| 360 |
+
with pytest.raises(RemovedConfigError, match="namespace-packages"):
|
| 361 |
+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
class TestPresetField:
|
| 365 |
+
def pyproject(self, tmp_path, dynamic, extra_content=""):
|
| 366 |
+
content = f"[project]\nname = 'proj'\ndynamic = {dynamic!r}\n"
|
| 367 |
+
if "version" not in dynamic:
|
| 368 |
+
content += "version = '42'\n"
|
| 369 |
+
file = tmp_path / "pyproject.toml"
|
| 370 |
+
file.write_text(content + extra_content, encoding="utf-8")
|
| 371 |
+
return file
|
| 372 |
+
|
| 373 |
+
@pytest.mark.parametrize(
|
| 374 |
+
("attr", "field", "value"),
|
| 375 |
+
[
|
| 376 |
+
("classifiers", "classifiers", ["Private :: Classifier"]),
|
| 377 |
+
("entry_points", "scripts", {"console_scripts": ["foobar=foobar:main"]}),
|
| 378 |
+
("entry_points", "gui-scripts", {"gui_scripts": ["bazquux=bazquux:main"]}),
|
| 379 |
+
pytest.param(
|
| 380 |
+
*("install_requires", "dependencies", ["six"]),
|
| 381 |
+
marks=[
|
| 382 |
+
pytest.mark.filterwarnings("ignore:.*install_requires. overwritten")
|
| 383 |
+
],
|
| 384 |
+
),
|
| 385 |
+
],
|
| 386 |
+
)
|
| 387 |
+
def test_not_listed_in_dynamic(self, tmp_path, attr, field, value):
|
| 388 |
+
"""Setuptools cannot set a field if not listed in ``dynamic``"""
|
| 389 |
+
pyproject = self.pyproject(tmp_path, [])
|
| 390 |
+
dist = makedist(tmp_path, **{attr: value})
|
| 391 |
+
msg = re.compile(f"defined outside of `pyproject.toml`:.*{field}", re.S)
|
| 392 |
+
with pytest.warns(_MissingDynamic, match=msg):
|
| 393 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 394 |
+
|
| 395 |
+
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
|
| 396 |
+
assert not dist_value
|
| 397 |
+
|
| 398 |
+
@pytest.mark.parametrize(
|
| 399 |
+
("attr", "field", "value"),
|
| 400 |
+
[
|
| 401 |
+
("install_requires", "dependencies", []),
|
| 402 |
+
("extras_require", "optional-dependencies", {}),
|
| 403 |
+
("install_requires", "dependencies", ["six"]),
|
| 404 |
+
("classifiers", "classifiers", ["Private :: Classifier"]),
|
| 405 |
+
],
|
| 406 |
+
)
|
| 407 |
+
def test_listed_in_dynamic(self, tmp_path, attr, field, value):
|
| 408 |
+
pyproject = self.pyproject(tmp_path, [field])
|
| 409 |
+
dist = makedist(tmp_path, **{attr: value})
|
| 410 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 411 |
+
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
|
| 412 |
+
assert dist_value == value
|
| 413 |
+
|
| 414 |
+
def test_warning_overwritten_dependencies(self, tmp_path):
|
| 415 |
+
src = "[project]\nname='pkg'\nversion='0.1'\ndependencies=['click']\n"
|
| 416 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 417 |
+
pyproject.write_text(src, encoding="utf-8")
|
| 418 |
+
dist = makedist(tmp_path, install_requires=["wheel"])
|
| 419 |
+
with pytest.warns(match="`install_requires` overwritten"):
|
| 420 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 421 |
+
assert "wheel" not in dist.install_requires
|
| 422 |
+
|
| 423 |
+
def test_optional_dependencies_dont_remove_env_markers(self, tmp_path):
|
| 424 |
+
"""
|
| 425 |
+
Internally setuptools converts dependencies with markers to "extras".
|
| 426 |
+
If ``install_requires`` is given by ``setup.py``, we have to ensure that
|
| 427 |
+
applying ``optional-dependencies`` does not overwrite the mandatory
|
| 428 |
+
dependencies with markers (see #3204).
|
| 429 |
+
"""
|
| 430 |
+
# If setuptools replace its internal mechanism that uses `requires.txt`
|
| 431 |
+
# this test has to be rewritten to adapt accordingly
|
| 432 |
+
extra = "\n[project.optional-dependencies]\nfoo = ['bar>1']\n"
|
| 433 |
+
pyproject = self.pyproject(tmp_path, ["dependencies"], extra)
|
| 434 |
+
install_req = ['importlib-resources (>=3.0.0) ; python_version < "3.7"']
|
| 435 |
+
dist = makedist(tmp_path, install_requires=install_req)
|
| 436 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 437 |
+
assert "foo" in dist.extras_require
|
| 438 |
+
egg_info = dist.get_command_obj("egg_info")
|
| 439 |
+
write_requirements(egg_info, tmp_path, tmp_path / "requires.txt")
|
| 440 |
+
reqs = (tmp_path / "requires.txt").read_text(encoding="utf-8")
|
| 441 |
+
assert "importlib-resources" in reqs
|
| 442 |
+
assert "bar" in reqs
|
| 443 |
+
assert ':python_version < "3.7"' in reqs
|
| 444 |
+
|
| 445 |
+
@pytest.mark.parametrize(
|
| 446 |
+
("field", "group"),
|
| 447 |
+
[("scripts", "console_scripts"), ("gui-scripts", "gui_scripts")],
|
| 448 |
+
)
|
| 449 |
+
@pytest.mark.filterwarnings("error")
|
| 450 |
+
def test_scripts_dont_require_dynamic_entry_points(self, tmp_path, field, group):
|
| 451 |
+
# Issue 3862
|
| 452 |
+
pyproject = self.pyproject(tmp_path, [field])
|
| 453 |
+
dist = makedist(tmp_path, entry_points={group: ["foobar=foobar:main"]})
|
| 454 |
+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
|
| 455 |
+
assert group in dist.entry_points
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
class TestMeta:
|
| 459 |
+
def test_example_file_in_sdist(self, setuptools_sdist):
|
| 460 |
+
"""Meta test to ensure tests can run from sdist"""
|
| 461 |
+
with tarfile.open(setuptools_sdist) as tar:
|
| 462 |
+
assert any(name.endswith(EXAMPLES_FILE) for name in tar.getnames())
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
class TestInteropCommandLineParsing:
|
| 466 |
+
def test_version(self, tmp_path, monkeypatch, capsys):
|
| 467 |
+
# See pypa/setuptools#4047
|
| 468 |
+
# This test can be removed once the CLI interface of setup.py is removed
|
| 469 |
+
monkeypatch.chdir(tmp_path)
|
| 470 |
+
toml_config = """
|
| 471 |
+
[project]
|
| 472 |
+
name = "test"
|
| 473 |
+
version = "42.0"
|
| 474 |
+
"""
|
| 475 |
+
pyproject = Path(tmp_path, "pyproject.toml")
|
| 476 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 477 |
+
opts = {"script_args": ["--version"]}
|
| 478 |
+
dist = pyprojecttoml.apply_configuration(Distribution(opts), pyproject)
|
| 479 |
+
dist.parse_command_line() # <-- there should be no exception here.
|
| 480 |
+
captured = capsys.readouterr()
|
| 481 |
+
assert "42.0" in captured.out
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
class TestStaticConfig:
|
| 485 |
+
def test_mark_static_fields(self, tmp_path, monkeypatch):
|
| 486 |
+
monkeypatch.chdir(tmp_path)
|
| 487 |
+
toml_config = """
|
| 488 |
+
[project]
|
| 489 |
+
name = "test"
|
| 490 |
+
version = "42.0"
|
| 491 |
+
dependencies = ["hello"]
|
| 492 |
+
keywords = ["world"]
|
| 493 |
+
classifiers = ["private :: hello world"]
|
| 494 |
+
[tool.setuptools]
|
| 495 |
+
obsoletes = ["abcd"]
|
| 496 |
+
provides = ["abcd"]
|
| 497 |
+
platforms = ["abcd"]
|
| 498 |
+
"""
|
| 499 |
+
pyproject = Path(tmp_path, "pyproject.toml")
|
| 500 |
+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
|
| 501 |
+
dist = pyprojecttoml.apply_configuration(Distribution({}), pyproject)
|
| 502 |
+
assert is_static(dist.install_requires)
|
| 503 |
+
assert is_static(dist.metadata.keywords)
|
| 504 |
+
assert is_static(dist.metadata.classifiers)
|
| 505 |
+
assert is_static(dist.metadata.obsoletes)
|
| 506 |
+
assert is_static(dist.metadata.provides)
|
| 507 |
+
assert is_static(dist.metadata.platforms)
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
# --- Auxiliary Functions ---
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def core_metadata(dist) -> str:
|
| 514 |
+
with io.StringIO() as buffer:
|
| 515 |
+
dist.metadata.write_pkg_file(buffer)
|
| 516 |
+
pkg_file_txt = buffer.getvalue()
|
| 517 |
+
|
| 518 |
+
# Make sure core metadata is valid
|
| 519 |
+
Metadata.from_email(pkg_file_txt, validate=True) # can raise exceptions
|
| 520 |
+
|
| 521 |
+
skip_prefixes: tuple[str, ...] = ()
|
| 522 |
+
skip_lines = set()
|
| 523 |
+
# ---- DIFF NORMALISATION ----
|
| 524 |
+
# PEP 621 is very particular about author/maintainer metadata conversion, so skip
|
| 525 |
+
skip_prefixes += ("Author:", "Author-email:", "Maintainer:", "Maintainer-email:")
|
| 526 |
+
# May be redundant with Home-page
|
| 527 |
+
skip_prefixes += ("Project-URL: Homepage,", "Home-page:")
|
| 528 |
+
# May be missing in original (relying on default) but backfilled in the TOML
|
| 529 |
+
skip_prefixes += ("Description-Content-Type:",)
|
| 530 |
+
# Remove empty lines
|
| 531 |
+
skip_lines.add("")
|
| 532 |
+
|
| 533 |
+
result = []
|
| 534 |
+
for line in pkg_file_txt.splitlines():
|
| 535 |
+
if line.startswith(skip_prefixes) or line in skip_lines:
|
| 536 |
+
continue
|
| 537 |
+
result.append(line + "\n")
|
| 538 |
+
|
| 539 |
+
return "".join(result)
|
valley/lib/python3.10/site-packages/setuptools/tests/config/test_pyprojecttoml_dynamic_deps.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from inspect import cleandoc
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
from jaraco import path
|
| 5 |
+
|
| 6 |
+
from setuptools.config.pyprojecttoml import apply_configuration
|
| 7 |
+
from setuptools.dist import Distribution
|
| 8 |
+
from setuptools.warnings import SetuptoolsWarning
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_dynamic_dependencies(tmp_path):
|
| 12 |
+
files = {
|
| 13 |
+
"requirements.txt": "six\n # comment\n",
|
| 14 |
+
"pyproject.toml": cleandoc(
|
| 15 |
+
"""
|
| 16 |
+
[project]
|
| 17 |
+
name = "myproj"
|
| 18 |
+
version = "1.0"
|
| 19 |
+
dynamic = ["dependencies"]
|
| 20 |
+
|
| 21 |
+
[build-system]
|
| 22 |
+
requires = ["setuptools", "wheel"]
|
| 23 |
+
build-backend = "setuptools.build_meta"
|
| 24 |
+
|
| 25 |
+
[tool.setuptools.dynamic.dependencies]
|
| 26 |
+
file = ["requirements.txt"]
|
| 27 |
+
"""
|
| 28 |
+
),
|
| 29 |
+
}
|
| 30 |
+
path.build(files, prefix=tmp_path)
|
| 31 |
+
dist = Distribution()
|
| 32 |
+
dist = apply_configuration(dist, tmp_path / "pyproject.toml")
|
| 33 |
+
assert dist.install_requires == ["six"]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_dynamic_optional_dependencies(tmp_path):
|
| 37 |
+
files = {
|
| 38 |
+
"requirements-docs.txt": "sphinx\n # comment\n",
|
| 39 |
+
"pyproject.toml": cleandoc(
|
| 40 |
+
"""
|
| 41 |
+
[project]
|
| 42 |
+
name = "myproj"
|
| 43 |
+
version = "1.0"
|
| 44 |
+
dynamic = ["optional-dependencies"]
|
| 45 |
+
|
| 46 |
+
[tool.setuptools.dynamic.optional-dependencies.docs]
|
| 47 |
+
file = ["requirements-docs.txt"]
|
| 48 |
+
|
| 49 |
+
[build-system]
|
| 50 |
+
requires = ["setuptools", "wheel"]
|
| 51 |
+
build-backend = "setuptools.build_meta"
|
| 52 |
+
"""
|
| 53 |
+
),
|
| 54 |
+
}
|
| 55 |
+
path.build(files, prefix=tmp_path)
|
| 56 |
+
dist = Distribution()
|
| 57 |
+
dist = apply_configuration(dist, tmp_path / "pyproject.toml")
|
| 58 |
+
assert dist.extras_require == {"docs": ["sphinx"]}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def test_mixed_dynamic_optional_dependencies(tmp_path):
|
| 62 |
+
"""
|
| 63 |
+
Test that if PEP 621 was loosened to allow mixing of dynamic and static
|
| 64 |
+
configurations in the case of fields containing sub-fields (groups),
|
| 65 |
+
things would work out.
|
| 66 |
+
"""
|
| 67 |
+
files = {
|
| 68 |
+
"requirements-images.txt": "pillow~=42.0\n # comment\n",
|
| 69 |
+
"pyproject.toml": cleandoc(
|
| 70 |
+
"""
|
| 71 |
+
[project]
|
| 72 |
+
name = "myproj"
|
| 73 |
+
version = "1.0"
|
| 74 |
+
dynamic = ["optional-dependencies"]
|
| 75 |
+
|
| 76 |
+
[project.optional-dependencies]
|
| 77 |
+
docs = ["sphinx"]
|
| 78 |
+
|
| 79 |
+
[tool.setuptools.dynamic.optional-dependencies.images]
|
| 80 |
+
file = ["requirements-images.txt"]
|
| 81 |
+
"""
|
| 82 |
+
),
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
path.build(files, prefix=tmp_path)
|
| 86 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 87 |
+
with pytest.raises(ValueError, match="project.optional-dependencies"):
|
| 88 |
+
apply_configuration(Distribution(), pyproject)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def test_mixed_extras_require_optional_dependencies(tmp_path):
|
| 92 |
+
files = {
|
| 93 |
+
"pyproject.toml": cleandoc(
|
| 94 |
+
"""
|
| 95 |
+
[project]
|
| 96 |
+
name = "myproj"
|
| 97 |
+
version = "1.0"
|
| 98 |
+
optional-dependencies.docs = ["sphinx"]
|
| 99 |
+
"""
|
| 100 |
+
),
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
path.build(files, prefix=tmp_path)
|
| 104 |
+
pyproject = tmp_path / "pyproject.toml"
|
| 105 |
+
|
| 106 |
+
with pytest.warns(SetuptoolsWarning, match=".extras_require. overwritten"):
|
| 107 |
+
dist = Distribution({"extras_require": {"hello": ["world"]}})
|
| 108 |
+
dist = apply_configuration(dist, pyproject)
|
| 109 |
+
assert dist.extras_require == {"docs": ["sphinx"]}
|
valley/lib/python3.10/site-packages/setuptools/tests/environment.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
import unicodedata
|
| 5 |
+
from subprocess import PIPE as _PIPE, Popen as _Popen
|
| 6 |
+
|
| 7 |
+
import jaraco.envs
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class VirtualEnv(jaraco.envs.VirtualEnv):
|
| 11 |
+
name = '.env'
|
| 12 |
+
# Some version of PyPy will import distutils on startup, implicitly
|
| 13 |
+
# importing setuptools, and thus leading to BackendInvalid errors
|
| 14 |
+
# when upgrading Setuptools. Bypass this behavior by avoiding the
|
| 15 |
+
# early availability and need to upgrade.
|
| 16 |
+
create_opts = ['--no-setuptools']
|
| 17 |
+
|
| 18 |
+
def run(self, cmd, *args, **kwargs):
|
| 19 |
+
cmd = [self.exe(cmd[0])] + cmd[1:]
|
| 20 |
+
kwargs = {"cwd": self.root, "encoding": "utf-8", **kwargs} # Allow overriding
|
| 21 |
+
# In some environments (eg. downstream distro packaging), where:
|
| 22 |
+
# - tox isn't used to run tests and
|
| 23 |
+
# - PYTHONPATH is set to point to a specific setuptools codebase and
|
| 24 |
+
# - no custom env is explicitly set by a test
|
| 25 |
+
# PYTHONPATH will leak into the spawned processes.
|
| 26 |
+
# In that case tests look for module in the wrong place (on PYTHONPATH).
|
| 27 |
+
# Unless the test sets its own special env, pass a copy of the existing
|
| 28 |
+
# environment with removed PYTHONPATH to the subprocesses.
|
| 29 |
+
if "env" not in kwargs:
|
| 30 |
+
env = dict(os.environ)
|
| 31 |
+
if "PYTHONPATH" in env:
|
| 32 |
+
del env["PYTHONPATH"]
|
| 33 |
+
kwargs["env"] = env
|
| 34 |
+
return subprocess.check_output(cmd, *args, **kwargs)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _which_dirs(cmd):
|
| 38 |
+
result = set()
|
| 39 |
+
for path in os.environ.get('PATH', '').split(os.pathsep):
|
| 40 |
+
filename = os.path.join(path, cmd)
|
| 41 |
+
if os.access(filename, os.X_OK):
|
| 42 |
+
result.add(path)
|
| 43 |
+
return result
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def run_setup_py(cmd, pypath=None, path=None, data_stream=0, env=None):
|
| 47 |
+
"""
|
| 48 |
+
Execution command for tests, separate from those used by the
|
| 49 |
+
code directly to prevent accidental behavior issues
|
| 50 |
+
"""
|
| 51 |
+
if env is None:
|
| 52 |
+
env = dict()
|
| 53 |
+
for envname in os.environ:
|
| 54 |
+
env[envname] = os.environ[envname]
|
| 55 |
+
|
| 56 |
+
# override the python path if needed
|
| 57 |
+
if pypath is not None:
|
| 58 |
+
env["PYTHONPATH"] = pypath
|
| 59 |
+
|
| 60 |
+
# override the execution path if needed
|
| 61 |
+
if path is not None:
|
| 62 |
+
env["PATH"] = path
|
| 63 |
+
if not env.get("PATH", ""):
|
| 64 |
+
env["PATH"] = _which_dirs("tar").union(_which_dirs("gzip"))
|
| 65 |
+
env["PATH"] = os.pathsep.join(env["PATH"])
|
| 66 |
+
|
| 67 |
+
cmd = [sys.executable, "setup.py"] + list(cmd)
|
| 68 |
+
|
| 69 |
+
# https://bugs.python.org/issue8557
|
| 70 |
+
shell = sys.platform == 'win32'
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
proc = _Popen(
|
| 74 |
+
cmd,
|
| 75 |
+
stdout=_PIPE,
|
| 76 |
+
stderr=_PIPE,
|
| 77 |
+
shell=shell,
|
| 78 |
+
env=env,
|
| 79 |
+
encoding="utf-8",
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
if isinstance(data_stream, tuple):
|
| 83 |
+
data_stream = slice(*data_stream)
|
| 84 |
+
data = proc.communicate()[data_stream]
|
| 85 |
+
except OSError:
|
| 86 |
+
return 1, ''
|
| 87 |
+
|
| 88 |
+
# decode the console string if needed
|
| 89 |
+
if hasattr(data, "decode"):
|
| 90 |
+
# use the default encoding
|
| 91 |
+
data = data.decode()
|
| 92 |
+
data = unicodedata.normalize('NFC', data)
|
| 93 |
+
|
| 94 |
+
# communicate calls wait()
|
| 95 |
+
return proc.returncode, data
|
valley/lib/python3.10/site-packages/setuptools/tests/fixtures.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import contextlib
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import path
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
from . import contexts, environment
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@pytest.fixture
|
| 14 |
+
def user_override(monkeypatch):
|
| 15 |
+
"""
|
| 16 |
+
Override site.USER_BASE and site.USER_SITE with temporary directories in
|
| 17 |
+
a context.
|
| 18 |
+
"""
|
| 19 |
+
with contexts.tempdir() as user_base:
|
| 20 |
+
monkeypatch.setattr('site.USER_BASE', user_base)
|
| 21 |
+
with contexts.tempdir() as user_site:
|
| 22 |
+
monkeypatch.setattr('site.USER_SITE', user_site)
|
| 23 |
+
with contexts.save_user_site_setting():
|
| 24 |
+
yield
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@pytest.fixture
|
| 28 |
+
def tmpdir_cwd(tmpdir):
|
| 29 |
+
with tmpdir.as_cwd() as orig:
|
| 30 |
+
yield orig
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@pytest.fixture(autouse=True, scope="session")
|
| 34 |
+
def workaround_xdist_376(request):
|
| 35 |
+
"""
|
| 36 |
+
Workaround pytest-dev/pytest-xdist#376
|
| 37 |
+
|
| 38 |
+
``pytest-xdist`` tends to inject '' into ``sys.path``,
|
| 39 |
+
which may break certain isolation expectations.
|
| 40 |
+
Remove the entry so the import
|
| 41 |
+
machinery behaves the same irrespective of xdist.
|
| 42 |
+
"""
|
| 43 |
+
if not request.config.pluginmanager.has_plugin('xdist'):
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
with contextlib.suppress(ValueError):
|
| 47 |
+
sys.path.remove('')
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@pytest.fixture
|
| 51 |
+
def sample_project(tmp_path):
|
| 52 |
+
"""
|
| 53 |
+
Clone the 'sampleproject' and return a path to it.
|
| 54 |
+
"""
|
| 55 |
+
cmd = ['git', 'clone', 'https://github.com/pypa/sampleproject']
|
| 56 |
+
try:
|
| 57 |
+
subprocess.check_call(cmd, cwd=str(tmp_path))
|
| 58 |
+
except Exception:
|
| 59 |
+
pytest.skip("Unable to clone sampleproject")
|
| 60 |
+
return tmp_path / 'sampleproject'
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# sdist and wheel artifacts should be stable across a round of tests
|
| 64 |
+
# so we can build them once per session and use the files as "readonly"
|
| 65 |
+
|
| 66 |
+
# In the case of setuptools, building the wheel without sdist may cause
|
| 67 |
+
# it to contain the `build` directory, and therefore create situations with
|
| 68 |
+
# `setuptools/build/lib/build/lib/...`. To avoid that, build both artifacts at once.
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def _build_distributions(tmp_path_factory, request):
|
| 72 |
+
with contexts.session_locked_tmp_dir(
|
| 73 |
+
request, tmp_path_factory, "dist_build"
|
| 74 |
+
) as tmp: # pragma: no cover
|
| 75 |
+
sdist = next(tmp.glob("*.tar.gz"), None)
|
| 76 |
+
wheel = next(tmp.glob("*.whl"), None)
|
| 77 |
+
if sdist and wheel:
|
| 78 |
+
return (sdist, wheel)
|
| 79 |
+
|
| 80 |
+
# Sanity check: should not create recursive setuptools/build/lib/build/lib/...
|
| 81 |
+
assert not Path(request.config.rootdir, "build/lib/build").exists()
|
| 82 |
+
|
| 83 |
+
subprocess.check_output([
|
| 84 |
+
sys.executable,
|
| 85 |
+
"-m",
|
| 86 |
+
"build",
|
| 87 |
+
"--outdir",
|
| 88 |
+
str(tmp),
|
| 89 |
+
str(request.config.rootdir),
|
| 90 |
+
])
|
| 91 |
+
|
| 92 |
+
# Sanity check: should not create recursive setuptools/build/lib/build/lib/...
|
| 93 |
+
assert not Path(request.config.rootdir, "build/lib/build").exists()
|
| 94 |
+
|
| 95 |
+
return next(tmp.glob("*.tar.gz")), next(tmp.glob("*.whl"))
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
@pytest.fixture(scope="session")
|
| 99 |
+
def setuptools_sdist(tmp_path_factory, request):
|
| 100 |
+
prebuilt = os.getenv("PRE_BUILT_SETUPTOOLS_SDIST")
|
| 101 |
+
if prebuilt and os.path.exists(prebuilt): # pragma: no cover
|
| 102 |
+
return Path(prebuilt).resolve()
|
| 103 |
+
|
| 104 |
+
sdist, _ = _build_distributions(tmp_path_factory, request)
|
| 105 |
+
return sdist
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@pytest.fixture(scope="session")
|
| 109 |
+
def setuptools_wheel(tmp_path_factory, request):
|
| 110 |
+
prebuilt = os.getenv("PRE_BUILT_SETUPTOOLS_WHEEL")
|
| 111 |
+
if prebuilt and os.path.exists(prebuilt): # pragma: no cover
|
| 112 |
+
return Path(prebuilt).resolve()
|
| 113 |
+
|
| 114 |
+
_, wheel = _build_distributions(tmp_path_factory, request)
|
| 115 |
+
return wheel
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
@pytest.fixture
|
| 119 |
+
def venv(tmp_path, setuptools_wheel):
|
| 120 |
+
"""Virtual env with the version of setuptools under test installed"""
|
| 121 |
+
env = environment.VirtualEnv()
|
| 122 |
+
env.root = path.Path(tmp_path / 'venv')
|
| 123 |
+
env.create_opts = ['--no-setuptools', '--wheel=bundle']
|
| 124 |
+
# TODO: Use `--no-wheel` when setuptools implements its own bdist_wheel
|
| 125 |
+
env.req = str(setuptools_wheel)
|
| 126 |
+
# In some environments (eg. downstream distro packaging),
|
| 127 |
+
# where tox isn't used to run tests and PYTHONPATH is set to point to
|
| 128 |
+
# a specific setuptools codebase, PYTHONPATH will leak into the spawned
|
| 129 |
+
# processes.
|
| 130 |
+
# env.create() should install the just created setuptools
|
| 131 |
+
# wheel, but it doesn't if it finds another existing matching setuptools
|
| 132 |
+
# installation present on PYTHONPATH:
|
| 133 |
+
# `setuptools is already installed with the same version as the provided
|
| 134 |
+
# wheel. Use --force-reinstall to force an installation of the wheel.`
|
| 135 |
+
# This prevents leaking PYTHONPATH to the created environment.
|
| 136 |
+
with contexts.environment(PYTHONPATH=None):
|
| 137 |
+
return env.create()
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
@pytest.fixture
|
| 141 |
+
def venv_without_setuptools(tmp_path):
|
| 142 |
+
"""Virtual env without any version of setuptools installed"""
|
| 143 |
+
env = environment.VirtualEnv()
|
| 144 |
+
env.root = path.Path(tmp_path / 'venv_without_setuptools')
|
| 145 |
+
env.create_opts = ['--no-setuptools', '--no-wheel']
|
| 146 |
+
env.ensure_env()
|
| 147 |
+
return env
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
@pytest.fixture
|
| 151 |
+
def bare_venv(tmp_path):
|
| 152 |
+
"""Virtual env without any common packages installed"""
|
| 153 |
+
env = environment.VirtualEnv()
|
| 154 |
+
env.root = path.Path(tmp_path / 'bare_venv')
|
| 155 |
+
env.create_opts = ['--no-setuptools', '--no-pip', '--no-wheel', '--no-seed']
|
| 156 |
+
env.ensure_env()
|
| 157 |
+
return env
|
valley/lib/python3.10/site-packages/setuptools/tests/mod_with_constant.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
value = 'three, sir!'
|
valley/lib/python3.10/site-packages/setuptools/tests/namespaces.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
import json
|
| 3 |
+
import textwrap
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def iter_namespace_pkgs(namespace):
|
| 8 |
+
parts = namespace.split(".")
|
| 9 |
+
for i in range(len(parts)):
|
| 10 |
+
yield ".".join(parts[: i + 1])
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def build_namespace_package(tmpdir, name, version="1.0", impl="pkg_resources"):
|
| 14 |
+
src_dir = tmpdir / name
|
| 15 |
+
src_dir.mkdir()
|
| 16 |
+
setup_py = src_dir / 'setup.py'
|
| 17 |
+
namespace, _, rest = name.rpartition('.')
|
| 18 |
+
namespaces = list(iter_namespace_pkgs(namespace))
|
| 19 |
+
setup_args = {
|
| 20 |
+
"name": name,
|
| 21 |
+
"version": version,
|
| 22 |
+
"packages": namespaces,
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
if impl == "pkg_resources":
|
| 26 |
+
tmpl = '__import__("pkg_resources").declare_namespace(__name__)'
|
| 27 |
+
setup_args["namespace_packages"] = namespaces
|
| 28 |
+
elif impl == "pkgutil":
|
| 29 |
+
tmpl = '__path__ = __import__("pkgutil").extend_path(__path__, __name__)'
|
| 30 |
+
else:
|
| 31 |
+
raise ValueError(f"Cannot recognise {impl=} when creating namespaces")
|
| 32 |
+
|
| 33 |
+
args = json.dumps(setup_args, indent=4)
|
| 34 |
+
assert ast.literal_eval(args) # ensure it is valid Python
|
| 35 |
+
|
| 36 |
+
script = textwrap.dedent(
|
| 37 |
+
"""\
|
| 38 |
+
import setuptools
|
| 39 |
+
args = {args}
|
| 40 |
+
setuptools.setup(**args)
|
| 41 |
+
"""
|
| 42 |
+
).format(args=args)
|
| 43 |
+
setup_py.write_text(script, encoding='utf-8')
|
| 44 |
+
|
| 45 |
+
ns_pkg_dir = Path(src_dir, namespace.replace(".", "/"))
|
| 46 |
+
ns_pkg_dir.mkdir(parents=True)
|
| 47 |
+
|
| 48 |
+
for ns in namespaces:
|
| 49 |
+
pkg_init = src_dir / ns.replace(".", "/") / '__init__.py'
|
| 50 |
+
pkg_init.write_text(tmpl, encoding='utf-8')
|
| 51 |
+
|
| 52 |
+
pkg_mod = ns_pkg_dir / (rest + '.py')
|
| 53 |
+
some_functionality = 'name = {rest!r}'.format(**locals())
|
| 54 |
+
pkg_mod.write_text(some_functionality, encoding='utf-8')
|
| 55 |
+
return src_dir
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def build_pep420_namespace_package(tmpdir, name):
|
| 59 |
+
src_dir = tmpdir / name
|
| 60 |
+
src_dir.mkdir()
|
| 61 |
+
pyproject = src_dir / "pyproject.toml"
|
| 62 |
+
namespace, _, rest = name.rpartition(".")
|
| 63 |
+
script = f"""\
|
| 64 |
+
[build-system]
|
| 65 |
+
requires = ["setuptools"]
|
| 66 |
+
build-backend = "setuptools.build_meta"
|
| 67 |
+
|
| 68 |
+
[project]
|
| 69 |
+
name = "{name}"
|
| 70 |
+
version = "3.14159"
|
| 71 |
+
"""
|
| 72 |
+
pyproject.write_text(textwrap.dedent(script), encoding='utf-8')
|
| 73 |
+
ns_pkg_dir = Path(src_dir, namespace.replace(".", "/"))
|
| 74 |
+
ns_pkg_dir.mkdir(parents=True)
|
| 75 |
+
pkg_mod = ns_pkg_dir / (rest + ".py")
|
| 76 |
+
some_functionality = f"name = {rest!r}"
|
| 77 |
+
pkg_mod.write_text(some_functionality, encoding='utf-8')
|
| 78 |
+
return src_dir
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def make_site_dir(target):
|
| 82 |
+
"""
|
| 83 |
+
Add a sitecustomize.py module in target to cause
|
| 84 |
+
target to be added to site dirs such that .pth files
|
| 85 |
+
are processed there.
|
| 86 |
+
"""
|
| 87 |
+
sc = target / 'sitecustomize.py'
|
| 88 |
+
target_str = str(target)
|
| 89 |
+
tmpl = '__import__("site").addsitedir({target_str!r})'
|
| 90 |
+
sc.write_text(tmpl.format(**locals()), encoding='utf-8')
|
valley/lib/python3.10/site-packages/setuptools/tests/script-with-bom.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
result = 'passed'
|
valley/lib/python3.10/site-packages/setuptools/tests/server.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Basic http server for tests to simulate PyPI or custom indexes"""
|
| 2 |
+
|
| 3 |
+
import http.server
|
| 4 |
+
import os
|
| 5 |
+
import threading
|
| 6 |
+
import time
|
| 7 |
+
import urllib.parse
|
| 8 |
+
import urllib.request
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class IndexServer(http.server.HTTPServer):
|
| 12 |
+
"""Basic single-threaded http server simulating a package index
|
| 13 |
+
|
| 14 |
+
You can use this server in unittest like this::
|
| 15 |
+
s = IndexServer()
|
| 16 |
+
s.start()
|
| 17 |
+
index_url = s.base_url() + 'mytestindex'
|
| 18 |
+
# do some test requests to the index
|
| 19 |
+
# The index files should be located in setuptools/tests/indexes
|
| 20 |
+
s.stop()
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
def __init__(
|
| 24 |
+
self,
|
| 25 |
+
server_address=('', 0),
|
| 26 |
+
RequestHandlerClass=http.server.SimpleHTTPRequestHandler,
|
| 27 |
+
):
|
| 28 |
+
http.server.HTTPServer.__init__(self, server_address, RequestHandlerClass)
|
| 29 |
+
self._run = True
|
| 30 |
+
|
| 31 |
+
def start(self):
|
| 32 |
+
self.thread = threading.Thread(target=self.serve_forever)
|
| 33 |
+
self.thread.start()
|
| 34 |
+
|
| 35 |
+
def stop(self):
|
| 36 |
+
"Stop the server"
|
| 37 |
+
|
| 38 |
+
# Let the server finish the last request and wait for a new one.
|
| 39 |
+
time.sleep(0.1)
|
| 40 |
+
|
| 41 |
+
self.shutdown()
|
| 42 |
+
self.thread.join()
|
| 43 |
+
self.socket.close()
|
| 44 |
+
|
| 45 |
+
def base_url(self):
|
| 46 |
+
port = self.server_port
|
| 47 |
+
return f'http://127.0.0.1:{port}/setuptools/tests/indexes/'
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class RequestRecorder(http.server.BaseHTTPRequestHandler):
|
| 51 |
+
def do_GET(self):
|
| 52 |
+
requests = vars(self.server).setdefault('requests', [])
|
| 53 |
+
requests.append(self)
|
| 54 |
+
self.send_response(200, 'OK')
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class MockServer(http.server.HTTPServer, threading.Thread):
|
| 58 |
+
"""
|
| 59 |
+
A simple HTTP Server that records the requests made to it.
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
def __init__(self, server_address=('', 0), RequestHandlerClass=RequestRecorder):
|
| 63 |
+
http.server.HTTPServer.__init__(self, server_address, RequestHandlerClass)
|
| 64 |
+
threading.Thread.__init__(self)
|
| 65 |
+
self.daemon = True
|
| 66 |
+
self.requests = []
|
| 67 |
+
|
| 68 |
+
def run(self):
|
| 69 |
+
self.serve_forever()
|
| 70 |
+
|
| 71 |
+
@property
|
| 72 |
+
def netloc(self):
|
| 73 |
+
return f'localhost:{self.server_port}'
|
| 74 |
+
|
| 75 |
+
@property
|
| 76 |
+
def url(self):
|
| 77 |
+
return f'http://{self.netloc}/'
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def path_to_url(path, authority=None):
|
| 81 |
+
"""Convert a path to a file: URL."""
|
| 82 |
+
path = os.path.normpath(os.path.abspath(path))
|
| 83 |
+
base = 'file:'
|
| 84 |
+
if authority is not None:
|
| 85 |
+
base += '//' + authority
|
| 86 |
+
return urllib.parse.urljoin(base, urllib.request.pathname2url(path))
|
valley/lib/python3.10/site-packages/setuptools/tests/test_archive_util.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import tarfile
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from setuptools import archive_util
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.fixture
|
| 10 |
+
def tarfile_with_unicode(tmpdir):
|
| 11 |
+
"""
|
| 12 |
+
Create a tarfile containing only a file whose name is
|
| 13 |
+
a zero byte file called testimäge.png.
|
| 14 |
+
"""
|
| 15 |
+
tarobj = io.BytesIO()
|
| 16 |
+
|
| 17 |
+
with tarfile.open(fileobj=tarobj, mode="w:gz") as tgz:
|
| 18 |
+
data = b""
|
| 19 |
+
|
| 20 |
+
filename = "testimäge.png"
|
| 21 |
+
|
| 22 |
+
t = tarfile.TarInfo(filename)
|
| 23 |
+
t.size = len(data)
|
| 24 |
+
|
| 25 |
+
tgz.addfile(t, io.BytesIO(data))
|
| 26 |
+
|
| 27 |
+
target = tmpdir / 'unicode-pkg-1.0.tar.gz'
|
| 28 |
+
with open(str(target), mode='wb') as tf:
|
| 29 |
+
tf.write(tarobj.getvalue())
|
| 30 |
+
return str(target)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@pytest.mark.xfail(reason="#710 and #712")
|
| 34 |
+
def test_unicode_files(tarfile_with_unicode, tmpdir):
|
| 35 |
+
target = tmpdir / 'out'
|
| 36 |
+
archive_util.unpack_archive(tarfile_with_unicode, str(target))
|
valley/lib/python3.10/site-packages/setuptools/tests/test_bdist_deprecations.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""develop tests"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from unittest import mock
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
from setuptools import SetuptoolsDeprecationWarning
|
| 9 |
+
from setuptools.dist import Distribution
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@pytest.mark.skipif(sys.platform == 'win32', reason='non-Windows only')
|
| 13 |
+
@pytest.mark.xfail(reason="bdist_rpm is long deprecated, should we remove it? #1988")
|
| 14 |
+
@mock.patch('distutils.command.bdist_rpm.bdist_rpm')
|
| 15 |
+
def test_bdist_rpm_warning(distutils_cmd, tmpdir_cwd):
|
| 16 |
+
dist = Distribution(
|
| 17 |
+
dict(
|
| 18 |
+
script_name='setup.py',
|
| 19 |
+
script_args=['bdist_rpm'],
|
| 20 |
+
name='foo',
|
| 21 |
+
py_modules=['hi'],
|
| 22 |
+
)
|
| 23 |
+
)
|
| 24 |
+
dist.parse_command_line()
|
| 25 |
+
with pytest.warns(SetuptoolsDeprecationWarning):
|
| 26 |
+
dist.run_commands()
|
| 27 |
+
|
| 28 |
+
distutils_cmd.run.assert_called_once()
|
valley/lib/python3.10/site-packages/setuptools/tests/test_bdist_egg.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""develop tests"""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import zipfile
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
from setuptools.dist import Distribution
|
| 10 |
+
|
| 11 |
+
from . import contexts
|
| 12 |
+
|
| 13 |
+
SETUP_PY = """\
|
| 14 |
+
from setuptools import setup
|
| 15 |
+
|
| 16 |
+
setup(py_modules=['hi'])
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@pytest.fixture
|
| 21 |
+
def setup_context(tmpdir):
|
| 22 |
+
with (tmpdir / 'setup.py').open('w') as f:
|
| 23 |
+
f.write(SETUP_PY)
|
| 24 |
+
with (tmpdir / 'hi.py').open('w') as f:
|
| 25 |
+
f.write('1\n')
|
| 26 |
+
with tmpdir.as_cwd():
|
| 27 |
+
yield tmpdir
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class Test:
|
| 31 |
+
@pytest.mark.usefixtures("user_override")
|
| 32 |
+
@pytest.mark.usefixtures("setup_context")
|
| 33 |
+
def test_bdist_egg(self):
|
| 34 |
+
dist = Distribution(
|
| 35 |
+
dict(
|
| 36 |
+
script_name='setup.py',
|
| 37 |
+
script_args=['bdist_egg'],
|
| 38 |
+
name='foo',
|
| 39 |
+
py_modules=['hi'],
|
| 40 |
+
)
|
| 41 |
+
)
|
| 42 |
+
os.makedirs(os.path.join('build', 'src'))
|
| 43 |
+
with contexts.quiet():
|
| 44 |
+
dist.parse_command_line()
|
| 45 |
+
dist.run_commands()
|
| 46 |
+
|
| 47 |
+
# let's see if we got our egg link at the right place
|
| 48 |
+
[content] = os.listdir('dist')
|
| 49 |
+
assert re.match(r'foo-0.0.0-py[23].\d+.egg$', content)
|
| 50 |
+
|
| 51 |
+
@pytest.mark.xfail(
|
| 52 |
+
os.environ.get('PYTHONDONTWRITEBYTECODE', False),
|
| 53 |
+
reason="Byte code disabled",
|
| 54 |
+
)
|
| 55 |
+
@pytest.mark.usefixtures("user_override")
|
| 56 |
+
@pytest.mark.usefixtures("setup_context")
|
| 57 |
+
def test_exclude_source_files(self):
|
| 58 |
+
dist = Distribution(
|
| 59 |
+
dict(
|
| 60 |
+
script_name='setup.py',
|
| 61 |
+
script_args=['bdist_egg', '--exclude-source-files'],
|
| 62 |
+
py_modules=['hi'],
|
| 63 |
+
)
|
| 64 |
+
)
|
| 65 |
+
with contexts.quiet():
|
| 66 |
+
dist.parse_command_line()
|
| 67 |
+
dist.run_commands()
|
| 68 |
+
[dist_name] = os.listdir('dist')
|
| 69 |
+
dist_filename = os.path.join('dist', dist_name)
|
| 70 |
+
zip = zipfile.ZipFile(dist_filename)
|
| 71 |
+
names = list(zi.filename for zi in zip.filelist)
|
| 72 |
+
assert 'hi.pyc' in names
|
| 73 |
+
assert 'hi.py' not in names
|
valley/lib/python3.10/site-packages/setuptools/tests/test_build.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from setuptools import Command
|
| 2 |
+
from setuptools.command.build import build
|
| 3 |
+
from setuptools.dist import Distribution
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_distribution_gives_setuptools_build_obj(tmpdir_cwd):
|
| 7 |
+
"""
|
| 8 |
+
Check that the setuptools Distribution uses the
|
| 9 |
+
setuptools specific build object.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
dist = Distribution(
|
| 13 |
+
dict(
|
| 14 |
+
script_name='setup.py',
|
| 15 |
+
script_args=['build'],
|
| 16 |
+
packages=[],
|
| 17 |
+
package_data={'': ['path/*']},
|
| 18 |
+
)
|
| 19 |
+
)
|
| 20 |
+
assert isinstance(dist.get_command_obj("build"), build)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class Subcommand(Command):
|
| 24 |
+
"""Dummy command to be used in tests"""
|
| 25 |
+
|
| 26 |
+
def initialize_options(self):
|
| 27 |
+
pass
|
| 28 |
+
|
| 29 |
+
def finalize_options(self):
|
| 30 |
+
pass
|
| 31 |
+
|
| 32 |
+
def run(self):
|
| 33 |
+
raise NotImplementedError("just to check if the command runs")
|
valley/lib/python3.10/site-packages/setuptools/tests/test_build_clib.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
from unittest import mock
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from setuptools.command.build_clib import build_clib
|
| 7 |
+
from setuptools.dist import Distribution
|
| 8 |
+
|
| 9 |
+
from distutils.errors import DistutilsSetupError
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TestBuildCLib:
|
| 13 |
+
@mock.patch('setuptools.command.build_clib.newer_pairwise_group')
|
| 14 |
+
def test_build_libraries(self, mock_newer):
|
| 15 |
+
dist = Distribution()
|
| 16 |
+
cmd = build_clib(dist)
|
| 17 |
+
|
| 18 |
+
# this will be a long section, just making sure all
|
| 19 |
+
# exceptions are properly raised
|
| 20 |
+
libs = [('example', {'sources': 'broken.c'})]
|
| 21 |
+
with pytest.raises(DistutilsSetupError):
|
| 22 |
+
cmd.build_libraries(libs)
|
| 23 |
+
|
| 24 |
+
obj_deps = 'some_string'
|
| 25 |
+
libs = [('example', {'sources': ['source.c'], 'obj_deps': obj_deps})]
|
| 26 |
+
with pytest.raises(DistutilsSetupError):
|
| 27 |
+
cmd.build_libraries(libs)
|
| 28 |
+
|
| 29 |
+
obj_deps = {'': ''}
|
| 30 |
+
libs = [('example', {'sources': ['source.c'], 'obj_deps': obj_deps})]
|
| 31 |
+
with pytest.raises(DistutilsSetupError):
|
| 32 |
+
cmd.build_libraries(libs)
|
| 33 |
+
|
| 34 |
+
obj_deps = {'source.c': ''}
|
| 35 |
+
libs = [('example', {'sources': ['source.c'], 'obj_deps': obj_deps})]
|
| 36 |
+
with pytest.raises(DistutilsSetupError):
|
| 37 |
+
cmd.build_libraries(libs)
|
| 38 |
+
|
| 39 |
+
# with that out of the way, let's see if the crude dependency
|
| 40 |
+
# system works
|
| 41 |
+
cmd.compiler = mock.MagicMock(spec=cmd.compiler)
|
| 42 |
+
mock_newer.return_value = ([], [])
|
| 43 |
+
|
| 44 |
+
obj_deps = {'': ('global.h',), 'example.c': ('example.h',)}
|
| 45 |
+
libs = [('example', {'sources': ['example.c'], 'obj_deps': obj_deps})]
|
| 46 |
+
|
| 47 |
+
cmd.build_libraries(libs)
|
| 48 |
+
assert [['example.c', 'global.h', 'example.h']] in mock_newer.call_args[0]
|
| 49 |
+
assert not cmd.compiler.compile.called
|
| 50 |
+
assert cmd.compiler.create_static_lib.call_count == 1
|
| 51 |
+
|
| 52 |
+
# reset the call numbers so we can test again
|
| 53 |
+
cmd.compiler.reset_mock()
|
| 54 |
+
|
| 55 |
+
mock_newer.return_value = '' # anything as long as it's not ([],[])
|
| 56 |
+
cmd.build_libraries(libs)
|
| 57 |
+
assert cmd.compiler.compile.call_count == 1
|
| 58 |
+
assert cmd.compiler.create_static_lib.call_count == 1
|
| 59 |
+
|
| 60 |
+
@mock.patch('setuptools.command.build_clib.newer_pairwise_group')
|
| 61 |
+
def test_build_libraries_reproducible(self, mock_newer):
|
| 62 |
+
dist = Distribution()
|
| 63 |
+
cmd = build_clib(dist)
|
| 64 |
+
|
| 65 |
+
# with that out of the way, let's see if the crude dependency
|
| 66 |
+
# system works
|
| 67 |
+
cmd.compiler = mock.MagicMock(spec=cmd.compiler)
|
| 68 |
+
mock_newer.return_value = ([], [])
|
| 69 |
+
|
| 70 |
+
original_sources = ['a-example.c', 'example.c']
|
| 71 |
+
sources = original_sources
|
| 72 |
+
|
| 73 |
+
obj_deps = {'': ('global.h',), 'example.c': ('example.h',)}
|
| 74 |
+
libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]
|
| 75 |
+
|
| 76 |
+
cmd.build_libraries(libs)
|
| 77 |
+
computed_call_args = mock_newer.call_args[0]
|
| 78 |
+
|
| 79 |
+
while sources == original_sources:
|
| 80 |
+
sources = random.sample(original_sources, len(original_sources))
|
| 81 |
+
libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]
|
| 82 |
+
|
| 83 |
+
cmd.build_libraries(libs)
|
| 84 |
+
assert computed_call_args == mock_newer.call_args[0]
|
valley/lib/python3.10/site-packages/setuptools/tests/test_build_ext.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from importlib.util import cache_from_source as _compiled_file_name
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
from jaraco import path
|
| 9 |
+
|
| 10 |
+
from setuptools.command.build_ext import build_ext, get_abi3_suffix
|
| 11 |
+
from setuptools.dist import Distribution
|
| 12 |
+
from setuptools.errors import CompileError
|
| 13 |
+
from setuptools.extension import Extension
|
| 14 |
+
|
| 15 |
+
from . import environment
|
| 16 |
+
from .textwrap import DALS
|
| 17 |
+
|
| 18 |
+
import distutils.command.build_ext as orig
|
| 19 |
+
from distutils.sysconfig import get_config_var
|
| 20 |
+
|
| 21 |
+
IS_PYPY = '__pypy__' in sys.builtin_module_names
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class TestBuildExt:
|
| 25 |
+
def test_get_ext_filename(self):
|
| 26 |
+
"""
|
| 27 |
+
Setuptools needs to give back the same
|
| 28 |
+
result as distutils, even if the fullname
|
| 29 |
+
is not in ext_map.
|
| 30 |
+
"""
|
| 31 |
+
dist = Distribution()
|
| 32 |
+
cmd = build_ext(dist)
|
| 33 |
+
cmd.ext_map['foo/bar'] = ''
|
| 34 |
+
res = cmd.get_ext_filename('foo')
|
| 35 |
+
wanted = orig.build_ext.get_ext_filename(cmd, 'foo')
|
| 36 |
+
assert res == wanted
|
| 37 |
+
|
| 38 |
+
def test_abi3_filename(self):
|
| 39 |
+
"""
|
| 40 |
+
Filename needs to be loadable by several versions
|
| 41 |
+
of Python 3 if 'is_abi3' is truthy on Extension()
|
| 42 |
+
"""
|
| 43 |
+
print(get_abi3_suffix())
|
| 44 |
+
|
| 45 |
+
extension = Extension('spam.eggs', ['eggs.c'], py_limited_api=True)
|
| 46 |
+
dist = Distribution(dict(ext_modules=[extension]))
|
| 47 |
+
cmd = build_ext(dist)
|
| 48 |
+
cmd.finalize_options()
|
| 49 |
+
assert 'spam.eggs' in cmd.ext_map
|
| 50 |
+
res = cmd.get_ext_filename('spam.eggs')
|
| 51 |
+
|
| 52 |
+
if not get_abi3_suffix():
|
| 53 |
+
assert res.endswith(get_config_var('EXT_SUFFIX'))
|
| 54 |
+
elif sys.platform == 'win32':
|
| 55 |
+
assert res.endswith('eggs.pyd')
|
| 56 |
+
else:
|
| 57 |
+
assert 'abi3' in res
|
| 58 |
+
|
| 59 |
+
def test_ext_suffix_override(self):
|
| 60 |
+
"""
|
| 61 |
+
SETUPTOOLS_EXT_SUFFIX variable always overrides
|
| 62 |
+
default extension options.
|
| 63 |
+
"""
|
| 64 |
+
dist = Distribution()
|
| 65 |
+
cmd = build_ext(dist)
|
| 66 |
+
cmd.ext_map['for_abi3'] = ext = Extension(
|
| 67 |
+
'for_abi3',
|
| 68 |
+
['s.c'],
|
| 69 |
+
# Override shouldn't affect abi3 modules
|
| 70 |
+
py_limited_api=True,
|
| 71 |
+
)
|
| 72 |
+
# Mock value needed to pass tests
|
| 73 |
+
ext._links_to_dynamic = False
|
| 74 |
+
|
| 75 |
+
if not IS_PYPY:
|
| 76 |
+
expect = cmd.get_ext_filename('for_abi3')
|
| 77 |
+
else:
|
| 78 |
+
# PyPy builds do not use ABI3 tag, so they will
|
| 79 |
+
# also get the overridden suffix.
|
| 80 |
+
expect = 'for_abi3.test-suffix'
|
| 81 |
+
|
| 82 |
+
try:
|
| 83 |
+
os.environ['SETUPTOOLS_EXT_SUFFIX'] = '.test-suffix'
|
| 84 |
+
res = cmd.get_ext_filename('normal')
|
| 85 |
+
assert 'normal.test-suffix' == res
|
| 86 |
+
res = cmd.get_ext_filename('for_abi3')
|
| 87 |
+
assert expect == res
|
| 88 |
+
finally:
|
| 89 |
+
del os.environ['SETUPTOOLS_EXT_SUFFIX']
|
| 90 |
+
|
| 91 |
+
def dist_with_example(self):
|
| 92 |
+
files = {
|
| 93 |
+
"src": {"mypkg": {"subpkg": {"ext2.c": ""}}},
|
| 94 |
+
"c-extensions": {"ext1": {"main.c": ""}},
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
ext1 = Extension("mypkg.ext1", ["c-extensions/ext1/main.c"])
|
| 98 |
+
ext2 = Extension("mypkg.subpkg.ext2", ["src/mypkg/subpkg/ext2.c"])
|
| 99 |
+
ext3 = Extension("ext3", ["c-extension/ext3.c"])
|
| 100 |
+
|
| 101 |
+
path.build(files)
|
| 102 |
+
return Distribution({
|
| 103 |
+
"script_name": "%test%",
|
| 104 |
+
"ext_modules": [ext1, ext2, ext3],
|
| 105 |
+
"package_dir": {"": "src"},
|
| 106 |
+
})
|
| 107 |
+
|
| 108 |
+
def test_get_outputs(self, tmpdir_cwd, monkeypatch):
|
| 109 |
+
monkeypatch.setenv('SETUPTOOLS_EXT_SUFFIX', '.mp3') # make test OS-independent
|
| 110 |
+
monkeypatch.setattr('setuptools.command.build_ext.use_stubs', False)
|
| 111 |
+
dist = self.dist_with_example()
|
| 112 |
+
|
| 113 |
+
# Regular build: get_outputs not empty, but get_output_mappings is empty
|
| 114 |
+
build_ext = dist.get_command_obj("build_ext")
|
| 115 |
+
build_ext.editable_mode = False
|
| 116 |
+
build_ext.ensure_finalized()
|
| 117 |
+
build_lib = build_ext.build_lib.replace(os.sep, "/")
|
| 118 |
+
outputs = [x.replace(os.sep, "/") for x in build_ext.get_outputs()]
|
| 119 |
+
assert outputs == [
|
| 120 |
+
f"{build_lib}/ext3.mp3",
|
| 121 |
+
f"{build_lib}/mypkg/ext1.mp3",
|
| 122 |
+
f"{build_lib}/mypkg/subpkg/ext2.mp3",
|
| 123 |
+
]
|
| 124 |
+
assert build_ext.get_output_mapping() == {}
|
| 125 |
+
|
| 126 |
+
# Editable build: get_output_mappings should contain everything in get_outputs
|
| 127 |
+
dist.reinitialize_command("build_ext")
|
| 128 |
+
build_ext.editable_mode = True
|
| 129 |
+
build_ext.ensure_finalized()
|
| 130 |
+
mapping = {
|
| 131 |
+
k.replace(os.sep, "/"): v.replace(os.sep, "/")
|
| 132 |
+
for k, v in build_ext.get_output_mapping().items()
|
| 133 |
+
}
|
| 134 |
+
assert mapping == {
|
| 135 |
+
f"{build_lib}/ext3.mp3": "src/ext3.mp3",
|
| 136 |
+
f"{build_lib}/mypkg/ext1.mp3": "src/mypkg/ext1.mp3",
|
| 137 |
+
f"{build_lib}/mypkg/subpkg/ext2.mp3": "src/mypkg/subpkg/ext2.mp3",
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
def test_get_output_mapping_with_stub(self, tmpdir_cwd, monkeypatch):
|
| 141 |
+
monkeypatch.setenv('SETUPTOOLS_EXT_SUFFIX', '.mp3') # make test OS-independent
|
| 142 |
+
monkeypatch.setattr('setuptools.command.build_ext.use_stubs', True)
|
| 143 |
+
dist = self.dist_with_example()
|
| 144 |
+
|
| 145 |
+
# Editable build should create compiled stubs (.pyc files only, no .py)
|
| 146 |
+
build_ext = dist.get_command_obj("build_ext")
|
| 147 |
+
build_ext.editable_mode = True
|
| 148 |
+
build_ext.ensure_finalized()
|
| 149 |
+
for ext in build_ext.extensions:
|
| 150 |
+
monkeypatch.setattr(ext, "_needs_stub", True)
|
| 151 |
+
|
| 152 |
+
build_lib = build_ext.build_lib.replace(os.sep, "/")
|
| 153 |
+
mapping = {
|
| 154 |
+
k.replace(os.sep, "/"): v.replace(os.sep, "/")
|
| 155 |
+
for k, v in build_ext.get_output_mapping().items()
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
def C(file):
|
| 159 |
+
"""Make it possible to do comparisons and tests in a OS-independent way"""
|
| 160 |
+
return _compiled_file_name(file).replace(os.sep, "/")
|
| 161 |
+
|
| 162 |
+
assert mapping == {
|
| 163 |
+
C(f"{build_lib}/ext3.py"): C("src/ext3.py"),
|
| 164 |
+
f"{build_lib}/ext3.mp3": "src/ext3.mp3",
|
| 165 |
+
C(f"{build_lib}/mypkg/ext1.py"): C("src/mypkg/ext1.py"),
|
| 166 |
+
f"{build_lib}/mypkg/ext1.mp3": "src/mypkg/ext1.mp3",
|
| 167 |
+
C(f"{build_lib}/mypkg/subpkg/ext2.py"): C("src/mypkg/subpkg/ext2.py"),
|
| 168 |
+
f"{build_lib}/mypkg/subpkg/ext2.mp3": "src/mypkg/subpkg/ext2.mp3",
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
# Ensure only the compiled stubs are present not the raw .py stub
|
| 172 |
+
assert f"{build_lib}/mypkg/ext1.py" not in mapping
|
| 173 |
+
assert f"{build_lib}/mypkg/subpkg/ext2.py" not in mapping
|
| 174 |
+
|
| 175 |
+
# Visualize what the cached stub files look like
|
| 176 |
+
example_stub = C(f"{build_lib}/mypkg/ext1.py")
|
| 177 |
+
assert example_stub in mapping
|
| 178 |
+
assert example_stub.startswith(f"{build_lib}/mypkg/__pycache__/ext1")
|
| 179 |
+
assert example_stub.endswith(".pyc")
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
class TestBuildExtInplace:
|
| 183 |
+
def get_build_ext_cmd(self, optional: bool, **opts) -> build_ext:
|
| 184 |
+
files: dict[str, str | dict[str, dict[str, str]]] = {
|
| 185 |
+
"eggs.c": "#include missingheader.h\n",
|
| 186 |
+
".build": {"lib": {}, "tmp": {}},
|
| 187 |
+
}
|
| 188 |
+
path.build(files)
|
| 189 |
+
extension = Extension('spam.eggs', ['eggs.c'], optional=optional)
|
| 190 |
+
dist = Distribution(dict(ext_modules=[extension]))
|
| 191 |
+
dist.script_name = 'setup.py'
|
| 192 |
+
cmd = build_ext(dist)
|
| 193 |
+
vars(cmd).update(build_lib=".build/lib", build_temp=".build/tmp", **opts)
|
| 194 |
+
cmd.ensure_finalized()
|
| 195 |
+
return cmd
|
| 196 |
+
|
| 197 |
+
def get_log_messages(self, caplog, capsys):
|
| 198 |
+
"""
|
| 199 |
+
Historically, distutils "logged" by printing to sys.std*.
|
| 200 |
+
Later versions adopted the logging framework. Grab
|
| 201 |
+
messages regardless of how they were captured.
|
| 202 |
+
"""
|
| 203 |
+
std = capsys.readouterr()
|
| 204 |
+
return std.out.splitlines() + std.err.splitlines() + caplog.messages
|
| 205 |
+
|
| 206 |
+
def test_optional(self, tmpdir_cwd, caplog, capsys):
|
| 207 |
+
"""
|
| 208 |
+
If optional extensions fail to build, setuptools should show the error
|
| 209 |
+
in the logs but not fail to build
|
| 210 |
+
"""
|
| 211 |
+
cmd = self.get_build_ext_cmd(optional=True, inplace=True)
|
| 212 |
+
cmd.run()
|
| 213 |
+
assert any(
|
| 214 |
+
'build_ext: building extension "spam.eggs" failed'
|
| 215 |
+
for msg in self.get_log_messages(caplog, capsys)
|
| 216 |
+
)
|
| 217 |
+
# No compile error exception should be raised
|
| 218 |
+
|
| 219 |
+
def test_non_optional(self, tmpdir_cwd):
|
| 220 |
+
# Non-optional extensions should raise an exception
|
| 221 |
+
cmd = self.get_build_ext_cmd(optional=False, inplace=True)
|
| 222 |
+
with pytest.raises(CompileError):
|
| 223 |
+
cmd.run()
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def test_build_ext_config_handling(tmpdir_cwd):
|
| 227 |
+
files = {
|
| 228 |
+
'setup.py': DALS(
|
| 229 |
+
"""
|
| 230 |
+
from setuptools import Extension, setup
|
| 231 |
+
setup(
|
| 232 |
+
name='foo',
|
| 233 |
+
version='0.0.0',
|
| 234 |
+
ext_modules=[Extension('foo', ['foo.c'])],
|
| 235 |
+
)
|
| 236 |
+
"""
|
| 237 |
+
),
|
| 238 |
+
'foo.c': DALS(
|
| 239 |
+
"""
|
| 240 |
+
#include "Python.h"
|
| 241 |
+
|
| 242 |
+
#if PY_MAJOR_VERSION >= 3
|
| 243 |
+
|
| 244 |
+
static struct PyModuleDef moduledef = {
|
| 245 |
+
PyModuleDef_HEAD_INIT,
|
| 246 |
+
"foo",
|
| 247 |
+
NULL,
|
| 248 |
+
0,
|
| 249 |
+
NULL,
|
| 250 |
+
NULL,
|
| 251 |
+
NULL,
|
| 252 |
+
NULL,
|
| 253 |
+
NULL
|
| 254 |
+
};
|
| 255 |
+
|
| 256 |
+
#define INITERROR return NULL
|
| 257 |
+
|
| 258 |
+
PyMODINIT_FUNC PyInit_foo(void)
|
| 259 |
+
|
| 260 |
+
#else
|
| 261 |
+
|
| 262 |
+
#define INITERROR return
|
| 263 |
+
|
| 264 |
+
void initfoo(void)
|
| 265 |
+
|
| 266 |
+
#endif
|
| 267 |
+
{
|
| 268 |
+
#if PY_MAJOR_VERSION >= 3
|
| 269 |
+
PyObject *module = PyModule_Create(&moduledef);
|
| 270 |
+
#else
|
| 271 |
+
PyObject *module = Py_InitModule("extension", NULL);
|
| 272 |
+
#endif
|
| 273 |
+
if (module == NULL)
|
| 274 |
+
INITERROR;
|
| 275 |
+
#if PY_MAJOR_VERSION >= 3
|
| 276 |
+
return module;
|
| 277 |
+
#endif
|
| 278 |
+
}
|
| 279 |
+
"""
|
| 280 |
+
),
|
| 281 |
+
'setup.cfg': DALS(
|
| 282 |
+
"""
|
| 283 |
+
[build]
|
| 284 |
+
build_base = foo_build
|
| 285 |
+
"""
|
| 286 |
+
),
|
| 287 |
+
}
|
| 288 |
+
path.build(files)
|
| 289 |
+
code, (stdout, stderr) = environment.run_setup_py(
|
| 290 |
+
cmd=['build'],
|
| 291 |
+
data_stream=(0, 2),
|
| 292 |
+
)
|
| 293 |
+
assert code == 0, f'\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}'
|
valley/lib/python3.10/site-packages/setuptools/tests/test_build_meta.py
ADDED
|
@@ -0,0 +1,970 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
import re
|
| 5 |
+
import shutil
|
| 6 |
+
import signal
|
| 7 |
+
import sys
|
| 8 |
+
import tarfile
|
| 9 |
+
from concurrent import futures
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any, Callable
|
| 12 |
+
from zipfile import ZipFile
|
| 13 |
+
|
| 14 |
+
import pytest
|
| 15 |
+
from jaraco import path
|
| 16 |
+
from packaging.requirements import Requirement
|
| 17 |
+
|
| 18 |
+
from .textwrap import DALS
|
| 19 |
+
|
| 20 |
+
SETUP_SCRIPT_STUB = "__import__('setuptools').setup()"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
TIMEOUT = int(os.getenv("TIMEOUT_BACKEND_TEST", "180")) # in seconds
|
| 24 |
+
IS_PYPY = '__pypy__' in sys.builtin_module_names
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
pytestmark = pytest.mark.skipif(
|
| 28 |
+
sys.platform == "win32" and IS_PYPY,
|
| 29 |
+
reason="The combination of PyPy + Windows + pytest-xdist + ProcessPoolExecutor "
|
| 30 |
+
"is flaky and problematic",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class BuildBackendBase:
|
| 35 |
+
def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta'):
|
| 36 |
+
self.cwd = cwd
|
| 37 |
+
self.env = env or {}
|
| 38 |
+
self.backend_name = backend_name
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class BuildBackend(BuildBackendBase):
|
| 42 |
+
"""PEP 517 Build Backend"""
|
| 43 |
+
|
| 44 |
+
def __init__(self, *args, **kwargs):
|
| 45 |
+
super().__init__(*args, **kwargs)
|
| 46 |
+
self.pool = futures.ProcessPoolExecutor(max_workers=1)
|
| 47 |
+
|
| 48 |
+
def __getattr__(self, name: str) -> Callable[..., Any]:
|
| 49 |
+
"""Handles arbitrary function invocations on the build backend."""
|
| 50 |
+
|
| 51 |
+
def method(*args, **kw):
|
| 52 |
+
root = os.path.abspath(self.cwd)
|
| 53 |
+
caller = BuildBackendCaller(root, self.env, self.backend_name)
|
| 54 |
+
pid = None
|
| 55 |
+
try:
|
| 56 |
+
pid = self.pool.submit(os.getpid).result(TIMEOUT)
|
| 57 |
+
return self.pool.submit(caller, name, *args, **kw).result(TIMEOUT)
|
| 58 |
+
except futures.TimeoutError:
|
| 59 |
+
self.pool.shutdown(wait=False) # doesn't stop already running processes
|
| 60 |
+
self._kill(pid)
|
| 61 |
+
pytest.xfail(f"Backend did not respond before timeout ({TIMEOUT} s)")
|
| 62 |
+
except (futures.process.BrokenProcessPool, MemoryError, OSError):
|
| 63 |
+
if IS_PYPY:
|
| 64 |
+
pytest.xfail("PyPy frequently fails tests with ProcessPoolExector")
|
| 65 |
+
raise
|
| 66 |
+
|
| 67 |
+
return method
|
| 68 |
+
|
| 69 |
+
def _kill(self, pid):
|
| 70 |
+
if pid is None:
|
| 71 |
+
return
|
| 72 |
+
with contextlib.suppress(ProcessLookupError, OSError):
|
| 73 |
+
os.kill(pid, signal.SIGTERM if os.name == "nt" else signal.SIGKILL)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class BuildBackendCaller(BuildBackendBase):
|
| 77 |
+
def __init__(self, *args, **kwargs):
|
| 78 |
+
super().__init__(*args, **kwargs)
|
| 79 |
+
|
| 80 |
+
(self.backend_name, _, self.backend_obj) = self.backend_name.partition(':')
|
| 81 |
+
|
| 82 |
+
def __call__(self, name, *args, **kw):
|
| 83 |
+
"""Handles arbitrary function invocations on the build backend."""
|
| 84 |
+
os.chdir(self.cwd)
|
| 85 |
+
os.environ.update(self.env)
|
| 86 |
+
mod = importlib.import_module(self.backend_name)
|
| 87 |
+
|
| 88 |
+
if self.backend_obj:
|
| 89 |
+
backend = getattr(mod, self.backend_obj)
|
| 90 |
+
else:
|
| 91 |
+
backend = mod
|
| 92 |
+
|
| 93 |
+
return getattr(backend, name)(*args, **kw)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
defns = [
|
| 97 |
+
{ # simple setup.py script
|
| 98 |
+
'setup.py': DALS(
|
| 99 |
+
"""
|
| 100 |
+
__import__('setuptools').setup(
|
| 101 |
+
name='foo',
|
| 102 |
+
version='0.0.0',
|
| 103 |
+
py_modules=['hello'],
|
| 104 |
+
setup_requires=['six'],
|
| 105 |
+
)
|
| 106 |
+
"""
|
| 107 |
+
),
|
| 108 |
+
'hello.py': DALS(
|
| 109 |
+
"""
|
| 110 |
+
def run():
|
| 111 |
+
print('hello')
|
| 112 |
+
"""
|
| 113 |
+
),
|
| 114 |
+
},
|
| 115 |
+
{ # setup.py that relies on __name__
|
| 116 |
+
'setup.py': DALS(
|
| 117 |
+
"""
|
| 118 |
+
assert __name__ == '__main__'
|
| 119 |
+
__import__('setuptools').setup(
|
| 120 |
+
name='foo',
|
| 121 |
+
version='0.0.0',
|
| 122 |
+
py_modules=['hello'],
|
| 123 |
+
setup_requires=['six'],
|
| 124 |
+
)
|
| 125 |
+
"""
|
| 126 |
+
),
|
| 127 |
+
'hello.py': DALS(
|
| 128 |
+
"""
|
| 129 |
+
def run():
|
| 130 |
+
print('hello')
|
| 131 |
+
"""
|
| 132 |
+
),
|
| 133 |
+
},
|
| 134 |
+
{ # setup.py script that runs arbitrary code
|
| 135 |
+
'setup.py': DALS(
|
| 136 |
+
"""
|
| 137 |
+
variable = True
|
| 138 |
+
def function():
|
| 139 |
+
return variable
|
| 140 |
+
assert variable
|
| 141 |
+
__import__('setuptools').setup(
|
| 142 |
+
name='foo',
|
| 143 |
+
version='0.0.0',
|
| 144 |
+
py_modules=['hello'],
|
| 145 |
+
setup_requires=['six'],
|
| 146 |
+
)
|
| 147 |
+
"""
|
| 148 |
+
),
|
| 149 |
+
'hello.py': DALS(
|
| 150 |
+
"""
|
| 151 |
+
def run():
|
| 152 |
+
print('hello')
|
| 153 |
+
"""
|
| 154 |
+
),
|
| 155 |
+
},
|
| 156 |
+
{ # setup.py script that constructs temp files to be included in the distribution
|
| 157 |
+
'setup.py': DALS(
|
| 158 |
+
"""
|
| 159 |
+
# Some packages construct files on the fly, include them in the package,
|
| 160 |
+
# and immediately remove them after `setup()` (e.g. pybind11==2.9.1).
|
| 161 |
+
# Therefore, we cannot use `distutils.core.run_setup(..., stop_after=...)`
|
| 162 |
+
# to obtain a distribution object first, and then run the distutils
|
| 163 |
+
# commands later, because these files will be removed in the meantime.
|
| 164 |
+
|
| 165 |
+
with open('world.py', 'w', encoding="utf-8") as f:
|
| 166 |
+
f.write('x = 42')
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
__import__('setuptools').setup(
|
| 170 |
+
name='foo',
|
| 171 |
+
version='0.0.0',
|
| 172 |
+
py_modules=['world'],
|
| 173 |
+
setup_requires=['six'],
|
| 174 |
+
)
|
| 175 |
+
finally:
|
| 176 |
+
# Some packages will clean temporary files
|
| 177 |
+
__import__('os').unlink('world.py')
|
| 178 |
+
"""
|
| 179 |
+
),
|
| 180 |
+
},
|
| 181 |
+
{ # setup.cfg only
|
| 182 |
+
'setup.cfg': DALS(
|
| 183 |
+
"""
|
| 184 |
+
[metadata]
|
| 185 |
+
name = foo
|
| 186 |
+
version = 0.0.0
|
| 187 |
+
|
| 188 |
+
[options]
|
| 189 |
+
py_modules=hello
|
| 190 |
+
setup_requires=six
|
| 191 |
+
"""
|
| 192 |
+
),
|
| 193 |
+
'hello.py': DALS(
|
| 194 |
+
"""
|
| 195 |
+
def run():
|
| 196 |
+
print('hello')
|
| 197 |
+
"""
|
| 198 |
+
),
|
| 199 |
+
},
|
| 200 |
+
{ # setup.cfg and setup.py
|
| 201 |
+
'setup.cfg': DALS(
|
| 202 |
+
"""
|
| 203 |
+
[metadata]
|
| 204 |
+
name = foo
|
| 205 |
+
version = 0.0.0
|
| 206 |
+
|
| 207 |
+
[options]
|
| 208 |
+
py_modules=hello
|
| 209 |
+
setup_requires=six
|
| 210 |
+
"""
|
| 211 |
+
),
|
| 212 |
+
'setup.py': "__import__('setuptools').setup()",
|
| 213 |
+
'hello.py': DALS(
|
| 214 |
+
"""
|
| 215 |
+
def run():
|
| 216 |
+
print('hello')
|
| 217 |
+
"""
|
| 218 |
+
),
|
| 219 |
+
},
|
| 220 |
+
]
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
class TestBuildMetaBackend:
|
| 224 |
+
backend_name = 'setuptools.build_meta'
|
| 225 |
+
|
| 226 |
+
def get_build_backend(self):
|
| 227 |
+
return BuildBackend(backend_name=self.backend_name)
|
| 228 |
+
|
| 229 |
+
@pytest.fixture(params=defns)
|
| 230 |
+
def build_backend(self, tmpdir, request):
|
| 231 |
+
path.build(request.param, prefix=str(tmpdir))
|
| 232 |
+
with tmpdir.as_cwd():
|
| 233 |
+
yield self.get_build_backend()
|
| 234 |
+
|
| 235 |
+
def test_get_requires_for_build_wheel(self, build_backend):
|
| 236 |
+
actual = build_backend.get_requires_for_build_wheel()
|
| 237 |
+
expected = ['six']
|
| 238 |
+
assert sorted(actual) == sorted(expected)
|
| 239 |
+
|
| 240 |
+
def test_get_requires_for_build_sdist(self, build_backend):
|
| 241 |
+
actual = build_backend.get_requires_for_build_sdist()
|
| 242 |
+
expected = ['six']
|
| 243 |
+
assert sorted(actual) == sorted(expected)
|
| 244 |
+
|
| 245 |
+
def test_build_wheel(self, build_backend):
|
| 246 |
+
dist_dir = os.path.abspath('pip-wheel')
|
| 247 |
+
os.makedirs(dist_dir)
|
| 248 |
+
wheel_name = build_backend.build_wheel(dist_dir)
|
| 249 |
+
|
| 250 |
+
wheel_file = os.path.join(dist_dir, wheel_name)
|
| 251 |
+
assert os.path.isfile(wheel_file)
|
| 252 |
+
|
| 253 |
+
# Temporary files should be removed
|
| 254 |
+
assert not os.path.isfile('world.py')
|
| 255 |
+
|
| 256 |
+
with ZipFile(wheel_file) as zipfile:
|
| 257 |
+
wheel_contents = set(zipfile.namelist())
|
| 258 |
+
|
| 259 |
+
# Each one of the examples have a single module
|
| 260 |
+
# that should be included in the distribution
|
| 261 |
+
python_scripts = (f for f in wheel_contents if f.endswith('.py'))
|
| 262 |
+
modules = [f for f in python_scripts if not f.endswith('setup.py')]
|
| 263 |
+
assert len(modules) == 1
|
| 264 |
+
|
| 265 |
+
@pytest.mark.parametrize('build_type', ('wheel', 'sdist'))
|
| 266 |
+
def test_build_with_existing_file_present(self, build_type, tmpdir_cwd):
|
| 267 |
+
# Building a sdist/wheel should still succeed if there's
|
| 268 |
+
# already a sdist/wheel in the destination directory.
|
| 269 |
+
files = {
|
| 270 |
+
'setup.py': "from setuptools import setup\nsetup()",
|
| 271 |
+
'VERSION': "0.0.1",
|
| 272 |
+
'setup.cfg': DALS(
|
| 273 |
+
"""
|
| 274 |
+
[metadata]
|
| 275 |
+
name = foo
|
| 276 |
+
version = file: VERSION
|
| 277 |
+
"""
|
| 278 |
+
),
|
| 279 |
+
'pyproject.toml': DALS(
|
| 280 |
+
"""
|
| 281 |
+
[build-system]
|
| 282 |
+
requires = ["setuptools", "wheel"]
|
| 283 |
+
build-backend = "setuptools.build_meta"
|
| 284 |
+
"""
|
| 285 |
+
),
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
path.build(files)
|
| 289 |
+
|
| 290 |
+
dist_dir = os.path.abspath('preexisting-' + build_type)
|
| 291 |
+
|
| 292 |
+
build_backend = self.get_build_backend()
|
| 293 |
+
build_method = getattr(build_backend, 'build_' + build_type)
|
| 294 |
+
|
| 295 |
+
# Build a first sdist/wheel.
|
| 296 |
+
# Note: this also check the destination directory is
|
| 297 |
+
# successfully created if it does not exist already.
|
| 298 |
+
first_result = build_method(dist_dir)
|
| 299 |
+
|
| 300 |
+
# Change version.
|
| 301 |
+
with open("VERSION", "wt", encoding="utf-8") as version_file:
|
| 302 |
+
version_file.write("0.0.2")
|
| 303 |
+
|
| 304 |
+
# Build a *second* sdist/wheel.
|
| 305 |
+
second_result = build_method(dist_dir)
|
| 306 |
+
|
| 307 |
+
assert os.path.isfile(os.path.join(dist_dir, first_result))
|
| 308 |
+
assert first_result != second_result
|
| 309 |
+
|
| 310 |
+
# And if rebuilding the exact same sdist/wheel?
|
| 311 |
+
open(os.path.join(dist_dir, second_result), 'wb').close()
|
| 312 |
+
third_result = build_method(dist_dir)
|
| 313 |
+
assert third_result == second_result
|
| 314 |
+
assert os.path.getsize(os.path.join(dist_dir, third_result)) > 0
|
| 315 |
+
|
| 316 |
+
@pytest.mark.parametrize("setup_script", [None, SETUP_SCRIPT_STUB])
|
| 317 |
+
def test_build_with_pyproject_config(self, tmpdir, setup_script):
|
| 318 |
+
files = {
|
| 319 |
+
'pyproject.toml': DALS(
|
| 320 |
+
"""
|
| 321 |
+
[build-system]
|
| 322 |
+
requires = ["setuptools", "wheel"]
|
| 323 |
+
build-backend = "setuptools.build_meta"
|
| 324 |
+
|
| 325 |
+
[project]
|
| 326 |
+
name = "foo"
|
| 327 |
+
license = {text = "MIT"}
|
| 328 |
+
description = "This is a Python package"
|
| 329 |
+
dynamic = ["version", "readme"]
|
| 330 |
+
classifiers = [
|
| 331 |
+
"Development Status :: 5 - Production/Stable",
|
| 332 |
+
"Intended Audience :: Developers"
|
| 333 |
+
]
|
| 334 |
+
urls = {Homepage = "http://github.com"}
|
| 335 |
+
dependencies = [
|
| 336 |
+
"appdirs",
|
| 337 |
+
]
|
| 338 |
+
|
| 339 |
+
[project.optional-dependencies]
|
| 340 |
+
all = [
|
| 341 |
+
"tomli>=1",
|
| 342 |
+
"pyscaffold>=4,<5",
|
| 343 |
+
'importlib; python_version == "2.6"',
|
| 344 |
+
]
|
| 345 |
+
|
| 346 |
+
[project.scripts]
|
| 347 |
+
foo = "foo.cli:main"
|
| 348 |
+
|
| 349 |
+
[tool.setuptools]
|
| 350 |
+
zip-safe = false
|
| 351 |
+
package-dir = {"" = "src"}
|
| 352 |
+
packages = {find = {where = ["src"]}}
|
| 353 |
+
license-files = ["LICENSE*"]
|
| 354 |
+
|
| 355 |
+
[tool.setuptools.dynamic]
|
| 356 |
+
version = {attr = "foo.__version__"}
|
| 357 |
+
readme = {file = "README.rst"}
|
| 358 |
+
|
| 359 |
+
[tool.distutils.sdist]
|
| 360 |
+
formats = "gztar"
|
| 361 |
+
"""
|
| 362 |
+
),
|
| 363 |
+
"MANIFEST.in": DALS(
|
| 364 |
+
"""
|
| 365 |
+
global-include *.py *.txt
|
| 366 |
+
global-exclude *.py[cod]
|
| 367 |
+
"""
|
| 368 |
+
),
|
| 369 |
+
"README.rst": "This is a ``README``",
|
| 370 |
+
"LICENSE.txt": "---- placeholder MIT license ----",
|
| 371 |
+
"src": {
|
| 372 |
+
"foo": {
|
| 373 |
+
"__init__.py": "__version__ = '0.1'",
|
| 374 |
+
"__init__.pyi": "__version__: str",
|
| 375 |
+
"cli.py": "def main(): print('hello world')",
|
| 376 |
+
"data.txt": "def main(): print('hello world')",
|
| 377 |
+
"py.typed": "",
|
| 378 |
+
}
|
| 379 |
+
},
|
| 380 |
+
}
|
| 381 |
+
if setup_script:
|
| 382 |
+
files["setup.py"] = setup_script
|
| 383 |
+
|
| 384 |
+
build_backend = self.get_build_backend()
|
| 385 |
+
with tmpdir.as_cwd():
|
| 386 |
+
path.build(files)
|
| 387 |
+
sdist_path = build_backend.build_sdist("temp")
|
| 388 |
+
wheel_file = build_backend.build_wheel("temp")
|
| 389 |
+
|
| 390 |
+
with tarfile.open(os.path.join(tmpdir, "temp", sdist_path)) as tar:
|
| 391 |
+
sdist_contents = set(tar.getnames())
|
| 392 |
+
|
| 393 |
+
with ZipFile(os.path.join(tmpdir, "temp", wheel_file)) as zipfile:
|
| 394 |
+
wheel_contents = set(zipfile.namelist())
|
| 395 |
+
metadata = str(zipfile.read("foo-0.1.dist-info/METADATA"), "utf-8")
|
| 396 |
+
license = str(zipfile.read("foo-0.1.dist-info/LICENSE.txt"), "utf-8")
|
| 397 |
+
epoints = str(zipfile.read("foo-0.1.dist-info/entry_points.txt"), "utf-8")
|
| 398 |
+
|
| 399 |
+
assert sdist_contents - {"foo-0.1/setup.py"} == {
|
| 400 |
+
'foo-0.1',
|
| 401 |
+
'foo-0.1/LICENSE.txt',
|
| 402 |
+
'foo-0.1/MANIFEST.in',
|
| 403 |
+
'foo-0.1/PKG-INFO',
|
| 404 |
+
'foo-0.1/README.rst',
|
| 405 |
+
'foo-0.1/pyproject.toml',
|
| 406 |
+
'foo-0.1/setup.cfg',
|
| 407 |
+
'foo-0.1/src',
|
| 408 |
+
'foo-0.1/src/foo',
|
| 409 |
+
'foo-0.1/src/foo/__init__.py',
|
| 410 |
+
'foo-0.1/src/foo/__init__.pyi',
|
| 411 |
+
'foo-0.1/src/foo/cli.py',
|
| 412 |
+
'foo-0.1/src/foo/data.txt',
|
| 413 |
+
'foo-0.1/src/foo/py.typed',
|
| 414 |
+
'foo-0.1/src/foo.egg-info',
|
| 415 |
+
'foo-0.1/src/foo.egg-info/PKG-INFO',
|
| 416 |
+
'foo-0.1/src/foo.egg-info/SOURCES.txt',
|
| 417 |
+
'foo-0.1/src/foo.egg-info/dependency_links.txt',
|
| 418 |
+
'foo-0.1/src/foo.egg-info/entry_points.txt',
|
| 419 |
+
'foo-0.1/src/foo.egg-info/requires.txt',
|
| 420 |
+
'foo-0.1/src/foo.egg-info/top_level.txt',
|
| 421 |
+
'foo-0.1/src/foo.egg-info/not-zip-safe',
|
| 422 |
+
}
|
| 423 |
+
assert wheel_contents == {
|
| 424 |
+
"foo/__init__.py",
|
| 425 |
+
"foo/__init__.pyi", # include type information by default
|
| 426 |
+
"foo/cli.py",
|
| 427 |
+
"foo/data.txt", # include_package_data defaults to True
|
| 428 |
+
"foo/py.typed", # include type information by default
|
| 429 |
+
"foo-0.1.dist-info/LICENSE.txt",
|
| 430 |
+
"foo-0.1.dist-info/METADATA",
|
| 431 |
+
"foo-0.1.dist-info/WHEEL",
|
| 432 |
+
"foo-0.1.dist-info/entry_points.txt",
|
| 433 |
+
"foo-0.1.dist-info/top_level.txt",
|
| 434 |
+
"foo-0.1.dist-info/RECORD",
|
| 435 |
+
}
|
| 436 |
+
assert license == "---- placeholder MIT license ----"
|
| 437 |
+
|
| 438 |
+
for line in (
|
| 439 |
+
"Summary: This is a Python package",
|
| 440 |
+
"License: MIT",
|
| 441 |
+
"Classifier: Intended Audience :: Developers",
|
| 442 |
+
"Requires-Dist: appdirs",
|
| 443 |
+
"Requires-Dist: " + str(Requirement('tomli>=1 ; extra == "all"')),
|
| 444 |
+
"Requires-Dist: "
|
| 445 |
+
+ str(Requirement('importlib; python_version=="2.6" and extra =="all"')),
|
| 446 |
+
):
|
| 447 |
+
assert line in metadata, (line, metadata)
|
| 448 |
+
|
| 449 |
+
assert metadata.strip().endswith("This is a ``README``")
|
| 450 |
+
assert epoints.strip() == "[console_scripts]\nfoo = foo.cli:main"
|
| 451 |
+
|
| 452 |
+
def test_static_metadata_in_pyproject_config(self, tmpdir):
|
| 453 |
+
# Make sure static metadata in pyproject.toml is not overwritten by setup.py
|
| 454 |
+
# as required by PEP 621
|
| 455 |
+
files = {
|
| 456 |
+
'pyproject.toml': DALS(
|
| 457 |
+
"""
|
| 458 |
+
[build-system]
|
| 459 |
+
requires = ["setuptools", "wheel"]
|
| 460 |
+
build-backend = "setuptools.build_meta"
|
| 461 |
+
|
| 462 |
+
[project]
|
| 463 |
+
name = "foo"
|
| 464 |
+
description = "This is a Python package"
|
| 465 |
+
version = "42"
|
| 466 |
+
dependencies = ["six"]
|
| 467 |
+
"""
|
| 468 |
+
),
|
| 469 |
+
'hello.py': DALS(
|
| 470 |
+
"""
|
| 471 |
+
def run():
|
| 472 |
+
print('hello')
|
| 473 |
+
"""
|
| 474 |
+
),
|
| 475 |
+
'setup.py': DALS(
|
| 476 |
+
"""
|
| 477 |
+
__import__('setuptools').setup(
|
| 478 |
+
name='bar',
|
| 479 |
+
version='13',
|
| 480 |
+
)
|
| 481 |
+
"""
|
| 482 |
+
),
|
| 483 |
+
}
|
| 484 |
+
build_backend = self.get_build_backend()
|
| 485 |
+
with tmpdir.as_cwd():
|
| 486 |
+
path.build(files)
|
| 487 |
+
sdist_path = build_backend.build_sdist("temp")
|
| 488 |
+
wheel_file = build_backend.build_wheel("temp")
|
| 489 |
+
|
| 490 |
+
assert (tmpdir / "temp/foo-42.tar.gz").exists()
|
| 491 |
+
assert (tmpdir / "temp/foo-42-py3-none-any.whl").exists()
|
| 492 |
+
assert not (tmpdir / "temp/bar-13.tar.gz").exists()
|
| 493 |
+
assert not (tmpdir / "temp/bar-42.tar.gz").exists()
|
| 494 |
+
assert not (tmpdir / "temp/foo-13.tar.gz").exists()
|
| 495 |
+
assert not (tmpdir / "temp/bar-13-py3-none-any.whl").exists()
|
| 496 |
+
assert not (tmpdir / "temp/bar-42-py3-none-any.whl").exists()
|
| 497 |
+
assert not (tmpdir / "temp/foo-13-py3-none-any.whl").exists()
|
| 498 |
+
|
| 499 |
+
with tarfile.open(os.path.join(tmpdir, "temp", sdist_path)) as tar:
|
| 500 |
+
pkg_info = str(tar.extractfile('foo-42/PKG-INFO').read(), "utf-8")
|
| 501 |
+
members = tar.getnames()
|
| 502 |
+
assert "bar-13/PKG-INFO" not in members
|
| 503 |
+
|
| 504 |
+
with ZipFile(os.path.join(tmpdir, "temp", wheel_file)) as zipfile:
|
| 505 |
+
metadata = str(zipfile.read("foo-42.dist-info/METADATA"), "utf-8")
|
| 506 |
+
members = zipfile.namelist()
|
| 507 |
+
assert "bar-13.dist-info/METADATA" not in members
|
| 508 |
+
|
| 509 |
+
for file in pkg_info, metadata:
|
| 510 |
+
for line in ("Name: foo", "Version: 42"):
|
| 511 |
+
assert line in file
|
| 512 |
+
for line in ("Name: bar", "Version: 13"):
|
| 513 |
+
assert line not in file
|
| 514 |
+
|
| 515 |
+
def test_build_sdist(self, build_backend):
|
| 516 |
+
dist_dir = os.path.abspath('pip-sdist')
|
| 517 |
+
os.makedirs(dist_dir)
|
| 518 |
+
sdist_name = build_backend.build_sdist(dist_dir)
|
| 519 |
+
|
| 520 |
+
assert os.path.isfile(os.path.join(dist_dir, sdist_name))
|
| 521 |
+
|
| 522 |
+
def test_prepare_metadata_for_build_wheel(self, build_backend):
|
| 523 |
+
dist_dir = os.path.abspath('pip-dist-info')
|
| 524 |
+
os.makedirs(dist_dir)
|
| 525 |
+
|
| 526 |
+
dist_info = build_backend.prepare_metadata_for_build_wheel(dist_dir)
|
| 527 |
+
|
| 528 |
+
assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))
|
| 529 |
+
|
| 530 |
+
def test_prepare_metadata_inplace(self, build_backend):
|
| 531 |
+
"""
|
| 532 |
+
Some users might pass metadata_directory pre-populated with `.tox` or `.venv`.
|
| 533 |
+
See issue #3523.
|
| 534 |
+
"""
|
| 535 |
+
for pre_existing in [
|
| 536 |
+
".tox/python/lib/python3.10/site-packages/attrs-22.1.0.dist-info",
|
| 537 |
+
".tox/python/lib/python3.10/site-packages/autocommand-2.2.1.dist-info",
|
| 538 |
+
".nox/python/lib/python3.10/site-packages/build-0.8.0.dist-info",
|
| 539 |
+
".venv/python3.10/site-packages/click-8.1.3.dist-info",
|
| 540 |
+
"venv/python3.10/site-packages/distlib-0.3.5.dist-info",
|
| 541 |
+
"env/python3.10/site-packages/docutils-0.19.dist-info",
|
| 542 |
+
]:
|
| 543 |
+
os.makedirs(pre_existing, exist_ok=True)
|
| 544 |
+
dist_info = build_backend.prepare_metadata_for_build_wheel(".")
|
| 545 |
+
assert os.path.isfile(os.path.join(dist_info, 'METADATA'))
|
| 546 |
+
|
| 547 |
+
def test_build_sdist_explicit_dist(self, build_backend):
|
| 548 |
+
# explicitly specifying the dist folder should work
|
| 549 |
+
# the folder sdist_directory and the ``--dist-dir`` can be the same
|
| 550 |
+
dist_dir = os.path.abspath('dist')
|
| 551 |
+
sdist_name = build_backend.build_sdist(dist_dir)
|
| 552 |
+
assert os.path.isfile(os.path.join(dist_dir, sdist_name))
|
| 553 |
+
|
| 554 |
+
def test_build_sdist_version_change(self, build_backend):
|
| 555 |
+
sdist_into_directory = os.path.abspath("out_sdist")
|
| 556 |
+
os.makedirs(sdist_into_directory)
|
| 557 |
+
|
| 558 |
+
sdist_name = build_backend.build_sdist(sdist_into_directory)
|
| 559 |
+
assert os.path.isfile(os.path.join(sdist_into_directory, sdist_name))
|
| 560 |
+
|
| 561 |
+
# if the setup.py changes subsequent call of the build meta
|
| 562 |
+
# should still succeed, given the
|
| 563 |
+
# sdist_directory the frontend specifies is empty
|
| 564 |
+
setup_loc = os.path.abspath("setup.py")
|
| 565 |
+
if not os.path.exists(setup_loc):
|
| 566 |
+
setup_loc = os.path.abspath("setup.cfg")
|
| 567 |
+
|
| 568 |
+
with open(setup_loc, 'rt', encoding="utf-8") as file_handler:
|
| 569 |
+
content = file_handler.read()
|
| 570 |
+
with open(setup_loc, 'wt', encoding="utf-8") as file_handler:
|
| 571 |
+
file_handler.write(content.replace("version='0.0.0'", "version='0.0.1'"))
|
| 572 |
+
|
| 573 |
+
shutil.rmtree(sdist_into_directory)
|
| 574 |
+
os.makedirs(sdist_into_directory)
|
| 575 |
+
|
| 576 |
+
sdist_name = build_backend.build_sdist("out_sdist")
|
| 577 |
+
assert os.path.isfile(os.path.join(os.path.abspath("out_sdist"), sdist_name))
|
| 578 |
+
|
| 579 |
+
def test_build_sdist_pyproject_toml_exists(self, tmpdir_cwd):
|
| 580 |
+
files = {
|
| 581 |
+
'setup.py': DALS(
|
| 582 |
+
"""
|
| 583 |
+
__import__('setuptools').setup(
|
| 584 |
+
name='foo',
|
| 585 |
+
version='0.0.0',
|
| 586 |
+
py_modules=['hello']
|
| 587 |
+
)"""
|
| 588 |
+
),
|
| 589 |
+
'hello.py': '',
|
| 590 |
+
'pyproject.toml': DALS(
|
| 591 |
+
"""
|
| 592 |
+
[build-system]
|
| 593 |
+
requires = ["setuptools", "wheel"]
|
| 594 |
+
build-backend = "setuptools.build_meta"
|
| 595 |
+
"""
|
| 596 |
+
),
|
| 597 |
+
}
|
| 598 |
+
path.build(files)
|
| 599 |
+
build_backend = self.get_build_backend()
|
| 600 |
+
targz_path = build_backend.build_sdist("temp")
|
| 601 |
+
with tarfile.open(os.path.join("temp", targz_path)) as tar:
|
| 602 |
+
assert any('pyproject.toml' in name for name in tar.getnames())
|
| 603 |
+
|
| 604 |
+
def test_build_sdist_setup_py_exists(self, tmpdir_cwd):
|
| 605 |
+
# If build_sdist is called from a script other than setup.py,
|
| 606 |
+
# ensure setup.py is included
|
| 607 |
+
path.build(defns[0])
|
| 608 |
+
|
| 609 |
+
build_backend = self.get_build_backend()
|
| 610 |
+
targz_path = build_backend.build_sdist("temp")
|
| 611 |
+
with tarfile.open(os.path.join("temp", targz_path)) as tar:
|
| 612 |
+
assert any('setup.py' in name for name in tar.getnames())
|
| 613 |
+
|
| 614 |
+
def test_build_sdist_setup_py_manifest_excluded(self, tmpdir_cwd):
|
| 615 |
+
# Ensure that MANIFEST.in can exclude setup.py
|
| 616 |
+
files = {
|
| 617 |
+
'setup.py': DALS(
|
| 618 |
+
"""
|
| 619 |
+
__import__('setuptools').setup(
|
| 620 |
+
name='foo',
|
| 621 |
+
version='0.0.0',
|
| 622 |
+
py_modules=['hello']
|
| 623 |
+
)"""
|
| 624 |
+
),
|
| 625 |
+
'hello.py': '',
|
| 626 |
+
'MANIFEST.in': DALS(
|
| 627 |
+
"""
|
| 628 |
+
exclude setup.py
|
| 629 |
+
"""
|
| 630 |
+
),
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
path.build(files)
|
| 634 |
+
|
| 635 |
+
build_backend = self.get_build_backend()
|
| 636 |
+
targz_path = build_backend.build_sdist("temp")
|
| 637 |
+
with tarfile.open(os.path.join("temp", targz_path)) as tar:
|
| 638 |
+
assert not any('setup.py' in name for name in tar.getnames())
|
| 639 |
+
|
| 640 |
+
def test_build_sdist_builds_targz_even_if_zip_indicated(self, tmpdir_cwd):
|
| 641 |
+
files = {
|
| 642 |
+
'setup.py': DALS(
|
| 643 |
+
"""
|
| 644 |
+
__import__('setuptools').setup(
|
| 645 |
+
name='foo',
|
| 646 |
+
version='0.0.0',
|
| 647 |
+
py_modules=['hello']
|
| 648 |
+
)"""
|
| 649 |
+
),
|
| 650 |
+
'hello.py': '',
|
| 651 |
+
'setup.cfg': DALS(
|
| 652 |
+
"""
|
| 653 |
+
[sdist]
|
| 654 |
+
formats=zip
|
| 655 |
+
"""
|
| 656 |
+
),
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
path.build(files)
|
| 660 |
+
|
| 661 |
+
build_backend = self.get_build_backend()
|
| 662 |
+
build_backend.build_sdist("temp")
|
| 663 |
+
|
| 664 |
+
_relative_path_import_files = {
|
| 665 |
+
'setup.py': DALS(
|
| 666 |
+
"""
|
| 667 |
+
__import__('setuptools').setup(
|
| 668 |
+
name='foo',
|
| 669 |
+
version=__import__('hello').__version__,
|
| 670 |
+
py_modules=['hello']
|
| 671 |
+
)"""
|
| 672 |
+
),
|
| 673 |
+
'hello.py': '__version__ = "0.0.0"',
|
| 674 |
+
'setup.cfg': DALS(
|
| 675 |
+
"""
|
| 676 |
+
[sdist]
|
| 677 |
+
formats=zip
|
| 678 |
+
"""
|
| 679 |
+
),
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
def test_build_sdist_relative_path_import(self, tmpdir_cwd):
|
| 683 |
+
path.build(self._relative_path_import_files)
|
| 684 |
+
build_backend = self.get_build_backend()
|
| 685 |
+
with pytest.raises(ImportError, match="^No module named 'hello'$"):
|
| 686 |
+
build_backend.build_sdist("temp")
|
| 687 |
+
|
| 688 |
+
_simple_pyproject_example = {
|
| 689 |
+
"pyproject.toml": DALS(
|
| 690 |
+
"""
|
| 691 |
+
[project]
|
| 692 |
+
name = "proj"
|
| 693 |
+
version = "42"
|
| 694 |
+
"""
|
| 695 |
+
),
|
| 696 |
+
"src": {"proj": {"__init__.py": ""}},
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
def _assert_link_tree(self, parent_dir):
|
| 700 |
+
"""All files in the directory should be either links or hard links"""
|
| 701 |
+
files = list(Path(parent_dir).glob("**/*"))
|
| 702 |
+
assert files # Should not be empty
|
| 703 |
+
for file in files:
|
| 704 |
+
assert file.is_symlink() or os.stat(file).st_nlink > 0
|
| 705 |
+
|
| 706 |
+
def test_editable_without_config_settings(self, tmpdir_cwd):
|
| 707 |
+
"""
|
| 708 |
+
Sanity check to ensure tests with --mode=strict are different from the ones
|
| 709 |
+
without --mode.
|
| 710 |
+
|
| 711 |
+
--mode=strict should create a local directory with a package tree.
|
| 712 |
+
The directory should not get created otherwise.
|
| 713 |
+
"""
|
| 714 |
+
path.build(self._simple_pyproject_example)
|
| 715 |
+
build_backend = self.get_build_backend()
|
| 716 |
+
assert not Path("build").exists()
|
| 717 |
+
build_backend.build_editable("temp")
|
| 718 |
+
assert not Path("build").exists()
|
| 719 |
+
|
| 720 |
+
def test_build_wheel_inplace(self, tmpdir_cwd):
|
| 721 |
+
config_settings = {"--build-option": ["build_ext", "--inplace"]}
|
| 722 |
+
path.build(self._simple_pyproject_example)
|
| 723 |
+
build_backend = self.get_build_backend()
|
| 724 |
+
assert not Path("build").exists()
|
| 725 |
+
Path("build").mkdir()
|
| 726 |
+
build_backend.prepare_metadata_for_build_wheel("build", config_settings)
|
| 727 |
+
build_backend.build_wheel("build", config_settings)
|
| 728 |
+
assert Path("build/proj-42-py3-none-any.whl").exists()
|
| 729 |
+
|
| 730 |
+
@pytest.mark.parametrize("config_settings", [{"editable-mode": "strict"}])
|
| 731 |
+
def test_editable_with_config_settings(self, tmpdir_cwd, config_settings):
|
| 732 |
+
path.build({**self._simple_pyproject_example, '_meta': {}})
|
| 733 |
+
assert not Path("build").exists()
|
| 734 |
+
build_backend = self.get_build_backend()
|
| 735 |
+
build_backend.prepare_metadata_for_build_editable("_meta", config_settings)
|
| 736 |
+
build_backend.build_editable("temp", config_settings, "_meta")
|
| 737 |
+
self._assert_link_tree(next(Path("build").glob("__editable__.*")))
|
| 738 |
+
|
| 739 |
+
@pytest.mark.parametrize(
|
| 740 |
+
("setup_literal", "requirements"),
|
| 741 |
+
[
|
| 742 |
+
("'foo'", ['foo']),
|
| 743 |
+
("['foo']", ['foo']),
|
| 744 |
+
(r"'foo\n'", ['foo']),
|
| 745 |
+
(r"'foo\n\n'", ['foo']),
|
| 746 |
+
("['foo', 'bar']", ['foo', 'bar']),
|
| 747 |
+
(r"'# Has a comment line\nfoo'", ['foo']),
|
| 748 |
+
(r"'foo # Has an inline comment'", ['foo']),
|
| 749 |
+
(r"'foo \\\n >=3.0'", ['foo>=3.0']),
|
| 750 |
+
(r"'foo\nbar'", ['foo', 'bar']),
|
| 751 |
+
(r"'foo\nbar\n'", ['foo', 'bar']),
|
| 752 |
+
(r"['foo\n', 'bar\n']", ['foo', 'bar']),
|
| 753 |
+
],
|
| 754 |
+
)
|
| 755 |
+
@pytest.mark.parametrize('use_wheel', [True, False])
|
| 756 |
+
def test_setup_requires(self, setup_literal, requirements, use_wheel, tmpdir_cwd):
|
| 757 |
+
files = {
|
| 758 |
+
'setup.py': DALS(
|
| 759 |
+
"""
|
| 760 |
+
from setuptools import setup
|
| 761 |
+
|
| 762 |
+
setup(
|
| 763 |
+
name="qux",
|
| 764 |
+
version="0.0.0",
|
| 765 |
+
py_modules=["hello"],
|
| 766 |
+
setup_requires={setup_literal},
|
| 767 |
+
)
|
| 768 |
+
"""
|
| 769 |
+
).format(setup_literal=setup_literal),
|
| 770 |
+
'hello.py': DALS(
|
| 771 |
+
"""
|
| 772 |
+
def run():
|
| 773 |
+
print('hello')
|
| 774 |
+
"""
|
| 775 |
+
),
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
path.build(files)
|
| 779 |
+
|
| 780 |
+
build_backend = self.get_build_backend()
|
| 781 |
+
|
| 782 |
+
if use_wheel:
|
| 783 |
+
get_requires = build_backend.get_requires_for_build_wheel
|
| 784 |
+
else:
|
| 785 |
+
get_requires = build_backend.get_requires_for_build_sdist
|
| 786 |
+
|
| 787 |
+
# Ensure that the build requirements are properly parsed
|
| 788 |
+
expected = sorted(requirements)
|
| 789 |
+
actual = get_requires()
|
| 790 |
+
|
| 791 |
+
assert expected == sorted(actual)
|
| 792 |
+
|
| 793 |
+
def test_setup_requires_with_auto_discovery(self, tmpdir_cwd):
|
| 794 |
+
# Make sure patches introduced to retrieve setup_requires don't accidentally
|
| 795 |
+
# activate auto-discovery and cause problems due to the incomplete set of
|
| 796 |
+
# attributes passed to MinimalDistribution
|
| 797 |
+
files = {
|
| 798 |
+
'pyproject.toml': DALS(
|
| 799 |
+
"""
|
| 800 |
+
[project]
|
| 801 |
+
name = "proj"
|
| 802 |
+
version = "42"
|
| 803 |
+
"""
|
| 804 |
+
),
|
| 805 |
+
"setup.py": DALS(
|
| 806 |
+
"""
|
| 807 |
+
__import__('setuptools').setup(
|
| 808 |
+
setup_requires=["foo"],
|
| 809 |
+
py_modules = ["hello", "world"]
|
| 810 |
+
)
|
| 811 |
+
"""
|
| 812 |
+
),
|
| 813 |
+
'hello.py': "'hello'",
|
| 814 |
+
'world.py': "'world'",
|
| 815 |
+
}
|
| 816 |
+
path.build(files)
|
| 817 |
+
build_backend = self.get_build_backend()
|
| 818 |
+
setup_requires = build_backend.get_requires_for_build_wheel()
|
| 819 |
+
assert setup_requires == ["foo"]
|
| 820 |
+
|
| 821 |
+
def test_dont_install_setup_requires(self, tmpdir_cwd):
|
| 822 |
+
files = {
|
| 823 |
+
'setup.py': DALS(
|
| 824 |
+
"""
|
| 825 |
+
from setuptools import setup
|
| 826 |
+
|
| 827 |
+
setup(
|
| 828 |
+
name="qux",
|
| 829 |
+
version="0.0.0",
|
| 830 |
+
py_modules=["hello"],
|
| 831 |
+
setup_requires=["does-not-exist >99"],
|
| 832 |
+
)
|
| 833 |
+
"""
|
| 834 |
+
),
|
| 835 |
+
'hello.py': DALS(
|
| 836 |
+
"""
|
| 837 |
+
def run():
|
| 838 |
+
print('hello')
|
| 839 |
+
"""
|
| 840 |
+
),
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
path.build(files)
|
| 844 |
+
|
| 845 |
+
build_backend = self.get_build_backend()
|
| 846 |
+
|
| 847 |
+
dist_dir = os.path.abspath('pip-dist-info')
|
| 848 |
+
os.makedirs(dist_dir)
|
| 849 |
+
|
| 850 |
+
# does-not-exist can't be satisfied, so if it attempts to install
|
| 851 |
+
# setup_requires, it will fail.
|
| 852 |
+
build_backend.prepare_metadata_for_build_wheel(dist_dir)
|
| 853 |
+
|
| 854 |
+
_sys_argv_0_passthrough = {
|
| 855 |
+
'setup.py': DALS(
|
| 856 |
+
"""
|
| 857 |
+
import os
|
| 858 |
+
import sys
|
| 859 |
+
|
| 860 |
+
__import__('setuptools').setup(
|
| 861 |
+
name='foo',
|
| 862 |
+
version='0.0.0',
|
| 863 |
+
)
|
| 864 |
+
|
| 865 |
+
sys_argv = os.path.abspath(sys.argv[0])
|
| 866 |
+
file_path = os.path.abspath('setup.py')
|
| 867 |
+
assert sys_argv == file_path
|
| 868 |
+
"""
|
| 869 |
+
)
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
def test_sys_argv_passthrough(self, tmpdir_cwd):
|
| 873 |
+
path.build(self._sys_argv_0_passthrough)
|
| 874 |
+
build_backend = self.get_build_backend()
|
| 875 |
+
with pytest.raises(AssertionError):
|
| 876 |
+
build_backend.build_sdist("temp")
|
| 877 |
+
|
| 878 |
+
_setup_py_file_abspath = {
|
| 879 |
+
'setup.py': DALS(
|
| 880 |
+
"""
|
| 881 |
+
import os
|
| 882 |
+
assert os.path.isabs(__file__)
|
| 883 |
+
__import__('setuptools').setup(
|
| 884 |
+
name='foo',
|
| 885 |
+
version='0.0.0',
|
| 886 |
+
py_modules=['hello'],
|
| 887 |
+
setup_requires=['six'],
|
| 888 |
+
)
|
| 889 |
+
"""
|
| 890 |
+
)
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
def test_setup_py_file_abspath(self, tmpdir_cwd):
|
| 894 |
+
path.build(self._setup_py_file_abspath)
|
| 895 |
+
build_backend = self.get_build_backend()
|
| 896 |
+
build_backend.build_sdist("temp")
|
| 897 |
+
|
| 898 |
+
@pytest.mark.parametrize('build_hook', ('build_sdist', 'build_wheel'))
|
| 899 |
+
def test_build_with_empty_setuppy(self, build_backend, build_hook):
|
| 900 |
+
files = {'setup.py': ''}
|
| 901 |
+
path.build(files)
|
| 902 |
+
|
| 903 |
+
msg = re.escape('No distribution was found.')
|
| 904 |
+
with pytest.raises(ValueError, match=msg):
|
| 905 |
+
getattr(build_backend, build_hook)("temp")
|
| 906 |
+
|
| 907 |
+
|
| 908 |
+
class TestBuildMetaLegacyBackend(TestBuildMetaBackend):
|
| 909 |
+
backend_name = 'setuptools.build_meta:__legacy__'
|
| 910 |
+
|
| 911 |
+
# build_meta_legacy-specific tests
|
| 912 |
+
def test_build_sdist_relative_path_import(self, tmpdir_cwd):
|
| 913 |
+
# This must fail in build_meta, but must pass in build_meta_legacy
|
| 914 |
+
path.build(self._relative_path_import_files)
|
| 915 |
+
|
| 916 |
+
build_backend = self.get_build_backend()
|
| 917 |
+
build_backend.build_sdist("temp")
|
| 918 |
+
|
| 919 |
+
def test_sys_argv_passthrough(self, tmpdir_cwd):
|
| 920 |
+
path.build(self._sys_argv_0_passthrough)
|
| 921 |
+
|
| 922 |
+
build_backend = self.get_build_backend()
|
| 923 |
+
build_backend.build_sdist("temp")
|
| 924 |
+
|
| 925 |
+
|
| 926 |
+
def test_legacy_editable_install(venv, tmpdir, tmpdir_cwd):
|
| 927 |
+
pyproject = """
|
| 928 |
+
[build-system]
|
| 929 |
+
requires = ["setuptools"]
|
| 930 |
+
build-backend = "setuptools.build_meta"
|
| 931 |
+
[project]
|
| 932 |
+
name = "myproj"
|
| 933 |
+
version = "42"
|
| 934 |
+
"""
|
| 935 |
+
path.build({"pyproject.toml": DALS(pyproject), "mymod.py": ""})
|
| 936 |
+
|
| 937 |
+
# First: sanity check
|
| 938 |
+
cmd = ["pip", "install", "--no-build-isolation", "-e", "."]
|
| 939 |
+
output = venv.run(cmd, cwd=tmpdir).lower()
|
| 940 |
+
assert "running setup.py develop for myproj" not in output
|
| 941 |
+
assert "created wheel for myproj" in output
|
| 942 |
+
|
| 943 |
+
# Then: real test
|
| 944 |
+
env = {**os.environ, "SETUPTOOLS_ENABLE_FEATURES": "legacy-editable"}
|
| 945 |
+
cmd = ["pip", "install", "--no-build-isolation", "-e", "."]
|
| 946 |
+
output = venv.run(cmd, cwd=tmpdir, env=env).lower()
|
| 947 |
+
assert "running setup.py develop for myproj" in output
|
| 948 |
+
|
| 949 |
+
|
| 950 |
+
@pytest.mark.filterwarnings("ignore::setuptools.SetuptoolsDeprecationWarning")
|
| 951 |
+
def test_sys_exit_0_in_setuppy(monkeypatch, tmp_path):
|
| 952 |
+
"""Setuptools should be resilient to setup.py with ``sys.exit(0)`` (#3973)."""
|
| 953 |
+
monkeypatch.chdir(tmp_path)
|
| 954 |
+
setuppy = """
|
| 955 |
+
import sys, setuptools
|
| 956 |
+
setuptools.setup(name='foo', version='0.0.0')
|
| 957 |
+
sys.exit(0)
|
| 958 |
+
"""
|
| 959 |
+
(tmp_path / "setup.py").write_text(DALS(setuppy), encoding="utf-8")
|
| 960 |
+
backend = BuildBackend(backend_name="setuptools.build_meta")
|
| 961 |
+
assert backend.get_requires_for_build_wheel() == []
|
| 962 |
+
|
| 963 |
+
|
| 964 |
+
def test_system_exit_in_setuppy(monkeypatch, tmp_path):
|
| 965 |
+
monkeypatch.chdir(tmp_path)
|
| 966 |
+
setuppy = "import sys; sys.exit('some error')"
|
| 967 |
+
(tmp_path / "setup.py").write_text(setuppy, encoding="utf-8")
|
| 968 |
+
with pytest.raises(SystemExit, match="some error"):
|
| 969 |
+
backend = BuildBackend(backend_name="setuptools.build_meta")
|
| 970 |
+
backend.get_requires_for_build_wheel()
|
valley/lib/python3.10/site-packages/setuptools/tests/test_build_py.py
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import stat
|
| 4 |
+
import warnings
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from unittest.mock import Mock
|
| 7 |
+
|
| 8 |
+
import jaraco.path
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
from setuptools import SetuptoolsDeprecationWarning
|
| 12 |
+
from setuptools.dist import Distribution
|
| 13 |
+
|
| 14 |
+
from .textwrap import DALS
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_directories_in_package_data_glob(tmpdir_cwd):
|
| 18 |
+
"""
|
| 19 |
+
Directories matching the glob in package_data should
|
| 20 |
+
not be included in the package data.
|
| 21 |
+
|
| 22 |
+
Regression test for #261.
|
| 23 |
+
"""
|
| 24 |
+
dist = Distribution(
|
| 25 |
+
dict(
|
| 26 |
+
script_name='setup.py',
|
| 27 |
+
script_args=['build_py'],
|
| 28 |
+
packages=[''],
|
| 29 |
+
package_data={'': ['path/*']},
|
| 30 |
+
)
|
| 31 |
+
)
|
| 32 |
+
os.makedirs('path/subpath')
|
| 33 |
+
dist.parse_command_line()
|
| 34 |
+
dist.run_commands()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_recursive_in_package_data_glob(tmpdir_cwd):
|
| 38 |
+
"""
|
| 39 |
+
Files matching recursive globs (**) in package_data should
|
| 40 |
+
be included in the package data.
|
| 41 |
+
|
| 42 |
+
#1806
|
| 43 |
+
"""
|
| 44 |
+
dist = Distribution(
|
| 45 |
+
dict(
|
| 46 |
+
script_name='setup.py',
|
| 47 |
+
script_args=['build_py'],
|
| 48 |
+
packages=[''],
|
| 49 |
+
package_data={'': ['path/**/data']},
|
| 50 |
+
)
|
| 51 |
+
)
|
| 52 |
+
os.makedirs('path/subpath/subsubpath')
|
| 53 |
+
open('path/subpath/subsubpath/data', 'wb').close()
|
| 54 |
+
|
| 55 |
+
dist.parse_command_line()
|
| 56 |
+
dist.run_commands()
|
| 57 |
+
|
| 58 |
+
assert stat.S_ISREG(os.stat('build/lib/path/subpath/subsubpath/data').st_mode), (
|
| 59 |
+
"File is not included"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def test_read_only(tmpdir_cwd):
|
| 64 |
+
"""
|
| 65 |
+
Ensure read-only flag is not preserved in copy
|
| 66 |
+
for package modules and package data, as that
|
| 67 |
+
causes problems with deleting read-only files on
|
| 68 |
+
Windows.
|
| 69 |
+
|
| 70 |
+
#1451
|
| 71 |
+
"""
|
| 72 |
+
dist = Distribution(
|
| 73 |
+
dict(
|
| 74 |
+
script_name='setup.py',
|
| 75 |
+
script_args=['build_py'],
|
| 76 |
+
packages=['pkg'],
|
| 77 |
+
package_data={'pkg': ['data.dat']},
|
| 78 |
+
)
|
| 79 |
+
)
|
| 80 |
+
os.makedirs('pkg')
|
| 81 |
+
open('pkg/__init__.py', 'wb').close()
|
| 82 |
+
open('pkg/data.dat', 'wb').close()
|
| 83 |
+
os.chmod('pkg/__init__.py', stat.S_IREAD)
|
| 84 |
+
os.chmod('pkg/data.dat', stat.S_IREAD)
|
| 85 |
+
dist.parse_command_line()
|
| 86 |
+
dist.run_commands()
|
| 87 |
+
shutil.rmtree('build')
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
@pytest.mark.xfail(
|
| 91 |
+
'platform.system() == "Windows"',
|
| 92 |
+
reason="On Windows, files do not have executable bits",
|
| 93 |
+
raises=AssertionError,
|
| 94 |
+
strict=True,
|
| 95 |
+
)
|
| 96 |
+
def test_executable_data(tmpdir_cwd):
|
| 97 |
+
"""
|
| 98 |
+
Ensure executable bit is preserved in copy for
|
| 99 |
+
package data, as users rely on it for scripts.
|
| 100 |
+
|
| 101 |
+
#2041
|
| 102 |
+
"""
|
| 103 |
+
dist = Distribution(
|
| 104 |
+
dict(
|
| 105 |
+
script_name='setup.py',
|
| 106 |
+
script_args=['build_py'],
|
| 107 |
+
packages=['pkg'],
|
| 108 |
+
package_data={'pkg': ['run-me']},
|
| 109 |
+
)
|
| 110 |
+
)
|
| 111 |
+
os.makedirs('pkg')
|
| 112 |
+
open('pkg/__init__.py', 'wb').close()
|
| 113 |
+
open('pkg/run-me', 'wb').close()
|
| 114 |
+
os.chmod('pkg/run-me', 0o700)
|
| 115 |
+
|
| 116 |
+
dist.parse_command_line()
|
| 117 |
+
dist.run_commands()
|
| 118 |
+
|
| 119 |
+
assert os.stat('build/lib/pkg/run-me').st_mode & stat.S_IEXEC, (
|
| 120 |
+
"Script is not executable"
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
EXAMPLE_WITH_MANIFEST = {
|
| 125 |
+
"setup.cfg": DALS(
|
| 126 |
+
"""
|
| 127 |
+
[metadata]
|
| 128 |
+
name = mypkg
|
| 129 |
+
version = 42
|
| 130 |
+
|
| 131 |
+
[options]
|
| 132 |
+
include_package_data = True
|
| 133 |
+
packages = find:
|
| 134 |
+
|
| 135 |
+
[options.packages.find]
|
| 136 |
+
exclude = *.tests*
|
| 137 |
+
"""
|
| 138 |
+
),
|
| 139 |
+
"mypkg": {
|
| 140 |
+
"__init__.py": "",
|
| 141 |
+
"resource_file.txt": "",
|
| 142 |
+
"tests": {
|
| 143 |
+
"__init__.py": "",
|
| 144 |
+
"test_mypkg.py": "",
|
| 145 |
+
"test_file.txt": "",
|
| 146 |
+
},
|
| 147 |
+
},
|
| 148 |
+
"MANIFEST.in": DALS(
|
| 149 |
+
"""
|
| 150 |
+
global-include *.py *.txt
|
| 151 |
+
global-exclude *.py[cod]
|
| 152 |
+
prune dist
|
| 153 |
+
prune build
|
| 154 |
+
prune *.egg-info
|
| 155 |
+
"""
|
| 156 |
+
),
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def test_excluded_subpackages(tmpdir_cwd):
|
| 161 |
+
jaraco.path.build(EXAMPLE_WITH_MANIFEST)
|
| 162 |
+
dist = Distribution({"script_name": "%PEP 517%"})
|
| 163 |
+
dist.parse_config_files()
|
| 164 |
+
|
| 165 |
+
build_py = dist.get_command_obj("build_py")
|
| 166 |
+
|
| 167 |
+
msg = r"Python recognizes 'mypkg\.tests' as an importable package"
|
| 168 |
+
with pytest.warns(SetuptoolsDeprecationWarning, match=msg):
|
| 169 |
+
# TODO: To fix #3260 we need some transition period to deprecate the
|
| 170 |
+
# existing behavior of `include_package_data`. After the transition, we
|
| 171 |
+
# should remove the warning and fix the behaviour.
|
| 172 |
+
|
| 173 |
+
if os.getenv("SETUPTOOLS_USE_DISTUTILS") == "stdlib":
|
| 174 |
+
# pytest.warns reset the warning filter temporarily
|
| 175 |
+
# https://github.com/pytest-dev/pytest/issues/4011#issuecomment-423494810
|
| 176 |
+
warnings.filterwarnings(
|
| 177 |
+
"ignore",
|
| 178 |
+
"'encoding' argument not specified",
|
| 179 |
+
module="distutils.text_file",
|
| 180 |
+
# This warning is already fixed in pypa/distutils but not in stdlib
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
build_py.finalize_options()
|
| 184 |
+
build_py.run()
|
| 185 |
+
|
| 186 |
+
build_dir = Path(dist.get_command_obj("build_py").build_lib)
|
| 187 |
+
assert (build_dir / "mypkg/__init__.py").exists()
|
| 188 |
+
assert (build_dir / "mypkg/resource_file.txt").exists()
|
| 189 |
+
|
| 190 |
+
# Setuptools is configured to ignore `mypkg.tests`, therefore the following
|
| 191 |
+
# files/dirs should not be included in the distribution.
|
| 192 |
+
for f in [
|
| 193 |
+
"mypkg/tests/__init__.py",
|
| 194 |
+
"mypkg/tests/test_mypkg.py",
|
| 195 |
+
"mypkg/tests/test_file.txt",
|
| 196 |
+
"mypkg/tests",
|
| 197 |
+
]:
|
| 198 |
+
with pytest.raises(AssertionError):
|
| 199 |
+
# TODO: Enforce the following assertion once #3260 is fixed
|
| 200 |
+
# (remove context manager and the following xfail).
|
| 201 |
+
assert not (build_dir / f).exists()
|
| 202 |
+
|
| 203 |
+
pytest.xfail("#3260")
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
@pytest.mark.filterwarnings("ignore::setuptools.SetuptoolsDeprecationWarning")
|
| 207 |
+
def test_existing_egg_info(tmpdir_cwd, monkeypatch):
|
| 208 |
+
"""When provided with the ``existing_egg_info_dir`` attribute, build_py should not
|
| 209 |
+
attempt to run egg_info again.
|
| 210 |
+
"""
|
| 211 |
+
# == Pre-condition ==
|
| 212 |
+
# Generate an egg-info dir
|
| 213 |
+
jaraco.path.build(EXAMPLE_WITH_MANIFEST)
|
| 214 |
+
dist = Distribution({"script_name": "%PEP 517%"})
|
| 215 |
+
dist.parse_config_files()
|
| 216 |
+
assert dist.include_package_data
|
| 217 |
+
|
| 218 |
+
egg_info = dist.get_command_obj("egg_info")
|
| 219 |
+
dist.run_command("egg_info")
|
| 220 |
+
egg_info_dir = next(Path(egg_info.egg_base).glob("*.egg-info"))
|
| 221 |
+
assert egg_info_dir.is_dir()
|
| 222 |
+
|
| 223 |
+
# == Setup ==
|
| 224 |
+
build_py = dist.get_command_obj("build_py")
|
| 225 |
+
build_py.finalize_options()
|
| 226 |
+
egg_info = dist.get_command_obj("egg_info")
|
| 227 |
+
egg_info_run = Mock(side_effect=egg_info.run)
|
| 228 |
+
monkeypatch.setattr(egg_info, "run", egg_info_run)
|
| 229 |
+
|
| 230 |
+
# == Remove caches ==
|
| 231 |
+
# egg_info is called when build_py looks for data_files, which gets cached.
|
| 232 |
+
# We need to ensure it is not cached yet, otherwise it may impact on the tests
|
| 233 |
+
build_py.__dict__.pop('data_files', None)
|
| 234 |
+
dist.reinitialize_command(egg_info)
|
| 235 |
+
|
| 236 |
+
# == Sanity check ==
|
| 237 |
+
# Ensure that if existing_egg_info is not given, build_py attempts to run egg_info
|
| 238 |
+
build_py.existing_egg_info_dir = None
|
| 239 |
+
build_py.run()
|
| 240 |
+
egg_info_run.assert_called()
|
| 241 |
+
|
| 242 |
+
# == Remove caches ==
|
| 243 |
+
egg_info_run.reset_mock()
|
| 244 |
+
build_py.__dict__.pop('data_files', None)
|
| 245 |
+
dist.reinitialize_command(egg_info)
|
| 246 |
+
|
| 247 |
+
# == Actual test ==
|
| 248 |
+
# Ensure that if existing_egg_info_dir is given, egg_info doesn't run
|
| 249 |
+
build_py.existing_egg_info_dir = egg_info_dir
|
| 250 |
+
build_py.run()
|
| 251 |
+
egg_info_run.assert_not_called()
|
| 252 |
+
assert build_py.data_files
|
| 253 |
+
|
| 254 |
+
# Make sure the list of outputs is actually OK
|
| 255 |
+
outputs = map(lambda x: x.replace(os.sep, "/"), build_py.get_outputs())
|
| 256 |
+
assert outputs
|
| 257 |
+
example = str(Path(build_py.build_lib, "mypkg/__init__.py")).replace(os.sep, "/")
|
| 258 |
+
assert example in outputs
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
EXAMPLE_ARBITRARY_MAPPING = {
|
| 262 |
+
"pyproject.toml": DALS(
|
| 263 |
+
"""
|
| 264 |
+
[project]
|
| 265 |
+
name = "mypkg"
|
| 266 |
+
version = "42"
|
| 267 |
+
|
| 268 |
+
[tool.setuptools]
|
| 269 |
+
packages = ["mypkg", "mypkg.sub1", "mypkg.sub2", "mypkg.sub2.nested"]
|
| 270 |
+
|
| 271 |
+
[tool.setuptools.package-dir]
|
| 272 |
+
"" = "src"
|
| 273 |
+
"mypkg.sub2" = "src/mypkg/_sub2"
|
| 274 |
+
"mypkg.sub2.nested" = "other"
|
| 275 |
+
"""
|
| 276 |
+
),
|
| 277 |
+
"src": {
|
| 278 |
+
"mypkg": {
|
| 279 |
+
"__init__.py": "",
|
| 280 |
+
"resource_file.txt": "",
|
| 281 |
+
"sub1": {
|
| 282 |
+
"__init__.py": "",
|
| 283 |
+
"mod1.py": "",
|
| 284 |
+
},
|
| 285 |
+
"_sub2": {
|
| 286 |
+
"mod2.py": "",
|
| 287 |
+
},
|
| 288 |
+
},
|
| 289 |
+
},
|
| 290 |
+
"other": {
|
| 291 |
+
"__init__.py": "",
|
| 292 |
+
"mod3.py": "",
|
| 293 |
+
},
|
| 294 |
+
"MANIFEST.in": DALS(
|
| 295 |
+
"""
|
| 296 |
+
global-include *.py *.txt
|
| 297 |
+
global-exclude *.py[cod]
|
| 298 |
+
"""
|
| 299 |
+
),
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
def test_get_outputs(tmpdir_cwd):
|
| 304 |
+
jaraco.path.build(EXAMPLE_ARBITRARY_MAPPING)
|
| 305 |
+
dist = Distribution({"script_name": "%test%"})
|
| 306 |
+
dist.parse_config_files()
|
| 307 |
+
|
| 308 |
+
build_py = dist.get_command_obj("build_py")
|
| 309 |
+
build_py.editable_mode = True
|
| 310 |
+
build_py.ensure_finalized()
|
| 311 |
+
build_lib = build_py.build_lib.replace(os.sep, "/")
|
| 312 |
+
outputs = {x.replace(os.sep, "/") for x in build_py.get_outputs()}
|
| 313 |
+
assert outputs == {
|
| 314 |
+
f"{build_lib}/mypkg/__init__.py",
|
| 315 |
+
f"{build_lib}/mypkg/resource_file.txt",
|
| 316 |
+
f"{build_lib}/mypkg/sub1/__init__.py",
|
| 317 |
+
f"{build_lib}/mypkg/sub1/mod1.py",
|
| 318 |
+
f"{build_lib}/mypkg/sub2/mod2.py",
|
| 319 |
+
f"{build_lib}/mypkg/sub2/nested/__init__.py",
|
| 320 |
+
f"{build_lib}/mypkg/sub2/nested/mod3.py",
|
| 321 |
+
}
|
| 322 |
+
mapping = {
|
| 323 |
+
k.replace(os.sep, "/"): v.replace(os.sep, "/")
|
| 324 |
+
for k, v in build_py.get_output_mapping().items()
|
| 325 |
+
}
|
| 326 |
+
assert mapping == {
|
| 327 |
+
f"{build_lib}/mypkg/__init__.py": "src/mypkg/__init__.py",
|
| 328 |
+
f"{build_lib}/mypkg/resource_file.txt": "src/mypkg/resource_file.txt",
|
| 329 |
+
f"{build_lib}/mypkg/sub1/__init__.py": "src/mypkg/sub1/__init__.py",
|
| 330 |
+
f"{build_lib}/mypkg/sub1/mod1.py": "src/mypkg/sub1/mod1.py",
|
| 331 |
+
f"{build_lib}/mypkg/sub2/mod2.py": "src/mypkg/_sub2/mod2.py",
|
| 332 |
+
f"{build_lib}/mypkg/sub2/nested/__init__.py": "other/__init__.py",
|
| 333 |
+
f"{build_lib}/mypkg/sub2/nested/mod3.py": "other/mod3.py",
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
class TestTypeInfoFiles:
|
| 338 |
+
PYPROJECTS = {
|
| 339 |
+
"default_pyproject": DALS(
|
| 340 |
+
"""
|
| 341 |
+
[project]
|
| 342 |
+
name = "foo"
|
| 343 |
+
version = "1"
|
| 344 |
+
"""
|
| 345 |
+
),
|
| 346 |
+
"dont_include_package_data": DALS(
|
| 347 |
+
"""
|
| 348 |
+
[project]
|
| 349 |
+
name = "foo"
|
| 350 |
+
version = "1"
|
| 351 |
+
|
| 352 |
+
[tool.setuptools]
|
| 353 |
+
include-package-data = false
|
| 354 |
+
"""
|
| 355 |
+
),
|
| 356 |
+
"exclude_type_info": DALS(
|
| 357 |
+
"""
|
| 358 |
+
[project]
|
| 359 |
+
name = "foo"
|
| 360 |
+
version = "1"
|
| 361 |
+
|
| 362 |
+
[tool.setuptools]
|
| 363 |
+
include-package-data = false
|
| 364 |
+
|
| 365 |
+
[tool.setuptools.exclude-package-data]
|
| 366 |
+
"*" = ["py.typed", "*.pyi"]
|
| 367 |
+
"""
|
| 368 |
+
),
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
EXAMPLES = {
|
| 372 |
+
"simple_namespace": {
|
| 373 |
+
"directory_structure": {
|
| 374 |
+
"foo": {
|
| 375 |
+
"bar.pyi": "",
|
| 376 |
+
"py.typed": "",
|
| 377 |
+
"__init__.py": "",
|
| 378 |
+
}
|
| 379 |
+
},
|
| 380 |
+
"expected_type_files": {"foo/bar.pyi", "foo/py.typed"},
|
| 381 |
+
},
|
| 382 |
+
"nested_inside_namespace": {
|
| 383 |
+
"directory_structure": {
|
| 384 |
+
"foo": {
|
| 385 |
+
"bar": {
|
| 386 |
+
"py.typed": "",
|
| 387 |
+
"mod.pyi": "",
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
},
|
| 391 |
+
"expected_type_files": {"foo/bar/mod.pyi", "foo/bar/py.typed"},
|
| 392 |
+
},
|
| 393 |
+
"namespace_nested_inside_regular": {
|
| 394 |
+
"directory_structure": {
|
| 395 |
+
"foo": {
|
| 396 |
+
"namespace": {
|
| 397 |
+
"foo.pyi": "",
|
| 398 |
+
},
|
| 399 |
+
"__init__.pyi": "",
|
| 400 |
+
"py.typed": "",
|
| 401 |
+
}
|
| 402 |
+
},
|
| 403 |
+
"expected_type_files": {
|
| 404 |
+
"foo/namespace/foo.pyi",
|
| 405 |
+
"foo/__init__.pyi",
|
| 406 |
+
"foo/py.typed",
|
| 407 |
+
},
|
| 408 |
+
},
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
@pytest.mark.parametrize(
|
| 412 |
+
"pyproject",
|
| 413 |
+
[
|
| 414 |
+
"default_pyproject",
|
| 415 |
+
pytest.param(
|
| 416 |
+
"dont_include_package_data",
|
| 417 |
+
marks=pytest.mark.xfail(reason="pypa/setuptools#4350"),
|
| 418 |
+
),
|
| 419 |
+
],
|
| 420 |
+
)
|
| 421 |
+
@pytest.mark.parametrize("example", EXAMPLES.keys())
|
| 422 |
+
def test_type_files_included_by_default(self, tmpdir_cwd, pyproject, example):
|
| 423 |
+
structure = {
|
| 424 |
+
**self.EXAMPLES[example]["directory_structure"],
|
| 425 |
+
"pyproject.toml": self.PYPROJECTS[pyproject],
|
| 426 |
+
}
|
| 427 |
+
expected_type_files = self.EXAMPLES[example]["expected_type_files"]
|
| 428 |
+
jaraco.path.build(structure)
|
| 429 |
+
|
| 430 |
+
build_py = get_finalized_build_py()
|
| 431 |
+
outputs = get_outputs(build_py)
|
| 432 |
+
assert expected_type_files <= outputs
|
| 433 |
+
|
| 434 |
+
@pytest.mark.parametrize("pyproject", ["exclude_type_info"])
|
| 435 |
+
@pytest.mark.parametrize("example", EXAMPLES.keys())
|
| 436 |
+
def test_type_files_can_be_excluded(self, tmpdir_cwd, pyproject, example):
|
| 437 |
+
structure = {
|
| 438 |
+
**self.EXAMPLES[example]["directory_structure"],
|
| 439 |
+
"pyproject.toml": self.PYPROJECTS[pyproject],
|
| 440 |
+
}
|
| 441 |
+
expected_type_files = self.EXAMPLES[example]["expected_type_files"]
|
| 442 |
+
jaraco.path.build(structure)
|
| 443 |
+
|
| 444 |
+
build_py = get_finalized_build_py()
|
| 445 |
+
outputs = get_outputs(build_py)
|
| 446 |
+
assert expected_type_files.isdisjoint(outputs)
|
| 447 |
+
|
| 448 |
+
def test_stub_only_package(self, tmpdir_cwd):
|
| 449 |
+
structure = {
|
| 450 |
+
"pyproject.toml": DALS(
|
| 451 |
+
"""
|
| 452 |
+
[project]
|
| 453 |
+
name = "foo-stubs"
|
| 454 |
+
version = "1"
|
| 455 |
+
"""
|
| 456 |
+
),
|
| 457 |
+
"foo-stubs": {"__init__.pyi": "", "bar.pyi": ""},
|
| 458 |
+
}
|
| 459 |
+
expected_type_files = {"foo-stubs/__init__.pyi", "foo-stubs/bar.pyi"}
|
| 460 |
+
jaraco.path.build(structure)
|
| 461 |
+
|
| 462 |
+
build_py = get_finalized_build_py()
|
| 463 |
+
outputs = get_outputs(build_py)
|
| 464 |
+
assert expected_type_files <= outputs
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
def get_finalized_build_py(script_name="%build_py-test%"):
|
| 468 |
+
dist = Distribution({"script_name": script_name})
|
| 469 |
+
dist.parse_config_files()
|
| 470 |
+
build_py = dist.get_command_obj("build_py")
|
| 471 |
+
build_py.finalize_options()
|
| 472 |
+
return build_py
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
def get_outputs(build_py):
|
| 476 |
+
build_dir = Path(build_py.build_lib)
|
| 477 |
+
return {
|
| 478 |
+
os.path.relpath(x, build_dir).replace(os.sep, "/")
|
| 479 |
+
for x in build_py.get_outputs()
|
| 480 |
+
}
|
valley/lib/python3.10/site-packages/setuptools/tests/test_core_metadata.py
ADDED
|
@@ -0,0 +1,577 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import functools
|
| 4 |
+
import importlib
|
| 5 |
+
import io
|
| 6 |
+
from email import message_from_string
|
| 7 |
+
from email.generator import Generator
|
| 8 |
+
from email.message import EmailMessage, Message
|
| 9 |
+
from email.parser import Parser
|
| 10 |
+
from email.policy import EmailPolicy
|
| 11 |
+
from inspect import cleandoc
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
from unittest.mock import Mock
|
| 14 |
+
|
| 15 |
+
import pytest
|
| 16 |
+
from packaging.metadata import Metadata
|
| 17 |
+
from packaging.requirements import Requirement
|
| 18 |
+
|
| 19 |
+
from setuptools import _reqs, sic
|
| 20 |
+
from setuptools._core_metadata import rfc822_escape, rfc822_unescape
|
| 21 |
+
from setuptools.command.egg_info import egg_info, write_requirements
|
| 22 |
+
from setuptools.config import expand, setupcfg
|
| 23 |
+
from setuptools.dist import Distribution
|
| 24 |
+
|
| 25 |
+
from .config.downloads import retrieve_file, urls_from_file
|
| 26 |
+
|
| 27 |
+
EXAMPLE_BASE_INFO = dict(
|
| 28 |
+
name="package",
|
| 29 |
+
version="0.0.1",
|
| 30 |
+
author="Foo Bar",
|
| 31 |
+
author_email="foo@bar.net",
|
| 32 |
+
long_description="Long\ndescription",
|
| 33 |
+
description="Short description",
|
| 34 |
+
keywords=["one", "two"],
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@pytest.mark.parametrize(
|
| 39 |
+
("content", "result"),
|
| 40 |
+
(
|
| 41 |
+
pytest.param(
|
| 42 |
+
"Just a single line",
|
| 43 |
+
None,
|
| 44 |
+
id="single_line",
|
| 45 |
+
),
|
| 46 |
+
pytest.param(
|
| 47 |
+
"Multiline\nText\nwithout\nextra indents\n",
|
| 48 |
+
None,
|
| 49 |
+
id="multiline",
|
| 50 |
+
),
|
| 51 |
+
pytest.param(
|
| 52 |
+
"Multiline\n With\n\nadditional\n indentation",
|
| 53 |
+
None,
|
| 54 |
+
id="multiline_with_indentation",
|
| 55 |
+
),
|
| 56 |
+
pytest.param(
|
| 57 |
+
" Leading whitespace",
|
| 58 |
+
"Leading whitespace",
|
| 59 |
+
id="remove_leading_whitespace",
|
| 60 |
+
),
|
| 61 |
+
pytest.param(
|
| 62 |
+
" Leading whitespace\nIn\n Multiline comment",
|
| 63 |
+
"Leading whitespace\nIn\n Multiline comment",
|
| 64 |
+
id="remove_leading_whitespace_multiline",
|
| 65 |
+
),
|
| 66 |
+
),
|
| 67 |
+
)
|
| 68 |
+
def test_rfc822_unescape(content, result):
|
| 69 |
+
assert (result or content) == rfc822_unescape(rfc822_escape(content))
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def __read_test_cases():
|
| 73 |
+
base = EXAMPLE_BASE_INFO
|
| 74 |
+
|
| 75 |
+
params = functools.partial(dict, base)
|
| 76 |
+
|
| 77 |
+
return [
|
| 78 |
+
('Metadata version 1.0', params()),
|
| 79 |
+
(
|
| 80 |
+
'Metadata Version 1.0: Short long description',
|
| 81 |
+
params(
|
| 82 |
+
long_description='Short long description',
|
| 83 |
+
),
|
| 84 |
+
),
|
| 85 |
+
(
|
| 86 |
+
'Metadata version 1.1: Classifiers',
|
| 87 |
+
params(
|
| 88 |
+
classifiers=[
|
| 89 |
+
'Programming Language :: Python :: 3',
|
| 90 |
+
'Programming Language :: Python :: 3.7',
|
| 91 |
+
'License :: OSI Approved :: MIT License',
|
| 92 |
+
],
|
| 93 |
+
),
|
| 94 |
+
),
|
| 95 |
+
(
|
| 96 |
+
'Metadata version 1.1: Download URL',
|
| 97 |
+
params(
|
| 98 |
+
download_url='https://example.com',
|
| 99 |
+
),
|
| 100 |
+
),
|
| 101 |
+
(
|
| 102 |
+
'Metadata Version 1.2: Requires-Python',
|
| 103 |
+
params(
|
| 104 |
+
python_requires='>=3.7',
|
| 105 |
+
),
|
| 106 |
+
),
|
| 107 |
+
pytest.param(
|
| 108 |
+
'Metadata Version 1.2: Project-Url',
|
| 109 |
+
params(project_urls=dict(Foo='https://example.bar')),
|
| 110 |
+
marks=pytest.mark.xfail(
|
| 111 |
+
reason="Issue #1578: project_urls not read",
|
| 112 |
+
),
|
| 113 |
+
),
|
| 114 |
+
(
|
| 115 |
+
'Metadata Version 2.1: Long Description Content Type',
|
| 116 |
+
params(
|
| 117 |
+
long_description_content_type='text/x-rst; charset=UTF-8',
|
| 118 |
+
),
|
| 119 |
+
),
|
| 120 |
+
(
|
| 121 |
+
'License',
|
| 122 |
+
params(
|
| 123 |
+
license='MIT',
|
| 124 |
+
),
|
| 125 |
+
),
|
| 126 |
+
(
|
| 127 |
+
'License multiline',
|
| 128 |
+
params(
|
| 129 |
+
license='This is a long license \nover multiple lines',
|
| 130 |
+
),
|
| 131 |
+
),
|
| 132 |
+
pytest.param(
|
| 133 |
+
'Metadata Version 2.1: Provides Extra',
|
| 134 |
+
params(provides_extras=['foo', 'bar']),
|
| 135 |
+
marks=pytest.mark.xfail(reason="provides_extras not read"),
|
| 136 |
+
),
|
| 137 |
+
(
|
| 138 |
+
'Missing author',
|
| 139 |
+
dict(
|
| 140 |
+
name='foo',
|
| 141 |
+
version='1.0.0',
|
| 142 |
+
author_email='snorri@sturluson.name',
|
| 143 |
+
),
|
| 144 |
+
),
|
| 145 |
+
(
|
| 146 |
+
'Missing author e-mail',
|
| 147 |
+
dict(
|
| 148 |
+
name='foo',
|
| 149 |
+
version='1.0.0',
|
| 150 |
+
author='Snorri Sturluson',
|
| 151 |
+
),
|
| 152 |
+
),
|
| 153 |
+
(
|
| 154 |
+
'Missing author and e-mail',
|
| 155 |
+
dict(
|
| 156 |
+
name='foo',
|
| 157 |
+
version='1.0.0',
|
| 158 |
+
),
|
| 159 |
+
),
|
| 160 |
+
(
|
| 161 |
+
'Bypass normalized version',
|
| 162 |
+
dict(
|
| 163 |
+
name='foo',
|
| 164 |
+
version=sic('1.0.0a'),
|
| 165 |
+
),
|
| 166 |
+
),
|
| 167 |
+
]
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
@pytest.mark.parametrize(("name", "attrs"), __read_test_cases())
|
| 171 |
+
def test_read_metadata(name, attrs):
|
| 172 |
+
dist = Distribution(attrs)
|
| 173 |
+
metadata_out = dist.metadata
|
| 174 |
+
dist_class = metadata_out.__class__
|
| 175 |
+
|
| 176 |
+
# Write to PKG_INFO and then load into a new metadata object
|
| 177 |
+
PKG_INFO = io.StringIO()
|
| 178 |
+
|
| 179 |
+
metadata_out.write_pkg_file(PKG_INFO)
|
| 180 |
+
PKG_INFO.seek(0)
|
| 181 |
+
pkg_info = PKG_INFO.read()
|
| 182 |
+
assert _valid_metadata(pkg_info)
|
| 183 |
+
|
| 184 |
+
PKG_INFO.seek(0)
|
| 185 |
+
metadata_in = dist_class()
|
| 186 |
+
metadata_in.read_pkg_file(PKG_INFO)
|
| 187 |
+
|
| 188 |
+
tested_attrs = [
|
| 189 |
+
('name', dist_class.get_name),
|
| 190 |
+
('version', dist_class.get_version),
|
| 191 |
+
('author', dist_class.get_contact),
|
| 192 |
+
('author_email', dist_class.get_contact_email),
|
| 193 |
+
('metadata_version', dist_class.get_metadata_version),
|
| 194 |
+
('provides', dist_class.get_provides),
|
| 195 |
+
('description', dist_class.get_description),
|
| 196 |
+
('long_description', dist_class.get_long_description),
|
| 197 |
+
('download_url', dist_class.get_download_url),
|
| 198 |
+
('keywords', dist_class.get_keywords),
|
| 199 |
+
('platforms', dist_class.get_platforms),
|
| 200 |
+
('obsoletes', dist_class.get_obsoletes),
|
| 201 |
+
('requires', dist_class.get_requires),
|
| 202 |
+
('classifiers', dist_class.get_classifiers),
|
| 203 |
+
('project_urls', lambda s: getattr(s, 'project_urls', {})),
|
| 204 |
+
('provides_extras', lambda s: getattr(s, 'provides_extras', {})),
|
| 205 |
+
]
|
| 206 |
+
|
| 207 |
+
for attr, getter in tested_attrs:
|
| 208 |
+
assert getter(metadata_in) == getter(metadata_out)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def __maintainer_test_cases():
|
| 212 |
+
attrs = {"name": "package", "version": "1.0", "description": "xxx"}
|
| 213 |
+
|
| 214 |
+
def merge_dicts(d1, d2):
|
| 215 |
+
d1 = d1.copy()
|
| 216 |
+
d1.update(d2)
|
| 217 |
+
|
| 218 |
+
return d1
|
| 219 |
+
|
| 220 |
+
return [
|
| 221 |
+
('No author, no maintainer', attrs.copy()),
|
| 222 |
+
(
|
| 223 |
+
'Author (no e-mail), no maintainer',
|
| 224 |
+
merge_dicts(attrs, {'author': 'Author Name'}),
|
| 225 |
+
),
|
| 226 |
+
(
|
| 227 |
+
'Author (e-mail), no maintainer',
|
| 228 |
+
merge_dicts(
|
| 229 |
+
attrs, {'author': 'Author Name', 'author_email': 'author@name.com'}
|
| 230 |
+
),
|
| 231 |
+
),
|
| 232 |
+
(
|
| 233 |
+
'No author, maintainer (no e-mail)',
|
| 234 |
+
merge_dicts(attrs, {'maintainer': 'Maintainer Name'}),
|
| 235 |
+
),
|
| 236 |
+
(
|
| 237 |
+
'No author, maintainer (e-mail)',
|
| 238 |
+
merge_dicts(
|
| 239 |
+
attrs,
|
| 240 |
+
{
|
| 241 |
+
'maintainer': 'Maintainer Name',
|
| 242 |
+
'maintainer_email': 'maintainer@name.com',
|
| 243 |
+
},
|
| 244 |
+
),
|
| 245 |
+
),
|
| 246 |
+
(
|
| 247 |
+
'Author (no e-mail), Maintainer (no-email)',
|
| 248 |
+
merge_dicts(
|
| 249 |
+
attrs, {'author': 'Author Name', 'maintainer': 'Maintainer Name'}
|
| 250 |
+
),
|
| 251 |
+
),
|
| 252 |
+
(
|
| 253 |
+
'Author (e-mail), Maintainer (e-mail)',
|
| 254 |
+
merge_dicts(
|
| 255 |
+
attrs,
|
| 256 |
+
{
|
| 257 |
+
'author': 'Author Name',
|
| 258 |
+
'author_email': 'author@name.com',
|
| 259 |
+
'maintainer': 'Maintainer Name',
|
| 260 |
+
'maintainer_email': 'maintainer@name.com',
|
| 261 |
+
},
|
| 262 |
+
),
|
| 263 |
+
),
|
| 264 |
+
(
|
| 265 |
+
'No author (e-mail), no maintainer (e-mail)',
|
| 266 |
+
merge_dicts(
|
| 267 |
+
attrs,
|
| 268 |
+
{
|
| 269 |
+
'author_email': 'author@name.com',
|
| 270 |
+
'maintainer_email': 'maintainer@name.com',
|
| 271 |
+
},
|
| 272 |
+
),
|
| 273 |
+
),
|
| 274 |
+
('Author unicode', merge_dicts(attrs, {'author': '鉄沢寛'})),
|
| 275 |
+
('Maintainer unicode', merge_dicts(attrs, {'maintainer': 'Jan Łukasiewicz'})),
|
| 276 |
+
]
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
@pytest.mark.parametrize(("name", "attrs"), __maintainer_test_cases())
|
| 280 |
+
def test_maintainer_author(name, attrs, tmpdir):
|
| 281 |
+
tested_keys = {
|
| 282 |
+
'author': 'Author',
|
| 283 |
+
'author_email': 'Author-email',
|
| 284 |
+
'maintainer': 'Maintainer',
|
| 285 |
+
'maintainer_email': 'Maintainer-email',
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
# Generate a PKG-INFO file
|
| 289 |
+
dist = Distribution(attrs)
|
| 290 |
+
fn = tmpdir.mkdir('pkg_info')
|
| 291 |
+
fn_s = str(fn)
|
| 292 |
+
|
| 293 |
+
dist.metadata.write_pkg_info(fn_s)
|
| 294 |
+
|
| 295 |
+
with open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f:
|
| 296 |
+
pkg_info = f.read()
|
| 297 |
+
|
| 298 |
+
assert _valid_metadata(pkg_info)
|
| 299 |
+
|
| 300 |
+
# Drop blank lines and strip lines from default description
|
| 301 |
+
raw_pkg_lines = pkg_info.splitlines()
|
| 302 |
+
pkg_lines = list(filter(None, raw_pkg_lines[:-2]))
|
| 303 |
+
|
| 304 |
+
pkg_lines_set = set(pkg_lines)
|
| 305 |
+
|
| 306 |
+
# Duplicate lines should not be generated
|
| 307 |
+
assert len(pkg_lines) == len(pkg_lines_set)
|
| 308 |
+
|
| 309 |
+
for fkey, dkey in tested_keys.items():
|
| 310 |
+
val = attrs.get(dkey, None)
|
| 311 |
+
if val is None:
|
| 312 |
+
for line in pkg_lines:
|
| 313 |
+
assert not line.startswith(fkey + ':')
|
| 314 |
+
else:
|
| 315 |
+
line = f'{fkey}: {val}'
|
| 316 |
+
assert line in pkg_lines_set
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
class TestParityWithMetadataFromPyPaWheel:
|
| 320 |
+
def base_example(self):
|
| 321 |
+
attrs = dict(
|
| 322 |
+
**EXAMPLE_BASE_INFO,
|
| 323 |
+
# Example with complex requirement definition
|
| 324 |
+
python_requires=">=3.8",
|
| 325 |
+
install_requires="""
|
| 326 |
+
packaging==23.2
|
| 327 |
+
more-itertools==8.8.0; extra == "other"
|
| 328 |
+
jaraco.text==3.7.0
|
| 329 |
+
importlib-resources==5.10.2; python_version<"3.8"
|
| 330 |
+
importlib-metadata==6.0.0 ; python_version<"3.8"
|
| 331 |
+
colorama>=0.4.4; sys_platform == "win32"
|
| 332 |
+
""",
|
| 333 |
+
extras_require={
|
| 334 |
+
"testing": """
|
| 335 |
+
pytest >= 6
|
| 336 |
+
pytest-checkdocs >= 2.4
|
| 337 |
+
tomli ; \\
|
| 338 |
+
# Using stdlib when possible
|
| 339 |
+
python_version < "3.11"
|
| 340 |
+
ini2toml[lite]>=0.9
|
| 341 |
+
""",
|
| 342 |
+
"other": [],
|
| 343 |
+
},
|
| 344 |
+
)
|
| 345 |
+
# Generate a PKG-INFO file using setuptools
|
| 346 |
+
return Distribution(attrs)
|
| 347 |
+
|
| 348 |
+
def test_requires_dist(self, tmp_path):
|
| 349 |
+
dist = self.base_example()
|
| 350 |
+
pkg_info = _get_pkginfo(dist)
|
| 351 |
+
assert _valid_metadata(pkg_info)
|
| 352 |
+
|
| 353 |
+
# Ensure Requires-Dist is present
|
| 354 |
+
expected = [
|
| 355 |
+
'Metadata-Version:',
|
| 356 |
+
'Requires-Python: >=3.8',
|
| 357 |
+
'Provides-Extra: other',
|
| 358 |
+
'Provides-Extra: testing',
|
| 359 |
+
'Requires-Dist: tomli; python_version < "3.11" and extra == "testing"',
|
| 360 |
+
'Requires-Dist: more-itertools==8.8.0; extra == "other"',
|
| 361 |
+
'Requires-Dist: ini2toml[lite]>=0.9; extra == "testing"',
|
| 362 |
+
]
|
| 363 |
+
for line in expected:
|
| 364 |
+
assert line in pkg_info
|
| 365 |
+
|
| 366 |
+
HERE = Path(__file__).parent
|
| 367 |
+
EXAMPLES_FILE = HERE / "config/setupcfg_examples.txt"
|
| 368 |
+
|
| 369 |
+
@pytest.fixture(params=[None, *urls_from_file(EXAMPLES_FILE)])
|
| 370 |
+
def dist(self, request, monkeypatch, tmp_path):
|
| 371 |
+
"""Example of distribution with arbitrary configuration"""
|
| 372 |
+
monkeypatch.chdir(tmp_path)
|
| 373 |
+
monkeypatch.setattr(expand, "read_attr", Mock(return_value="0.42"))
|
| 374 |
+
monkeypatch.setattr(expand, "read_files", Mock(return_value="hello world"))
|
| 375 |
+
if request.param is None:
|
| 376 |
+
yield self.base_example()
|
| 377 |
+
else:
|
| 378 |
+
# Real-world usage
|
| 379 |
+
config = retrieve_file(request.param)
|
| 380 |
+
yield setupcfg.apply_configuration(Distribution({}), config)
|
| 381 |
+
|
| 382 |
+
@pytest.mark.uses_network
|
| 383 |
+
def test_equivalent_output(self, tmp_path, dist):
|
| 384 |
+
"""Ensure output from setuptools is equivalent to the one from `pypa/wheel`"""
|
| 385 |
+
# Generate a METADATA file using pypa/wheel for comparison
|
| 386 |
+
wheel_metadata = importlib.import_module("wheel.metadata")
|
| 387 |
+
pkginfo_to_metadata = getattr(wheel_metadata, "pkginfo_to_metadata", None)
|
| 388 |
+
|
| 389 |
+
if pkginfo_to_metadata is None: # pragma: nocover
|
| 390 |
+
pytest.xfail(
|
| 391 |
+
"wheel.metadata.pkginfo_to_metadata is undefined, "
|
| 392 |
+
"(this is likely to be caused by API changes in pypa/wheel"
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
# Generate an simplified "egg-info" dir for pypa/wheel to convert
|
| 396 |
+
pkg_info = _get_pkginfo(dist)
|
| 397 |
+
egg_info_dir = tmp_path / "pkg.egg-info"
|
| 398 |
+
egg_info_dir.mkdir(parents=True)
|
| 399 |
+
(egg_info_dir / "PKG-INFO").write_text(pkg_info, encoding="utf-8")
|
| 400 |
+
write_requirements(egg_info(dist), egg_info_dir, egg_info_dir / "requires.txt")
|
| 401 |
+
|
| 402 |
+
# Get pypa/wheel generated METADATA but normalize requirements formatting
|
| 403 |
+
metadata_msg = pkginfo_to_metadata(egg_info_dir, egg_info_dir / "PKG-INFO")
|
| 404 |
+
metadata_str = _normalize_metadata(metadata_msg)
|
| 405 |
+
pkg_info_msg = message_from_string(pkg_info)
|
| 406 |
+
pkg_info_str = _normalize_metadata(pkg_info_msg)
|
| 407 |
+
|
| 408 |
+
# Compare setuptools PKG-INFO x pypa/wheel METADATA
|
| 409 |
+
assert metadata_str == pkg_info_str
|
| 410 |
+
|
| 411 |
+
# Make sure it parses/serializes well in pypa/wheel
|
| 412 |
+
_assert_roundtrip_message(pkg_info)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
class TestPEP643:
|
| 416 |
+
STATIC_CONFIG = {
|
| 417 |
+
"setup.cfg": cleandoc(
|
| 418 |
+
"""
|
| 419 |
+
[metadata]
|
| 420 |
+
name = package
|
| 421 |
+
version = 0.0.1
|
| 422 |
+
author = Foo Bar
|
| 423 |
+
author_email = foo@bar.net
|
| 424 |
+
long_description = Long
|
| 425 |
+
description
|
| 426 |
+
description = Short description
|
| 427 |
+
keywords = one, two
|
| 428 |
+
platforms = abcd
|
| 429 |
+
[options]
|
| 430 |
+
install_requires = requests
|
| 431 |
+
"""
|
| 432 |
+
),
|
| 433 |
+
"pyproject.toml": cleandoc(
|
| 434 |
+
"""
|
| 435 |
+
[project]
|
| 436 |
+
name = "package"
|
| 437 |
+
version = "0.0.1"
|
| 438 |
+
authors = [
|
| 439 |
+
{name = "Foo Bar", email = "foo@bar.net"}
|
| 440 |
+
]
|
| 441 |
+
description = "Short description"
|
| 442 |
+
readme = {text = "Long\\ndescription", content-type = "text/plain"}
|
| 443 |
+
keywords = ["one", "two"]
|
| 444 |
+
dependencies = ["requests"]
|
| 445 |
+
[tool.setuptools]
|
| 446 |
+
provides = ["abcd"]
|
| 447 |
+
obsoletes = ["abcd"]
|
| 448 |
+
"""
|
| 449 |
+
),
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
@pytest.mark.parametrize("file", STATIC_CONFIG.keys())
|
| 453 |
+
def test_static_config_has_no_dynamic(self, file, tmpdir_cwd):
|
| 454 |
+
Path(file).write_text(self.STATIC_CONFIG[file], encoding="utf-8")
|
| 455 |
+
metadata = _get_metadata()
|
| 456 |
+
assert metadata.get_all("Dynamic") is None
|
| 457 |
+
assert metadata.get_all("dynamic") is None
|
| 458 |
+
|
| 459 |
+
@pytest.mark.parametrize("file", STATIC_CONFIG.keys())
|
| 460 |
+
@pytest.mark.parametrize(
|
| 461 |
+
"fields",
|
| 462 |
+
[
|
| 463 |
+
# Single dynamic field
|
| 464 |
+
{"requires-python": ("python_requires", ">=3.12")},
|
| 465 |
+
{"author-email": ("author_email", "snoopy@peanuts.com")},
|
| 466 |
+
{"keywords": ("keywords", ["hello", "world"])},
|
| 467 |
+
{"platform": ("platforms", ["abcd"])},
|
| 468 |
+
# Multiple dynamic fields
|
| 469 |
+
{
|
| 470 |
+
"summary": ("description", "hello world"),
|
| 471 |
+
"description": ("long_description", "bla bla bla bla"),
|
| 472 |
+
"requires-dist": ("install_requires", ["hello-world"]),
|
| 473 |
+
},
|
| 474 |
+
],
|
| 475 |
+
)
|
| 476 |
+
def test_modified_fields_marked_as_dynamic(self, file, fields, tmpdir_cwd):
|
| 477 |
+
# We start with a static config
|
| 478 |
+
Path(file).write_text(self.STATIC_CONFIG[file], encoding="utf-8")
|
| 479 |
+
dist = _makedist()
|
| 480 |
+
|
| 481 |
+
# ... but then we simulate the effects of a plugin modifying the distribution
|
| 482 |
+
for attr, value in fields.values():
|
| 483 |
+
# `dist` and `dist.metadata` are complicated...
|
| 484 |
+
# Some attributes work when set on `dist`, others on `dist.metadata`...
|
| 485 |
+
# Here we set in both just in case (this also avoids calling `_finalize_*`)
|
| 486 |
+
setattr(dist, attr, value)
|
| 487 |
+
setattr(dist.metadata, attr, value)
|
| 488 |
+
|
| 489 |
+
# Then we should be able to list the modified fields as Dynamic
|
| 490 |
+
metadata = _get_metadata(dist)
|
| 491 |
+
assert set(metadata.get_all("Dynamic")) == set(fields)
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def _makedist(**attrs):
|
| 495 |
+
dist = Distribution(attrs)
|
| 496 |
+
dist.parse_config_files()
|
| 497 |
+
return dist
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
def _assert_roundtrip_message(metadata: str) -> None:
|
| 501 |
+
"""Emulate the way wheel.bdist_wheel parses and regenerates the message,
|
| 502 |
+
then ensures the metadata generated by setuptools is compatible.
|
| 503 |
+
"""
|
| 504 |
+
with io.StringIO(metadata) as buffer:
|
| 505 |
+
msg = Parser(EmailMessage).parse(buffer)
|
| 506 |
+
|
| 507 |
+
serialization_policy = EmailPolicy(
|
| 508 |
+
utf8=True,
|
| 509 |
+
mangle_from_=False,
|
| 510 |
+
max_line_length=0,
|
| 511 |
+
)
|
| 512 |
+
with io.BytesIO() as buffer:
|
| 513 |
+
out = io.TextIOWrapper(buffer, encoding="utf-8")
|
| 514 |
+
Generator(out, policy=serialization_policy).flatten(msg)
|
| 515 |
+
out.flush()
|
| 516 |
+
regenerated = buffer.getvalue()
|
| 517 |
+
|
| 518 |
+
raw_metadata = bytes(metadata, "utf-8")
|
| 519 |
+
# Normalise newlines to avoid test errors on Windows:
|
| 520 |
+
raw_metadata = b"\n".join(raw_metadata.splitlines())
|
| 521 |
+
regenerated = b"\n".join(regenerated.splitlines())
|
| 522 |
+
assert regenerated == raw_metadata
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
def _normalize_metadata(msg: Message) -> str:
|
| 526 |
+
"""Allow equivalent metadata to be compared directly"""
|
| 527 |
+
# The main challenge regards the requirements and extras.
|
| 528 |
+
# Both setuptools and wheel already apply some level of normalization
|
| 529 |
+
# but they differ regarding which character is chosen, according to the
|
| 530 |
+
# following spec it should be "-":
|
| 531 |
+
# https://packaging.python.org/en/latest/specifications/name-normalization/
|
| 532 |
+
|
| 533 |
+
# Related issues:
|
| 534 |
+
# https://github.com/pypa/packaging/issues/845
|
| 535 |
+
# https://github.com/pypa/packaging/issues/644#issuecomment-2429813968
|
| 536 |
+
|
| 537 |
+
extras = {x.replace("_", "-"): x for x in msg.get_all("Provides-Extra", [])}
|
| 538 |
+
reqs = [
|
| 539 |
+
_normalize_req(req, extras)
|
| 540 |
+
for req in _reqs.parse(msg.get_all("Requires-Dist", []))
|
| 541 |
+
]
|
| 542 |
+
del msg["Requires-Dist"]
|
| 543 |
+
del msg["Provides-Extra"]
|
| 544 |
+
|
| 545 |
+
# Ensure consistent ord
|
| 546 |
+
for req in sorted(reqs):
|
| 547 |
+
msg["Requires-Dist"] = req
|
| 548 |
+
for extra in sorted(extras):
|
| 549 |
+
msg["Provides-Extra"] = extra
|
| 550 |
+
|
| 551 |
+
# TODO: Handle lack of PEP 643 implementation in pypa/wheel?
|
| 552 |
+
del msg["Metadata-Version"]
|
| 553 |
+
|
| 554 |
+
return msg.as_string()
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
def _normalize_req(req: Requirement, extras: dict[str, str]) -> str:
|
| 558 |
+
"""Allow equivalent requirement objects to be compared directly"""
|
| 559 |
+
as_str = str(req).replace(req.name, req.name.replace("_", "-"))
|
| 560 |
+
for norm, orig in extras.items():
|
| 561 |
+
as_str = as_str.replace(orig, norm)
|
| 562 |
+
return as_str
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def _get_pkginfo(dist: Distribution):
|
| 566 |
+
with io.StringIO() as fp:
|
| 567 |
+
dist.metadata.write_pkg_file(fp)
|
| 568 |
+
return fp.getvalue()
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def _get_metadata(dist: Distribution | None = None):
|
| 572 |
+
return message_from_string(_get_pkginfo(dist or _makedist()))
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
def _valid_metadata(text: str) -> bool:
|
| 576 |
+
metadata = Metadata.from_email(text, validate=True) # can raise exceptions
|
| 577 |
+
return metadata is not None
|
valley/lib/python3.10/site-packages/setuptools/tests/test_depends.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
from setuptools import depends
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class TestGetModuleConstant:
|
| 7 |
+
def test_basic(self):
|
| 8 |
+
"""
|
| 9 |
+
Invoke get_module_constant on a module in
|
| 10 |
+
the test package.
|
| 11 |
+
"""
|
| 12 |
+
mod_name = 'setuptools.tests.mod_with_constant'
|
| 13 |
+
val = depends.get_module_constant(mod_name, 'value')
|
| 14 |
+
assert val == 'three, sir!'
|
| 15 |
+
assert 'setuptools.tests.mod_with_constant' not in sys.modules
|
valley/lib/python3.10/site-packages/setuptools/tests/test_develop.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""develop tests"""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import platform
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
from setuptools._path import paths_on_pythonpath
|
| 12 |
+
from setuptools.command.develop import develop
|
| 13 |
+
from setuptools.dist import Distribution
|
| 14 |
+
|
| 15 |
+
from . import contexts, namespaces
|
| 16 |
+
|
| 17 |
+
SETUP_PY = """\
|
| 18 |
+
from setuptools import setup
|
| 19 |
+
|
| 20 |
+
setup(name='foo',
|
| 21 |
+
packages=['foo'],
|
| 22 |
+
)
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
INIT_PY = """print "foo"
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@pytest.fixture
|
| 30 |
+
def temp_user(monkeypatch):
|
| 31 |
+
with contexts.tempdir() as user_base:
|
| 32 |
+
with contexts.tempdir() as user_site:
|
| 33 |
+
monkeypatch.setattr('site.USER_BASE', user_base)
|
| 34 |
+
monkeypatch.setattr('site.USER_SITE', user_site)
|
| 35 |
+
yield
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@pytest.fixture
|
| 39 |
+
def test_env(tmpdir, temp_user):
|
| 40 |
+
target = tmpdir
|
| 41 |
+
foo = target.mkdir('foo')
|
| 42 |
+
setup = target / 'setup.py'
|
| 43 |
+
if setup.isfile():
|
| 44 |
+
raise ValueError(dir(target))
|
| 45 |
+
with setup.open('w') as f:
|
| 46 |
+
f.write(SETUP_PY)
|
| 47 |
+
init = foo / '__init__.py'
|
| 48 |
+
with init.open('w') as f:
|
| 49 |
+
f.write(INIT_PY)
|
| 50 |
+
with target.as_cwd():
|
| 51 |
+
yield target
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class TestDevelop:
|
| 55 |
+
in_virtualenv = hasattr(sys, 'real_prefix')
|
| 56 |
+
in_venv = hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix
|
| 57 |
+
|
| 58 |
+
def test_console_scripts(self, tmpdir):
|
| 59 |
+
"""
|
| 60 |
+
Test that console scripts are installed and that they reference
|
| 61 |
+
only the project by name and not the current version.
|
| 62 |
+
"""
|
| 63 |
+
pytest.skip(
|
| 64 |
+
"TODO: needs a fixture to cause 'develop' "
|
| 65 |
+
"to be invoked without mutating environment."
|
| 66 |
+
)
|
| 67 |
+
settings = dict(
|
| 68 |
+
name='foo',
|
| 69 |
+
packages=['foo'],
|
| 70 |
+
version='0.0',
|
| 71 |
+
entry_points={
|
| 72 |
+
'console_scripts': [
|
| 73 |
+
'foocmd = foo:foo',
|
| 74 |
+
],
|
| 75 |
+
},
|
| 76 |
+
)
|
| 77 |
+
dist = Distribution(settings)
|
| 78 |
+
dist.script_name = 'setup.py'
|
| 79 |
+
cmd = develop(dist)
|
| 80 |
+
cmd.ensure_finalized()
|
| 81 |
+
cmd.install_dir = tmpdir
|
| 82 |
+
cmd.run()
|
| 83 |
+
# assert '0.0' not in foocmd_text
|
| 84 |
+
|
| 85 |
+
@pytest.mark.xfail(reason="legacy behavior retained for compatibility #4167")
|
| 86 |
+
def test_egg_link_filename(self):
|
| 87 |
+
settings = dict(
|
| 88 |
+
name='Foo $$$ Bar_baz-bing',
|
| 89 |
+
)
|
| 90 |
+
dist = Distribution(settings)
|
| 91 |
+
cmd = develop(dist)
|
| 92 |
+
cmd.ensure_finalized()
|
| 93 |
+
link = pathlib.Path(cmd.egg_link)
|
| 94 |
+
assert link.suffix == '.egg-link'
|
| 95 |
+
assert link.stem == 'Foo_Bar_baz_bing'
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class TestResolver:
|
| 99 |
+
"""
|
| 100 |
+
TODO: These tests were written with a minimal understanding
|
| 101 |
+
of what _resolve_setup_path is intending to do. Come up with
|
| 102 |
+
more meaningful cases that look like real-world scenarios.
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
def test_resolve_setup_path_cwd(self):
|
| 106 |
+
assert develop._resolve_setup_path('.', '.', '.') == '.'
|
| 107 |
+
|
| 108 |
+
def test_resolve_setup_path_one_dir(self):
|
| 109 |
+
assert develop._resolve_setup_path('pkgs', '.', 'pkgs') == '../'
|
| 110 |
+
|
| 111 |
+
def test_resolve_setup_path_one_dir_trailing_slash(self):
|
| 112 |
+
assert develop._resolve_setup_path('pkgs/', '.', 'pkgs') == '../'
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class TestNamespaces:
|
| 116 |
+
@staticmethod
|
| 117 |
+
def install_develop(src_dir, target):
|
| 118 |
+
develop_cmd = [
|
| 119 |
+
sys.executable,
|
| 120 |
+
'setup.py',
|
| 121 |
+
'develop',
|
| 122 |
+
'--install-dir',
|
| 123 |
+
str(target),
|
| 124 |
+
]
|
| 125 |
+
with src_dir.as_cwd():
|
| 126 |
+
with paths_on_pythonpath([str(target)]):
|
| 127 |
+
subprocess.check_call(develop_cmd)
|
| 128 |
+
|
| 129 |
+
@pytest.mark.skipif(
|
| 130 |
+
bool(os.environ.get("APPVEYOR")),
|
| 131 |
+
reason="https://github.com/pypa/setuptools/issues/851",
|
| 132 |
+
)
|
| 133 |
+
@pytest.mark.skipif(
|
| 134 |
+
platform.python_implementation() == 'PyPy',
|
| 135 |
+
reason="https://github.com/pypa/setuptools/issues/1202",
|
| 136 |
+
)
|
| 137 |
+
def test_namespace_package_importable(self, tmpdir):
|
| 138 |
+
"""
|
| 139 |
+
Installing two packages sharing the same namespace, one installed
|
| 140 |
+
naturally using pip or `--single-version-externally-managed`
|
| 141 |
+
and the other installed using `develop` should leave the namespace
|
| 142 |
+
in tact and both packages reachable by import.
|
| 143 |
+
"""
|
| 144 |
+
pkg_A = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')
|
| 145 |
+
pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB')
|
| 146 |
+
target = tmpdir / 'packages'
|
| 147 |
+
# use pip to install to the target directory
|
| 148 |
+
install_cmd = [
|
| 149 |
+
sys.executable,
|
| 150 |
+
'-m',
|
| 151 |
+
'pip',
|
| 152 |
+
'install',
|
| 153 |
+
str(pkg_A),
|
| 154 |
+
'-t',
|
| 155 |
+
str(target),
|
| 156 |
+
]
|
| 157 |
+
subprocess.check_call(install_cmd)
|
| 158 |
+
self.install_develop(pkg_B, target)
|
| 159 |
+
namespaces.make_site_dir(target)
|
| 160 |
+
try_import = [
|
| 161 |
+
sys.executable,
|
| 162 |
+
'-c',
|
| 163 |
+
'import myns.pkgA; import myns.pkgB',
|
| 164 |
+
]
|
| 165 |
+
with paths_on_pythonpath([str(target)]):
|
| 166 |
+
subprocess.check_call(try_import)
|
| 167 |
+
|
| 168 |
+
# additionally ensure that pkg_resources import works
|
| 169 |
+
pkg_resources_imp = [
|
| 170 |
+
sys.executable,
|
| 171 |
+
'-c',
|
| 172 |
+
'import pkg_resources',
|
| 173 |
+
]
|
| 174 |
+
with paths_on_pythonpath([str(target)]):
|
| 175 |
+
subprocess.check_call(pkg_resources_imp)
|
valley/lib/python3.10/site-packages/setuptools/tests/test_dist.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 8 |
+
from setuptools import Distribution
|
| 9 |
+
from setuptools.dist import check_package_data, check_specifier
|
| 10 |
+
|
| 11 |
+
from .test_easy_install import make_nspkg_sdist
|
| 12 |
+
from .test_find_packages import ensure_files
|
| 13 |
+
from .textwrap import DALS
|
| 14 |
+
|
| 15 |
+
from distutils.errors import DistutilsSetupError
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def test_dist_fetch_build_egg(tmpdir):
|
| 19 |
+
"""
|
| 20 |
+
Check multiple calls to `Distribution.fetch_build_egg` work as expected.
|
| 21 |
+
"""
|
| 22 |
+
index = tmpdir.mkdir('index')
|
| 23 |
+
index_url = urllib.parse.urljoin('file://', urllib.request.pathname2url(str(index)))
|
| 24 |
+
|
| 25 |
+
def sdist_with_index(distname, version):
|
| 26 |
+
dist_dir = index.mkdir(distname)
|
| 27 |
+
dist_sdist = f'{distname}-{version}.tar.gz'
|
| 28 |
+
make_nspkg_sdist(str(dist_dir.join(dist_sdist)), distname, version)
|
| 29 |
+
with dist_dir.join('index.html').open('w') as fp:
|
| 30 |
+
fp.write(
|
| 31 |
+
DALS(
|
| 32 |
+
"""
|
| 33 |
+
<!DOCTYPE html><html><body>
|
| 34 |
+
<a href="{dist_sdist}" rel="internal">{dist_sdist}</a><br/>
|
| 35 |
+
</body></html>
|
| 36 |
+
"""
|
| 37 |
+
).format(dist_sdist=dist_sdist)
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
sdist_with_index('barbazquux', '3.2.0')
|
| 41 |
+
sdist_with_index('barbazquux-runner', '2.11.1')
|
| 42 |
+
with tmpdir.join('setup.cfg').open('w') as fp:
|
| 43 |
+
fp.write(
|
| 44 |
+
DALS(
|
| 45 |
+
"""
|
| 46 |
+
[easy_install]
|
| 47 |
+
index_url = {index_url}
|
| 48 |
+
"""
|
| 49 |
+
).format(index_url=index_url)
|
| 50 |
+
)
|
| 51 |
+
reqs = """
|
| 52 |
+
barbazquux-runner
|
| 53 |
+
barbazquux
|
| 54 |
+
""".split()
|
| 55 |
+
with tmpdir.as_cwd():
|
| 56 |
+
dist = Distribution()
|
| 57 |
+
dist.parse_config_files()
|
| 58 |
+
resolved_dists = [dist.fetch_build_egg(r) for r in reqs]
|
| 59 |
+
assert [dist.key for dist in resolved_dists if dist] == reqs
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
EXAMPLE_BASE_INFO = dict(
|
| 63 |
+
name="package",
|
| 64 |
+
version="0.0.1",
|
| 65 |
+
author="Foo Bar",
|
| 66 |
+
author_email="foo@bar.net",
|
| 67 |
+
long_description="Long\ndescription",
|
| 68 |
+
description="Short description",
|
| 69 |
+
keywords=["one", "two"],
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_provides_extras_deterministic_order():
|
| 74 |
+
attrs = dict(extras_require=dict(a=['foo'], b=['bar']))
|
| 75 |
+
dist = Distribution(attrs)
|
| 76 |
+
assert list(dist.metadata.provides_extras) == ['a', 'b']
|
| 77 |
+
attrs['extras_require'] = dict(reversed(attrs['extras_require'].items()))
|
| 78 |
+
dist = Distribution(attrs)
|
| 79 |
+
assert list(dist.metadata.provides_extras) == ['b', 'a']
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
CHECK_PACKAGE_DATA_TESTS = (
|
| 83 |
+
# Valid.
|
| 84 |
+
(
|
| 85 |
+
{
|
| 86 |
+
'': ['*.txt', '*.rst'],
|
| 87 |
+
'hello': ['*.msg'],
|
| 88 |
+
},
|
| 89 |
+
None,
|
| 90 |
+
),
|
| 91 |
+
# Not a dictionary.
|
| 92 |
+
(
|
| 93 |
+
(
|
| 94 |
+
('', ['*.txt', '*.rst']),
|
| 95 |
+
('hello', ['*.msg']),
|
| 96 |
+
),
|
| 97 |
+
(
|
| 98 |
+
"'package_data' must be a dictionary mapping package"
|
| 99 |
+
" names to lists of string wildcard patterns"
|
| 100 |
+
),
|
| 101 |
+
),
|
| 102 |
+
# Invalid key type.
|
| 103 |
+
(
|
| 104 |
+
{
|
| 105 |
+
400: ['*.txt', '*.rst'],
|
| 106 |
+
},
|
| 107 |
+
("keys of 'package_data' dict must be strings (got 400)"),
|
| 108 |
+
),
|
| 109 |
+
# Invalid value type.
|
| 110 |
+
(
|
| 111 |
+
{
|
| 112 |
+
'hello': '*.msg',
|
| 113 |
+
},
|
| 114 |
+
(
|
| 115 |
+
"\"values of 'package_data' dict\" must be of type <tuple[str, ...] | list[str]>"
|
| 116 |
+
" (got '*.msg')"
|
| 117 |
+
),
|
| 118 |
+
),
|
| 119 |
+
# Invalid value type (generators are single use)
|
| 120 |
+
(
|
| 121 |
+
{
|
| 122 |
+
'hello': (x for x in "generator"),
|
| 123 |
+
},
|
| 124 |
+
(
|
| 125 |
+
"\"values of 'package_data' dict\" must be of type <tuple[str, ...] | list[str]>"
|
| 126 |
+
" (got <generator object"
|
| 127 |
+
),
|
| 128 |
+
),
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
@pytest.mark.parametrize(('package_data', 'expected_message'), CHECK_PACKAGE_DATA_TESTS)
|
| 133 |
+
def test_check_package_data(package_data, expected_message):
|
| 134 |
+
if expected_message is None:
|
| 135 |
+
assert check_package_data(None, 'package_data', package_data) is None
|
| 136 |
+
else:
|
| 137 |
+
with pytest.raises(DistutilsSetupError, match=re.escape(expected_message)):
|
| 138 |
+
check_package_data(None, 'package_data', package_data)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def test_check_specifier():
|
| 142 |
+
# valid specifier value
|
| 143 |
+
attrs = {'name': 'foo', 'python_requires': '>=3.0, !=3.1'}
|
| 144 |
+
dist = Distribution(attrs)
|
| 145 |
+
check_specifier(dist, attrs, attrs['python_requires'])
|
| 146 |
+
|
| 147 |
+
attrs = {'name': 'foo', 'python_requires': ['>=3.0', '!=3.1']}
|
| 148 |
+
dist = Distribution(attrs)
|
| 149 |
+
check_specifier(dist, attrs, attrs['python_requires'])
|
| 150 |
+
|
| 151 |
+
# invalid specifier value
|
| 152 |
+
attrs = {'name': 'foo', 'python_requires': '>=invalid-version'}
|
| 153 |
+
with pytest.raises(DistutilsSetupError):
|
| 154 |
+
dist = Distribution(attrs)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def test_metadata_name():
|
| 158 |
+
with pytest.raises(DistutilsSetupError, match='missing.*name'):
|
| 159 |
+
Distribution()._validate_metadata()
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
@pytest.mark.parametrize(
|
| 163 |
+
('dist_name', 'py_module'),
|
| 164 |
+
[
|
| 165 |
+
("my.pkg", "my_pkg"),
|
| 166 |
+
("my-pkg", "my_pkg"),
|
| 167 |
+
("my_pkg", "my_pkg"),
|
| 168 |
+
("pkg", "pkg"),
|
| 169 |
+
],
|
| 170 |
+
)
|
| 171 |
+
def test_dist_default_py_modules(tmp_path, dist_name, py_module):
|
| 172 |
+
(tmp_path / f"{py_module}.py").touch()
|
| 173 |
+
|
| 174 |
+
(tmp_path / "setup.py").touch()
|
| 175 |
+
(tmp_path / "noxfile.py").touch()
|
| 176 |
+
# ^-- make sure common tool files are ignored
|
| 177 |
+
|
| 178 |
+
attrs = {**EXAMPLE_BASE_INFO, "name": dist_name, "src_root": str(tmp_path)}
|
| 179 |
+
# Find `py_modules` corresponding to dist_name if not given
|
| 180 |
+
dist = Distribution(attrs)
|
| 181 |
+
dist.set_defaults()
|
| 182 |
+
assert dist.py_modules == [py_module]
|
| 183 |
+
# When `py_modules` is given, don't do anything
|
| 184 |
+
dist = Distribution({**attrs, "py_modules": ["explicity_py_module"]})
|
| 185 |
+
dist.set_defaults()
|
| 186 |
+
assert dist.py_modules == ["explicity_py_module"]
|
| 187 |
+
# When `packages` is given, don't do anything
|
| 188 |
+
dist = Distribution({**attrs, "packages": ["explicity_package"]})
|
| 189 |
+
dist.set_defaults()
|
| 190 |
+
assert not dist.py_modules
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
@pytest.mark.parametrize(
|
| 194 |
+
('dist_name', 'package_dir', 'package_files', 'packages'),
|
| 195 |
+
[
|
| 196 |
+
("my.pkg", None, ["my_pkg/__init__.py", "my_pkg/mod.py"], ["my_pkg"]),
|
| 197 |
+
("my-pkg", None, ["my_pkg/__init__.py", "my_pkg/mod.py"], ["my_pkg"]),
|
| 198 |
+
("my_pkg", None, ["my_pkg/__init__.py", "my_pkg/mod.py"], ["my_pkg"]),
|
| 199 |
+
("my.pkg", None, ["my/pkg/__init__.py"], ["my", "my.pkg"]),
|
| 200 |
+
(
|
| 201 |
+
"my_pkg",
|
| 202 |
+
None,
|
| 203 |
+
["src/my_pkg/__init__.py", "src/my_pkg2/__init__.py"],
|
| 204 |
+
["my_pkg", "my_pkg2"],
|
| 205 |
+
),
|
| 206 |
+
(
|
| 207 |
+
"my_pkg",
|
| 208 |
+
{"pkg": "lib", "pkg2": "lib2"},
|
| 209 |
+
["lib/__init__.py", "lib/nested/__init__.pyt", "lib2/__init__.py"],
|
| 210 |
+
["pkg", "pkg.nested", "pkg2"],
|
| 211 |
+
),
|
| 212 |
+
],
|
| 213 |
+
)
|
| 214 |
+
def test_dist_default_packages(
|
| 215 |
+
tmp_path, dist_name, package_dir, package_files, packages
|
| 216 |
+
):
|
| 217 |
+
ensure_files(tmp_path, package_files)
|
| 218 |
+
|
| 219 |
+
(tmp_path / "setup.py").touch()
|
| 220 |
+
(tmp_path / "noxfile.py").touch()
|
| 221 |
+
# ^-- should not be included by default
|
| 222 |
+
|
| 223 |
+
attrs = {
|
| 224 |
+
**EXAMPLE_BASE_INFO,
|
| 225 |
+
"name": dist_name,
|
| 226 |
+
"src_root": str(tmp_path),
|
| 227 |
+
"package_dir": package_dir,
|
| 228 |
+
}
|
| 229 |
+
# Find `packages` either corresponding to dist_name or inside src
|
| 230 |
+
dist = Distribution(attrs)
|
| 231 |
+
dist.set_defaults()
|
| 232 |
+
assert not dist.py_modules
|
| 233 |
+
assert not dist.py_modules
|
| 234 |
+
assert set(dist.packages) == set(packages)
|
| 235 |
+
# When `py_modules` is given, don't do anything
|
| 236 |
+
dist = Distribution({**attrs, "py_modules": ["explicit_py_module"]})
|
| 237 |
+
dist.set_defaults()
|
| 238 |
+
assert not dist.packages
|
| 239 |
+
assert set(dist.py_modules) == {"explicit_py_module"}
|
| 240 |
+
# When `packages` is given, don't do anything
|
| 241 |
+
dist = Distribution({**attrs, "packages": ["explicit_package"]})
|
| 242 |
+
dist.set_defaults()
|
| 243 |
+
assert not dist.py_modules
|
| 244 |
+
assert set(dist.packages) == {"explicit_package"}
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
@pytest.mark.parametrize(
|
| 248 |
+
('dist_name', 'package_dir', 'package_files'),
|
| 249 |
+
[
|
| 250 |
+
("my.pkg.nested", None, ["my/pkg/nested/__init__.py"]),
|
| 251 |
+
("my.pkg", None, ["my/pkg/__init__.py", "my/pkg/file.py"]),
|
| 252 |
+
("my_pkg", None, ["my_pkg.py"]),
|
| 253 |
+
("my_pkg", None, ["my_pkg/__init__.py", "my_pkg/nested/__init__.py"]),
|
| 254 |
+
("my_pkg", None, ["src/my_pkg/__init__.py", "src/my_pkg/nested/__init__.py"]),
|
| 255 |
+
(
|
| 256 |
+
"my_pkg",
|
| 257 |
+
{"my_pkg": "lib", "my_pkg.lib2": "lib2"},
|
| 258 |
+
["lib/__init__.py", "lib/nested/__init__.pyt", "lib2/__init__.py"],
|
| 259 |
+
),
|
| 260 |
+
# Should not try to guess a name from multiple py_modules/packages
|
| 261 |
+
("UNKNOWN", None, ["src/mod1.py", "src/mod2.py"]),
|
| 262 |
+
("UNKNOWN", None, ["src/pkg1/__ini__.py", "src/pkg2/__init__.py"]),
|
| 263 |
+
],
|
| 264 |
+
)
|
| 265 |
+
def test_dist_default_name(tmp_path, dist_name, package_dir, package_files):
|
| 266 |
+
"""Make sure dist.name is discovered from packages/py_modules"""
|
| 267 |
+
ensure_files(tmp_path, package_files)
|
| 268 |
+
attrs = {
|
| 269 |
+
**EXAMPLE_BASE_INFO,
|
| 270 |
+
"src_root": "/".join(os.path.split(tmp_path)), # POSIX-style
|
| 271 |
+
"package_dir": package_dir,
|
| 272 |
+
}
|
| 273 |
+
del attrs["name"]
|
| 274 |
+
|
| 275 |
+
dist = Distribution(attrs)
|
| 276 |
+
dist.set_defaults()
|
| 277 |
+
assert dist.py_modules or dist.packages
|
| 278 |
+
assert dist.get_name() == dist_name
|