Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- videollama2/lib/python3.10/site-packages/setuptools/tests/__pycache__/test_core_metadata.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/__init__.py +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_apply_pyprojecttoml.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_expand.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_pyprojecttoml.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_pyprojecttoml_dynamic_deps.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/downloads/__init__.py +59 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/downloads/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/config/downloads/__pycache__/preload.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/contexts.py +145 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/environment.py +95 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/integration/__init__.py +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/integration/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/integration/helpers.py +77 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_bdist_deprecations.py +28 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_bdist_wheel.py +623 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_build_clib.py +84 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_build_ext.py +293 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_config_discovery.py +647 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_dist.py +278 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_distutils_adoption.py +198 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_easy_install.py +1472 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_egg_info.py +1280 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_extern.py +15 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_find_packages.py +218 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_find_py_modules.py +73 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_install_scripts.py +89 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_logging.py +76 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_manifest.py +622 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_setopt.py +40 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_setuptools.py +290 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_virtualenv.py +113 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_warnings.py +106 -0
- videollama2/lib/python3.10/site-packages/setuptools/tests/test_windows_wrappers.py +259 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h +25 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_req.h +29 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_resp.h +23 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_req.h +42 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_resp.h +24 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_autograd.h +98 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_req.h +62 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_resp.h +59 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rref_backward_resp.h +21 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/CUDASymmetricMemory-inl.h +256 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/DMAConnectivity.hpp +40 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FakeProcessGroup.hpp +186 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/GlooDeviceFactory.hpp +32 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/NCCLUtils.hpp +718 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/ParamCommsUtils.hpp +180 -0
videollama2/lib/python3.10/site-packages/setuptools/tests/__pycache__/test_core_metadata.cpython-310.pyc
ADDED
|
Binary file (14.9 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/__init__.py
ADDED
|
File without changes
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (157 Bytes). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_apply_pyprojecttoml.cpython-310.pyc
ADDED
|
Binary file (19.1 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_expand.cpython-310.pyc
ADDED
|
Binary file (7.79 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_pyprojecttoml.cpython-310.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/__pycache__/test_pyprojecttoml_dynamic_deps.cpython-310.pyc
ADDED
|
Binary file (3.37 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/downloads/__init__.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
import time
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from urllib.error import HTTPError
|
| 7 |
+
from urllib.request import urlopen
|
| 8 |
+
|
| 9 |
+
__all__ = ["DOWNLOAD_DIR", "retrieve_file", "output_file", "urls_from_file"]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
NAME_REMOVE = ("http://", "https://", "github.com/", "/raw/")
|
| 13 |
+
DOWNLOAD_DIR = Path(__file__).parent
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# ----------------------------------------------------------------------
|
| 17 |
+
# Please update ./preload.py accordingly when modifying this file
|
| 18 |
+
# ----------------------------------------------------------------------
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def output_file(url: str, download_dir: Path = DOWNLOAD_DIR) -> Path:
|
| 22 |
+
file_name = url.strip()
|
| 23 |
+
for part in NAME_REMOVE:
|
| 24 |
+
file_name = file_name.replace(part, '').strip().strip('/:').strip()
|
| 25 |
+
return Path(download_dir, re.sub(r"[^\-_\.\w\d]+", "_", file_name))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def retrieve_file(url: str, download_dir: Path = DOWNLOAD_DIR, wait: float = 5) -> Path:
|
| 29 |
+
path = output_file(url, download_dir)
|
| 30 |
+
if path.exists():
|
| 31 |
+
print(f"Skipping {url} (already exists: {path})")
|
| 32 |
+
else:
|
| 33 |
+
download_dir.mkdir(exist_ok=True, parents=True)
|
| 34 |
+
print(f"Downloading {url} to {path}")
|
| 35 |
+
try:
|
| 36 |
+
download(url, path)
|
| 37 |
+
except HTTPError:
|
| 38 |
+
time.sleep(wait) # wait a few seconds and try again.
|
| 39 |
+
download(url, path)
|
| 40 |
+
return path
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def urls_from_file(list_file: Path) -> list[str]:
|
| 44 |
+
"""``list_file`` should be a text file where each line corresponds to a URL to
|
| 45 |
+
download.
|
| 46 |
+
"""
|
| 47 |
+
print(f"file: {list_file}")
|
| 48 |
+
content = list_file.read_text(encoding="utf-8")
|
| 49 |
+
return [url for url in content.splitlines() if not url.startswith("#")]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def download(url: str, dest: Path):
|
| 53 |
+
with urlopen(url) as f:
|
| 54 |
+
data = f.read()
|
| 55 |
+
|
| 56 |
+
with open(dest, "wb") as f:
|
| 57 |
+
f.write(data)
|
| 58 |
+
|
| 59 |
+
assert Path(dest).exists()
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/downloads/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (2.15 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/config/downloads/__pycache__/preload.cpython-310.pyc
ADDED
|
Binary file (650 Bytes). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/contexts.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import contextlib
|
| 2 |
+
import io
|
| 3 |
+
import os
|
| 4 |
+
import shutil
|
| 5 |
+
import site
|
| 6 |
+
import sys
|
| 7 |
+
import tempfile
|
| 8 |
+
|
| 9 |
+
from filelock import FileLock
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@contextlib.contextmanager
|
| 13 |
+
def tempdir(cd=lambda dir: None, **kwargs):
|
| 14 |
+
temp_dir = tempfile.mkdtemp(**kwargs)
|
| 15 |
+
orig_dir = os.getcwd()
|
| 16 |
+
try:
|
| 17 |
+
cd(temp_dir)
|
| 18 |
+
yield temp_dir
|
| 19 |
+
finally:
|
| 20 |
+
cd(orig_dir)
|
| 21 |
+
shutil.rmtree(temp_dir)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@contextlib.contextmanager
|
| 25 |
+
def environment(**replacements):
|
| 26 |
+
"""
|
| 27 |
+
In a context, patch the environment with replacements. Pass None values
|
| 28 |
+
to clear the values.
|
| 29 |
+
"""
|
| 30 |
+
saved = dict((key, os.environ[key]) for key in replacements if key in os.environ)
|
| 31 |
+
|
| 32 |
+
# remove values that are null
|
| 33 |
+
remove = (key for (key, value) in replacements.items() if value is None)
|
| 34 |
+
for key in list(remove):
|
| 35 |
+
os.environ.pop(key, None)
|
| 36 |
+
replacements.pop(key)
|
| 37 |
+
|
| 38 |
+
os.environ.update(replacements)
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
yield saved
|
| 42 |
+
finally:
|
| 43 |
+
for key in replacements:
|
| 44 |
+
os.environ.pop(key, None)
|
| 45 |
+
os.environ.update(saved)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@contextlib.contextmanager
|
| 49 |
+
def quiet():
|
| 50 |
+
"""
|
| 51 |
+
Redirect stdout/stderr to StringIO objects to prevent console output from
|
| 52 |
+
distutils commands.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
old_stdout = sys.stdout
|
| 56 |
+
old_stderr = sys.stderr
|
| 57 |
+
new_stdout = sys.stdout = io.StringIO()
|
| 58 |
+
new_stderr = sys.stderr = io.StringIO()
|
| 59 |
+
try:
|
| 60 |
+
yield new_stdout, new_stderr
|
| 61 |
+
finally:
|
| 62 |
+
new_stdout.seek(0)
|
| 63 |
+
new_stderr.seek(0)
|
| 64 |
+
sys.stdout = old_stdout
|
| 65 |
+
sys.stderr = old_stderr
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
@contextlib.contextmanager
|
| 69 |
+
def save_user_site_setting():
|
| 70 |
+
saved = site.ENABLE_USER_SITE
|
| 71 |
+
try:
|
| 72 |
+
yield saved
|
| 73 |
+
finally:
|
| 74 |
+
site.ENABLE_USER_SITE = saved
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
@contextlib.contextmanager
|
| 78 |
+
def save_pkg_resources_state():
|
| 79 |
+
import pkg_resources
|
| 80 |
+
|
| 81 |
+
pr_state = pkg_resources.__getstate__()
|
| 82 |
+
# also save sys.path
|
| 83 |
+
sys_path = sys.path[:]
|
| 84 |
+
try:
|
| 85 |
+
yield pr_state, sys_path
|
| 86 |
+
finally:
|
| 87 |
+
sys.path[:] = sys_path
|
| 88 |
+
pkg_resources.__setstate__(pr_state)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@contextlib.contextmanager
|
| 92 |
+
def suppress_exceptions(*excs):
|
| 93 |
+
try:
|
| 94 |
+
yield
|
| 95 |
+
except excs:
|
| 96 |
+
pass
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def multiproc(request):
|
| 100 |
+
"""
|
| 101 |
+
Return True if running under xdist and multiple
|
| 102 |
+
workers are used.
|
| 103 |
+
"""
|
| 104 |
+
try:
|
| 105 |
+
worker_id = request.getfixturevalue('worker_id')
|
| 106 |
+
except Exception:
|
| 107 |
+
return False
|
| 108 |
+
return worker_id != 'master'
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
@contextlib.contextmanager
|
| 112 |
+
def session_locked_tmp_dir(request, tmp_path_factory, name):
|
| 113 |
+
"""Uses a file lock to guarantee only one worker can access a temp dir"""
|
| 114 |
+
# get the temp directory shared by all workers
|
| 115 |
+
base = tmp_path_factory.getbasetemp()
|
| 116 |
+
shared_dir = base.parent if multiproc(request) else base
|
| 117 |
+
|
| 118 |
+
locked_dir = shared_dir / name
|
| 119 |
+
with FileLock(locked_dir.with_suffix(".lock")):
|
| 120 |
+
# ^-- prevent multiple workers to access the directory at once
|
| 121 |
+
locked_dir.mkdir(exist_ok=True, parents=True)
|
| 122 |
+
yield locked_dir
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
@contextlib.contextmanager
|
| 126 |
+
def save_paths():
|
| 127 |
+
"""Make sure ``sys.path``, ``sys.meta_path`` and ``sys.path_hooks`` are preserved"""
|
| 128 |
+
prev = sys.path[:], sys.meta_path[:], sys.path_hooks[:]
|
| 129 |
+
|
| 130 |
+
try:
|
| 131 |
+
yield
|
| 132 |
+
finally:
|
| 133 |
+
sys.path, sys.meta_path, sys.path_hooks = prev
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
@contextlib.contextmanager
|
| 137 |
+
def save_sys_modules():
|
| 138 |
+
"""Make sure initial ``sys.modules`` is preserved"""
|
| 139 |
+
prev_modules = sys.modules
|
| 140 |
+
|
| 141 |
+
try:
|
| 142 |
+
sys.modules = sys.modules.copy()
|
| 143 |
+
yield
|
| 144 |
+
finally:
|
| 145 |
+
sys.modules = prev_modules
|
videollama2/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
|
videollama2/lib/python3.10/site-packages/setuptools/tests/integration/__init__.py
ADDED
|
File without changes
|
videollama2/lib/python3.10/site-packages/setuptools/tests/integration/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (162 Bytes). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/tests/integration/helpers.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Reusable functions and classes for different types of integration tests.
|
| 2 |
+
|
| 3 |
+
For example ``Archive`` can be used to check the contents of distribution built
|
| 4 |
+
with setuptools, and ``run`` will always try to be as verbose as possible to
|
| 5 |
+
facilitate debugging.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
import tarfile
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from zipfile import ZipFile
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def run(cmd, env=None):
|
| 16 |
+
r = subprocess.run(
|
| 17 |
+
cmd,
|
| 18 |
+
capture_output=True,
|
| 19 |
+
text=True,
|
| 20 |
+
encoding="utf-8",
|
| 21 |
+
env={**os.environ, **(env or {})},
|
| 22 |
+
# ^-- allow overwriting instead of discarding the current env
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
out = r.stdout + "\n" + r.stderr
|
| 26 |
+
# pytest omits stdout/err by default, if the test fails they help debugging
|
| 27 |
+
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
|
| 28 |
+
print(f"Command: {cmd}\nreturn code: {r.returncode}\n\n{out}")
|
| 29 |
+
|
| 30 |
+
if r.returncode == 0:
|
| 31 |
+
return out
|
| 32 |
+
raise subprocess.CalledProcessError(r.returncode, cmd, r.stdout, r.stderr)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class Archive:
|
| 36 |
+
"""Compatibility layer for ZipFile/Info and TarFile/Info"""
|
| 37 |
+
|
| 38 |
+
def __init__(self, filename):
|
| 39 |
+
self._filename = filename
|
| 40 |
+
if filename.endswith("tar.gz"):
|
| 41 |
+
self._obj = tarfile.open(filename, "r:gz")
|
| 42 |
+
elif filename.endswith("zip"):
|
| 43 |
+
self._obj = ZipFile(filename)
|
| 44 |
+
else:
|
| 45 |
+
raise ValueError(f"{filename} doesn't seem to be a zip or tar.gz")
|
| 46 |
+
|
| 47 |
+
def __iter__(self):
|
| 48 |
+
if hasattr(self._obj, "infolist"):
|
| 49 |
+
return iter(self._obj.infolist())
|
| 50 |
+
return iter(self._obj)
|
| 51 |
+
|
| 52 |
+
def get_name(self, zip_or_tar_info):
|
| 53 |
+
if hasattr(zip_or_tar_info, "filename"):
|
| 54 |
+
return zip_or_tar_info.filename
|
| 55 |
+
return zip_or_tar_info.name
|
| 56 |
+
|
| 57 |
+
def get_content(self, zip_or_tar_info):
|
| 58 |
+
if hasattr(self._obj, "extractfile"):
|
| 59 |
+
content = self._obj.extractfile(zip_or_tar_info)
|
| 60 |
+
if content is None:
|
| 61 |
+
msg = f"Invalid {zip_or_tar_info.name} in {self._filename}"
|
| 62 |
+
raise ValueError(msg)
|
| 63 |
+
return str(content.read(), "utf-8")
|
| 64 |
+
return str(self._obj.read(zip_or_tar_info), "utf-8")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def get_sdist_members(sdist_path):
|
| 68 |
+
with tarfile.open(sdist_path, "r:gz") as tar:
|
| 69 |
+
files = [Path(f) for f in tar.getnames()]
|
| 70 |
+
# remove root folder
|
| 71 |
+
relative_files = ("/".join(f.parts[1:]) for f in files)
|
| 72 |
+
return {f for f in relative_files if f}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def get_wheel_members(wheel_path):
|
| 76 |
+
with ZipFile(wheel_path) as zipfile:
|
| 77 |
+
return set(zipfile.namelist())
|
videollama2/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()
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_bdist_wheel.py
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 import annotations
|
| 2 |
+
|
| 3 |
+
import builtins
|
| 4 |
+
import importlib
|
| 5 |
+
import os.path
|
| 6 |
+
import platform
|
| 7 |
+
import shutil
|
| 8 |
+
import stat
|
| 9 |
+
import struct
|
| 10 |
+
import sys
|
| 11 |
+
import sysconfig
|
| 12 |
+
from contextlib import suppress
|
| 13 |
+
from inspect import cleandoc
|
| 14 |
+
from zipfile import ZipFile
|
| 15 |
+
|
| 16 |
+
import jaraco.path
|
| 17 |
+
import pytest
|
| 18 |
+
from packaging import tags
|
| 19 |
+
|
| 20 |
+
import setuptools
|
| 21 |
+
from setuptools.command.bdist_wheel import bdist_wheel, get_abi_tag
|
| 22 |
+
from setuptools.dist import Distribution
|
| 23 |
+
from setuptools.warnings import SetuptoolsDeprecationWarning
|
| 24 |
+
|
| 25 |
+
from distutils.core import run_setup
|
| 26 |
+
|
| 27 |
+
DEFAULT_FILES = {
|
| 28 |
+
"dummy_dist-1.0.dist-info/top_level.txt",
|
| 29 |
+
"dummy_dist-1.0.dist-info/METADATA",
|
| 30 |
+
"dummy_dist-1.0.dist-info/WHEEL",
|
| 31 |
+
"dummy_dist-1.0.dist-info/RECORD",
|
| 32 |
+
}
|
| 33 |
+
DEFAULT_LICENSE_FILES = {
|
| 34 |
+
"LICENSE",
|
| 35 |
+
"LICENSE.txt",
|
| 36 |
+
"LICENCE",
|
| 37 |
+
"LICENCE.txt",
|
| 38 |
+
"COPYING",
|
| 39 |
+
"COPYING.md",
|
| 40 |
+
"NOTICE",
|
| 41 |
+
"NOTICE.rst",
|
| 42 |
+
"AUTHORS",
|
| 43 |
+
"AUTHORS.txt",
|
| 44 |
+
}
|
| 45 |
+
OTHER_IGNORED_FILES = {
|
| 46 |
+
"LICENSE~",
|
| 47 |
+
"AUTHORS~",
|
| 48 |
+
}
|
| 49 |
+
SETUPPY_EXAMPLE = """\
|
| 50 |
+
from setuptools import setup
|
| 51 |
+
|
| 52 |
+
setup(
|
| 53 |
+
name='dummy_dist',
|
| 54 |
+
version='1.0',
|
| 55 |
+
)
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
EXAMPLES = {
|
| 60 |
+
"dummy-dist": {
|
| 61 |
+
"setup.py": SETUPPY_EXAMPLE,
|
| 62 |
+
"licenses": {"DUMMYFILE": ""},
|
| 63 |
+
**dict.fromkeys(DEFAULT_LICENSE_FILES | OTHER_IGNORED_FILES, ""),
|
| 64 |
+
},
|
| 65 |
+
"simple-dist": {
|
| 66 |
+
"setup.py": cleandoc(
|
| 67 |
+
"""
|
| 68 |
+
from setuptools import setup
|
| 69 |
+
|
| 70 |
+
setup(
|
| 71 |
+
name="simple.dist",
|
| 72 |
+
version="0.1",
|
| 73 |
+
description="A testing distribution \N{SNOWMAN}",
|
| 74 |
+
extras_require={"voting": ["beaglevote"]},
|
| 75 |
+
)
|
| 76 |
+
"""
|
| 77 |
+
),
|
| 78 |
+
"simpledist": "",
|
| 79 |
+
},
|
| 80 |
+
"complex-dist": {
|
| 81 |
+
"setup.py": cleandoc(
|
| 82 |
+
"""
|
| 83 |
+
from setuptools import setup
|
| 84 |
+
|
| 85 |
+
setup(
|
| 86 |
+
name="complex-dist",
|
| 87 |
+
version="0.1",
|
| 88 |
+
description="Another testing distribution \N{SNOWMAN}",
|
| 89 |
+
long_description="Another testing distribution \N{SNOWMAN}",
|
| 90 |
+
author="Illustrious Author",
|
| 91 |
+
author_email="illustrious@example.org",
|
| 92 |
+
url="http://example.org/exemplary",
|
| 93 |
+
packages=["complexdist"],
|
| 94 |
+
setup_requires=["setuptools"],
|
| 95 |
+
install_requires=["quux", "splort"],
|
| 96 |
+
extras_require={"simple": ["simple.dist"]},
|
| 97 |
+
entry_points={
|
| 98 |
+
"console_scripts": [
|
| 99 |
+
"complex-dist=complexdist:main",
|
| 100 |
+
"complex-dist2=complexdist:main",
|
| 101 |
+
],
|
| 102 |
+
},
|
| 103 |
+
)
|
| 104 |
+
"""
|
| 105 |
+
),
|
| 106 |
+
"complexdist": {"__init__.py": "def main(): return"},
|
| 107 |
+
},
|
| 108 |
+
"headers-dist": {
|
| 109 |
+
"setup.py": cleandoc(
|
| 110 |
+
"""
|
| 111 |
+
from setuptools import setup
|
| 112 |
+
|
| 113 |
+
setup(
|
| 114 |
+
name="headers.dist",
|
| 115 |
+
version="0.1",
|
| 116 |
+
description="A distribution with headers",
|
| 117 |
+
headers=["header.h"],
|
| 118 |
+
)
|
| 119 |
+
"""
|
| 120 |
+
),
|
| 121 |
+
"headersdist.py": "",
|
| 122 |
+
"header.h": "",
|
| 123 |
+
},
|
| 124 |
+
"commasinfilenames-dist": {
|
| 125 |
+
"setup.py": cleandoc(
|
| 126 |
+
"""
|
| 127 |
+
from setuptools import setup
|
| 128 |
+
|
| 129 |
+
setup(
|
| 130 |
+
name="testrepo",
|
| 131 |
+
version="0.1",
|
| 132 |
+
packages=["mypackage"],
|
| 133 |
+
description="A test package with commas in file names",
|
| 134 |
+
include_package_data=True,
|
| 135 |
+
package_data={"mypackage.data": ["*"]},
|
| 136 |
+
)
|
| 137 |
+
"""
|
| 138 |
+
),
|
| 139 |
+
"mypackage": {
|
| 140 |
+
"__init__.py": "",
|
| 141 |
+
"data": {"__init__.py": "", "1,2,3.txt": ""},
|
| 142 |
+
},
|
| 143 |
+
"testrepo-0.1.0": {
|
| 144 |
+
"mypackage": {"__init__.py": ""},
|
| 145 |
+
},
|
| 146 |
+
},
|
| 147 |
+
"unicode-dist": {
|
| 148 |
+
"setup.py": cleandoc(
|
| 149 |
+
"""
|
| 150 |
+
from setuptools import setup
|
| 151 |
+
|
| 152 |
+
setup(
|
| 153 |
+
name="unicode.dist",
|
| 154 |
+
version="0.1",
|
| 155 |
+
description="A testing distribution \N{SNOWMAN}",
|
| 156 |
+
packages=["unicodedist"],
|
| 157 |
+
zip_safe=True,
|
| 158 |
+
)
|
| 159 |
+
"""
|
| 160 |
+
),
|
| 161 |
+
"unicodedist": {"__init__.py": "", "åäö_日本語.py": ""},
|
| 162 |
+
},
|
| 163 |
+
"utf8-metadata-dist": {
|
| 164 |
+
"setup.cfg": cleandoc(
|
| 165 |
+
"""
|
| 166 |
+
[metadata]
|
| 167 |
+
name = utf8-metadata-dist
|
| 168 |
+
version = 42
|
| 169 |
+
author_email = "John X. Ãørçeč" <john@utf8.org>, Γαμα קּ 東 <gama@utf8.org>
|
| 170 |
+
long_description = file: README.rst
|
| 171 |
+
"""
|
| 172 |
+
),
|
| 173 |
+
"README.rst": "UTF-8 描述 説明",
|
| 174 |
+
},
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
if sys.platform != "win32":
|
| 179 |
+
# ABI3 extensions don't really work on Windows
|
| 180 |
+
EXAMPLES["abi3extension-dist"] = {
|
| 181 |
+
"setup.py": cleandoc(
|
| 182 |
+
"""
|
| 183 |
+
from setuptools import Extension, setup
|
| 184 |
+
|
| 185 |
+
setup(
|
| 186 |
+
name="extension.dist",
|
| 187 |
+
version="0.1",
|
| 188 |
+
description="A testing distribution \N{SNOWMAN}",
|
| 189 |
+
ext_modules=[
|
| 190 |
+
Extension(
|
| 191 |
+
name="extension", sources=["extension.c"], py_limited_api=True
|
| 192 |
+
)
|
| 193 |
+
],
|
| 194 |
+
)
|
| 195 |
+
"""
|
| 196 |
+
),
|
| 197 |
+
"setup.cfg": "[bdist_wheel]\npy_limited_api=cp32",
|
| 198 |
+
"extension.c": "#define Py_LIMITED_API 0x03020000\n#include <Python.h>",
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def bdist_wheel_cmd(**kwargs):
|
| 203 |
+
"""Run command in the same process so that it is easier to collect coverage"""
|
| 204 |
+
dist_obj = (
|
| 205 |
+
run_setup("setup.py", stop_after="init")
|
| 206 |
+
if os.path.exists("setup.py")
|
| 207 |
+
else Distribution({"script_name": "%%build_meta%%"})
|
| 208 |
+
)
|
| 209 |
+
dist_obj.parse_config_files()
|
| 210 |
+
cmd = bdist_wheel(dist_obj)
|
| 211 |
+
for attr, value in kwargs.items():
|
| 212 |
+
setattr(cmd, attr, value)
|
| 213 |
+
cmd.finalize_options()
|
| 214 |
+
return cmd
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
def mkexample(tmp_path_factory, name):
|
| 218 |
+
basedir = tmp_path_factory.mktemp(name)
|
| 219 |
+
jaraco.path.build(EXAMPLES[name], prefix=str(basedir))
|
| 220 |
+
return basedir
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
@pytest.fixture(scope="session")
|
| 224 |
+
def wheel_paths(tmp_path_factory):
|
| 225 |
+
build_base = tmp_path_factory.mktemp("build")
|
| 226 |
+
dist_dir = tmp_path_factory.mktemp("dist")
|
| 227 |
+
for name in EXAMPLES:
|
| 228 |
+
example_dir = mkexample(tmp_path_factory, name)
|
| 229 |
+
build_dir = build_base / name
|
| 230 |
+
with jaraco.path.DirectoryStack().context(example_dir):
|
| 231 |
+
bdist_wheel_cmd(bdist_dir=str(build_dir), dist_dir=str(dist_dir)).run()
|
| 232 |
+
|
| 233 |
+
return sorted(str(fname) for fname in dist_dir.glob("*.whl"))
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
@pytest.fixture
|
| 237 |
+
def dummy_dist(tmp_path_factory):
|
| 238 |
+
return mkexample(tmp_path_factory, "dummy-dist")
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def test_no_scripts(wheel_paths):
|
| 242 |
+
"""Make sure entry point scripts are not generated."""
|
| 243 |
+
path = next(path for path in wheel_paths if "complex_dist" in path)
|
| 244 |
+
for entry in ZipFile(path).infolist():
|
| 245 |
+
assert ".data/scripts/" not in entry.filename
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def test_unicode_record(wheel_paths):
|
| 249 |
+
path = next(path for path in wheel_paths if "unicode.dist" in path)
|
| 250 |
+
with ZipFile(path) as zf:
|
| 251 |
+
record = zf.read("unicode.dist-0.1.dist-info/RECORD")
|
| 252 |
+
|
| 253 |
+
assert "åäö_日本語.py".encode() in record
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
UTF8_PKG_INFO = """\
|
| 257 |
+
Metadata-Version: 2.1
|
| 258 |
+
Name: helloworld
|
| 259 |
+
Version: 42
|
| 260 |
+
Author-email: "John X. Ãørçeč" <john@utf8.org>, Γαμα קּ 東 <gama@utf8.org>
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
UTF-8 描述 説明
|
| 264 |
+
"""
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def test_preserve_unicode_metadata(monkeypatch, tmp_path):
|
| 268 |
+
monkeypatch.chdir(tmp_path)
|
| 269 |
+
egginfo = tmp_path / "dummy_dist.egg-info"
|
| 270 |
+
distinfo = tmp_path / "dummy_dist.dist-info"
|
| 271 |
+
|
| 272 |
+
egginfo.mkdir()
|
| 273 |
+
(egginfo / "PKG-INFO").write_text(UTF8_PKG_INFO, encoding="utf-8")
|
| 274 |
+
(egginfo / "dependency_links.txt").touch()
|
| 275 |
+
|
| 276 |
+
class simpler_bdist_wheel(bdist_wheel):
|
| 277 |
+
"""Avoid messing with setuptools/distutils internals"""
|
| 278 |
+
|
| 279 |
+
def __init__(self):
|
| 280 |
+
pass
|
| 281 |
+
|
| 282 |
+
@property
|
| 283 |
+
def license_paths(self):
|
| 284 |
+
return []
|
| 285 |
+
|
| 286 |
+
cmd_obj = simpler_bdist_wheel()
|
| 287 |
+
cmd_obj.egg2dist(egginfo, distinfo)
|
| 288 |
+
|
| 289 |
+
metadata = (distinfo / "METADATA").read_text(encoding="utf-8")
|
| 290 |
+
assert 'Author-email: "John X. Ãørçeč"' in metadata
|
| 291 |
+
assert "Γαμα קּ 東 " in metadata
|
| 292 |
+
assert "UTF-8 描述 説明" in metadata
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def test_licenses_default(dummy_dist, monkeypatch, tmp_path):
|
| 296 |
+
monkeypatch.chdir(dummy_dist)
|
| 297 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()
|
| 298 |
+
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
|
| 299 |
+
license_files = {
|
| 300 |
+
"dummy_dist-1.0.dist-info/" + fname for fname in DEFAULT_LICENSE_FILES
|
| 301 |
+
}
|
| 302 |
+
assert set(wf.namelist()) == DEFAULT_FILES | license_files
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def test_licenses_deprecated(dummy_dist, monkeypatch, tmp_path):
|
| 306 |
+
dummy_dist.joinpath("setup.cfg").write_text(
|
| 307 |
+
"[metadata]\nlicense_file=licenses/DUMMYFILE", encoding="utf-8"
|
| 308 |
+
)
|
| 309 |
+
monkeypatch.chdir(dummy_dist)
|
| 310 |
+
|
| 311 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()
|
| 312 |
+
|
| 313 |
+
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
|
| 314 |
+
license_files = {"dummy_dist-1.0.dist-info/DUMMYFILE"}
|
| 315 |
+
assert set(wf.namelist()) == DEFAULT_FILES | license_files
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
@pytest.mark.parametrize(
|
| 319 |
+
("config_file", "config"),
|
| 320 |
+
[
|
| 321 |
+
("setup.cfg", "[metadata]\nlicense_files=licenses/*\n LICENSE"),
|
| 322 |
+
("setup.cfg", "[metadata]\nlicense_files=licenses/*, LICENSE"),
|
| 323 |
+
(
|
| 324 |
+
"setup.py",
|
| 325 |
+
SETUPPY_EXAMPLE.replace(
|
| 326 |
+
")", " license_files=['licenses/DUMMYFILE', 'LICENSE'])"
|
| 327 |
+
),
|
| 328 |
+
),
|
| 329 |
+
],
|
| 330 |
+
)
|
| 331 |
+
def test_licenses_override(dummy_dist, monkeypatch, tmp_path, config_file, config):
|
| 332 |
+
dummy_dist.joinpath(config_file).write_text(config, encoding="utf-8")
|
| 333 |
+
monkeypatch.chdir(dummy_dist)
|
| 334 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()
|
| 335 |
+
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
|
| 336 |
+
license_files = {
|
| 337 |
+
"dummy_dist-1.0.dist-info/" + fname for fname in {"DUMMYFILE", "LICENSE"}
|
| 338 |
+
}
|
| 339 |
+
assert set(wf.namelist()) == DEFAULT_FILES | license_files
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def test_licenses_disabled(dummy_dist, monkeypatch, tmp_path):
|
| 343 |
+
dummy_dist.joinpath("setup.cfg").write_text(
|
| 344 |
+
"[metadata]\nlicense_files=\n", encoding="utf-8"
|
| 345 |
+
)
|
| 346 |
+
monkeypatch.chdir(dummy_dist)
|
| 347 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()
|
| 348 |
+
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
|
| 349 |
+
assert set(wf.namelist()) == DEFAULT_FILES
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def test_build_number(dummy_dist, monkeypatch, tmp_path):
|
| 353 |
+
monkeypatch.chdir(dummy_dist)
|
| 354 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path), build_number="2").run()
|
| 355 |
+
with ZipFile("dist/dummy_dist-1.0-2-py3-none-any.whl") as wf:
|
| 356 |
+
filenames = set(wf.namelist())
|
| 357 |
+
assert "dummy_dist-1.0.dist-info/RECORD" in filenames
|
| 358 |
+
assert "dummy_dist-1.0.dist-info/METADATA" in filenames
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def test_universal_deprecated(dummy_dist, monkeypatch, tmp_path):
|
| 362 |
+
monkeypatch.chdir(dummy_dist)
|
| 363 |
+
with pytest.warns(SetuptoolsDeprecationWarning, match=".*universal is deprecated"):
|
| 364 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path), universal=True).run()
|
| 365 |
+
|
| 366 |
+
# For now we still respect the option
|
| 367 |
+
assert os.path.exists("dist/dummy_dist-1.0-py2.py3-none-any.whl")
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
EXTENSION_EXAMPLE = """\
|
| 371 |
+
#include <Python.h>
|
| 372 |
+
|
| 373 |
+
static PyMethodDef methods[] = {
|
| 374 |
+
{ NULL, NULL, 0, NULL }
|
| 375 |
+
};
|
| 376 |
+
|
| 377 |
+
static struct PyModuleDef module_def = {
|
| 378 |
+
PyModuleDef_HEAD_INIT,
|
| 379 |
+
"extension",
|
| 380 |
+
"Dummy extension module",
|
| 381 |
+
-1,
|
| 382 |
+
methods
|
| 383 |
+
};
|
| 384 |
+
|
| 385 |
+
PyMODINIT_FUNC PyInit_extension(void) {
|
| 386 |
+
return PyModule_Create(&module_def);
|
| 387 |
+
}
|
| 388 |
+
"""
|
| 389 |
+
EXTENSION_SETUPPY = """\
|
| 390 |
+
from __future__ import annotations
|
| 391 |
+
|
| 392 |
+
from setuptools import Extension, setup
|
| 393 |
+
|
| 394 |
+
setup(
|
| 395 |
+
name="extension.dist",
|
| 396 |
+
version="0.1",
|
| 397 |
+
description="A testing distribution \N{SNOWMAN}",
|
| 398 |
+
ext_modules=[Extension(name="extension", sources=["extension.c"])],
|
| 399 |
+
)
|
| 400 |
+
"""
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
@pytest.mark.filterwarnings(
|
| 404 |
+
"once:Config variable '.*' is unset.*, Python ABI tag may be incorrect"
|
| 405 |
+
)
|
| 406 |
+
def test_limited_abi(monkeypatch, tmp_path, tmp_path_factory):
|
| 407 |
+
"""Test that building a binary wheel with the limited ABI works."""
|
| 408 |
+
source_dir = tmp_path_factory.mktemp("extension_dist")
|
| 409 |
+
(source_dir / "setup.py").write_text(EXTENSION_SETUPPY, encoding="utf-8")
|
| 410 |
+
(source_dir / "extension.c").write_text(EXTENSION_EXAMPLE, encoding="utf-8")
|
| 411 |
+
build_dir = tmp_path.joinpath("build")
|
| 412 |
+
dist_dir = tmp_path.joinpath("dist")
|
| 413 |
+
monkeypatch.chdir(source_dir)
|
| 414 |
+
bdist_wheel_cmd(bdist_dir=str(build_dir), dist_dir=str(dist_dir)).run()
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def test_build_from_readonly_tree(dummy_dist, monkeypatch, tmp_path):
|
| 418 |
+
basedir = str(tmp_path.joinpath("dummy"))
|
| 419 |
+
shutil.copytree(str(dummy_dist), basedir)
|
| 420 |
+
monkeypatch.chdir(basedir)
|
| 421 |
+
|
| 422 |
+
# Make the tree read-only
|
| 423 |
+
for root, _dirs, files in os.walk(basedir):
|
| 424 |
+
for fname in files:
|
| 425 |
+
os.chmod(os.path.join(root, fname), stat.S_IREAD)
|
| 426 |
+
|
| 427 |
+
bdist_wheel_cmd().run()
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
@pytest.mark.parametrize(
|
| 431 |
+
("option", "compress_type"),
|
| 432 |
+
list(bdist_wheel.supported_compressions.items()),
|
| 433 |
+
ids=list(bdist_wheel.supported_compressions),
|
| 434 |
+
)
|
| 435 |
+
def test_compression(dummy_dist, monkeypatch, tmp_path, option, compress_type):
|
| 436 |
+
monkeypatch.chdir(dummy_dist)
|
| 437 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path), compression=option).run()
|
| 438 |
+
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
|
| 439 |
+
filenames = set(wf.namelist())
|
| 440 |
+
assert "dummy_dist-1.0.dist-info/RECORD" in filenames
|
| 441 |
+
assert "dummy_dist-1.0.dist-info/METADATA" in filenames
|
| 442 |
+
for zinfo in wf.filelist:
|
| 443 |
+
assert zinfo.compress_type == compress_type
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
def test_wheelfile_line_endings(wheel_paths):
|
| 447 |
+
for path in wheel_paths:
|
| 448 |
+
with ZipFile(path) as wf:
|
| 449 |
+
wheelfile = next(fn for fn in wf.filelist if fn.filename.endswith("WHEEL"))
|
| 450 |
+
wheelfile_contents = wf.read(wheelfile)
|
| 451 |
+
assert b"\r" not in wheelfile_contents
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def test_unix_epoch_timestamps(dummy_dist, monkeypatch, tmp_path):
|
| 455 |
+
monkeypatch.setenv("SOURCE_DATE_EPOCH", "0")
|
| 456 |
+
monkeypatch.chdir(dummy_dist)
|
| 457 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path), build_number="2a").run()
|
| 458 |
+
with ZipFile("dist/dummy_dist-1.0-2a-py3-none-any.whl") as wf:
|
| 459 |
+
for zinfo in wf.filelist:
|
| 460 |
+
assert zinfo.date_time >= (1980, 1, 1, 0, 0, 0) # min epoch is used
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def test_get_abi_tag_windows(monkeypatch):
|
| 464 |
+
monkeypatch.setattr(tags, "interpreter_name", lambda: "cp")
|
| 465 |
+
monkeypatch.setattr(sysconfig, "get_config_var", lambda x: "cp313-win_amd64")
|
| 466 |
+
assert get_abi_tag() == "cp313"
|
| 467 |
+
monkeypatch.setattr(sys, "gettotalrefcount", lambda: 1, False)
|
| 468 |
+
assert get_abi_tag() == "cp313d"
|
| 469 |
+
monkeypatch.setattr(sysconfig, "get_config_var", lambda x: "cp313t-win_amd64")
|
| 470 |
+
assert get_abi_tag() == "cp313td"
|
| 471 |
+
monkeypatch.delattr(sys, "gettotalrefcount")
|
| 472 |
+
assert get_abi_tag() == "cp313t"
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
def test_get_abi_tag_pypy_old(monkeypatch):
|
| 476 |
+
monkeypatch.setattr(tags, "interpreter_name", lambda: "pp")
|
| 477 |
+
monkeypatch.setattr(sysconfig, "get_config_var", lambda x: "pypy36-pp73")
|
| 478 |
+
assert get_abi_tag() == "pypy36_pp73"
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
def test_get_abi_tag_pypy_new(monkeypatch):
|
| 482 |
+
monkeypatch.setattr(sysconfig, "get_config_var", lambda x: "pypy37-pp73-darwin")
|
| 483 |
+
monkeypatch.setattr(tags, "interpreter_name", lambda: "pp")
|
| 484 |
+
assert get_abi_tag() == "pypy37_pp73"
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def test_get_abi_tag_graalpy(monkeypatch):
|
| 488 |
+
monkeypatch.setattr(
|
| 489 |
+
sysconfig, "get_config_var", lambda x: "graalpy231-310-native-x86_64-linux"
|
| 490 |
+
)
|
| 491 |
+
monkeypatch.setattr(tags, "interpreter_name", lambda: "graalpy")
|
| 492 |
+
assert get_abi_tag() == "graalpy231_310_native"
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
def test_get_abi_tag_fallback(monkeypatch):
|
| 496 |
+
monkeypatch.setattr(sysconfig, "get_config_var", lambda x: "unknown-python-310")
|
| 497 |
+
monkeypatch.setattr(tags, "interpreter_name", lambda: "unknown-python")
|
| 498 |
+
assert get_abi_tag() == "unknown_python_310"
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
def test_platform_with_space(dummy_dist, monkeypatch):
|
| 502 |
+
"""Ensure building on platforms with a space in the name succeed."""
|
| 503 |
+
monkeypatch.chdir(dummy_dist)
|
| 504 |
+
bdist_wheel_cmd(plat_name="isilon onefs").run()
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
def test_data_dir_with_tag_build(monkeypatch, tmp_path):
|
| 508 |
+
"""
|
| 509 |
+
Setuptools allow authors to set PEP 440's local version segments
|
| 510 |
+
using ``egg_info.tag_build``. This should be reflected not only in the
|
| 511 |
+
``.whl`` file name, but also in the ``.dist-info`` and ``.data`` dirs.
|
| 512 |
+
See pypa/setuptools#3997.
|
| 513 |
+
"""
|
| 514 |
+
monkeypatch.chdir(tmp_path)
|
| 515 |
+
files = {
|
| 516 |
+
"setup.py": """
|
| 517 |
+
from setuptools import setup
|
| 518 |
+
setup(headers=["hello.h"])
|
| 519 |
+
""",
|
| 520 |
+
"setup.cfg": """
|
| 521 |
+
[metadata]
|
| 522 |
+
name = test
|
| 523 |
+
version = 1.0
|
| 524 |
+
|
| 525 |
+
[options.data_files]
|
| 526 |
+
hello/world = file.txt
|
| 527 |
+
|
| 528 |
+
[egg_info]
|
| 529 |
+
tag_build = +what
|
| 530 |
+
tag_date = 0
|
| 531 |
+
""",
|
| 532 |
+
"file.txt": "",
|
| 533 |
+
"hello.h": "",
|
| 534 |
+
}
|
| 535 |
+
for file, content in files.items():
|
| 536 |
+
with open(file, "w", encoding="utf-8") as fh:
|
| 537 |
+
fh.write(cleandoc(content))
|
| 538 |
+
|
| 539 |
+
bdist_wheel_cmd().run()
|
| 540 |
+
|
| 541 |
+
# Ensure .whl, .dist-info and .data contain the local segment
|
| 542 |
+
wheel_path = "dist/test-1.0+what-py3-none-any.whl"
|
| 543 |
+
assert os.path.exists(wheel_path)
|
| 544 |
+
entries = set(ZipFile(wheel_path).namelist())
|
| 545 |
+
for expected in (
|
| 546 |
+
"test-1.0+what.data/headers/hello.h",
|
| 547 |
+
"test-1.0+what.data/data/hello/world/file.txt",
|
| 548 |
+
"test-1.0+what.dist-info/METADATA",
|
| 549 |
+
"test-1.0+what.dist-info/WHEEL",
|
| 550 |
+
):
|
| 551 |
+
assert expected in entries
|
| 552 |
+
|
| 553 |
+
for not_expected in (
|
| 554 |
+
"test.data/headers/hello.h",
|
| 555 |
+
"test-1.0.data/data/hello/world/file.txt",
|
| 556 |
+
"test.dist-info/METADATA",
|
| 557 |
+
"test-1.0.dist-info/WHEEL",
|
| 558 |
+
):
|
| 559 |
+
assert not_expected not in entries
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
@pytest.mark.parametrize(
|
| 563 |
+
("reported", "expected"),
|
| 564 |
+
[("linux-x86_64", "linux_i686"), ("linux-aarch64", "linux_armv7l")],
|
| 565 |
+
)
|
| 566 |
+
@pytest.mark.skipif(
|
| 567 |
+
platform.system() != "Linux", reason="Only makes sense to test on Linux"
|
| 568 |
+
)
|
| 569 |
+
def test_platform_linux32(reported, expected, monkeypatch):
|
| 570 |
+
monkeypatch.setattr(struct, "calcsize", lambda x: 4)
|
| 571 |
+
dist = setuptools.Distribution()
|
| 572 |
+
cmd = bdist_wheel(dist)
|
| 573 |
+
cmd.plat_name = reported
|
| 574 |
+
cmd.root_is_pure = False
|
| 575 |
+
_, _, actual = cmd.get_tag()
|
| 576 |
+
assert actual == expected
|
| 577 |
+
|
| 578 |
+
|
| 579 |
+
def test_no_ctypes(monkeypatch) -> None:
|
| 580 |
+
def _fake_import(name: str, *args, **kwargs):
|
| 581 |
+
if name == "ctypes":
|
| 582 |
+
raise ModuleNotFoundError(f"No module named {name}")
|
| 583 |
+
|
| 584 |
+
return importlib.__import__(name, *args, **kwargs)
|
| 585 |
+
|
| 586 |
+
with suppress(KeyError):
|
| 587 |
+
monkeypatch.delitem(sys.modules, "wheel.macosx_libfile")
|
| 588 |
+
|
| 589 |
+
# Install an importer shim that refuses to load ctypes
|
| 590 |
+
monkeypatch.setattr(builtins, "__import__", _fake_import)
|
| 591 |
+
with pytest.raises(ModuleNotFoundError, match="No module named ctypes"):
|
| 592 |
+
import wheel.macosx_libfile # noqa: F401
|
| 593 |
+
|
| 594 |
+
# Unload and reimport the bdist_wheel command module to make sure it won't try to
|
| 595 |
+
# import ctypes
|
| 596 |
+
monkeypatch.delitem(sys.modules, "setuptools.command.bdist_wheel")
|
| 597 |
+
|
| 598 |
+
import setuptools.command.bdist_wheel # noqa: F401
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def test_dist_info_provided(dummy_dist, monkeypatch, tmp_path):
|
| 602 |
+
monkeypatch.chdir(dummy_dist)
|
| 603 |
+
distinfo = tmp_path / "dummy_dist.dist-info"
|
| 604 |
+
|
| 605 |
+
distinfo.mkdir()
|
| 606 |
+
(distinfo / "METADATA").write_text("name: helloworld", encoding="utf-8")
|
| 607 |
+
|
| 608 |
+
# We don't control the metadata. According to PEP-517, "The hook MAY also
|
| 609 |
+
# create other files inside this directory, and a build frontend MUST
|
| 610 |
+
# preserve".
|
| 611 |
+
(distinfo / "FOO").write_text("bar", encoding="utf-8")
|
| 612 |
+
|
| 613 |
+
bdist_wheel_cmd(bdist_dir=str(tmp_path), dist_info_dir=str(distinfo)).run()
|
| 614 |
+
expected = {
|
| 615 |
+
"dummy_dist-1.0.dist-info/FOO",
|
| 616 |
+
"dummy_dist-1.0.dist-info/RECORD",
|
| 617 |
+
}
|
| 618 |
+
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
|
| 619 |
+
files_found = set(wf.namelist())
|
| 620 |
+
# Check that all expected files are there.
|
| 621 |
+
assert expected - files_found == set()
|
| 622 |
+
# Make sure there is no accidental egg-info bleeding into the wheel.
|
| 623 |
+
assert not [path for path in files_found if 'egg-info' in str(path)]
|
videollama2/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]
|
videollama2/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}'
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_config_discovery.py
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from configparser import ConfigParser
|
| 4 |
+
from itertools import product
|
| 5 |
+
from typing import cast
|
| 6 |
+
|
| 7 |
+
import jaraco.path
|
| 8 |
+
import pytest
|
| 9 |
+
from path import Path
|
| 10 |
+
|
| 11 |
+
import setuptools # noqa: F401 # force distutils.core to be patched
|
| 12 |
+
from setuptools.command.sdist import sdist
|
| 13 |
+
from setuptools.discovery import find_package_path, find_parent_package
|
| 14 |
+
from setuptools.dist import Distribution
|
| 15 |
+
from setuptools.errors import PackageDiscoveryError
|
| 16 |
+
|
| 17 |
+
from .contexts import quiet
|
| 18 |
+
from .integration.helpers import get_sdist_members, get_wheel_members, run
|
| 19 |
+
from .textwrap import DALS
|
| 20 |
+
|
| 21 |
+
import distutils.core
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class TestFindParentPackage:
|
| 25 |
+
def test_single_package(self, tmp_path):
|
| 26 |
+
# find_parent_package should find a non-namespace parent package
|
| 27 |
+
(tmp_path / "src/namespace/pkg/nested").mkdir(exist_ok=True, parents=True)
|
| 28 |
+
(tmp_path / "src/namespace/pkg/nested/__init__.py").touch()
|
| 29 |
+
(tmp_path / "src/namespace/pkg/__init__.py").touch()
|
| 30 |
+
packages = ["namespace", "namespace.pkg", "namespace.pkg.nested"]
|
| 31 |
+
assert find_parent_package(packages, {"": "src"}, tmp_path) == "namespace.pkg"
|
| 32 |
+
|
| 33 |
+
def test_multiple_toplevel(self, tmp_path):
|
| 34 |
+
# find_parent_package should return null if the given list of packages does not
|
| 35 |
+
# have a single parent package
|
| 36 |
+
multiple = ["pkg", "pkg1", "pkg2"]
|
| 37 |
+
for name in multiple:
|
| 38 |
+
(tmp_path / f"src/{name}").mkdir(exist_ok=True, parents=True)
|
| 39 |
+
(tmp_path / f"src/{name}/__init__.py").touch()
|
| 40 |
+
assert find_parent_package(multiple, {"": "src"}, tmp_path) is None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class TestDiscoverPackagesAndPyModules:
|
| 44 |
+
"""Make sure discovered values for ``packages`` and ``py_modules`` work
|
| 45 |
+
similarly to explicit configuration for the simple scenarios.
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
OPTIONS = {
|
| 49 |
+
# Different options according to the circumstance being tested
|
| 50 |
+
"explicit-src": {"package_dir": {"": "src"}, "packages": ["pkg"]},
|
| 51 |
+
"variation-lib": {
|
| 52 |
+
"package_dir": {"": "lib"}, # variation of the source-layout
|
| 53 |
+
},
|
| 54 |
+
"explicit-flat": {"packages": ["pkg"]},
|
| 55 |
+
"explicit-single_module": {"py_modules": ["pkg"]},
|
| 56 |
+
"explicit-namespace": {"packages": ["ns", "ns.pkg"]},
|
| 57 |
+
"automatic-src": {},
|
| 58 |
+
"automatic-flat": {},
|
| 59 |
+
"automatic-single_module": {},
|
| 60 |
+
"automatic-namespace": {},
|
| 61 |
+
}
|
| 62 |
+
FILES = {
|
| 63 |
+
"src": ["src/pkg/__init__.py", "src/pkg/main.py"],
|
| 64 |
+
"lib": ["lib/pkg/__init__.py", "lib/pkg/main.py"],
|
| 65 |
+
"flat": ["pkg/__init__.py", "pkg/main.py"],
|
| 66 |
+
"single_module": ["pkg.py"],
|
| 67 |
+
"namespace": ["ns/pkg/__init__.py"],
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
def _get_info(self, circumstance):
|
| 71 |
+
_, _, layout = circumstance.partition("-")
|
| 72 |
+
files = self.FILES[layout]
|
| 73 |
+
options = self.OPTIONS[circumstance]
|
| 74 |
+
return files, options
|
| 75 |
+
|
| 76 |
+
@pytest.mark.parametrize("circumstance", OPTIONS.keys())
|
| 77 |
+
def test_sdist_filelist(self, tmp_path, circumstance):
|
| 78 |
+
files, options = self._get_info(circumstance)
|
| 79 |
+
_populate_project_dir(tmp_path, files, options)
|
| 80 |
+
|
| 81 |
+
_, cmd = _run_sdist_programatically(tmp_path, options)
|
| 82 |
+
|
| 83 |
+
manifest = [f.replace(os.sep, "/") for f in cmd.filelist.files]
|
| 84 |
+
for file in files:
|
| 85 |
+
assert any(f.endswith(file) for f in manifest)
|
| 86 |
+
|
| 87 |
+
@pytest.mark.parametrize("circumstance", OPTIONS.keys())
|
| 88 |
+
def test_project(self, tmp_path, circumstance):
|
| 89 |
+
files, options = self._get_info(circumstance)
|
| 90 |
+
_populate_project_dir(tmp_path, files, options)
|
| 91 |
+
|
| 92 |
+
# Simulate a pre-existing `build` directory
|
| 93 |
+
(tmp_path / "build").mkdir()
|
| 94 |
+
(tmp_path / "build/lib").mkdir()
|
| 95 |
+
(tmp_path / "build/bdist.linux-x86_64").mkdir()
|
| 96 |
+
(tmp_path / "build/bdist.linux-x86_64/file.py").touch()
|
| 97 |
+
(tmp_path / "build/lib/__init__.py").touch()
|
| 98 |
+
(tmp_path / "build/lib/file.py").touch()
|
| 99 |
+
(tmp_path / "dist").mkdir()
|
| 100 |
+
(tmp_path / "dist/file.py").touch()
|
| 101 |
+
|
| 102 |
+
_run_build(tmp_path)
|
| 103 |
+
|
| 104 |
+
sdist_files = get_sdist_members(next(tmp_path.glob("dist/*.tar.gz")))
|
| 105 |
+
print("~~~~~ sdist_members ~~~~~")
|
| 106 |
+
print('\n'.join(sdist_files))
|
| 107 |
+
assert sdist_files >= set(files)
|
| 108 |
+
|
| 109 |
+
wheel_files = get_wheel_members(next(tmp_path.glob("dist/*.whl")))
|
| 110 |
+
print("~~~~~ wheel_members ~~~~~")
|
| 111 |
+
print('\n'.join(wheel_files))
|
| 112 |
+
orig_files = {f.replace("src/", "").replace("lib/", "") for f in files}
|
| 113 |
+
assert wheel_files >= orig_files
|
| 114 |
+
|
| 115 |
+
# Make sure build files are not included by mistake
|
| 116 |
+
for file in wheel_files:
|
| 117 |
+
assert "build" not in files
|
| 118 |
+
assert "dist" not in files
|
| 119 |
+
|
| 120 |
+
PURPOSEFULLY_EMPY = {
|
| 121 |
+
"setup.cfg": DALS(
|
| 122 |
+
"""
|
| 123 |
+
[metadata]
|
| 124 |
+
name = myproj
|
| 125 |
+
version = 0.0.0
|
| 126 |
+
|
| 127 |
+
[options]
|
| 128 |
+
{param} =
|
| 129 |
+
"""
|
| 130 |
+
),
|
| 131 |
+
"setup.py": DALS(
|
| 132 |
+
"""
|
| 133 |
+
__import__('setuptools').setup(
|
| 134 |
+
name="myproj",
|
| 135 |
+
version="0.0.0",
|
| 136 |
+
{param}=[]
|
| 137 |
+
)
|
| 138 |
+
"""
|
| 139 |
+
),
|
| 140 |
+
"pyproject.toml": DALS(
|
| 141 |
+
"""
|
| 142 |
+
[build-system]
|
| 143 |
+
requires = []
|
| 144 |
+
build-backend = 'setuptools.build_meta'
|
| 145 |
+
|
| 146 |
+
[project]
|
| 147 |
+
name = "myproj"
|
| 148 |
+
version = "0.0.0"
|
| 149 |
+
|
| 150 |
+
[tool.setuptools]
|
| 151 |
+
{param} = []
|
| 152 |
+
"""
|
| 153 |
+
),
|
| 154 |
+
"template-pyproject.toml": DALS(
|
| 155 |
+
"""
|
| 156 |
+
[build-system]
|
| 157 |
+
requires = []
|
| 158 |
+
build-backend = 'setuptools.build_meta'
|
| 159 |
+
"""
|
| 160 |
+
),
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
@pytest.mark.parametrize(
|
| 164 |
+
("config_file", "param", "circumstance"),
|
| 165 |
+
product(
|
| 166 |
+
["setup.cfg", "setup.py", "pyproject.toml"],
|
| 167 |
+
["packages", "py_modules"],
|
| 168 |
+
FILES.keys(),
|
| 169 |
+
),
|
| 170 |
+
)
|
| 171 |
+
def test_purposefully_empty(self, tmp_path, config_file, param, circumstance):
|
| 172 |
+
files = self.FILES[circumstance] + ["mod.py", "other.py", "src/pkg/__init__.py"]
|
| 173 |
+
_populate_project_dir(tmp_path, files, {})
|
| 174 |
+
|
| 175 |
+
if config_file == "pyproject.toml":
|
| 176 |
+
template_param = param.replace("_", "-")
|
| 177 |
+
else:
|
| 178 |
+
# Make sure build works with or without setup.cfg
|
| 179 |
+
pyproject = self.PURPOSEFULLY_EMPY["template-pyproject.toml"]
|
| 180 |
+
(tmp_path / "pyproject.toml").write_text(pyproject, encoding="utf-8")
|
| 181 |
+
template_param = param
|
| 182 |
+
|
| 183 |
+
config = self.PURPOSEFULLY_EMPY[config_file].format(param=template_param)
|
| 184 |
+
(tmp_path / config_file).write_text(config, encoding="utf-8")
|
| 185 |
+
|
| 186 |
+
dist = _get_dist(tmp_path, {})
|
| 187 |
+
# When either parameter package or py_modules is an empty list,
|
| 188 |
+
# then there should be no discovery
|
| 189 |
+
assert getattr(dist, param) == []
|
| 190 |
+
other = {"py_modules": "packages", "packages": "py_modules"}[param]
|
| 191 |
+
assert getattr(dist, other) is None
|
| 192 |
+
|
| 193 |
+
@pytest.mark.parametrize(
|
| 194 |
+
("extra_files", "pkgs"),
|
| 195 |
+
[
|
| 196 |
+
(["venv/bin/simulate_venv"], {"pkg"}),
|
| 197 |
+
(["pkg-stubs/__init__.pyi"], {"pkg", "pkg-stubs"}),
|
| 198 |
+
(["other-stubs/__init__.pyi"], {"pkg", "other-stubs"}),
|
| 199 |
+
(
|
| 200 |
+
# Type stubs can also be namespaced
|
| 201 |
+
["namespace-stubs/pkg/__init__.pyi"],
|
| 202 |
+
{"pkg", "namespace-stubs", "namespace-stubs.pkg"},
|
| 203 |
+
),
|
| 204 |
+
(
|
| 205 |
+
# Just the top-level package can have `-stubs`, ignore nested ones
|
| 206 |
+
["namespace-stubs/pkg-stubs/__init__.pyi"],
|
| 207 |
+
{"pkg", "namespace-stubs"},
|
| 208 |
+
),
|
| 209 |
+
(["_hidden/file.py"], {"pkg"}),
|
| 210 |
+
(["news/finalize.py"], {"pkg"}),
|
| 211 |
+
],
|
| 212 |
+
)
|
| 213 |
+
def test_flat_layout_with_extra_files(self, tmp_path, extra_files, pkgs):
|
| 214 |
+
files = self.FILES["flat"] + extra_files
|
| 215 |
+
_populate_project_dir(tmp_path, files, {})
|
| 216 |
+
dist = _get_dist(tmp_path, {})
|
| 217 |
+
assert set(dist.packages) == pkgs
|
| 218 |
+
|
| 219 |
+
@pytest.mark.parametrize(
|
| 220 |
+
"extra_files",
|
| 221 |
+
[
|
| 222 |
+
["other/__init__.py"],
|
| 223 |
+
["other/finalize.py"],
|
| 224 |
+
],
|
| 225 |
+
)
|
| 226 |
+
def test_flat_layout_with_dangerous_extra_files(self, tmp_path, extra_files):
|
| 227 |
+
files = self.FILES["flat"] + extra_files
|
| 228 |
+
_populate_project_dir(tmp_path, files, {})
|
| 229 |
+
with pytest.raises(PackageDiscoveryError, match="multiple (packages|modules)"):
|
| 230 |
+
_get_dist(tmp_path, {})
|
| 231 |
+
|
| 232 |
+
def test_flat_layout_with_single_module(self, tmp_path):
|
| 233 |
+
files = self.FILES["single_module"] + ["invalid-module-name.py"]
|
| 234 |
+
_populate_project_dir(tmp_path, files, {})
|
| 235 |
+
dist = _get_dist(tmp_path, {})
|
| 236 |
+
assert set(dist.py_modules) == {"pkg"}
|
| 237 |
+
|
| 238 |
+
def test_flat_layout_with_multiple_modules(self, tmp_path):
|
| 239 |
+
files = self.FILES["single_module"] + ["valid_module_name.py"]
|
| 240 |
+
_populate_project_dir(tmp_path, files, {})
|
| 241 |
+
with pytest.raises(PackageDiscoveryError, match="multiple (packages|modules)"):
|
| 242 |
+
_get_dist(tmp_path, {})
|
| 243 |
+
|
| 244 |
+
def test_py_modules_when_wheel_dir_is_cwd(self, tmp_path):
|
| 245 |
+
"""Regression for issue 3692"""
|
| 246 |
+
from setuptools import build_meta
|
| 247 |
+
|
| 248 |
+
pyproject = '[project]\nname = "test"\nversion = "1"'
|
| 249 |
+
(tmp_path / "pyproject.toml").write_text(DALS(pyproject), encoding="utf-8")
|
| 250 |
+
(tmp_path / "foo.py").touch()
|
| 251 |
+
with jaraco.path.DirectoryStack().context(tmp_path):
|
| 252 |
+
build_meta.build_wheel(".")
|
| 253 |
+
# Ensure py_modules are found
|
| 254 |
+
wheel_files = get_wheel_members(next(tmp_path.glob("*.whl")))
|
| 255 |
+
assert "foo.py" in wheel_files
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
class TestNoConfig:
|
| 259 |
+
DEFAULT_VERSION = "0.0.0" # Default version given by setuptools
|
| 260 |
+
|
| 261 |
+
EXAMPLES = {
|
| 262 |
+
"pkg1": ["src/pkg1.py"],
|
| 263 |
+
"pkg2": ["src/pkg2/__init__.py"],
|
| 264 |
+
"pkg3": ["src/pkg3/__init__.py", "src/pkg3-stubs/__init__.py"],
|
| 265 |
+
"pkg4": ["pkg4/__init__.py", "pkg4-stubs/__init__.py"],
|
| 266 |
+
"ns.nested.pkg1": ["src/ns/nested/pkg1/__init__.py"],
|
| 267 |
+
"ns.nested.pkg2": ["ns/nested/pkg2/__init__.py"],
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
@pytest.mark.parametrize("example", EXAMPLES.keys())
|
| 271 |
+
def test_discover_name(self, tmp_path, example):
|
| 272 |
+
_populate_project_dir(tmp_path, self.EXAMPLES[example], {})
|
| 273 |
+
dist = _get_dist(tmp_path, {})
|
| 274 |
+
assert dist.get_name() == example
|
| 275 |
+
|
| 276 |
+
def test_build_with_discovered_name(self, tmp_path):
|
| 277 |
+
files = ["src/ns/nested/pkg/__init__.py"]
|
| 278 |
+
_populate_project_dir(tmp_path, files, {})
|
| 279 |
+
_run_build(tmp_path, "--sdist")
|
| 280 |
+
# Expected distribution file
|
| 281 |
+
dist_file = tmp_path / f"dist/ns_nested_pkg-{self.DEFAULT_VERSION}.tar.gz"
|
| 282 |
+
assert dist_file.is_file()
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
class TestWithAttrDirective:
|
| 286 |
+
@pytest.mark.parametrize(
|
| 287 |
+
("folder", "opts"),
|
| 288 |
+
[
|
| 289 |
+
("src", {}),
|
| 290 |
+
("lib", {"packages": "find:", "packages.find": {"where": "lib"}}),
|
| 291 |
+
],
|
| 292 |
+
)
|
| 293 |
+
def test_setupcfg_metadata(self, tmp_path, folder, opts):
|
| 294 |
+
files = [f"{folder}/pkg/__init__.py", "setup.cfg"]
|
| 295 |
+
_populate_project_dir(tmp_path, files, opts)
|
| 296 |
+
|
| 297 |
+
config = (tmp_path / "setup.cfg").read_text(encoding="utf-8")
|
| 298 |
+
overwrite = {
|
| 299 |
+
folder: {"pkg": {"__init__.py": "version = 42"}},
|
| 300 |
+
"setup.cfg": "[metadata]\nversion = attr: pkg.version\n" + config,
|
| 301 |
+
}
|
| 302 |
+
jaraco.path.build(overwrite, prefix=tmp_path)
|
| 303 |
+
|
| 304 |
+
dist = _get_dist(tmp_path, {})
|
| 305 |
+
assert dist.get_name() == "pkg"
|
| 306 |
+
assert dist.get_version() == "42"
|
| 307 |
+
assert dist.package_dir
|
| 308 |
+
package_path = find_package_path("pkg", dist.package_dir, tmp_path)
|
| 309 |
+
assert os.path.exists(package_path)
|
| 310 |
+
assert folder in Path(package_path).parts()
|
| 311 |
+
|
| 312 |
+
_run_build(tmp_path, "--sdist")
|
| 313 |
+
dist_file = tmp_path / "dist/pkg-42.tar.gz"
|
| 314 |
+
assert dist_file.is_file()
|
| 315 |
+
|
| 316 |
+
def test_pyproject_metadata(self, tmp_path):
|
| 317 |
+
_populate_project_dir(tmp_path, ["src/pkg/__init__.py"], {})
|
| 318 |
+
|
| 319 |
+
overwrite = {
|
| 320 |
+
"src": {"pkg": {"__init__.py": "version = 42"}},
|
| 321 |
+
"pyproject.toml": (
|
| 322 |
+
"[project]\nname = 'pkg'\ndynamic = ['version']\n"
|
| 323 |
+
"[tool.setuptools.dynamic]\nversion = {attr = 'pkg.version'}\n"
|
| 324 |
+
),
|
| 325 |
+
}
|
| 326 |
+
jaraco.path.build(overwrite, prefix=tmp_path)
|
| 327 |
+
|
| 328 |
+
dist = _get_dist(tmp_path, {})
|
| 329 |
+
assert dist.get_version() == "42"
|
| 330 |
+
assert dist.package_dir == {"": "src"}
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
class TestWithCExtension:
|
| 334 |
+
def _simulate_package_with_extension(self, tmp_path):
|
| 335 |
+
# This example is based on: https://github.com/nucleic/kiwi/tree/1.4.0
|
| 336 |
+
files = [
|
| 337 |
+
"benchmarks/file.py",
|
| 338 |
+
"docs/Makefile",
|
| 339 |
+
"docs/requirements.txt",
|
| 340 |
+
"docs/source/conf.py",
|
| 341 |
+
"proj/header.h",
|
| 342 |
+
"proj/file.py",
|
| 343 |
+
"py/proj.cpp",
|
| 344 |
+
"py/other.cpp",
|
| 345 |
+
"py/file.py",
|
| 346 |
+
"py/py.typed",
|
| 347 |
+
"py/tests/test_proj.py",
|
| 348 |
+
"README.rst",
|
| 349 |
+
]
|
| 350 |
+
_populate_project_dir(tmp_path, files, {})
|
| 351 |
+
|
| 352 |
+
setup_script = """
|
| 353 |
+
from setuptools import Extension, setup
|
| 354 |
+
|
| 355 |
+
ext_modules = [
|
| 356 |
+
Extension(
|
| 357 |
+
"proj",
|
| 358 |
+
["py/proj.cpp", "py/other.cpp"],
|
| 359 |
+
include_dirs=["."],
|
| 360 |
+
language="c++",
|
| 361 |
+
),
|
| 362 |
+
]
|
| 363 |
+
setup(ext_modules=ext_modules)
|
| 364 |
+
"""
|
| 365 |
+
(tmp_path / "setup.py").write_text(DALS(setup_script), encoding="utf-8")
|
| 366 |
+
|
| 367 |
+
def test_skip_discovery_with_setupcfg_metadata(self, tmp_path):
|
| 368 |
+
"""Ensure that auto-discovery is not triggered when the project is based on
|
| 369 |
+
C-extensions only, for backward compatibility.
|
| 370 |
+
"""
|
| 371 |
+
self._simulate_package_with_extension(tmp_path)
|
| 372 |
+
|
| 373 |
+
pyproject = """
|
| 374 |
+
[build-system]
|
| 375 |
+
requires = []
|
| 376 |
+
build-backend = 'setuptools.build_meta'
|
| 377 |
+
"""
|
| 378 |
+
(tmp_path / "pyproject.toml").write_text(DALS(pyproject), encoding="utf-8")
|
| 379 |
+
|
| 380 |
+
setupcfg = """
|
| 381 |
+
[metadata]
|
| 382 |
+
name = proj
|
| 383 |
+
version = 42
|
| 384 |
+
"""
|
| 385 |
+
(tmp_path / "setup.cfg").write_text(DALS(setupcfg), encoding="utf-8")
|
| 386 |
+
|
| 387 |
+
dist = _get_dist(tmp_path, {})
|
| 388 |
+
assert dist.get_name() == "proj"
|
| 389 |
+
assert dist.get_version() == "42"
|
| 390 |
+
assert dist.py_modules is None
|
| 391 |
+
assert dist.packages is None
|
| 392 |
+
assert len(dist.ext_modules) == 1
|
| 393 |
+
assert dist.ext_modules[0].name == "proj"
|
| 394 |
+
|
| 395 |
+
def test_dont_skip_discovery_with_pyproject_metadata(self, tmp_path):
|
| 396 |
+
"""When opting-in to pyproject.toml metadata, auto-discovery will be active if
|
| 397 |
+
the package lists C-extensions, but does not configure py-modules or packages.
|
| 398 |
+
|
| 399 |
+
This way we ensure users with complex package layouts that would lead to the
|
| 400 |
+
discovery of multiple top-level modules/packages see errors and are forced to
|
| 401 |
+
explicitly set ``packages`` or ``py-modules``.
|
| 402 |
+
"""
|
| 403 |
+
self._simulate_package_with_extension(tmp_path)
|
| 404 |
+
|
| 405 |
+
pyproject = """
|
| 406 |
+
[project]
|
| 407 |
+
name = 'proj'
|
| 408 |
+
version = '42'
|
| 409 |
+
"""
|
| 410 |
+
(tmp_path / "pyproject.toml").write_text(DALS(pyproject), encoding="utf-8")
|
| 411 |
+
with pytest.raises(PackageDiscoveryError, match="multiple (packages|modules)"):
|
| 412 |
+
_get_dist(tmp_path, {})
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
class TestWithPackageData:
|
| 416 |
+
def _simulate_package_with_data_files(self, tmp_path, src_root):
|
| 417 |
+
files = [
|
| 418 |
+
f"{src_root}/proj/__init__.py",
|
| 419 |
+
f"{src_root}/proj/file1.txt",
|
| 420 |
+
f"{src_root}/proj/nested/file2.txt",
|
| 421 |
+
]
|
| 422 |
+
_populate_project_dir(tmp_path, files, {})
|
| 423 |
+
|
| 424 |
+
manifest = """
|
| 425 |
+
global-include *.py *.txt
|
| 426 |
+
"""
|
| 427 |
+
(tmp_path / "MANIFEST.in").write_text(DALS(manifest), encoding="utf-8")
|
| 428 |
+
|
| 429 |
+
EXAMPLE_SETUPCFG = """
|
| 430 |
+
[metadata]
|
| 431 |
+
name = proj
|
| 432 |
+
version = 42
|
| 433 |
+
|
| 434 |
+
[options]
|
| 435 |
+
include_package_data = True
|
| 436 |
+
"""
|
| 437 |
+
EXAMPLE_PYPROJECT = """
|
| 438 |
+
[project]
|
| 439 |
+
name = "proj"
|
| 440 |
+
version = "42"
|
| 441 |
+
"""
|
| 442 |
+
|
| 443 |
+
PYPROJECT_PACKAGE_DIR = """
|
| 444 |
+
[tool.setuptools]
|
| 445 |
+
package-dir = {"" = "src"}
|
| 446 |
+
"""
|
| 447 |
+
|
| 448 |
+
@pytest.mark.parametrize(
|
| 449 |
+
("src_root", "files"),
|
| 450 |
+
[
|
| 451 |
+
(".", {"setup.cfg": DALS(EXAMPLE_SETUPCFG)}),
|
| 452 |
+
(".", {"pyproject.toml": DALS(EXAMPLE_PYPROJECT)}),
|
| 453 |
+
("src", {"setup.cfg": DALS(EXAMPLE_SETUPCFG)}),
|
| 454 |
+
("src", {"pyproject.toml": DALS(EXAMPLE_PYPROJECT)}),
|
| 455 |
+
(
|
| 456 |
+
"src",
|
| 457 |
+
{
|
| 458 |
+
"setup.cfg": DALS(EXAMPLE_SETUPCFG)
|
| 459 |
+
+ DALS(
|
| 460 |
+
"""
|
| 461 |
+
packages = find:
|
| 462 |
+
package_dir =
|
| 463 |
+
=src
|
| 464 |
+
|
| 465 |
+
[options.packages.find]
|
| 466 |
+
where = src
|
| 467 |
+
"""
|
| 468 |
+
)
|
| 469 |
+
},
|
| 470 |
+
),
|
| 471 |
+
(
|
| 472 |
+
"src",
|
| 473 |
+
{
|
| 474 |
+
"pyproject.toml": DALS(EXAMPLE_PYPROJECT)
|
| 475 |
+
+ DALS(
|
| 476 |
+
"""
|
| 477 |
+
[tool.setuptools]
|
| 478 |
+
package-dir = {"" = "src"}
|
| 479 |
+
"""
|
| 480 |
+
)
|
| 481 |
+
},
|
| 482 |
+
),
|
| 483 |
+
],
|
| 484 |
+
)
|
| 485 |
+
def test_include_package_data(self, tmp_path, src_root, files):
|
| 486 |
+
"""
|
| 487 |
+
Make sure auto-discovery does not affect package include_package_data.
|
| 488 |
+
See issue #3196.
|
| 489 |
+
"""
|
| 490 |
+
jaraco.path.build(files, prefix=str(tmp_path))
|
| 491 |
+
self._simulate_package_with_data_files(tmp_path, src_root)
|
| 492 |
+
|
| 493 |
+
expected = {
|
| 494 |
+
os.path.normpath(f"{src_root}/proj/file1.txt").replace(os.sep, "/"),
|
| 495 |
+
os.path.normpath(f"{src_root}/proj/nested/file2.txt").replace(os.sep, "/"),
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
_run_build(tmp_path)
|
| 499 |
+
|
| 500 |
+
sdist_files = get_sdist_members(next(tmp_path.glob("dist/*.tar.gz")))
|
| 501 |
+
print("~~~~~ sdist_members ~~~~~")
|
| 502 |
+
print('\n'.join(sdist_files))
|
| 503 |
+
assert sdist_files >= expected
|
| 504 |
+
|
| 505 |
+
wheel_files = get_wheel_members(next(tmp_path.glob("dist/*.whl")))
|
| 506 |
+
print("~~~~~ wheel_members ~~~~~")
|
| 507 |
+
print('\n'.join(wheel_files))
|
| 508 |
+
orig_files = {f.replace("src/", "").replace("lib/", "") for f in expected}
|
| 509 |
+
assert wheel_files >= orig_files
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
def test_compatible_with_numpy_configuration(tmp_path):
|
| 513 |
+
files = [
|
| 514 |
+
"dir1/__init__.py",
|
| 515 |
+
"dir2/__init__.py",
|
| 516 |
+
"file.py",
|
| 517 |
+
]
|
| 518 |
+
_populate_project_dir(tmp_path, files, {})
|
| 519 |
+
dist = Distribution({})
|
| 520 |
+
dist.configuration = object()
|
| 521 |
+
dist.set_defaults()
|
| 522 |
+
assert dist.py_modules is None
|
| 523 |
+
assert dist.packages is None
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
def test_name_discovery_doesnt_break_cli(tmpdir_cwd):
|
| 527 |
+
jaraco.path.build({"pkg.py": ""})
|
| 528 |
+
dist = Distribution({})
|
| 529 |
+
dist.script_args = ["--name"]
|
| 530 |
+
dist.set_defaults()
|
| 531 |
+
dist.parse_command_line() # <-- no exception should be raised here.
|
| 532 |
+
assert dist.get_name() == "pkg"
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
def test_preserve_explicit_name_with_dynamic_version(tmpdir_cwd, monkeypatch):
|
| 536 |
+
"""According to #3545 it seems that ``name`` discovery is running,
|
| 537 |
+
even when the project already explicitly sets it.
|
| 538 |
+
This seems to be related to parsing of dynamic versions (via ``attr`` directive),
|
| 539 |
+
which requires the auto-discovery of ``package_dir``.
|
| 540 |
+
"""
|
| 541 |
+
files = {
|
| 542 |
+
"src": {
|
| 543 |
+
"pkg": {"__init__.py": "__version__ = 42\n"},
|
| 544 |
+
},
|
| 545 |
+
"pyproject.toml": DALS(
|
| 546 |
+
"""
|
| 547 |
+
[project]
|
| 548 |
+
name = "myproj" # purposefully different from package name
|
| 549 |
+
dynamic = ["version"]
|
| 550 |
+
[tool.setuptools.dynamic]
|
| 551 |
+
version = {"attr" = "pkg.__version__"}
|
| 552 |
+
"""
|
| 553 |
+
),
|
| 554 |
+
}
|
| 555 |
+
jaraco.path.build(files)
|
| 556 |
+
dist = Distribution({})
|
| 557 |
+
orig_analyse_name = dist.set_defaults.analyse_name
|
| 558 |
+
|
| 559 |
+
def spy_analyse_name():
|
| 560 |
+
# We can check if name discovery was triggered by ensuring the original
|
| 561 |
+
# name remains instead of the package name.
|
| 562 |
+
orig_analyse_name()
|
| 563 |
+
assert dist.get_name() == "myproj"
|
| 564 |
+
|
| 565 |
+
monkeypatch.setattr(dist.set_defaults, "analyse_name", spy_analyse_name)
|
| 566 |
+
dist.parse_config_files()
|
| 567 |
+
assert dist.get_version() == "42"
|
| 568 |
+
assert set(dist.packages) == {"pkg"}
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def _populate_project_dir(root, files, options):
|
| 572 |
+
# NOTE: Currently pypa/build will refuse to build the project if no
|
| 573 |
+
# `pyproject.toml` or `setup.py` is found. So it is impossible to do
|
| 574 |
+
# completely "config-less" projects.
|
| 575 |
+
basic = {
|
| 576 |
+
"setup.py": "import setuptools\nsetuptools.setup()",
|
| 577 |
+
"README.md": "# Example Package",
|
| 578 |
+
"LICENSE": "Copyright (c) 2018",
|
| 579 |
+
}
|
| 580 |
+
jaraco.path.build(basic, prefix=root)
|
| 581 |
+
_write_setupcfg(root, options)
|
| 582 |
+
paths = (root / f for f in files)
|
| 583 |
+
for path in paths:
|
| 584 |
+
path.parent.mkdir(exist_ok=True, parents=True)
|
| 585 |
+
path.touch()
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
def _write_setupcfg(root, options):
|
| 589 |
+
if not options:
|
| 590 |
+
print("~~~~~ **NO** setup.cfg ~~~~~")
|
| 591 |
+
return
|
| 592 |
+
setupcfg = ConfigParser()
|
| 593 |
+
setupcfg.add_section("options")
|
| 594 |
+
for key, value in options.items():
|
| 595 |
+
if key == "packages.find":
|
| 596 |
+
setupcfg.add_section(f"options.{key}")
|
| 597 |
+
setupcfg[f"options.{key}"].update(value)
|
| 598 |
+
elif isinstance(value, list):
|
| 599 |
+
setupcfg["options"][key] = ", ".join(value)
|
| 600 |
+
elif isinstance(value, dict):
|
| 601 |
+
str_value = "\n".join(f"\t{k} = {v}" for k, v in value.items())
|
| 602 |
+
setupcfg["options"][key] = "\n" + str_value
|
| 603 |
+
else:
|
| 604 |
+
setupcfg["options"][key] = str(value)
|
| 605 |
+
with open(root / "setup.cfg", "w", encoding="utf-8") as f:
|
| 606 |
+
setupcfg.write(f)
|
| 607 |
+
print("~~~~~ setup.cfg ~~~~~")
|
| 608 |
+
print((root / "setup.cfg").read_text(encoding="utf-8"))
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
def _run_build(path, *flags):
|
| 612 |
+
cmd = [sys.executable, "-m", "build", "--no-isolation", *flags, str(path)]
|
| 613 |
+
return run(cmd, env={'DISTUTILS_DEBUG': ''})
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
def _get_dist(dist_path, attrs):
|
| 617 |
+
root = "/".join(os.path.split(dist_path)) # POSIX-style
|
| 618 |
+
|
| 619 |
+
script = dist_path / 'setup.py'
|
| 620 |
+
if script.exists():
|
| 621 |
+
with Path(dist_path):
|
| 622 |
+
dist = cast(
|
| 623 |
+
Distribution,
|
| 624 |
+
distutils.core.run_setup("setup.py", {}, stop_after="init"),
|
| 625 |
+
)
|
| 626 |
+
else:
|
| 627 |
+
dist = Distribution(attrs)
|
| 628 |
+
|
| 629 |
+
dist.src_root = root
|
| 630 |
+
dist.script_name = "setup.py"
|
| 631 |
+
with Path(dist_path):
|
| 632 |
+
dist.parse_config_files()
|
| 633 |
+
|
| 634 |
+
dist.set_defaults()
|
| 635 |
+
return dist
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
def _run_sdist_programatically(dist_path, attrs):
|
| 639 |
+
dist = _get_dist(dist_path, attrs)
|
| 640 |
+
cmd = sdist(dist)
|
| 641 |
+
cmd.ensure_finalized()
|
| 642 |
+
assert cmd.distribution.packages or cmd.distribution.py_modules
|
| 643 |
+
|
| 644 |
+
with quiet(), Path(dist_path):
|
| 645 |
+
cmd.run()
|
| 646 |
+
|
| 647 |
+
return dist, cmd
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_dist.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import urllib.parse
|
| 4 |
+
import urllib.request
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 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
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_distutils_adoption.py
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import platform
|
| 3 |
+
import sys
|
| 4 |
+
import textwrap
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
IS_PYPY = '__pypy__' in sys.builtin_module_names
|
| 9 |
+
|
| 10 |
+
_TEXT_KWARGS = {"text": True, "encoding": "utf-8"} # For subprocess.run
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def win_sr(env):
|
| 14 |
+
"""
|
| 15 |
+
On Windows, SYSTEMROOT must be present to avoid
|
| 16 |
+
|
| 17 |
+
> Fatal Python error: _Py_HashRandomization_Init: failed to
|
| 18 |
+
> get random numbers to initialize Python
|
| 19 |
+
"""
|
| 20 |
+
if env and platform.system() == 'Windows':
|
| 21 |
+
env['SYSTEMROOT'] = os.environ['SYSTEMROOT']
|
| 22 |
+
return env
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def find_distutils(venv, imports='distutils', env=None, **kwargs):
|
| 26 |
+
py_cmd = 'import {imports}; print(distutils.__file__)'.format(**locals())
|
| 27 |
+
cmd = ['python', '-c', py_cmd]
|
| 28 |
+
return venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS, **kwargs)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def count_meta_path(venv, env=None):
|
| 32 |
+
py_cmd = textwrap.dedent(
|
| 33 |
+
"""
|
| 34 |
+
import sys
|
| 35 |
+
is_distutils = lambda finder: finder.__class__.__name__ == "DistutilsMetaFinder"
|
| 36 |
+
print(len(list(filter(is_distutils, sys.meta_path))))
|
| 37 |
+
"""
|
| 38 |
+
)
|
| 39 |
+
cmd = ['python', '-c', py_cmd]
|
| 40 |
+
return int(venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
skip_without_stdlib_distutils = pytest.mark.skipif(
|
| 44 |
+
sys.version_info >= (3, 12),
|
| 45 |
+
reason='stdlib distutils is removed from Python 3.12+',
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
@skip_without_stdlib_distutils
|
| 50 |
+
def test_distutils_stdlib(venv):
|
| 51 |
+
"""
|
| 52 |
+
Ensure stdlib distutils is used when appropriate.
|
| 53 |
+
"""
|
| 54 |
+
env = dict(SETUPTOOLS_USE_DISTUTILS='stdlib')
|
| 55 |
+
assert venv.name not in find_distutils(venv, env=env).split(os.sep)
|
| 56 |
+
assert count_meta_path(venv, env=env) == 0
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def test_distutils_local_with_setuptools(venv):
|
| 60 |
+
"""
|
| 61 |
+
Ensure local distutils is used when appropriate.
|
| 62 |
+
"""
|
| 63 |
+
env = dict(SETUPTOOLS_USE_DISTUTILS='local')
|
| 64 |
+
loc = find_distutils(venv, imports='setuptools, distutils', env=env)
|
| 65 |
+
assert venv.name in loc.split(os.sep)
|
| 66 |
+
assert count_meta_path(venv, env=env) <= 1
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
@pytest.mark.xfail('IS_PYPY', reason='pypy imports distutils on startup')
|
| 70 |
+
def test_distutils_local(venv):
|
| 71 |
+
"""
|
| 72 |
+
Even without importing, the setuptools-local copy of distutils is
|
| 73 |
+
preferred.
|
| 74 |
+
"""
|
| 75 |
+
env = dict(SETUPTOOLS_USE_DISTUTILS='local')
|
| 76 |
+
assert venv.name in find_distutils(venv, env=env).split(os.sep)
|
| 77 |
+
assert count_meta_path(venv, env=env) <= 1
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def test_pip_import(venv):
|
| 81 |
+
"""
|
| 82 |
+
Ensure pip can be imported.
|
| 83 |
+
Regression test for #3002.
|
| 84 |
+
"""
|
| 85 |
+
cmd = ['python', '-c', 'import pip']
|
| 86 |
+
venv.run(cmd, **_TEXT_KWARGS)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def test_distutils_has_origin():
|
| 90 |
+
"""
|
| 91 |
+
Distutils module spec should have an origin. #2990.
|
| 92 |
+
"""
|
| 93 |
+
assert __import__('distutils').__spec__.origin
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
ENSURE_IMPORTS_ARE_NOT_DUPLICATED = r"""
|
| 97 |
+
# Depending on the importlib machinery and _distutils_hack, some imports are
|
| 98 |
+
# duplicated resulting in different module objects being loaded, which prevents
|
| 99 |
+
# patches as shown in #3042.
|
| 100 |
+
# This script provides a way of verifying if this duplication is happening.
|
| 101 |
+
|
| 102 |
+
from distutils import cmd
|
| 103 |
+
import distutils.command.sdist as sdist
|
| 104 |
+
|
| 105 |
+
# import last to prevent caching
|
| 106 |
+
from distutils import {imported_module}
|
| 107 |
+
|
| 108 |
+
for mod in (cmd, sdist):
|
| 109 |
+
assert mod.{imported_module} == {imported_module}, (
|
| 110 |
+
f"\n{{mod.dir_util}}\n!=\n{{{imported_module}}}"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
print("success")
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
@pytest.mark.usefixtures("tmpdir_cwd")
|
| 118 |
+
@pytest.mark.parametrize(
|
| 119 |
+
('distutils_version', 'imported_module'),
|
| 120 |
+
[
|
| 121 |
+
pytest.param("stdlib", "dir_util", marks=skip_without_stdlib_distutils),
|
| 122 |
+
pytest.param("stdlib", "file_util", marks=skip_without_stdlib_distutils),
|
| 123 |
+
pytest.param("stdlib", "archive_util", marks=skip_without_stdlib_distutils),
|
| 124 |
+
("local", "dir_util"),
|
| 125 |
+
("local", "file_util"),
|
| 126 |
+
("local", "archive_util"),
|
| 127 |
+
],
|
| 128 |
+
)
|
| 129 |
+
def test_modules_are_not_duplicated_on_import(distutils_version, imported_module, venv):
|
| 130 |
+
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
|
| 131 |
+
script = ENSURE_IMPORTS_ARE_NOT_DUPLICATED.format(imported_module=imported_module)
|
| 132 |
+
cmd = ['python', '-c', script]
|
| 133 |
+
output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip()
|
| 134 |
+
assert output == "success"
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
ENSURE_LOG_IMPORT_IS_NOT_DUPLICATED = r"""
|
| 138 |
+
import types
|
| 139 |
+
import distutils.dist as dist
|
| 140 |
+
from distutils import log
|
| 141 |
+
if isinstance(dist.log, types.ModuleType):
|
| 142 |
+
assert dist.log == log, f"\n{dist.log}\n!=\n{log}"
|
| 143 |
+
print("success")
|
| 144 |
+
"""
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
@pytest.mark.usefixtures("tmpdir_cwd")
|
| 148 |
+
@pytest.mark.parametrize(
|
| 149 |
+
"distutils_version",
|
| 150 |
+
[
|
| 151 |
+
"local",
|
| 152 |
+
pytest.param("stdlib", marks=skip_without_stdlib_distutils),
|
| 153 |
+
],
|
| 154 |
+
)
|
| 155 |
+
def test_log_module_is_not_duplicated_on_import(distutils_version, venv):
|
| 156 |
+
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
|
| 157 |
+
cmd = ['python', '-c', ENSURE_LOG_IMPORT_IS_NOT_DUPLICATED]
|
| 158 |
+
output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip()
|
| 159 |
+
assert output == "success"
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
ENSURE_CONSISTENT_ERROR_FROM_MODIFIED_PY = r"""
|
| 163 |
+
from setuptools.modified import newer
|
| 164 |
+
from {imported_module}.errors import DistutilsError
|
| 165 |
+
|
| 166 |
+
# Can't use pytest.raises in this context
|
| 167 |
+
try:
|
| 168 |
+
newer("", "")
|
| 169 |
+
except DistutilsError:
|
| 170 |
+
print("success")
|
| 171 |
+
else:
|
| 172 |
+
raise AssertionError("Expected to raise")
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
@pytest.mark.usefixtures("tmpdir_cwd")
|
| 177 |
+
@pytest.mark.parametrize(
|
| 178 |
+
('distutils_version', 'imported_module'),
|
| 179 |
+
[
|
| 180 |
+
("local", "distutils"),
|
| 181 |
+
# Unfortunately we still get ._distutils.errors.DistutilsError with SETUPTOOLS_USE_DISTUTILS=stdlib
|
| 182 |
+
# But that's a deprecated use-case we don't mind not fully supporting in newer code
|
| 183 |
+
pytest.param(
|
| 184 |
+
"stdlib", "setuptools._distutils", marks=skip_without_stdlib_distutils
|
| 185 |
+
),
|
| 186 |
+
],
|
| 187 |
+
)
|
| 188 |
+
def test_consistent_error_from_modified_py(distutils_version, imported_module, venv):
|
| 189 |
+
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
|
| 190 |
+
cmd = [
|
| 191 |
+
'python',
|
| 192 |
+
'-c',
|
| 193 |
+
ENSURE_CONSISTENT_ERROR_FROM_MODIFIED_PY.format(
|
| 194 |
+
imported_module=imported_module
|
| 195 |
+
),
|
| 196 |
+
]
|
| 197 |
+
output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip()
|
| 198 |
+
assert output == "success"
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_easy_install.py
ADDED
|
@@ -0,0 +1,1472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
import io
|
| 5 |
+
import itertools
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import re
|
| 10 |
+
import site
|
| 11 |
+
import subprocess
|
| 12 |
+
import sys
|
| 13 |
+
import tarfile
|
| 14 |
+
import tempfile
|
| 15 |
+
import time
|
| 16 |
+
import warnings
|
| 17 |
+
import zipfile
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
from typing import NamedTuple
|
| 20 |
+
from unittest import mock
|
| 21 |
+
|
| 22 |
+
import pytest
|
| 23 |
+
from jaraco import path
|
| 24 |
+
|
| 25 |
+
import pkg_resources
|
| 26 |
+
import setuptools.command.easy_install as ei
|
| 27 |
+
from pkg_resources import Distribution as PRDistribution, normalize_path, working_set
|
| 28 |
+
from setuptools import sandbox
|
| 29 |
+
from setuptools.command.easy_install import PthDistributions
|
| 30 |
+
from setuptools.dist import Distribution
|
| 31 |
+
from setuptools.sandbox import run_setup
|
| 32 |
+
from setuptools.tests import fail_on_ascii
|
| 33 |
+
from setuptools.tests.server import MockServer, path_to_url
|
| 34 |
+
|
| 35 |
+
from . import contexts
|
| 36 |
+
from .textwrap import DALS
|
| 37 |
+
|
| 38 |
+
import distutils.errors
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@pytest.fixture(autouse=True)
|
| 42 |
+
def pip_disable_index(monkeypatch):
|
| 43 |
+
"""
|
| 44 |
+
Important: Disable the default index for pip to avoid
|
| 45 |
+
querying packages in the index and potentially resolving
|
| 46 |
+
and installing packages there.
|
| 47 |
+
"""
|
| 48 |
+
monkeypatch.setenv('PIP_NO_INDEX', 'true')
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class FakeDist:
|
| 52 |
+
def get_entry_map(self, group):
|
| 53 |
+
if group != 'console_scripts':
|
| 54 |
+
return {}
|
| 55 |
+
return {'name': 'ep'}
|
| 56 |
+
|
| 57 |
+
def as_requirement(self):
|
| 58 |
+
return 'spec'
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
SETUP_PY = DALS(
|
| 62 |
+
"""
|
| 63 |
+
from setuptools import setup
|
| 64 |
+
|
| 65 |
+
setup()
|
| 66 |
+
"""
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class TestEasyInstallTest:
|
| 71 |
+
def test_get_script_args(self):
|
| 72 |
+
header = ei.CommandSpec.best().from_environment().as_header()
|
| 73 |
+
dist = FakeDist()
|
| 74 |
+
args = next(ei.ScriptWriter.get_args(dist))
|
| 75 |
+
_name, script = itertools.islice(args, 2)
|
| 76 |
+
assert script.startswith(header)
|
| 77 |
+
assert "'spec'" in script
|
| 78 |
+
assert "'console_scripts'" in script
|
| 79 |
+
assert "'name'" in script
|
| 80 |
+
assert re.search('^# EASY-INSTALL-ENTRY-SCRIPT', script, flags=re.MULTILINE)
|
| 81 |
+
|
| 82 |
+
def test_no_find_links(self):
|
| 83 |
+
# new option '--no-find-links', that blocks find-links added at
|
| 84 |
+
# the project level
|
| 85 |
+
dist = Distribution()
|
| 86 |
+
cmd = ei.easy_install(dist)
|
| 87 |
+
cmd.check_pth_processing = lambda: True
|
| 88 |
+
cmd.no_find_links = True
|
| 89 |
+
cmd.find_links = ['link1', 'link2']
|
| 90 |
+
cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
|
| 91 |
+
cmd.args = ['ok']
|
| 92 |
+
cmd.ensure_finalized()
|
| 93 |
+
assert cmd.package_index.scanned_urls == {}
|
| 94 |
+
|
| 95 |
+
# let's try without it (default behavior)
|
| 96 |
+
cmd = ei.easy_install(dist)
|
| 97 |
+
cmd.check_pth_processing = lambda: True
|
| 98 |
+
cmd.find_links = ['link1', 'link2']
|
| 99 |
+
cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
|
| 100 |
+
cmd.args = ['ok']
|
| 101 |
+
cmd.ensure_finalized()
|
| 102 |
+
keys = sorted(cmd.package_index.scanned_urls.keys())
|
| 103 |
+
assert keys == ['link1', 'link2']
|
| 104 |
+
|
| 105 |
+
def test_write_exception(self):
|
| 106 |
+
"""
|
| 107 |
+
Test that `cant_write_to_target` is rendered as a DistutilsError.
|
| 108 |
+
"""
|
| 109 |
+
dist = Distribution()
|
| 110 |
+
cmd = ei.easy_install(dist)
|
| 111 |
+
cmd.install_dir = os.getcwd()
|
| 112 |
+
with pytest.raises(distutils.errors.DistutilsError):
|
| 113 |
+
cmd.cant_write_to_target()
|
| 114 |
+
|
| 115 |
+
def test_all_site_dirs(self, monkeypatch):
|
| 116 |
+
"""
|
| 117 |
+
get_site_dirs should always return site dirs reported by
|
| 118 |
+
site.getsitepackages.
|
| 119 |
+
"""
|
| 120 |
+
path = normalize_path('/setuptools/test/site-packages')
|
| 121 |
+
|
| 122 |
+
def mock_gsp():
|
| 123 |
+
return [path]
|
| 124 |
+
|
| 125 |
+
monkeypatch.setattr(site, 'getsitepackages', mock_gsp, raising=False)
|
| 126 |
+
assert path in ei.get_site_dirs()
|
| 127 |
+
|
| 128 |
+
def test_all_site_dirs_works_without_getsitepackages(self, monkeypatch):
|
| 129 |
+
monkeypatch.delattr(site, 'getsitepackages', raising=False)
|
| 130 |
+
assert ei.get_site_dirs()
|
| 131 |
+
|
| 132 |
+
@pytest.fixture
|
| 133 |
+
def sdist_unicode(self, tmpdir):
|
| 134 |
+
files = [
|
| 135 |
+
(
|
| 136 |
+
'setup.py',
|
| 137 |
+
DALS(
|
| 138 |
+
"""
|
| 139 |
+
import setuptools
|
| 140 |
+
setuptools.setup(
|
| 141 |
+
name="setuptools-test-unicode",
|
| 142 |
+
version="1.0",
|
| 143 |
+
packages=["mypkg"],
|
| 144 |
+
include_package_data=True,
|
| 145 |
+
)
|
| 146 |
+
"""
|
| 147 |
+
),
|
| 148 |
+
),
|
| 149 |
+
(
|
| 150 |
+
'mypkg/__init__.py',
|
| 151 |
+
"",
|
| 152 |
+
),
|
| 153 |
+
(
|
| 154 |
+
'mypkg/☃.txt',
|
| 155 |
+
"",
|
| 156 |
+
),
|
| 157 |
+
]
|
| 158 |
+
sdist_name = 'setuptools-test-unicode-1.0.zip'
|
| 159 |
+
sdist = tmpdir / sdist_name
|
| 160 |
+
# can't use make_sdist, because the issue only occurs
|
| 161 |
+
# with zip sdists.
|
| 162 |
+
sdist_zip = zipfile.ZipFile(str(sdist), 'w')
|
| 163 |
+
for filename, content in files:
|
| 164 |
+
sdist_zip.writestr(filename, content)
|
| 165 |
+
sdist_zip.close()
|
| 166 |
+
return str(sdist)
|
| 167 |
+
|
| 168 |
+
@fail_on_ascii
|
| 169 |
+
def test_unicode_filename_in_sdist(self, sdist_unicode, tmpdir, monkeypatch):
|
| 170 |
+
"""
|
| 171 |
+
The install command should execute correctly even if
|
| 172 |
+
the package has unicode filenames.
|
| 173 |
+
"""
|
| 174 |
+
dist = Distribution({'script_args': ['easy_install']})
|
| 175 |
+
target = (tmpdir / 'target').ensure_dir()
|
| 176 |
+
cmd = ei.easy_install(
|
| 177 |
+
dist,
|
| 178 |
+
install_dir=str(target),
|
| 179 |
+
args=['x'],
|
| 180 |
+
)
|
| 181 |
+
monkeypatch.setitem(os.environ, 'PYTHONPATH', str(target))
|
| 182 |
+
cmd.ensure_finalized()
|
| 183 |
+
cmd.easy_install(sdist_unicode)
|
| 184 |
+
|
| 185 |
+
@pytest.fixture
|
| 186 |
+
def sdist_unicode_in_script(self, tmpdir):
|
| 187 |
+
files = [
|
| 188 |
+
(
|
| 189 |
+
"setup.py",
|
| 190 |
+
DALS(
|
| 191 |
+
"""
|
| 192 |
+
import setuptools
|
| 193 |
+
setuptools.setup(
|
| 194 |
+
name="setuptools-test-unicode",
|
| 195 |
+
version="1.0",
|
| 196 |
+
packages=["mypkg"],
|
| 197 |
+
include_package_data=True,
|
| 198 |
+
scripts=['mypkg/unicode_in_script'],
|
| 199 |
+
)
|
| 200 |
+
"""
|
| 201 |
+
),
|
| 202 |
+
),
|
| 203 |
+
("mypkg/__init__.py", ""),
|
| 204 |
+
(
|
| 205 |
+
"mypkg/unicode_in_script",
|
| 206 |
+
DALS(
|
| 207 |
+
"""
|
| 208 |
+
#!/bin/sh
|
| 209 |
+
# á
|
| 210 |
+
|
| 211 |
+
non_python_fn() {
|
| 212 |
+
}
|
| 213 |
+
"""
|
| 214 |
+
),
|
| 215 |
+
),
|
| 216 |
+
]
|
| 217 |
+
sdist_name = "setuptools-test-unicode-script-1.0.zip"
|
| 218 |
+
sdist = tmpdir / sdist_name
|
| 219 |
+
# can't use make_sdist, because the issue only occurs
|
| 220 |
+
# with zip sdists.
|
| 221 |
+
sdist_zip = zipfile.ZipFile(str(sdist), "w")
|
| 222 |
+
for filename, content in files:
|
| 223 |
+
sdist_zip.writestr(filename, content.encode('utf-8'))
|
| 224 |
+
sdist_zip.close()
|
| 225 |
+
return str(sdist)
|
| 226 |
+
|
| 227 |
+
@fail_on_ascii
|
| 228 |
+
def test_unicode_content_in_sdist(
|
| 229 |
+
self, sdist_unicode_in_script, tmpdir, monkeypatch
|
| 230 |
+
):
|
| 231 |
+
"""
|
| 232 |
+
The install command should execute correctly even if
|
| 233 |
+
the package has unicode in scripts.
|
| 234 |
+
"""
|
| 235 |
+
dist = Distribution({"script_args": ["easy_install"]})
|
| 236 |
+
target = (tmpdir / "target").ensure_dir()
|
| 237 |
+
cmd = ei.easy_install(dist, install_dir=str(target), args=["x"])
|
| 238 |
+
monkeypatch.setitem(os.environ, "PYTHONPATH", str(target))
|
| 239 |
+
cmd.ensure_finalized()
|
| 240 |
+
cmd.easy_install(sdist_unicode_in_script)
|
| 241 |
+
|
| 242 |
+
@pytest.fixture
|
| 243 |
+
def sdist_script(self, tmpdir):
|
| 244 |
+
files = [
|
| 245 |
+
(
|
| 246 |
+
'setup.py',
|
| 247 |
+
DALS(
|
| 248 |
+
"""
|
| 249 |
+
import setuptools
|
| 250 |
+
setuptools.setup(
|
| 251 |
+
name="setuptools-test-script",
|
| 252 |
+
version="1.0",
|
| 253 |
+
scripts=["mypkg_script"],
|
| 254 |
+
)
|
| 255 |
+
"""
|
| 256 |
+
),
|
| 257 |
+
),
|
| 258 |
+
(
|
| 259 |
+
'mypkg_script',
|
| 260 |
+
DALS(
|
| 261 |
+
"""
|
| 262 |
+
#/usr/bin/python
|
| 263 |
+
print('mypkg_script')
|
| 264 |
+
"""
|
| 265 |
+
),
|
| 266 |
+
),
|
| 267 |
+
]
|
| 268 |
+
sdist_name = 'setuptools-test-script-1.0.zip'
|
| 269 |
+
sdist = str(tmpdir / sdist_name)
|
| 270 |
+
make_sdist(sdist, files)
|
| 271 |
+
return sdist
|
| 272 |
+
|
| 273 |
+
@pytest.mark.skipif(
|
| 274 |
+
not sys.platform.startswith('linux'), reason="Test can only be run on Linux"
|
| 275 |
+
)
|
| 276 |
+
def test_script_install(self, sdist_script, tmpdir, monkeypatch):
|
| 277 |
+
"""
|
| 278 |
+
Check scripts are installed.
|
| 279 |
+
"""
|
| 280 |
+
dist = Distribution({'script_args': ['easy_install']})
|
| 281 |
+
target = (tmpdir / 'target').ensure_dir()
|
| 282 |
+
cmd = ei.easy_install(
|
| 283 |
+
dist,
|
| 284 |
+
install_dir=str(target),
|
| 285 |
+
args=['x'],
|
| 286 |
+
)
|
| 287 |
+
monkeypatch.setitem(os.environ, 'PYTHONPATH', str(target))
|
| 288 |
+
cmd.ensure_finalized()
|
| 289 |
+
cmd.easy_install(sdist_script)
|
| 290 |
+
assert (target / 'mypkg_script').exists()
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
@pytest.mark.filterwarnings('ignore:Unbuilt egg')
|
| 294 |
+
class TestPTHFileWriter:
|
| 295 |
+
def test_add_from_cwd_site_sets_dirty(self):
|
| 296 |
+
"""a pth file manager should set dirty
|
| 297 |
+
if a distribution is in site but also the cwd
|
| 298 |
+
"""
|
| 299 |
+
pth = PthDistributions('does-not_exist', [os.getcwd()])
|
| 300 |
+
assert not pth.dirty
|
| 301 |
+
pth.add(PRDistribution(os.getcwd()))
|
| 302 |
+
assert pth.dirty
|
| 303 |
+
|
| 304 |
+
def test_add_from_site_is_ignored(self):
|
| 305 |
+
location = '/test/location/does-not-have-to-exist'
|
| 306 |
+
# PthDistributions expects all locations to be normalized
|
| 307 |
+
location = pkg_resources.normalize_path(location)
|
| 308 |
+
pth = PthDistributions(
|
| 309 |
+
'does-not_exist',
|
| 310 |
+
[
|
| 311 |
+
location,
|
| 312 |
+
],
|
| 313 |
+
)
|
| 314 |
+
assert not pth.dirty
|
| 315 |
+
pth.add(PRDistribution(location))
|
| 316 |
+
assert not pth.dirty
|
| 317 |
+
|
| 318 |
+
def test_many_pth_distributions_merge_together(self, tmpdir):
|
| 319 |
+
"""
|
| 320 |
+
If the pth file is modified under the hood, then PthDistribution
|
| 321 |
+
will refresh its content before saving, merging contents when
|
| 322 |
+
necessary.
|
| 323 |
+
"""
|
| 324 |
+
# putting the pth file in a dedicated sub-folder,
|
| 325 |
+
pth_subdir = tmpdir.join("pth_subdir")
|
| 326 |
+
pth_subdir.mkdir()
|
| 327 |
+
pth_path = str(pth_subdir.join("file1.pth"))
|
| 328 |
+
pth1 = PthDistributions(pth_path)
|
| 329 |
+
pth2 = PthDistributions(pth_path)
|
| 330 |
+
assert pth1.paths == pth2.paths == [], (
|
| 331 |
+
"unless there would be some default added at some point"
|
| 332 |
+
)
|
| 333 |
+
# and so putting the src_subdir in folder distinct than the pth one,
|
| 334 |
+
# so to keep it absolute by PthDistributions
|
| 335 |
+
new_src_path = tmpdir.join("src_subdir")
|
| 336 |
+
new_src_path.mkdir() # must exist to be accounted
|
| 337 |
+
new_src_path_str = str(new_src_path)
|
| 338 |
+
pth1.paths.append(new_src_path_str)
|
| 339 |
+
pth1.save()
|
| 340 |
+
assert pth1.paths, (
|
| 341 |
+
"the new_src_path added must still be present/valid in pth1 after save"
|
| 342 |
+
)
|
| 343 |
+
# now,
|
| 344 |
+
assert new_src_path_str not in pth2.paths, (
|
| 345 |
+
"right before we save the entry should still not be present"
|
| 346 |
+
)
|
| 347 |
+
pth2.save()
|
| 348 |
+
assert new_src_path_str in pth2.paths, (
|
| 349 |
+
"the new_src_path entry should have been added by pth2 with its save() call"
|
| 350 |
+
)
|
| 351 |
+
assert pth2.paths[-1] == new_src_path, (
|
| 352 |
+
"and it should match exactly on the last entry actually "
|
| 353 |
+
"given we append to it in save()"
|
| 354 |
+
)
|
| 355 |
+
# finally,
|
| 356 |
+
assert PthDistributions(pth_path).paths == pth2.paths, (
|
| 357 |
+
"and we should have the exact same list at the end "
|
| 358 |
+
"with a fresh PthDistributions instance"
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
@pytest.fixture
|
| 363 |
+
def setup_context(tmpdir):
|
| 364 |
+
with (tmpdir / 'setup.py').open('w', encoding="utf-8") as f:
|
| 365 |
+
f.write(SETUP_PY)
|
| 366 |
+
with tmpdir.as_cwd():
|
| 367 |
+
yield tmpdir
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
@pytest.mark.usefixtures("user_override")
|
| 371 |
+
@pytest.mark.usefixtures("setup_context")
|
| 372 |
+
class TestUserInstallTest:
|
| 373 |
+
# prevent check that site-packages is writable. easy_install
|
| 374 |
+
# shouldn't be writing to system site-packages during finalize
|
| 375 |
+
# options, but while it does, bypass the behavior.
|
| 376 |
+
prev_sp_write = mock.patch(
|
| 377 |
+
'setuptools.command.easy_install.easy_install.check_site_dir',
|
| 378 |
+
mock.Mock(),
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
# simulate setuptools installed in user site packages
|
| 382 |
+
@mock.patch('setuptools.command.easy_install.__file__', site.USER_SITE)
|
| 383 |
+
@mock.patch('site.ENABLE_USER_SITE', True)
|
| 384 |
+
@prev_sp_write
|
| 385 |
+
def test_user_install_not_implied_user_site_enabled(self):
|
| 386 |
+
self.assert_not_user_site()
|
| 387 |
+
|
| 388 |
+
@mock.patch('site.ENABLE_USER_SITE', False)
|
| 389 |
+
@prev_sp_write
|
| 390 |
+
def test_user_install_not_implied_user_site_disabled(self):
|
| 391 |
+
self.assert_not_user_site()
|
| 392 |
+
|
| 393 |
+
@staticmethod
|
| 394 |
+
def assert_not_user_site():
|
| 395 |
+
# create a finalized easy_install command
|
| 396 |
+
dist = Distribution()
|
| 397 |
+
dist.script_name = 'setup.py'
|
| 398 |
+
cmd = ei.easy_install(dist)
|
| 399 |
+
cmd.args = ['py']
|
| 400 |
+
cmd.ensure_finalized()
|
| 401 |
+
assert not cmd.user, 'user should not be implied'
|
| 402 |
+
|
| 403 |
+
def test_multiproc_atexit(self):
|
| 404 |
+
pytest.importorskip('multiprocessing')
|
| 405 |
+
|
| 406 |
+
log = logging.getLogger('test_easy_install')
|
| 407 |
+
logging.basicConfig(level=logging.INFO, stream=sys.stderr)
|
| 408 |
+
log.info('this should not break')
|
| 409 |
+
|
| 410 |
+
@pytest.fixture
|
| 411 |
+
def foo_package(self, tmpdir):
|
| 412 |
+
egg_file = tmpdir / 'foo-1.0.egg-info'
|
| 413 |
+
with egg_file.open('w') as f:
|
| 414 |
+
f.write('Name: foo\n')
|
| 415 |
+
return str(tmpdir)
|
| 416 |
+
|
| 417 |
+
@pytest.fixture
|
| 418 |
+
def install_target(self, tmpdir):
|
| 419 |
+
target = str(tmpdir)
|
| 420 |
+
with mock.patch('sys.path', sys.path + [target]):
|
| 421 |
+
python_path = os.path.pathsep.join(sys.path)
|
| 422 |
+
with mock.patch.dict(os.environ, PYTHONPATH=python_path):
|
| 423 |
+
yield target
|
| 424 |
+
|
| 425 |
+
def test_local_index(self, foo_package, install_target):
|
| 426 |
+
"""
|
| 427 |
+
The local index must be used when easy_install locates installed
|
| 428 |
+
packages.
|
| 429 |
+
"""
|
| 430 |
+
dist = Distribution()
|
| 431 |
+
dist.script_name = 'setup.py'
|
| 432 |
+
cmd = ei.easy_install(dist)
|
| 433 |
+
cmd.install_dir = install_target
|
| 434 |
+
cmd.args = ['foo']
|
| 435 |
+
cmd.ensure_finalized()
|
| 436 |
+
cmd.local_index.scan([foo_package])
|
| 437 |
+
res = cmd.easy_install('foo')
|
| 438 |
+
actual = os.path.normcase(os.path.realpath(res.location))
|
| 439 |
+
expected = os.path.normcase(os.path.realpath(foo_package))
|
| 440 |
+
assert actual == expected
|
| 441 |
+
|
| 442 |
+
@contextlib.contextmanager
|
| 443 |
+
def user_install_setup_context(self, *args, **kwargs):
|
| 444 |
+
"""
|
| 445 |
+
Wrap sandbox.setup_context to patch easy_install in that context to
|
| 446 |
+
appear as user-installed.
|
| 447 |
+
"""
|
| 448 |
+
with self.orig_context(*args, **kwargs):
|
| 449 |
+
import setuptools.command.easy_install as ei
|
| 450 |
+
|
| 451 |
+
ei.__file__ = site.USER_SITE
|
| 452 |
+
yield
|
| 453 |
+
|
| 454 |
+
def patched_setup_context(self):
|
| 455 |
+
self.orig_context = sandbox.setup_context
|
| 456 |
+
|
| 457 |
+
return mock.patch(
|
| 458 |
+
'setuptools.sandbox.setup_context',
|
| 459 |
+
self.user_install_setup_context,
|
| 460 |
+
)
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
@pytest.fixture
|
| 464 |
+
def distutils_package():
|
| 465 |
+
distutils_setup_py = SETUP_PY.replace(
|
| 466 |
+
'from setuptools import setup',
|
| 467 |
+
'from distutils.core import setup',
|
| 468 |
+
)
|
| 469 |
+
with contexts.tempdir(cd=os.chdir):
|
| 470 |
+
with open('setup.py', 'w', encoding="utf-8") as f:
|
| 471 |
+
f.write(distutils_setup_py)
|
| 472 |
+
yield
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
@pytest.mark.usefixtures("distutils_package")
|
| 476 |
+
class TestDistutilsPackage:
|
| 477 |
+
def test_bdist_egg_available_on_distutils_pkg(self):
|
| 478 |
+
run_setup('setup.py', ['bdist_egg'])
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
@pytest.fixture
|
| 482 |
+
def mock_index():
|
| 483 |
+
# set up a server which will simulate an alternate package index.
|
| 484 |
+
p_index = MockServer()
|
| 485 |
+
if p_index.server_port == 0:
|
| 486 |
+
# Some platforms (Jython) don't find a port to which to bind,
|
| 487 |
+
# so skip test for them.
|
| 488 |
+
pytest.skip("could not find a valid port")
|
| 489 |
+
p_index.start()
|
| 490 |
+
return p_index
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
class TestInstallRequires:
|
| 494 |
+
def test_setup_install_includes_dependencies(self, tmp_path, mock_index):
|
| 495 |
+
"""
|
| 496 |
+
When ``python setup.py install`` is called directly, it will use easy_install
|
| 497 |
+
to fetch dependencies.
|
| 498 |
+
"""
|
| 499 |
+
# TODO: Remove these tests once `setup.py install` is completely removed
|
| 500 |
+
project_root = tmp_path / "project"
|
| 501 |
+
project_root.mkdir(exist_ok=True)
|
| 502 |
+
install_root = tmp_path / "install"
|
| 503 |
+
install_root.mkdir(exist_ok=True)
|
| 504 |
+
|
| 505 |
+
self.create_project(project_root)
|
| 506 |
+
cmd = [
|
| 507 |
+
sys.executable,
|
| 508 |
+
'-c',
|
| 509 |
+
'__import__("setuptools").setup()',
|
| 510 |
+
'install',
|
| 511 |
+
'--install-base',
|
| 512 |
+
str(install_root),
|
| 513 |
+
'--install-lib',
|
| 514 |
+
str(install_root),
|
| 515 |
+
'--install-headers',
|
| 516 |
+
str(install_root),
|
| 517 |
+
'--install-scripts',
|
| 518 |
+
str(install_root),
|
| 519 |
+
'--install-data',
|
| 520 |
+
str(install_root),
|
| 521 |
+
'--install-purelib',
|
| 522 |
+
str(install_root),
|
| 523 |
+
'--install-platlib',
|
| 524 |
+
str(install_root),
|
| 525 |
+
]
|
| 526 |
+
env = {**os.environ, "__EASYINSTALL_INDEX": mock_index.url}
|
| 527 |
+
cp = subprocess.run(
|
| 528 |
+
cmd,
|
| 529 |
+
cwd=str(project_root),
|
| 530 |
+
env=env,
|
| 531 |
+
stdout=subprocess.PIPE,
|
| 532 |
+
stderr=subprocess.STDOUT,
|
| 533 |
+
text=True,
|
| 534 |
+
encoding="utf-8",
|
| 535 |
+
)
|
| 536 |
+
assert cp.returncode != 0
|
| 537 |
+
try:
|
| 538 |
+
assert '/does-not-exist/' in {r.path for r in mock_index.requests}
|
| 539 |
+
assert next(
|
| 540 |
+
line
|
| 541 |
+
for line in cp.stdout.splitlines()
|
| 542 |
+
if "not find suitable distribution for" in line
|
| 543 |
+
and "does-not-exist" in line
|
| 544 |
+
)
|
| 545 |
+
except Exception:
|
| 546 |
+
if "failed to get random numbers" in cp.stdout:
|
| 547 |
+
pytest.xfail(f"{sys.platform} failure - {cp.stdout}")
|
| 548 |
+
raise
|
| 549 |
+
|
| 550 |
+
def create_project(self, root):
|
| 551 |
+
config = """
|
| 552 |
+
[metadata]
|
| 553 |
+
name = project
|
| 554 |
+
version = 42
|
| 555 |
+
|
| 556 |
+
[options]
|
| 557 |
+
install_requires = does-not-exist
|
| 558 |
+
py_modules = mod
|
| 559 |
+
"""
|
| 560 |
+
(root / 'setup.cfg').write_text(DALS(config), encoding="utf-8")
|
| 561 |
+
(root / 'mod.py').touch()
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
class TestSetupRequires:
|
| 565 |
+
def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch):
|
| 566 |
+
"""
|
| 567 |
+
When easy_install installs a source distribution which specifies
|
| 568 |
+
setup_requires, it should honor the fetch parameters (such as
|
| 569 |
+
index-url, and find-links).
|
| 570 |
+
"""
|
| 571 |
+
monkeypatch.setenv('PIP_RETRIES', '0')
|
| 572 |
+
monkeypatch.setenv('PIP_TIMEOUT', '0')
|
| 573 |
+
monkeypatch.setenv('PIP_NO_INDEX', 'false')
|
| 574 |
+
with contexts.quiet():
|
| 575 |
+
# create an sdist that has a build-time dependency.
|
| 576 |
+
with TestSetupRequires.create_sdist() as dist_file:
|
| 577 |
+
with contexts.tempdir() as temp_install_dir:
|
| 578 |
+
with contexts.environment(PYTHONPATH=temp_install_dir):
|
| 579 |
+
cmd = [
|
| 580 |
+
sys.executable,
|
| 581 |
+
'-c',
|
| 582 |
+
'__import__("setuptools").setup()',
|
| 583 |
+
'easy_install',
|
| 584 |
+
'--index-url',
|
| 585 |
+
mock_index.url,
|
| 586 |
+
'--exclude-scripts',
|
| 587 |
+
'--install-dir',
|
| 588 |
+
temp_install_dir,
|
| 589 |
+
dist_file,
|
| 590 |
+
]
|
| 591 |
+
subprocess.Popen(cmd).wait()
|
| 592 |
+
# there should have been one requests to the server
|
| 593 |
+
assert [r.path for r in mock_index.requests] == ['/does-not-exist/']
|
| 594 |
+
|
| 595 |
+
@staticmethod
|
| 596 |
+
@contextlib.contextmanager
|
| 597 |
+
def create_sdist():
|
| 598 |
+
"""
|
| 599 |
+
Return an sdist with a setup_requires dependency (of something that
|
| 600 |
+
doesn't exist)
|
| 601 |
+
"""
|
| 602 |
+
with contexts.tempdir() as dir:
|
| 603 |
+
dist_path = os.path.join(dir, 'setuptools-test-fetcher-1.0.tar.gz')
|
| 604 |
+
make_sdist(
|
| 605 |
+
dist_path,
|
| 606 |
+
[
|
| 607 |
+
(
|
| 608 |
+
'setup.py',
|
| 609 |
+
DALS(
|
| 610 |
+
"""
|
| 611 |
+
import setuptools
|
| 612 |
+
setuptools.setup(
|
| 613 |
+
name="setuptools-test-fetcher",
|
| 614 |
+
version="1.0",
|
| 615 |
+
setup_requires = ['does-not-exist'],
|
| 616 |
+
)
|
| 617 |
+
"""
|
| 618 |
+
),
|
| 619 |
+
),
|
| 620 |
+
('setup.cfg', ''),
|
| 621 |
+
],
|
| 622 |
+
)
|
| 623 |
+
yield dist_path
|
| 624 |
+
|
| 625 |
+
use_setup_cfg = (
|
| 626 |
+
(),
|
| 627 |
+
('dependency_links',),
|
| 628 |
+
('setup_requires',),
|
| 629 |
+
('dependency_links', 'setup_requires'),
|
| 630 |
+
)
|
| 631 |
+
|
| 632 |
+
@pytest.mark.parametrize('use_setup_cfg', use_setup_cfg)
|
| 633 |
+
def test_setup_requires_overrides_version_conflict(self, use_setup_cfg):
|
| 634 |
+
"""
|
| 635 |
+
Regression test for distribution issue 323:
|
| 636 |
+
https://bitbucket.org/tarek/distribute/issues/323
|
| 637 |
+
|
| 638 |
+
Ensures that a distribution's setup_requires requirements can still be
|
| 639 |
+
installed and used locally even if a conflicting version of that
|
| 640 |
+
requirement is already on the path.
|
| 641 |
+
"""
|
| 642 |
+
|
| 643 |
+
fake_dist = PRDistribution(
|
| 644 |
+
'does-not-matter', project_name='foobar', version='0.0'
|
| 645 |
+
)
|
| 646 |
+
working_set.add(fake_dist)
|
| 647 |
+
|
| 648 |
+
with contexts.save_pkg_resources_state():
|
| 649 |
+
with contexts.tempdir() as temp_dir:
|
| 650 |
+
test_pkg = create_setup_requires_package(
|
| 651 |
+
temp_dir, use_setup_cfg=use_setup_cfg
|
| 652 |
+
)
|
| 653 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 654 |
+
with contexts.quiet() as (stdout, _stderr):
|
| 655 |
+
# Don't even need to install the package, just
|
| 656 |
+
# running the setup.py at all is sufficient
|
| 657 |
+
run_setup(test_setup_py, ['--name'])
|
| 658 |
+
|
| 659 |
+
lines = stdout.readlines()
|
| 660 |
+
assert len(lines) > 0
|
| 661 |
+
assert lines[-1].strip() == 'test_pkg'
|
| 662 |
+
|
| 663 |
+
@pytest.mark.parametrize('use_setup_cfg', use_setup_cfg)
|
| 664 |
+
def test_setup_requires_override_nspkg(self, use_setup_cfg):
|
| 665 |
+
"""
|
| 666 |
+
Like ``test_setup_requires_overrides_version_conflict`` but where the
|
| 667 |
+
``setup_requires`` package is part of a namespace package that has
|
| 668 |
+
*already* been imported.
|
| 669 |
+
"""
|
| 670 |
+
|
| 671 |
+
with contexts.save_pkg_resources_state():
|
| 672 |
+
with contexts.tempdir() as temp_dir:
|
| 673 |
+
foobar_1_archive = os.path.join(temp_dir, 'foo.bar-0.1.tar.gz')
|
| 674 |
+
make_nspkg_sdist(foobar_1_archive, 'foo.bar', '0.1')
|
| 675 |
+
# Now actually go ahead an extract to the temp dir and add the
|
| 676 |
+
# extracted path to sys.path so foo.bar v0.1 is importable
|
| 677 |
+
foobar_1_dir = os.path.join(temp_dir, 'foo.bar-0.1')
|
| 678 |
+
os.mkdir(foobar_1_dir)
|
| 679 |
+
with tarfile.open(foobar_1_archive) as tf:
|
| 680 |
+
tf.extraction_filter = lambda member, path: member
|
| 681 |
+
tf.extractall(foobar_1_dir)
|
| 682 |
+
sys.path.insert(1, foobar_1_dir)
|
| 683 |
+
|
| 684 |
+
dist = PRDistribution(
|
| 685 |
+
foobar_1_dir, project_name='foo.bar', version='0.1'
|
| 686 |
+
)
|
| 687 |
+
working_set.add(dist)
|
| 688 |
+
|
| 689 |
+
template = DALS(
|
| 690 |
+
"""\
|
| 691 |
+
import foo # Even with foo imported first the
|
| 692 |
+
# setup_requires package should override
|
| 693 |
+
import setuptools
|
| 694 |
+
setuptools.setup(**%r)
|
| 695 |
+
|
| 696 |
+
if not (hasattr(foo, '__path__') and
|
| 697 |
+
len(foo.__path__) == 2):
|
| 698 |
+
print('FAIL')
|
| 699 |
+
|
| 700 |
+
if 'foo.bar-0.2' not in foo.__path__[0]:
|
| 701 |
+
print('FAIL')
|
| 702 |
+
"""
|
| 703 |
+
)
|
| 704 |
+
|
| 705 |
+
test_pkg = create_setup_requires_package(
|
| 706 |
+
temp_dir,
|
| 707 |
+
'foo.bar',
|
| 708 |
+
'0.2',
|
| 709 |
+
make_nspkg_sdist,
|
| 710 |
+
template,
|
| 711 |
+
use_setup_cfg=use_setup_cfg,
|
| 712 |
+
)
|
| 713 |
+
|
| 714 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 715 |
+
|
| 716 |
+
with contexts.quiet() as (stdout, _stderr):
|
| 717 |
+
try:
|
| 718 |
+
# Don't even need to install the package, just
|
| 719 |
+
# running the setup.py at all is sufficient
|
| 720 |
+
run_setup(test_setup_py, ['--name'])
|
| 721 |
+
except pkg_resources.VersionConflict:
|
| 722 |
+
self.fail(
|
| 723 |
+
'Installing setup.py requirements caused a VersionConflict'
|
| 724 |
+
)
|
| 725 |
+
|
| 726 |
+
assert 'FAIL' not in stdout.getvalue()
|
| 727 |
+
lines = stdout.readlines()
|
| 728 |
+
assert len(lines) > 0
|
| 729 |
+
assert lines[-1].strip() == 'test_pkg'
|
| 730 |
+
|
| 731 |
+
@pytest.mark.parametrize('use_setup_cfg', use_setup_cfg)
|
| 732 |
+
def test_setup_requires_with_attr_version(self, use_setup_cfg):
|
| 733 |
+
def make_dependency_sdist(dist_path, distname, version):
|
| 734 |
+
files = [
|
| 735 |
+
(
|
| 736 |
+
'setup.py',
|
| 737 |
+
DALS(
|
| 738 |
+
f"""
|
| 739 |
+
import setuptools
|
| 740 |
+
setuptools.setup(
|
| 741 |
+
name={distname!r},
|
| 742 |
+
version={version!r},
|
| 743 |
+
py_modules=[{distname!r}],
|
| 744 |
+
)
|
| 745 |
+
"""
|
| 746 |
+
),
|
| 747 |
+
),
|
| 748 |
+
(
|
| 749 |
+
distname + '.py',
|
| 750 |
+
DALS(
|
| 751 |
+
"""
|
| 752 |
+
version = 42
|
| 753 |
+
"""
|
| 754 |
+
),
|
| 755 |
+
),
|
| 756 |
+
]
|
| 757 |
+
make_sdist(dist_path, files)
|
| 758 |
+
|
| 759 |
+
with contexts.save_pkg_resources_state():
|
| 760 |
+
with contexts.tempdir() as temp_dir:
|
| 761 |
+
test_pkg = create_setup_requires_package(
|
| 762 |
+
temp_dir,
|
| 763 |
+
setup_attrs=dict(version='attr: foobar.version'),
|
| 764 |
+
make_package=make_dependency_sdist,
|
| 765 |
+
use_setup_cfg=use_setup_cfg + ('version',),
|
| 766 |
+
)
|
| 767 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 768 |
+
with contexts.quiet() as (stdout, _stderr):
|
| 769 |
+
run_setup(test_setup_py, ['--version'])
|
| 770 |
+
lines = stdout.readlines()
|
| 771 |
+
assert len(lines) > 0
|
| 772 |
+
assert lines[-1].strip() == '42'
|
| 773 |
+
|
| 774 |
+
def test_setup_requires_honors_pip_env(self, mock_index, monkeypatch):
|
| 775 |
+
monkeypatch.setenv('PIP_RETRIES', '0')
|
| 776 |
+
monkeypatch.setenv('PIP_TIMEOUT', '0')
|
| 777 |
+
monkeypatch.setenv('PIP_NO_INDEX', 'false')
|
| 778 |
+
monkeypatch.setenv('PIP_INDEX_URL', mock_index.url)
|
| 779 |
+
with contexts.save_pkg_resources_state():
|
| 780 |
+
with contexts.tempdir() as temp_dir:
|
| 781 |
+
test_pkg = create_setup_requires_package(
|
| 782 |
+
temp_dir,
|
| 783 |
+
'python-xlib',
|
| 784 |
+
'0.19',
|
| 785 |
+
setup_attrs=dict(dependency_links=[]),
|
| 786 |
+
)
|
| 787 |
+
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
|
| 788 |
+
with open(test_setup_cfg, 'w', encoding="utf-8") as fp:
|
| 789 |
+
fp.write(
|
| 790 |
+
DALS(
|
| 791 |
+
"""
|
| 792 |
+
[easy_install]
|
| 793 |
+
index_url = https://pypi.org/legacy/
|
| 794 |
+
"""
|
| 795 |
+
)
|
| 796 |
+
)
|
| 797 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 798 |
+
with pytest.raises(distutils.errors.DistutilsError):
|
| 799 |
+
run_setup(test_setup_py, ['--version'])
|
| 800 |
+
assert len(mock_index.requests) == 1
|
| 801 |
+
assert mock_index.requests[0].path == '/python-xlib/'
|
| 802 |
+
|
| 803 |
+
def test_setup_requires_with_pep508_url(self, mock_index, monkeypatch):
|
| 804 |
+
monkeypatch.setenv('PIP_RETRIES', '0')
|
| 805 |
+
monkeypatch.setenv('PIP_TIMEOUT', '0')
|
| 806 |
+
monkeypatch.setenv('PIP_INDEX_URL', mock_index.url)
|
| 807 |
+
with contexts.save_pkg_resources_state():
|
| 808 |
+
with contexts.tempdir() as temp_dir:
|
| 809 |
+
dep_sdist = os.path.join(temp_dir, 'dep.tar.gz')
|
| 810 |
+
make_trivial_sdist(dep_sdist, 'dependency', '42')
|
| 811 |
+
dep_url = path_to_url(dep_sdist, authority='localhost')
|
| 812 |
+
test_pkg = create_setup_requires_package(
|
| 813 |
+
temp_dir,
|
| 814 |
+
# Ignored (overridden by setup_attrs)
|
| 815 |
+
'python-xlib',
|
| 816 |
+
'0.19',
|
| 817 |
+
setup_attrs=dict(setup_requires=f'dependency @ {dep_url}'),
|
| 818 |
+
)
|
| 819 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 820 |
+
run_setup(test_setup_py, ['--version'])
|
| 821 |
+
assert len(mock_index.requests) == 0
|
| 822 |
+
|
| 823 |
+
def test_setup_requires_with_allow_hosts(self, mock_index):
|
| 824 |
+
"""The `allow-hosts` option in not supported anymore."""
|
| 825 |
+
files = {
|
| 826 |
+
'test_pkg': {
|
| 827 |
+
'setup.py': DALS(
|
| 828 |
+
"""
|
| 829 |
+
from setuptools import setup
|
| 830 |
+
setup(setup_requires='python-xlib')
|
| 831 |
+
"""
|
| 832 |
+
),
|
| 833 |
+
'setup.cfg': DALS(
|
| 834 |
+
"""
|
| 835 |
+
[easy_install]
|
| 836 |
+
allow_hosts = *
|
| 837 |
+
"""
|
| 838 |
+
),
|
| 839 |
+
}
|
| 840 |
+
}
|
| 841 |
+
with contexts.save_pkg_resources_state():
|
| 842 |
+
with contexts.tempdir() as temp_dir:
|
| 843 |
+
path.build(files, prefix=temp_dir)
|
| 844 |
+
setup_py = str(pathlib.Path(temp_dir, 'test_pkg', 'setup.py'))
|
| 845 |
+
with pytest.raises(distutils.errors.DistutilsError):
|
| 846 |
+
run_setup(setup_py, ['--version'])
|
| 847 |
+
assert len(mock_index.requests) == 0
|
| 848 |
+
|
| 849 |
+
def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir):
|
| 850 |
+
"""Check `python_requires` is honored."""
|
| 851 |
+
monkeypatch.setenv('PIP_RETRIES', '0')
|
| 852 |
+
monkeypatch.setenv('PIP_TIMEOUT', '0')
|
| 853 |
+
monkeypatch.setenv('PIP_NO_INDEX', '1')
|
| 854 |
+
monkeypatch.setenv('PIP_VERBOSE', '1')
|
| 855 |
+
dep_1_0_sdist = 'dep-1.0.tar.gz'
|
| 856 |
+
dep_1_0_url = path_to_url(str(tmpdir / dep_1_0_sdist))
|
| 857 |
+
dep_1_0_python_requires = '>=2.7'
|
| 858 |
+
make_python_requires_sdist(
|
| 859 |
+
str(tmpdir / dep_1_0_sdist), 'dep', '1.0', dep_1_0_python_requires
|
| 860 |
+
)
|
| 861 |
+
dep_2_0_sdist = 'dep-2.0.tar.gz'
|
| 862 |
+
dep_2_0_url = path_to_url(str(tmpdir / dep_2_0_sdist))
|
| 863 |
+
dep_2_0_python_requires = (
|
| 864 |
+
f'!={sys.version_info.major}.{sys.version_info.minor}.*'
|
| 865 |
+
)
|
| 866 |
+
make_python_requires_sdist(
|
| 867 |
+
str(tmpdir / dep_2_0_sdist), 'dep', '2.0', dep_2_0_python_requires
|
| 868 |
+
)
|
| 869 |
+
index = tmpdir / 'index.html'
|
| 870 |
+
index.write_text(
|
| 871 |
+
DALS(
|
| 872 |
+
"""
|
| 873 |
+
<!DOCTYPE html>
|
| 874 |
+
<html><head><title>Links for dep</title></head>
|
| 875 |
+
<body>
|
| 876 |
+
<h1>Links for dep</h1>
|
| 877 |
+
<a href="{dep_1_0_url}"\
|
| 878 |
+
data-requires-python="{dep_1_0_python_requires}">{dep_1_0_sdist}</a><br/>
|
| 879 |
+
<a href="{dep_2_0_url}"\
|
| 880 |
+
data-requires-python="{dep_2_0_python_requires}">{dep_2_0_sdist}</a><br/>
|
| 881 |
+
</body>
|
| 882 |
+
</html>
|
| 883 |
+
"""
|
| 884 |
+
).format(
|
| 885 |
+
dep_1_0_url=dep_1_0_url,
|
| 886 |
+
dep_1_0_sdist=dep_1_0_sdist,
|
| 887 |
+
dep_1_0_python_requires=dep_1_0_python_requires,
|
| 888 |
+
dep_2_0_url=dep_2_0_url,
|
| 889 |
+
dep_2_0_sdist=dep_2_0_sdist,
|
| 890 |
+
dep_2_0_python_requires=dep_2_0_python_requires,
|
| 891 |
+
),
|
| 892 |
+
'utf-8',
|
| 893 |
+
)
|
| 894 |
+
index_url = path_to_url(str(index))
|
| 895 |
+
with contexts.save_pkg_resources_state():
|
| 896 |
+
test_pkg = create_setup_requires_package(
|
| 897 |
+
str(tmpdir),
|
| 898 |
+
'python-xlib',
|
| 899 |
+
'0.19', # Ignored (overridden by setup_attrs).
|
| 900 |
+
setup_attrs=dict(setup_requires='dep', dependency_links=[index_url]),
|
| 901 |
+
)
|
| 902 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 903 |
+
run_setup(test_setup_py, ['--version'])
|
| 904 |
+
eggs = list(
|
| 905 |
+
map(str, pkg_resources.find_distributions(os.path.join(test_pkg, '.eggs')))
|
| 906 |
+
)
|
| 907 |
+
assert eggs == ['dep 1.0']
|
| 908 |
+
|
| 909 |
+
@pytest.mark.parametrize('with_dependency_links_in_setup_py', (False, True))
|
| 910 |
+
def test_setup_requires_with_find_links_in_setup_cfg(
|
| 911 |
+
self, monkeypatch, with_dependency_links_in_setup_py
|
| 912 |
+
):
|
| 913 |
+
monkeypatch.setenv('PIP_RETRIES', '0')
|
| 914 |
+
monkeypatch.setenv('PIP_TIMEOUT', '0')
|
| 915 |
+
with contexts.save_pkg_resources_state():
|
| 916 |
+
with contexts.tempdir() as temp_dir:
|
| 917 |
+
make_trivial_sdist(
|
| 918 |
+
os.path.join(temp_dir, 'python-xlib-42.tar.gz'), 'python-xlib', '42'
|
| 919 |
+
)
|
| 920 |
+
test_pkg = os.path.join(temp_dir, 'test_pkg')
|
| 921 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 922 |
+
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
|
| 923 |
+
os.mkdir(test_pkg)
|
| 924 |
+
with open(test_setup_py, 'w', encoding="utf-8") as fp:
|
| 925 |
+
if with_dependency_links_in_setup_py:
|
| 926 |
+
dependency_links = [os.path.join(temp_dir, 'links')]
|
| 927 |
+
else:
|
| 928 |
+
dependency_links = []
|
| 929 |
+
fp.write(
|
| 930 |
+
DALS(
|
| 931 |
+
"""
|
| 932 |
+
from setuptools import installer, setup
|
| 933 |
+
setup(setup_requires='python-xlib==42',
|
| 934 |
+
dependency_links={dependency_links!r})
|
| 935 |
+
"""
|
| 936 |
+
).format(dependency_links=dependency_links)
|
| 937 |
+
)
|
| 938 |
+
with open(test_setup_cfg, 'w', encoding="utf-8") as fp:
|
| 939 |
+
fp.write(
|
| 940 |
+
DALS(
|
| 941 |
+
"""
|
| 942 |
+
[easy_install]
|
| 943 |
+
index_url = {index_url}
|
| 944 |
+
find_links = {find_links}
|
| 945 |
+
"""
|
| 946 |
+
).format(
|
| 947 |
+
index_url=os.path.join(temp_dir, 'index'),
|
| 948 |
+
find_links=temp_dir,
|
| 949 |
+
)
|
| 950 |
+
)
|
| 951 |
+
run_setup(test_setup_py, ['--version'])
|
| 952 |
+
|
| 953 |
+
def test_setup_requires_with_transitive_extra_dependency(self, monkeypatch):
|
| 954 |
+
"""
|
| 955 |
+
Use case: installing a package with a build dependency on
|
| 956 |
+
an already installed `dep[extra]`, which in turn depends
|
| 957 |
+
on `extra_dep` (whose is not already installed).
|
| 958 |
+
"""
|
| 959 |
+
with contexts.save_pkg_resources_state():
|
| 960 |
+
with contexts.tempdir() as temp_dir:
|
| 961 |
+
# Create source distribution for `extra_dep`.
|
| 962 |
+
make_trivial_sdist(
|
| 963 |
+
os.path.join(temp_dir, 'extra_dep-1.0.tar.gz'), 'extra_dep', '1.0'
|
| 964 |
+
)
|
| 965 |
+
# Create source tree for `dep`.
|
| 966 |
+
dep_pkg = os.path.join(temp_dir, 'dep')
|
| 967 |
+
os.mkdir(dep_pkg)
|
| 968 |
+
path.build(
|
| 969 |
+
{
|
| 970 |
+
'setup.py': DALS(
|
| 971 |
+
"""
|
| 972 |
+
import setuptools
|
| 973 |
+
setuptools.setup(
|
| 974 |
+
name='dep', version='2.0',
|
| 975 |
+
extras_require={'extra': ['extra_dep']},
|
| 976 |
+
)
|
| 977 |
+
"""
|
| 978 |
+
),
|
| 979 |
+
'setup.cfg': '',
|
| 980 |
+
},
|
| 981 |
+
prefix=dep_pkg,
|
| 982 |
+
)
|
| 983 |
+
# "Install" dep.
|
| 984 |
+
run_setup(os.path.join(dep_pkg, 'setup.py'), ['dist_info'])
|
| 985 |
+
working_set.add_entry(dep_pkg)
|
| 986 |
+
# Create source tree for test package.
|
| 987 |
+
test_pkg = os.path.join(temp_dir, 'test_pkg')
|
| 988 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 989 |
+
os.mkdir(test_pkg)
|
| 990 |
+
with open(test_setup_py, 'w', encoding="utf-8") as fp:
|
| 991 |
+
fp.write(
|
| 992 |
+
DALS(
|
| 993 |
+
"""
|
| 994 |
+
from setuptools import installer, setup
|
| 995 |
+
setup(setup_requires='dep[extra]')
|
| 996 |
+
"""
|
| 997 |
+
)
|
| 998 |
+
)
|
| 999 |
+
# Check...
|
| 1000 |
+
monkeypatch.setenv('PIP_FIND_LINKS', str(temp_dir))
|
| 1001 |
+
monkeypatch.setenv('PIP_NO_INDEX', '1')
|
| 1002 |
+
monkeypatch.setenv('PIP_RETRIES', '0')
|
| 1003 |
+
monkeypatch.setenv('PIP_TIMEOUT', '0')
|
| 1004 |
+
run_setup(test_setup_py, ['--version'])
|
| 1005 |
+
|
| 1006 |
+
def test_setup_requires_with_distutils_command_dep(self, monkeypatch):
|
| 1007 |
+
"""
|
| 1008 |
+
Use case: ensure build requirements' extras
|
| 1009 |
+
are properly installed and activated.
|
| 1010 |
+
"""
|
| 1011 |
+
with contexts.save_pkg_resources_state():
|
| 1012 |
+
with contexts.tempdir() as temp_dir:
|
| 1013 |
+
# Create source distribution for `extra_dep`.
|
| 1014 |
+
make_sdist(
|
| 1015 |
+
os.path.join(temp_dir, 'extra_dep-1.0.tar.gz'),
|
| 1016 |
+
[
|
| 1017 |
+
(
|
| 1018 |
+
'setup.py',
|
| 1019 |
+
DALS(
|
| 1020 |
+
"""
|
| 1021 |
+
import setuptools
|
| 1022 |
+
setuptools.setup(
|
| 1023 |
+
name='extra_dep',
|
| 1024 |
+
version='1.0',
|
| 1025 |
+
py_modules=['extra_dep'],
|
| 1026 |
+
)
|
| 1027 |
+
"""
|
| 1028 |
+
),
|
| 1029 |
+
),
|
| 1030 |
+
('setup.cfg', ''),
|
| 1031 |
+
('extra_dep.py', ''),
|
| 1032 |
+
],
|
| 1033 |
+
)
|
| 1034 |
+
# Create source tree for `epdep`.
|
| 1035 |
+
dep_pkg = os.path.join(temp_dir, 'epdep')
|
| 1036 |
+
os.mkdir(dep_pkg)
|
| 1037 |
+
path.build(
|
| 1038 |
+
{
|
| 1039 |
+
'setup.py': DALS(
|
| 1040 |
+
"""
|
| 1041 |
+
import setuptools
|
| 1042 |
+
setuptools.setup(
|
| 1043 |
+
name='dep', version='2.0',
|
| 1044 |
+
py_modules=['epcmd'],
|
| 1045 |
+
extras_require={'extra': ['extra_dep']},
|
| 1046 |
+
entry_points='''
|
| 1047 |
+
[distutils.commands]
|
| 1048 |
+
epcmd = epcmd:epcmd [extra]
|
| 1049 |
+
''',
|
| 1050 |
+
)
|
| 1051 |
+
"""
|
| 1052 |
+
),
|
| 1053 |
+
'setup.cfg': '',
|
| 1054 |
+
'epcmd.py': DALS(
|
| 1055 |
+
"""
|
| 1056 |
+
from distutils.command.build_py import build_py
|
| 1057 |
+
|
| 1058 |
+
import extra_dep
|
| 1059 |
+
|
| 1060 |
+
class epcmd(build_py):
|
| 1061 |
+
pass
|
| 1062 |
+
"""
|
| 1063 |
+
),
|
| 1064 |
+
},
|
| 1065 |
+
prefix=dep_pkg,
|
| 1066 |
+
)
|
| 1067 |
+
# "Install" dep.
|
| 1068 |
+
run_setup(os.path.join(dep_pkg, 'setup.py'), ['dist_info'])
|
| 1069 |
+
working_set.add_entry(dep_pkg)
|
| 1070 |
+
# Create source tree for test package.
|
| 1071 |
+
test_pkg = os.path.join(temp_dir, 'test_pkg')
|
| 1072 |
+
test_setup_py = os.path.join(test_pkg, 'setup.py')
|
| 1073 |
+
os.mkdir(test_pkg)
|
| 1074 |
+
with open(test_setup_py, 'w', encoding="utf-8") as fp:
|
| 1075 |
+
fp.write(
|
| 1076 |
+
DALS(
|
| 1077 |
+
"""
|
| 1078 |
+
from setuptools import installer, setup
|
| 1079 |
+
setup(setup_requires='dep[extra]')
|
| 1080 |
+
"""
|
| 1081 |
+
)
|
| 1082 |
+
)
|
| 1083 |
+
# Check...
|
| 1084 |
+
monkeypatch.setenv('PIP_FIND_LINKS', str(temp_dir))
|
| 1085 |
+
monkeypatch.setenv('PIP_NO_INDEX', '1')
|
| 1086 |
+
monkeypatch.setenv('PIP_RETRIES', '0')
|
| 1087 |
+
monkeypatch.setenv('PIP_TIMEOUT', '0')
|
| 1088 |
+
run_setup(test_setup_py, ['epcmd'])
|
| 1089 |
+
|
| 1090 |
+
|
| 1091 |
+
def make_trivial_sdist(dist_path, distname, version):
|
| 1092 |
+
"""
|
| 1093 |
+
Create a simple sdist tarball at dist_path, containing just a simple
|
| 1094 |
+
setup.py.
|
| 1095 |
+
"""
|
| 1096 |
+
|
| 1097 |
+
make_sdist(
|
| 1098 |
+
dist_path,
|
| 1099 |
+
[
|
| 1100 |
+
(
|
| 1101 |
+
'setup.py',
|
| 1102 |
+
DALS(
|
| 1103 |
+
f"""\
|
| 1104 |
+
import setuptools
|
| 1105 |
+
setuptools.setup(
|
| 1106 |
+
name={distname!r},
|
| 1107 |
+
version={version!r}
|
| 1108 |
+
)
|
| 1109 |
+
"""
|
| 1110 |
+
),
|
| 1111 |
+
),
|
| 1112 |
+
('setup.cfg', ''),
|
| 1113 |
+
],
|
| 1114 |
+
)
|
| 1115 |
+
|
| 1116 |
+
|
| 1117 |
+
def make_nspkg_sdist(dist_path, distname, version):
|
| 1118 |
+
"""
|
| 1119 |
+
Make an sdist tarball with distname and version which also contains one
|
| 1120 |
+
package with the same name as distname. The top-level package is
|
| 1121 |
+
designated a namespace package).
|
| 1122 |
+
"""
|
| 1123 |
+
|
| 1124 |
+
parts = distname.split('.')
|
| 1125 |
+
nspackage = parts[0]
|
| 1126 |
+
|
| 1127 |
+
packages = ['.'.join(parts[:idx]) for idx in range(1, len(parts) + 1)]
|
| 1128 |
+
|
| 1129 |
+
setup_py = DALS(
|
| 1130 |
+
f"""\
|
| 1131 |
+
import setuptools
|
| 1132 |
+
setuptools.setup(
|
| 1133 |
+
name={distname!r},
|
| 1134 |
+
version={version!r},
|
| 1135 |
+
packages={packages!r},
|
| 1136 |
+
namespace_packages=[{nspackage!r}]
|
| 1137 |
+
)
|
| 1138 |
+
"""
|
| 1139 |
+
)
|
| 1140 |
+
|
| 1141 |
+
init = "__import__('pkg_resources').declare_namespace(__name__)"
|
| 1142 |
+
|
| 1143 |
+
files = [('setup.py', setup_py), (os.path.join(nspackage, '__init__.py'), init)]
|
| 1144 |
+
for package in packages[1:]:
|
| 1145 |
+
filename = os.path.join(*(package.split('.') + ['__init__.py']))
|
| 1146 |
+
files.append((filename, ''))
|
| 1147 |
+
|
| 1148 |
+
make_sdist(dist_path, files)
|
| 1149 |
+
|
| 1150 |
+
|
| 1151 |
+
def make_python_requires_sdist(dist_path, distname, version, python_requires):
|
| 1152 |
+
make_sdist(
|
| 1153 |
+
dist_path,
|
| 1154 |
+
[
|
| 1155 |
+
(
|
| 1156 |
+
'setup.py',
|
| 1157 |
+
DALS(
|
| 1158 |
+
"""\
|
| 1159 |
+
import setuptools
|
| 1160 |
+
setuptools.setup(
|
| 1161 |
+
name={name!r},
|
| 1162 |
+
version={version!r},
|
| 1163 |
+
python_requires={python_requires!r},
|
| 1164 |
+
)
|
| 1165 |
+
"""
|
| 1166 |
+
).format(
|
| 1167 |
+
name=distname, version=version, python_requires=python_requires
|
| 1168 |
+
),
|
| 1169 |
+
),
|
| 1170 |
+
('setup.cfg', ''),
|
| 1171 |
+
],
|
| 1172 |
+
)
|
| 1173 |
+
|
| 1174 |
+
|
| 1175 |
+
def make_sdist(dist_path, files):
|
| 1176 |
+
"""
|
| 1177 |
+
Create a simple sdist tarball at dist_path, containing the files
|
| 1178 |
+
listed in ``files`` as ``(filename, content)`` tuples.
|
| 1179 |
+
"""
|
| 1180 |
+
|
| 1181 |
+
# Distributions with only one file don't play well with pip.
|
| 1182 |
+
assert len(files) > 1
|
| 1183 |
+
with tarfile.open(dist_path, 'w:gz') as dist:
|
| 1184 |
+
for filename, content in files:
|
| 1185 |
+
file_bytes = io.BytesIO(content.encode('utf-8'))
|
| 1186 |
+
file_info = tarfile.TarInfo(name=filename)
|
| 1187 |
+
file_info.size = len(file_bytes.getvalue())
|
| 1188 |
+
file_info.mtime = int(time.time())
|
| 1189 |
+
dist.addfile(file_info, fileobj=file_bytes)
|
| 1190 |
+
|
| 1191 |
+
|
| 1192 |
+
def create_setup_requires_package(
|
| 1193 |
+
path,
|
| 1194 |
+
distname='foobar',
|
| 1195 |
+
version='0.1',
|
| 1196 |
+
make_package=make_trivial_sdist,
|
| 1197 |
+
setup_py_template=None,
|
| 1198 |
+
setup_attrs=None,
|
| 1199 |
+
use_setup_cfg=(),
|
| 1200 |
+
):
|
| 1201 |
+
"""Creates a source tree under path for a trivial test package that has a
|
| 1202 |
+
single requirement in setup_requires--a tarball for that requirement is
|
| 1203 |
+
also created and added to the dependency_links argument.
|
| 1204 |
+
|
| 1205 |
+
``distname`` and ``version`` refer to the name/version of the package that
|
| 1206 |
+
the test package requires via ``setup_requires``. The name of the test
|
| 1207 |
+
package itself is just 'test_pkg'.
|
| 1208 |
+
"""
|
| 1209 |
+
|
| 1210 |
+
test_setup_attrs = {
|
| 1211 |
+
'name': 'test_pkg',
|
| 1212 |
+
'version': '0.0',
|
| 1213 |
+
'setup_requires': [f'{distname}=={version}'],
|
| 1214 |
+
'dependency_links': [os.path.abspath(path)],
|
| 1215 |
+
}
|
| 1216 |
+
if setup_attrs:
|
| 1217 |
+
test_setup_attrs.update(setup_attrs)
|
| 1218 |
+
|
| 1219 |
+
test_pkg = os.path.join(path, 'test_pkg')
|
| 1220 |
+
os.mkdir(test_pkg)
|
| 1221 |
+
|
| 1222 |
+
# setup.cfg
|
| 1223 |
+
if use_setup_cfg:
|
| 1224 |
+
options = []
|
| 1225 |
+
metadata = []
|
| 1226 |
+
for name in use_setup_cfg:
|
| 1227 |
+
value = test_setup_attrs.pop(name)
|
| 1228 |
+
if name in 'name version'.split():
|
| 1229 |
+
section = metadata
|
| 1230 |
+
else:
|
| 1231 |
+
section = options
|
| 1232 |
+
if isinstance(value, (tuple, list)):
|
| 1233 |
+
value = ';'.join(value)
|
| 1234 |
+
section.append(f'{name}: {value}')
|
| 1235 |
+
test_setup_cfg_contents = DALS(
|
| 1236 |
+
"""
|
| 1237 |
+
[metadata]
|
| 1238 |
+
{metadata}
|
| 1239 |
+
[options]
|
| 1240 |
+
{options}
|
| 1241 |
+
"""
|
| 1242 |
+
).format(
|
| 1243 |
+
options='\n'.join(options),
|
| 1244 |
+
metadata='\n'.join(metadata),
|
| 1245 |
+
)
|
| 1246 |
+
else:
|
| 1247 |
+
test_setup_cfg_contents = ''
|
| 1248 |
+
with open(os.path.join(test_pkg, 'setup.cfg'), 'w', encoding="utf-8") as f:
|
| 1249 |
+
f.write(test_setup_cfg_contents)
|
| 1250 |
+
|
| 1251 |
+
# setup.py
|
| 1252 |
+
if setup_py_template is None:
|
| 1253 |
+
setup_py_template = DALS(
|
| 1254 |
+
"""\
|
| 1255 |
+
import setuptools
|
| 1256 |
+
setuptools.setup(**%r)
|
| 1257 |
+
"""
|
| 1258 |
+
)
|
| 1259 |
+
with open(os.path.join(test_pkg, 'setup.py'), 'w', encoding="utf-8") as f:
|
| 1260 |
+
f.write(setup_py_template % test_setup_attrs)
|
| 1261 |
+
|
| 1262 |
+
foobar_path = os.path.join(path, f'{distname}-{version}.tar.gz')
|
| 1263 |
+
make_package(foobar_path, distname, version)
|
| 1264 |
+
|
| 1265 |
+
return test_pkg
|
| 1266 |
+
|
| 1267 |
+
|
| 1268 |
+
@pytest.mark.skipif(
|
| 1269 |
+
sys.platform.startswith('java') and ei.is_sh(sys.executable),
|
| 1270 |
+
reason="Test cannot run under java when executable is sh",
|
| 1271 |
+
)
|
| 1272 |
+
class TestScriptHeader:
|
| 1273 |
+
non_ascii_exe = '/Users/José/bin/python'
|
| 1274 |
+
exe_with_spaces = r'C:\Program Files\Python36\python.exe'
|
| 1275 |
+
|
| 1276 |
+
def test_get_script_header(self):
|
| 1277 |
+
expected = f'#!{ei.nt_quote_arg(os.path.normpath(sys.executable))}\n'
|
| 1278 |
+
actual = ei.ScriptWriter.get_header('#!/usr/local/bin/python')
|
| 1279 |
+
assert actual == expected
|
| 1280 |
+
|
| 1281 |
+
def test_get_script_header_args(self):
|
| 1282 |
+
expected = f'#!{ei.nt_quote_arg(os.path.normpath(sys.executable))} -x\n'
|
| 1283 |
+
actual = ei.ScriptWriter.get_header('#!/usr/bin/python -x')
|
| 1284 |
+
assert actual == expected
|
| 1285 |
+
|
| 1286 |
+
def test_get_script_header_non_ascii_exe(self):
|
| 1287 |
+
actual = ei.ScriptWriter.get_header(
|
| 1288 |
+
'#!/usr/bin/python', executable=self.non_ascii_exe
|
| 1289 |
+
)
|
| 1290 |
+
expected = f'#!{self.non_ascii_exe} -x\n'
|
| 1291 |
+
assert actual == expected
|
| 1292 |
+
|
| 1293 |
+
def test_get_script_header_exe_with_spaces(self):
|
| 1294 |
+
actual = ei.ScriptWriter.get_header(
|
| 1295 |
+
'#!/usr/bin/python', executable='"' + self.exe_with_spaces + '"'
|
| 1296 |
+
)
|
| 1297 |
+
expected = f'#!"{self.exe_with_spaces}"\n'
|
| 1298 |
+
assert actual == expected
|
| 1299 |
+
|
| 1300 |
+
|
| 1301 |
+
class TestCommandSpec:
|
| 1302 |
+
def test_custom_launch_command(self):
|
| 1303 |
+
"""
|
| 1304 |
+
Show how a custom CommandSpec could be used to specify a #! executable
|
| 1305 |
+
which takes parameters.
|
| 1306 |
+
"""
|
| 1307 |
+
cmd = ei.CommandSpec(['/usr/bin/env', 'python3'])
|
| 1308 |
+
assert cmd.as_header() == '#!/usr/bin/env python3\n'
|
| 1309 |
+
|
| 1310 |
+
def test_from_param_for_CommandSpec_is_passthrough(self):
|
| 1311 |
+
"""
|
| 1312 |
+
from_param should return an instance of a CommandSpec
|
| 1313 |
+
"""
|
| 1314 |
+
cmd = ei.CommandSpec(['python'])
|
| 1315 |
+
cmd_new = ei.CommandSpec.from_param(cmd)
|
| 1316 |
+
assert cmd is cmd_new
|
| 1317 |
+
|
| 1318 |
+
@mock.patch('sys.executable', TestScriptHeader.exe_with_spaces)
|
| 1319 |
+
@mock.patch.dict(os.environ)
|
| 1320 |
+
def test_from_environment_with_spaces_in_executable(self):
|
| 1321 |
+
os.environ.pop('__PYVENV_LAUNCHER__', None)
|
| 1322 |
+
cmd = ei.CommandSpec.from_environment()
|
| 1323 |
+
assert len(cmd) == 1
|
| 1324 |
+
assert cmd.as_header().startswith('#!"')
|
| 1325 |
+
|
| 1326 |
+
def test_from_simple_string_uses_shlex(self):
|
| 1327 |
+
"""
|
| 1328 |
+
In order to support `executable = /usr/bin/env my-python`, make sure
|
| 1329 |
+
from_param invokes shlex on that input.
|
| 1330 |
+
"""
|
| 1331 |
+
cmd = ei.CommandSpec.from_param('/usr/bin/env my-python')
|
| 1332 |
+
assert len(cmd) == 2
|
| 1333 |
+
assert '"' not in cmd.as_header()
|
| 1334 |
+
|
| 1335 |
+
def test_from_param_raises_expected_error(self) -> None:
|
| 1336 |
+
"""
|
| 1337 |
+
from_param should raise its own TypeError when the argument's type is unsupported
|
| 1338 |
+
"""
|
| 1339 |
+
with pytest.raises(TypeError) as exc_info:
|
| 1340 |
+
ei.CommandSpec.from_param(object()) # type: ignore[arg-type] # We want a type error here
|
| 1341 |
+
assert (
|
| 1342 |
+
str(exc_info.value) == "Argument has an unsupported type <class 'object'>"
|
| 1343 |
+
), exc_info.value
|
| 1344 |
+
|
| 1345 |
+
|
| 1346 |
+
class TestWindowsScriptWriter:
|
| 1347 |
+
def test_header(self):
|
| 1348 |
+
hdr = ei.WindowsScriptWriter.get_header('')
|
| 1349 |
+
assert hdr.startswith('#!')
|
| 1350 |
+
assert hdr.endswith('\n')
|
| 1351 |
+
hdr = hdr.lstrip('#!')
|
| 1352 |
+
hdr = hdr.rstrip('\n')
|
| 1353 |
+
# header should not start with an escaped quote
|
| 1354 |
+
assert not hdr.startswith('\\"')
|
| 1355 |
+
|
| 1356 |
+
|
| 1357 |
+
class VersionStub(NamedTuple):
|
| 1358 |
+
major: int
|
| 1359 |
+
minor: int
|
| 1360 |
+
micro: int
|
| 1361 |
+
releaselevel: str
|
| 1362 |
+
serial: int
|
| 1363 |
+
|
| 1364 |
+
|
| 1365 |
+
def test_use_correct_python_version_string(tmpdir, tmpdir_cwd, monkeypatch):
|
| 1366 |
+
# In issue #3001, easy_install wrongly uses the `python3.1` directory
|
| 1367 |
+
# when the interpreter is `python3.10` and the `--user` option is given.
|
| 1368 |
+
# See pypa/setuptools#3001.
|
| 1369 |
+
dist = Distribution()
|
| 1370 |
+
cmd = dist.get_command_obj('easy_install')
|
| 1371 |
+
cmd.args = ['ok']
|
| 1372 |
+
cmd.optimize = 0
|
| 1373 |
+
cmd.user = True
|
| 1374 |
+
cmd.install_userbase = str(tmpdir)
|
| 1375 |
+
cmd.install_usersite = None
|
| 1376 |
+
install_cmd = dist.get_command_obj('install')
|
| 1377 |
+
install_cmd.install_userbase = str(tmpdir)
|
| 1378 |
+
install_cmd.install_usersite = None
|
| 1379 |
+
|
| 1380 |
+
with monkeypatch.context() as patch, warnings.catch_warnings():
|
| 1381 |
+
warnings.simplefilter("ignore")
|
| 1382 |
+
version = '3.10.1 (main, Dec 21 2021, 09:17:12) [GCC 10.2.1 20210110]'
|
| 1383 |
+
info = VersionStub(3, 10, 1, "final", 0)
|
| 1384 |
+
patch.setattr('site.ENABLE_USER_SITE', True)
|
| 1385 |
+
patch.setattr('sys.version', version)
|
| 1386 |
+
patch.setattr('sys.version_info', info)
|
| 1387 |
+
patch.setattr(cmd, 'create_home_path', mock.Mock())
|
| 1388 |
+
cmd.finalize_options()
|
| 1389 |
+
|
| 1390 |
+
name = "pypy" if hasattr(sys, 'pypy_version_info') else "python"
|
| 1391 |
+
install_dir = cmd.install_dir.lower()
|
| 1392 |
+
|
| 1393 |
+
# In some platforms (e.g. Windows), install_dir is mostly determined
|
| 1394 |
+
# via `sysconfig`, which define constants eagerly at module creation.
|
| 1395 |
+
# This means that monkeypatching `sys.version` to emulate 3.10 for testing
|
| 1396 |
+
# may have no effect.
|
| 1397 |
+
# The safest test here is to rely on the fact that 3.1 is no longer
|
| 1398 |
+
# supported/tested, and make sure that if 'python3.1' ever appears in the string
|
| 1399 |
+
# it is followed by another digit (e.g. 'python3.10').
|
| 1400 |
+
if re.search(name + r'3\.?1', install_dir):
|
| 1401 |
+
assert re.search(name + r'3\.?1\d', install_dir)
|
| 1402 |
+
|
| 1403 |
+
# The following "variables" are used for interpolation in distutils
|
| 1404 |
+
# installation schemes, so it should be fair to treat them as "semi-public",
|
| 1405 |
+
# or at least public enough so we can have a test to make sure they are correct
|
| 1406 |
+
assert cmd.config_vars['py_version'] == '3.10.1'
|
| 1407 |
+
assert cmd.config_vars['py_version_short'] == '3.10'
|
| 1408 |
+
assert cmd.config_vars['py_version_nodot'] == '310'
|
| 1409 |
+
|
| 1410 |
+
|
| 1411 |
+
@pytest.mark.xfail(
|
| 1412 |
+
sys.platform == "darwin",
|
| 1413 |
+
reason="https://github.com/pypa/setuptools/pull/4716#issuecomment-2447624418",
|
| 1414 |
+
)
|
| 1415 |
+
def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmp_path):
|
| 1416 |
+
"""`setup.py develop` should honor `--user` even under build isolation"""
|
| 1417 |
+
|
| 1418 |
+
# == Arrange ==
|
| 1419 |
+
# Pretend that build isolation was enabled
|
| 1420 |
+
# e.g pip sets the environment variable PYTHONNOUSERSITE=1
|
| 1421 |
+
monkeypatch.setattr('site.ENABLE_USER_SITE', False)
|
| 1422 |
+
|
| 1423 |
+
# Patching $HOME for 2 reasons:
|
| 1424 |
+
# 1. setuptools/command/easy_install.py:create_home_path
|
| 1425 |
+
# tries creating directories in $HOME.
|
| 1426 |
+
# Given::
|
| 1427 |
+
# self.config_vars['DESTDIRS'] = (
|
| 1428 |
+
# "/home/user/.pyenv/versions/3.9.10 "
|
| 1429 |
+
# "/home/user/.pyenv/versions/3.9.10/lib "
|
| 1430 |
+
# "/home/user/.pyenv/versions/3.9.10/lib/python3.9 "
|
| 1431 |
+
# "/home/user/.pyenv/versions/3.9.10/lib/python3.9/lib-dynload")
|
| 1432 |
+
# `create_home_path` will::
|
| 1433 |
+
# makedirs(
|
| 1434 |
+
# "/home/user/.pyenv/versions/3.9.10 "
|
| 1435 |
+
# "/home/user/.pyenv/versions/3.9.10/lib "
|
| 1436 |
+
# "/home/user/.pyenv/versions/3.9.10/lib/python3.9 "
|
| 1437 |
+
# "/home/user/.pyenv/versions/3.9.10/lib/python3.9/lib-dynload")
|
| 1438 |
+
#
|
| 1439 |
+
# 2. We are going to force `site` to update site.USER_BASE and site.USER_SITE
|
| 1440 |
+
# To point inside our new home
|
| 1441 |
+
monkeypatch.setenv('HOME', str(tmp_path / '.home'))
|
| 1442 |
+
monkeypatch.setenv('USERPROFILE', str(tmp_path / '.home'))
|
| 1443 |
+
monkeypatch.setenv('APPDATA', str(tmp_path / '.home'))
|
| 1444 |
+
monkeypatch.setattr('site.USER_BASE', None)
|
| 1445 |
+
monkeypatch.setattr('site.USER_SITE', None)
|
| 1446 |
+
user_site = Path(site.getusersitepackages())
|
| 1447 |
+
user_site.mkdir(parents=True, exist_ok=True)
|
| 1448 |
+
|
| 1449 |
+
sys_prefix = tmp_path / '.sys_prefix'
|
| 1450 |
+
sys_prefix.mkdir(parents=True, exist_ok=True)
|
| 1451 |
+
monkeypatch.setattr('sys.prefix', str(sys_prefix))
|
| 1452 |
+
|
| 1453 |
+
setup_script = (
|
| 1454 |
+
"__import__('setuptools').setup(name='aproj', version=42, packages=[])\n"
|
| 1455 |
+
)
|
| 1456 |
+
(tmp_path / "setup.py").write_text(setup_script, encoding="utf-8")
|
| 1457 |
+
|
| 1458 |
+
# == Sanity check ==
|
| 1459 |
+
assert list(sys_prefix.glob("*")) == []
|
| 1460 |
+
assert list(user_site.glob("*")) == []
|
| 1461 |
+
|
| 1462 |
+
# == Act ==
|
| 1463 |
+
run_setup('setup.py', ['develop', '--user'])
|
| 1464 |
+
|
| 1465 |
+
# == Assert ==
|
| 1466 |
+
# Should not install to sys.prefix
|
| 1467 |
+
assert list(sys_prefix.glob("*")) == []
|
| 1468 |
+
# Should install to user site
|
| 1469 |
+
installed = {f.name for f in user_site.glob("*")}
|
| 1470 |
+
# sometimes easy-install.pth is created and sometimes not
|
| 1471 |
+
installed = installed - {"easy-install.pth"}
|
| 1472 |
+
assert installed == {'aproj.egg-link'}
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_egg_info.py
ADDED
|
@@ -0,0 +1,1280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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unittest import mock
|
| 12 |
+
|
| 13 |
+
import pytest
|
| 14 |
+
from jaraco import path
|
| 15 |
+
|
| 16 |
+
from setuptools import errors
|
| 17 |
+
from setuptools.command.egg_info import egg_info, manifest_maker, write_entries
|
| 18 |
+
from setuptools.dist import Distribution
|
| 19 |
+
|
| 20 |
+
from . import contexts, environment
|
| 21 |
+
from .textwrap import DALS
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Environment(str):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@pytest.fixture
|
| 29 |
+
def env():
|
| 30 |
+
with contexts.tempdir(prefix='setuptools-test.') as env_dir:
|
| 31 |
+
env = Environment(env_dir)
|
| 32 |
+
os.chmod(env_dir, stat.S_IRWXU)
|
| 33 |
+
subs = 'home', 'lib', 'scripts', 'data', 'egg-base'
|
| 34 |
+
env.paths = dict((dirname, os.path.join(env_dir, dirname)) for dirname in subs)
|
| 35 |
+
list(map(os.mkdir, env.paths.values()))
|
| 36 |
+
path.build({
|
| 37 |
+
env.paths['home']: {
|
| 38 |
+
'.pydistutils.cfg': DALS(
|
| 39 |
+
"""
|
| 40 |
+
[egg_info]
|
| 41 |
+
egg-base = {egg-base}
|
| 42 |
+
""".format(**env.paths)
|
| 43 |
+
)
|
| 44 |
+
}
|
| 45 |
+
})
|
| 46 |
+
yield env
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class TestEggInfo:
|
| 50 |
+
setup_script = DALS(
|
| 51 |
+
"""
|
| 52 |
+
from setuptools import setup
|
| 53 |
+
|
| 54 |
+
setup(
|
| 55 |
+
name='foo',
|
| 56 |
+
py_modules=['hello'],
|
| 57 |
+
entry_points={'console_scripts': ['hi = hello.run']},
|
| 58 |
+
zip_safe=False,
|
| 59 |
+
)
|
| 60 |
+
"""
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
def _create_project(self):
|
| 64 |
+
path.build({
|
| 65 |
+
'setup.py': self.setup_script,
|
| 66 |
+
'hello.py': DALS(
|
| 67 |
+
"""
|
| 68 |
+
def run():
|
| 69 |
+
print('hello')
|
| 70 |
+
"""
|
| 71 |
+
),
|
| 72 |
+
})
|
| 73 |
+
|
| 74 |
+
@staticmethod
|
| 75 |
+
def _extract_mv_version(pkg_info_lines: list[str]) -> tuple[int, int]:
|
| 76 |
+
version_str = pkg_info_lines[0].split(' ')[1]
|
| 77 |
+
major, minor = map(int, version_str.split('.')[:2])
|
| 78 |
+
return major, minor
|
| 79 |
+
|
| 80 |
+
def test_egg_info_save_version_info_setup_empty(self, tmpdir_cwd, env):
|
| 81 |
+
"""
|
| 82 |
+
When the egg_info section is empty or not present, running
|
| 83 |
+
save_version_info should add the settings to the setup.cfg
|
| 84 |
+
in a deterministic order.
|
| 85 |
+
"""
|
| 86 |
+
setup_cfg = os.path.join(env.paths['home'], 'setup.cfg')
|
| 87 |
+
dist = Distribution()
|
| 88 |
+
ei = egg_info(dist)
|
| 89 |
+
ei.initialize_options()
|
| 90 |
+
ei.save_version_info(setup_cfg)
|
| 91 |
+
|
| 92 |
+
with open(setup_cfg, 'r', encoding="utf-8") as f:
|
| 93 |
+
content = f.read()
|
| 94 |
+
|
| 95 |
+
assert '[egg_info]' in content
|
| 96 |
+
assert 'tag_build =' in content
|
| 97 |
+
assert 'tag_date = 0' in content
|
| 98 |
+
|
| 99 |
+
expected_order = (
|
| 100 |
+
'tag_build',
|
| 101 |
+
'tag_date',
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
self._validate_content_order(content, expected_order)
|
| 105 |
+
|
| 106 |
+
@staticmethod
|
| 107 |
+
def _validate_content_order(content, expected):
|
| 108 |
+
"""
|
| 109 |
+
Assert that the strings in expected appear in content
|
| 110 |
+
in order.
|
| 111 |
+
"""
|
| 112 |
+
pattern = '.*'.join(expected)
|
| 113 |
+
flags = re.MULTILINE | re.DOTALL
|
| 114 |
+
assert re.search(pattern, content, flags)
|
| 115 |
+
|
| 116 |
+
def test_egg_info_save_version_info_setup_defaults(self, tmpdir_cwd, env):
|
| 117 |
+
"""
|
| 118 |
+
When running save_version_info on an existing setup.cfg
|
| 119 |
+
with the 'default' values present from a previous run,
|
| 120 |
+
the file should remain unchanged.
|
| 121 |
+
"""
|
| 122 |
+
setup_cfg = os.path.join(env.paths['home'], 'setup.cfg')
|
| 123 |
+
path.build({
|
| 124 |
+
setup_cfg: DALS(
|
| 125 |
+
"""
|
| 126 |
+
[egg_info]
|
| 127 |
+
tag_build =
|
| 128 |
+
tag_date = 0
|
| 129 |
+
"""
|
| 130 |
+
),
|
| 131 |
+
})
|
| 132 |
+
dist = Distribution()
|
| 133 |
+
ei = egg_info(dist)
|
| 134 |
+
ei.initialize_options()
|
| 135 |
+
ei.save_version_info(setup_cfg)
|
| 136 |
+
|
| 137 |
+
with open(setup_cfg, 'r', encoding="utf-8") as f:
|
| 138 |
+
content = f.read()
|
| 139 |
+
|
| 140 |
+
assert '[egg_info]' in content
|
| 141 |
+
assert 'tag_build =' in content
|
| 142 |
+
assert 'tag_date = 0' in content
|
| 143 |
+
|
| 144 |
+
expected_order = (
|
| 145 |
+
'tag_build',
|
| 146 |
+
'tag_date',
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
self._validate_content_order(content, expected_order)
|
| 150 |
+
|
| 151 |
+
def test_expected_files_produced(self, tmpdir_cwd, env):
|
| 152 |
+
self._create_project()
|
| 153 |
+
|
| 154 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 155 |
+
actual = os.listdir('foo.egg-info')
|
| 156 |
+
|
| 157 |
+
expected = [
|
| 158 |
+
'PKG-INFO',
|
| 159 |
+
'SOURCES.txt',
|
| 160 |
+
'dependency_links.txt',
|
| 161 |
+
'entry_points.txt',
|
| 162 |
+
'not-zip-safe',
|
| 163 |
+
'top_level.txt',
|
| 164 |
+
]
|
| 165 |
+
assert sorted(actual) == expected
|
| 166 |
+
|
| 167 |
+
def test_handling_utime_error(self, tmpdir_cwd, env):
|
| 168 |
+
dist = Distribution()
|
| 169 |
+
ei = egg_info(dist)
|
| 170 |
+
utime_patch = mock.patch('os.utime', side_effect=OSError("TEST"))
|
| 171 |
+
mkpath_patch = mock.patch(
|
| 172 |
+
'setuptools.command.egg_info.egg_info.mkpath', return_val=None
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
with utime_patch, mkpath_patch:
|
| 176 |
+
import distutils.errors
|
| 177 |
+
|
| 178 |
+
msg = r"Cannot update time stamp of directory 'None'"
|
| 179 |
+
with pytest.raises(distutils.errors.DistutilsFileError, match=msg):
|
| 180 |
+
ei.run()
|
| 181 |
+
|
| 182 |
+
def test_license_is_a_string(self, tmpdir_cwd, env):
|
| 183 |
+
setup_config = DALS(
|
| 184 |
+
"""
|
| 185 |
+
[metadata]
|
| 186 |
+
name=foo
|
| 187 |
+
version=0.0.1
|
| 188 |
+
license=file:MIT
|
| 189 |
+
"""
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
setup_script = DALS(
|
| 193 |
+
"""
|
| 194 |
+
from setuptools import setup
|
| 195 |
+
|
| 196 |
+
setup()
|
| 197 |
+
"""
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
path.build({
|
| 201 |
+
'setup.py': setup_script,
|
| 202 |
+
'setup.cfg': setup_config,
|
| 203 |
+
})
|
| 204 |
+
|
| 205 |
+
# This command should fail with a ValueError, but because it's
|
| 206 |
+
# currently configured to use a subprocess, the actual traceback
|
| 207 |
+
# object is lost and we need to parse it from stderr
|
| 208 |
+
with pytest.raises(AssertionError) as exc:
|
| 209 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 210 |
+
|
| 211 |
+
# The only argument to the assertion error should be a traceback
|
| 212 |
+
# containing a ValueError
|
| 213 |
+
assert 'ValueError' in exc.value.args[0]
|
| 214 |
+
|
| 215 |
+
def test_rebuilt(self, tmpdir_cwd, env):
|
| 216 |
+
"""Ensure timestamps are updated when the command is re-run."""
|
| 217 |
+
self._create_project()
|
| 218 |
+
|
| 219 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 220 |
+
timestamp_a = os.path.getmtime('foo.egg-info')
|
| 221 |
+
|
| 222 |
+
# arbitrary sleep just to handle *really* fast systems
|
| 223 |
+
time.sleep(0.001)
|
| 224 |
+
|
| 225 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 226 |
+
timestamp_b = os.path.getmtime('foo.egg-info')
|
| 227 |
+
|
| 228 |
+
assert timestamp_a != timestamp_b
|
| 229 |
+
|
| 230 |
+
def test_manifest_template_is_read(self, tmpdir_cwd, env):
|
| 231 |
+
self._create_project()
|
| 232 |
+
path.build({
|
| 233 |
+
'MANIFEST.in': DALS(
|
| 234 |
+
"""
|
| 235 |
+
recursive-include docs *.rst
|
| 236 |
+
"""
|
| 237 |
+
),
|
| 238 |
+
'docs': {
|
| 239 |
+
'usage.rst': "Run 'hi'",
|
| 240 |
+
},
|
| 241 |
+
})
|
| 242 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 243 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 244 |
+
sources_txt = os.path.join(egg_info_dir, 'SOURCES.txt')
|
| 245 |
+
with open(sources_txt, encoding="utf-8") as f:
|
| 246 |
+
assert 'docs/usage.rst' in f.read().split('\n')
|
| 247 |
+
|
| 248 |
+
def _setup_script_with_requires(self, requires, use_setup_cfg=False):
|
| 249 |
+
setup_script = DALS(
|
| 250 |
+
"""
|
| 251 |
+
from setuptools import setup
|
| 252 |
+
|
| 253 |
+
setup(name='foo', zip_safe=False, %s)
|
| 254 |
+
"""
|
| 255 |
+
) % ('' if use_setup_cfg else requires)
|
| 256 |
+
setup_config = requires if use_setup_cfg else ''
|
| 257 |
+
path.build({
|
| 258 |
+
'setup.py': setup_script,
|
| 259 |
+
'setup.cfg': setup_config,
|
| 260 |
+
})
|
| 261 |
+
|
| 262 |
+
mismatch_marker = f"python_version<'{sys.version_info[0]}'"
|
| 263 |
+
# Alternate equivalent syntax.
|
| 264 |
+
mismatch_marker_alternate = f'python_version < "{sys.version_info[0]}"'
|
| 265 |
+
invalid_marker = "<=>++"
|
| 266 |
+
|
| 267 |
+
class RequiresTestHelper:
|
| 268 |
+
@staticmethod
|
| 269 |
+
def parametrize(*test_list, **format_dict):
|
| 270 |
+
idlist = []
|
| 271 |
+
argvalues = []
|
| 272 |
+
for test in test_list:
|
| 273 |
+
test_params = test.lstrip().split('\n\n', 3)
|
| 274 |
+
name_kwargs = test_params.pop(0).split('\n')
|
| 275 |
+
if len(name_kwargs) > 1:
|
| 276 |
+
val = name_kwargs[1].strip()
|
| 277 |
+
install_cmd_kwargs = ast.literal_eval(val)
|
| 278 |
+
else:
|
| 279 |
+
install_cmd_kwargs = {}
|
| 280 |
+
name = name_kwargs[0].strip()
|
| 281 |
+
setup_py_requires, setup_cfg_requires, expected_requires = [
|
| 282 |
+
DALS(a).format(**format_dict) for a in test_params
|
| 283 |
+
]
|
| 284 |
+
for id_, requires, use_cfg in (
|
| 285 |
+
(name, setup_py_requires, False),
|
| 286 |
+
(name + '_in_setup_cfg', setup_cfg_requires, True),
|
| 287 |
+
):
|
| 288 |
+
idlist.append(id_)
|
| 289 |
+
marks = ()
|
| 290 |
+
if requires.startswith('@xfail\n'):
|
| 291 |
+
requires = requires[7:]
|
| 292 |
+
marks = pytest.mark.xfail
|
| 293 |
+
argvalues.append(
|
| 294 |
+
pytest.param(
|
| 295 |
+
requires,
|
| 296 |
+
use_cfg,
|
| 297 |
+
expected_requires,
|
| 298 |
+
install_cmd_kwargs,
|
| 299 |
+
marks=marks,
|
| 300 |
+
)
|
| 301 |
+
)
|
| 302 |
+
return pytest.mark.parametrize(
|
| 303 |
+
'requires,use_setup_cfg,expected_requires,install_cmd_kwargs',
|
| 304 |
+
argvalues,
|
| 305 |
+
ids=idlist,
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
@RequiresTestHelper.parametrize(
|
| 309 |
+
# Format of a test:
|
| 310 |
+
#
|
| 311 |
+
# id
|
| 312 |
+
# install_cmd_kwargs [optional]
|
| 313 |
+
#
|
| 314 |
+
# requires block (when used in setup.py)
|
| 315 |
+
#
|
| 316 |
+
# requires block (when used in setup.cfg)
|
| 317 |
+
#
|
| 318 |
+
# expected contents of requires.txt
|
| 319 |
+
"""
|
| 320 |
+
install_requires_deterministic
|
| 321 |
+
|
| 322 |
+
install_requires=["wheel>=0.5", "pytest"]
|
| 323 |
+
|
| 324 |
+
[options]
|
| 325 |
+
install_requires =
|
| 326 |
+
wheel>=0.5
|
| 327 |
+
pytest
|
| 328 |
+
|
| 329 |
+
wheel>=0.5
|
| 330 |
+
pytest
|
| 331 |
+
""",
|
| 332 |
+
"""
|
| 333 |
+
install_requires_ordered
|
| 334 |
+
|
| 335 |
+
install_requires=["pytest>=3.0.2,!=10.9999"]
|
| 336 |
+
|
| 337 |
+
[options]
|
| 338 |
+
install_requires =
|
| 339 |
+
pytest>=3.0.2,!=10.9999
|
| 340 |
+
|
| 341 |
+
pytest!=10.9999,>=3.0.2
|
| 342 |
+
""",
|
| 343 |
+
"""
|
| 344 |
+
install_requires_with_marker
|
| 345 |
+
|
| 346 |
+
install_requires=["barbazquux;{mismatch_marker}"],
|
| 347 |
+
|
| 348 |
+
[options]
|
| 349 |
+
install_requires =
|
| 350 |
+
barbazquux; {mismatch_marker}
|
| 351 |
+
|
| 352 |
+
[:{mismatch_marker_alternate}]
|
| 353 |
+
barbazquux
|
| 354 |
+
""",
|
| 355 |
+
"""
|
| 356 |
+
install_requires_with_extra
|
| 357 |
+
{'cmd': ['egg_info']}
|
| 358 |
+
|
| 359 |
+
install_requires=["barbazquux [test]"],
|
| 360 |
+
|
| 361 |
+
[options]
|
| 362 |
+
install_requires =
|
| 363 |
+
barbazquux [test]
|
| 364 |
+
|
| 365 |
+
barbazquux[test]
|
| 366 |
+
""",
|
| 367 |
+
"""
|
| 368 |
+
install_requires_with_extra_and_marker
|
| 369 |
+
|
| 370 |
+
install_requires=["barbazquux [test]; {mismatch_marker}"],
|
| 371 |
+
|
| 372 |
+
[options]
|
| 373 |
+
install_requires =
|
| 374 |
+
barbazquux [test]; {mismatch_marker}
|
| 375 |
+
|
| 376 |
+
[:{mismatch_marker_alternate}]
|
| 377 |
+
barbazquux[test]
|
| 378 |
+
""",
|
| 379 |
+
"""
|
| 380 |
+
setup_requires_with_markers
|
| 381 |
+
|
| 382 |
+
setup_requires=["barbazquux;{mismatch_marker}"],
|
| 383 |
+
|
| 384 |
+
[options]
|
| 385 |
+
setup_requires =
|
| 386 |
+
barbazquux; {mismatch_marker}
|
| 387 |
+
|
| 388 |
+
""",
|
| 389 |
+
"""
|
| 390 |
+
extras_require_with_extra
|
| 391 |
+
{'cmd': ['egg_info']}
|
| 392 |
+
|
| 393 |
+
extras_require={{"extra": ["barbazquux [test]"]}},
|
| 394 |
+
|
| 395 |
+
[options.extras_require]
|
| 396 |
+
extra = barbazquux [test]
|
| 397 |
+
|
| 398 |
+
[extra]
|
| 399 |
+
barbazquux[test]
|
| 400 |
+
""",
|
| 401 |
+
"""
|
| 402 |
+
extras_require_with_extra_and_marker_in_req
|
| 403 |
+
|
| 404 |
+
extras_require={{"extra": ["barbazquux [test]; {mismatch_marker}"]}},
|
| 405 |
+
|
| 406 |
+
[options.extras_require]
|
| 407 |
+
extra =
|
| 408 |
+
barbazquux [test]; {mismatch_marker}
|
| 409 |
+
|
| 410 |
+
[extra]
|
| 411 |
+
|
| 412 |
+
[extra:{mismatch_marker_alternate}]
|
| 413 |
+
barbazquux[test]
|
| 414 |
+
""",
|
| 415 |
+
# FIXME: ConfigParser does not allow : in key names!
|
| 416 |
+
"""
|
| 417 |
+
extras_require_with_marker
|
| 418 |
+
|
| 419 |
+
extras_require={{":{mismatch_marker}": ["barbazquux"]}},
|
| 420 |
+
|
| 421 |
+
@xfail
|
| 422 |
+
[options.extras_require]
|
| 423 |
+
:{mismatch_marker} = barbazquux
|
| 424 |
+
|
| 425 |
+
[:{mismatch_marker}]
|
| 426 |
+
barbazquux
|
| 427 |
+
""",
|
| 428 |
+
"""
|
| 429 |
+
extras_require_with_marker_in_req
|
| 430 |
+
|
| 431 |
+
extras_require={{"extra": ["barbazquux; {mismatch_marker}"]}},
|
| 432 |
+
|
| 433 |
+
[options.extras_require]
|
| 434 |
+
extra =
|
| 435 |
+
barbazquux; {mismatch_marker}
|
| 436 |
+
|
| 437 |
+
[extra]
|
| 438 |
+
|
| 439 |
+
[extra:{mismatch_marker_alternate}]
|
| 440 |
+
barbazquux
|
| 441 |
+
""",
|
| 442 |
+
"""
|
| 443 |
+
extras_require_with_empty_section
|
| 444 |
+
|
| 445 |
+
extras_require={{"empty": []}},
|
| 446 |
+
|
| 447 |
+
[options.extras_require]
|
| 448 |
+
empty =
|
| 449 |
+
|
| 450 |
+
[empty]
|
| 451 |
+
""",
|
| 452 |
+
# Format arguments.
|
| 453 |
+
invalid_marker=invalid_marker,
|
| 454 |
+
mismatch_marker=mismatch_marker,
|
| 455 |
+
mismatch_marker_alternate=mismatch_marker_alternate,
|
| 456 |
+
)
|
| 457 |
+
def test_requires(
|
| 458 |
+
self,
|
| 459 |
+
tmpdir_cwd,
|
| 460 |
+
env,
|
| 461 |
+
requires,
|
| 462 |
+
use_setup_cfg,
|
| 463 |
+
expected_requires,
|
| 464 |
+
install_cmd_kwargs,
|
| 465 |
+
):
|
| 466 |
+
self._setup_script_with_requires(requires, use_setup_cfg)
|
| 467 |
+
self._run_egg_info_command(tmpdir_cwd, env, **install_cmd_kwargs)
|
| 468 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 469 |
+
requires_txt = os.path.join(egg_info_dir, 'requires.txt')
|
| 470 |
+
if os.path.exists(requires_txt):
|
| 471 |
+
with open(requires_txt, encoding="utf-8") as fp:
|
| 472 |
+
install_requires = fp.read()
|
| 473 |
+
else:
|
| 474 |
+
install_requires = ''
|
| 475 |
+
assert install_requires.lstrip() == expected_requires
|
| 476 |
+
assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == []
|
| 477 |
+
|
| 478 |
+
def test_install_requires_unordered_disallowed(self, tmpdir_cwd, env):
|
| 479 |
+
"""
|
| 480 |
+
Packages that pass unordered install_requires sequences
|
| 481 |
+
should be rejected as they produce non-deterministic
|
| 482 |
+
builds. See #458.
|
| 483 |
+
"""
|
| 484 |
+
req = 'install_requires={"fake-factory==0.5.2", "pytz"}'
|
| 485 |
+
self._setup_script_with_requires(req)
|
| 486 |
+
with pytest.raises(AssertionError):
|
| 487 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 488 |
+
|
| 489 |
+
def test_extras_require_with_invalid_marker(self, tmpdir_cwd, env):
|
| 490 |
+
tmpl = 'extras_require={{":{marker}": ["barbazquux"]}},'
|
| 491 |
+
req = tmpl.format(marker=self.invalid_marker)
|
| 492 |
+
self._setup_script_with_requires(req)
|
| 493 |
+
with pytest.raises(AssertionError):
|
| 494 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 495 |
+
assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == []
|
| 496 |
+
|
| 497 |
+
def test_extras_require_with_invalid_marker_in_req(self, tmpdir_cwd, env):
|
| 498 |
+
tmpl = 'extras_require={{"extra": ["barbazquux; {marker}"]}},'
|
| 499 |
+
req = tmpl.format(marker=self.invalid_marker)
|
| 500 |
+
self._setup_script_with_requires(req)
|
| 501 |
+
with pytest.raises(AssertionError):
|
| 502 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 503 |
+
assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == []
|
| 504 |
+
|
| 505 |
+
def test_provides_extra(self, tmpdir_cwd, env):
|
| 506 |
+
self._setup_script_with_requires('extras_require={"foobar": ["barbazquux"]},')
|
| 507 |
+
environ = os.environ.copy().update(
|
| 508 |
+
HOME=env.paths['home'],
|
| 509 |
+
)
|
| 510 |
+
environment.run_setup_py(
|
| 511 |
+
cmd=['egg_info'],
|
| 512 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 513 |
+
data_stream=1,
|
| 514 |
+
env=environ,
|
| 515 |
+
)
|
| 516 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 517 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 518 |
+
pkg_info_lines = fp.read().split('\n')
|
| 519 |
+
assert 'Provides-Extra: foobar' in pkg_info_lines
|
| 520 |
+
assert 'Metadata-Version: 2.2' in pkg_info_lines
|
| 521 |
+
|
| 522 |
+
def test_doesnt_provides_extra(self, tmpdir_cwd, env):
|
| 523 |
+
self._setup_script_with_requires(
|
| 524 |
+
"""install_requires=["spam ; python_version<'3.6'"]"""
|
| 525 |
+
)
|
| 526 |
+
environ = os.environ.copy().update(
|
| 527 |
+
HOME=env.paths['home'],
|
| 528 |
+
)
|
| 529 |
+
environment.run_setup_py(
|
| 530 |
+
cmd=['egg_info'],
|
| 531 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 532 |
+
data_stream=1,
|
| 533 |
+
env=environ,
|
| 534 |
+
)
|
| 535 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 536 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 537 |
+
pkg_info_text = fp.read()
|
| 538 |
+
assert 'Provides-Extra:' not in pkg_info_text
|
| 539 |
+
|
| 540 |
+
@pytest.mark.parametrize(
|
| 541 |
+
('files', 'license_in_sources'),
|
| 542 |
+
[
|
| 543 |
+
(
|
| 544 |
+
{
|
| 545 |
+
'setup.cfg': DALS(
|
| 546 |
+
"""
|
| 547 |
+
[metadata]
|
| 548 |
+
license_file = LICENSE
|
| 549 |
+
"""
|
| 550 |
+
),
|
| 551 |
+
'LICENSE': "Test license",
|
| 552 |
+
},
|
| 553 |
+
True,
|
| 554 |
+
), # with license
|
| 555 |
+
(
|
| 556 |
+
{
|
| 557 |
+
'setup.cfg': DALS(
|
| 558 |
+
"""
|
| 559 |
+
[metadata]
|
| 560 |
+
license_file = INVALID_LICENSE
|
| 561 |
+
"""
|
| 562 |
+
),
|
| 563 |
+
'LICENSE': "Test license",
|
| 564 |
+
},
|
| 565 |
+
False,
|
| 566 |
+
), # with an invalid license
|
| 567 |
+
(
|
| 568 |
+
{
|
| 569 |
+
'setup.cfg': DALS(
|
| 570 |
+
"""
|
| 571 |
+
"""
|
| 572 |
+
),
|
| 573 |
+
'LICENSE': "Test license",
|
| 574 |
+
},
|
| 575 |
+
True,
|
| 576 |
+
), # no license_file attribute, LICENSE auto-included
|
| 577 |
+
(
|
| 578 |
+
{
|
| 579 |
+
'setup.cfg': DALS(
|
| 580 |
+
"""
|
| 581 |
+
[metadata]
|
| 582 |
+
license_file = LICENSE
|
| 583 |
+
"""
|
| 584 |
+
),
|
| 585 |
+
'MANIFEST.in': "exclude LICENSE",
|
| 586 |
+
'LICENSE': "Test license",
|
| 587 |
+
},
|
| 588 |
+
True,
|
| 589 |
+
), # manifest is overwritten by license_file
|
| 590 |
+
pytest.param(
|
| 591 |
+
{
|
| 592 |
+
'setup.cfg': DALS(
|
| 593 |
+
"""
|
| 594 |
+
[metadata]
|
| 595 |
+
license_file = LICEN[CS]E*
|
| 596 |
+
"""
|
| 597 |
+
),
|
| 598 |
+
'LICENSE': "Test license",
|
| 599 |
+
},
|
| 600 |
+
True,
|
| 601 |
+
id="glob_pattern",
|
| 602 |
+
),
|
| 603 |
+
],
|
| 604 |
+
)
|
| 605 |
+
def test_setup_cfg_license_file(self, tmpdir_cwd, env, files, license_in_sources):
|
| 606 |
+
self._create_project()
|
| 607 |
+
path.build(files)
|
| 608 |
+
|
| 609 |
+
environment.run_setup_py(
|
| 610 |
+
cmd=['egg_info'],
|
| 611 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 612 |
+
)
|
| 613 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 614 |
+
|
| 615 |
+
sources_text = Path(egg_info_dir, "SOURCES.txt").read_text(encoding="utf-8")
|
| 616 |
+
|
| 617 |
+
if license_in_sources:
|
| 618 |
+
assert 'LICENSE' in sources_text
|
| 619 |
+
else:
|
| 620 |
+
assert 'LICENSE' not in sources_text
|
| 621 |
+
# for invalid license test
|
| 622 |
+
assert 'INVALID_LICENSE' not in sources_text
|
| 623 |
+
|
| 624 |
+
@pytest.mark.parametrize(
|
| 625 |
+
('files', 'incl_licenses', 'excl_licenses'),
|
| 626 |
+
[
|
| 627 |
+
(
|
| 628 |
+
{
|
| 629 |
+
'setup.cfg': DALS(
|
| 630 |
+
"""
|
| 631 |
+
[metadata]
|
| 632 |
+
license_files =
|
| 633 |
+
LICENSE-ABC
|
| 634 |
+
LICENSE-XYZ
|
| 635 |
+
"""
|
| 636 |
+
),
|
| 637 |
+
'LICENSE-ABC': "ABC license",
|
| 638 |
+
'LICENSE-XYZ': "XYZ license",
|
| 639 |
+
},
|
| 640 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 641 |
+
[],
|
| 642 |
+
), # with licenses
|
| 643 |
+
(
|
| 644 |
+
{
|
| 645 |
+
'setup.cfg': DALS(
|
| 646 |
+
"""
|
| 647 |
+
[metadata]
|
| 648 |
+
license_files = LICENSE-ABC, LICENSE-XYZ
|
| 649 |
+
"""
|
| 650 |
+
),
|
| 651 |
+
'LICENSE-ABC': "ABC license",
|
| 652 |
+
'LICENSE-XYZ': "XYZ license",
|
| 653 |
+
},
|
| 654 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 655 |
+
[],
|
| 656 |
+
), # with commas
|
| 657 |
+
(
|
| 658 |
+
{
|
| 659 |
+
'setup.cfg': DALS(
|
| 660 |
+
"""
|
| 661 |
+
[metadata]
|
| 662 |
+
license_files =
|
| 663 |
+
LICENSE-ABC
|
| 664 |
+
"""
|
| 665 |
+
),
|
| 666 |
+
'LICENSE-ABC': "ABC license",
|
| 667 |
+
'LICENSE-XYZ': "XYZ license",
|
| 668 |
+
},
|
| 669 |
+
['LICENSE-ABC'],
|
| 670 |
+
['LICENSE-XYZ'],
|
| 671 |
+
), # with one license
|
| 672 |
+
(
|
| 673 |
+
{
|
| 674 |
+
'setup.cfg': DALS(
|
| 675 |
+
"""
|
| 676 |
+
[metadata]
|
| 677 |
+
license_files =
|
| 678 |
+
"""
|
| 679 |
+
),
|
| 680 |
+
'LICENSE-ABC': "ABC license",
|
| 681 |
+
'LICENSE-XYZ': "XYZ license",
|
| 682 |
+
},
|
| 683 |
+
[],
|
| 684 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 685 |
+
), # empty
|
| 686 |
+
(
|
| 687 |
+
{
|
| 688 |
+
'setup.cfg': DALS(
|
| 689 |
+
"""
|
| 690 |
+
[metadata]
|
| 691 |
+
license_files = LICENSE-XYZ
|
| 692 |
+
"""
|
| 693 |
+
),
|
| 694 |
+
'LICENSE-ABC': "ABC license",
|
| 695 |
+
'LICENSE-XYZ': "XYZ license",
|
| 696 |
+
},
|
| 697 |
+
['LICENSE-XYZ'],
|
| 698 |
+
['LICENSE-ABC'],
|
| 699 |
+
), # on same line
|
| 700 |
+
(
|
| 701 |
+
{
|
| 702 |
+
'setup.cfg': DALS(
|
| 703 |
+
"""
|
| 704 |
+
[metadata]
|
| 705 |
+
license_files =
|
| 706 |
+
LICENSE-ABC
|
| 707 |
+
INVALID_LICENSE
|
| 708 |
+
"""
|
| 709 |
+
),
|
| 710 |
+
'LICENSE-ABC': "Test license",
|
| 711 |
+
},
|
| 712 |
+
['LICENSE-ABC'],
|
| 713 |
+
['INVALID_LICENSE'],
|
| 714 |
+
), # with an invalid license
|
| 715 |
+
(
|
| 716 |
+
{
|
| 717 |
+
'setup.cfg': DALS(
|
| 718 |
+
"""
|
| 719 |
+
"""
|
| 720 |
+
),
|
| 721 |
+
'LICENSE': "Test license",
|
| 722 |
+
},
|
| 723 |
+
['LICENSE'],
|
| 724 |
+
[],
|
| 725 |
+
), # no license_files attribute, LICENSE auto-included
|
| 726 |
+
(
|
| 727 |
+
{
|
| 728 |
+
'setup.cfg': DALS(
|
| 729 |
+
"""
|
| 730 |
+
[metadata]
|
| 731 |
+
license_files = LICENSE
|
| 732 |
+
"""
|
| 733 |
+
),
|
| 734 |
+
'MANIFEST.in': "exclude LICENSE",
|
| 735 |
+
'LICENSE': "Test license",
|
| 736 |
+
},
|
| 737 |
+
['LICENSE'],
|
| 738 |
+
[],
|
| 739 |
+
), # manifest is overwritten by license_files
|
| 740 |
+
(
|
| 741 |
+
{
|
| 742 |
+
'setup.cfg': DALS(
|
| 743 |
+
"""
|
| 744 |
+
[metadata]
|
| 745 |
+
license_files =
|
| 746 |
+
LICENSE-ABC
|
| 747 |
+
LICENSE-XYZ
|
| 748 |
+
"""
|
| 749 |
+
),
|
| 750 |
+
'MANIFEST.in': "exclude LICENSE-XYZ",
|
| 751 |
+
'LICENSE-ABC': "ABC license",
|
| 752 |
+
'LICENSE-XYZ': "XYZ license",
|
| 753 |
+
# manifest is overwritten by license_files
|
| 754 |
+
},
|
| 755 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 756 |
+
[],
|
| 757 |
+
),
|
| 758 |
+
pytest.param(
|
| 759 |
+
{
|
| 760 |
+
'setup.cfg': "",
|
| 761 |
+
'LICENSE-ABC': "ABC license",
|
| 762 |
+
'COPYING-ABC': "ABC copying",
|
| 763 |
+
'NOTICE-ABC': "ABC notice",
|
| 764 |
+
'AUTHORS-ABC': "ABC authors",
|
| 765 |
+
'LICENCE-XYZ': "XYZ license",
|
| 766 |
+
'LICENSE': "License",
|
| 767 |
+
'INVALID-LICENSE': "Invalid license",
|
| 768 |
+
},
|
| 769 |
+
[
|
| 770 |
+
'LICENSE-ABC',
|
| 771 |
+
'COPYING-ABC',
|
| 772 |
+
'NOTICE-ABC',
|
| 773 |
+
'AUTHORS-ABC',
|
| 774 |
+
'LICENCE-XYZ',
|
| 775 |
+
'LICENSE',
|
| 776 |
+
],
|
| 777 |
+
['INVALID-LICENSE'],
|
| 778 |
+
# ('LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*')
|
| 779 |
+
id="default_glob_patterns",
|
| 780 |
+
),
|
| 781 |
+
pytest.param(
|
| 782 |
+
{
|
| 783 |
+
'setup.cfg': DALS(
|
| 784 |
+
"""
|
| 785 |
+
[metadata]
|
| 786 |
+
license_files =
|
| 787 |
+
LICENSE*
|
| 788 |
+
"""
|
| 789 |
+
),
|
| 790 |
+
'LICENSE-ABC': "ABC license",
|
| 791 |
+
'NOTICE-XYZ': "XYZ notice",
|
| 792 |
+
},
|
| 793 |
+
['LICENSE-ABC'],
|
| 794 |
+
['NOTICE-XYZ'],
|
| 795 |
+
id="no_default_glob_patterns",
|
| 796 |
+
),
|
| 797 |
+
pytest.param(
|
| 798 |
+
{
|
| 799 |
+
'setup.cfg': DALS(
|
| 800 |
+
"""
|
| 801 |
+
[metadata]
|
| 802 |
+
license_files =
|
| 803 |
+
LICENSE-ABC
|
| 804 |
+
LICENSE*
|
| 805 |
+
"""
|
| 806 |
+
),
|
| 807 |
+
'LICENSE-ABC': "ABC license",
|
| 808 |
+
},
|
| 809 |
+
['LICENSE-ABC'],
|
| 810 |
+
[],
|
| 811 |
+
id="files_only_added_once",
|
| 812 |
+
),
|
| 813 |
+
],
|
| 814 |
+
)
|
| 815 |
+
def test_setup_cfg_license_files(
|
| 816 |
+
self, tmpdir_cwd, env, files, incl_licenses, excl_licenses
|
| 817 |
+
):
|
| 818 |
+
self._create_project()
|
| 819 |
+
path.build(files)
|
| 820 |
+
|
| 821 |
+
environment.run_setup_py(
|
| 822 |
+
cmd=['egg_info'],
|
| 823 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 824 |
+
)
|
| 825 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 826 |
+
|
| 827 |
+
sources_text = Path(egg_info_dir, "SOURCES.txt").read_text(encoding="utf-8")
|
| 828 |
+
sources_lines = [line.strip() for line in sources_text.splitlines()]
|
| 829 |
+
|
| 830 |
+
for lf in incl_licenses:
|
| 831 |
+
assert sources_lines.count(lf) == 1
|
| 832 |
+
|
| 833 |
+
for lf in excl_licenses:
|
| 834 |
+
assert sources_lines.count(lf) == 0
|
| 835 |
+
|
| 836 |
+
@pytest.mark.parametrize(
|
| 837 |
+
('files', 'incl_licenses', 'excl_licenses'),
|
| 838 |
+
[
|
| 839 |
+
(
|
| 840 |
+
{
|
| 841 |
+
'setup.cfg': DALS(
|
| 842 |
+
"""
|
| 843 |
+
[metadata]
|
| 844 |
+
license_file =
|
| 845 |
+
license_files =
|
| 846 |
+
"""
|
| 847 |
+
),
|
| 848 |
+
'LICENSE-ABC': "ABC license",
|
| 849 |
+
'LICENSE-XYZ': "XYZ license",
|
| 850 |
+
},
|
| 851 |
+
[],
|
| 852 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 853 |
+
), # both empty
|
| 854 |
+
(
|
| 855 |
+
{
|
| 856 |
+
'setup.cfg': DALS(
|
| 857 |
+
"""
|
| 858 |
+
[metadata]
|
| 859 |
+
license_file =
|
| 860 |
+
LICENSE-ABC
|
| 861 |
+
LICENSE-XYZ
|
| 862 |
+
"""
|
| 863 |
+
),
|
| 864 |
+
'LICENSE-ABC': "ABC license",
|
| 865 |
+
'LICENSE-XYZ': "XYZ license",
|
| 866 |
+
# license_file is still singular
|
| 867 |
+
},
|
| 868 |
+
[],
|
| 869 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 870 |
+
),
|
| 871 |
+
(
|
| 872 |
+
{
|
| 873 |
+
'setup.cfg': DALS(
|
| 874 |
+
"""
|
| 875 |
+
[metadata]
|
| 876 |
+
license_file = LICENSE-ABC
|
| 877 |
+
license_files =
|
| 878 |
+
LICENSE-XYZ
|
| 879 |
+
LICENSE-PQR
|
| 880 |
+
"""
|
| 881 |
+
),
|
| 882 |
+
'LICENSE-ABC': "ABC license",
|
| 883 |
+
'LICENSE-PQR': "PQR license",
|
| 884 |
+
'LICENSE-XYZ': "XYZ license",
|
| 885 |
+
},
|
| 886 |
+
['LICENSE-ABC', 'LICENSE-PQR', 'LICENSE-XYZ'],
|
| 887 |
+
[],
|
| 888 |
+
), # combined
|
| 889 |
+
(
|
| 890 |
+
{
|
| 891 |
+
'setup.cfg': DALS(
|
| 892 |
+
"""
|
| 893 |
+
[metadata]
|
| 894 |
+
license_file = LICENSE-ABC
|
| 895 |
+
license_files =
|
| 896 |
+
LICENSE-ABC
|
| 897 |
+
LICENSE-XYZ
|
| 898 |
+
LICENSE-PQR
|
| 899 |
+
"""
|
| 900 |
+
),
|
| 901 |
+
'LICENSE-ABC': "ABC license",
|
| 902 |
+
'LICENSE-PQR': "PQR license",
|
| 903 |
+
'LICENSE-XYZ': "XYZ license",
|
| 904 |
+
# duplicate license
|
| 905 |
+
},
|
| 906 |
+
['LICENSE-ABC', 'LICENSE-PQR', 'LICENSE-XYZ'],
|
| 907 |
+
[],
|
| 908 |
+
),
|
| 909 |
+
(
|
| 910 |
+
{
|
| 911 |
+
'setup.cfg': DALS(
|
| 912 |
+
"""
|
| 913 |
+
[metadata]
|
| 914 |
+
license_file = LICENSE-ABC
|
| 915 |
+
license_files =
|
| 916 |
+
LICENSE-XYZ
|
| 917 |
+
"""
|
| 918 |
+
),
|
| 919 |
+
'LICENSE-ABC': "ABC license",
|
| 920 |
+
'LICENSE-PQR': "PQR license",
|
| 921 |
+
'LICENSE-XYZ': "XYZ license",
|
| 922 |
+
# combined subset
|
| 923 |
+
},
|
| 924 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 925 |
+
['LICENSE-PQR'],
|
| 926 |
+
),
|
| 927 |
+
(
|
| 928 |
+
{
|
| 929 |
+
'setup.cfg': DALS(
|
| 930 |
+
"""
|
| 931 |
+
[metadata]
|
| 932 |
+
license_file = LICENSE-ABC
|
| 933 |
+
license_files =
|
| 934 |
+
LICENSE-XYZ
|
| 935 |
+
LICENSE-PQR
|
| 936 |
+
"""
|
| 937 |
+
),
|
| 938 |
+
'LICENSE-PQR': "Test license",
|
| 939 |
+
# with invalid licenses
|
| 940 |
+
},
|
| 941 |
+
['LICENSE-PQR'],
|
| 942 |
+
['LICENSE-ABC', 'LICENSE-XYZ'],
|
| 943 |
+
),
|
| 944 |
+
(
|
| 945 |
+
{
|
| 946 |
+
'setup.cfg': DALS(
|
| 947 |
+
"""
|
| 948 |
+
[metadata]
|
| 949 |
+
license_file = LICENSE-ABC
|
| 950 |
+
license_files =
|
| 951 |
+
LICENSE-PQR
|
| 952 |
+
LICENSE-XYZ
|
| 953 |
+
"""
|
| 954 |
+
),
|
| 955 |
+
'MANIFEST.in': "exclude LICENSE-ABC\nexclude LICENSE-PQR",
|
| 956 |
+
'LICENSE-ABC': "ABC license",
|
| 957 |
+
'LICENSE-PQR': "PQR license",
|
| 958 |
+
'LICENSE-XYZ': "XYZ license",
|
| 959 |
+
# manifest is overwritten
|
| 960 |
+
},
|
| 961 |
+
['LICENSE-ABC', 'LICENSE-PQR', 'LICENSE-XYZ'],
|
| 962 |
+
[],
|
| 963 |
+
),
|
| 964 |
+
pytest.param(
|
| 965 |
+
{
|
| 966 |
+
'setup.cfg': DALS(
|
| 967 |
+
"""
|
| 968 |
+
[metadata]
|
| 969 |
+
license_file = LICENSE*
|
| 970 |
+
"""
|
| 971 |
+
),
|
| 972 |
+
'LICENSE-ABC': "ABC license",
|
| 973 |
+
'NOTICE-XYZ': "XYZ notice",
|
| 974 |
+
},
|
| 975 |
+
['LICENSE-ABC'],
|
| 976 |
+
['NOTICE-XYZ'],
|
| 977 |
+
id="no_default_glob_patterns",
|
| 978 |
+
),
|
| 979 |
+
pytest.param(
|
| 980 |
+
{
|
| 981 |
+
'setup.cfg': DALS(
|
| 982 |
+
"""
|
| 983 |
+
[metadata]
|
| 984 |
+
license_file = LICENSE*
|
| 985 |
+
license_files =
|
| 986 |
+
NOTICE*
|
| 987 |
+
"""
|
| 988 |
+
),
|
| 989 |
+
'LICENSE-ABC': "ABC license",
|
| 990 |
+
'NOTICE-ABC': "ABC notice",
|
| 991 |
+
'AUTHORS-ABC': "ABC authors",
|
| 992 |
+
},
|
| 993 |
+
['LICENSE-ABC', 'NOTICE-ABC'],
|
| 994 |
+
['AUTHORS-ABC'],
|
| 995 |
+
id="combined_glob_patterrns",
|
| 996 |
+
),
|
| 997 |
+
],
|
| 998 |
+
)
|
| 999 |
+
def test_setup_cfg_license_file_license_files(
|
| 1000 |
+
self, tmpdir_cwd, env, files, incl_licenses, excl_licenses
|
| 1001 |
+
):
|
| 1002 |
+
self._create_project()
|
| 1003 |
+
path.build(files)
|
| 1004 |
+
|
| 1005 |
+
environment.run_setup_py(
|
| 1006 |
+
cmd=['egg_info'],
|
| 1007 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1008 |
+
)
|
| 1009 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1010 |
+
|
| 1011 |
+
sources_text = Path(egg_info_dir, "SOURCES.txt").read_text(encoding="utf-8")
|
| 1012 |
+
sources_lines = [line.strip() for line in sources_text.splitlines()]
|
| 1013 |
+
|
| 1014 |
+
for lf in incl_licenses:
|
| 1015 |
+
assert sources_lines.count(lf) == 1
|
| 1016 |
+
|
| 1017 |
+
for lf in excl_licenses:
|
| 1018 |
+
assert sources_lines.count(lf) == 0
|
| 1019 |
+
|
| 1020 |
+
def test_license_file_attr_pkg_info(self, tmpdir_cwd, env):
|
| 1021 |
+
"""All matched license files should have a corresponding License-File."""
|
| 1022 |
+
self._create_project()
|
| 1023 |
+
path.build({
|
| 1024 |
+
"setup.cfg": DALS(
|
| 1025 |
+
"""
|
| 1026 |
+
[metadata]
|
| 1027 |
+
license_files =
|
| 1028 |
+
NOTICE*
|
| 1029 |
+
LICENSE*
|
| 1030 |
+
"""
|
| 1031 |
+
),
|
| 1032 |
+
"LICENSE-ABC": "ABC license",
|
| 1033 |
+
"LICENSE-XYZ": "XYZ license",
|
| 1034 |
+
"NOTICE": "included",
|
| 1035 |
+
"IGNORE": "not include",
|
| 1036 |
+
})
|
| 1037 |
+
|
| 1038 |
+
environment.run_setup_py(
|
| 1039 |
+
cmd=['egg_info'],
|
| 1040 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1041 |
+
)
|
| 1042 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1043 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1044 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1045 |
+
license_file_lines = [
|
| 1046 |
+
line for line in pkg_info_lines if line.startswith('License-File:')
|
| 1047 |
+
]
|
| 1048 |
+
|
| 1049 |
+
# Only 'NOTICE', LICENSE-ABC', and 'LICENSE-XYZ' should have been matched
|
| 1050 |
+
# Also assert that order from license_files is keeped
|
| 1051 |
+
assert "License-File: NOTICE" == license_file_lines[0]
|
| 1052 |
+
assert "License-File: LICENSE-ABC" in license_file_lines[1:]
|
| 1053 |
+
assert "License-File: LICENSE-XYZ" in license_file_lines[1:]
|
| 1054 |
+
|
| 1055 |
+
def test_metadata_version(self, tmpdir_cwd, env):
|
| 1056 |
+
"""Make sure latest metadata version is used by default."""
|
| 1057 |
+
self._setup_script_with_requires("")
|
| 1058 |
+
environment.run_setup_py(
|
| 1059 |
+
cmd=['egg_info'],
|
| 1060 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1061 |
+
data_stream=1,
|
| 1062 |
+
)
|
| 1063 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1064 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1065 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1066 |
+
# Update metadata version if changed
|
| 1067 |
+
assert self._extract_mv_version(pkg_info_lines) == (2, 2)
|
| 1068 |
+
|
| 1069 |
+
def test_long_description_content_type(self, tmpdir_cwd, env):
|
| 1070 |
+
# Test that specifying a `long_description_content_type` keyword arg to
|
| 1071 |
+
# the `setup` function results in writing a `Description-Content-Type`
|
| 1072 |
+
# line to the `PKG-INFO` file in the `<distribution>.egg-info`
|
| 1073 |
+
# directory.
|
| 1074 |
+
# `Description-Content-Type` is described at
|
| 1075 |
+
# https://github.com/pypa/python-packaging-user-guide/pull/258
|
| 1076 |
+
|
| 1077 |
+
self._setup_script_with_requires(
|
| 1078 |
+
"""long_description_content_type='text/markdown',"""
|
| 1079 |
+
)
|
| 1080 |
+
environ = os.environ.copy().update(
|
| 1081 |
+
HOME=env.paths['home'],
|
| 1082 |
+
)
|
| 1083 |
+
environment.run_setup_py(
|
| 1084 |
+
cmd=['egg_info'],
|
| 1085 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1086 |
+
data_stream=1,
|
| 1087 |
+
env=environ,
|
| 1088 |
+
)
|
| 1089 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1090 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1091 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1092 |
+
expected_line = 'Description-Content-Type: text/markdown'
|
| 1093 |
+
assert expected_line in pkg_info_lines
|
| 1094 |
+
assert 'Metadata-Version: 2.2' in pkg_info_lines
|
| 1095 |
+
|
| 1096 |
+
def test_long_description(self, tmpdir_cwd, env):
|
| 1097 |
+
# Test that specifying `long_description` and `long_description_content_type`
|
| 1098 |
+
# keyword args to the `setup` function results in writing
|
| 1099 |
+
# the description in the message payload of the `PKG-INFO` file
|
| 1100 |
+
# in the `<distribution>.egg-info` directory.
|
| 1101 |
+
self._setup_script_with_requires(
|
| 1102 |
+
"long_description='This is a long description\\nover multiple lines',"
|
| 1103 |
+
"long_description_content_type='text/markdown',"
|
| 1104 |
+
)
|
| 1105 |
+
environment.run_setup_py(
|
| 1106 |
+
cmd=['egg_info'],
|
| 1107 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1108 |
+
data_stream=1,
|
| 1109 |
+
)
|
| 1110 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1111 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1112 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1113 |
+
assert 'Metadata-Version: 2.2' in pkg_info_lines
|
| 1114 |
+
assert '' == pkg_info_lines[-1] # last line should be empty
|
| 1115 |
+
long_desc_lines = pkg_info_lines[pkg_info_lines.index('') :]
|
| 1116 |
+
assert 'This is a long description' in long_desc_lines
|
| 1117 |
+
assert 'over multiple lines' in long_desc_lines
|
| 1118 |
+
|
| 1119 |
+
def test_project_urls(self, tmpdir_cwd, env):
|
| 1120 |
+
# Test that specifying a `project_urls` dict to the `setup`
|
| 1121 |
+
# function results in writing multiple `Project-URL` lines to
|
| 1122 |
+
# the `PKG-INFO` file in the `<distribution>.egg-info`
|
| 1123 |
+
# directory.
|
| 1124 |
+
# `Project-URL` is described at https://packaging.python.org
|
| 1125 |
+
# /specifications/core-metadata/#project-url-multiple-use
|
| 1126 |
+
|
| 1127 |
+
self._setup_script_with_requires(
|
| 1128 |
+
"""project_urls={
|
| 1129 |
+
'Link One': 'https://example.com/one/',
|
| 1130 |
+
'Link Two': 'https://example.com/two/',
|
| 1131 |
+
},"""
|
| 1132 |
+
)
|
| 1133 |
+
environ = os.environ.copy().update(
|
| 1134 |
+
HOME=env.paths['home'],
|
| 1135 |
+
)
|
| 1136 |
+
environment.run_setup_py(
|
| 1137 |
+
cmd=['egg_info'],
|
| 1138 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1139 |
+
data_stream=1,
|
| 1140 |
+
env=environ,
|
| 1141 |
+
)
|
| 1142 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1143 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1144 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1145 |
+
expected_line = 'Project-URL: Link One, https://example.com/one/'
|
| 1146 |
+
assert expected_line in pkg_info_lines
|
| 1147 |
+
expected_line = 'Project-URL: Link Two, https://example.com/two/'
|
| 1148 |
+
assert expected_line in pkg_info_lines
|
| 1149 |
+
assert self._extract_mv_version(pkg_info_lines) >= (1, 2)
|
| 1150 |
+
|
| 1151 |
+
def test_license(self, tmpdir_cwd, env):
|
| 1152 |
+
"""Test single line license."""
|
| 1153 |
+
self._setup_script_with_requires("license='MIT',")
|
| 1154 |
+
environment.run_setup_py(
|
| 1155 |
+
cmd=['egg_info'],
|
| 1156 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1157 |
+
data_stream=1,
|
| 1158 |
+
)
|
| 1159 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1160 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1161 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1162 |
+
assert 'License: MIT' in pkg_info_lines
|
| 1163 |
+
|
| 1164 |
+
def test_license_escape(self, tmpdir_cwd, env):
|
| 1165 |
+
"""Test license is escaped correctly if longer than one line."""
|
| 1166 |
+
self._setup_script_with_requires(
|
| 1167 |
+
"license='This is a long license text \\nover multiple lines',"
|
| 1168 |
+
)
|
| 1169 |
+
environment.run_setup_py(
|
| 1170 |
+
cmd=['egg_info'],
|
| 1171 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1172 |
+
data_stream=1,
|
| 1173 |
+
)
|
| 1174 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1175 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1176 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1177 |
+
|
| 1178 |
+
assert 'License: This is a long license text ' in pkg_info_lines
|
| 1179 |
+
assert ' over multiple lines' in pkg_info_lines
|
| 1180 |
+
assert 'text \n over multiple' in '\n'.join(pkg_info_lines)
|
| 1181 |
+
|
| 1182 |
+
def test_python_requires_egg_info(self, tmpdir_cwd, env):
|
| 1183 |
+
self._setup_script_with_requires("""python_requires='>=2.7.12',""")
|
| 1184 |
+
environ = os.environ.copy().update(
|
| 1185 |
+
HOME=env.paths['home'],
|
| 1186 |
+
)
|
| 1187 |
+
environment.run_setup_py(
|
| 1188 |
+
cmd=['egg_info'],
|
| 1189 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1190 |
+
data_stream=1,
|
| 1191 |
+
env=environ,
|
| 1192 |
+
)
|
| 1193 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1194 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1195 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1196 |
+
assert 'Requires-Python: >=2.7.12' in pkg_info_lines
|
| 1197 |
+
assert self._extract_mv_version(pkg_info_lines) >= (1, 2)
|
| 1198 |
+
|
| 1199 |
+
def test_manifest_maker_warning_suppression(self):
|
| 1200 |
+
fixtures = [
|
| 1201 |
+
"standard file not found: should have one of foo.py, bar.py",
|
| 1202 |
+
"standard file 'setup.py' not found",
|
| 1203 |
+
]
|
| 1204 |
+
|
| 1205 |
+
for msg in fixtures:
|
| 1206 |
+
assert manifest_maker._should_suppress_warning(msg)
|
| 1207 |
+
|
| 1208 |
+
def test_egg_info_includes_setup_py(self, tmpdir_cwd):
|
| 1209 |
+
self._create_project()
|
| 1210 |
+
dist = Distribution({"name": "foo", "version": "0.0.1"})
|
| 1211 |
+
dist.script_name = "non_setup.py"
|
| 1212 |
+
egg_info_instance = egg_info(dist)
|
| 1213 |
+
egg_info_instance.finalize_options()
|
| 1214 |
+
egg_info_instance.run()
|
| 1215 |
+
|
| 1216 |
+
assert 'setup.py' in egg_info_instance.filelist.files
|
| 1217 |
+
|
| 1218 |
+
with open(egg_info_instance.egg_info + "/SOURCES.txt", encoding="utf-8") as f:
|
| 1219 |
+
sources = f.read().split('\n')
|
| 1220 |
+
assert 'setup.py' in sources
|
| 1221 |
+
|
| 1222 |
+
def _run_egg_info_command(self, tmpdir_cwd, env, cmd=None, output=None):
|
| 1223 |
+
environ = os.environ.copy().update(
|
| 1224 |
+
HOME=env.paths['home'],
|
| 1225 |
+
)
|
| 1226 |
+
if cmd is None:
|
| 1227 |
+
cmd = [
|
| 1228 |
+
'egg_info',
|
| 1229 |
+
]
|
| 1230 |
+
code, data = environment.run_setup_py(
|
| 1231 |
+
cmd=cmd,
|
| 1232 |
+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
|
| 1233 |
+
data_stream=1,
|
| 1234 |
+
env=environ,
|
| 1235 |
+
)
|
| 1236 |
+
assert not code, data
|
| 1237 |
+
|
| 1238 |
+
if output:
|
| 1239 |
+
assert output in data
|
| 1240 |
+
|
| 1241 |
+
def test_egg_info_tag_only_once(self, tmpdir_cwd, env):
|
| 1242 |
+
self._create_project()
|
| 1243 |
+
path.build({
|
| 1244 |
+
'setup.cfg': DALS(
|
| 1245 |
+
"""
|
| 1246 |
+
[egg_info]
|
| 1247 |
+
tag_build = dev
|
| 1248 |
+
tag_date = 0
|
| 1249 |
+
tag_svn_revision = 0
|
| 1250 |
+
"""
|
| 1251 |
+
),
|
| 1252 |
+
})
|
| 1253 |
+
self._run_egg_info_command(tmpdir_cwd, env)
|
| 1254 |
+
egg_info_dir = os.path.join('.', 'foo.egg-info')
|
| 1255 |
+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
|
| 1256 |
+
pkg_info_lines = fp.read().split('\n')
|
| 1257 |
+
assert 'Version: 0.0.0.dev0' in pkg_info_lines
|
| 1258 |
+
|
| 1259 |
+
|
| 1260 |
+
class TestWriteEntries:
|
| 1261 |
+
def test_invalid_entry_point(self, tmpdir_cwd, env):
|
| 1262 |
+
dist = Distribution({"name": "foo", "version": "0.0.1"})
|
| 1263 |
+
dist.entry_points = {"foo": "foo = invalid-identifier:foo"}
|
| 1264 |
+
cmd = dist.get_command_obj("egg_info")
|
| 1265 |
+
expected_msg = r"Problems to parse .*invalid-identifier.*"
|
| 1266 |
+
with pytest.raises(errors.OptionError, match=expected_msg) as ex:
|
| 1267 |
+
write_entries(cmd, "entry_points", "entry_points.txt")
|
| 1268 |
+
assert "ensure entry-point follows the spec" in ex.value.args[0]
|
| 1269 |
+
|
| 1270 |
+
def test_valid_entry_point(self, tmpdir_cwd, env):
|
| 1271 |
+
dist = Distribution({"name": "foo", "version": "0.0.1"})
|
| 1272 |
+
dist.entry_points = {
|
| 1273 |
+
"abc": "foo = bar:baz",
|
| 1274 |
+
"def": ["faa = bor:boz"],
|
| 1275 |
+
}
|
| 1276 |
+
cmd = dist.get_command_obj("egg_info")
|
| 1277 |
+
write_entries(cmd, "entry_points", "entry_points.txt")
|
| 1278 |
+
content = Path("entry_points.txt").read_text(encoding="utf-8")
|
| 1279 |
+
assert "[abc]\nfoo = bar:baz\n" in content
|
| 1280 |
+
assert "[def]\nfaa = bor:boz\n" in content
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_extern.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import pickle
|
| 3 |
+
|
| 4 |
+
import packaging
|
| 5 |
+
|
| 6 |
+
from setuptools import Distribution
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_reimport_extern():
|
| 10 |
+
packaging2 = importlib.import_module(packaging.__name__)
|
| 11 |
+
assert packaging is packaging2
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def test_distribution_picklable():
|
| 15 |
+
pickle.loads(pickle.dumps(Distribution()))
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_find_packages.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for automatic package discovery"""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import shutil
|
| 5 |
+
import tempfile
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
from setuptools import find_namespace_packages, find_packages
|
| 10 |
+
from setuptools.discovery import FlatLayoutPackageFinder
|
| 11 |
+
|
| 12 |
+
from .compat.py39 import os_helper
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TestFindPackages:
|
| 16 |
+
def setup_method(self, method):
|
| 17 |
+
self.dist_dir = tempfile.mkdtemp()
|
| 18 |
+
self._make_pkg_structure()
|
| 19 |
+
|
| 20 |
+
def teardown_method(self, method):
|
| 21 |
+
shutil.rmtree(self.dist_dir)
|
| 22 |
+
|
| 23 |
+
def _make_pkg_structure(self):
|
| 24 |
+
"""Make basic package structure.
|
| 25 |
+
|
| 26 |
+
dist/
|
| 27 |
+
docs/
|
| 28 |
+
conf.py
|
| 29 |
+
pkg/
|
| 30 |
+
__pycache__/
|
| 31 |
+
nspkg/
|
| 32 |
+
mod.py
|
| 33 |
+
subpkg/
|
| 34 |
+
assets/
|
| 35 |
+
asset
|
| 36 |
+
__init__.py
|
| 37 |
+
setup.py
|
| 38 |
+
|
| 39 |
+
"""
|
| 40 |
+
self.docs_dir = self._mkdir('docs', self.dist_dir)
|
| 41 |
+
self._touch('conf.py', self.docs_dir)
|
| 42 |
+
self.pkg_dir = self._mkdir('pkg', self.dist_dir)
|
| 43 |
+
self._mkdir('__pycache__', self.pkg_dir)
|
| 44 |
+
self.ns_pkg_dir = self._mkdir('nspkg', self.pkg_dir)
|
| 45 |
+
self._touch('mod.py', self.ns_pkg_dir)
|
| 46 |
+
self.sub_pkg_dir = self._mkdir('subpkg', self.pkg_dir)
|
| 47 |
+
self.asset_dir = self._mkdir('assets', self.sub_pkg_dir)
|
| 48 |
+
self._touch('asset', self.asset_dir)
|
| 49 |
+
self._touch('__init__.py', self.sub_pkg_dir)
|
| 50 |
+
self._touch('setup.py', self.dist_dir)
|
| 51 |
+
|
| 52 |
+
def _mkdir(self, path, parent_dir=None):
|
| 53 |
+
if parent_dir:
|
| 54 |
+
path = os.path.join(parent_dir, path)
|
| 55 |
+
os.mkdir(path)
|
| 56 |
+
return path
|
| 57 |
+
|
| 58 |
+
def _touch(self, path, dir_=None):
|
| 59 |
+
if dir_:
|
| 60 |
+
path = os.path.join(dir_, path)
|
| 61 |
+
open(path, 'wb').close()
|
| 62 |
+
return path
|
| 63 |
+
|
| 64 |
+
def test_regular_package(self):
|
| 65 |
+
self._touch('__init__.py', self.pkg_dir)
|
| 66 |
+
packages = find_packages(self.dist_dir)
|
| 67 |
+
assert packages == ['pkg', 'pkg.subpkg']
|
| 68 |
+
|
| 69 |
+
def test_exclude(self):
|
| 70 |
+
self._touch('__init__.py', self.pkg_dir)
|
| 71 |
+
packages = find_packages(self.dist_dir, exclude=('pkg.*',))
|
| 72 |
+
assert packages == ['pkg']
|
| 73 |
+
|
| 74 |
+
def test_exclude_recursive(self):
|
| 75 |
+
"""
|
| 76 |
+
Excluding a parent package should not exclude child packages as well.
|
| 77 |
+
"""
|
| 78 |
+
self._touch('__init__.py', self.pkg_dir)
|
| 79 |
+
self._touch('__init__.py', self.sub_pkg_dir)
|
| 80 |
+
packages = find_packages(self.dist_dir, exclude=('pkg',))
|
| 81 |
+
assert packages == ['pkg.subpkg']
|
| 82 |
+
|
| 83 |
+
def test_include_excludes_other(self):
|
| 84 |
+
"""
|
| 85 |
+
If include is specified, other packages should be excluded.
|
| 86 |
+
"""
|
| 87 |
+
self._touch('__init__.py', self.pkg_dir)
|
| 88 |
+
alt_dir = self._mkdir('other_pkg', self.dist_dir)
|
| 89 |
+
self._touch('__init__.py', alt_dir)
|
| 90 |
+
packages = find_packages(self.dist_dir, include=['other_pkg'])
|
| 91 |
+
assert packages == ['other_pkg']
|
| 92 |
+
|
| 93 |
+
def test_dir_with_dot_is_skipped(self):
|
| 94 |
+
shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets'))
|
| 95 |
+
data_dir = self._mkdir('some.data', self.pkg_dir)
|
| 96 |
+
self._touch('__init__.py', data_dir)
|
| 97 |
+
self._touch('file.dat', data_dir)
|
| 98 |
+
packages = find_packages(self.dist_dir)
|
| 99 |
+
assert 'pkg.some.data' not in packages
|
| 100 |
+
|
| 101 |
+
def test_dir_with_packages_in_subdir_is_excluded(self):
|
| 102 |
+
"""
|
| 103 |
+
Ensure that a package in a non-package such as build/pkg/__init__.py
|
| 104 |
+
is excluded.
|
| 105 |
+
"""
|
| 106 |
+
build_dir = self._mkdir('build', self.dist_dir)
|
| 107 |
+
build_pkg_dir = self._mkdir('pkg', build_dir)
|
| 108 |
+
self._touch('__init__.py', build_pkg_dir)
|
| 109 |
+
packages = find_packages(self.dist_dir)
|
| 110 |
+
assert 'build.pkg' not in packages
|
| 111 |
+
|
| 112 |
+
@pytest.mark.skipif(not os_helper.can_symlink(), reason='Symlink support required')
|
| 113 |
+
def test_symlinked_packages_are_included(self):
|
| 114 |
+
"""
|
| 115 |
+
A symbolically-linked directory should be treated like any other
|
| 116 |
+
directory when matched as a package.
|
| 117 |
+
|
| 118 |
+
Create a link from lpkg -> pkg.
|
| 119 |
+
"""
|
| 120 |
+
self._touch('__init__.py', self.pkg_dir)
|
| 121 |
+
linked_pkg = os.path.join(self.dist_dir, 'lpkg')
|
| 122 |
+
os.symlink('pkg', linked_pkg)
|
| 123 |
+
assert os.path.isdir(linked_pkg)
|
| 124 |
+
packages = find_packages(self.dist_dir)
|
| 125 |
+
assert 'lpkg' in packages
|
| 126 |
+
|
| 127 |
+
def _assert_packages(self, actual, expected):
|
| 128 |
+
assert set(actual) == set(expected)
|
| 129 |
+
|
| 130 |
+
def test_pep420_ns_package(self):
|
| 131 |
+
packages = find_namespace_packages(
|
| 132 |
+
self.dist_dir, include=['pkg*'], exclude=['pkg.subpkg.assets']
|
| 133 |
+
)
|
| 134 |
+
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
|
| 135 |
+
|
| 136 |
+
def test_pep420_ns_package_no_includes(self):
|
| 137 |
+
packages = find_namespace_packages(self.dist_dir, exclude=['pkg.subpkg.assets'])
|
| 138 |
+
self._assert_packages(packages, ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg'])
|
| 139 |
+
|
| 140 |
+
def test_pep420_ns_package_no_includes_or_excludes(self):
|
| 141 |
+
packages = find_namespace_packages(self.dist_dir)
|
| 142 |
+
expected = ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg', 'pkg.subpkg.assets']
|
| 143 |
+
self._assert_packages(packages, expected)
|
| 144 |
+
|
| 145 |
+
def test_regular_package_with_nested_pep420_ns_packages(self):
|
| 146 |
+
self._touch('__init__.py', self.pkg_dir)
|
| 147 |
+
packages = find_namespace_packages(
|
| 148 |
+
self.dist_dir, exclude=['docs', 'pkg.subpkg.assets']
|
| 149 |
+
)
|
| 150 |
+
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
|
| 151 |
+
|
| 152 |
+
def test_pep420_ns_package_no_non_package_dirs(self):
|
| 153 |
+
shutil.rmtree(self.docs_dir)
|
| 154 |
+
shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets'))
|
| 155 |
+
packages = find_namespace_packages(self.dist_dir)
|
| 156 |
+
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class TestFlatLayoutPackageFinder:
|
| 160 |
+
EXAMPLES = {
|
| 161 |
+
"hidden-folders": (
|
| 162 |
+
[".pkg/__init__.py", "pkg/__init__.py", "pkg/nested/file.txt"],
|
| 163 |
+
["pkg", "pkg.nested"],
|
| 164 |
+
),
|
| 165 |
+
"private-packages": (
|
| 166 |
+
["_pkg/__init__.py", "pkg/_private/__init__.py"],
|
| 167 |
+
["pkg", "pkg._private"],
|
| 168 |
+
),
|
| 169 |
+
"invalid-name": (
|
| 170 |
+
["invalid-pkg/__init__.py", "other.pkg/__init__.py", "yet,another/file.py"],
|
| 171 |
+
[],
|
| 172 |
+
),
|
| 173 |
+
"docs": (["pkg/__init__.py", "docs/conf.py", "docs/readme.rst"], ["pkg"]),
|
| 174 |
+
"tests": (
|
| 175 |
+
["pkg/__init__.py", "tests/test_pkg.py", "tests/__init__.py"],
|
| 176 |
+
["pkg"],
|
| 177 |
+
),
|
| 178 |
+
"examples": (
|
| 179 |
+
[
|
| 180 |
+
"pkg/__init__.py",
|
| 181 |
+
"examples/__init__.py",
|
| 182 |
+
"examples/file.py",
|
| 183 |
+
"example/other_file.py",
|
| 184 |
+
# Sub-packages should always be fine
|
| 185 |
+
"pkg/example/__init__.py",
|
| 186 |
+
"pkg/examples/__init__.py",
|
| 187 |
+
],
|
| 188 |
+
["pkg", "pkg.examples", "pkg.example"],
|
| 189 |
+
),
|
| 190 |
+
"tool-specific": (
|
| 191 |
+
[
|
| 192 |
+
"htmlcov/index.html",
|
| 193 |
+
"pkg/__init__.py",
|
| 194 |
+
"tasks/__init__.py",
|
| 195 |
+
"tasks/subpackage/__init__.py",
|
| 196 |
+
"fabfile/__init__.py",
|
| 197 |
+
"fabfile/subpackage/__init__.py",
|
| 198 |
+
# Sub-packages should always be fine
|
| 199 |
+
"pkg/tasks/__init__.py",
|
| 200 |
+
"pkg/fabfile/__init__.py",
|
| 201 |
+
],
|
| 202 |
+
["pkg", "pkg.tasks", "pkg.fabfile"],
|
| 203 |
+
),
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
@pytest.mark.parametrize("example", EXAMPLES.keys())
|
| 207 |
+
def test_unwanted_directories_not_included(self, tmp_path, example):
|
| 208 |
+
files, expected_packages = self.EXAMPLES[example]
|
| 209 |
+
ensure_files(tmp_path, files)
|
| 210 |
+
found_packages = FlatLayoutPackageFinder.find(str(tmp_path))
|
| 211 |
+
assert set(found_packages) == set(expected_packages)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def ensure_files(root_path, files):
|
| 215 |
+
for file in files:
|
| 216 |
+
path = root_path / file
|
| 217 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 218 |
+
path.touch()
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_find_py_modules.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for automatic discovery of modules"""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from setuptools.discovery import FlatLayoutModuleFinder, ModuleFinder
|
| 8 |
+
|
| 9 |
+
from .compat.py39 import os_helper
|
| 10 |
+
from .test_find_packages import ensure_files
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TestModuleFinder:
|
| 14 |
+
def find(self, path, *args, **kwargs):
|
| 15 |
+
return set(ModuleFinder.find(str(path), *args, **kwargs))
|
| 16 |
+
|
| 17 |
+
EXAMPLES = {
|
| 18 |
+
# circumstance: (files, kwargs, expected_modules)
|
| 19 |
+
"simple_folder": (
|
| 20 |
+
["file.py", "other.py"],
|
| 21 |
+
{}, # kwargs
|
| 22 |
+
["file", "other"],
|
| 23 |
+
),
|
| 24 |
+
"exclude": (
|
| 25 |
+
["file.py", "other.py"],
|
| 26 |
+
{"exclude": ["f*"]},
|
| 27 |
+
["other"],
|
| 28 |
+
),
|
| 29 |
+
"include": (
|
| 30 |
+
["file.py", "fole.py", "other.py"],
|
| 31 |
+
{"include": ["f*"], "exclude": ["fo*"]},
|
| 32 |
+
["file"],
|
| 33 |
+
),
|
| 34 |
+
"invalid-name": (["my-file.py", "other.file.py"], {}, []),
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
@pytest.mark.parametrize("example", EXAMPLES.keys())
|
| 38 |
+
def test_finder(self, tmp_path, example):
|
| 39 |
+
files, kwargs, expected_modules = self.EXAMPLES[example]
|
| 40 |
+
ensure_files(tmp_path, files)
|
| 41 |
+
assert self.find(tmp_path, **kwargs) == set(expected_modules)
|
| 42 |
+
|
| 43 |
+
@pytest.mark.skipif(not os_helper.can_symlink(), reason='Symlink support required')
|
| 44 |
+
def test_symlinked_packages_are_included(self, tmp_path):
|
| 45 |
+
src = "_myfiles/file.py"
|
| 46 |
+
ensure_files(tmp_path, [src])
|
| 47 |
+
os.symlink(tmp_path / src, tmp_path / "link.py")
|
| 48 |
+
assert self.find(tmp_path) == {"link"}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class TestFlatLayoutModuleFinder:
|
| 52 |
+
def find(self, path, *args, **kwargs):
|
| 53 |
+
return set(FlatLayoutModuleFinder.find(str(path)))
|
| 54 |
+
|
| 55 |
+
EXAMPLES = {
|
| 56 |
+
# circumstance: (files, expected_modules)
|
| 57 |
+
"hidden-files": ([".module.py"], []),
|
| 58 |
+
"private-modules": (["_module.py"], []),
|
| 59 |
+
"common-names": (
|
| 60 |
+
["setup.py", "conftest.py", "test.py", "tests.py", "example.py", "mod.py"],
|
| 61 |
+
["mod"],
|
| 62 |
+
),
|
| 63 |
+
"tool-specific": (
|
| 64 |
+
["tasks.py", "fabfile.py", "noxfile.py", "dodo.py", "manage.py", "mod.py"],
|
| 65 |
+
["mod"],
|
| 66 |
+
),
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
@pytest.mark.parametrize("example", EXAMPLES.keys())
|
| 70 |
+
def test_unwanted_files_not_included(self, tmp_path, example):
|
| 71 |
+
files, expected_modules = self.EXAMPLES[example]
|
| 72 |
+
ensure_files(tmp_path, files)
|
| 73 |
+
assert self.find(tmp_path) == set(expected_modules)
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_install_scripts.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""install_scripts tests"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from setuptools.command.install_scripts import install_scripts
|
| 8 |
+
from setuptools.dist import Distribution
|
| 9 |
+
|
| 10 |
+
from . import contexts
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TestInstallScripts:
|
| 14 |
+
settings = dict(
|
| 15 |
+
name='foo',
|
| 16 |
+
entry_points={'console_scripts': ['foo=foo:foo']},
|
| 17 |
+
version='0.0',
|
| 18 |
+
)
|
| 19 |
+
unix_exe = '/usr/dummy-test-path/local/bin/python'
|
| 20 |
+
unix_spaces_exe = '/usr/bin/env dummy-test-python'
|
| 21 |
+
win32_exe = 'C:\\Dummy Test Path\\Program Files\\Python 3.6\\python.exe'
|
| 22 |
+
|
| 23 |
+
def _run_install_scripts(self, install_dir, executable=None):
|
| 24 |
+
dist = Distribution(self.settings)
|
| 25 |
+
dist.script_name = 'setup.py'
|
| 26 |
+
cmd = install_scripts(dist)
|
| 27 |
+
cmd.install_dir = install_dir
|
| 28 |
+
if executable is not None:
|
| 29 |
+
bs = cmd.get_finalized_command('build_scripts')
|
| 30 |
+
bs.executable = executable
|
| 31 |
+
cmd.ensure_finalized()
|
| 32 |
+
with contexts.quiet():
|
| 33 |
+
cmd.run()
|
| 34 |
+
|
| 35 |
+
@pytest.mark.skipif(sys.platform == 'win32', reason='non-Windows only')
|
| 36 |
+
def test_sys_executable_escaping_unix(self, tmpdir, monkeypatch):
|
| 37 |
+
"""
|
| 38 |
+
Ensure that shebang is not quoted on Unix when getting the Python exe
|
| 39 |
+
from sys.executable.
|
| 40 |
+
"""
|
| 41 |
+
expected = f'#!{self.unix_exe}\n'
|
| 42 |
+
monkeypatch.setattr('sys.executable', self.unix_exe)
|
| 43 |
+
with tmpdir.as_cwd():
|
| 44 |
+
self._run_install_scripts(str(tmpdir))
|
| 45 |
+
with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:
|
| 46 |
+
actual = f.readline()
|
| 47 |
+
assert actual == expected
|
| 48 |
+
|
| 49 |
+
@pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
|
| 50 |
+
def test_sys_executable_escaping_win32(self, tmpdir, monkeypatch):
|
| 51 |
+
"""
|
| 52 |
+
Ensure that shebang is quoted on Windows when getting the Python exe
|
| 53 |
+
from sys.executable and it contains a space.
|
| 54 |
+
"""
|
| 55 |
+
expected = f'#!"{self.win32_exe}"\n'
|
| 56 |
+
monkeypatch.setattr('sys.executable', self.win32_exe)
|
| 57 |
+
with tmpdir.as_cwd():
|
| 58 |
+
self._run_install_scripts(str(tmpdir))
|
| 59 |
+
with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:
|
| 60 |
+
actual = f.readline()
|
| 61 |
+
assert actual == expected
|
| 62 |
+
|
| 63 |
+
@pytest.mark.skipif(sys.platform == 'win32', reason='non-Windows only')
|
| 64 |
+
def test_executable_with_spaces_escaping_unix(self, tmpdir):
|
| 65 |
+
"""
|
| 66 |
+
Ensure that shebang on Unix is not quoted, even when
|
| 67 |
+
a value with spaces
|
| 68 |
+
is specified using --executable.
|
| 69 |
+
"""
|
| 70 |
+
expected = f'#!{self.unix_spaces_exe}\n'
|
| 71 |
+
with tmpdir.as_cwd():
|
| 72 |
+
self._run_install_scripts(str(tmpdir), self.unix_spaces_exe)
|
| 73 |
+
with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:
|
| 74 |
+
actual = f.readline()
|
| 75 |
+
assert actual == expected
|
| 76 |
+
|
| 77 |
+
@pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
|
| 78 |
+
def test_executable_arg_escaping_win32(self, tmpdir):
|
| 79 |
+
"""
|
| 80 |
+
Ensure that shebang on Windows is quoted when
|
| 81 |
+
getting a path with spaces
|
| 82 |
+
from --executable, that is itself properly quoted.
|
| 83 |
+
"""
|
| 84 |
+
expected = f'#!"{self.win32_exe}"\n'
|
| 85 |
+
with tmpdir.as_cwd():
|
| 86 |
+
self._run_install_scripts(str(tmpdir), '"' + self.win32_exe + '"')
|
| 87 |
+
with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:
|
| 88 |
+
actual = f.readline()
|
| 89 |
+
assert actual == expected
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_logging.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import inspect
|
| 3 |
+
import logging
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
IS_PYPY = '__pypy__' in sys.builtin_module_names
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
setup_py = """\
|
| 12 |
+
from setuptools import setup
|
| 13 |
+
|
| 14 |
+
setup(
|
| 15 |
+
name="test_logging",
|
| 16 |
+
version="0.0"
|
| 17 |
+
)
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@pytest.mark.parametrize(
|
| 22 |
+
('flag', 'expected_level'), [("--dry-run", "INFO"), ("--verbose", "DEBUG")]
|
| 23 |
+
)
|
| 24 |
+
def test_verbosity_level(tmp_path, monkeypatch, flag, expected_level):
|
| 25 |
+
"""Make sure the correct verbosity level is set (issue #3038)"""
|
| 26 |
+
import setuptools # noqa: F401 # import setuptools to monkeypatch distutils
|
| 27 |
+
|
| 28 |
+
import distutils # <- load distutils after all the patches take place
|
| 29 |
+
|
| 30 |
+
logger = logging.Logger(__name__)
|
| 31 |
+
monkeypatch.setattr(logging, "root", logger)
|
| 32 |
+
unset_log_level = logger.getEffectiveLevel()
|
| 33 |
+
assert logging.getLevelName(unset_log_level) == "NOTSET"
|
| 34 |
+
|
| 35 |
+
setup_script = tmp_path / "setup.py"
|
| 36 |
+
setup_script.write_text(setup_py, encoding="utf-8")
|
| 37 |
+
dist = distutils.core.run_setup(setup_script, stop_after="init")
|
| 38 |
+
dist.script_args = [flag, "sdist"]
|
| 39 |
+
dist.parse_command_line() # <- where the log level is set
|
| 40 |
+
log_level = logger.getEffectiveLevel()
|
| 41 |
+
log_level_name = logging.getLevelName(log_level)
|
| 42 |
+
assert log_level_name == expected_level
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def flaky_on_pypy(func):
|
| 46 |
+
@functools.wraps(func)
|
| 47 |
+
def _func():
|
| 48 |
+
try:
|
| 49 |
+
func()
|
| 50 |
+
except AssertionError: # pragma: no cover
|
| 51 |
+
if IS_PYPY:
|
| 52 |
+
msg = "Flaky monkeypatch on PyPy (#4124)"
|
| 53 |
+
pytest.xfail(f"{msg}. Original discussion in #3707, #3709.")
|
| 54 |
+
raise
|
| 55 |
+
|
| 56 |
+
return _func
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
@flaky_on_pypy
|
| 60 |
+
def test_patching_does_not_cause_problems():
|
| 61 |
+
# Ensure `dist.log` is only patched if necessary
|
| 62 |
+
|
| 63 |
+
import _distutils_hack
|
| 64 |
+
|
| 65 |
+
import setuptools.logging
|
| 66 |
+
|
| 67 |
+
from distutils import dist
|
| 68 |
+
|
| 69 |
+
setuptools.logging.configure()
|
| 70 |
+
|
| 71 |
+
if _distutils_hack.enabled():
|
| 72 |
+
# Modern logging infra, no problematic patching.
|
| 73 |
+
assert dist.__file__ is None or "setuptools" in dist.__file__
|
| 74 |
+
assert isinstance(dist.log, logging.Logger)
|
| 75 |
+
else:
|
| 76 |
+
assert inspect.ismodule(dist.log)
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_manifest.py
ADDED
|
@@ -0,0 +1,622 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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import itertools
|
| 8 |
+
import logging
|
| 9 |
+
import os
|
| 10 |
+
import shutil
|
| 11 |
+
import sys
|
| 12 |
+
import tempfile
|
| 13 |
+
|
| 14 |
+
import pytest
|
| 15 |
+
|
| 16 |
+
from setuptools.command.egg_info import FileList, egg_info, translate_pattern
|
| 17 |
+
from setuptools.dist import Distribution
|
| 18 |
+
from setuptools.tests.textwrap import DALS
|
| 19 |
+
|
| 20 |
+
from distutils import log
|
| 21 |
+
from distutils.errors import DistutilsTemplateError
|
| 22 |
+
|
| 23 |
+
IS_PYPY = '__pypy__' in sys.builtin_module_names
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def make_local_path(s):
|
| 27 |
+
"""Converts '/' in a string to os.sep"""
|
| 28 |
+
return s.replace('/', os.sep)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
SETUP_ATTRS = {
|
| 32 |
+
'name': 'app',
|
| 33 |
+
'version': '0.0',
|
| 34 |
+
'packages': ['app'],
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
SETUP_PY = f"""\
|
| 38 |
+
from setuptools import setup
|
| 39 |
+
|
| 40 |
+
setup(**{SETUP_ATTRS!r})
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@contextlib.contextmanager
|
| 45 |
+
def quiet():
|
| 46 |
+
old_stdout, old_stderr = sys.stdout, sys.stderr
|
| 47 |
+
sys.stdout, sys.stderr = io.StringIO(), io.StringIO()
|
| 48 |
+
try:
|
| 49 |
+
yield
|
| 50 |
+
finally:
|
| 51 |
+
sys.stdout, sys.stderr = old_stdout, old_stderr
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def touch(filename):
|
| 55 |
+
open(filename, 'wb').close()
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# The set of files always in the manifest, including all files in the
|
| 59 |
+
# .egg-info directory
|
| 60 |
+
default_files = frozenset(
|
| 61 |
+
map(
|
| 62 |
+
make_local_path,
|
| 63 |
+
[
|
| 64 |
+
'README.rst',
|
| 65 |
+
'MANIFEST.in',
|
| 66 |
+
'setup.py',
|
| 67 |
+
'app.egg-info/PKG-INFO',
|
| 68 |
+
'app.egg-info/SOURCES.txt',
|
| 69 |
+
'app.egg-info/dependency_links.txt',
|
| 70 |
+
'app.egg-info/top_level.txt',
|
| 71 |
+
'app/__init__.py',
|
| 72 |
+
],
|
| 73 |
+
)
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
translate_specs: list[tuple[str, list[str], list[str]]] = [
|
| 78 |
+
('foo', ['foo'], ['bar', 'foobar']),
|
| 79 |
+
('foo/bar', ['foo/bar'], ['foo/bar/baz', './foo/bar', 'foo']),
|
| 80 |
+
# Glob matching
|
| 81 |
+
('*.txt', ['foo.txt', 'bar.txt'], ['foo/foo.txt']),
|
| 82 |
+
('dir/*.txt', ['dir/foo.txt', 'dir/bar.txt', 'dir/.txt'], ['notdir/foo.txt']),
|
| 83 |
+
('*/*.py', ['bin/start.py'], []),
|
| 84 |
+
('docs/page-?.txt', ['docs/page-9.txt'], ['docs/page-10.txt']),
|
| 85 |
+
# Globstars change what they mean depending upon where they are
|
| 86 |
+
(
|
| 87 |
+
'foo/**/bar',
|
| 88 |
+
['foo/bing/bar', 'foo/bing/bang/bar', 'foo/bar'],
|
| 89 |
+
['foo/abar'],
|
| 90 |
+
),
|
| 91 |
+
(
|
| 92 |
+
'foo/**',
|
| 93 |
+
['foo/bar/bing.py', 'foo/x'],
|
| 94 |
+
['/foo/x'],
|
| 95 |
+
),
|
| 96 |
+
(
|
| 97 |
+
'**',
|
| 98 |
+
['x', 'abc/xyz', '@nything'],
|
| 99 |
+
[],
|
| 100 |
+
),
|
| 101 |
+
# Character classes
|
| 102 |
+
(
|
| 103 |
+
'pre[one]post',
|
| 104 |
+
['preopost', 'prenpost', 'preepost'],
|
| 105 |
+
['prepost', 'preonepost'],
|
| 106 |
+
),
|
| 107 |
+
(
|
| 108 |
+
'hello[!one]world',
|
| 109 |
+
['helloxworld', 'helloyworld'],
|
| 110 |
+
['hellooworld', 'helloworld', 'hellooneworld'],
|
| 111 |
+
),
|
| 112 |
+
(
|
| 113 |
+
'[]one].txt',
|
| 114 |
+
['o.txt', '].txt', 'e.txt'],
|
| 115 |
+
['one].txt'],
|
| 116 |
+
),
|
| 117 |
+
(
|
| 118 |
+
'foo[!]one]bar',
|
| 119 |
+
['fooybar'],
|
| 120 |
+
['foo]bar', 'fooobar', 'fooebar'],
|
| 121 |
+
),
|
| 122 |
+
]
|
| 123 |
+
"""
|
| 124 |
+
A spec of inputs for 'translate_pattern' and matches and mismatches
|
| 125 |
+
for that input.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
match_params = itertools.chain.from_iterable(
|
| 129 |
+
zip(itertools.repeat(pattern), matches)
|
| 130 |
+
for pattern, matches, mismatches in translate_specs
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
@pytest.fixture(params=match_params)
|
| 135 |
+
def pattern_match(request):
|
| 136 |
+
return map(make_local_path, request.param)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
mismatch_params = itertools.chain.from_iterable(
|
| 140 |
+
zip(itertools.repeat(pattern), mismatches)
|
| 141 |
+
for pattern, matches, mismatches in translate_specs
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@pytest.fixture(params=mismatch_params)
|
| 146 |
+
def pattern_mismatch(request):
|
| 147 |
+
return map(make_local_path, request.param)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def test_translated_pattern_match(pattern_match):
|
| 151 |
+
pattern, target = pattern_match
|
| 152 |
+
assert translate_pattern(pattern).match(target)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def test_translated_pattern_mismatch(pattern_mismatch):
|
| 156 |
+
pattern, target = pattern_mismatch
|
| 157 |
+
assert not translate_pattern(pattern).match(target)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class TempDirTestCase:
|
| 161 |
+
def setup_method(self, method):
|
| 162 |
+
self.temp_dir = tempfile.mkdtemp()
|
| 163 |
+
self.old_cwd = os.getcwd()
|
| 164 |
+
os.chdir(self.temp_dir)
|
| 165 |
+
|
| 166 |
+
def teardown_method(self, method):
|
| 167 |
+
os.chdir(self.old_cwd)
|
| 168 |
+
shutil.rmtree(self.temp_dir)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class TestManifestTest(TempDirTestCase):
|
| 172 |
+
def setup_method(self, method):
|
| 173 |
+
super().setup_method(method)
|
| 174 |
+
|
| 175 |
+
f = open(os.path.join(self.temp_dir, 'setup.py'), 'w', encoding="utf-8")
|
| 176 |
+
f.write(SETUP_PY)
|
| 177 |
+
f.close()
|
| 178 |
+
"""
|
| 179 |
+
Create a file tree like:
|
| 180 |
+
- LICENSE
|
| 181 |
+
- README.rst
|
| 182 |
+
- testing.rst
|
| 183 |
+
- .hidden.rst
|
| 184 |
+
- app/
|
| 185 |
+
- __init__.py
|
| 186 |
+
- a.txt
|
| 187 |
+
- b.txt
|
| 188 |
+
- c.rst
|
| 189 |
+
- static/
|
| 190 |
+
- app.js
|
| 191 |
+
- app.js.map
|
| 192 |
+
- app.css
|
| 193 |
+
- app.css.map
|
| 194 |
+
"""
|
| 195 |
+
|
| 196 |
+
for fname in ['README.rst', '.hidden.rst', 'testing.rst', 'LICENSE']:
|
| 197 |
+
touch(os.path.join(self.temp_dir, fname))
|
| 198 |
+
|
| 199 |
+
# Set up the rest of the test package
|
| 200 |
+
test_pkg = os.path.join(self.temp_dir, 'app')
|
| 201 |
+
os.mkdir(test_pkg)
|
| 202 |
+
for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']:
|
| 203 |
+
touch(os.path.join(test_pkg, fname))
|
| 204 |
+
|
| 205 |
+
# Some compiled front-end assets to include
|
| 206 |
+
static = os.path.join(test_pkg, 'static')
|
| 207 |
+
os.mkdir(static)
|
| 208 |
+
for fname in ['app.js', 'app.js.map', 'app.css', 'app.css.map']:
|
| 209 |
+
touch(os.path.join(static, fname))
|
| 210 |
+
|
| 211 |
+
def make_manifest(self, contents):
|
| 212 |
+
"""Write a MANIFEST.in."""
|
| 213 |
+
manifest = os.path.join(self.temp_dir, 'MANIFEST.in')
|
| 214 |
+
with open(manifest, 'w', encoding="utf-8") as f:
|
| 215 |
+
f.write(DALS(contents))
|
| 216 |
+
|
| 217 |
+
def get_files(self):
|
| 218 |
+
"""Run egg_info and get all the files to include, as a set"""
|
| 219 |
+
dist = Distribution(SETUP_ATTRS)
|
| 220 |
+
dist.script_name = 'setup.py'
|
| 221 |
+
cmd = egg_info(dist)
|
| 222 |
+
cmd.ensure_finalized()
|
| 223 |
+
|
| 224 |
+
cmd.run()
|
| 225 |
+
|
| 226 |
+
return set(cmd.filelist.files)
|
| 227 |
+
|
| 228 |
+
def test_no_manifest(self):
|
| 229 |
+
"""Check a missing MANIFEST.in includes only the standard files."""
|
| 230 |
+
assert (default_files - set(['MANIFEST.in'])) == self.get_files()
|
| 231 |
+
|
| 232 |
+
def test_empty_files(self):
|
| 233 |
+
"""Check an empty MANIFEST.in includes only the standard files."""
|
| 234 |
+
self.make_manifest("")
|
| 235 |
+
assert default_files == self.get_files()
|
| 236 |
+
|
| 237 |
+
def test_include(self):
|
| 238 |
+
"""Include extra rst files in the project root."""
|
| 239 |
+
self.make_manifest("include *.rst")
|
| 240 |
+
files = default_files | set(['testing.rst', '.hidden.rst'])
|
| 241 |
+
assert files == self.get_files()
|
| 242 |
+
|
| 243 |
+
def test_exclude(self):
|
| 244 |
+
"""Include everything in app/ except the text files"""
|
| 245 |
+
ml = make_local_path
|
| 246 |
+
self.make_manifest(
|
| 247 |
+
"""
|
| 248 |
+
include app/*
|
| 249 |
+
exclude app/*.txt
|
| 250 |
+
"""
|
| 251 |
+
)
|
| 252 |
+
files = default_files | set([ml('app/c.rst')])
|
| 253 |
+
assert files == self.get_files()
|
| 254 |
+
|
| 255 |
+
def test_include_multiple(self):
|
| 256 |
+
"""Include with multiple patterns."""
|
| 257 |
+
ml = make_local_path
|
| 258 |
+
self.make_manifest("include app/*.txt app/static/*")
|
| 259 |
+
files = default_files | set([
|
| 260 |
+
ml('app/a.txt'),
|
| 261 |
+
ml('app/b.txt'),
|
| 262 |
+
ml('app/static/app.js'),
|
| 263 |
+
ml('app/static/app.js.map'),
|
| 264 |
+
ml('app/static/app.css'),
|
| 265 |
+
ml('app/static/app.css.map'),
|
| 266 |
+
])
|
| 267 |
+
assert files == self.get_files()
|
| 268 |
+
|
| 269 |
+
def test_graft(self):
|
| 270 |
+
"""Include the whole app/static/ directory."""
|
| 271 |
+
ml = make_local_path
|
| 272 |
+
self.make_manifest("graft app/static")
|
| 273 |
+
files = default_files | set([
|
| 274 |
+
ml('app/static/app.js'),
|
| 275 |
+
ml('app/static/app.js.map'),
|
| 276 |
+
ml('app/static/app.css'),
|
| 277 |
+
ml('app/static/app.css.map'),
|
| 278 |
+
])
|
| 279 |
+
assert files == self.get_files()
|
| 280 |
+
|
| 281 |
+
def test_graft_glob_syntax(self):
|
| 282 |
+
"""Include the whole app/static/ directory."""
|
| 283 |
+
ml = make_local_path
|
| 284 |
+
self.make_manifest("graft */static")
|
| 285 |
+
files = default_files | set([
|
| 286 |
+
ml('app/static/app.js'),
|
| 287 |
+
ml('app/static/app.js.map'),
|
| 288 |
+
ml('app/static/app.css'),
|
| 289 |
+
ml('app/static/app.css.map'),
|
| 290 |
+
])
|
| 291 |
+
assert files == self.get_files()
|
| 292 |
+
|
| 293 |
+
def test_graft_global_exclude(self):
|
| 294 |
+
"""Exclude all *.map files in the project."""
|
| 295 |
+
ml = make_local_path
|
| 296 |
+
self.make_manifest(
|
| 297 |
+
"""
|
| 298 |
+
graft app/static
|
| 299 |
+
global-exclude *.map
|
| 300 |
+
"""
|
| 301 |
+
)
|
| 302 |
+
files = default_files | set([ml('app/static/app.js'), ml('app/static/app.css')])
|
| 303 |
+
assert files == self.get_files()
|
| 304 |
+
|
| 305 |
+
def test_global_include(self):
|
| 306 |
+
"""Include all *.rst, *.js, and *.css files in the whole tree."""
|
| 307 |
+
ml = make_local_path
|
| 308 |
+
self.make_manifest(
|
| 309 |
+
"""
|
| 310 |
+
global-include *.rst *.js *.css
|
| 311 |
+
"""
|
| 312 |
+
)
|
| 313 |
+
files = default_files | set([
|
| 314 |
+
'.hidden.rst',
|
| 315 |
+
'testing.rst',
|
| 316 |
+
ml('app/c.rst'),
|
| 317 |
+
ml('app/static/app.js'),
|
| 318 |
+
ml('app/static/app.css'),
|
| 319 |
+
])
|
| 320 |
+
assert files == self.get_files()
|
| 321 |
+
|
| 322 |
+
def test_graft_prune(self):
|
| 323 |
+
"""Include all files in app/, except for the whole app/static/ dir."""
|
| 324 |
+
ml = make_local_path
|
| 325 |
+
self.make_manifest(
|
| 326 |
+
"""
|
| 327 |
+
graft app
|
| 328 |
+
prune app/static
|
| 329 |
+
"""
|
| 330 |
+
)
|
| 331 |
+
files = default_files | set([ml('app/a.txt'), ml('app/b.txt'), ml('app/c.rst')])
|
| 332 |
+
assert files == self.get_files()
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
class TestFileListTest(TempDirTestCase):
|
| 336 |
+
"""
|
| 337 |
+
A copy of the relevant bits of distutils/tests/test_filelist.py,
|
| 338 |
+
to ensure setuptools' version of FileList keeps parity with distutils.
|
| 339 |
+
"""
|
| 340 |
+
|
| 341 |
+
@pytest.fixture(autouse=os.getenv("SETUPTOOLS_USE_DISTUTILS") == "stdlib")
|
| 342 |
+
def _compat_record_logs(self, monkeypatch, caplog):
|
| 343 |
+
"""Account for stdlib compatibility"""
|
| 344 |
+
|
| 345 |
+
def _log(_logger, level, msg, args):
|
| 346 |
+
exc = sys.exc_info()
|
| 347 |
+
rec = logging.LogRecord("distutils", level, "", 0, msg, args, exc)
|
| 348 |
+
caplog.records.append(rec)
|
| 349 |
+
|
| 350 |
+
monkeypatch.setattr(log.Log, "_log", _log)
|
| 351 |
+
|
| 352 |
+
def get_records(self, caplog, *levels):
|
| 353 |
+
return [r for r in caplog.records if r.levelno in levels]
|
| 354 |
+
|
| 355 |
+
def assertNoWarnings(self, caplog):
|
| 356 |
+
assert self.get_records(caplog, log.WARN) == []
|
| 357 |
+
caplog.clear()
|
| 358 |
+
|
| 359 |
+
def assertWarnings(self, caplog):
|
| 360 |
+
if IS_PYPY and not caplog.records:
|
| 361 |
+
pytest.xfail("caplog checks may not work well in PyPy")
|
| 362 |
+
else:
|
| 363 |
+
assert len(self.get_records(caplog, log.WARN)) > 0
|
| 364 |
+
caplog.clear()
|
| 365 |
+
|
| 366 |
+
def make_files(self, files):
|
| 367 |
+
for file in files:
|
| 368 |
+
file = os.path.join(self.temp_dir, file)
|
| 369 |
+
dirname, _basename = os.path.split(file)
|
| 370 |
+
os.makedirs(dirname, exist_ok=True)
|
| 371 |
+
touch(file)
|
| 372 |
+
|
| 373 |
+
def test_process_template_line(self):
|
| 374 |
+
# testing all MANIFEST.in template patterns
|
| 375 |
+
file_list = FileList()
|
| 376 |
+
ml = make_local_path
|
| 377 |
+
|
| 378 |
+
# simulated file list
|
| 379 |
+
self.make_files([
|
| 380 |
+
'foo.tmp',
|
| 381 |
+
'ok',
|
| 382 |
+
'xo',
|
| 383 |
+
'four.txt',
|
| 384 |
+
'buildout.cfg',
|
| 385 |
+
# filelist does not filter out VCS directories,
|
| 386 |
+
# it's sdist that does
|
| 387 |
+
ml('.hg/last-message.txt'),
|
| 388 |
+
ml('global/one.txt'),
|
| 389 |
+
ml('global/two.txt'),
|
| 390 |
+
ml('global/files.x'),
|
| 391 |
+
ml('global/here.tmp'),
|
| 392 |
+
ml('f/o/f.oo'),
|
| 393 |
+
ml('dir/graft-one'),
|
| 394 |
+
ml('dir/dir2/graft2'),
|
| 395 |
+
ml('dir3/ok'),
|
| 396 |
+
ml('dir3/sub/ok.txt'),
|
| 397 |
+
])
|
| 398 |
+
|
| 399 |
+
MANIFEST_IN = DALS(
|
| 400 |
+
"""\
|
| 401 |
+
include ok
|
| 402 |
+
include xo
|
| 403 |
+
exclude xo
|
| 404 |
+
include foo.tmp
|
| 405 |
+
include buildout.cfg
|
| 406 |
+
global-include *.x
|
| 407 |
+
global-include *.txt
|
| 408 |
+
global-exclude *.tmp
|
| 409 |
+
recursive-include f *.oo
|
| 410 |
+
recursive-exclude global *.x
|
| 411 |
+
graft dir
|
| 412 |
+
prune dir3
|
| 413 |
+
"""
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
for line in MANIFEST_IN.split('\n'):
|
| 417 |
+
if not line:
|
| 418 |
+
continue
|
| 419 |
+
file_list.process_template_line(line)
|
| 420 |
+
|
| 421 |
+
wanted = [
|
| 422 |
+
'buildout.cfg',
|
| 423 |
+
'four.txt',
|
| 424 |
+
'ok',
|
| 425 |
+
ml('.hg/last-message.txt'),
|
| 426 |
+
ml('dir/graft-one'),
|
| 427 |
+
ml('dir/dir2/graft2'),
|
| 428 |
+
ml('f/o/f.oo'),
|
| 429 |
+
ml('global/one.txt'),
|
| 430 |
+
ml('global/two.txt'),
|
| 431 |
+
]
|
| 432 |
+
|
| 433 |
+
file_list.sort()
|
| 434 |
+
assert file_list.files == wanted
|
| 435 |
+
|
| 436 |
+
def test_exclude_pattern(self):
|
| 437 |
+
# return False if no match
|
| 438 |
+
file_list = FileList()
|
| 439 |
+
assert not file_list.exclude_pattern('*.py')
|
| 440 |
+
|
| 441 |
+
# return True if files match
|
| 442 |
+
file_list = FileList()
|
| 443 |
+
file_list.files = ['a.py', 'b.py']
|
| 444 |
+
assert file_list.exclude_pattern('*.py')
|
| 445 |
+
|
| 446 |
+
# test excludes
|
| 447 |
+
file_list = FileList()
|
| 448 |
+
file_list.files = ['a.py', 'a.txt']
|
| 449 |
+
file_list.exclude_pattern('*.py')
|
| 450 |
+
file_list.sort()
|
| 451 |
+
assert file_list.files == ['a.txt']
|
| 452 |
+
|
| 453 |
+
def test_include_pattern(self):
|
| 454 |
+
# return False if no match
|
| 455 |
+
file_list = FileList()
|
| 456 |
+
self.make_files([])
|
| 457 |
+
assert not file_list.include_pattern('*.py')
|
| 458 |
+
|
| 459 |
+
# return True if files match
|
| 460 |
+
file_list = FileList()
|
| 461 |
+
self.make_files(['a.py', 'b.txt'])
|
| 462 |
+
assert file_list.include_pattern('*.py')
|
| 463 |
+
|
| 464 |
+
# test * matches all files
|
| 465 |
+
file_list = FileList()
|
| 466 |
+
self.make_files(['a.py', 'b.txt'])
|
| 467 |
+
file_list.include_pattern('*')
|
| 468 |
+
file_list.sort()
|
| 469 |
+
assert file_list.files == ['a.py', 'b.txt']
|
| 470 |
+
|
| 471 |
+
def test_process_template_line_invalid(self):
|
| 472 |
+
# invalid lines
|
| 473 |
+
file_list = FileList()
|
| 474 |
+
for action in (
|
| 475 |
+
'include',
|
| 476 |
+
'exclude',
|
| 477 |
+
'global-include',
|
| 478 |
+
'global-exclude',
|
| 479 |
+
'recursive-include',
|
| 480 |
+
'recursive-exclude',
|
| 481 |
+
'graft',
|
| 482 |
+
'prune',
|
| 483 |
+
'blarg',
|
| 484 |
+
):
|
| 485 |
+
with pytest.raises(DistutilsTemplateError):
|
| 486 |
+
file_list.process_template_line(action)
|
| 487 |
+
|
| 488 |
+
def test_include(self, caplog):
|
| 489 |
+
caplog.set_level(logging.DEBUG)
|
| 490 |
+
ml = make_local_path
|
| 491 |
+
# include
|
| 492 |
+
file_list = FileList()
|
| 493 |
+
self.make_files(['a.py', 'b.txt', ml('d/c.py')])
|
| 494 |
+
|
| 495 |
+
file_list.process_template_line('include *.py')
|
| 496 |
+
file_list.sort()
|
| 497 |
+
assert file_list.files == ['a.py']
|
| 498 |
+
self.assertNoWarnings(caplog)
|
| 499 |
+
|
| 500 |
+
file_list.process_template_line('include *.rb')
|
| 501 |
+
file_list.sort()
|
| 502 |
+
assert file_list.files == ['a.py']
|
| 503 |
+
self.assertWarnings(caplog)
|
| 504 |
+
|
| 505 |
+
def test_exclude(self, caplog):
|
| 506 |
+
caplog.set_level(logging.DEBUG)
|
| 507 |
+
ml = make_local_path
|
| 508 |
+
# exclude
|
| 509 |
+
file_list = FileList()
|
| 510 |
+
file_list.files = ['a.py', 'b.txt', ml('d/c.py')]
|
| 511 |
+
|
| 512 |
+
file_list.process_template_line('exclude *.py')
|
| 513 |
+
file_list.sort()
|
| 514 |
+
assert file_list.files == ['b.txt', ml('d/c.py')]
|
| 515 |
+
self.assertNoWarnings(caplog)
|
| 516 |
+
|
| 517 |
+
file_list.process_template_line('exclude *.rb')
|
| 518 |
+
file_list.sort()
|
| 519 |
+
assert file_list.files == ['b.txt', ml('d/c.py')]
|
| 520 |
+
self.assertWarnings(caplog)
|
| 521 |
+
|
| 522 |
+
def test_global_include(self, caplog):
|
| 523 |
+
caplog.set_level(logging.DEBUG)
|
| 524 |
+
ml = make_local_path
|
| 525 |
+
# global-include
|
| 526 |
+
file_list = FileList()
|
| 527 |
+
self.make_files(['a.py', 'b.txt', ml('d/c.py')])
|
| 528 |
+
|
| 529 |
+
file_list.process_template_line('global-include *.py')
|
| 530 |
+
file_list.sort()
|
| 531 |
+
assert file_list.files == ['a.py', ml('d/c.py')]
|
| 532 |
+
self.assertNoWarnings(caplog)
|
| 533 |
+
|
| 534 |
+
file_list.process_template_line('global-include *.rb')
|
| 535 |
+
file_list.sort()
|
| 536 |
+
assert file_list.files == ['a.py', ml('d/c.py')]
|
| 537 |
+
self.assertWarnings(caplog)
|
| 538 |
+
|
| 539 |
+
def test_global_exclude(self, caplog):
|
| 540 |
+
caplog.set_level(logging.DEBUG)
|
| 541 |
+
ml = make_local_path
|
| 542 |
+
# global-exclude
|
| 543 |
+
file_list = FileList()
|
| 544 |
+
file_list.files = ['a.py', 'b.txt', ml('d/c.py')]
|
| 545 |
+
|
| 546 |
+
file_list.process_template_line('global-exclude *.py')
|
| 547 |
+
file_list.sort()
|
| 548 |
+
assert file_list.files == ['b.txt']
|
| 549 |
+
self.assertNoWarnings(caplog)
|
| 550 |
+
|
| 551 |
+
file_list.process_template_line('global-exclude *.rb')
|
| 552 |
+
file_list.sort()
|
| 553 |
+
assert file_list.files == ['b.txt']
|
| 554 |
+
self.assertWarnings(caplog)
|
| 555 |
+
|
| 556 |
+
def test_recursive_include(self, caplog):
|
| 557 |
+
caplog.set_level(logging.DEBUG)
|
| 558 |
+
ml = make_local_path
|
| 559 |
+
# recursive-include
|
| 560 |
+
file_list = FileList()
|
| 561 |
+
self.make_files(['a.py', ml('d/b.py'), ml('d/c.txt'), ml('d/d/e.py')])
|
| 562 |
+
|
| 563 |
+
file_list.process_template_line('recursive-include d *.py')
|
| 564 |
+
file_list.sort()
|
| 565 |
+
assert file_list.files == [ml('d/b.py'), ml('d/d/e.py')]
|
| 566 |
+
self.assertNoWarnings(caplog)
|
| 567 |
+
|
| 568 |
+
file_list.process_template_line('recursive-include e *.py')
|
| 569 |
+
file_list.sort()
|
| 570 |
+
assert file_list.files == [ml('d/b.py'), ml('d/d/e.py')]
|
| 571 |
+
self.assertWarnings(caplog)
|
| 572 |
+
|
| 573 |
+
def test_recursive_exclude(self, caplog):
|
| 574 |
+
caplog.set_level(logging.DEBUG)
|
| 575 |
+
ml = make_local_path
|
| 576 |
+
# recursive-exclude
|
| 577 |
+
file_list = FileList()
|
| 578 |
+
file_list.files = ['a.py', ml('d/b.py'), ml('d/c.txt'), ml('d/d/e.py')]
|
| 579 |
+
|
| 580 |
+
file_list.process_template_line('recursive-exclude d *.py')
|
| 581 |
+
file_list.sort()
|
| 582 |
+
assert file_list.files == ['a.py', ml('d/c.txt')]
|
| 583 |
+
self.assertNoWarnings(caplog)
|
| 584 |
+
|
| 585 |
+
file_list.process_template_line('recursive-exclude e *.py')
|
| 586 |
+
file_list.sort()
|
| 587 |
+
assert file_list.files == ['a.py', ml('d/c.txt')]
|
| 588 |
+
self.assertWarnings(caplog)
|
| 589 |
+
|
| 590 |
+
def test_graft(self, caplog):
|
| 591 |
+
caplog.set_level(logging.DEBUG)
|
| 592 |
+
ml = make_local_path
|
| 593 |
+
# graft
|
| 594 |
+
file_list = FileList()
|
| 595 |
+
self.make_files(['a.py', ml('d/b.py'), ml('d/d/e.py'), ml('f/f.py')])
|
| 596 |
+
|
| 597 |
+
file_list.process_template_line('graft d')
|
| 598 |
+
file_list.sort()
|
| 599 |
+
assert file_list.files == [ml('d/b.py'), ml('d/d/e.py')]
|
| 600 |
+
self.assertNoWarnings(caplog)
|
| 601 |
+
|
| 602 |
+
file_list.process_template_line('graft e')
|
| 603 |
+
file_list.sort()
|
| 604 |
+
assert file_list.files == [ml('d/b.py'), ml('d/d/e.py')]
|
| 605 |
+
self.assertWarnings(caplog)
|
| 606 |
+
|
| 607 |
+
def test_prune(self, caplog):
|
| 608 |
+
caplog.set_level(logging.DEBUG)
|
| 609 |
+
ml = make_local_path
|
| 610 |
+
# prune
|
| 611 |
+
file_list = FileList()
|
| 612 |
+
file_list.files = ['a.py', ml('d/b.py'), ml('d/d/e.py'), ml('f/f.py')]
|
| 613 |
+
|
| 614 |
+
file_list.process_template_line('prune d')
|
| 615 |
+
file_list.sort()
|
| 616 |
+
assert file_list.files == ['a.py', ml('f/f.py')]
|
| 617 |
+
self.assertNoWarnings(caplog)
|
| 618 |
+
|
| 619 |
+
file_list.process_template_line('prune e')
|
| 620 |
+
file_list.sort()
|
| 621 |
+
assert file_list.files == ['a.py', ml('f/f.py')]
|
| 622 |
+
self.assertWarnings(caplog)
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_setopt.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import configparser
|
| 2 |
+
|
| 3 |
+
from setuptools.command import setopt
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class TestEdit:
|
| 7 |
+
@staticmethod
|
| 8 |
+
def parse_config(filename):
|
| 9 |
+
parser = configparser.ConfigParser()
|
| 10 |
+
with open(filename, encoding='utf-8') as reader:
|
| 11 |
+
parser.read_file(reader)
|
| 12 |
+
return parser
|
| 13 |
+
|
| 14 |
+
@staticmethod
|
| 15 |
+
def write_text(file, content):
|
| 16 |
+
with open(file, 'wb') as strm:
|
| 17 |
+
strm.write(content.encode('utf-8'))
|
| 18 |
+
|
| 19 |
+
def test_utf8_encoding_retained(self, tmpdir):
|
| 20 |
+
"""
|
| 21 |
+
When editing a file, non-ASCII characters encoded in
|
| 22 |
+
UTF-8 should be retained.
|
| 23 |
+
"""
|
| 24 |
+
config = tmpdir.join('setup.cfg')
|
| 25 |
+
self.write_text(str(config), '[names]\njaraco=джарако')
|
| 26 |
+
setopt.edit_config(str(config), dict(names=dict(other='yes')))
|
| 27 |
+
parser = self.parse_config(str(config))
|
| 28 |
+
assert parser.get('names', 'jaraco') == 'джарако'
|
| 29 |
+
assert parser.get('names', 'other') == 'yes'
|
| 30 |
+
|
| 31 |
+
def test_case_retained(self, tmpdir):
|
| 32 |
+
"""
|
| 33 |
+
When editing a file, case of keys should be retained.
|
| 34 |
+
"""
|
| 35 |
+
config = tmpdir.join('setup.cfg')
|
| 36 |
+
self.write_text(str(config), '[names]\nFoO=bAr')
|
| 37 |
+
setopt.edit_config(str(config), dict(names=dict(oTher='yes')))
|
| 38 |
+
actual = config.read_text(encoding='ascii')
|
| 39 |
+
assert 'FoO' in actual
|
| 40 |
+
assert 'oTher' in actual
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_setuptools.py
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for the 'setuptools' package"""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import sys
|
| 6 |
+
from zipfile import ZipFile
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
from packaging.version import Version
|
| 10 |
+
|
| 11 |
+
import setuptools
|
| 12 |
+
import setuptools.depends as dep
|
| 13 |
+
import setuptools.dist
|
| 14 |
+
from setuptools.depends import Require
|
| 15 |
+
|
| 16 |
+
import distutils.cmd
|
| 17 |
+
import distutils.core
|
| 18 |
+
from distutils.core import Extension
|
| 19 |
+
from distutils.errors import DistutilsSetupError
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@pytest.fixture(autouse=True)
|
| 23 |
+
def isolated_dir(tmpdir_cwd):
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def makeSetup(**args):
|
| 28 |
+
"""Return distribution from 'setup(**args)', without executing commands"""
|
| 29 |
+
|
| 30 |
+
distutils.core._setup_stop_after = "commandline"
|
| 31 |
+
|
| 32 |
+
# Don't let system command line leak into tests!
|
| 33 |
+
args.setdefault('script_args', ['install'])
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
return setuptools.setup(**args)
|
| 37 |
+
finally:
|
| 38 |
+
distutils.core._setup_stop_after = None
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
needs_bytecode = pytest.mark.skipif(
|
| 42 |
+
not hasattr(dep, 'get_module_constant'),
|
| 43 |
+
reason="bytecode support not available",
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class TestDepends:
|
| 48 |
+
def testExtractConst(self):
|
| 49 |
+
if not hasattr(dep, 'extract_constant'):
|
| 50 |
+
# skip on non-bytecode platforms
|
| 51 |
+
return
|
| 52 |
+
|
| 53 |
+
def f1():
|
| 54 |
+
global x, y, z
|
| 55 |
+
x = "test"
|
| 56 |
+
y = z # pyright: ignore[reportUnboundVariable] # Explicitly testing for this runtime issue
|
| 57 |
+
|
| 58 |
+
fc = f1.__code__
|
| 59 |
+
|
| 60 |
+
# unrecognized name
|
| 61 |
+
assert dep.extract_constant(fc, 'q', -1) is None
|
| 62 |
+
|
| 63 |
+
# constant assigned
|
| 64 |
+
assert dep.extract_constant(fc, 'x', -1) == "test"
|
| 65 |
+
|
| 66 |
+
# expression assigned
|
| 67 |
+
assert dep.extract_constant(fc, 'y', -1) == -1
|
| 68 |
+
|
| 69 |
+
# recognized name, not assigned
|
| 70 |
+
assert dep.extract_constant(fc, 'z', -1) is None
|
| 71 |
+
|
| 72 |
+
def testFindModule(self):
|
| 73 |
+
with pytest.raises(ImportError):
|
| 74 |
+
dep.find_module('no-such.-thing')
|
| 75 |
+
with pytest.raises(ImportError):
|
| 76 |
+
dep.find_module('setuptools.non-existent')
|
| 77 |
+
f, _p, _i = dep.find_module('setuptools.tests')
|
| 78 |
+
f.close()
|
| 79 |
+
|
| 80 |
+
@needs_bytecode
|
| 81 |
+
def testModuleExtract(self):
|
| 82 |
+
from json import __version__
|
| 83 |
+
|
| 84 |
+
assert dep.get_module_constant('json', '__version__') == __version__
|
| 85 |
+
assert dep.get_module_constant('sys', 'version') == sys.version
|
| 86 |
+
assert (
|
| 87 |
+
dep.get_module_constant('setuptools.tests.test_setuptools', '__doc__')
|
| 88 |
+
== __doc__
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
@needs_bytecode
|
| 92 |
+
def testRequire(self):
|
| 93 |
+
req = Require('Json', '1.0.3', 'json')
|
| 94 |
+
|
| 95 |
+
assert req.name == 'Json'
|
| 96 |
+
assert req.module == 'json'
|
| 97 |
+
assert req.requested_version == Version('1.0.3')
|
| 98 |
+
assert req.attribute == '__version__'
|
| 99 |
+
assert req.full_name() == 'Json-1.0.3'
|
| 100 |
+
|
| 101 |
+
from json import __version__
|
| 102 |
+
|
| 103 |
+
assert str(req.get_version()) == __version__
|
| 104 |
+
assert req.version_ok('1.0.9')
|
| 105 |
+
assert not req.version_ok('0.9.1')
|
| 106 |
+
assert not req.version_ok('unknown')
|
| 107 |
+
|
| 108 |
+
assert req.is_present()
|
| 109 |
+
assert req.is_current()
|
| 110 |
+
|
| 111 |
+
req = Require('Do-what-I-mean', '1.0', 'd-w-i-m')
|
| 112 |
+
assert not req.is_present()
|
| 113 |
+
assert not req.is_current()
|
| 114 |
+
|
| 115 |
+
@needs_bytecode
|
| 116 |
+
def test_require_present(self):
|
| 117 |
+
# In #1896, this test was failing for months with the only
|
| 118 |
+
# complaint coming from test runners (not end users).
|
| 119 |
+
# TODO: Evaluate if this code is needed at all.
|
| 120 |
+
req = Require('Tests', None, 'tests', homepage="http://example.com")
|
| 121 |
+
assert req.format is None
|
| 122 |
+
assert req.attribute is None
|
| 123 |
+
assert req.requested_version is None
|
| 124 |
+
assert req.full_name() == 'Tests'
|
| 125 |
+
assert req.homepage == 'http://example.com'
|
| 126 |
+
|
| 127 |
+
from setuptools.tests import __path__
|
| 128 |
+
|
| 129 |
+
paths = [os.path.dirname(p) for p in __path__]
|
| 130 |
+
assert req.is_present(paths)
|
| 131 |
+
assert req.is_current(paths)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class TestDistro:
|
| 135 |
+
def setup_method(self, method):
|
| 136 |
+
self.e1 = Extension('bar.ext', ['bar.c'])
|
| 137 |
+
self.e2 = Extension('c.y', ['y.c'])
|
| 138 |
+
|
| 139 |
+
self.dist = makeSetup(
|
| 140 |
+
packages=['a', 'a.b', 'a.b.c', 'b', 'c'],
|
| 141 |
+
py_modules=['b.d', 'x'],
|
| 142 |
+
ext_modules=(self.e1, self.e2),
|
| 143 |
+
package_dir={},
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
def testDistroType(self):
|
| 147 |
+
assert isinstance(self.dist, setuptools.dist.Distribution)
|
| 148 |
+
|
| 149 |
+
def testExcludePackage(self):
|
| 150 |
+
self.dist.exclude_package('a')
|
| 151 |
+
assert self.dist.packages == ['b', 'c']
|
| 152 |
+
|
| 153 |
+
self.dist.exclude_package('b')
|
| 154 |
+
assert self.dist.packages == ['c']
|
| 155 |
+
assert self.dist.py_modules == ['x']
|
| 156 |
+
assert self.dist.ext_modules == [self.e1, self.e2]
|
| 157 |
+
|
| 158 |
+
self.dist.exclude_package('c')
|
| 159 |
+
assert self.dist.packages == []
|
| 160 |
+
assert self.dist.py_modules == ['x']
|
| 161 |
+
assert self.dist.ext_modules == [self.e1]
|
| 162 |
+
|
| 163 |
+
# test removals from unspecified options
|
| 164 |
+
makeSetup().exclude_package('x')
|
| 165 |
+
|
| 166 |
+
def testIncludeExclude(self):
|
| 167 |
+
# remove an extension
|
| 168 |
+
self.dist.exclude(ext_modules=[self.e1])
|
| 169 |
+
assert self.dist.ext_modules == [self.e2]
|
| 170 |
+
|
| 171 |
+
# add it back in
|
| 172 |
+
self.dist.include(ext_modules=[self.e1])
|
| 173 |
+
assert self.dist.ext_modules == [self.e2, self.e1]
|
| 174 |
+
|
| 175 |
+
# should not add duplicate
|
| 176 |
+
self.dist.include(ext_modules=[self.e1])
|
| 177 |
+
assert self.dist.ext_modules == [self.e2, self.e1]
|
| 178 |
+
|
| 179 |
+
def testExcludePackages(self):
|
| 180 |
+
self.dist.exclude(packages=['c', 'b', 'a'])
|
| 181 |
+
assert self.dist.packages == []
|
| 182 |
+
assert self.dist.py_modules == ['x']
|
| 183 |
+
assert self.dist.ext_modules == [self.e1]
|
| 184 |
+
|
| 185 |
+
def testEmpty(self):
|
| 186 |
+
dist = makeSetup()
|
| 187 |
+
dist.include(packages=['a'], py_modules=['b'], ext_modules=[self.e2])
|
| 188 |
+
dist = makeSetup()
|
| 189 |
+
dist.exclude(packages=['a'], py_modules=['b'], ext_modules=[self.e2])
|
| 190 |
+
|
| 191 |
+
def testContents(self):
|
| 192 |
+
assert self.dist.has_contents_for('a')
|
| 193 |
+
self.dist.exclude_package('a')
|
| 194 |
+
assert not self.dist.has_contents_for('a')
|
| 195 |
+
|
| 196 |
+
assert self.dist.has_contents_for('b')
|
| 197 |
+
self.dist.exclude_package('b')
|
| 198 |
+
assert not self.dist.has_contents_for('b')
|
| 199 |
+
|
| 200 |
+
assert self.dist.has_contents_for('c')
|
| 201 |
+
self.dist.exclude_package('c')
|
| 202 |
+
assert not self.dist.has_contents_for('c')
|
| 203 |
+
|
| 204 |
+
def testInvalidIncludeExclude(self):
|
| 205 |
+
with pytest.raises(DistutilsSetupError):
|
| 206 |
+
self.dist.include(nonexistent_option='x')
|
| 207 |
+
with pytest.raises(DistutilsSetupError):
|
| 208 |
+
self.dist.exclude(nonexistent_option='x')
|
| 209 |
+
with pytest.raises(DistutilsSetupError):
|
| 210 |
+
self.dist.include(packages={'x': 'y'})
|
| 211 |
+
with pytest.raises(DistutilsSetupError):
|
| 212 |
+
self.dist.exclude(packages={'x': 'y'})
|
| 213 |
+
with pytest.raises(DistutilsSetupError):
|
| 214 |
+
self.dist.include(ext_modules={'x': 'y'})
|
| 215 |
+
with pytest.raises(DistutilsSetupError):
|
| 216 |
+
self.dist.exclude(ext_modules={'x': 'y'})
|
| 217 |
+
|
| 218 |
+
with pytest.raises(DistutilsSetupError):
|
| 219 |
+
self.dist.include(package_dir=['q'])
|
| 220 |
+
with pytest.raises(DistutilsSetupError):
|
| 221 |
+
self.dist.exclude(package_dir=['q'])
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
@pytest.fixture
|
| 225 |
+
def example_source(tmpdir):
|
| 226 |
+
tmpdir.mkdir('foo')
|
| 227 |
+
(tmpdir / 'foo/bar.py').write('')
|
| 228 |
+
(tmpdir / 'readme.txt').write('')
|
| 229 |
+
return tmpdir
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def test_findall(example_source):
|
| 233 |
+
found = list(setuptools.findall(str(example_source)))
|
| 234 |
+
expected = ['readme.txt', 'foo/bar.py']
|
| 235 |
+
expected = [example_source.join(fn) for fn in expected]
|
| 236 |
+
assert found == expected
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def test_findall_curdir(example_source):
|
| 240 |
+
with example_source.as_cwd():
|
| 241 |
+
found = list(setuptools.findall())
|
| 242 |
+
expected = ['readme.txt', os.path.join('foo', 'bar.py')]
|
| 243 |
+
assert found == expected
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
@pytest.fixture
|
| 247 |
+
def can_symlink(tmpdir):
|
| 248 |
+
"""
|
| 249 |
+
Skip if cannot create a symbolic link
|
| 250 |
+
"""
|
| 251 |
+
link_fn = 'link'
|
| 252 |
+
target_fn = 'target'
|
| 253 |
+
try:
|
| 254 |
+
os.symlink(target_fn, link_fn)
|
| 255 |
+
except (OSError, NotImplementedError, AttributeError):
|
| 256 |
+
pytest.skip("Cannot create symbolic links")
|
| 257 |
+
os.remove(link_fn)
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
@pytest.mark.usefixtures("can_symlink")
|
| 261 |
+
def test_findall_missing_symlink(tmpdir):
|
| 262 |
+
with tmpdir.as_cwd():
|
| 263 |
+
os.symlink('foo', 'bar')
|
| 264 |
+
found = list(setuptools.findall())
|
| 265 |
+
assert found == []
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
@pytest.mark.xfail(reason="unable to exclude tests; #4475 #3260")
|
| 269 |
+
def test_its_own_wheel_does_not_contain_tests(setuptools_wheel):
|
| 270 |
+
with ZipFile(setuptools_wheel) as zipfile:
|
| 271 |
+
contents = [f.replace(os.sep, '/') for f in zipfile.namelist()]
|
| 272 |
+
|
| 273 |
+
for member in contents:
|
| 274 |
+
assert '/tests/' not in member
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def test_wheel_includes_cli_scripts(setuptools_wheel):
|
| 278 |
+
with ZipFile(setuptools_wheel) as zipfile:
|
| 279 |
+
contents = [f.replace(os.sep, '/') for f in zipfile.namelist()]
|
| 280 |
+
|
| 281 |
+
assert any('cli-64.exe' in member for member in contents)
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def test_wheel_includes_vendored_metadata(setuptools_wheel):
|
| 285 |
+
with ZipFile(setuptools_wheel) as zipfile:
|
| 286 |
+
contents = [f.replace(os.sep, '/') for f in zipfile.namelist()]
|
| 287 |
+
|
| 288 |
+
assert any(
|
| 289 |
+
re.search(r'_vendor/.*\.dist-info/METADATA', member) for member in contents
|
| 290 |
+
)
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_virtualenv.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
from urllib.error import URLError
|
| 5 |
+
from urllib.request import urlopen
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.fixture(autouse=True)
|
| 11 |
+
def pytest_virtualenv_works(venv):
|
| 12 |
+
"""
|
| 13 |
+
pytest_virtualenv may not work. if it doesn't, skip these
|
| 14 |
+
tests. See #1284.
|
| 15 |
+
"""
|
| 16 |
+
venv_prefix = venv.run(["python", "-c", "import sys; print(sys.prefix)"]).strip()
|
| 17 |
+
if venv_prefix == sys.prefix:
|
| 18 |
+
pytest.skip("virtualenv is broken (see pypa/setuptools#1284)")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_clean_env_install(venv_without_setuptools, setuptools_wheel):
|
| 22 |
+
"""
|
| 23 |
+
Check setuptools can be installed in a clean environment.
|
| 24 |
+
"""
|
| 25 |
+
cmd = ["python", "-m", "pip", "install", str(setuptools_wheel)]
|
| 26 |
+
venv_without_setuptools.run(cmd)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def access_pypi():
|
| 30 |
+
# Detect if tests are being run without connectivity
|
| 31 |
+
if not os.environ.get('NETWORK_REQUIRED', False): # pragma: nocover
|
| 32 |
+
try:
|
| 33 |
+
urlopen('https://pypi.org', timeout=1)
|
| 34 |
+
except URLError:
|
| 35 |
+
# No network, disable most of these tests
|
| 36 |
+
return False
|
| 37 |
+
|
| 38 |
+
return True
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@pytest.mark.skipif(
|
| 42 |
+
'platform.python_implementation() == "PyPy"',
|
| 43 |
+
reason="https://github.com/pypa/setuptools/pull/2865#issuecomment-965834995",
|
| 44 |
+
)
|
| 45 |
+
@pytest.mark.skipif(not access_pypi(), reason="no network")
|
| 46 |
+
# ^-- Even when it is not necessary to install a different version of `pip`
|
| 47 |
+
# the build process will still try to download `wheel`, see #3147 and #2986.
|
| 48 |
+
@pytest.mark.parametrize(
|
| 49 |
+
'pip_version',
|
| 50 |
+
[
|
| 51 |
+
None,
|
| 52 |
+
pytest.param(
|
| 53 |
+
'pip<20.1',
|
| 54 |
+
marks=pytest.mark.xfail(
|
| 55 |
+
'sys.version_info >= (3, 12)',
|
| 56 |
+
reason="pip 23.1.2 required for Python 3.12 and later",
|
| 57 |
+
),
|
| 58 |
+
),
|
| 59 |
+
pytest.param(
|
| 60 |
+
'pip<21',
|
| 61 |
+
marks=pytest.mark.xfail(
|
| 62 |
+
'sys.version_info >= (3, 12)',
|
| 63 |
+
reason="pip 23.1.2 required for Python 3.12 and later",
|
| 64 |
+
),
|
| 65 |
+
),
|
| 66 |
+
pytest.param(
|
| 67 |
+
'pip<22',
|
| 68 |
+
marks=pytest.mark.xfail(
|
| 69 |
+
'sys.version_info >= (3, 12)',
|
| 70 |
+
reason="pip 23.1.2 required for Python 3.12 and later",
|
| 71 |
+
),
|
| 72 |
+
),
|
| 73 |
+
pytest.param(
|
| 74 |
+
'pip<23',
|
| 75 |
+
marks=pytest.mark.xfail(
|
| 76 |
+
'sys.version_info >= (3, 12)',
|
| 77 |
+
reason="pip 23.1.2 required for Python 3.12 and later",
|
| 78 |
+
),
|
| 79 |
+
),
|
| 80 |
+
pytest.param(
|
| 81 |
+
'https://github.com/pypa/pip/archive/main.zip',
|
| 82 |
+
marks=pytest.mark.xfail(reason='#2975'),
|
| 83 |
+
),
|
| 84 |
+
],
|
| 85 |
+
)
|
| 86 |
+
def test_pip_upgrade_from_source(
|
| 87 |
+
pip_version, venv_without_setuptools, setuptools_wheel, setuptools_sdist
|
| 88 |
+
):
|
| 89 |
+
"""
|
| 90 |
+
Check pip can upgrade setuptools from source.
|
| 91 |
+
"""
|
| 92 |
+
# Install pip/wheel, in a venv without setuptools (as it
|
| 93 |
+
# should not be needed for bootstrapping from source)
|
| 94 |
+
venv = venv_without_setuptools
|
| 95 |
+
venv.run(["pip", "install", "-U", "wheel"])
|
| 96 |
+
if pip_version is not None:
|
| 97 |
+
venv.run(["python", "-m", "pip", "install", "-U", pip_version, "--retries=1"])
|
| 98 |
+
with pytest.raises(subprocess.CalledProcessError):
|
| 99 |
+
# Meta-test to make sure setuptools is not installed
|
| 100 |
+
venv.run(["python", "-c", "import setuptools"])
|
| 101 |
+
|
| 102 |
+
# Then install from wheel.
|
| 103 |
+
venv.run(["pip", "install", str(setuptools_wheel)])
|
| 104 |
+
# And finally try to upgrade from source.
|
| 105 |
+
venv.run(["pip", "install", "--no-cache-dir", "--upgrade", str(setuptools_sdist)])
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def test_no_missing_dependencies(bare_venv, request):
|
| 109 |
+
"""
|
| 110 |
+
Quick and dirty test to ensure all external dependencies are vendored.
|
| 111 |
+
"""
|
| 112 |
+
setuptools_dir = request.config.rootdir
|
| 113 |
+
bare_venv.run(['python', 'setup.py', '--help'], cwd=setuptools_dir)
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_warnings.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from inspect import cleandoc
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from setuptools.warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning
|
| 6 |
+
|
| 7 |
+
_EXAMPLES = {
|
| 8 |
+
"default": dict(
|
| 9 |
+
args=("Hello {x}", "\n\t{target} {v:.1f}"),
|
| 10 |
+
kwargs={"x": 5, "v": 3, "target": "World"},
|
| 11 |
+
expected="""
|
| 12 |
+
Hello 5
|
| 13 |
+
!!
|
| 14 |
+
|
| 15 |
+
********************************************************************************
|
| 16 |
+
World 3.0
|
| 17 |
+
********************************************************************************
|
| 18 |
+
|
| 19 |
+
!!
|
| 20 |
+
""",
|
| 21 |
+
),
|
| 22 |
+
"futue_due_date": dict(
|
| 23 |
+
args=("Summary", "Lorem ipsum"),
|
| 24 |
+
kwargs={"due_date": (9999, 11, 22)},
|
| 25 |
+
expected="""
|
| 26 |
+
Summary
|
| 27 |
+
!!
|
| 28 |
+
|
| 29 |
+
********************************************************************************
|
| 30 |
+
Lorem ipsum
|
| 31 |
+
|
| 32 |
+
By 9999-Nov-22, you need to update your project and remove deprecated calls
|
| 33 |
+
or your builds will no longer be supported.
|
| 34 |
+
********************************************************************************
|
| 35 |
+
|
| 36 |
+
!!
|
| 37 |
+
""",
|
| 38 |
+
),
|
| 39 |
+
"past_due_date_with_docs": dict(
|
| 40 |
+
args=("Summary", "Lorem ipsum"),
|
| 41 |
+
kwargs={"due_date": (2000, 11, 22), "see_docs": "some_page.html"},
|
| 42 |
+
expected="""
|
| 43 |
+
Summary
|
| 44 |
+
!!
|
| 45 |
+
|
| 46 |
+
********************************************************************************
|
| 47 |
+
Lorem ipsum
|
| 48 |
+
|
| 49 |
+
This deprecation is overdue, please update your project and remove deprecated
|
| 50 |
+
calls to avoid build errors in the future.
|
| 51 |
+
|
| 52 |
+
See https://setuptools.pypa.io/en/latest/some_page.html for details.
|
| 53 |
+
********************************************************************************
|
| 54 |
+
|
| 55 |
+
!!
|
| 56 |
+
""",
|
| 57 |
+
),
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@pytest.mark.parametrize("example_name", _EXAMPLES.keys())
|
| 62 |
+
def test_formatting(monkeypatch, example_name):
|
| 63 |
+
"""
|
| 64 |
+
It should automatically handle indentation, interpolation and things like due date.
|
| 65 |
+
"""
|
| 66 |
+
args = _EXAMPLES[example_name]["args"]
|
| 67 |
+
kwargs = _EXAMPLES[example_name]["kwargs"]
|
| 68 |
+
expected = _EXAMPLES[example_name]["expected"]
|
| 69 |
+
|
| 70 |
+
monkeypatch.setenv("SETUPTOOLS_ENFORCE_DEPRECATION", "false")
|
| 71 |
+
with pytest.warns(SetuptoolsWarning) as warn_info:
|
| 72 |
+
SetuptoolsWarning.emit(*args, **kwargs)
|
| 73 |
+
assert _get_message(warn_info) == cleandoc(expected)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def test_due_date_enforcement(monkeypatch):
|
| 77 |
+
class _MyDeprecation(SetuptoolsDeprecationWarning):
|
| 78 |
+
_SUMMARY = "Summary"
|
| 79 |
+
_DETAILS = "Lorem ipsum"
|
| 80 |
+
_DUE_DATE = (2000, 11, 22)
|
| 81 |
+
_SEE_DOCS = "some_page.html"
|
| 82 |
+
|
| 83 |
+
monkeypatch.setenv("SETUPTOOLS_ENFORCE_DEPRECATION", "true")
|
| 84 |
+
with pytest.raises(SetuptoolsDeprecationWarning) as exc_info:
|
| 85 |
+
_MyDeprecation.emit()
|
| 86 |
+
|
| 87 |
+
expected = """
|
| 88 |
+
Summary
|
| 89 |
+
!!
|
| 90 |
+
|
| 91 |
+
********************************************************************************
|
| 92 |
+
Lorem ipsum
|
| 93 |
+
|
| 94 |
+
This deprecation is overdue, please update your project and remove deprecated
|
| 95 |
+
calls to avoid build errors in the future.
|
| 96 |
+
|
| 97 |
+
See https://setuptools.pypa.io/en/latest/some_page.html for details.
|
| 98 |
+
********************************************************************************
|
| 99 |
+
|
| 100 |
+
!!
|
| 101 |
+
"""
|
| 102 |
+
assert str(exc_info.value) == cleandoc(expected)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def _get_message(warn_info):
|
| 106 |
+
return next(warn.message.args[0] for warn in warn_info)
|
videollama2/lib/python3.10/site-packages/setuptools/tests/test_windows_wrappers.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Python Script Wrapper for Windows
|
| 3 |
+
=================================
|
| 4 |
+
|
| 5 |
+
setuptools includes wrappers for Python scripts that allows them to be
|
| 6 |
+
executed like regular windows programs. There are 2 wrappers, one
|
| 7 |
+
for command-line programs, cli.exe, and one for graphical programs,
|
| 8 |
+
gui.exe. These programs are almost identical, function pretty much
|
| 9 |
+
the same way, and are generated from the same source file. The
|
| 10 |
+
wrapper programs are used by copying them to the directory containing
|
| 11 |
+
the script they are to wrap and with the same name as the script they
|
| 12 |
+
are to wrap.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import pathlib
|
| 16 |
+
import platform
|
| 17 |
+
import subprocess
|
| 18 |
+
import sys
|
| 19 |
+
import textwrap
|
| 20 |
+
|
| 21 |
+
import pytest
|
| 22 |
+
|
| 23 |
+
import pkg_resources
|
| 24 |
+
from setuptools.command.easy_install import nt_quote_arg
|
| 25 |
+
|
| 26 |
+
pytestmark = pytest.mark.skipif(sys.platform != 'win32', reason="Windows only")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class WrapperTester:
|
| 30 |
+
@classmethod
|
| 31 |
+
def prep_script(cls, template):
|
| 32 |
+
python_exe = nt_quote_arg(sys.executable)
|
| 33 |
+
return template % locals()
|
| 34 |
+
|
| 35 |
+
@classmethod
|
| 36 |
+
def create_script(cls, tmpdir):
|
| 37 |
+
"""
|
| 38 |
+
Create a simple script, foo-script.py
|
| 39 |
+
|
| 40 |
+
Note that the script starts with a Unix-style '#!' line saying which
|
| 41 |
+
Python executable to run. The wrapper will use this line to find the
|
| 42 |
+
correct Python executable.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
script = cls.prep_script(cls.script_tmpl)
|
| 46 |
+
|
| 47 |
+
with (tmpdir / cls.script_name).open('w') as f:
|
| 48 |
+
f.write(script)
|
| 49 |
+
|
| 50 |
+
# also copy cli.exe to the sample directory
|
| 51 |
+
with (tmpdir / cls.wrapper_name).open('wb') as f:
|
| 52 |
+
w = pkg_resources.resource_string('setuptools', cls.wrapper_source)
|
| 53 |
+
f.write(w)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def win_launcher_exe(prefix):
|
| 57 |
+
"""A simple routine to select launcher script based on platform."""
|
| 58 |
+
assert prefix in ('cli', 'gui')
|
| 59 |
+
if platform.machine() == "ARM64":
|
| 60 |
+
return f"{prefix}-arm64.exe"
|
| 61 |
+
else:
|
| 62 |
+
return f"{prefix}-32.exe"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class TestCLI(WrapperTester):
|
| 66 |
+
script_name = 'foo-script.py'
|
| 67 |
+
wrapper_name = 'foo.exe'
|
| 68 |
+
wrapper_source = win_launcher_exe('cli')
|
| 69 |
+
|
| 70 |
+
script_tmpl = textwrap.dedent(
|
| 71 |
+
"""
|
| 72 |
+
#!%(python_exe)s
|
| 73 |
+
import sys
|
| 74 |
+
input = repr(sys.stdin.read())
|
| 75 |
+
print(sys.argv[0][-14:])
|
| 76 |
+
print(sys.argv[1:])
|
| 77 |
+
print(input)
|
| 78 |
+
if __debug__:
|
| 79 |
+
print('non-optimized')
|
| 80 |
+
"""
|
| 81 |
+
).lstrip()
|
| 82 |
+
|
| 83 |
+
def test_basic(self, tmpdir):
|
| 84 |
+
"""
|
| 85 |
+
When the copy of cli.exe, foo.exe in this example, runs, it examines
|
| 86 |
+
the path name it was run with and computes a Python script path name
|
| 87 |
+
by removing the '.exe' suffix and adding the '-script.py' suffix. (For
|
| 88 |
+
GUI programs, the suffix '-script.pyw' is added.) This is why we
|
| 89 |
+
named out script the way we did. Now we can run out script by running
|
| 90 |
+
the wrapper:
|
| 91 |
+
|
| 92 |
+
This example was a little pathological in that it exercised windows
|
| 93 |
+
(MS C runtime) quoting rules:
|
| 94 |
+
|
| 95 |
+
- Strings containing spaces are surrounded by double quotes.
|
| 96 |
+
|
| 97 |
+
- Double quotes in strings need to be escaped by preceding them with
|
| 98 |
+
back slashes.
|
| 99 |
+
|
| 100 |
+
- One or more backslashes preceding double quotes need to be escaped
|
| 101 |
+
by preceding each of them with back slashes.
|
| 102 |
+
"""
|
| 103 |
+
self.create_script(tmpdir)
|
| 104 |
+
cmd = [
|
| 105 |
+
str(tmpdir / 'foo.exe'),
|
| 106 |
+
'arg1',
|
| 107 |
+
'arg 2',
|
| 108 |
+
'arg "2\\"',
|
| 109 |
+
'arg 4\\',
|
| 110 |
+
'arg5 a\\\\b',
|
| 111 |
+
]
|
| 112 |
+
proc = subprocess.Popen(
|
| 113 |
+
cmd,
|
| 114 |
+
stdout=subprocess.PIPE,
|
| 115 |
+
stdin=subprocess.PIPE,
|
| 116 |
+
text=True,
|
| 117 |
+
encoding="utf-8",
|
| 118 |
+
)
|
| 119 |
+
stdout, _stderr = proc.communicate('hello\nworld\n')
|
| 120 |
+
actual = stdout.replace('\r\n', '\n')
|
| 121 |
+
expected = textwrap.dedent(
|
| 122 |
+
r"""
|
| 123 |
+
\foo-script.py
|
| 124 |
+
['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
|
| 125 |
+
'hello\nworld\n'
|
| 126 |
+
non-optimized
|
| 127 |
+
"""
|
| 128 |
+
).lstrip()
|
| 129 |
+
assert actual == expected
|
| 130 |
+
|
| 131 |
+
def test_symlink(self, tmpdir):
|
| 132 |
+
"""
|
| 133 |
+
Ensure that symlink for the foo.exe is working correctly.
|
| 134 |
+
"""
|
| 135 |
+
script_dir = tmpdir / "script_dir"
|
| 136 |
+
script_dir.mkdir()
|
| 137 |
+
self.create_script(script_dir)
|
| 138 |
+
symlink = pathlib.Path(tmpdir / "foo.exe")
|
| 139 |
+
symlink.symlink_to(script_dir / "foo.exe")
|
| 140 |
+
|
| 141 |
+
cmd = [
|
| 142 |
+
str(tmpdir / 'foo.exe'),
|
| 143 |
+
'arg1',
|
| 144 |
+
'arg 2',
|
| 145 |
+
'arg "2\\"',
|
| 146 |
+
'arg 4\\',
|
| 147 |
+
'arg5 a\\\\b',
|
| 148 |
+
]
|
| 149 |
+
proc = subprocess.Popen(
|
| 150 |
+
cmd,
|
| 151 |
+
stdout=subprocess.PIPE,
|
| 152 |
+
stdin=subprocess.PIPE,
|
| 153 |
+
text=True,
|
| 154 |
+
encoding="utf-8",
|
| 155 |
+
)
|
| 156 |
+
stdout, _stderr = proc.communicate('hello\nworld\n')
|
| 157 |
+
actual = stdout.replace('\r\n', '\n')
|
| 158 |
+
expected = textwrap.dedent(
|
| 159 |
+
r"""
|
| 160 |
+
\foo-script.py
|
| 161 |
+
['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
|
| 162 |
+
'hello\nworld\n'
|
| 163 |
+
non-optimized
|
| 164 |
+
"""
|
| 165 |
+
).lstrip()
|
| 166 |
+
assert actual == expected
|
| 167 |
+
|
| 168 |
+
def test_with_options(self, tmpdir):
|
| 169 |
+
"""
|
| 170 |
+
Specifying Python Command-line Options
|
| 171 |
+
--------------------------------------
|
| 172 |
+
|
| 173 |
+
You can specify a single argument on the '#!' line. This can be used
|
| 174 |
+
to specify Python options like -O, to run in optimized mode or -i
|
| 175 |
+
to start the interactive interpreter. You can combine multiple
|
| 176 |
+
options as usual. For example, to run in optimized mode and
|
| 177 |
+
enter the interpreter after running the script, you could use -Oi:
|
| 178 |
+
"""
|
| 179 |
+
self.create_script(tmpdir)
|
| 180 |
+
tmpl = textwrap.dedent(
|
| 181 |
+
"""
|
| 182 |
+
#!%(python_exe)s -Oi
|
| 183 |
+
import sys
|
| 184 |
+
input = repr(sys.stdin.read())
|
| 185 |
+
print(sys.argv[0][-14:])
|
| 186 |
+
print(sys.argv[1:])
|
| 187 |
+
print(input)
|
| 188 |
+
if __debug__:
|
| 189 |
+
print('non-optimized')
|
| 190 |
+
sys.ps1 = '---'
|
| 191 |
+
"""
|
| 192 |
+
).lstrip()
|
| 193 |
+
with (tmpdir / 'foo-script.py').open('w') as f:
|
| 194 |
+
f.write(self.prep_script(tmpl))
|
| 195 |
+
cmd = [str(tmpdir / 'foo.exe')]
|
| 196 |
+
proc = subprocess.Popen(
|
| 197 |
+
cmd,
|
| 198 |
+
stdout=subprocess.PIPE,
|
| 199 |
+
stdin=subprocess.PIPE,
|
| 200 |
+
stderr=subprocess.STDOUT,
|
| 201 |
+
text=True,
|
| 202 |
+
encoding="utf-8",
|
| 203 |
+
)
|
| 204 |
+
stdout, _stderr = proc.communicate()
|
| 205 |
+
actual = stdout.replace('\r\n', '\n')
|
| 206 |
+
expected = textwrap.dedent(
|
| 207 |
+
r"""
|
| 208 |
+
\foo-script.py
|
| 209 |
+
[]
|
| 210 |
+
''
|
| 211 |
+
---
|
| 212 |
+
"""
|
| 213 |
+
).lstrip()
|
| 214 |
+
assert actual == expected
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class TestGUI(WrapperTester):
|
| 218 |
+
"""
|
| 219 |
+
Testing the GUI Version
|
| 220 |
+
-----------------------
|
| 221 |
+
"""
|
| 222 |
+
|
| 223 |
+
script_name = 'bar-script.pyw'
|
| 224 |
+
wrapper_source = win_launcher_exe('gui')
|
| 225 |
+
wrapper_name = 'bar.exe'
|
| 226 |
+
|
| 227 |
+
script_tmpl = textwrap.dedent(
|
| 228 |
+
"""
|
| 229 |
+
#!%(python_exe)s
|
| 230 |
+
import sys
|
| 231 |
+
f = open(sys.argv[1], 'wb')
|
| 232 |
+
bytes_written = f.write(repr(sys.argv[2]).encode('utf-8'))
|
| 233 |
+
f.close()
|
| 234 |
+
"""
|
| 235 |
+
).strip()
|
| 236 |
+
|
| 237 |
+
def test_basic(self, tmpdir):
|
| 238 |
+
"""Test the GUI version with the simple script, bar-script.py"""
|
| 239 |
+
self.create_script(tmpdir)
|
| 240 |
+
|
| 241 |
+
cmd = [
|
| 242 |
+
str(tmpdir / 'bar.exe'),
|
| 243 |
+
str(tmpdir / 'test_output.txt'),
|
| 244 |
+
'Test Argument',
|
| 245 |
+
]
|
| 246 |
+
proc = subprocess.Popen(
|
| 247 |
+
cmd,
|
| 248 |
+
stdout=subprocess.PIPE,
|
| 249 |
+
stdin=subprocess.PIPE,
|
| 250 |
+
stderr=subprocess.STDOUT,
|
| 251 |
+
text=True,
|
| 252 |
+
encoding="utf-8",
|
| 253 |
+
)
|
| 254 |
+
stdout, stderr = proc.communicate()
|
| 255 |
+
assert not stdout
|
| 256 |
+
assert not stderr
|
| 257 |
+
with (tmpdir / 'test_output.txt').open('rb') as f_out:
|
| 258 |
+
actual = f_out.read().decode('ascii')
|
| 259 |
+
assert actual == repr('Test Argument')
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/Export.h>
|
| 4 |
+
#include <cstdint>
|
| 5 |
+
|
| 6 |
+
namespace torch {
|
| 7 |
+
namespace distributed {
|
| 8 |
+
namespace autograd {
|
| 9 |
+
|
| 10 |
+
// This structure represents autograd metadata that we need to pass across
|
| 11 |
+
// different nodes when we call an RPC which needs autograd computation.
|
| 12 |
+
struct TORCH_API AutogradMetadata {
|
| 13 |
+
AutogradMetadata(int64_t autogradContextId, int64_t autogradMessageId);
|
| 14 |
+
|
| 15 |
+
// autogradContextId_ is a globally unique integer that identifies a
|
| 16 |
+
// particular distributed autograd pass.
|
| 17 |
+
int64_t autogradContextId;
|
| 18 |
+
// autogradMessageId_ is a globally unique integer that identifies a pair
|
| 19 |
+
// of send/recv autograd functions.
|
| 20 |
+
int64_t autogradMessageId;
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
} // namespace autograd
|
| 24 |
+
} // namespace distributed
|
| 25 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_req.h
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/message.h>
|
| 5 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 6 |
+
|
| 7 |
+
namespace torch {
|
| 8 |
+
namespace distributed {
|
| 9 |
+
namespace autograd {
|
| 10 |
+
|
| 11 |
+
// Used to request other workers to clean up their autograd context.
|
| 12 |
+
class TORCH_API CleanupAutogradContextReq : public rpc::RpcCommandBase {
|
| 13 |
+
public:
|
| 14 |
+
explicit CleanupAutogradContextReq(int64_t context_id);
|
| 15 |
+
// Serialization and deserialization methods.
|
| 16 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 17 |
+
static std::unique_ptr<CleanupAutogradContextReq> fromMessage(
|
| 18 |
+
const rpc::Message& message);
|
| 19 |
+
|
| 20 |
+
// Retrieve the context id we are cleaning up with this message.
|
| 21 |
+
int64_t getContextId();
|
| 22 |
+
|
| 23 |
+
private:
|
| 24 |
+
int64_t context_id_;
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
} // namespace autograd
|
| 28 |
+
} // namespace distributed
|
| 29 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_resp.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/distributed/rpc/message.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 5 |
+
|
| 6 |
+
namespace torch {
|
| 7 |
+
namespace distributed {
|
| 8 |
+
namespace autograd {
|
| 9 |
+
|
| 10 |
+
// Empty response for CleanupAutogradContextReq. Send to acknowledge receipt of
|
| 11 |
+
// a CleanupAutogradContextReq.
|
| 12 |
+
class TORCH_API CleanupAutogradContextResp : public rpc::RpcCommandBase {
|
| 13 |
+
public:
|
| 14 |
+
CleanupAutogradContextResp() = default;
|
| 15 |
+
// Serialization and deserialization methods.
|
| 16 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 17 |
+
static std::unique_ptr<CleanupAutogradContextResp> fromMessage(
|
| 18 |
+
const rpc::Message& message);
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
} // namespace autograd
|
| 22 |
+
} // namespace distributed
|
| 23 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_req.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/message.h>
|
| 5 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
namespace torch {
|
| 9 |
+
namespace distributed {
|
| 10 |
+
namespace autograd {
|
| 11 |
+
|
| 12 |
+
// Used to propagate gradients from one node to another during a distributed
|
| 13 |
+
// backwards pass. This RPC call is invoked when we hit a `recv` autograd
|
| 14 |
+
// function during backward pass execution.
|
| 15 |
+
class TORCH_API PropagateGradientsReq : public rpc::RpcCommandBase {
|
| 16 |
+
public:
|
| 17 |
+
PropagateGradientsReq(
|
| 18 |
+
const AutogradMetadata& autogradMetadata,
|
| 19 |
+
std::vector<torch::autograd::Variable> grads,
|
| 20 |
+
bool retainGraph = false);
|
| 21 |
+
|
| 22 |
+
const AutogradMetadata& getAutogradMetadata();
|
| 23 |
+
|
| 24 |
+
const std::vector<torch::autograd::Variable>& getGrads();
|
| 25 |
+
|
| 26 |
+
// Serialization and deserialization methods.
|
| 27 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 28 |
+
static std::unique_ptr<PropagateGradientsReq> fromMessage(
|
| 29 |
+
const rpc::Message& message);
|
| 30 |
+
|
| 31 |
+
// Whether or not to retain the autograd graph.
|
| 32 |
+
bool retainGraph();
|
| 33 |
+
|
| 34 |
+
private:
|
| 35 |
+
AutogradMetadata autogradMetadata_;
|
| 36 |
+
std::vector<torch::autograd::Variable> grads_;
|
| 37 |
+
bool retainGraph_;
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
} // namespace autograd
|
| 41 |
+
} // namespace distributed
|
| 42 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_resp.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/distributed/rpc/message.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 5 |
+
|
| 6 |
+
namespace torch {
|
| 7 |
+
namespace distributed {
|
| 8 |
+
namespace autograd {
|
| 9 |
+
|
| 10 |
+
// Response for the PropagateGradients call. Currently, this class is mostly
|
| 11 |
+
// just a placeholder and sends an empty message over the wire. The purpose of
|
| 12 |
+
// this RPC command is to indicate whether or not the PropagateGradientsReq call
|
| 13 |
+
// was successfully or not.
|
| 14 |
+
class TORCH_API PropagateGradientsResp : public rpc::RpcCommandBase {
|
| 15 |
+
public:
|
| 16 |
+
PropagateGradientsResp() = default;
|
| 17 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 18 |
+
static std::unique_ptr<PropagateGradientsResp> fromMessage(
|
| 19 |
+
const rpc::Message& message);
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
} // namespace autograd
|
| 23 |
+
} // namespace distributed
|
| 24 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_autograd.h
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/rpc_agent.h>
|
| 5 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 6 |
+
|
| 7 |
+
namespace torch {
|
| 8 |
+
namespace distributed {
|
| 9 |
+
namespace autograd {
|
| 10 |
+
|
| 11 |
+
// Represents an RPC that includes autograd information. This class basically
|
| 12 |
+
// wraps another `RpcCommandBase` object which represents the actual RPC and has
|
| 13 |
+
// additional autograd information associated with that RPC.
|
| 14 |
+
class TORCH_API RpcWithAutograd final : public rpc::RpcCommandBase {
|
| 15 |
+
public:
|
| 16 |
+
// Used when we are sending an RPC over the wire.
|
| 17 |
+
RpcWithAutograd(
|
| 18 |
+
rpc::worker_id_t fromWorkerId,
|
| 19 |
+
rpc::MessageType messageType,
|
| 20 |
+
const AutogradMetadata& autogradMetadata,
|
| 21 |
+
c10::intrusive_ptr<rpc::Message> wrappedMessage,
|
| 22 |
+
rpc::DeviceMap deviceMap = {});
|
| 23 |
+
|
| 24 |
+
// Used when receiving an RPC over the wire.
|
| 25 |
+
RpcWithAutograd(
|
| 26 |
+
rpc::worker_id_t fromWorkerId,
|
| 27 |
+
rpc::MessageType messageType,
|
| 28 |
+
const AutogradMetadata& autogradMetadata,
|
| 29 |
+
std::unique_ptr<rpc::RpcCommandBase> wrappedRpc,
|
| 30 |
+
rpc::MessageType wrappedMessageType,
|
| 31 |
+
std::vector<torch::Tensor> tensors,
|
| 32 |
+
rpc::DeviceMap deviceMap = {});
|
| 33 |
+
|
| 34 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 35 |
+
|
| 36 |
+
static std::unique_ptr<RpcWithAutograd> fromMessage(
|
| 37 |
+
const rpc::Message& message);
|
| 38 |
+
|
| 39 |
+
// Retrieves tensors as part of this RPC, which need to be considered for
|
| 40 |
+
// autograd computations.
|
| 41 |
+
std::vector<torch::Tensor>& tensors();
|
| 42 |
+
|
| 43 |
+
const AutogradMetadata& autogradMetadata() const;
|
| 44 |
+
|
| 45 |
+
RpcCommandBase& wrappedRpc();
|
| 46 |
+
|
| 47 |
+
void setWrappedRpc(std::unique_ptr<RpcCommandBase> wrappedRpc);
|
| 48 |
+
|
| 49 |
+
std::unique_ptr<RpcCommandBase> moveWrappedRpc() &&;
|
| 50 |
+
|
| 51 |
+
// Message type of the wrapped RPC.
|
| 52 |
+
rpc::MessageType wrappedMessageType() const;
|
| 53 |
+
|
| 54 |
+
// Retrieve the worker id from which the RPC originated.
|
| 55 |
+
rpc::worker_id_t fromWorkerId() const;
|
| 56 |
+
|
| 57 |
+
// Retrieve the device map.
|
| 58 |
+
const rpc::DeviceMap& deviceMap();
|
| 59 |
+
|
| 60 |
+
private:
|
| 61 |
+
// WorkerId from which this RPC originated. This is necessary for knowing
|
| 62 |
+
// which worker we need to contact during the backward pass.
|
| 63 |
+
rpc::worker_id_t fromWorkerId_;
|
| 64 |
+
|
| 65 |
+
// Message type for this call.
|
| 66 |
+
rpc::MessageType messageType_;
|
| 67 |
+
|
| 68 |
+
AutogradMetadata autogradMetadata_;
|
| 69 |
+
|
| 70 |
+
// Since wrappedMessage_ is destructively constructed from wrappedRpc_,
|
| 71 |
+
// they are valid exclusively. They are used for different purpose.
|
| 72 |
+
// wrappedRpc_ is used while constructing receive rpcWithAutograd;
|
| 73 |
+
// wrappedMessage_ is used while constructing send rpcWithAutograd;
|
| 74 |
+
|
| 75 |
+
// When receive rpcWithAutograd is constructed fromMessage, it is valid;
|
| 76 |
+
// When send rpcWithAutograd is constructed before toMessage, it is nullptr;
|
| 77 |
+
std::unique_ptr<RpcCommandBase> wrappedRpc_;
|
| 78 |
+
|
| 79 |
+
// Serialized message representing wrappedRpc_. Used mostly as a cache to
|
| 80 |
+
// avoid serializing the request twice.
|
| 81 |
+
// When receive rpcWithAutograd is constructed fromMessage, it is nullptr;
|
| 82 |
+
// When send rpcWithAutograd is constructed before toMessage, it is valid;
|
| 83 |
+
c10::intrusive_ptr<rpc::Message> wrappedMessage_;
|
| 84 |
+
|
| 85 |
+
// message type of the wrappedMessage, this is stored separately since
|
| 86 |
+
// wrappedMessage_ is not always guaranteed to be populated.
|
| 87 |
+
rpc::MessageType wrappedMessageType_;
|
| 88 |
+
|
| 89 |
+
// Tensors part of the wrappedRpc that need to be considered for autograd.
|
| 90 |
+
std::vector<torch::Tensor> tensors_;
|
| 91 |
+
|
| 92 |
+
// Device mapping for tensors that are sent across an RPC to another node.
|
| 93 |
+
rpc::DeviceMap deviceMap_;
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
} // namespace autograd
|
| 97 |
+
} // namespace distributed
|
| 98 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_req.h
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/autograd/profiler.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/message.h>
|
| 5 |
+
#include <torch/csrc/distributed/rpc/rpc_agent.h>
|
| 6 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 7 |
+
#include <torch/csrc/distributed/rpc/types.h>
|
| 8 |
+
|
| 9 |
+
namespace torch {
|
| 10 |
+
namespace distributed {
|
| 11 |
+
namespace autograd {
|
| 12 |
+
|
| 13 |
+
class TORCH_API RpcWithProfilingReq : public rpc::RpcCommandBase {
|
| 14 |
+
public:
|
| 15 |
+
// For sending RPCs, invoked when client is creating this RPC command.
|
| 16 |
+
RpcWithProfilingReq(
|
| 17 |
+
rpc::MessageType messageType,
|
| 18 |
+
c10::intrusive_ptr<rpc::Message> wrappedMessage,
|
| 19 |
+
torch::autograd::profiler::ProfilerConfig&& profilerConfig,
|
| 20 |
+
rpc::ProfilingId profilingKeyId);
|
| 21 |
+
|
| 22 |
+
// For receiving an RPC
|
| 23 |
+
// Used in fromMessage.
|
| 24 |
+
RpcWithProfilingReq(
|
| 25 |
+
rpc::MessageType messageType,
|
| 26 |
+
std::unique_ptr<rpc::RpcCommandBase> wrappedRpc,
|
| 27 |
+
rpc::MessageType wrappedMessageType,
|
| 28 |
+
std::vector<torch::Tensor> tensors,
|
| 29 |
+
torch::autograd::profiler::ProfilerConfig&& profilerConfig,
|
| 30 |
+
rpc::ProfilingId profilingKeyId);
|
| 31 |
+
|
| 32 |
+
// Convert this RPC Command to a Message that can be sent over the wire.
|
| 33 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 34 |
+
static std::unique_ptr<RpcWithProfilingReq> fromMessage(
|
| 35 |
+
const rpc::Message& message);
|
| 36 |
+
|
| 37 |
+
// Retrieve the profiling data that is associated with this command.
|
| 38 |
+
torch::autograd::profiler::ProfilerConfig getProfilingConfig() const;
|
| 39 |
+
// Retrieve the globally unique profiling ID corresponding to this command.
|
| 40 |
+
const rpc::ProfilingId& getProfilingId() const;
|
| 41 |
+
// Retrieve the original RPC which this ProfilingRPC wraps.
|
| 42 |
+
RpcCommandBase& wrappedRpc();
|
| 43 |
+
// Destructively move the wrapped RPC.
|
| 44 |
+
std::unique_ptr<RpcCommandBase> moveWrappedRpc() &&;
|
| 45 |
+
// Message type of the wrapped RPC
|
| 46 |
+
rpc::MessageType wrappedMessageType() const;
|
| 47 |
+
void setWrappedRpc(std::unique_ptr<RpcCommandBase> wrappedRpc);
|
| 48 |
+
|
| 49 |
+
private:
|
| 50 |
+
// message type
|
| 51 |
+
const rpc::MessageType messageType_;
|
| 52 |
+
// wrapped message
|
| 53 |
+
c10::intrusive_ptr<rpc::Message> wrappedMessage_;
|
| 54 |
+
std::unique_ptr<RpcCommandBase> wrappedRpc_;
|
| 55 |
+
rpc::MessageType wrappedMessageType_;
|
| 56 |
+
std::vector<torch::Tensor> tensors_;
|
| 57 |
+
const torch::autograd::profiler::ProfilerConfig profilerConfig_;
|
| 58 |
+
const rpc::ProfilingId profilingKeyId_;
|
| 59 |
+
};
|
| 60 |
+
} // namespace autograd
|
| 61 |
+
} // namespace distributed
|
| 62 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_resp.h
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/autograd/profiler.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/message.h>
|
| 5 |
+
#include <torch/csrc/distributed/rpc/rpc_agent.h>
|
| 6 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 7 |
+
#include <torch/csrc/distributed/rpc/types.h>
|
| 8 |
+
|
| 9 |
+
namespace torch {
|
| 10 |
+
namespace distributed {
|
| 11 |
+
namespace autograd {
|
| 12 |
+
class TORCH_API RpcWithProfilingResp : public rpc::RpcCommandBase {
|
| 13 |
+
public:
|
| 14 |
+
// For sending RPCs over the wire
|
| 15 |
+
RpcWithProfilingResp(
|
| 16 |
+
rpc::MessageType messageType,
|
| 17 |
+
c10::intrusive_ptr<rpc::Message> wrappedMessage,
|
| 18 |
+
std::vector<torch::autograd::profiler::LegacyEvent> profiledEvents,
|
| 19 |
+
rpc::ProfilingId profilingId);
|
| 20 |
+
|
| 21 |
+
// For receiving RPCs. Used in from message when converting a message received
|
| 22 |
+
// over the wire.
|
| 23 |
+
RpcWithProfilingResp(
|
| 24 |
+
rpc::MessageType messageType,
|
| 25 |
+
std::unique_ptr<rpc::RpcCommandBase> wrappedRpc,
|
| 26 |
+
rpc::MessageType wrappedMessageType,
|
| 27 |
+
std::vector<torch::Tensor> tensors,
|
| 28 |
+
std::vector<torch::autograd::profiler::LegacyEvent> profiledEvents,
|
| 29 |
+
rpc::ProfilingId profilingId);
|
| 30 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 31 |
+
static std::unique_ptr<RpcWithProfilingResp> fromMessage(
|
| 32 |
+
const rpc::Message& message);
|
| 33 |
+
// Retrieve remote Events
|
| 34 |
+
std::vector<torch::autograd::profiler::LegacyEvent> getProfiledEvents() const;
|
| 35 |
+
// Retrieve the globally unique profiling ID corresponding to this command.
|
| 36 |
+
const rpc::ProfilingId& getProfilingId() const;
|
| 37 |
+
// Retrieve the original RPC which this ProfilingRPC wraps.
|
| 38 |
+
RpcCommandBase& wrappedRpc();
|
| 39 |
+
// Destructively move the wrapped RPC.
|
| 40 |
+
std::unique_ptr<RpcCommandBase> moveWrappedRpc() &&;
|
| 41 |
+
// Message type of the wrapped RPC
|
| 42 |
+
rpc::MessageType wrappedMessageType() const;
|
| 43 |
+
// Set the wrapped RPC for this RPC.
|
| 44 |
+
void setWrappedRpc(std::unique_ptr<RpcCommandBase> wrappedRpc);
|
| 45 |
+
|
| 46 |
+
private:
|
| 47 |
+
// message type
|
| 48 |
+
const rpc::MessageType messageType_;
|
| 49 |
+
// wrapped message
|
| 50 |
+
c10::intrusive_ptr<rpc::Message> wrappedMessage_;
|
| 51 |
+
std::unique_ptr<RpcCommandBase> wrappedRpc_;
|
| 52 |
+
rpc::MessageType wrappedMessageType_;
|
| 53 |
+
std::vector<torch::Tensor> tensors_;
|
| 54 |
+
const std::vector<torch::autograd::profiler::LegacyEvent> profiledEvents_;
|
| 55 |
+
const rpc::ProfilingId profilingId_;
|
| 56 |
+
};
|
| 57 |
+
} // namespace autograd
|
| 58 |
+
} // namespace distributed
|
| 59 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rref_backward_resp.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/distributed/rpc/message.h>
|
| 4 |
+
#include <torch/csrc/distributed/rpc/rpc_command_base.h>
|
| 5 |
+
|
| 6 |
+
namespace torch {
|
| 7 |
+
namespace distributed {
|
| 8 |
+
namespace autograd {
|
| 9 |
+
|
| 10 |
+
// Response for the RRefBackwardReq.
|
| 11 |
+
class TORCH_API RRefBackwardResp : public rpc::RpcCommandBase {
|
| 12 |
+
public:
|
| 13 |
+
RRefBackwardResp() = default;
|
| 14 |
+
c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
|
| 15 |
+
static std::unique_ptr<RRefBackwardResp> fromMessage(
|
| 16 |
+
const rpc::Message& message);
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
} // namespace autograd
|
| 20 |
+
} // namespace distributed
|
| 21 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/CUDASymmetricMemory-inl.h
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) && CUDART_VERSION >= 12010
|
| 4 |
+
#define NVCC_SUPPORTS_MULTICAST 1
|
| 5 |
+
#endif
|
| 6 |
+
|
| 7 |
+
#include <ATen/ATen.h>
|
| 8 |
+
|
| 9 |
+
namespace c10d::symmetric_memory {
|
| 10 |
+
|
| 11 |
+
constexpr size_t max_num_threads_per_block = 1024;
|
| 12 |
+
constexpr size_t max_num_blocks = 8;
|
| 13 |
+
|
| 14 |
+
template <typename T>
|
| 15 |
+
size_t get_alignment(T ptr_or_size) {
|
| 16 |
+
auto val = reinterpret_cast<uintptr_t>(ptr_or_size);
|
| 17 |
+
if (val % 16 == 0) {
|
| 18 |
+
return 16;
|
| 19 |
+
} else if (val % 8 == 0) {
|
| 20 |
+
return 8;
|
| 21 |
+
} else if (val % 4 == 0) {
|
| 22 |
+
return 4;
|
| 23 |
+
} else if (val % 2 == 0) {
|
| 24 |
+
return 2;
|
| 25 |
+
} else {
|
| 26 |
+
return 1;
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
template <>
|
| 31 |
+
size_t get_alignment<size_t>(size_t size) {
|
| 32 |
+
return get_alignment(reinterpret_cast<void*>(size));
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
__device__ __forceinline__ uint32_t
|
| 36 |
+
cas_sys(uint32_t* addr, uint32_t compare, uint32_t val) {
|
| 37 |
+
#if defined(USE_ROCM) || (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 800))
|
| 38 |
+
CUDA_KERNEL_ASSERT(false);
|
| 39 |
+
#else
|
| 40 |
+
uint32_t old_val;
|
| 41 |
+
asm volatile("atom.global.sys.cas.b32 %0, [%1], %2, %3;"
|
| 42 |
+
: "=r"(old_val)
|
| 43 |
+
: "l"(addr), "r"(compare), "r"(val)
|
| 44 |
+
: "memory");
|
| 45 |
+
return old_val;
|
| 46 |
+
#endif
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
__device__ __forceinline__ uint32_t
|
| 50 |
+
cas_release_sys(uint32_t* addr, uint32_t compare, uint32_t val) {
|
| 51 |
+
#if defined(USE_ROCM) || (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 800))
|
| 52 |
+
CUDA_KERNEL_ASSERT(false);
|
| 53 |
+
#else
|
| 54 |
+
uint32_t old_val;
|
| 55 |
+
asm volatile("atom.global.release.sys.cas.b32 %0, [%1], %2, %3;"
|
| 56 |
+
: "=r"(old_val)
|
| 57 |
+
: "l"(addr), "r"(compare), "r"(val)
|
| 58 |
+
: "memory");
|
| 59 |
+
return old_val;
|
| 60 |
+
#endif
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
__device__ __forceinline__ void release_signal(uint32_t* addr) {
|
| 64 |
+
while (cas_release_sys(addr, 0, 1) != 0)
|
| 65 |
+
;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
__device__ __forceinline__ void wait_signal(uint32_t* addr) {
|
| 69 |
+
while (cas_sys(addr, 1, 0) != 1)
|
| 70 |
+
;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
__device__ __forceinline__ uint32_t acquire_signal(uint32_t* addr) {
|
| 74 |
+
#if defined(USE_ROCM) || (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 800))
|
| 75 |
+
CUDA_KERNEL_ASSERT(false);
|
| 76 |
+
#else
|
| 77 |
+
uint32_t val;
|
| 78 |
+
asm volatile("ld.acquire.sys.global.u32 %0, [%1];"
|
| 79 |
+
: "=r"(val)
|
| 80 |
+
: "l"(addr)
|
| 81 |
+
: "memory");
|
| 82 |
+
return val;
|
| 83 |
+
#endif
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Perform a barrier to establish observation order between memory operations
|
| 87 |
+
// issued before and after the barrier.
|
| 88 |
+
__device__ __forceinline__ void barrier(
|
| 89 |
+
uint32_t** signal_pads,
|
| 90 |
+
size_t rank,
|
| 91 |
+
size_t world_size) {
|
| 92 |
+
if (threadIdx.x < world_size) {
|
| 93 |
+
auto target_rank = threadIdx.x;
|
| 94 |
+
release_signal(signal_pads[target_rank] + blockIdx.x * world_size + rank);
|
| 95 |
+
wait_signal(signal_pads[rank] + blockIdx.x * world_size + target_rank);
|
| 96 |
+
}
|
| 97 |
+
__syncthreads();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// Perform a barrier and establish causality order between memory operations
|
| 101 |
+
// issued before the calling kernel on all devices and memory operations
|
| 102 |
+
// issued after this function by all thread in the calling kernel.
|
| 103 |
+
//
|
| 104 |
+
// NOTE: this function does NOT ensure that memory operations issues in the
|
| 105 |
+
// current kernel are visible to all threads in the current kernel.
|
| 106 |
+
//
|
| 107 |
+
// | mem ops (guaranteed to be visible by all threads at point T)
|
| 108 |
+
// | kernel K
|
| 109 |
+
// | +- mem ops (not guaranteed to be visible all threads at point T)
|
| 110 |
+
// | +- barrier_and_acquire_previous_kernel_writes()
|
| 111 |
+
// | +- point T
|
| 112 |
+
// v
|
| 113 |
+
__device__ __forceinline__ void barrier_and_acquire_previous_kernel_writes(
|
| 114 |
+
uint32_t** signal_pads,
|
| 115 |
+
size_t rank,
|
| 116 |
+
size_t world_size) {
|
| 117 |
+
if (threadIdx.x < world_size) {
|
| 118 |
+
auto target_rank = threadIdx.x;
|
| 119 |
+
release_signal(signal_pads[target_rank] + blockIdx.x * world_size + rank);
|
| 120 |
+
wait_signal(signal_pads[rank] + blockIdx.x * world_size + target_rank);
|
| 121 |
+
}
|
| 122 |
+
__syncthreads();
|
| 123 |
+
// At this point, we established observation order between memory operations
|
| 124 |
+
// issued before and after the barrier. Now we convert the observation order
|
| 125 |
+
// into causality order by having every thread acquire the signals released
|
| 126 |
+
// by threads on peer devices. Due to the implicit synchronizes-with
|
| 127 |
+
// relationships at task/kernel boundaries, acquiring the signal released by
|
| 128 |
+
// thread T in kernel K transitively acquires memory operations issued prior
|
| 129 |
+
// to kernel K.
|
| 130 |
+
//
|
| 131 |
+
// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#memory-fence-interference
|
| 132 |
+
for (size_t target_rank = 0; target_rank < world_size; ++target_rank) {
|
| 133 |
+
acquire_signal(signal_pads[rank] + blockIdx.x * world_size + target_rank);
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
template <bool Value, class... Args>
|
| 138 |
+
inline constexpr bool dependent_bool_value = Value;
|
| 139 |
+
|
| 140 |
+
template <class... Args>
|
| 141 |
+
inline constexpr bool dependent_false = dependent_bool_value<false, Args...>;
|
| 142 |
+
|
| 143 |
+
template <int Size>
|
| 144 |
+
union Vec;
|
| 145 |
+
|
| 146 |
+
template <>
|
| 147 |
+
union Vec<4> {
|
| 148 |
+
uint16_t u16[2];
|
| 149 |
+
uint32_t u32, as_scalar;
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
template <>
|
| 153 |
+
union Vec<8> {
|
| 154 |
+
uint16_t u16[4];
|
| 155 |
+
uint32_t u32[2];
|
| 156 |
+
uint64_t u64, as_scalar;
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
template <>
|
| 160 |
+
union alignas(16) Vec<16> {
|
| 161 |
+
uint16_t u16[8];
|
| 162 |
+
uint32_t u32[4];
|
| 163 |
+
uint64_t u64[2];
|
| 164 |
+
uint4 u128, as_scalar;
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
template <typename T>
|
| 168 |
+
struct MultimemLdReduce {
|
| 169 |
+
template <int Alignment>
|
| 170 |
+
__device__ __inline__ Vec<Alignment> operator()(T* mc_ptr) {
|
| 171 |
+
static_assert(dependent_false<T>);
|
| 172 |
+
}
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
template <int Alignment, typename T>
|
| 176 |
+
__device__ __inline__ Vec<Alignment> multimem_ld_reduce_add(T* mc_ptr) {
|
| 177 |
+
MultimemLdReduce<T> functor;
|
| 178 |
+
return functor.template operator()<Alignment>(mc_ptr);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
#if defined(USE_ROCM) || !defined(NVCC_SUPPORTS_MULTICAST)
|
| 182 |
+
#define SPECIALIZE_MULTIMEM_LD_REDUCE_VEC_32(type, asm_type) \
|
| 183 |
+
template <> \
|
| 184 |
+
struct MultimemLdReduce<type> { \
|
| 185 |
+
template <int Alignment> \
|
| 186 |
+
__device__ __inline__ Vec<Alignment> operator()(type* mc_ptr) { \
|
| 187 |
+
CUDA_KERNEL_ASSERT(false); \
|
| 188 |
+
} \
|
| 189 |
+
};
|
| 190 |
+
#else
|
| 191 |
+
#define SPECIALIZE_MULTIMEM_LD_REDUCE_VEC_32(type, asm_type) \
|
| 192 |
+
template <> \
|
| 193 |
+
struct MultimemLdReduce<type> { \
|
| 194 |
+
template <int Alignment> \
|
| 195 |
+
__device__ __inline__ Vec<Alignment> operator()(type* mc_ptr) { \
|
| 196 |
+
Vec<Alignment> vec; \
|
| 197 |
+
if constexpr (Alignment == 16) { \
|
| 198 |
+
asm("multimem.ld_reduce.relaxed.sys.global.add.v4." asm_type \
|
| 199 |
+
" {%0,%1,%2,%3}, [%4];" \
|
| 200 |
+
: "=r"(vec.u32[0]), \
|
| 201 |
+
"=r"(vec.u32[1]), \
|
| 202 |
+
"=r"(vec.u32[2]), \
|
| 203 |
+
"=r"(vec.u32[3]) \
|
| 204 |
+
: "l"(mc_ptr) \
|
| 205 |
+
: "memory"); \
|
| 206 |
+
} else if constexpr (Alignment == 8) { \
|
| 207 |
+
asm("multimem.ld_reduce.relaxed.sys.global.add.v2." asm_type \
|
| 208 |
+
" {%0,%1}, [%2];" \
|
| 209 |
+
: "=r"(vec.u32[0]), "=r"(vec.u32[1]) \
|
| 210 |
+
: "l"(mc_ptr) \
|
| 211 |
+
: "memory"); \
|
| 212 |
+
} else if constexpr (Alignment == 4) { \
|
| 213 |
+
asm("multimem.ld_reduce.relaxed.sys.global.add." asm_type " %0, [%1];" \
|
| 214 |
+
: "=r"(vec.u32) \
|
| 215 |
+
: "l"(mc_ptr) \
|
| 216 |
+
: "memory"); \
|
| 217 |
+
} \
|
| 218 |
+
return vec; \
|
| 219 |
+
} \
|
| 220 |
+
};
|
| 221 |
+
#endif
|
| 222 |
+
|
| 223 |
+
SPECIALIZE_MULTIMEM_LD_REDUCE_VEC_32(at::BFloat16, "bf16x2");
|
| 224 |
+
SPECIALIZE_MULTIMEM_LD_REDUCE_VEC_32(float, "f32");
|
| 225 |
+
|
| 226 |
+
template <int Alignment, typename T>
|
| 227 |
+
__device__ __inline__ void multimem_st(T* mc_ptr, Vec<Alignment>& vec) {
|
| 228 |
+
#if defined(USE_ROCM) || !defined(NVCC_SUPPORTS_MULTICAST)
|
| 229 |
+
CUDA_KERNEL_ASSERT(false);
|
| 230 |
+
#else
|
| 231 |
+
if constexpr (Alignment == 16) {
|
| 232 |
+
asm("multimem.st.relaxed.sys.global.v4.f32 [%0], {%1,%2,%3,%4};"
|
| 233 |
+
:
|
| 234 |
+
: "l"(mc_ptr),
|
| 235 |
+
"r"(vec.u32[0]),
|
| 236 |
+
"r"(vec.u32[1]),
|
| 237 |
+
"r"(vec.u32[2]),
|
| 238 |
+
"r"(vec.u32[3])
|
| 239 |
+
: "memory");
|
| 240 |
+
} else if constexpr (Alignment == 8) {
|
| 241 |
+
asm("multimem.st.relaxed.sys.global.v2.f32 [%0], {%1,%2};"
|
| 242 |
+
:
|
| 243 |
+
: "l"(mc_ptr), "r"(vec.u32[0]), "r"(vec.u32[1])
|
| 244 |
+
: "memory");
|
| 245 |
+
} else if constexpr (Alignment == 4) {
|
| 246 |
+
asm("multimem.st.relaxed.sys.global.f32 [%0], %1;"
|
| 247 |
+
:
|
| 248 |
+
: "l"(mc_ptr), "r"(vec.u32)
|
| 249 |
+
: "memory");
|
| 250 |
+
} else {
|
| 251 |
+
static_assert(dependent_false<T>);
|
| 252 |
+
}
|
| 253 |
+
#endif
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
} // namespace c10d::symmetric_memory
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/DMAConnectivity.hpp
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <optional>
|
| 4 |
+
|
| 5 |
+
#include <ATen/ATen.h>
|
| 6 |
+
|
| 7 |
+
namespace c10d {
|
| 8 |
+
|
| 9 |
+
struct TORCH_API DMAConnectivity : c10::intrusive_ptr_target {
|
| 10 |
+
c10::DeviceType device_type;
|
| 11 |
+
std::string connection_type;
|
| 12 |
+
|
| 13 |
+
// This is an NxN matrix representing the connectivity between N devices,
|
| 14 |
+
// where each element matrix[i][j] indicates the connectivity between device
|
| 15 |
+
// i and device j. A value of 0 denotes that there is no connection between
|
| 16 |
+
// device i and j. The meaning of non-zero values are specific to the
|
| 17 |
+
// connection type (e.g., for NVLink it represents the number of NVLinks).
|
| 18 |
+
std::vector<std::vector<int>> matrix;
|
| 19 |
+
|
| 20 |
+
explicit DMAConnectivity(
|
| 21 |
+
c10::DeviceType device_type,
|
| 22 |
+
std::string connection_type,
|
| 23 |
+
std::vector<std::vector<int>> matrix);
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
struct DMAConnectivityDetector : c10::intrusive_ptr_target {
|
| 27 |
+
virtual c10::intrusive_ptr<DMAConnectivity> detect() = 0;
|
| 28 |
+
virtual ~DMAConnectivityDetector() {}
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
C10_EXPORT void register_dma_connectivity_detector(
|
| 32 |
+
c10::DeviceType device_type,
|
| 33 |
+
const std::string& connection_type,
|
| 34 |
+
c10::intrusive_ptr<DMAConnectivityDetector> detector);
|
| 35 |
+
|
| 36 |
+
TORCH_API c10::intrusive_ptr<DMAConnectivity> detect_dma_connectivity(
|
| 37 |
+
c10::DeviceType device_type,
|
| 38 |
+
const std::string& connection_type);
|
| 39 |
+
|
| 40 |
+
} // namespace c10d
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FakeProcessGroup.hpp
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/distributed/c10d/Backend.hpp>
|
| 4 |
+
|
| 5 |
+
namespace c10d {
|
| 6 |
+
|
| 7 |
+
class FakeWork : public Work {
|
| 8 |
+
public:
|
| 9 |
+
bool wait(std::chrono::milliseconds timeout) override {
|
| 10 |
+
return true;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
c10::intrusive_ptr<c10::ivalue::Future> getFuture() override {
|
| 14 |
+
auto fut = c10::make_intrusive<c10::ivalue::Future>(c10::NoneType::get());
|
| 15 |
+
fut->markCompleted();
|
| 16 |
+
return fut;
|
| 17 |
+
}
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
class FakeProcessGroup : public Backend {
|
| 21 |
+
public:
|
| 22 |
+
FakeProcessGroup(int rank, int size) : Backend(rank, size) {}
|
| 23 |
+
|
| 24 |
+
c10::intrusive_ptr<Work> broadcast(
|
| 25 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 26 |
+
const BroadcastOptions& /* opts */ = BroadcastOptions()) override {
|
| 27 |
+
return c10::make_intrusive<FakeWork>();
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
c10::intrusive_ptr<Work> allreduce(
|
| 31 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 32 |
+
const AllreduceOptions& /* opts */ = AllreduceOptions()) override {
|
| 33 |
+
return c10::make_intrusive<FakeWork>();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
c10::intrusive_ptr<Work> allreduce_sparse(
|
| 37 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 38 |
+
const AllreduceOptions& /* opts */ = AllreduceOptions()) override {
|
| 39 |
+
return c10::make_intrusive<FakeWork>();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
c10::intrusive_ptr<Work> allreduce_coalesced(
|
| 43 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 44 |
+
const AllreduceCoalescedOptions& /* opts */ =
|
| 45 |
+
AllreduceCoalescedOptions()) override {
|
| 46 |
+
return c10::make_intrusive<FakeWork>();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
c10::intrusive_ptr<Work> reduce(
|
| 50 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 51 |
+
const ReduceOptions& /* opts */ = ReduceOptions()) override {
|
| 52 |
+
return c10::make_intrusive<FakeWork>();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// NOTE [allgather on FakeProcessGroup]
|
| 56 |
+
// Assume each rank have the same input tensor so we just copy to the results
|
| 57 |
+
// since it's not a real allgather, we simply make this copying logic to let
|
| 58 |
+
// some simple validation works (i.e. calling allgather to see if each rank
|
| 59 |
+
// have the same tensor or not).
|
| 60 |
+
//
|
| 61 |
+
// NOTE: in general it's not good form to try to make FakeProcessGroup work
|
| 62 |
+
// with real data, but the reasoning here is that we want FakeProcessGroup to
|
| 63 |
+
// work with DeviceMesh's init code that have the data validation, which
|
| 64 |
+
// makes it worth the tradeoff.
|
| 65 |
+
c10::intrusive_ptr<Work> allgather(
|
| 66 |
+
std::vector<std::vector<at::Tensor>>& outputTensors,
|
| 67 |
+
std::vector<at::Tensor>& inputTensors,
|
| 68 |
+
const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
|
| 69 |
+
for (auto& tensor : outputTensors[0]) {
|
| 70 |
+
tensor.copy_(inputTensors[0]);
|
| 71 |
+
}
|
| 72 |
+
return c10::make_intrusive<FakeWork>();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
c10::intrusive_ptr<Work> _allgather_base(
|
| 76 |
+
at::Tensor& outputBuffer,
|
| 77 |
+
at::Tensor& inputBuffer,
|
| 78 |
+
const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
|
| 79 |
+
auto chunks = outputBuffer.chunk(size_);
|
| 80 |
+
for (auto& tensor : chunks) {
|
| 81 |
+
tensor.copy_(inputBuffer);
|
| 82 |
+
}
|
| 83 |
+
return c10::make_intrusive<FakeWork>();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
c10::intrusive_ptr<Work> allgather_coalesced(
|
| 87 |
+
std::vector<std::vector<at::Tensor>>& /* outputTensorLists */,
|
| 88 |
+
std::vector<at::Tensor>& /* inputTensors */,
|
| 89 |
+
const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
|
| 90 |
+
return c10::make_intrusive<FakeWork>();
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
c10::intrusive_ptr<Work> allgather_into_tensor_coalesced(
|
| 94 |
+
std::vector<at::Tensor>& outputs,
|
| 95 |
+
std::vector<at::Tensor>& inputs,
|
| 96 |
+
const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
|
| 97 |
+
for (size_t i = 0; i < outputs.size(); ++i) {
|
| 98 |
+
auto chunks = outputs[i].chunk(size_);
|
| 99 |
+
for (auto& chunk : chunks) {
|
| 100 |
+
chunk.copy_(inputs[i]);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
return c10::make_intrusive<FakeWork>();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
c10::intrusive_ptr<Work> gather(
|
| 107 |
+
std::vector<std::vector<at::Tensor>>& /* outputTensors */,
|
| 108 |
+
std::vector<at::Tensor>& /* inputTensors */,
|
| 109 |
+
const GatherOptions& /* opts */ = GatherOptions()) override {
|
| 110 |
+
return c10::make_intrusive<FakeWork>();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
c10::intrusive_ptr<Work> scatter(
|
| 114 |
+
std::vector<at::Tensor>& /* outputTensors */,
|
| 115 |
+
std::vector<std::vector<at::Tensor>>& /* inputTensors */,
|
| 116 |
+
const ScatterOptions& /* opts */ = ScatterOptions()) override {
|
| 117 |
+
return c10::make_intrusive<FakeWork>();
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
c10::intrusive_ptr<Work> reduce_scatter(
|
| 121 |
+
std::vector<at::Tensor>& /* outputTensors */,
|
| 122 |
+
std::vector<std::vector<at::Tensor>>& /* inputTensors */,
|
| 123 |
+
const ReduceScatterOptions& /* opts */ =
|
| 124 |
+
ReduceScatterOptions()) override {
|
| 125 |
+
return c10::make_intrusive<FakeWork>();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
c10::intrusive_ptr<Work> _reduce_scatter_base(
|
| 129 |
+
at::Tensor& /* outputBuffer */,
|
| 130 |
+
at::Tensor& /* inputBuffer */,
|
| 131 |
+
const ReduceScatterOptions& /* opts */ =
|
| 132 |
+
ReduceScatterOptions()) override {
|
| 133 |
+
return c10::make_intrusive<FakeWork>();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
c10::intrusive_ptr<Work> reduce_scatter_tensor_coalesced(
|
| 137 |
+
std::vector<at::Tensor>& /* outputs */,
|
| 138 |
+
std::vector<at::Tensor>& /* inputs */,
|
| 139 |
+
const ReduceScatterOptions& /* opts */ =
|
| 140 |
+
ReduceScatterOptions()) override {
|
| 141 |
+
return c10::make_intrusive<FakeWork>();
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
c10::intrusive_ptr<Work> alltoall_base(
|
| 145 |
+
at::Tensor& /* outputBuffer */,
|
| 146 |
+
at::Tensor& /* inputBuffer */,
|
| 147 |
+
std::vector<int64_t>& /* outputSplitSizes */,
|
| 148 |
+
std::vector<int64_t>& /* inputSplitSizes */,
|
| 149 |
+
const AllToAllOptions& /* opts */ = AllToAllOptions()) override {
|
| 150 |
+
return c10::make_intrusive<FakeWork>();
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
c10::intrusive_ptr<Work> alltoall(
|
| 154 |
+
std::vector<at::Tensor>& /* outputTensors */,
|
| 155 |
+
std::vector<at::Tensor>& /* inputTensors */,
|
| 156 |
+
const AllToAllOptions& opts = AllToAllOptions()) override {
|
| 157 |
+
return c10::make_intrusive<FakeWork>();
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
c10::intrusive_ptr<Work> send(
|
| 161 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 162 |
+
int /* dstRank */,
|
| 163 |
+
int /* tag */) override {
|
| 164 |
+
return c10::make_intrusive<FakeWork>();
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
c10::intrusive_ptr<Work> recv(
|
| 168 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 169 |
+
int /* srcRank */,
|
| 170 |
+
int /* tag */) override {
|
| 171 |
+
return c10::make_intrusive<FakeWork>();
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
c10::intrusive_ptr<Work> recvAnysource(
|
| 175 |
+
std::vector<at::Tensor>& /* tensors */,
|
| 176 |
+
int /* tag */) override {
|
| 177 |
+
return c10::make_intrusive<FakeWork>();
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
c10::intrusive_ptr<Work> barrier(
|
| 181 |
+
const BarrierOptions& /* opts */ = BarrierOptions()) override {
|
| 182 |
+
return c10::make_intrusive<FakeWork>();
|
| 183 |
+
}
|
| 184 |
+
};
|
| 185 |
+
|
| 186 |
+
} // namespace c10d
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/GlooDeviceFactory.hpp
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#ifdef USE_C10D_GLOO
|
| 4 |
+
|
| 5 |
+
#include <string>
|
| 6 |
+
|
| 7 |
+
#include <c10/util/Registry.h>
|
| 8 |
+
#include <gloo/config.h>
|
| 9 |
+
#include <gloo/transport/device.h>
|
| 10 |
+
|
| 11 |
+
namespace c10d {
|
| 12 |
+
|
| 13 |
+
class TORCH_API GlooDeviceFactory {
|
| 14 |
+
public:
|
| 15 |
+
// Create new device instance for specific interface.
|
| 16 |
+
static std::shared_ptr<::gloo::transport::Device> makeDeviceForInterface(
|
| 17 |
+
const std::string& interface);
|
| 18 |
+
|
| 19 |
+
// Create new device instance for specific hostname or address.
|
| 20 |
+
static std::shared_ptr<::gloo::transport::Device> makeDeviceForHostname(
|
| 21 |
+
const std::string& hostname);
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
TORCH_DECLARE_SHARED_REGISTRY(
|
| 25 |
+
GlooDeviceRegistry,
|
| 26 |
+
::gloo::transport::Device,
|
| 27 |
+
const std::string&, /* interface */
|
| 28 |
+
const std::string& /* hostname */);
|
| 29 |
+
|
| 30 |
+
} // namespace c10d
|
| 31 |
+
|
| 32 |
+
#endif // USE_C10D_GLOO
|
vll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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#ifdef USE_C10D_NCCL
|
| 4 |
+
|
| 5 |
+
#include <stdio.h>
|
| 6 |
+
#include <stdlib.h>
|
| 7 |
+
|
| 8 |
+
#include <memory>
|
| 9 |
+
#include <mutex>
|
| 10 |
+
#include <thread>
|
| 11 |
+
|
| 12 |
+
#include <ATen/ATen.h>
|
| 13 |
+
#include <ATen/cuda/CUDAEvent.h>
|
| 14 |
+
#include <c10/util/Exception.h>
|
| 15 |
+
#include <nccl.h>
|
| 16 |
+
#include <torch/csrc/distributed/c10d/TraceUtils.h>
|
| 17 |
+
#include <optional>
|
| 18 |
+
|
| 19 |
+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 20 |
+
(NCCL_MINOR >= 14)
|
| 21 |
+
#define NCCL_HAS_COMM_NONBLOCKING
|
| 22 |
+
#endif
|
| 23 |
+
|
| 24 |
+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 25 |
+
(NCCL_MINOR >= 18)
|
| 26 |
+
#define NCCL_HAS_COMM_SPLIT
|
| 27 |
+
#endif
|
| 28 |
+
|
| 29 |
+
// ncclGetLastError() is enabled only for NCCL versions 2.13+
|
| 30 |
+
// ncclRemoteError only exists in NCCL versions 2.13+
|
| 31 |
+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 32 |
+
(NCCL_MINOR >= 13)
|
| 33 |
+
#define ENABLE_NCCL_GET_LAST_ERROR
|
| 34 |
+
#define NCCL_REMOTE_ERROR
|
| 35 |
+
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
|
| 36 |
+
#define ENABLE_NCCL_GET_LAST_ERROR
|
| 37 |
+
#define NCCL_REMOTE_ERROR
|
| 38 |
+
#endif
|
| 39 |
+
|
| 40 |
+
// Error checking is enabled only for NCCL versions 2.4+ since ncclCommAbort()
|
| 41 |
+
// and ncclCommGetAsyncError() are not supported in earlier versions.
|
| 42 |
+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 43 |
+
(NCCL_MINOR >= 4)
|
| 44 |
+
#define ENABLE_NCCL_ERROR_CHECKING
|
| 45 |
+
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
|
| 46 |
+
#define ENABLE_NCCL_ERROR_CHECKING
|
| 47 |
+
#endif
|
| 48 |
+
|
| 49 |
+
// P2P is enabled only for NCCL versions 2.7+ since ncclSend()
|
| 50 |
+
// and ncclRecv() are not supported in earlier versions.
|
| 51 |
+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 52 |
+
(NCCL_MINOR >= 7)
|
| 53 |
+
#define ENABLE_NCCL_P2P_SUPPORT
|
| 54 |
+
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
|
| 55 |
+
#define ENABLE_NCCL_P2P_SUPPORT
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 59 |
+
(NCCL_MINOR >= 11)
|
| 60 |
+
#define ENABLE_NCCL_PREMUL_SUM_SUPPORT
|
| 61 |
+
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
|
| 62 |
+
#define ENABLE_NCCL_PREMUL_SUM_SUPPORT
|
| 63 |
+
#endif
|
| 64 |
+
|
| 65 |
+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 66 |
+
(NCCL_MINOR >= 17)
|
| 67 |
+
#define NCCL_HAS_COMM_CTA_CGA
|
| 68 |
+
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
|
| 69 |
+
#define NCCL_HAS_COMM_CTA_CGA
|
| 70 |
+
#endif
|
| 71 |
+
|
| 72 |
+
#if defined(NCCL_REGISTRATION_SUPPORTED) || \
|
| 73 |
+
((defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
|
| 74 |
+
(NCCL_MINOR >= 19)))
|
| 75 |
+
#define NCCL_HAS_COMM_REGISTER
|
| 76 |
+
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
|
| 77 |
+
#define NCCL_HAS_COMM_REGISTER
|
| 78 |
+
#endif
|
| 79 |
+
|
| 80 |
+
// Macro to throw on a non-successful NCCL return value.
|
| 81 |
+
#define C10D_NCCL_CHECK(cmd, failureReason) \
|
| 82 |
+
do { \
|
| 83 |
+
ncclResult_t result = cmd; \
|
| 84 |
+
if (result != ncclSuccess) { \
|
| 85 |
+
std::string err = "NCCL error in: " + std::string(__FILE__) + ":" + \
|
| 86 |
+
std::to_string(__LINE__) + ", " + ncclGetErrorWithVersion(result) + \
|
| 87 |
+
"\n" + getNcclErrorDetailStr(result, failureReason); \
|
| 88 |
+
TORCH_CHECK_WITH(DistBackendError, false, err); \
|
| 89 |
+
} \
|
| 90 |
+
} while (0)
|
| 91 |
+
|
| 92 |
+
// Macro to throw on a non-successful NCCL return value for NONBLOCKING calls.
|
| 93 |
+
#define C10D_NCCL_CHECK_NONBLOCKING(cmd, failureReason) \
|
| 94 |
+
do { \
|
| 95 |
+
ncclResult_t result = cmd; \
|
| 96 |
+
if (result != ncclSuccess && result != ncclInProgress) { \
|
| 97 |
+
std::string err = "NCCL error in: " + std::string(__FILE__) + ":" + \
|
| 98 |
+
std::to_string(__LINE__) + ", " + ncclGetErrorWithVersion(result) + \
|
| 99 |
+
"\n" + getNcclErrorDetailStr(result, failureReason); \
|
| 100 |
+
TORCH_CHECK_WITH(DistBackendError, false, err); \
|
| 101 |
+
} \
|
| 102 |
+
} while (0)
|
| 103 |
+
|
| 104 |
+
// Macro to throw on a non-successful NCCL return value, non-blocking.
|
| 105 |
+
#define C10D_NCCL_CHECK_TIMEOUT(cmd, comm, failureReason) \
|
| 106 |
+
ncclResult_t result = cmd; \
|
| 107 |
+
auto startTimepoint = std::chrono::steady_clock::now(); \
|
| 108 |
+
while (result == ncclInProgress) { \
|
| 109 |
+
if (nccl_nonblocking_timeout() > 0) { \
|
| 110 |
+
auto currentTimepoint = std::chrono::steady_clock::now(); \
|
| 111 |
+
auto timeElapsed = std::chrono::duration_cast<std::chrono::seconds>( \
|
| 112 |
+
currentTimepoint - startTimepoint) \
|
| 113 |
+
.count(); \
|
| 114 |
+
if (timeElapsed > nccl_nonblocking_timeout()) { \
|
| 115 |
+
std::string err = "NCCL timeout in: " + std::string(__FILE__) + ":" + \
|
| 116 |
+
std::to_string(__LINE__) + ", " + \
|
| 117 |
+
ncclGetErrorWithVersion(result) + "\n" + \
|
| 118 |
+
getNcclErrorDetailStr(result, failureReason); \
|
| 119 |
+
TORCH_CHECK_WITH(DistBackendError, false, err); \
|
| 120 |
+
} \
|
| 121 |
+
} \
|
| 122 |
+
ncclCommGetAsyncError(comm, &result); \
|
| 123 |
+
} \
|
| 124 |
+
if (result != ncclSuccess) { \
|
| 125 |
+
std::string err = "NCCL error in: " + std::string(__FILE__) + ":" + \
|
| 126 |
+
std::to_string(__LINE__) + ", " + ncclGetErrorWithVersion(result) + \
|
| 127 |
+
"\n" + getNcclErrorDetailStr(result, failureReason); \
|
| 128 |
+
TORCH_CHECK_WITH(DistBackendError, false, err); \
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
#define C10D_NCCL_CHECK_TIMEOUT_GROUPEND(cmd, comm, failureReason) \
|
| 132 |
+
ncclResult_t state = cmd; \
|
| 133 |
+
auto startTimepoint = std::chrono::steady_clock::now(); \
|
| 134 |
+
if (state == ncclInProgress) { \
|
| 135 |
+
do { \
|
| 136 |
+
if (nccl_nonblocking_timeout() > 0) { \
|
| 137 |
+
auto currentTimepoint = std::chrono::steady_clock::now(); \
|
| 138 |
+
auto timeElapsed = std::chrono::duration_cast<std::chrono::seconds>( \
|
| 139 |
+
currentTimepoint - startTimepoint) \
|
| 140 |
+
.count(); \
|
| 141 |
+
if (timeElapsed > nccl_nonblocking_timeout()) { \
|
| 142 |
+
std::string err = "NCCL timeout in: " + std::string(__FILE__) + \
|
| 143 |
+
":" + std::to_string(__LINE__) + ", " + \
|
| 144 |
+
ncclGetErrorWithVersion(state) + "\n" + \
|
| 145 |
+
getNcclErrorDetailStr(state, failureReason); \
|
| 146 |
+
TORCH_CHECK_WITH(DistBackendError, false, err); \
|
| 147 |
+
} \
|
| 148 |
+
} \
|
| 149 |
+
ncclCommGetAsyncError(comm->getNcclComm(), &state); \
|
| 150 |
+
} while (state == ncclInProgress); \
|
| 151 |
+
} \
|
| 152 |
+
if (state != ncclSuccess) { \
|
| 153 |
+
std::string err = "NCCL error in: " + std::string(__FILE__) + ":" + \
|
| 154 |
+
std::to_string(__LINE__) + ", " + ncclGetErrorWithVersion(state) + \
|
| 155 |
+
"\n" + getNcclErrorDetailStr(state, failureReason); \
|
| 156 |
+
TORCH_CHECK_WITH(DistBackendError, false, err); \
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// Macro to print and abort on a non-successful NCCL return value.
|
| 160 |
+
#define C10D_NCCL_ASSERT(cmd) \
|
| 161 |
+
do { \
|
| 162 |
+
ncclResult_t result = cmd; \
|
| 163 |
+
if (result != ncclSuccess) { \
|
| 164 |
+
std::string err = ncclGetErrorWithVersion(result); \
|
| 165 |
+
fprintf( \
|
| 166 |
+
stderr, \
|
| 167 |
+
"NCCL error in: %s:%d, %s\n", \
|
| 168 |
+
__FILE__, \
|
| 169 |
+
__LINE__, \
|
| 170 |
+
err.c_str()); \
|
| 171 |
+
abort(); \
|
| 172 |
+
} \
|
| 173 |
+
} while (0)
|
| 174 |
+
|
| 175 |
+
namespace c10d {
|
| 176 |
+
#define DEFINE_CONSTANT(name, value) \
|
| 177 |
+
static c10::IValue name = value; \
|
| 178 |
+
static std::string name##_str = value;
|
| 179 |
+
// Update whenever changing contents or formatting of the dump
|
| 180 |
+
// (minor when adding fields, major when changing existing fields)
|
| 181 |
+
// Also update both JSON and Pickle dumps to make use of the newly defined
|
| 182 |
+
// field(s).
|
| 183 |
+
DEFINE_CONSTANT(version_val, "2.4");
|
| 184 |
+
DEFINE_CONSTANT(entries_key, "entries");
|
| 185 |
+
DEFINE_CONSTANT(nccl_comm_key, "nccl_comm_state");
|
| 186 |
+
DEFINE_CONSTANT(version_key, "version");
|
| 187 |
+
DEFINE_CONSTANT(pg_config_key, "pg_config");
|
| 188 |
+
DEFINE_CONSTANT(pg_status_key, "pg_status");
|
| 189 |
+
DEFINE_CONSTANT(record_id_key, "record_id");
|
| 190 |
+
DEFINE_CONSTANT(pg_id_key, "pg_id");
|
| 191 |
+
DEFINE_CONSTANT(pg_name_key, "process_group");
|
| 192 |
+
DEFINE_CONSTANT(collective_seq_id_key, "collective_seq_id");
|
| 193 |
+
DEFINE_CONSTANT(p2p_seq_id_key, "p2p_seq_id");
|
| 194 |
+
DEFINE_CONSTANT(is_p2p_key, "is_p2p");
|
| 195 |
+
DEFINE_CONSTANT(op_id_key, "op_id");
|
| 196 |
+
DEFINE_CONSTANT(profiling_name_key, "profiling_name");
|
| 197 |
+
DEFINE_CONSTANT(input_sizes_key, "input_sizes");
|
| 198 |
+
DEFINE_CONSTANT(input_dtypes_key, "input_dtypes");
|
| 199 |
+
DEFINE_CONSTANT(output_sizes_key, "output_sizes");
|
| 200 |
+
DEFINE_CONSTANT(output_dtypes_key, "output_dtypes");
|
| 201 |
+
DEFINE_CONSTANT(time_created_key, "time_created_ns");
|
| 202 |
+
DEFINE_CONSTANT(duration_key, "duration_ms");
|
| 203 |
+
DEFINE_CONSTANT(timeout_key, "timeout_ms");
|
| 204 |
+
DEFINE_CONSTANT(frames_key, "frames");
|
| 205 |
+
DEFINE_CONSTANT(state_key, "state");
|
| 206 |
+
DEFINE_CONSTANT(line_key, "line");
|
| 207 |
+
DEFINE_CONSTANT(name_key, "name");
|
| 208 |
+
DEFINE_CONSTANT(filename_key, "filename");
|
| 209 |
+
DEFINE_CONSTANT(retired_key, "retired");
|
| 210 |
+
DEFINE_CONSTANT(time_discovered_started_key, "time_discovered_started_ns");
|
| 211 |
+
DEFINE_CONSTANT(time_discovered_completed_key, "time_discovered_completed_ns");
|
| 212 |
+
DEFINE_CONSTANT(completed_state, "completed");
|
| 213 |
+
DEFINE_CONSTANT(scheduled_state, "scheduled");
|
| 214 |
+
DEFINE_CONSTANT(started_state, "started");
|
| 215 |
+
#undef DEFINE_CONSTANT
|
| 216 |
+
|
| 217 |
+
TORCH_API size_t hashTensors(const std::vector<at::Tensor>& tensors);
|
| 218 |
+
TORCH_API std::string getNcclVersion();
|
| 219 |
+
TORCH_API std::string ncclGetErrorWithVersion(ncclResult_t error);
|
| 220 |
+
bool nccl_use_nonblocking();
|
| 221 |
+
int nccl_nonblocking_timeout();
|
| 222 |
+
|
| 223 |
+
// Provides additional detail into NCCL error codes based on when these are
|
| 224 |
+
// thrown in the NCCL codebase.
|
| 225 |
+
TORCH_API std::string getNcclErrorDetailStr(
|
| 226 |
+
ncclResult_t error,
|
| 227 |
+
std::optional<std::string> processGroupFailureReason = std::nullopt);
|
| 228 |
+
|
| 229 |
+
// Write NCCL debug info to local disk or any storage users define.
|
| 230 |
+
// There are some constrains we set for the debug info writer:
|
| 231 |
+
// 1. The writer should only be registered once.
|
| 232 |
+
// 2. Once registered, users cannot change it including un-register.
|
| 233 |
+
// 3. It is recommended to register the customized writer in the trainer setup,
|
| 234 |
+
// If users don't register before calling launchAsyncDebugDump, then users
|
| 235 |
+
// lose the chance to register (and the default writer will be
|
| 236 |
+
// auto-registered).
|
| 237 |
+
class TORCH_API DebugInfoWriter {
|
| 238 |
+
public:
|
| 239 |
+
virtual ~DebugInfoWriter() = default;
|
| 240 |
+
virtual void write(const std::string& ncclTrace);
|
| 241 |
+
static DebugInfoWriter& getWriter(int rank);
|
| 242 |
+
static void registerWriter(std::unique_ptr<DebugInfoWriter> writer);
|
| 243 |
+
virtual std::string getWriterTarget() {
|
| 244 |
+
return filename_;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
protected:
|
| 248 |
+
DebugInfoWriter(std::string namePrefix, int rank) {
|
| 249 |
+
filename_ = c10::str(namePrefix, rank);
|
| 250 |
+
}
|
| 251 |
+
std::string filename_;
|
| 252 |
+
|
| 253 |
+
private:
|
| 254 |
+
static std::unique_ptr<DebugInfoWriter> writer_;
|
| 255 |
+
static std::atomic<bool> hasWriterRegistered_;
|
| 256 |
+
};
|
| 257 |
+
|
| 258 |
+
// RAII wrapper for NCCL communicator
|
| 259 |
+
class NCCLComm {
|
| 260 |
+
public:
|
| 261 |
+
explicit NCCLComm(ncclComm_t ncclComm)
|
| 262 |
+
: ncclComm_(ncclComm),
|
| 263 |
+
aborted_(false),
|
| 264 |
+
ncclAsyncErr_(ncclSuccess),
|
| 265 |
+
commFailureReason_(std::nullopt),
|
| 266 |
+
initialized_(false) {}
|
| 267 |
+
|
| 268 |
+
NCCLComm() : NCCLComm(nullptr) {}
|
| 269 |
+
|
| 270 |
+
~NCCLComm() noexcept {
|
| 271 |
+
// Add lock in this destructor, as aborted_ needs to be read after memory
|
| 272 |
+
// barrier here.
|
| 273 |
+
std::unique_lock<std::mutex> lock(mutex_);
|
| 274 |
+
if (ncclComm_ && initialized_ && !aborted_) {
|
| 275 |
+
#ifdef ENABLE_NCCL_ERROR_CHECKING
|
| 276 |
+
// Use ncclCommAbort instead of ncclCommDestroy here since
|
| 277 |
+
// ncclCommDestroy could block forever waiting for work to complete on
|
| 278 |
+
// the communicator.
|
| 279 |
+
C10D_NCCL_ASSERT(::ncclCommAbort(ncclComm_));
|
| 280 |
+
#else
|
| 281 |
+
C10D_NCCL_ASSERT(::ncclCommDestroy(ncclComm_));
|
| 282 |
+
#endif
|
| 283 |
+
}
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
static std::shared_ptr<NCCLComm> create(
|
| 287 |
+
int numRanks,
|
| 288 |
+
int rank,
|
| 289 |
+
ncclUniqueId commId) {
|
| 290 |
+
auto comm = std::make_shared<NCCLComm>();
|
| 291 |
+
C10D_NCCL_CHECK(
|
| 292 |
+
ncclCommInitRank(&(comm->ncclComm_), numRanks, commId, rank),
|
| 293 |
+
std::nullopt);
|
| 294 |
+
comm->ncclId_ = commId;
|
| 295 |
+
comm->rank_ = rank;
|
| 296 |
+
comm->initialized_ = true;
|
| 297 |
+
return comm;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
#ifdef NCCL_HAS_COMM_NONBLOCKING
|
| 301 |
+
static std::shared_ptr<NCCLComm> create(
|
| 302 |
+
int numRanks,
|
| 303 |
+
int rank,
|
| 304 |
+
ncclUniqueId commId,
|
| 305 |
+
ncclConfig_t& config) {
|
| 306 |
+
auto comm = std::make_shared<NCCLComm>();
|
| 307 |
+
bool isInitialized = false;
|
| 308 |
+
if (nccl_use_nonblocking()) {
|
| 309 |
+
config.blocking = 0;
|
| 310 |
+
LOG(INFO) << "Rank " << rank
|
| 311 |
+
<< ": creating NCCL communicator in nonblocking mode";
|
| 312 |
+
C10D_NCCL_CHECK_NONBLOCKING(
|
| 313 |
+
ncclCommInitRankConfig(
|
| 314 |
+
&(comm->ncclComm_), numRanks, commId, rank, &config),
|
| 315 |
+
std::nullopt);
|
| 316 |
+
} else {
|
| 317 |
+
C10D_NCCL_CHECK(
|
| 318 |
+
ncclCommInitRankConfig(
|
| 319 |
+
&(comm->ncclComm_), numRanks, commId, rank, &config),
|
| 320 |
+
std::nullopt);
|
| 321 |
+
// under blocking mode, comm is initialized after NCCL CHECK
|
| 322 |
+
isInitialized = true;
|
| 323 |
+
}
|
| 324 |
+
comm->ncclId_ = commId;
|
| 325 |
+
comm->rank_ = rank;
|
| 326 |
+
comm->initialized_ = isInitialized;
|
| 327 |
+
return comm;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
static std::shared_ptr<NCCLComm> split(
|
| 331 |
+
NCCLComm* source,
|
| 332 |
+
int color_id,
|
| 333 |
+
int rank,
|
| 334 |
+
ncclConfig_t& config,
|
| 335 |
+
std::vector<uint64_t>& ranks_ull);
|
| 336 |
+
#endif
|
| 337 |
+
|
| 338 |
+
#if defined(IS_NCCLX) && defined(NCCL_COMM_DUMP)
|
| 339 |
+
std::unordered_map<std::string, std::string> ncclCommDump() {
|
| 340 |
+
std::unordered_map<std::string, std::string> dump;
|
| 341 |
+
if (isAborted()) {
|
| 342 |
+
LOG(INFO) << "Communicator was aborted before trying to dump its state.";
|
| 343 |
+
return dump;
|
| 344 |
+
}
|
| 345 |
+
C10D_NCCL_CHECK(::ncclCommDump(ncclComm_, dump), std::nullopt);
|
| 346 |
+
return dump;
|
| 347 |
+
}
|
| 348 |
+
#endif
|
| 349 |
+
|
| 350 |
+
ncclUniqueId getNcclId() {
|
| 351 |
+
return ncclId_;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
// Must not be copyable
|
| 355 |
+
NCCLComm(const NCCLComm&) = delete;
|
| 356 |
+
NCCLComm& operator=(const NCCLComm&) = delete;
|
| 357 |
+
|
| 358 |
+
// Do not support move assignment as there is no valid use case
|
| 359 |
+
NCCLComm& operator=(NCCLComm&& other) = delete;
|
| 360 |
+
|
| 361 |
+
// Move constructable
|
| 362 |
+
NCCLComm(NCCLComm&& other) {
|
| 363 |
+
// Using other's lock, as it reads other's states
|
| 364 |
+
// Can not use this.mutex_, as this object is being constructed.
|
| 365 |
+
std::unique_lock<std::mutex> lock(other.mutex_);
|
| 366 |
+
std::swap(ncclComm_, other.ncclComm_);
|
| 367 |
+
std::swap(aborted_, other.aborted_);
|
| 368 |
+
std::swap(ncclAsyncErr_, other.ncclAsyncErr_);
|
| 369 |
+
std::swap(initialized_, other.initialized_);
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
ncclComm_t getNcclComm();
|
| 373 |
+
|
| 374 |
+
std::optional<std::string> getNcclCommFailureReason() const {
|
| 375 |
+
std::unique_lock<std::mutex> lock(mutex_);
|
| 376 |
+
return commFailureReason_;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
void ncclCommAbort(
|
| 380 |
+
std::optional<std::string> commFailureReason = std::nullopt) {
|
| 381 |
+
std::unique_lock<std::mutex> lock(mutex_);
|
| 382 |
+
#ifdef ENABLE_NCCL_ERROR_CHECKING
|
| 383 |
+
if (aborted_ && !initialized_) {
|
| 384 |
+
// Should not abort twice.
|
| 385 |
+
return;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
#ifdef NCCL_HAS_COMM_REGISTER
|
| 389 |
+
// Deregister all registered segments before aborting.
|
| 390 |
+
for (auto& it : registeredSegmentHandles_) {
|
| 391 |
+
void* handle = it.second;
|
| 392 |
+
C10D_NCCL_CHECK(
|
| 393 |
+
::ncclCommDeregister(ncclComm_, handle),
|
| 394 |
+
c10::str(
|
| 395 |
+
"Failed to deregister segment handle ",
|
| 396 |
+
handle,
|
| 397 |
+
" on ncclComm_ ",
|
| 398 |
+
ncclComm_));
|
| 399 |
+
}
|
| 400 |
+
registeredSegmentHandles_.clear();
|
| 401 |
+
#endif
|
| 402 |
+
|
| 403 |
+
// Set true failure reason if provided by ProcessGroupNCCL (e.g. work
|
| 404 |
+
// timeout)
|
| 405 |
+
commFailureReason_ = commFailureReason;
|
| 406 |
+
LOG(INFO) << "Aborting ncclComm_ " << ncclComm_ << " with reason: "
|
| 407 |
+
<< (commFailureReason ? *commFailureReason
|
| 408 |
+
: "No abort reason provided.");
|
| 409 |
+
#ifndef NCCL_HAS_COMM_NONBLOCKING
|
| 410 |
+
C10D_NCCL_CHECK(::ncclCommAbort(ncclComm_), commFailureReason_);
|
| 411 |
+
#else
|
| 412 |
+
C10D_NCCL_CHECK_TIMEOUT(
|
| 413 |
+
::ncclCommAbort(ncclComm_), ncclComm_, commFailureReason_);
|
| 414 |
+
#endif
|
| 415 |
+
aborted_ = true;
|
| 416 |
+
ncclComm_ = nullptr;
|
| 417 |
+
|
| 418 |
+
// Set an appropriate error so that we avoid using the communicator.
|
| 419 |
+
if (ncclAsyncErr_ == ncclSuccess) {
|
| 420 |
+
ncclAsyncErr_ = ncclSystemError;
|
| 421 |
+
}
|
| 422 |
+
#else
|
| 423 |
+
// This is a NOOP, if error checks are disabled.
|
| 424 |
+
return;
|
| 425 |
+
#endif
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
bool isAborted() const {
|
| 429 |
+
std::unique_lock<std::mutex> lock(mutex_);
|
| 430 |
+
return aborted_;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
uint64_t getCommSplitCounter() const {
|
| 434 |
+
return ncclCommSplitCounter_;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
ncclResult_t checkForNcclError() {
|
| 438 |
+
std::unique_lock<std::mutex> lock(mutex_);
|
| 439 |
+
#ifdef ENABLE_NCCL_ERROR_CHECKING
|
| 440 |
+
if (ncclAsyncErr_ != ncclSuccess) {
|
| 441 |
+
return ncclAsyncErr_;
|
| 442 |
+
}
|
| 443 |
+
C10D_NCCL_CHECK(
|
| 444 |
+
ncclCommGetAsyncError(ncclComm_, &ncclAsyncErr_), commFailureReason_);
|
| 445 |
+
return ncclAsyncErr_;
|
| 446 |
+
#else
|
| 447 |
+
// Always return success, if error checks are disabled.
|
| 448 |
+
return ncclSuccess;
|
| 449 |
+
#endif
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
ncclResult_t registerSegment(void* ptr, size_t size) {
|
| 453 |
+
std::unique_lock<std::mutex> lock(mutex_);
|
| 454 |
+
#ifdef NCCL_HAS_COMM_REGISTER
|
| 455 |
+
// We register only segments from cache allocator
|
| 456 |
+
// which are guaranteed to be with disjoint addr ranges. Thus, a ptr always
|
| 457 |
+
// maps to a unique handle and should not be registered before the current
|
| 458 |
+
// ptr is deregistered and freed.
|
| 459 |
+
TORCH_CHECK(
|
| 460 |
+
registeredSegmentHandles_.count(ptr) == 0,
|
| 461 |
+
"Segment with ptr ",
|
| 462 |
+
ptr,
|
| 463 |
+
" has already been registered on ncclComm_ ",
|
| 464 |
+
ncclComm_);
|
| 465 |
+
|
| 466 |
+
void* handle;
|
| 467 |
+
C10D_NCCL_CHECK(
|
| 468 |
+
ncclCommRegister(ncclComm_, ptr, size, &handle),
|
| 469 |
+
c10::str(
|
| 470 |
+
"Failed to register segment with ptr ",
|
| 471 |
+
ptr,
|
| 472 |
+
", size ",
|
| 473 |
+
size,
|
| 474 |
+
" on ncclComm_ ",
|
| 475 |
+
ncclComm_));
|
| 476 |
+
registeredSegmentHandles_[ptr] = handle;
|
| 477 |
+
return ncclSuccess;
|
| 478 |
+
#else
|
| 479 |
+
return ncclInvalidUsage;
|
| 480 |
+
#endif
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
ncclResult_t deregisterSegment(void* ptr) {
|
| 484 |
+
std::unique_lock<std::mutex> lock(mutex_);
|
| 485 |
+
#ifdef NCCL_HAS_COMM_REGISTER
|
| 486 |
+
TORCH_CHECK(
|
| 487 |
+
registeredSegmentHandles_.count(ptr) == 1,
|
| 488 |
+
"Segment with ptr ",
|
| 489 |
+
ptr,
|
| 490 |
+
" is not registered on ncclComm_ ",
|
| 491 |
+
ncclComm_);
|
| 492 |
+
|
| 493 |
+
void* handle = registeredSegmentHandles_[ptr];
|
| 494 |
+
C10D_NCCL_CHECK(
|
| 495 |
+
ncclCommDeregister(ncclComm_, handle),
|
| 496 |
+
c10::str(
|
| 497 |
+
"Failed to deregister segment handle ",
|
| 498 |
+
handle,
|
| 499 |
+
", with ptr ",
|
| 500 |
+
ptr,
|
| 501 |
+
" on ncclComm_ ",
|
| 502 |
+
ncclComm_));
|
| 503 |
+
registeredSegmentHandles_.erase(ptr);
|
| 504 |
+
return ncclSuccess;
|
| 505 |
+
#else
|
| 506 |
+
return ncclInvalidUsage;
|
| 507 |
+
#endif
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
friend class ProcessGroupNCCL;
|
| 511 |
+
|
| 512 |
+
protected:
|
| 513 |
+
// a helper function to wait until the communicator is initialized;
|
| 514 |
+
void waitUntilInitialized(int timeoutSecs);
|
| 515 |
+
ncclComm_t ncclComm_;
|
| 516 |
+
// Unique nccl_id for this communicator.
|
| 517 |
+
ncclUniqueId ncclId_;
|
| 518 |
+
bool aborted_;
|
| 519 |
+
uint64_t ncclCommSplitCounter_{0};
|
| 520 |
+
ncclResult_t ncclAsyncErr_;
|
| 521 |
+
mutable std::mutex mutex_;
|
| 522 |
+
// Rank that this communicator corresponds to.
|
| 523 |
+
int rank_;
|
| 524 |
+
// Optional reason for communicator failure, provided by ProcessGroupNCCL for
|
| 525 |
+
// better error messaging.
|
| 526 |
+
std::optional<std::string> commFailureReason_;
|
| 527 |
+
bool initialized_{false};
|
| 528 |
+
#ifdef NCCL_HAS_COMM_REGISTER
|
| 529 |
+
// Stores handlers for tensors registered by NCCL
|
| 530 |
+
std::unordered_map<void*, void*> registeredSegmentHandles_;
|
| 531 |
+
#endif
|
| 532 |
+
};
|
| 533 |
+
|
| 534 |
+
// Helper that automatically cleans up premul sums.
|
| 535 |
+
struct ncclRedOpRAII {
|
| 536 |
+
ncclRedOpRAII() = default;
|
| 537 |
+
ncclRedOpRAII(ncclRedOp_t op) : op_(op) {}
|
| 538 |
+
ncclRedOpRAII(ncclRedOp_t op, ncclComm_t comm)
|
| 539 |
+
: op_(op), comm_(comm), premul_sum_(true) {}
|
| 540 |
+
ncclRedOpRAII(const ncclRedOpRAII&) = delete;
|
| 541 |
+
ncclRedOpRAII& operator=(const ncclRedOpRAII&) = delete;
|
| 542 |
+
ncclRedOpRAII(ncclRedOpRAII&& tmp) : ncclRedOpRAII() {
|
| 543 |
+
std::swap(tmp.op_, this->op_);
|
| 544 |
+
std::swap(tmp.comm_, this->comm_);
|
| 545 |
+
std::swap(tmp.premul_sum_, this->premul_sum_);
|
| 546 |
+
}
|
| 547 |
+
#if defined(ENABLE_NCCL_PREMUL_SUM_SUPPORT)
|
| 548 |
+
~ncclRedOpRAII() {
|
| 549 |
+
if (premul_sum_) {
|
| 550 |
+
ncclRedOpDestroy(op_, comm_);
|
| 551 |
+
}
|
| 552 |
+
}
|
| 553 |
+
#endif
|
| 554 |
+
operator ncclRedOp_t() const {
|
| 555 |
+
return op_;
|
| 556 |
+
}
|
| 557 |
+
ncclRedOp_t op_;
|
| 558 |
+
ncclComm_t comm_;
|
| 559 |
+
bool premul_sum_ = false;
|
| 560 |
+
};
|
| 561 |
+
|
| 562 |
+
/* Helper used by work::getDuration() and nccl flight recorder */
|
| 563 |
+
float getDurationFromEvent(
|
| 564 |
+
at::cuda::CUDAEvent& ncclStartEvent,
|
| 565 |
+
at::cuda::CUDAEvent& ncclEndEvent);
|
| 566 |
+
|
| 567 |
+
struct NCCLTraceBuffer {
|
| 568 |
+
static NCCLTraceBuffer* get() {
|
| 569 |
+
// intentionally leak on exit
|
| 570 |
+
// because this will hold python state that may get destructed
|
| 571 |
+
static NCCLTraceBuffer* instance = new NCCLTraceBuffer();
|
| 572 |
+
return instance;
|
| 573 |
+
}
|
| 574 |
+
NCCLTraceBuffer() {
|
| 575 |
+
max_entries_ = getCvarInt({"TORCH_NCCL_TRACE_BUFFER_SIZE"}, 0);
|
| 576 |
+
capture_cpp_stack_ = getCvarBool({"TORCH_NCCL_TRACE_CPP_STACK"}, false);
|
| 577 |
+
enabled_ = max_entries_ > 0;
|
| 578 |
+
}
|
| 579 |
+
using Event = at::cuda::CUDAEvent;
|
| 580 |
+
struct Entry {
|
| 581 |
+
size_t id_; // incremented id in the trace buffer
|
| 582 |
+
// used to figure out where in the circular entries
|
| 583 |
+
// buffer this entry will be located to
|
| 584 |
+
// update state information
|
| 585 |
+
size_t pg_id_;
|
| 586 |
+
std::tuple<std::string, std::string> pg_name_; // <group_name, group_desc>
|
| 587 |
+
|
| 588 |
+
// collective_seq_id and p2p_seq_id refer to actual kernel launches (e.g. 1
|
| 589 |
+
// per coalesced group).
|
| 590 |
+
// collective_seq_id only increments for true collective operations (over
|
| 591 |
+
// all ranks in the group). p2p_seq_id only increments over non-collective
|
| 592 |
+
// operations in the group. op_id refers to logical operations (e.g. one per
|
| 593 |
+
// op inside coalesced group)
|
| 594 |
+
size_t collective_seq_id_;
|
| 595 |
+
size_t p2p_seq_id_;
|
| 596 |
+
size_t op_id_;
|
| 597 |
+
std::string profiling_name_;
|
| 598 |
+
|
| 599 |
+
std::shared_ptr<torch::CapturedTraceback> traceback_;
|
| 600 |
+
// we borrow pointers to start_ and end_ so we can query the state
|
| 601 |
+
// on reporting. However, once the event is completed, the call
|
| 602 |
+
// to `complete` will clear these.
|
| 603 |
+
Event *start_, *end_;
|
| 604 |
+
|
| 605 |
+
// timestamp when the entry was created, likely close to the time the work
|
| 606 |
+
// was 'enqueued'- not necessarily started
|
| 607 |
+
c10::time_t time_created_;
|
| 608 |
+
|
| 609 |
+
// configured timeout for this entry
|
| 610 |
+
c10::time_t timeout_ms_;
|
| 611 |
+
|
| 612 |
+
// Is this a P2P event?
|
| 613 |
+
bool isP2P_;
|
| 614 |
+
|
| 615 |
+
std::optional<float> duration_;
|
| 616 |
+
|
| 617 |
+
// timestamp when our CPU threads discovered that the kernel started.
|
| 618 |
+
// will always be _after_ it actually started, and can be very late
|
| 619 |
+
// if the watchdog thread got stuck on CUDA APIs.
|
| 620 |
+
std::optional<c10::time_t> time_discovered_started_;
|
| 621 |
+
|
| 622 |
+
// timestamp when our CPU threads discovered that the kernel completed.
|
| 623 |
+
// will always be _after_ it actually complated, and can be the same time
|
| 624 |
+
// as the discovery of the start if the watchdog thread is stuck on CUDA
|
| 625 |
+
// APIs
|
| 626 |
+
std::optional<c10::time_t> time_discovered_completed_;
|
| 627 |
+
|
| 628 |
+
// size information for input/output tensors
|
| 629 |
+
c10::SmallVector<int, 4> input_dims_;
|
| 630 |
+
std::vector<c10::ScalarType> input_dtypes_;
|
| 631 |
+
c10::SmallVector<int, 4> output_dims_;
|
| 632 |
+
std::vector<c10::ScalarType> output_dtypes_;
|
| 633 |
+
c10::SmallVector<int64_t, 8> sizes_; // flattened from inputs, outputs
|
| 634 |
+
bool retired_ = false; // is this work entry no longer in the workMetaList_?
|
| 635 |
+
// a retired but not completed event has timed out
|
| 636 |
+
};
|
| 637 |
+
|
| 638 |
+
bool enabled_ = false;
|
| 639 |
+
bool capture_cpp_stack_ = false;
|
| 640 |
+
std::mutex mutex_;
|
| 641 |
+
std::vector<Entry> entries_;
|
| 642 |
+
size_t max_entries_ = 0;
|
| 643 |
+
size_t next_ = 0;
|
| 644 |
+
size_t id_ = 0;
|
| 645 |
+
std::map<size_t, std::shared_ptr<ProcessGroupStatus>> all_pg_status_ = {};
|
| 646 |
+
std::map<std::tuple<std::string, std::string>, std::vector<uint64_t>>
|
| 647 |
+
pg_name_to_ranks_ = {};
|
| 648 |
+
|
| 649 |
+
std::optional<size_t> record(
|
| 650 |
+
size_t pg_id,
|
| 651 |
+
const std::tuple<std::string, std::string>& pg_name,
|
| 652 |
+
size_t collective_seq_id,
|
| 653 |
+
size_t p2p_seq_id,
|
| 654 |
+
size_t op_id,
|
| 655 |
+
std::string profiling_name,
|
| 656 |
+
const std::vector<at::Tensor>& inputs,
|
| 657 |
+
const std::vector<at::Tensor>& outputs,
|
| 658 |
+
Event* start,
|
| 659 |
+
Event* end,
|
| 660 |
+
std::chrono::milliseconds timeout_ms,
|
| 661 |
+
std::shared_ptr<ProcessGroupStatus> pg_status,
|
| 662 |
+
bool isP2P);
|
| 663 |
+
|
| 664 |
+
void record_pg_ranks(
|
| 665 |
+
const std::tuple<std::string, std::string>& pg_name,
|
| 666 |
+
std::vector<uint64_t> ranks);
|
| 667 |
+
|
| 668 |
+
void update_state(Entry& r);
|
| 669 |
+
|
| 670 |
+
std::vector<Entry> dump_entries();
|
| 671 |
+
|
| 672 |
+
/*
|
| 673 |
+
Mark an Event as completed and free its events.
|
| 674 |
+
This is called by the watchdog thread, and is asynchronous from the
|
| 675 |
+
perspective of the main thread.
|
| 676 |
+
compute_duration defaults to true since retire_id is only called in the
|
| 677 |
+
watchdog thread, which is currently a place we call cuda APIs which may hang,
|
| 678 |
+
but care should be taken to avoid computing duration in any function that must
|
| 679 |
+
never hang. (timing must also be enabled for compute_duration - see
|
| 680 |
+
TORCH_NCCL_ENABLE_TIMING).
|
| 681 |
+
*/
|
| 682 |
+
void retire_id(std::optional<size_t> id, bool compute_duration = true);
|
| 683 |
+
|
| 684 |
+
const c10::List<c10::IValue> getCollectiveTrace(
|
| 685 |
+
bool includeStacktraces,
|
| 686 |
+
bool onlyActive);
|
| 687 |
+
|
| 688 |
+
// dump pg_entries
|
| 689 |
+
const c10::Dict<c10::IValue, c10::IValue> getPgConfig();
|
| 690 |
+
|
| 691 |
+
const std::map<std::string, std::map<std::string, std::string>>
|
| 692 |
+
getPgConfigJson();
|
| 693 |
+
|
| 694 |
+
// dump pg_status
|
| 695 |
+
const c10::Dict<c10::IValue, c10::IValue> getPgStatus();
|
| 696 |
+
|
| 697 |
+
const std::map<std::string, std::map<std::string, std::string>>
|
| 698 |
+
getPgStatusJson();
|
| 699 |
+
|
| 700 |
+
std::string dump_json(
|
| 701 |
+
const std::optional<std::unordered_map<
|
| 702 |
+
std::string,
|
| 703 |
+
std::unordered_map<std::string, std::string>>>& ncclDumpMap,
|
| 704 |
+
bool includeCollectives,
|
| 705 |
+
bool onlyActive);
|
| 706 |
+
|
| 707 |
+
// dump all collectives + ncclDumpMap
|
| 708 |
+
std::string dump(
|
| 709 |
+
const std::optional<std::unordered_map<
|
| 710 |
+
std::string,
|
| 711 |
+
std::unordered_map<std::string, std::string>>>& ncclDumpMap,
|
| 712 |
+
bool includeCollectives,
|
| 713 |
+
bool includeStackTraces,
|
| 714 |
+
bool onlyActive);
|
| 715 |
+
};
|
| 716 |
+
} // namespace c10d
|
| 717 |
+
|
| 718 |
+
#endif // USE_C10D_NCCL
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/ParamCommsUtils.hpp
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/core/ivalue.h>
|
| 4 |
+
#include <ATen/record_function.h>
|
| 5 |
+
#include <c10/macros/Macros.h>
|
| 6 |
+
#include <c10/util/ThreadLocalDebugInfo.h>
|
| 7 |
+
#include <string>
|
| 8 |
+
#include <vector>
|
| 9 |
+
|
| 10 |
+
namespace torch {
|
| 11 |
+
|
| 12 |
+
class TORCH_API ParamCommsDebugInfo : public c10::DebugInfoBase {
|
| 13 |
+
public:
|
| 14 |
+
ParamCommsDebugInfo() = default;
|
| 15 |
+
ParamCommsDebugInfo(
|
| 16 |
+
std::tuple<std::string, std::string> pgName,
|
| 17 |
+
int rank,
|
| 18 |
+
std::string&& collName,
|
| 19 |
+
int64_t inNelems,
|
| 20 |
+
int64_t outNelems,
|
| 21 |
+
at::ScalarType dType,
|
| 22 |
+
std::vector<int64_t> inSplitSizes,
|
| 23 |
+
std::vector<int64_t> outSplitSizes,
|
| 24 |
+
int globalRankStart,
|
| 25 |
+
int globalRankStride,
|
| 26 |
+
int worldSize);
|
| 27 |
+
|
| 28 |
+
~ParamCommsDebugInfo() override = default;
|
| 29 |
+
|
| 30 |
+
const std::string getProcessGroupName() const {
|
| 31 |
+
return std::get<0>(pgName_);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const std::string getProcessGroupDesc() const {
|
| 35 |
+
return std::get<1>(pgName_);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
int getRank() const {
|
| 39 |
+
return rank_;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
int getWorldSize() const {
|
| 43 |
+
return worldSize_;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
int getGlobalRankStart() const {
|
| 47 |
+
return globalRankStart_;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
int getGlobalRankStride() const {
|
| 51 |
+
return globalRankStride_;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
const std::string getCollectiveName() const {
|
| 55 |
+
return collectiveName_;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
int64_t getInMessageNelems() const {
|
| 59 |
+
return inMessageNelems_;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
int64_t getOutMessageNelems() const {
|
| 63 |
+
return outMessageNelems_;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
at::ScalarType getDType() const {
|
| 67 |
+
return dType_;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const std::vector<int64_t>& getInputSplitSizes() const {
|
| 71 |
+
return inputSplitSizes_;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
const std::vector<int64_t>& getOutputSplitSizes() const {
|
| 75 |
+
return outputSplitSizes_;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
const std::vector<int64_t>& getGroupRanks() const {
|
| 79 |
+
return groupRanks_;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
private:
|
| 83 |
+
std::tuple<std::string, std::string> pgName_; // <group_name, group_desc>
|
| 84 |
+
int rank_{};
|
| 85 |
+
int worldSize_{};
|
| 86 |
+
std::string collectiveName_;
|
| 87 |
+
int64_t inMessageNelems_{};
|
| 88 |
+
int64_t outMessageNelems_{};
|
| 89 |
+
at::ScalarType dType_ = at::kByte;
|
| 90 |
+
std::vector<int64_t> inputSplitSizes_;
|
| 91 |
+
std::vector<int64_t> outputSplitSizes_;
|
| 92 |
+
int globalRankStart_{};
|
| 93 |
+
int globalRankStride_{};
|
| 94 |
+
std::vector<int64_t> groupRanks_{};
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
#define RECORD_PARAM_COMMS( \
|
| 98 |
+
seq, \
|
| 99 |
+
pgName, \
|
| 100 |
+
rank, \
|
| 101 |
+
collName, \
|
| 102 |
+
inNelems, \
|
| 103 |
+
outNelems, \
|
| 104 |
+
dType, \
|
| 105 |
+
inSplitSizes, \
|
| 106 |
+
outSplitSizes, \
|
| 107 |
+
globalRankStart, \
|
| 108 |
+
globalRankStride, \
|
| 109 |
+
worldSize) \
|
| 110 |
+
auto paramCommsInfo = std::make_shared<torch::ParamCommsDebugInfo>( \
|
| 111 |
+
pgName, \
|
| 112 |
+
rank, \
|
| 113 |
+
collName, \
|
| 114 |
+
inNelems, \
|
| 115 |
+
outNelems, \
|
| 116 |
+
dType, \
|
| 117 |
+
inSplitSizes, \
|
| 118 |
+
outSplitSizes, \
|
| 119 |
+
globalRankStart, \
|
| 120 |
+
globalRankStride, \
|
| 121 |
+
worldSize); \
|
| 122 |
+
c10::DebugInfoGuard g(c10::DebugInfoKind::PARAM_COMMS_INFO, paramCommsInfo); \
|
| 123 |
+
std::initializer_list<const c10::IValue> paramList = { \
|
| 124 |
+
c10::IValue(seq), \
|
| 125 |
+
pgName, \
|
| 126 |
+
rank, \
|
| 127 |
+
collName, \
|
| 128 |
+
inSplitSizes, \
|
| 129 |
+
outSplitSizes, \
|
| 130 |
+
globalRankStart, \
|
| 131 |
+
globalRankStride, \
|
| 132 |
+
worldSize}; \
|
| 133 |
+
c10::ArrayRef<const c10::IValue> paramInputs(paramList); \
|
| 134 |
+
RECORD_FUNCTION(at::kParamCommsCallName, paramInputs);
|
| 135 |
+
|
| 136 |
+
#define RECORD_PARAM_COMMS_DATA( \
|
| 137 |
+
seq, \
|
| 138 |
+
pgName, \
|
| 139 |
+
InputTensors, \
|
| 140 |
+
OutputTensors, \
|
| 141 |
+
rank, \
|
| 142 |
+
collName, \
|
| 143 |
+
inNelems, \
|
| 144 |
+
outNelems, \
|
| 145 |
+
dType, \
|
| 146 |
+
inSplitSizes, \
|
| 147 |
+
outSplitSizes, \
|
| 148 |
+
globalRankStart, \
|
| 149 |
+
globalRankStride, \
|
| 150 |
+
worldSize) \
|
| 151 |
+
auto paramCommsInfo = std::make_shared<torch::ParamCommsDebugInfo>( \
|
| 152 |
+
pgName, \
|
| 153 |
+
rank, \
|
| 154 |
+
collName, \
|
| 155 |
+
inNelems, \
|
| 156 |
+
outNelems, \
|
| 157 |
+
dType, \
|
| 158 |
+
inSplitSizes, \
|
| 159 |
+
outSplitSizes, \
|
| 160 |
+
globalRankStart, \
|
| 161 |
+
globalRankStride, \
|
| 162 |
+
worldSize); \
|
| 163 |
+
c10::DebugInfoGuard g(c10::DebugInfoKind::PARAM_COMMS_INFO, paramCommsInfo); \
|
| 164 |
+
std::initializer_list<const c10::IValue> paramList = { \
|
| 165 |
+
c10::IValue(InputTensors), \
|
| 166 |
+
c10::IValue(seq), \
|
| 167 |
+
pgName, \
|
| 168 |
+
rank, \
|
| 169 |
+
collName, \
|
| 170 |
+
inSplitSizes, \
|
| 171 |
+
outSplitSizes, \
|
| 172 |
+
globalRankStart, \
|
| 173 |
+
globalRankStride, \
|
| 174 |
+
worldSize}; \
|
| 175 |
+
c10::ArrayRef<const c10::IValue> paramInputs(paramList); \
|
| 176 |
+
RECORD_FUNCTION_WITH_INPUTS_OUTPUTS( \
|
| 177 |
+
at::kParamCommsCallName, \
|
| 178 |
+
paramInputs, \
|
| 179 |
+
std::vector<c10::IValue>(1, c10::IValue(OutputTensors)));
|
| 180 |
+
} // namespace torch
|