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/_distutils/_log.py +3 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/_macos_compat.py +12 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/_msvccompiler.py +611 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/archive_util.py +264 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/core.py +289 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.py +339 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/dep_util.py +14 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/dir_util.py +244 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_dumb.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/__pycache__/test_build_ext.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/__pycache__/test_mingwccompiler.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_bdist_dumb.py +78 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_check.py +194 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_clean.py +45 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_dir_util.py +139 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_install_data.py +74 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_log.py +12 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_sysconfig.py +319 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/version.py +348 -0
- videollama2/lib/python3.10/site-packages/setuptools/_distutils/versionpredicate.py +175 -0
- vllm/lib/python3.10/site-packages/torch/include/THC/THCDeviceUtils.cuh +3 -0
- vllm/lib/python3.10/site-packages/torch/include/kineto/ClientInterface.h +22 -0
- vllm/lib/python3.10/site-packages/torch/include/kineto/LoggingAPI.h +14 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/channel/basic/factory.h +23 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/channel/cma/factory.h +23 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/channel/mpt/factory.h +27 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/buffer.h +135 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/cpu_buffer.h +23 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/cuda_buffer.h +24 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/device.h +64 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/error.h +127 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/optional.h +1020 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/config.h +14 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/core/context.h +96 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/tensorpipe.h +55 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/context.h +78 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/error.h +47 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/ibv/error.h +48 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/ibv/factory.h +23 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/ibv/utility.h +26 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/shm/factory.h +23 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/uv/error.h +38 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/uv/factory.h +23 -0
- vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/uv/utility.h +36 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/base.h +255 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h +63 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/stateless.h +82 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader_options.h +65 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/datasets/base.h +104 -0
- vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/datasets/chunk.h +529 -0
videollama2/lib/python3.10/site-packages/setuptools/_distutils/_log.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
+
log = logging.getLogger()
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/_macos_compat.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def bypass_compiler_fixup(cmd, args):
|
| 6 |
+
return cmd
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
if sys.platform == 'darwin':
|
| 10 |
+
compiler_fixup = importlib.import_module('_osx_support').compiler_fixup
|
| 11 |
+
else:
|
| 12 |
+
compiler_fixup = bypass_compiler_fixup
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/_msvccompiler.py
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils._msvccompiler
|
| 2 |
+
|
| 3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
| 4 |
+
for Microsoft Visual Studio 2015.
|
| 5 |
+
|
| 6 |
+
This module requires VS 2015 or later.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
# Written by Perry Stoll
|
| 10 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
| 11 |
+
# finding DevStudio (through the registry)
|
| 12 |
+
# ported to VS 2005 and VS 2008 by Christian Heimes
|
| 13 |
+
# ported to VS 2015 by Steve Dower
|
| 14 |
+
|
| 15 |
+
import contextlib
|
| 16 |
+
import os
|
| 17 |
+
import subprocess
|
| 18 |
+
import unittest.mock as mock
|
| 19 |
+
import warnings
|
| 20 |
+
|
| 21 |
+
with contextlib.suppress(ImportError):
|
| 22 |
+
import winreg
|
| 23 |
+
|
| 24 |
+
from itertools import count
|
| 25 |
+
|
| 26 |
+
from ._log import log
|
| 27 |
+
from .ccompiler import CCompiler, gen_lib_options
|
| 28 |
+
from .errors import (
|
| 29 |
+
CompileError,
|
| 30 |
+
DistutilsExecError,
|
| 31 |
+
DistutilsPlatformError,
|
| 32 |
+
LibError,
|
| 33 |
+
LinkError,
|
| 34 |
+
)
|
| 35 |
+
from .util import get_host_platform, get_platform
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _find_vc2015():
|
| 39 |
+
try:
|
| 40 |
+
key = winreg.OpenKeyEx(
|
| 41 |
+
winreg.HKEY_LOCAL_MACHINE,
|
| 42 |
+
r"Software\Microsoft\VisualStudio\SxS\VC7",
|
| 43 |
+
access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY,
|
| 44 |
+
)
|
| 45 |
+
except OSError:
|
| 46 |
+
log.debug("Visual C++ is not registered")
|
| 47 |
+
return None, None
|
| 48 |
+
|
| 49 |
+
best_version = 0
|
| 50 |
+
best_dir = None
|
| 51 |
+
with key:
|
| 52 |
+
for i in count():
|
| 53 |
+
try:
|
| 54 |
+
v, vc_dir, vt = winreg.EnumValue(key, i)
|
| 55 |
+
except OSError:
|
| 56 |
+
break
|
| 57 |
+
if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
|
| 58 |
+
try:
|
| 59 |
+
version = int(float(v))
|
| 60 |
+
except (ValueError, TypeError):
|
| 61 |
+
continue
|
| 62 |
+
if version >= 14 and version > best_version:
|
| 63 |
+
best_version, best_dir = version, vc_dir
|
| 64 |
+
return best_version, best_dir
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def _find_vc2017():
|
| 68 |
+
"""Returns "15, path" based on the result of invoking vswhere.exe
|
| 69 |
+
If no install is found, returns "None, None"
|
| 70 |
+
|
| 71 |
+
The version is returned to avoid unnecessarily changing the function
|
| 72 |
+
result. It may be ignored when the path is not None.
|
| 73 |
+
|
| 74 |
+
If vswhere.exe is not available, by definition, VS 2017 is not
|
| 75 |
+
installed.
|
| 76 |
+
"""
|
| 77 |
+
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
|
| 78 |
+
if not root:
|
| 79 |
+
return None, None
|
| 80 |
+
|
| 81 |
+
variant = 'arm64' if get_platform() == 'win-arm64' else 'x86.x64'
|
| 82 |
+
suitable_components = (
|
| 83 |
+
f"Microsoft.VisualStudio.Component.VC.Tools.{variant}",
|
| 84 |
+
"Microsoft.VisualStudio.Workload.WDExpress",
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
for component in suitable_components:
|
| 88 |
+
# Workaround for `-requiresAny` (only available on VS 2017 > 15.6)
|
| 89 |
+
with contextlib.suppress(
|
| 90 |
+
subprocess.CalledProcessError, OSError, UnicodeDecodeError
|
| 91 |
+
):
|
| 92 |
+
path = (
|
| 93 |
+
subprocess.check_output([
|
| 94 |
+
os.path.join(
|
| 95 |
+
root, "Microsoft Visual Studio", "Installer", "vswhere.exe"
|
| 96 |
+
),
|
| 97 |
+
"-latest",
|
| 98 |
+
"-prerelease",
|
| 99 |
+
"-requires",
|
| 100 |
+
component,
|
| 101 |
+
"-property",
|
| 102 |
+
"installationPath",
|
| 103 |
+
"-products",
|
| 104 |
+
"*",
|
| 105 |
+
])
|
| 106 |
+
.decode(encoding="mbcs", errors="strict")
|
| 107 |
+
.strip()
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
path = os.path.join(path, "VC", "Auxiliary", "Build")
|
| 111 |
+
if os.path.isdir(path):
|
| 112 |
+
return 15, path
|
| 113 |
+
|
| 114 |
+
return None, None # no suitable component found
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
PLAT_SPEC_TO_RUNTIME = {
|
| 118 |
+
'x86': 'x86',
|
| 119 |
+
'x86_amd64': 'x64',
|
| 120 |
+
'x86_arm': 'arm',
|
| 121 |
+
'x86_arm64': 'arm64',
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _find_vcvarsall(plat_spec):
|
| 126 |
+
# bpo-38597: Removed vcruntime return value
|
| 127 |
+
_, best_dir = _find_vc2017()
|
| 128 |
+
|
| 129 |
+
if not best_dir:
|
| 130 |
+
best_version, best_dir = _find_vc2015()
|
| 131 |
+
|
| 132 |
+
if not best_dir:
|
| 133 |
+
log.debug("No suitable Visual C++ version found")
|
| 134 |
+
return None, None
|
| 135 |
+
|
| 136 |
+
vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
|
| 137 |
+
if not os.path.isfile(vcvarsall):
|
| 138 |
+
log.debug("%s cannot be found", vcvarsall)
|
| 139 |
+
return None, None
|
| 140 |
+
|
| 141 |
+
return vcvarsall, None
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def _get_vc_env(plat_spec):
|
| 145 |
+
if os.getenv("DISTUTILS_USE_SDK"):
|
| 146 |
+
return {key.lower(): value for key, value in os.environ.items()}
|
| 147 |
+
|
| 148 |
+
vcvarsall, _ = _find_vcvarsall(plat_spec)
|
| 149 |
+
if not vcvarsall:
|
| 150 |
+
raise DistutilsPlatformError(
|
| 151 |
+
'Microsoft Visual C++ 14.0 or greater is required. '
|
| 152 |
+
'Get it with "Microsoft C++ Build Tools": '
|
| 153 |
+
'https://visualstudio.microsoft.com/visual-cpp-build-tools/'
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
try:
|
| 157 |
+
out = subprocess.check_output(
|
| 158 |
+
f'cmd /u /c "{vcvarsall}" {plat_spec} && set',
|
| 159 |
+
stderr=subprocess.STDOUT,
|
| 160 |
+
).decode('utf-16le', errors='replace')
|
| 161 |
+
except subprocess.CalledProcessError as exc:
|
| 162 |
+
log.error(exc.output)
|
| 163 |
+
raise DistutilsPlatformError(f"Error executing {exc.cmd}")
|
| 164 |
+
|
| 165 |
+
env = {
|
| 166 |
+
key.lower(): value
|
| 167 |
+
for key, _, value in (line.partition('=') for line in out.splitlines())
|
| 168 |
+
if key and value
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
return env
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def _find_exe(exe, paths=None):
|
| 175 |
+
"""Return path to an MSVC executable program.
|
| 176 |
+
|
| 177 |
+
Tries to find the program in several places: first, one of the
|
| 178 |
+
MSVC program search paths from the registry; next, the directories
|
| 179 |
+
in the PATH environment variable. If any of those work, return an
|
| 180 |
+
absolute path that is known to exist. If none of them work, just
|
| 181 |
+
return the original program name, 'exe'.
|
| 182 |
+
"""
|
| 183 |
+
if not paths:
|
| 184 |
+
paths = os.getenv('path').split(os.pathsep)
|
| 185 |
+
for p in paths:
|
| 186 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
| 187 |
+
if os.path.isfile(fn):
|
| 188 |
+
return fn
|
| 189 |
+
return exe
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
_vcvars_names = {
|
| 193 |
+
'win32': 'x86',
|
| 194 |
+
'win-amd64': 'amd64',
|
| 195 |
+
'win-arm32': 'arm',
|
| 196 |
+
'win-arm64': 'arm64',
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def _get_vcvars_spec(host_platform, platform):
|
| 201 |
+
"""
|
| 202 |
+
Given a host platform and platform, determine the spec for vcvarsall.
|
| 203 |
+
|
| 204 |
+
Uses the native MSVC host if the host platform would need expensive
|
| 205 |
+
emulation for x86.
|
| 206 |
+
|
| 207 |
+
>>> _get_vcvars_spec('win-arm64', 'win32')
|
| 208 |
+
'arm64_x86'
|
| 209 |
+
>>> _get_vcvars_spec('win-arm64', 'win-amd64')
|
| 210 |
+
'arm64_amd64'
|
| 211 |
+
|
| 212 |
+
Otherwise, always cross-compile from x86 to work with the
|
| 213 |
+
lighter-weight MSVC installs that do not include native 64-bit tools.
|
| 214 |
+
|
| 215 |
+
>>> _get_vcvars_spec('win32', 'win32')
|
| 216 |
+
'x86'
|
| 217 |
+
>>> _get_vcvars_spec('win-arm32', 'win-arm32')
|
| 218 |
+
'x86_arm'
|
| 219 |
+
>>> _get_vcvars_spec('win-amd64', 'win-arm64')
|
| 220 |
+
'x86_arm64'
|
| 221 |
+
"""
|
| 222 |
+
if host_platform != 'win-arm64':
|
| 223 |
+
host_platform = 'win32'
|
| 224 |
+
vc_hp = _vcvars_names[host_platform]
|
| 225 |
+
vc_plat = _vcvars_names[platform]
|
| 226 |
+
return vc_hp if vc_hp == vc_plat else f'{vc_hp}_{vc_plat}'
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
class MSVCCompiler(CCompiler):
|
| 230 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
| 231 |
+
as defined by the CCompiler abstract class."""
|
| 232 |
+
|
| 233 |
+
compiler_type = 'msvc'
|
| 234 |
+
|
| 235 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 236 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 237 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 238 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 239 |
+
# though, so it's worth thinking about.
|
| 240 |
+
executables = {}
|
| 241 |
+
|
| 242 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 243 |
+
_c_extensions = ['.c']
|
| 244 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 245 |
+
_rc_extensions = ['.rc']
|
| 246 |
+
_mc_extensions = ['.mc']
|
| 247 |
+
|
| 248 |
+
# Needed for the filename generation methods provided by the
|
| 249 |
+
# base class, CCompiler.
|
| 250 |
+
src_extensions = _c_extensions + _cpp_extensions + _rc_extensions + _mc_extensions
|
| 251 |
+
res_extension = '.res'
|
| 252 |
+
obj_extension = '.obj'
|
| 253 |
+
static_lib_extension = '.lib'
|
| 254 |
+
shared_lib_extension = '.dll'
|
| 255 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 256 |
+
exe_extension = '.exe'
|
| 257 |
+
|
| 258 |
+
def __init__(self, verbose=False, dry_run=False, force=False):
|
| 259 |
+
super().__init__(verbose, dry_run, force)
|
| 260 |
+
# target platform (.plat_name is consistent with 'bdist')
|
| 261 |
+
self.plat_name = None
|
| 262 |
+
self.initialized = False
|
| 263 |
+
|
| 264 |
+
@classmethod
|
| 265 |
+
def _configure(cls, vc_env):
|
| 266 |
+
"""
|
| 267 |
+
Set class-level include/lib dirs.
|
| 268 |
+
"""
|
| 269 |
+
cls.include_dirs = cls._parse_path(vc_env.get('include', ''))
|
| 270 |
+
cls.library_dirs = cls._parse_path(vc_env.get('lib', ''))
|
| 271 |
+
|
| 272 |
+
@staticmethod
|
| 273 |
+
def _parse_path(val):
|
| 274 |
+
return [dir.rstrip(os.sep) for dir in val.split(os.pathsep) if dir]
|
| 275 |
+
|
| 276 |
+
def initialize(self, plat_name=None):
|
| 277 |
+
# multi-init means we would need to check platform same each time...
|
| 278 |
+
assert not self.initialized, "don't init multiple times"
|
| 279 |
+
if plat_name is None:
|
| 280 |
+
plat_name = get_platform()
|
| 281 |
+
# sanity check for platforms to prevent obscure errors later.
|
| 282 |
+
if plat_name not in _vcvars_names:
|
| 283 |
+
raise DistutilsPlatformError(
|
| 284 |
+
f"--plat-name must be one of {tuple(_vcvars_names)}"
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
plat_spec = _get_vcvars_spec(get_host_platform(), plat_name)
|
| 288 |
+
|
| 289 |
+
vc_env = _get_vc_env(plat_spec)
|
| 290 |
+
if not vc_env:
|
| 291 |
+
raise DistutilsPlatformError(
|
| 292 |
+
"Unable to find a compatible Visual Studio installation."
|
| 293 |
+
)
|
| 294 |
+
self._configure(vc_env)
|
| 295 |
+
|
| 296 |
+
self._paths = vc_env.get('path', '')
|
| 297 |
+
paths = self._paths.split(os.pathsep)
|
| 298 |
+
self.cc = _find_exe("cl.exe", paths)
|
| 299 |
+
self.linker = _find_exe("link.exe", paths)
|
| 300 |
+
self.lib = _find_exe("lib.exe", paths)
|
| 301 |
+
self.rc = _find_exe("rc.exe", paths) # resource compiler
|
| 302 |
+
self.mc = _find_exe("mc.exe", paths) # message compiler
|
| 303 |
+
self.mt = _find_exe("mt.exe", paths) # message compiler
|
| 304 |
+
|
| 305 |
+
self.preprocess_options = None
|
| 306 |
+
# bpo-38597: Always compile with dynamic linking
|
| 307 |
+
# Future releases of Python 3.x will include all past
|
| 308 |
+
# versions of vcruntime*.dll for compatibility.
|
| 309 |
+
self.compile_options = ['/nologo', '/O2', '/W3', '/GL', '/DNDEBUG', '/MD']
|
| 310 |
+
|
| 311 |
+
self.compile_options_debug = [
|
| 312 |
+
'/nologo',
|
| 313 |
+
'/Od',
|
| 314 |
+
'/MDd',
|
| 315 |
+
'/Zi',
|
| 316 |
+
'/W3',
|
| 317 |
+
'/D_DEBUG',
|
| 318 |
+
]
|
| 319 |
+
|
| 320 |
+
ldflags = ['/nologo', '/INCREMENTAL:NO', '/LTCG']
|
| 321 |
+
|
| 322 |
+
ldflags_debug = ['/nologo', '/INCREMENTAL:NO', '/LTCG', '/DEBUG:FULL']
|
| 323 |
+
|
| 324 |
+
self.ldflags_exe = [*ldflags, '/MANIFEST:EMBED,ID=1']
|
| 325 |
+
self.ldflags_exe_debug = [*ldflags_debug, '/MANIFEST:EMBED,ID=1']
|
| 326 |
+
self.ldflags_shared = [
|
| 327 |
+
*ldflags,
|
| 328 |
+
'/DLL',
|
| 329 |
+
'/MANIFEST:EMBED,ID=2',
|
| 330 |
+
'/MANIFESTUAC:NO',
|
| 331 |
+
]
|
| 332 |
+
self.ldflags_shared_debug = [
|
| 333 |
+
*ldflags_debug,
|
| 334 |
+
'/DLL',
|
| 335 |
+
'/MANIFEST:EMBED,ID=2',
|
| 336 |
+
'/MANIFESTUAC:NO',
|
| 337 |
+
]
|
| 338 |
+
self.ldflags_static = [*ldflags]
|
| 339 |
+
self.ldflags_static_debug = [*ldflags_debug]
|
| 340 |
+
|
| 341 |
+
self._ldflags = {
|
| 342 |
+
(CCompiler.EXECUTABLE, None): self.ldflags_exe,
|
| 343 |
+
(CCompiler.EXECUTABLE, False): self.ldflags_exe,
|
| 344 |
+
(CCompiler.EXECUTABLE, True): self.ldflags_exe_debug,
|
| 345 |
+
(CCompiler.SHARED_OBJECT, None): self.ldflags_shared,
|
| 346 |
+
(CCompiler.SHARED_OBJECT, False): self.ldflags_shared,
|
| 347 |
+
(CCompiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
|
| 348 |
+
(CCompiler.SHARED_LIBRARY, None): self.ldflags_static,
|
| 349 |
+
(CCompiler.SHARED_LIBRARY, False): self.ldflags_static,
|
| 350 |
+
(CCompiler.SHARED_LIBRARY, True): self.ldflags_static_debug,
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
self.initialized = True
|
| 354 |
+
|
| 355 |
+
# -- Worker methods ------------------------------------------------
|
| 356 |
+
|
| 357 |
+
@property
|
| 358 |
+
def out_extensions(self):
|
| 359 |
+
return {
|
| 360 |
+
**super().out_extensions,
|
| 361 |
+
**{
|
| 362 |
+
ext: self.res_extension
|
| 363 |
+
for ext in self._rc_extensions + self._mc_extensions
|
| 364 |
+
},
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
def compile( # noqa: C901
|
| 368 |
+
self,
|
| 369 |
+
sources,
|
| 370 |
+
output_dir=None,
|
| 371 |
+
macros=None,
|
| 372 |
+
include_dirs=None,
|
| 373 |
+
debug=False,
|
| 374 |
+
extra_preargs=None,
|
| 375 |
+
extra_postargs=None,
|
| 376 |
+
depends=None,
|
| 377 |
+
):
|
| 378 |
+
if not self.initialized:
|
| 379 |
+
self.initialize()
|
| 380 |
+
compile_info = self._setup_compile(
|
| 381 |
+
output_dir, macros, include_dirs, sources, depends, extra_postargs
|
| 382 |
+
)
|
| 383 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
| 384 |
+
|
| 385 |
+
compile_opts = extra_preargs or []
|
| 386 |
+
compile_opts.append('/c')
|
| 387 |
+
if debug:
|
| 388 |
+
compile_opts.extend(self.compile_options_debug)
|
| 389 |
+
else:
|
| 390 |
+
compile_opts.extend(self.compile_options)
|
| 391 |
+
|
| 392 |
+
add_cpp_opts = False
|
| 393 |
+
|
| 394 |
+
for obj in objects:
|
| 395 |
+
try:
|
| 396 |
+
src, ext = build[obj]
|
| 397 |
+
except KeyError:
|
| 398 |
+
continue
|
| 399 |
+
if debug:
|
| 400 |
+
# pass the full pathname to MSVC in debug mode,
|
| 401 |
+
# this allows the debugger to find the source file
|
| 402 |
+
# without asking the user to browse for it
|
| 403 |
+
src = os.path.abspath(src)
|
| 404 |
+
|
| 405 |
+
# Anaconda/conda-forge customisation, we want our pdbs to be
|
| 406 |
+
# relocatable:
|
| 407 |
+
# https://developercommunity.visualstudio.com/comments/623156/view.html
|
| 408 |
+
d1trimfile_opts = []
|
| 409 |
+
if 'SRC_DIR' in os.environ and os.path.basename(self.cc) == "cl.exe":
|
| 410 |
+
d1trimfile_opts.append("/d1trimfile:" + os.environ['SRC_DIR'])
|
| 411 |
+
|
| 412 |
+
if ext in self._c_extensions:
|
| 413 |
+
input_opt = "/Tc" + src
|
| 414 |
+
elif ext in self._cpp_extensions:
|
| 415 |
+
input_opt = "/Tp" + src
|
| 416 |
+
add_cpp_opts = True
|
| 417 |
+
elif ext in self._rc_extensions:
|
| 418 |
+
# compile .RC to .RES file
|
| 419 |
+
input_opt = src
|
| 420 |
+
output_opt = "/fo" + obj
|
| 421 |
+
try:
|
| 422 |
+
self.spawn([self.rc] + pp_opts + [output_opt, input_opt])
|
| 423 |
+
except DistutilsExecError as msg:
|
| 424 |
+
raise CompileError(msg)
|
| 425 |
+
continue
|
| 426 |
+
elif ext in self._mc_extensions:
|
| 427 |
+
# Compile .MC to .RC file to .RES file.
|
| 428 |
+
# * '-h dir' specifies the directory for the
|
| 429 |
+
# generated include file
|
| 430 |
+
# * '-r dir' specifies the target directory of the
|
| 431 |
+
# generated RC file and the binary message resource
|
| 432 |
+
# it includes
|
| 433 |
+
#
|
| 434 |
+
# For now (since there are no options to change this),
|
| 435 |
+
# we use the source-directory for the include file and
|
| 436 |
+
# the build directory for the RC file and message
|
| 437 |
+
# resources. This works at least for win32all.
|
| 438 |
+
h_dir = os.path.dirname(src)
|
| 439 |
+
rc_dir = os.path.dirname(obj)
|
| 440 |
+
try:
|
| 441 |
+
# first compile .MC to .RC and .H file
|
| 442 |
+
self.spawn([self.mc, '-h', h_dir, '-r', rc_dir, src])
|
| 443 |
+
base, _ = os.path.splitext(os.path.basename(src))
|
| 444 |
+
rc_file = os.path.join(rc_dir, base + '.rc')
|
| 445 |
+
# then compile .RC to .RES file
|
| 446 |
+
self.spawn([self.rc, "/fo" + obj, rc_file])
|
| 447 |
+
|
| 448 |
+
except DistutilsExecError as msg:
|
| 449 |
+
raise CompileError(msg)
|
| 450 |
+
continue
|
| 451 |
+
else:
|
| 452 |
+
# how to handle this file?
|
| 453 |
+
raise CompileError(f"Don't know how to compile {src} to {obj}")
|
| 454 |
+
|
| 455 |
+
args = [self.cc] + compile_opts + pp_opts + d1trimfile_opts
|
| 456 |
+
if add_cpp_opts:
|
| 457 |
+
args.append('/EHsc')
|
| 458 |
+
args.extend((input_opt, "/Fo" + obj))
|
| 459 |
+
args.extend(extra_postargs)
|
| 460 |
+
|
| 461 |
+
try:
|
| 462 |
+
self.spawn(args)
|
| 463 |
+
except DistutilsExecError as msg:
|
| 464 |
+
raise CompileError(msg)
|
| 465 |
+
|
| 466 |
+
return objects
|
| 467 |
+
|
| 468 |
+
def create_static_lib(
|
| 469 |
+
self, objects, output_libname, output_dir=None, debug=False, target_lang=None
|
| 470 |
+
):
|
| 471 |
+
if not self.initialized:
|
| 472 |
+
self.initialize()
|
| 473 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 474 |
+
output_filename = self.library_filename(output_libname, output_dir=output_dir)
|
| 475 |
+
|
| 476 |
+
if self._need_link(objects, output_filename):
|
| 477 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
| 478 |
+
if debug:
|
| 479 |
+
pass # XXX what goes here?
|
| 480 |
+
try:
|
| 481 |
+
log.debug('Executing "%s" %s', self.lib, ' '.join(lib_args))
|
| 482 |
+
self.spawn([self.lib] + lib_args)
|
| 483 |
+
except DistutilsExecError as msg:
|
| 484 |
+
raise LibError(msg)
|
| 485 |
+
else:
|
| 486 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 487 |
+
|
| 488 |
+
def link(
|
| 489 |
+
self,
|
| 490 |
+
target_desc,
|
| 491 |
+
objects,
|
| 492 |
+
output_filename,
|
| 493 |
+
output_dir=None,
|
| 494 |
+
libraries=None,
|
| 495 |
+
library_dirs=None,
|
| 496 |
+
runtime_library_dirs=None,
|
| 497 |
+
export_symbols=None,
|
| 498 |
+
debug=False,
|
| 499 |
+
extra_preargs=None,
|
| 500 |
+
extra_postargs=None,
|
| 501 |
+
build_temp=None,
|
| 502 |
+
target_lang=None,
|
| 503 |
+
):
|
| 504 |
+
if not self.initialized:
|
| 505 |
+
self.initialize()
|
| 506 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 507 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
|
| 508 |
+
libraries, library_dirs, runtime_library_dirs = fixed_args
|
| 509 |
+
|
| 510 |
+
if runtime_library_dirs:
|
| 511 |
+
self.warn(
|
| 512 |
+
"I don't know what to do with 'runtime_library_dirs': "
|
| 513 |
+
+ str(runtime_library_dirs)
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
|
| 517 |
+
if output_dir is not None:
|
| 518 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 519 |
+
|
| 520 |
+
if self._need_link(objects, output_filename):
|
| 521 |
+
ldflags = self._ldflags[target_desc, debug]
|
| 522 |
+
|
| 523 |
+
export_opts = ["/EXPORT:" + sym for sym in (export_symbols or [])]
|
| 524 |
+
|
| 525 |
+
ld_args = (
|
| 526 |
+
ldflags + lib_opts + export_opts + objects + ['/OUT:' + output_filename]
|
| 527 |
+
)
|
| 528 |
+
|
| 529 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
| 530 |
+
# suppressed by any linker switches. The .lib files may even be
|
| 531 |
+
# needed! Make sure they are generated in the temporary build
|
| 532 |
+
# directory. Since they have different names for debug and release
|
| 533 |
+
# builds, they can go into the same directory.
|
| 534 |
+
build_temp = os.path.dirname(objects[0])
|
| 535 |
+
if export_symbols is not None:
|
| 536 |
+
(dll_name, dll_ext) = os.path.splitext(
|
| 537 |
+
os.path.basename(output_filename)
|
| 538 |
+
)
|
| 539 |
+
implib_file = os.path.join(build_temp, self.library_filename(dll_name))
|
| 540 |
+
ld_args.append('/IMPLIB:' + implib_file)
|
| 541 |
+
|
| 542 |
+
if extra_preargs:
|
| 543 |
+
ld_args[:0] = extra_preargs
|
| 544 |
+
if extra_postargs:
|
| 545 |
+
ld_args.extend(extra_postargs)
|
| 546 |
+
|
| 547 |
+
output_dir = os.path.dirname(os.path.abspath(output_filename))
|
| 548 |
+
self.mkpath(output_dir)
|
| 549 |
+
try:
|
| 550 |
+
log.debug('Executing "%s" %s', self.linker, ' '.join(ld_args))
|
| 551 |
+
self.spawn([self.linker] + ld_args)
|
| 552 |
+
except DistutilsExecError as msg:
|
| 553 |
+
raise LinkError(msg)
|
| 554 |
+
else:
|
| 555 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 556 |
+
|
| 557 |
+
def spawn(self, cmd):
|
| 558 |
+
env = dict(os.environ, PATH=self._paths)
|
| 559 |
+
with self._fallback_spawn(cmd, env) as fallback:
|
| 560 |
+
return super().spawn(cmd, env=env)
|
| 561 |
+
return fallback.value
|
| 562 |
+
|
| 563 |
+
@contextlib.contextmanager
|
| 564 |
+
def _fallback_spawn(self, cmd, env):
|
| 565 |
+
"""
|
| 566 |
+
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
|
| 567 |
+
so the 'env' kwarg causes a TypeError. Detect this condition and
|
| 568 |
+
restore the legacy, unsafe behavior.
|
| 569 |
+
"""
|
| 570 |
+
bag = type('Bag', (), {})()
|
| 571 |
+
try:
|
| 572 |
+
yield bag
|
| 573 |
+
except TypeError as exc:
|
| 574 |
+
if "unexpected keyword argument 'env'" not in str(exc):
|
| 575 |
+
raise
|
| 576 |
+
else:
|
| 577 |
+
return
|
| 578 |
+
warnings.warn("Fallback spawn triggered. Please update distutils monkeypatch.")
|
| 579 |
+
with mock.patch.dict('os.environ', env):
|
| 580 |
+
bag.value = super().spawn(cmd)
|
| 581 |
+
|
| 582 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 583 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 584 |
+
# ccompiler.py.
|
| 585 |
+
|
| 586 |
+
def library_dir_option(self, dir):
|
| 587 |
+
return "/LIBPATH:" + dir
|
| 588 |
+
|
| 589 |
+
def runtime_library_dir_option(self, dir):
|
| 590 |
+
raise DistutilsPlatformError(
|
| 591 |
+
"don't know how to set runtime library search path for MSVC"
|
| 592 |
+
)
|
| 593 |
+
|
| 594 |
+
def library_option(self, lib):
|
| 595 |
+
return self.library_filename(lib)
|
| 596 |
+
|
| 597 |
+
def find_library_file(self, dirs, lib, debug=False):
|
| 598 |
+
# Prefer a debugging library if found (and requested), but deal
|
| 599 |
+
# with it if we don't have one.
|
| 600 |
+
if debug:
|
| 601 |
+
try_names = [lib + "_d", lib]
|
| 602 |
+
else:
|
| 603 |
+
try_names = [lib]
|
| 604 |
+
for dir in dirs:
|
| 605 |
+
for name in try_names:
|
| 606 |
+
libfile = os.path.join(dir, self.library_filename(name))
|
| 607 |
+
if os.path.isfile(libfile):
|
| 608 |
+
return libfile
|
| 609 |
+
else:
|
| 610 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 611 |
+
return None
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/archive_util.py
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.archive_util
|
| 2 |
+
|
| 3 |
+
Utility functions for creating archive files (tarballs, zip files,
|
| 4 |
+
that sort of thing)."""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
import zipfile
|
| 10 |
+
except ImportError:
|
| 11 |
+
zipfile = None
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
from ._log import log
|
| 15 |
+
from .dir_util import mkpath
|
| 16 |
+
from .errors import DistutilsExecError
|
| 17 |
+
from .spawn import spawn
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
from pwd import getpwnam
|
| 21 |
+
except ImportError:
|
| 22 |
+
getpwnam = None
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
from grp import getgrnam
|
| 26 |
+
except ImportError:
|
| 27 |
+
getgrnam = None
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _get_gid(name):
|
| 31 |
+
"""Returns a gid, given a group name."""
|
| 32 |
+
if getgrnam is None or name is None:
|
| 33 |
+
return None
|
| 34 |
+
try:
|
| 35 |
+
result = getgrnam(name)
|
| 36 |
+
except KeyError:
|
| 37 |
+
result = None
|
| 38 |
+
if result is not None:
|
| 39 |
+
return result[2]
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _get_uid(name):
|
| 44 |
+
"""Returns an uid, given a user name."""
|
| 45 |
+
if getpwnam is None or name is None:
|
| 46 |
+
return None
|
| 47 |
+
try:
|
| 48 |
+
result = getpwnam(name)
|
| 49 |
+
except KeyError:
|
| 50 |
+
result = None
|
| 51 |
+
if result is not None:
|
| 52 |
+
return result[2]
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def make_tarball(
|
| 57 |
+
base_name,
|
| 58 |
+
base_dir,
|
| 59 |
+
compress="gzip",
|
| 60 |
+
verbose=False,
|
| 61 |
+
dry_run=False,
|
| 62 |
+
owner=None,
|
| 63 |
+
group=None,
|
| 64 |
+
):
|
| 65 |
+
"""Create a (possibly compressed) tar file from all the files under
|
| 66 |
+
'base_dir'.
|
| 67 |
+
|
| 68 |
+
'compress' must be "gzip" (the default), "bzip2", "xz", or None.
|
| 69 |
+
|
| 70 |
+
'owner' and 'group' can be used to define an owner and a group for the
|
| 71 |
+
archive that is being built. If not provided, the current owner and group
|
| 72 |
+
will be used.
|
| 73 |
+
|
| 74 |
+
The output tar file will be named 'base_dir' + ".tar", possibly plus
|
| 75 |
+
the appropriate compression extension (".gz", ".bz2", ".xz" or ".Z").
|
| 76 |
+
|
| 77 |
+
Returns the output filename.
|
| 78 |
+
"""
|
| 79 |
+
tar_compression = {
|
| 80 |
+
'gzip': 'gz',
|
| 81 |
+
'bzip2': 'bz2',
|
| 82 |
+
'xz': 'xz',
|
| 83 |
+
None: '',
|
| 84 |
+
}
|
| 85 |
+
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz'}
|
| 86 |
+
|
| 87 |
+
# flags for compression program, each element of list will be an argument
|
| 88 |
+
if compress is not None and compress not in compress_ext.keys():
|
| 89 |
+
raise ValueError(
|
| 90 |
+
"bad value for 'compress': must be None, 'gzip', 'bzip2', 'xz'"
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
archive_name = base_name + '.tar'
|
| 94 |
+
archive_name += compress_ext.get(compress, '')
|
| 95 |
+
|
| 96 |
+
mkpath(os.path.dirname(archive_name), dry_run=dry_run)
|
| 97 |
+
|
| 98 |
+
# creating the tarball
|
| 99 |
+
import tarfile # late import so Python build itself doesn't break
|
| 100 |
+
|
| 101 |
+
log.info('Creating tar archive')
|
| 102 |
+
|
| 103 |
+
uid = _get_uid(owner)
|
| 104 |
+
gid = _get_gid(group)
|
| 105 |
+
|
| 106 |
+
def _set_uid_gid(tarinfo):
|
| 107 |
+
if gid is not None:
|
| 108 |
+
tarinfo.gid = gid
|
| 109 |
+
tarinfo.gname = group
|
| 110 |
+
if uid is not None:
|
| 111 |
+
tarinfo.uid = uid
|
| 112 |
+
tarinfo.uname = owner
|
| 113 |
+
return tarinfo
|
| 114 |
+
|
| 115 |
+
if not dry_run:
|
| 116 |
+
tar = tarfile.open(archive_name, f'w|{tar_compression[compress]}')
|
| 117 |
+
try:
|
| 118 |
+
tar.add(base_dir, filter=_set_uid_gid)
|
| 119 |
+
finally:
|
| 120 |
+
tar.close()
|
| 121 |
+
|
| 122 |
+
return archive_name
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def make_zipfile(base_name, base_dir, verbose=False, dry_run=False): # noqa: C901
|
| 126 |
+
"""Create a zip file from all the files under 'base_dir'.
|
| 127 |
+
|
| 128 |
+
The output zip file will be named 'base_name' + ".zip". Uses either the
|
| 129 |
+
"zipfile" Python module (if available) or the InfoZIP "zip" utility
|
| 130 |
+
(if installed and found on the default search path). If neither tool is
|
| 131 |
+
available, raises DistutilsExecError. Returns the name of the output zip
|
| 132 |
+
file.
|
| 133 |
+
"""
|
| 134 |
+
zip_filename = base_name + ".zip"
|
| 135 |
+
mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
|
| 136 |
+
|
| 137 |
+
# If zipfile module is not available, try spawning an external
|
| 138 |
+
# 'zip' command.
|
| 139 |
+
if zipfile is None:
|
| 140 |
+
if verbose:
|
| 141 |
+
zipoptions = "-r"
|
| 142 |
+
else:
|
| 143 |
+
zipoptions = "-rq"
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run)
|
| 147 |
+
except DistutilsExecError:
|
| 148 |
+
# XXX really should distinguish between "couldn't find
|
| 149 |
+
# external 'zip' command" and "zip failed".
|
| 150 |
+
raise DistutilsExecError(
|
| 151 |
+
f"unable to create zip file '{zip_filename}': "
|
| 152 |
+
"could neither import the 'zipfile' module nor "
|
| 153 |
+
"find a standalone zip utility"
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
else:
|
| 157 |
+
log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir)
|
| 158 |
+
|
| 159 |
+
if not dry_run:
|
| 160 |
+
try:
|
| 161 |
+
zip = zipfile.ZipFile(
|
| 162 |
+
zip_filename, "w", compression=zipfile.ZIP_DEFLATED
|
| 163 |
+
)
|
| 164 |
+
except RuntimeError:
|
| 165 |
+
zip = zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_STORED)
|
| 166 |
+
|
| 167 |
+
with zip:
|
| 168 |
+
if base_dir != os.curdir:
|
| 169 |
+
path = os.path.normpath(os.path.join(base_dir, ''))
|
| 170 |
+
zip.write(path, path)
|
| 171 |
+
log.info("adding '%s'", path)
|
| 172 |
+
for dirpath, dirnames, filenames in os.walk(base_dir):
|
| 173 |
+
for name in dirnames:
|
| 174 |
+
path = os.path.normpath(os.path.join(dirpath, name, ''))
|
| 175 |
+
zip.write(path, path)
|
| 176 |
+
log.info("adding '%s'", path)
|
| 177 |
+
for name in filenames:
|
| 178 |
+
path = os.path.normpath(os.path.join(dirpath, name))
|
| 179 |
+
if os.path.isfile(path):
|
| 180 |
+
zip.write(path, path)
|
| 181 |
+
log.info("adding '%s'", path)
|
| 182 |
+
|
| 183 |
+
return zip_filename
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
ARCHIVE_FORMATS = {
|
| 187 |
+
'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
|
| 188 |
+
'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
|
| 189 |
+
'xztar': (make_tarball, [('compress', 'xz')], "xz'ed tar-file"),
|
| 190 |
+
'ztar': (make_tarball, [('compress', 'compress')], "compressed tar file"),
|
| 191 |
+
'tar': (make_tarball, [('compress', None)], "uncompressed tar file"),
|
| 192 |
+
'zip': (make_zipfile, [], "ZIP file"),
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def check_archive_formats(formats):
|
| 197 |
+
"""Returns the first format from the 'format' list that is unknown.
|
| 198 |
+
|
| 199 |
+
If all formats are known, returns None
|
| 200 |
+
"""
|
| 201 |
+
for format in formats:
|
| 202 |
+
if format not in ARCHIVE_FORMATS:
|
| 203 |
+
return format
|
| 204 |
+
return None
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def make_archive(
|
| 208 |
+
base_name,
|
| 209 |
+
format,
|
| 210 |
+
root_dir=None,
|
| 211 |
+
base_dir=None,
|
| 212 |
+
verbose=False,
|
| 213 |
+
dry_run=False,
|
| 214 |
+
owner=None,
|
| 215 |
+
group=None,
|
| 216 |
+
):
|
| 217 |
+
"""Create an archive file (eg. zip or tar).
|
| 218 |
+
|
| 219 |
+
'base_name' is the name of the file to create, minus any format-specific
|
| 220 |
+
extension; 'format' is the archive format: one of "zip", "tar", "gztar",
|
| 221 |
+
"bztar", "xztar", or "ztar".
|
| 222 |
+
|
| 223 |
+
'root_dir' is a directory that will be the root directory of the
|
| 224 |
+
archive; ie. we typically chdir into 'root_dir' before creating the
|
| 225 |
+
archive. 'base_dir' is the directory where we start archiving from;
|
| 226 |
+
ie. 'base_dir' will be the common prefix of all files and
|
| 227 |
+
directories in the archive. 'root_dir' and 'base_dir' both default
|
| 228 |
+
to the current directory. Returns the name of the archive file.
|
| 229 |
+
|
| 230 |
+
'owner' and 'group' are used when creating a tar archive. By default,
|
| 231 |
+
uses the current owner and group.
|
| 232 |
+
"""
|
| 233 |
+
save_cwd = os.getcwd()
|
| 234 |
+
if root_dir is not None:
|
| 235 |
+
log.debug("changing into '%s'", root_dir)
|
| 236 |
+
base_name = os.path.abspath(base_name)
|
| 237 |
+
if not dry_run:
|
| 238 |
+
os.chdir(root_dir)
|
| 239 |
+
|
| 240 |
+
if base_dir is None:
|
| 241 |
+
base_dir = os.curdir
|
| 242 |
+
|
| 243 |
+
kwargs = {'dry_run': dry_run}
|
| 244 |
+
|
| 245 |
+
try:
|
| 246 |
+
format_info = ARCHIVE_FORMATS[format]
|
| 247 |
+
except KeyError:
|
| 248 |
+
raise ValueError(f"unknown archive format '{format}'")
|
| 249 |
+
|
| 250 |
+
func = format_info[0]
|
| 251 |
+
kwargs.update(format_info[1])
|
| 252 |
+
|
| 253 |
+
if format != 'zip':
|
| 254 |
+
kwargs['owner'] = owner
|
| 255 |
+
kwargs['group'] = group
|
| 256 |
+
|
| 257 |
+
try:
|
| 258 |
+
filename = func(base_name, base_dir, **kwargs)
|
| 259 |
+
finally:
|
| 260 |
+
if root_dir is not None:
|
| 261 |
+
log.debug("changing back to '%s'", save_cwd)
|
| 262 |
+
os.chdir(save_cwd)
|
| 263 |
+
|
| 264 |
+
return filename
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/core.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.core
|
| 2 |
+
|
| 3 |
+
The only module that needs to be imported to use the Distutils; provides
|
| 4 |
+
the 'setup' function (which is to be called from the setup script). Also
|
| 5 |
+
indirectly provides the Distribution and Command classes, although they are
|
| 6 |
+
really defined in distutils.dist and distutils.cmd.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import sys
|
| 13 |
+
import tokenize
|
| 14 |
+
from collections.abc import Iterable
|
| 15 |
+
|
| 16 |
+
from .cmd import Command
|
| 17 |
+
from .debug import DEBUG
|
| 18 |
+
|
| 19 |
+
# Mainly import these so setup scripts can "from distutils.core import" them.
|
| 20 |
+
from .dist import Distribution
|
| 21 |
+
from .errors import (
|
| 22 |
+
CCompilerError,
|
| 23 |
+
DistutilsArgError,
|
| 24 |
+
DistutilsError,
|
| 25 |
+
DistutilsSetupError,
|
| 26 |
+
)
|
| 27 |
+
from .extension import Extension
|
| 28 |
+
|
| 29 |
+
__all__ = ['Distribution', 'Command', 'Extension', 'setup']
|
| 30 |
+
|
| 31 |
+
# This is a barebones help message generated displayed when the user
|
| 32 |
+
# runs the setup script with no arguments at all. More useful help
|
| 33 |
+
# is generated with various --help options: global help, list commands,
|
| 34 |
+
# and per-command help.
|
| 35 |
+
USAGE = """\
|
| 36 |
+
usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
|
| 37 |
+
or: %(script)s --help [cmd1 cmd2 ...]
|
| 38 |
+
or: %(script)s --help-commands
|
| 39 |
+
or: %(script)s cmd --help
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def gen_usage(script_name):
|
| 44 |
+
script = os.path.basename(script_name)
|
| 45 |
+
return USAGE % locals()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
|
| 49 |
+
_setup_stop_after = None
|
| 50 |
+
_setup_distribution = None
|
| 51 |
+
|
| 52 |
+
# Legal keyword arguments for the setup() function
|
| 53 |
+
setup_keywords = (
|
| 54 |
+
'distclass',
|
| 55 |
+
'script_name',
|
| 56 |
+
'script_args',
|
| 57 |
+
'options',
|
| 58 |
+
'name',
|
| 59 |
+
'version',
|
| 60 |
+
'author',
|
| 61 |
+
'author_email',
|
| 62 |
+
'maintainer',
|
| 63 |
+
'maintainer_email',
|
| 64 |
+
'url',
|
| 65 |
+
'license',
|
| 66 |
+
'description',
|
| 67 |
+
'long_description',
|
| 68 |
+
'keywords',
|
| 69 |
+
'platforms',
|
| 70 |
+
'classifiers',
|
| 71 |
+
'download_url',
|
| 72 |
+
'requires',
|
| 73 |
+
'provides',
|
| 74 |
+
'obsoletes',
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Legal keyword arguments for the Extension constructor
|
| 78 |
+
extension_keywords = (
|
| 79 |
+
'name',
|
| 80 |
+
'sources',
|
| 81 |
+
'include_dirs',
|
| 82 |
+
'define_macros',
|
| 83 |
+
'undef_macros',
|
| 84 |
+
'library_dirs',
|
| 85 |
+
'libraries',
|
| 86 |
+
'runtime_library_dirs',
|
| 87 |
+
'extra_objects',
|
| 88 |
+
'extra_compile_args',
|
| 89 |
+
'extra_link_args',
|
| 90 |
+
'swig_opts',
|
| 91 |
+
'export_symbols',
|
| 92 |
+
'depends',
|
| 93 |
+
'language',
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def setup(**attrs): # noqa: C901
|
| 98 |
+
"""The gateway to the Distutils: do everything your setup script needs
|
| 99 |
+
to do, in a highly flexible and user-driven way. Briefly: create a
|
| 100 |
+
Distribution instance; find and parse config files; parse the command
|
| 101 |
+
line; run each Distutils command found there, customized by the options
|
| 102 |
+
supplied to 'setup()' (as keyword arguments), in config files, and on
|
| 103 |
+
the command line.
|
| 104 |
+
|
| 105 |
+
The Distribution instance might be an instance of a class supplied via
|
| 106 |
+
the 'distclass' keyword argument to 'setup'; if no such class is
|
| 107 |
+
supplied, then the Distribution class (in dist.py) is instantiated.
|
| 108 |
+
All other arguments to 'setup' (except for 'cmdclass') are used to set
|
| 109 |
+
attributes of the Distribution instance.
|
| 110 |
+
|
| 111 |
+
The 'cmdclass' argument, if supplied, is a dictionary mapping command
|
| 112 |
+
names to command classes. Each command encountered on the command line
|
| 113 |
+
will be turned into a command class, which is in turn instantiated; any
|
| 114 |
+
class found in 'cmdclass' is used in place of the default, which is
|
| 115 |
+
(for command 'foo_bar') class 'foo_bar' in module
|
| 116 |
+
'distutils.command.foo_bar'. The command class must provide a
|
| 117 |
+
'user_options' attribute which is a list of option specifiers for
|
| 118 |
+
'distutils.fancy_getopt'. Any command-line options between the current
|
| 119 |
+
and the next command are used to set attributes of the current command
|
| 120 |
+
object.
|
| 121 |
+
|
| 122 |
+
When the entire command-line has been successfully parsed, calls the
|
| 123 |
+
'run()' method on each command object in turn. This method will be
|
| 124 |
+
driven entirely by the Distribution object (which each command object
|
| 125 |
+
has a reference to, thanks to its constructor), and the
|
| 126 |
+
command-specific options that became attributes of each command
|
| 127 |
+
object.
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
global _setup_stop_after, _setup_distribution
|
| 131 |
+
|
| 132 |
+
# Determine the distribution class -- either caller-supplied or
|
| 133 |
+
# our Distribution (see below).
|
| 134 |
+
klass = attrs.get('distclass')
|
| 135 |
+
if klass:
|
| 136 |
+
attrs.pop('distclass')
|
| 137 |
+
else:
|
| 138 |
+
klass = Distribution
|
| 139 |
+
|
| 140 |
+
if 'script_name' not in attrs:
|
| 141 |
+
attrs['script_name'] = os.path.basename(sys.argv[0])
|
| 142 |
+
if 'script_args' not in attrs:
|
| 143 |
+
attrs['script_args'] = sys.argv[1:]
|
| 144 |
+
|
| 145 |
+
# Create the Distribution instance, using the remaining arguments
|
| 146 |
+
# (ie. everything except distclass) to initialize it
|
| 147 |
+
try:
|
| 148 |
+
_setup_distribution = dist = klass(attrs)
|
| 149 |
+
except DistutilsSetupError as msg:
|
| 150 |
+
if 'name' not in attrs:
|
| 151 |
+
raise SystemExit(f"error in setup command: {msg}")
|
| 152 |
+
else:
|
| 153 |
+
raise SystemExit("error in {} setup command: {}".format(attrs['name'], msg))
|
| 154 |
+
|
| 155 |
+
if _setup_stop_after == "init":
|
| 156 |
+
return dist
|
| 157 |
+
|
| 158 |
+
# Find and parse the config file(s): they will override options from
|
| 159 |
+
# the setup script, but be overridden by the command line.
|
| 160 |
+
dist.parse_config_files()
|
| 161 |
+
|
| 162 |
+
if DEBUG:
|
| 163 |
+
print("options (after parsing config files):")
|
| 164 |
+
dist.dump_option_dicts()
|
| 165 |
+
|
| 166 |
+
if _setup_stop_after == "config":
|
| 167 |
+
return dist
|
| 168 |
+
|
| 169 |
+
# Parse the command line and override config files; any
|
| 170 |
+
# command-line errors are the end user's fault, so turn them into
|
| 171 |
+
# SystemExit to suppress tracebacks.
|
| 172 |
+
try:
|
| 173 |
+
ok = dist.parse_command_line()
|
| 174 |
+
except DistutilsArgError as msg:
|
| 175 |
+
raise SystemExit(gen_usage(dist.script_name) + f"\nerror: {msg}")
|
| 176 |
+
|
| 177 |
+
if DEBUG:
|
| 178 |
+
print("options (after parsing command line):")
|
| 179 |
+
dist.dump_option_dicts()
|
| 180 |
+
|
| 181 |
+
if _setup_stop_after == "commandline":
|
| 182 |
+
return dist
|
| 183 |
+
|
| 184 |
+
# And finally, run all the commands found on the command line.
|
| 185 |
+
if ok:
|
| 186 |
+
return run_commands(dist)
|
| 187 |
+
|
| 188 |
+
return dist
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
# setup ()
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def run_commands(dist):
|
| 195 |
+
"""Given a Distribution object run all the commands,
|
| 196 |
+
raising ``SystemExit`` errors in the case of failure.
|
| 197 |
+
|
| 198 |
+
This function assumes that either ``sys.argv`` or ``dist.script_args``
|
| 199 |
+
is already set accordingly.
|
| 200 |
+
"""
|
| 201 |
+
try:
|
| 202 |
+
dist.run_commands()
|
| 203 |
+
except KeyboardInterrupt:
|
| 204 |
+
raise SystemExit("interrupted")
|
| 205 |
+
except OSError as exc:
|
| 206 |
+
if DEBUG:
|
| 207 |
+
sys.stderr.write(f"error: {exc}\n")
|
| 208 |
+
raise
|
| 209 |
+
else:
|
| 210 |
+
raise SystemExit(f"error: {exc}")
|
| 211 |
+
|
| 212 |
+
except (DistutilsError, CCompilerError) as msg:
|
| 213 |
+
if DEBUG:
|
| 214 |
+
raise
|
| 215 |
+
else:
|
| 216 |
+
raise SystemExit("error: " + str(msg))
|
| 217 |
+
|
| 218 |
+
return dist
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def run_setup(script_name, script_args: Iterable[str] | None = None, stop_after="run"):
|
| 222 |
+
"""Run a setup script in a somewhat controlled environment, and
|
| 223 |
+
return the Distribution instance that drives things. This is useful
|
| 224 |
+
if you need to find out the distribution meta-data (passed as
|
| 225 |
+
keyword args from 'script' to 'setup()', or the contents of the
|
| 226 |
+
config files or command-line.
|
| 227 |
+
|
| 228 |
+
'script_name' is a file that will be read and run with 'exec()';
|
| 229 |
+
'sys.argv[0]' will be replaced with 'script' for the duration of the
|
| 230 |
+
call. 'script_args' is a list of strings; if supplied,
|
| 231 |
+
'sys.argv[1:]' will be replaced by 'script_args' for the duration of
|
| 232 |
+
the call.
|
| 233 |
+
|
| 234 |
+
'stop_after' tells 'setup()' when to stop processing; possible
|
| 235 |
+
values:
|
| 236 |
+
init
|
| 237 |
+
stop after the Distribution instance has been created and
|
| 238 |
+
populated with the keyword arguments to 'setup()'
|
| 239 |
+
config
|
| 240 |
+
stop after config files have been parsed (and their data
|
| 241 |
+
stored in the Distribution instance)
|
| 242 |
+
commandline
|
| 243 |
+
stop after the command-line ('sys.argv[1:]' or 'script_args')
|
| 244 |
+
have been parsed (and the data stored in the Distribution)
|
| 245 |
+
run [default]
|
| 246 |
+
stop after all commands have been run (the same as if 'setup()'
|
| 247 |
+
had been called in the usual way
|
| 248 |
+
|
| 249 |
+
Returns the Distribution instance, which provides all information
|
| 250 |
+
used to drive the Distutils.
|
| 251 |
+
"""
|
| 252 |
+
if stop_after not in ('init', 'config', 'commandline', 'run'):
|
| 253 |
+
raise ValueError(f"invalid value for 'stop_after': {stop_after!r}")
|
| 254 |
+
|
| 255 |
+
global _setup_stop_after, _setup_distribution
|
| 256 |
+
_setup_stop_after = stop_after
|
| 257 |
+
|
| 258 |
+
save_argv = sys.argv.copy()
|
| 259 |
+
g = {'__file__': script_name, '__name__': '__main__'}
|
| 260 |
+
try:
|
| 261 |
+
try:
|
| 262 |
+
sys.argv[0] = script_name
|
| 263 |
+
if script_args is not None:
|
| 264 |
+
sys.argv[1:] = script_args
|
| 265 |
+
# tokenize.open supports automatic encoding detection
|
| 266 |
+
with tokenize.open(script_name) as f:
|
| 267 |
+
code = f.read().replace(r'\r\n', r'\n')
|
| 268 |
+
exec(code, g)
|
| 269 |
+
finally:
|
| 270 |
+
sys.argv = save_argv
|
| 271 |
+
_setup_stop_after = None
|
| 272 |
+
except SystemExit:
|
| 273 |
+
# Hmm, should we do something if exiting with a non-zero code
|
| 274 |
+
# (ie. error)?
|
| 275 |
+
pass
|
| 276 |
+
|
| 277 |
+
if _setup_distribution is None:
|
| 278 |
+
raise RuntimeError(
|
| 279 |
+
"'distutils.core.setup()' was never called -- "
|
| 280 |
+
f"perhaps '{script_name}' is not a Distutils setup script?"
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
# I wonder if the setup script's namespace -- g and l -- would be of
|
| 284 |
+
# any interest to callers?
|
| 285 |
+
# print "_setup_distribution:", _setup_distribution
|
| 286 |
+
return _setup_distribution
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
# run_setup ()
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.cygwinccompiler
|
| 2 |
+
|
| 3 |
+
Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
|
| 4 |
+
handles the Cygwin port of the GNU C compiler to Windows. It also contains
|
| 5 |
+
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
|
| 6 |
+
cygwin in no-cygwin mode).
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import copy
|
| 10 |
+
import os
|
| 11 |
+
import pathlib
|
| 12 |
+
import shlex
|
| 13 |
+
import sys
|
| 14 |
+
import warnings
|
| 15 |
+
from subprocess import check_output
|
| 16 |
+
|
| 17 |
+
from .errors import (
|
| 18 |
+
CCompilerError,
|
| 19 |
+
CompileError,
|
| 20 |
+
DistutilsExecError,
|
| 21 |
+
DistutilsPlatformError,
|
| 22 |
+
)
|
| 23 |
+
from .file_util import write_file
|
| 24 |
+
from .sysconfig import get_config_vars
|
| 25 |
+
from .unixccompiler import UnixCCompiler
|
| 26 |
+
from .version import LooseVersion, suppress_known_deprecation
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def get_msvcr():
|
| 30 |
+
"""No longer needed, but kept for backward compatibility."""
|
| 31 |
+
return []
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
_runtime_library_dirs_msg = (
|
| 35 |
+
"Unable to set runtime library search path on Windows, "
|
| 36 |
+
"usually indicated by `runtime_library_dirs` parameter to Extension"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class CygwinCCompiler(UnixCCompiler):
|
| 41 |
+
"""Handles the Cygwin port of the GNU C compiler to Windows."""
|
| 42 |
+
|
| 43 |
+
compiler_type = 'cygwin'
|
| 44 |
+
obj_extension = ".o"
|
| 45 |
+
static_lib_extension = ".a"
|
| 46 |
+
shared_lib_extension = ".dll.a"
|
| 47 |
+
dylib_lib_extension = ".dll"
|
| 48 |
+
static_lib_format = "lib%s%s"
|
| 49 |
+
shared_lib_format = "lib%s%s"
|
| 50 |
+
dylib_lib_format = "cyg%s%s"
|
| 51 |
+
exe_extension = ".exe"
|
| 52 |
+
|
| 53 |
+
def __init__(self, verbose=False, dry_run=False, force=False):
|
| 54 |
+
super().__init__(verbose, dry_run, force)
|
| 55 |
+
|
| 56 |
+
status, details = check_config_h()
|
| 57 |
+
self.debug_print(f"Python's GCC status: {status} (details: {details})")
|
| 58 |
+
if status is not CONFIG_H_OK:
|
| 59 |
+
self.warn(
|
| 60 |
+
"Python's pyconfig.h doesn't seem to support your compiler. "
|
| 61 |
+
f"Reason: {details}. "
|
| 62 |
+
"Compiling may fail because of undefined preprocessor macros."
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
self.cc, self.cxx = get_config_vars('CC', 'CXX')
|
| 66 |
+
|
| 67 |
+
# Override 'CC' and 'CXX' environment variables for
|
| 68 |
+
# building using MINGW compiler for MSVC python.
|
| 69 |
+
self.cc = os.environ.get('CC', self.cc or 'gcc')
|
| 70 |
+
self.cxx = os.environ.get('CXX', self.cxx or 'g++')
|
| 71 |
+
|
| 72 |
+
self.linker_dll = self.cc
|
| 73 |
+
self.linker_dll_cxx = self.cxx
|
| 74 |
+
shared_option = "-shared"
|
| 75 |
+
|
| 76 |
+
self.set_executables(
|
| 77 |
+
compiler=f'{self.cc} -mcygwin -O -Wall',
|
| 78 |
+
compiler_so=f'{self.cc} -mcygwin -mdll -O -Wall',
|
| 79 |
+
compiler_cxx=f'{self.cxx} -mcygwin -O -Wall',
|
| 80 |
+
compiler_so_cxx=f'{self.cxx} -mcygwin -mdll -O -Wall',
|
| 81 |
+
linker_exe=f'{self.cc} -mcygwin',
|
| 82 |
+
linker_so=f'{self.linker_dll} -mcygwin {shared_option}',
|
| 83 |
+
linker_exe_cxx=f'{self.cxx} -mcygwin',
|
| 84 |
+
linker_so_cxx=f'{self.linker_dll_cxx} -mcygwin {shared_option}',
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
self.dll_libraries = get_msvcr()
|
| 88 |
+
|
| 89 |
+
@property
|
| 90 |
+
def gcc_version(self):
|
| 91 |
+
# Older numpy depended on this existing to check for ancient
|
| 92 |
+
# gcc versions. This doesn't make much sense with clang etc so
|
| 93 |
+
# just hardcode to something recent.
|
| 94 |
+
# https://github.com/numpy/numpy/pull/20333
|
| 95 |
+
warnings.warn(
|
| 96 |
+
"gcc_version attribute of CygwinCCompiler is deprecated. "
|
| 97 |
+
"Instead of returning actual gcc version a fixed value 11.2.0 is returned.",
|
| 98 |
+
DeprecationWarning,
|
| 99 |
+
stacklevel=2,
|
| 100 |
+
)
|
| 101 |
+
with suppress_known_deprecation():
|
| 102 |
+
return LooseVersion("11.2.0")
|
| 103 |
+
|
| 104 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 105 |
+
"""Compiles the source by spawning GCC and windres if needed."""
|
| 106 |
+
if ext in ('.rc', '.res'):
|
| 107 |
+
# gcc needs '.res' and '.rc' compiled to object files !!!
|
| 108 |
+
try:
|
| 109 |
+
self.spawn(["windres", "-i", src, "-o", obj])
|
| 110 |
+
except DistutilsExecError as msg:
|
| 111 |
+
raise CompileError(msg)
|
| 112 |
+
else: # for other files use the C-compiler
|
| 113 |
+
try:
|
| 114 |
+
if self.detect_language(src) == 'c++':
|
| 115 |
+
self.spawn(
|
| 116 |
+
self.compiler_so_cxx
|
| 117 |
+
+ cc_args
|
| 118 |
+
+ [src, '-o', obj]
|
| 119 |
+
+ extra_postargs
|
| 120 |
+
)
|
| 121 |
+
else:
|
| 122 |
+
self.spawn(
|
| 123 |
+
self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs
|
| 124 |
+
)
|
| 125 |
+
except DistutilsExecError as msg:
|
| 126 |
+
raise CompileError(msg)
|
| 127 |
+
|
| 128 |
+
def link(
|
| 129 |
+
self,
|
| 130 |
+
target_desc,
|
| 131 |
+
objects,
|
| 132 |
+
output_filename,
|
| 133 |
+
output_dir=None,
|
| 134 |
+
libraries=None,
|
| 135 |
+
library_dirs=None,
|
| 136 |
+
runtime_library_dirs=None,
|
| 137 |
+
export_symbols=None,
|
| 138 |
+
debug=False,
|
| 139 |
+
extra_preargs=None,
|
| 140 |
+
extra_postargs=None,
|
| 141 |
+
build_temp=None,
|
| 142 |
+
target_lang=None,
|
| 143 |
+
):
|
| 144 |
+
"""Link the objects."""
|
| 145 |
+
# use separate copies, so we can modify the lists
|
| 146 |
+
extra_preargs = copy.copy(extra_preargs or [])
|
| 147 |
+
libraries = copy.copy(libraries or [])
|
| 148 |
+
objects = copy.copy(objects or [])
|
| 149 |
+
|
| 150 |
+
if runtime_library_dirs:
|
| 151 |
+
self.warn(_runtime_library_dirs_msg)
|
| 152 |
+
|
| 153 |
+
# Additional libraries
|
| 154 |
+
libraries.extend(self.dll_libraries)
|
| 155 |
+
|
| 156 |
+
# handle export symbols by creating a def-file
|
| 157 |
+
# with executables this only works with gcc/ld as linker
|
| 158 |
+
if (export_symbols is not None) and (
|
| 159 |
+
target_desc != self.EXECUTABLE or self.linker_dll == "gcc"
|
| 160 |
+
):
|
| 161 |
+
# (The linker doesn't do anything if output is up-to-date.
|
| 162 |
+
# So it would probably better to check if we really need this,
|
| 163 |
+
# but for this we had to insert some unchanged parts of
|
| 164 |
+
# UnixCCompiler, and this is not what we want.)
|
| 165 |
+
|
| 166 |
+
# we want to put some files in the same directory as the
|
| 167 |
+
# object files are, build_temp doesn't help much
|
| 168 |
+
# where are the object files
|
| 169 |
+
temp_dir = os.path.dirname(objects[0])
|
| 170 |
+
# name of dll to give the helper files the same base name
|
| 171 |
+
(dll_name, dll_extension) = os.path.splitext(
|
| 172 |
+
os.path.basename(output_filename)
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
# generate the filenames for these files
|
| 176 |
+
def_file = os.path.join(temp_dir, dll_name + ".def")
|
| 177 |
+
|
| 178 |
+
# Generate .def file
|
| 179 |
+
contents = [f"LIBRARY {os.path.basename(output_filename)}", "EXPORTS"]
|
| 180 |
+
contents.extend(export_symbols)
|
| 181 |
+
self.execute(write_file, (def_file, contents), f"writing {def_file}")
|
| 182 |
+
|
| 183 |
+
# next add options for def-file
|
| 184 |
+
|
| 185 |
+
# for gcc/ld the def-file is specified as any object files
|
| 186 |
+
objects.append(def_file)
|
| 187 |
+
|
| 188 |
+
# end: if ((export_symbols is not None) and
|
| 189 |
+
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
| 190 |
+
|
| 191 |
+
# who wants symbols and a many times larger output file
|
| 192 |
+
# should explicitly switch the debug mode on
|
| 193 |
+
# otherwise we let ld strip the output file
|
| 194 |
+
# (On my machine: 10KiB < stripped_file < ??100KiB
|
| 195 |
+
# unstripped_file = stripped_file + XXX KiB
|
| 196 |
+
# ( XXX=254 for a typical python extension))
|
| 197 |
+
if not debug:
|
| 198 |
+
extra_preargs.append("-s")
|
| 199 |
+
|
| 200 |
+
UnixCCompiler.link(
|
| 201 |
+
self,
|
| 202 |
+
target_desc,
|
| 203 |
+
objects,
|
| 204 |
+
output_filename,
|
| 205 |
+
output_dir,
|
| 206 |
+
libraries,
|
| 207 |
+
library_dirs,
|
| 208 |
+
runtime_library_dirs,
|
| 209 |
+
None, # export_symbols, we do this in our def-file
|
| 210 |
+
debug,
|
| 211 |
+
extra_preargs,
|
| 212 |
+
extra_postargs,
|
| 213 |
+
build_temp,
|
| 214 |
+
target_lang,
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
def runtime_library_dir_option(self, dir):
|
| 218 |
+
# cygwin doesn't support rpath. While in theory we could error
|
| 219 |
+
# out like MSVC does, code might expect it to work like on Unix, so
|
| 220 |
+
# just warn and hope for the best.
|
| 221 |
+
self.warn(_runtime_library_dirs_msg)
|
| 222 |
+
return []
|
| 223 |
+
|
| 224 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 225 |
+
|
| 226 |
+
def _make_out_path(self, output_dir, strip_dir, src_name):
|
| 227 |
+
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
| 228 |
+
norm_src_name = os.path.normcase(src_name)
|
| 229 |
+
return super()._make_out_path(output_dir, strip_dir, norm_src_name)
|
| 230 |
+
|
| 231 |
+
@property
|
| 232 |
+
def out_extensions(self):
|
| 233 |
+
"""
|
| 234 |
+
Add support for rc and res files.
|
| 235 |
+
"""
|
| 236 |
+
return {
|
| 237 |
+
**super().out_extensions,
|
| 238 |
+
**{ext: ext + self.obj_extension for ext in ('.res', '.rc')},
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
# the same as cygwin plus some additional parameters
|
| 243 |
+
class Mingw32CCompiler(CygwinCCompiler):
|
| 244 |
+
"""Handles the Mingw32 port of the GNU C compiler to Windows."""
|
| 245 |
+
|
| 246 |
+
compiler_type = 'mingw32'
|
| 247 |
+
|
| 248 |
+
def __init__(self, verbose=False, dry_run=False, force=False):
|
| 249 |
+
super().__init__(verbose, dry_run, force)
|
| 250 |
+
|
| 251 |
+
shared_option = "-shared"
|
| 252 |
+
|
| 253 |
+
if is_cygwincc(self.cc):
|
| 254 |
+
raise CCompilerError('Cygwin gcc cannot be used with --compiler=mingw32')
|
| 255 |
+
|
| 256 |
+
self.set_executables(
|
| 257 |
+
compiler=f'{self.cc} -O -Wall',
|
| 258 |
+
compiler_so=f'{self.cc} -shared -O -Wall',
|
| 259 |
+
compiler_so_cxx=f'{self.cxx} -shared -O -Wall',
|
| 260 |
+
compiler_cxx=f'{self.cxx} -O -Wall',
|
| 261 |
+
linker_exe=f'{self.cc}',
|
| 262 |
+
linker_so=f'{self.linker_dll} {shared_option}',
|
| 263 |
+
linker_exe_cxx=f'{self.cxx}',
|
| 264 |
+
linker_so_cxx=f'{self.linker_dll_cxx} {shared_option}',
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
def runtime_library_dir_option(self, dir):
|
| 268 |
+
raise DistutilsPlatformError(_runtime_library_dirs_msg)
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
# Because these compilers aren't configured in Python's pyconfig.h file by
|
| 272 |
+
# default, we should at least warn the user if he is using an unmodified
|
| 273 |
+
# version.
|
| 274 |
+
|
| 275 |
+
CONFIG_H_OK = "ok"
|
| 276 |
+
CONFIG_H_NOTOK = "not ok"
|
| 277 |
+
CONFIG_H_UNCERTAIN = "uncertain"
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def check_config_h():
|
| 281 |
+
"""Check if the current Python installation appears amenable to building
|
| 282 |
+
extensions with GCC.
|
| 283 |
+
|
| 284 |
+
Returns a tuple (status, details), where 'status' is one of the following
|
| 285 |
+
constants:
|
| 286 |
+
|
| 287 |
+
- CONFIG_H_OK: all is well, go ahead and compile
|
| 288 |
+
- CONFIG_H_NOTOK: doesn't look good
|
| 289 |
+
- CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
|
| 290 |
+
|
| 291 |
+
'details' is a human-readable string explaining the situation.
|
| 292 |
+
|
| 293 |
+
Note there are two ways to conclude "OK": either 'sys.version' contains
|
| 294 |
+
the string "GCC" (implying that this Python was built with GCC), or the
|
| 295 |
+
installed "pyconfig.h" contains the string "__GNUC__".
|
| 296 |
+
"""
|
| 297 |
+
|
| 298 |
+
# XXX since this function also checks sys.version, it's not strictly a
|
| 299 |
+
# "pyconfig.h" check -- should probably be renamed...
|
| 300 |
+
|
| 301 |
+
from distutils import sysconfig
|
| 302 |
+
|
| 303 |
+
# if sys.version contains GCC then python was compiled with GCC, and the
|
| 304 |
+
# pyconfig.h file should be OK
|
| 305 |
+
if "GCC" in sys.version:
|
| 306 |
+
return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
| 307 |
+
|
| 308 |
+
# Clang would also work
|
| 309 |
+
if "Clang" in sys.version:
|
| 310 |
+
return CONFIG_H_OK, "sys.version mentions 'Clang'"
|
| 311 |
+
|
| 312 |
+
# let's see if __GNUC__ is mentioned in python.h
|
| 313 |
+
fn = sysconfig.get_config_h_filename()
|
| 314 |
+
try:
|
| 315 |
+
config_h = pathlib.Path(fn).read_text(encoding='utf-8')
|
| 316 |
+
except OSError as exc:
|
| 317 |
+
return (CONFIG_H_UNCERTAIN, f"couldn't read '{fn}': {exc.strerror}")
|
| 318 |
+
else:
|
| 319 |
+
substring = '__GNUC__'
|
| 320 |
+
if substring in config_h:
|
| 321 |
+
code = CONFIG_H_OK
|
| 322 |
+
mention_inflected = 'mentions'
|
| 323 |
+
else:
|
| 324 |
+
code = CONFIG_H_NOTOK
|
| 325 |
+
mention_inflected = 'does not mention'
|
| 326 |
+
return code, f"{fn!r} {mention_inflected} {substring!r}"
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def is_cygwincc(cc):
|
| 330 |
+
"""Try to determine if the compiler that would be used is from cygwin."""
|
| 331 |
+
out_string = check_output(shlex.split(cc) + ['-dumpmachine'])
|
| 332 |
+
return out_string.strip().endswith(b'cygwin')
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
get_versions = None
|
| 336 |
+
"""
|
| 337 |
+
A stand-in for the previous get_versions() function to prevent failures
|
| 338 |
+
when monkeypatched. See pypa/setuptools#2969.
|
| 339 |
+
"""
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/dep_util.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
|
| 3 |
+
from . import _modified
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def __getattr__(name):
|
| 7 |
+
if name not in ['newer', 'newer_group', 'newer_pairwise']:
|
| 8 |
+
raise AttributeError(name)
|
| 9 |
+
warnings.warn(
|
| 10 |
+
"dep_util is Deprecated. Use functions from setuptools instead.",
|
| 11 |
+
DeprecationWarning,
|
| 12 |
+
stacklevel=2,
|
| 13 |
+
)
|
| 14 |
+
return getattr(_modified, name)
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/dir_util.py
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.dir_util
|
| 2 |
+
|
| 3 |
+
Utility functions for manipulating directories and directory trees."""
|
| 4 |
+
|
| 5 |
+
import functools
|
| 6 |
+
import itertools
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
|
| 10 |
+
from . import file_util
|
| 11 |
+
from ._log import log
|
| 12 |
+
from .errors import DistutilsFileError, DistutilsInternalError
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class SkipRepeatAbsolutePaths(set):
|
| 16 |
+
"""
|
| 17 |
+
Cache for mkpath.
|
| 18 |
+
|
| 19 |
+
In addition to cheapening redundant calls, eliminates redundant
|
| 20 |
+
"creating /foo/bar/baz" messages in dry-run mode.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
def __init__(self):
|
| 24 |
+
SkipRepeatAbsolutePaths.instance = self
|
| 25 |
+
|
| 26 |
+
@classmethod
|
| 27 |
+
def clear(cls):
|
| 28 |
+
super(cls, cls.instance).clear()
|
| 29 |
+
|
| 30 |
+
def wrap(self, func):
|
| 31 |
+
@functools.wraps(func)
|
| 32 |
+
def wrapper(path, *args, **kwargs):
|
| 33 |
+
if path.absolute() in self:
|
| 34 |
+
return
|
| 35 |
+
result = func(path, *args, **kwargs)
|
| 36 |
+
self.add(path.absolute())
|
| 37 |
+
return result
|
| 38 |
+
|
| 39 |
+
return wrapper
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# Python 3.8 compatibility
|
| 43 |
+
wrapper = SkipRepeatAbsolutePaths().wrap
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@functools.singledispatch
|
| 47 |
+
@wrapper
|
| 48 |
+
def mkpath(name: pathlib.Path, mode=0o777, verbose=True, dry_run=False) -> None:
|
| 49 |
+
"""Create a directory and any missing ancestor directories.
|
| 50 |
+
|
| 51 |
+
If the directory already exists (or if 'name' is the empty string, which
|
| 52 |
+
means the current directory, which of course exists), then do nothing.
|
| 53 |
+
Raise DistutilsFileError if unable to create some directory along the way
|
| 54 |
+
(eg. some sub-path exists, but is a file rather than a directory).
|
| 55 |
+
If 'verbose' is true, log the directory created.
|
| 56 |
+
"""
|
| 57 |
+
if verbose and not name.is_dir():
|
| 58 |
+
log.info("creating %s", name)
|
| 59 |
+
|
| 60 |
+
try:
|
| 61 |
+
dry_run or name.mkdir(mode=mode, parents=True, exist_ok=True)
|
| 62 |
+
except OSError as exc:
|
| 63 |
+
raise DistutilsFileError(f"could not create '{name}': {exc.args[-1]}")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@mkpath.register
|
| 67 |
+
def _(name: str, *args, **kwargs):
|
| 68 |
+
return mkpath(pathlib.Path(name), *args, **kwargs)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@mkpath.register
|
| 72 |
+
def _(name: None, *args, **kwargs):
|
| 73 |
+
"""
|
| 74 |
+
Detect a common bug -- name is None.
|
| 75 |
+
"""
|
| 76 |
+
raise DistutilsInternalError(f"mkpath: 'name' must be a string (got {name!r})")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def create_tree(base_dir, files, mode=0o777, verbose=True, dry_run=False):
|
| 80 |
+
"""Create all the empty directories under 'base_dir' needed to put 'files'
|
| 81 |
+
there.
|
| 82 |
+
|
| 83 |
+
'base_dir' is just the name of a directory which doesn't necessarily
|
| 84 |
+
exist yet; 'files' is a list of filenames to be interpreted relative to
|
| 85 |
+
'base_dir'. 'base_dir' + the directory portion of every file in 'files'
|
| 86 |
+
will be created if it doesn't already exist. 'mode', 'verbose' and
|
| 87 |
+
'dry_run' flags are as for 'mkpath()'.
|
| 88 |
+
"""
|
| 89 |
+
# First get the list of directories to create
|
| 90 |
+
need_dir = set(os.path.join(base_dir, os.path.dirname(file)) for file in files)
|
| 91 |
+
|
| 92 |
+
# Now create them
|
| 93 |
+
for dir in sorted(need_dir):
|
| 94 |
+
mkpath(dir, mode, verbose=verbose, dry_run=dry_run)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def copy_tree(
|
| 98 |
+
src,
|
| 99 |
+
dst,
|
| 100 |
+
preserve_mode=True,
|
| 101 |
+
preserve_times=True,
|
| 102 |
+
preserve_symlinks=False,
|
| 103 |
+
update=False,
|
| 104 |
+
verbose=True,
|
| 105 |
+
dry_run=False,
|
| 106 |
+
):
|
| 107 |
+
"""Copy an entire directory tree 'src' to a new location 'dst'.
|
| 108 |
+
|
| 109 |
+
Both 'src' and 'dst' must be directory names. If 'src' is not a
|
| 110 |
+
directory, raise DistutilsFileError. If 'dst' does not exist, it is
|
| 111 |
+
created with 'mkpath()'. The end result of the copy is that every
|
| 112 |
+
file in 'src' is copied to 'dst', and directories under 'src' are
|
| 113 |
+
recursively copied to 'dst'. Return the list of files that were
|
| 114 |
+
copied or might have been copied, using their output name. The
|
| 115 |
+
return value is unaffected by 'update' or 'dry_run': it is simply
|
| 116 |
+
the list of all files under 'src', with the names changed to be
|
| 117 |
+
under 'dst'.
|
| 118 |
+
|
| 119 |
+
'preserve_mode' and 'preserve_times' are the same as for
|
| 120 |
+
'copy_file'; note that they only apply to regular files, not to
|
| 121 |
+
directories. If 'preserve_symlinks' is true, symlinks will be
|
| 122 |
+
copied as symlinks (on platforms that support them!); otherwise
|
| 123 |
+
(the default), the destination of the symlink will be copied.
|
| 124 |
+
'update' and 'verbose' are the same as for 'copy_file'.
|
| 125 |
+
"""
|
| 126 |
+
if not dry_run and not os.path.isdir(src):
|
| 127 |
+
raise DistutilsFileError(f"cannot copy tree '{src}': not a directory")
|
| 128 |
+
try:
|
| 129 |
+
names = os.listdir(src)
|
| 130 |
+
except OSError as e:
|
| 131 |
+
if dry_run:
|
| 132 |
+
names = []
|
| 133 |
+
else:
|
| 134 |
+
raise DistutilsFileError(f"error listing files in '{src}': {e.strerror}")
|
| 135 |
+
|
| 136 |
+
if not dry_run:
|
| 137 |
+
mkpath(dst, verbose=verbose)
|
| 138 |
+
|
| 139 |
+
copy_one = functools.partial(
|
| 140 |
+
_copy_one,
|
| 141 |
+
src=src,
|
| 142 |
+
dst=dst,
|
| 143 |
+
preserve_symlinks=preserve_symlinks,
|
| 144 |
+
verbose=verbose,
|
| 145 |
+
dry_run=dry_run,
|
| 146 |
+
preserve_mode=preserve_mode,
|
| 147 |
+
preserve_times=preserve_times,
|
| 148 |
+
update=update,
|
| 149 |
+
)
|
| 150 |
+
return list(itertools.chain.from_iterable(map(copy_one, names)))
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def _copy_one(
|
| 154 |
+
name,
|
| 155 |
+
*,
|
| 156 |
+
src,
|
| 157 |
+
dst,
|
| 158 |
+
preserve_symlinks,
|
| 159 |
+
verbose,
|
| 160 |
+
dry_run,
|
| 161 |
+
preserve_mode,
|
| 162 |
+
preserve_times,
|
| 163 |
+
update,
|
| 164 |
+
):
|
| 165 |
+
src_name = os.path.join(src, name)
|
| 166 |
+
dst_name = os.path.join(dst, name)
|
| 167 |
+
|
| 168 |
+
if name.startswith('.nfs'):
|
| 169 |
+
# skip NFS rename files
|
| 170 |
+
return
|
| 171 |
+
|
| 172 |
+
if preserve_symlinks and os.path.islink(src_name):
|
| 173 |
+
link_dest = os.readlink(src_name)
|
| 174 |
+
if verbose >= 1:
|
| 175 |
+
log.info("linking %s -> %s", dst_name, link_dest)
|
| 176 |
+
if not dry_run:
|
| 177 |
+
os.symlink(link_dest, dst_name)
|
| 178 |
+
yield dst_name
|
| 179 |
+
|
| 180 |
+
elif os.path.isdir(src_name):
|
| 181 |
+
yield from copy_tree(
|
| 182 |
+
src_name,
|
| 183 |
+
dst_name,
|
| 184 |
+
preserve_mode,
|
| 185 |
+
preserve_times,
|
| 186 |
+
preserve_symlinks,
|
| 187 |
+
update,
|
| 188 |
+
verbose=verbose,
|
| 189 |
+
dry_run=dry_run,
|
| 190 |
+
)
|
| 191 |
+
else:
|
| 192 |
+
file_util.copy_file(
|
| 193 |
+
src_name,
|
| 194 |
+
dst_name,
|
| 195 |
+
preserve_mode,
|
| 196 |
+
preserve_times,
|
| 197 |
+
update,
|
| 198 |
+
verbose=verbose,
|
| 199 |
+
dry_run=dry_run,
|
| 200 |
+
)
|
| 201 |
+
yield dst_name
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _build_cmdtuple(path, cmdtuples):
|
| 205 |
+
"""Helper for remove_tree()."""
|
| 206 |
+
for f in os.listdir(path):
|
| 207 |
+
real_f = os.path.join(path, f)
|
| 208 |
+
if os.path.isdir(real_f) and not os.path.islink(real_f):
|
| 209 |
+
_build_cmdtuple(real_f, cmdtuples)
|
| 210 |
+
else:
|
| 211 |
+
cmdtuples.append((os.remove, real_f))
|
| 212 |
+
cmdtuples.append((os.rmdir, path))
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def remove_tree(directory, verbose=True, dry_run=False):
|
| 216 |
+
"""Recursively remove an entire directory tree.
|
| 217 |
+
|
| 218 |
+
Any errors are ignored (apart from being reported to stdout if 'verbose'
|
| 219 |
+
is true).
|
| 220 |
+
"""
|
| 221 |
+
if verbose >= 1:
|
| 222 |
+
log.info("removing '%s' (and everything under it)", directory)
|
| 223 |
+
if dry_run:
|
| 224 |
+
return
|
| 225 |
+
cmdtuples = []
|
| 226 |
+
_build_cmdtuple(directory, cmdtuples)
|
| 227 |
+
for cmd in cmdtuples:
|
| 228 |
+
try:
|
| 229 |
+
cmd[0](cmd[1])
|
| 230 |
+
# Clear the cache
|
| 231 |
+
SkipRepeatAbsolutePaths.clear()
|
| 232 |
+
except OSError as exc:
|
| 233 |
+
log.warning("error removing %s: %s", directory, exc)
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def ensure_relative(path):
|
| 237 |
+
"""Take the full path 'path', and make it a relative path.
|
| 238 |
+
|
| 239 |
+
This is useful to make 'path' the second argument to os.path.join().
|
| 240 |
+
"""
|
| 241 |
+
drive, path = os.path.splitdrive(path)
|
| 242 |
+
if path[0:1] == os.sep:
|
| 243 |
+
path = drive + path[1:]
|
| 244 |
+
return path
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_dumb.cpython-310.pyc
ADDED
|
Binary file (2.09 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/__pycache__/test_build_ext.cpython-310.pyc
ADDED
|
Binary file (13.7 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/__pycache__/test_mingwccompiler.cpython-310.pyc
ADDED
|
Binary file (2.56 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_bdist_dumb.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist_dumb."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import zipfile
|
| 6 |
+
from distutils.command.bdist_dumb import bdist_dumb
|
| 7 |
+
from distutils.core import Distribution
|
| 8 |
+
from distutils.tests import support
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
SETUP_PY = """\
|
| 13 |
+
from distutils.core import setup
|
| 14 |
+
import foo
|
| 15 |
+
|
| 16 |
+
setup(name='foo', version='0.1', py_modules=['foo'],
|
| 17 |
+
url='xxx', author='xxx', author_email='xxx')
|
| 18 |
+
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@support.combine_markers
|
| 23 |
+
@pytest.mark.usefixtures('save_env')
|
| 24 |
+
@pytest.mark.usefixtures('save_argv')
|
| 25 |
+
@pytest.mark.usefixtures('save_cwd')
|
| 26 |
+
class TestBuildDumb(
|
| 27 |
+
support.TempdirManager,
|
| 28 |
+
):
|
| 29 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 30 |
+
def test_simple_built(self):
|
| 31 |
+
# let's create a simple package
|
| 32 |
+
tmp_dir = self.mkdtemp()
|
| 33 |
+
pkg_dir = os.path.join(tmp_dir, 'foo')
|
| 34 |
+
os.mkdir(pkg_dir)
|
| 35 |
+
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
|
| 36 |
+
self.write_file((pkg_dir, 'foo.py'), '#')
|
| 37 |
+
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
|
| 38 |
+
self.write_file((pkg_dir, 'README'), '')
|
| 39 |
+
|
| 40 |
+
dist = Distribution({
|
| 41 |
+
'name': 'foo',
|
| 42 |
+
'version': '0.1',
|
| 43 |
+
'py_modules': ['foo'],
|
| 44 |
+
'url': 'xxx',
|
| 45 |
+
'author': 'xxx',
|
| 46 |
+
'author_email': 'xxx',
|
| 47 |
+
})
|
| 48 |
+
dist.script_name = 'setup.py'
|
| 49 |
+
os.chdir(pkg_dir)
|
| 50 |
+
|
| 51 |
+
sys.argv = ['setup.py']
|
| 52 |
+
cmd = bdist_dumb(dist)
|
| 53 |
+
|
| 54 |
+
# so the output is the same no matter
|
| 55 |
+
# what is the platform
|
| 56 |
+
cmd.format = 'zip'
|
| 57 |
+
|
| 58 |
+
cmd.ensure_finalized()
|
| 59 |
+
cmd.run()
|
| 60 |
+
|
| 61 |
+
# see what we have
|
| 62 |
+
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
| 63 |
+
base = f"{dist.get_fullname()}.{cmd.plat_name}.zip"
|
| 64 |
+
|
| 65 |
+
assert dist_created == [base]
|
| 66 |
+
|
| 67 |
+
# now let's check what we have in the zip file
|
| 68 |
+
fp = zipfile.ZipFile(os.path.join('dist', base))
|
| 69 |
+
try:
|
| 70 |
+
contents = fp.namelist()
|
| 71 |
+
finally:
|
| 72 |
+
fp.close()
|
| 73 |
+
|
| 74 |
+
contents = sorted(filter(None, map(os.path.basename, contents)))
|
| 75 |
+
wanted = ['foo-0.1-py{}.{}.egg-info'.format(*sys.version_info[:2]), 'foo.py']
|
| 76 |
+
if not sys.dont_write_bytecode:
|
| 77 |
+
wanted.append(f'foo.{sys.implementation.cache_tag}.pyc')
|
| 78 |
+
assert contents == sorted(wanted)
|
videollama2/lib/python3.10/site-packages/setuptools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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.check."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import textwrap
|
| 5 |
+
from distutils.command.check import check
|
| 6 |
+
from distutils.errors import DistutilsSetupError
|
| 7 |
+
from distutils.tests import support
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
import pygments
|
| 13 |
+
except ImportError:
|
| 14 |
+
pygments = None
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
HERE = os.path.dirname(__file__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@support.combine_markers
|
| 21 |
+
class TestCheck(support.TempdirManager):
|
| 22 |
+
def _run(self, metadata=None, cwd=None, **options):
|
| 23 |
+
if metadata is None:
|
| 24 |
+
metadata = {}
|
| 25 |
+
if cwd is not None:
|
| 26 |
+
old_dir = os.getcwd()
|
| 27 |
+
os.chdir(cwd)
|
| 28 |
+
pkg_info, dist = self.create_dist(**metadata)
|
| 29 |
+
cmd = check(dist)
|
| 30 |
+
cmd.initialize_options()
|
| 31 |
+
for name, value in options.items():
|
| 32 |
+
setattr(cmd, name, value)
|
| 33 |
+
cmd.ensure_finalized()
|
| 34 |
+
cmd.run()
|
| 35 |
+
if cwd is not None:
|
| 36 |
+
os.chdir(old_dir)
|
| 37 |
+
return cmd
|
| 38 |
+
|
| 39 |
+
def test_check_metadata(self):
|
| 40 |
+
# let's run the command with no metadata at all
|
| 41 |
+
# by default, check is checking the metadata
|
| 42 |
+
# should have some warnings
|
| 43 |
+
cmd = self._run()
|
| 44 |
+
assert cmd._warnings == 1
|
| 45 |
+
|
| 46 |
+
# now let's add the required fields
|
| 47 |
+
# and run it again, to make sure we don't get
|
| 48 |
+
# any warning anymore
|
| 49 |
+
metadata = {
|
| 50 |
+
'url': 'xxx',
|
| 51 |
+
'author': 'xxx',
|
| 52 |
+
'author_email': 'xxx',
|
| 53 |
+
'name': 'xxx',
|
| 54 |
+
'version': 'xxx',
|
| 55 |
+
}
|
| 56 |
+
cmd = self._run(metadata)
|
| 57 |
+
assert cmd._warnings == 0
|
| 58 |
+
|
| 59 |
+
# now with the strict mode, we should
|
| 60 |
+
# get an error if there are missing metadata
|
| 61 |
+
with pytest.raises(DistutilsSetupError):
|
| 62 |
+
self._run({}, **{'strict': 1})
|
| 63 |
+
|
| 64 |
+
# and of course, no error when all metadata are present
|
| 65 |
+
cmd = self._run(metadata, strict=True)
|
| 66 |
+
assert cmd._warnings == 0
|
| 67 |
+
|
| 68 |
+
# now a test with non-ASCII characters
|
| 69 |
+
metadata = {
|
| 70 |
+
'url': 'xxx',
|
| 71 |
+
'author': '\u00c9ric',
|
| 72 |
+
'author_email': 'xxx',
|
| 73 |
+
'name': 'xxx',
|
| 74 |
+
'version': 'xxx',
|
| 75 |
+
'description': 'Something about esszet \u00df',
|
| 76 |
+
'long_description': 'More things about esszet \u00df',
|
| 77 |
+
}
|
| 78 |
+
cmd = self._run(metadata)
|
| 79 |
+
assert cmd._warnings == 0
|
| 80 |
+
|
| 81 |
+
def test_check_author_maintainer(self):
|
| 82 |
+
for kind in ("author", "maintainer"):
|
| 83 |
+
# ensure no warning when author_email or maintainer_email is given
|
| 84 |
+
# (the spec allows these fields to take the form "Name <email>")
|
| 85 |
+
metadata = {
|
| 86 |
+
'url': 'xxx',
|
| 87 |
+
kind + '_email': 'Name <name@email.com>',
|
| 88 |
+
'name': 'xxx',
|
| 89 |
+
'version': 'xxx',
|
| 90 |
+
}
|
| 91 |
+
cmd = self._run(metadata)
|
| 92 |
+
assert cmd._warnings == 0
|
| 93 |
+
|
| 94 |
+
# the check should not warn if only email is given
|
| 95 |
+
metadata[kind + '_email'] = 'name@email.com'
|
| 96 |
+
cmd = self._run(metadata)
|
| 97 |
+
assert cmd._warnings == 0
|
| 98 |
+
|
| 99 |
+
# the check should not warn if only the name is given
|
| 100 |
+
metadata[kind] = "Name"
|
| 101 |
+
del metadata[kind + '_email']
|
| 102 |
+
cmd = self._run(metadata)
|
| 103 |
+
assert cmd._warnings == 0
|
| 104 |
+
|
| 105 |
+
def test_check_document(self):
|
| 106 |
+
pytest.importorskip('docutils')
|
| 107 |
+
pkg_info, dist = self.create_dist()
|
| 108 |
+
cmd = check(dist)
|
| 109 |
+
|
| 110 |
+
# let's see if it detects broken rest
|
| 111 |
+
broken_rest = 'title\n===\n\ntest'
|
| 112 |
+
msgs = cmd._check_rst_data(broken_rest)
|
| 113 |
+
assert len(msgs) == 1
|
| 114 |
+
|
| 115 |
+
# and non-broken rest
|
| 116 |
+
rest = 'title\n=====\n\ntest'
|
| 117 |
+
msgs = cmd._check_rst_data(rest)
|
| 118 |
+
assert len(msgs) == 0
|
| 119 |
+
|
| 120 |
+
def test_check_restructuredtext(self):
|
| 121 |
+
pytest.importorskip('docutils')
|
| 122 |
+
# let's see if it detects broken rest in long_description
|
| 123 |
+
broken_rest = 'title\n===\n\ntest'
|
| 124 |
+
pkg_info, dist = self.create_dist(long_description=broken_rest)
|
| 125 |
+
cmd = check(dist)
|
| 126 |
+
cmd.check_restructuredtext()
|
| 127 |
+
assert cmd._warnings == 1
|
| 128 |
+
|
| 129 |
+
# let's see if we have an error with strict=True
|
| 130 |
+
metadata = {
|
| 131 |
+
'url': 'xxx',
|
| 132 |
+
'author': 'xxx',
|
| 133 |
+
'author_email': 'xxx',
|
| 134 |
+
'name': 'xxx',
|
| 135 |
+
'version': 'xxx',
|
| 136 |
+
'long_description': broken_rest,
|
| 137 |
+
}
|
| 138 |
+
with pytest.raises(DistutilsSetupError):
|
| 139 |
+
self._run(metadata, **{'strict': 1, 'restructuredtext': 1})
|
| 140 |
+
|
| 141 |
+
# and non-broken rest, including a non-ASCII character to test #12114
|
| 142 |
+
metadata['long_description'] = 'title\n=====\n\ntest \u00df'
|
| 143 |
+
cmd = self._run(metadata, strict=True, restructuredtext=True)
|
| 144 |
+
assert cmd._warnings == 0
|
| 145 |
+
|
| 146 |
+
# check that includes work to test #31292
|
| 147 |
+
metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
|
| 148 |
+
cmd = self._run(metadata, cwd=HERE, strict=True, restructuredtext=True)
|
| 149 |
+
assert cmd._warnings == 0
|
| 150 |
+
|
| 151 |
+
def test_check_restructuredtext_with_syntax_highlight(self):
|
| 152 |
+
pytest.importorskip('docutils')
|
| 153 |
+
# Don't fail if there is a `code` or `code-block` directive
|
| 154 |
+
|
| 155 |
+
example_rst_docs = [
|
| 156 |
+
textwrap.dedent(
|
| 157 |
+
"""\
|
| 158 |
+
Here's some code:
|
| 159 |
+
|
| 160 |
+
.. code:: python
|
| 161 |
+
|
| 162 |
+
def foo():
|
| 163 |
+
pass
|
| 164 |
+
"""
|
| 165 |
+
),
|
| 166 |
+
textwrap.dedent(
|
| 167 |
+
"""\
|
| 168 |
+
Here's some code:
|
| 169 |
+
|
| 170 |
+
.. code-block:: python
|
| 171 |
+
|
| 172 |
+
def foo():
|
| 173 |
+
pass
|
| 174 |
+
"""
|
| 175 |
+
),
|
| 176 |
+
]
|
| 177 |
+
|
| 178 |
+
for rest_with_code in example_rst_docs:
|
| 179 |
+
pkg_info, dist = self.create_dist(long_description=rest_with_code)
|
| 180 |
+
cmd = check(dist)
|
| 181 |
+
cmd.check_restructuredtext()
|
| 182 |
+
msgs = cmd._check_rst_data(rest_with_code)
|
| 183 |
+
if pygments is not None:
|
| 184 |
+
assert len(msgs) == 0
|
| 185 |
+
else:
|
| 186 |
+
assert len(msgs) == 1
|
| 187 |
+
assert (
|
| 188 |
+
str(msgs[0][1])
|
| 189 |
+
== 'Cannot analyze code. Pygments package not found.'
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
def test_check_all(self):
|
| 193 |
+
with pytest.raises(DistutilsSetupError):
|
| 194 |
+
self._run({}, **{'strict': 1, 'restructuredtext': 1})
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_clean.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.clean."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from distutils.command.clean import clean
|
| 5 |
+
from distutils.tests import support
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestClean(support.TempdirManager):
|
| 9 |
+
def test_simple_run(self):
|
| 10 |
+
pkg_dir, dist = self.create_dist()
|
| 11 |
+
cmd = clean(dist)
|
| 12 |
+
|
| 13 |
+
# let's add some elements clean should remove
|
| 14 |
+
dirs = [
|
| 15 |
+
(d, os.path.join(pkg_dir, d))
|
| 16 |
+
for d in (
|
| 17 |
+
'build_temp',
|
| 18 |
+
'build_lib',
|
| 19 |
+
'bdist_base',
|
| 20 |
+
'build_scripts',
|
| 21 |
+
'build_base',
|
| 22 |
+
)
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
for name, path in dirs:
|
| 26 |
+
os.mkdir(path)
|
| 27 |
+
setattr(cmd, name, path)
|
| 28 |
+
if name == 'build_base':
|
| 29 |
+
continue
|
| 30 |
+
for f in ('one', 'two', 'three'):
|
| 31 |
+
self.write_file(os.path.join(path, f))
|
| 32 |
+
|
| 33 |
+
# let's run the command
|
| 34 |
+
cmd.all = 1
|
| 35 |
+
cmd.ensure_finalized()
|
| 36 |
+
cmd.run()
|
| 37 |
+
|
| 38 |
+
# make sure the files where removed
|
| 39 |
+
for _name, path in dirs:
|
| 40 |
+
assert not os.path.exists(path), f'{path} was not removed'
|
| 41 |
+
|
| 42 |
+
# let's run the command again (should spit warnings but succeed)
|
| 43 |
+
cmd.all = 1
|
| 44 |
+
cmd.ensure_finalized()
|
| 45 |
+
cmd.run()
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_dir_util.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.dir_util."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import stat
|
| 6 |
+
import sys
|
| 7 |
+
import unittest.mock as mock
|
| 8 |
+
from distutils import dir_util, errors
|
| 9 |
+
from distutils.dir_util import (
|
| 10 |
+
copy_tree,
|
| 11 |
+
create_tree,
|
| 12 |
+
ensure_relative,
|
| 13 |
+
mkpath,
|
| 14 |
+
remove_tree,
|
| 15 |
+
)
|
| 16 |
+
from distutils.tests import support
|
| 17 |
+
|
| 18 |
+
import jaraco.path
|
| 19 |
+
import path
|
| 20 |
+
import pytest
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@pytest.fixture(autouse=True)
|
| 24 |
+
def stuff(request, monkeypatch, distutils_managed_tempdir):
|
| 25 |
+
self = request.instance
|
| 26 |
+
tmp_dir = self.mkdtemp()
|
| 27 |
+
self.root_target = os.path.join(tmp_dir, 'deep')
|
| 28 |
+
self.target = os.path.join(self.root_target, 'here')
|
| 29 |
+
self.target2 = os.path.join(tmp_dir, 'deep2')
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class TestDirUtil(support.TempdirManager):
|
| 33 |
+
def test_mkpath_remove_tree_verbosity(self, caplog):
|
| 34 |
+
mkpath(self.target, verbose=False)
|
| 35 |
+
assert not caplog.records
|
| 36 |
+
remove_tree(self.root_target, verbose=False)
|
| 37 |
+
|
| 38 |
+
mkpath(self.target, verbose=True)
|
| 39 |
+
wanted = [f'creating {self.target}']
|
| 40 |
+
assert caplog.messages == wanted
|
| 41 |
+
caplog.clear()
|
| 42 |
+
|
| 43 |
+
remove_tree(self.root_target, verbose=True)
|
| 44 |
+
wanted = [f"removing '{self.root_target}' (and everything under it)"]
|
| 45 |
+
assert caplog.messages == wanted
|
| 46 |
+
|
| 47 |
+
@pytest.mark.skipif("platform.system() == 'Windows'")
|
| 48 |
+
def test_mkpath_with_custom_mode(self):
|
| 49 |
+
# Get and set the current umask value for testing mode bits.
|
| 50 |
+
umask = os.umask(0o002)
|
| 51 |
+
os.umask(umask)
|
| 52 |
+
mkpath(self.target, 0o700)
|
| 53 |
+
assert stat.S_IMODE(os.stat(self.target).st_mode) == 0o700 & ~umask
|
| 54 |
+
mkpath(self.target2, 0o555)
|
| 55 |
+
assert stat.S_IMODE(os.stat(self.target2).st_mode) == 0o555 & ~umask
|
| 56 |
+
|
| 57 |
+
def test_create_tree_verbosity(self, caplog):
|
| 58 |
+
create_tree(self.root_target, ['one', 'two', 'three'], verbose=False)
|
| 59 |
+
assert caplog.messages == []
|
| 60 |
+
remove_tree(self.root_target, verbose=False)
|
| 61 |
+
|
| 62 |
+
wanted = [f'creating {self.root_target}']
|
| 63 |
+
create_tree(self.root_target, ['one', 'two', 'three'], verbose=True)
|
| 64 |
+
assert caplog.messages == wanted
|
| 65 |
+
|
| 66 |
+
remove_tree(self.root_target, verbose=False)
|
| 67 |
+
|
| 68 |
+
def test_copy_tree_verbosity(self, caplog):
|
| 69 |
+
mkpath(self.target, verbose=False)
|
| 70 |
+
|
| 71 |
+
copy_tree(self.target, self.target2, verbose=False)
|
| 72 |
+
assert caplog.messages == []
|
| 73 |
+
|
| 74 |
+
remove_tree(self.root_target, verbose=False)
|
| 75 |
+
|
| 76 |
+
mkpath(self.target, verbose=False)
|
| 77 |
+
a_file = path.Path(self.target) / 'ok.txt'
|
| 78 |
+
jaraco.path.build({'ok.txt': 'some content'}, self.target)
|
| 79 |
+
|
| 80 |
+
wanted = [f'copying {a_file} -> {self.target2}']
|
| 81 |
+
copy_tree(self.target, self.target2, verbose=True)
|
| 82 |
+
assert caplog.messages == wanted
|
| 83 |
+
|
| 84 |
+
remove_tree(self.root_target, verbose=False)
|
| 85 |
+
remove_tree(self.target2, verbose=False)
|
| 86 |
+
|
| 87 |
+
def test_copy_tree_skips_nfs_temp_files(self):
|
| 88 |
+
mkpath(self.target, verbose=False)
|
| 89 |
+
|
| 90 |
+
jaraco.path.build({'ok.txt': 'some content', '.nfs123abc': ''}, self.target)
|
| 91 |
+
|
| 92 |
+
copy_tree(self.target, self.target2)
|
| 93 |
+
assert os.listdir(self.target2) == ['ok.txt']
|
| 94 |
+
|
| 95 |
+
remove_tree(self.root_target, verbose=False)
|
| 96 |
+
remove_tree(self.target2, verbose=False)
|
| 97 |
+
|
| 98 |
+
def test_ensure_relative(self):
|
| 99 |
+
if os.sep == '/':
|
| 100 |
+
assert ensure_relative('/home/foo') == 'home/foo'
|
| 101 |
+
assert ensure_relative('some/path') == 'some/path'
|
| 102 |
+
else: # \\
|
| 103 |
+
assert ensure_relative('c:\\home\\foo') == 'c:home\\foo'
|
| 104 |
+
assert ensure_relative('home\\foo') == 'home\\foo'
|
| 105 |
+
|
| 106 |
+
def test_copy_tree_exception_in_listdir(self):
|
| 107 |
+
"""
|
| 108 |
+
An exception in listdir should raise a DistutilsFileError
|
| 109 |
+
"""
|
| 110 |
+
with (
|
| 111 |
+
mock.patch("os.listdir", side_effect=OSError()),
|
| 112 |
+
pytest.raises(errors.DistutilsFileError),
|
| 113 |
+
):
|
| 114 |
+
src = self.tempdirs[-1]
|
| 115 |
+
dir_util.copy_tree(src, None)
|
| 116 |
+
|
| 117 |
+
def test_mkpath_exception_uncached(self, monkeypatch, tmp_path):
|
| 118 |
+
"""
|
| 119 |
+
Caching should not remember failed attempts.
|
| 120 |
+
|
| 121 |
+
pypa/distutils#304
|
| 122 |
+
"""
|
| 123 |
+
|
| 124 |
+
class FailPath(pathlib.Path):
|
| 125 |
+
def mkdir(self, *args, **kwargs):
|
| 126 |
+
raise OSError("Failed to create directory")
|
| 127 |
+
|
| 128 |
+
if sys.version_info < (3, 12):
|
| 129 |
+
_flavour = pathlib.Path()._flavour
|
| 130 |
+
|
| 131 |
+
target = tmp_path / 'foodir'
|
| 132 |
+
|
| 133 |
+
with pytest.raises(errors.DistutilsFileError):
|
| 134 |
+
mkpath(FailPath(target))
|
| 135 |
+
|
| 136 |
+
assert not target.exists()
|
| 137 |
+
|
| 138 |
+
mkpath(target)
|
| 139 |
+
assert target.exists()
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_install_data.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.install_data."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
from distutils.command.install_data import install_data
|
| 6 |
+
from distutils.tests import support
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@pytest.mark.usefixtures('save_env')
|
| 12 |
+
class TestInstallData(
|
| 13 |
+
support.TempdirManager,
|
| 14 |
+
):
|
| 15 |
+
def test_simple_run(self):
|
| 16 |
+
pkg_dir, dist = self.create_dist()
|
| 17 |
+
cmd = install_data(dist)
|
| 18 |
+
cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
|
| 19 |
+
|
| 20 |
+
# data_files can contain
|
| 21 |
+
# - simple files
|
| 22 |
+
# - a Path object
|
| 23 |
+
# - a tuple with a path, and a list of file
|
| 24 |
+
one = os.path.join(pkg_dir, 'one')
|
| 25 |
+
self.write_file(one, 'xxx')
|
| 26 |
+
inst2 = os.path.join(pkg_dir, 'inst2')
|
| 27 |
+
two = os.path.join(pkg_dir, 'two')
|
| 28 |
+
self.write_file(two, 'xxx')
|
| 29 |
+
three = pathlib.Path(pkg_dir) / 'three'
|
| 30 |
+
self.write_file(three, 'xxx')
|
| 31 |
+
|
| 32 |
+
cmd.data_files = [one, (inst2, [two]), three]
|
| 33 |
+
assert cmd.get_inputs() == [one, (inst2, [two]), three]
|
| 34 |
+
|
| 35 |
+
# let's run the command
|
| 36 |
+
cmd.ensure_finalized()
|
| 37 |
+
cmd.run()
|
| 38 |
+
|
| 39 |
+
# let's check the result
|
| 40 |
+
assert len(cmd.get_outputs()) == 3
|
| 41 |
+
rthree = os.path.split(one)[-1]
|
| 42 |
+
assert os.path.exists(os.path.join(inst, rthree))
|
| 43 |
+
rtwo = os.path.split(two)[-1]
|
| 44 |
+
assert os.path.exists(os.path.join(inst2, rtwo))
|
| 45 |
+
rone = os.path.split(one)[-1]
|
| 46 |
+
assert os.path.exists(os.path.join(inst, rone))
|
| 47 |
+
cmd.outfiles = []
|
| 48 |
+
|
| 49 |
+
# let's try with warn_dir one
|
| 50 |
+
cmd.warn_dir = True
|
| 51 |
+
cmd.ensure_finalized()
|
| 52 |
+
cmd.run()
|
| 53 |
+
|
| 54 |
+
# let's check the result
|
| 55 |
+
assert len(cmd.get_outputs()) == 3
|
| 56 |
+
assert os.path.exists(os.path.join(inst, rthree))
|
| 57 |
+
assert os.path.exists(os.path.join(inst2, rtwo))
|
| 58 |
+
assert os.path.exists(os.path.join(inst, rone))
|
| 59 |
+
cmd.outfiles = []
|
| 60 |
+
|
| 61 |
+
# now using root and empty dir
|
| 62 |
+
cmd.root = os.path.join(pkg_dir, 'root')
|
| 63 |
+
inst5 = os.path.join(pkg_dir, 'inst5')
|
| 64 |
+
four = os.path.join(cmd.install_dir, 'four')
|
| 65 |
+
self.write_file(four, 'xx')
|
| 66 |
+
cmd.data_files = [one, (inst2, [two]), three, ('inst5', [four]), (inst5, [])]
|
| 67 |
+
cmd.ensure_finalized()
|
| 68 |
+
cmd.run()
|
| 69 |
+
|
| 70 |
+
# let's check the result
|
| 71 |
+
assert len(cmd.get_outputs()) == 5
|
| 72 |
+
assert os.path.exists(os.path.join(inst, rthree))
|
| 73 |
+
assert os.path.exists(os.path.join(inst2, rtwo))
|
| 74 |
+
assert os.path.exists(os.path.join(inst, rone))
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_log.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.log"""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
from distutils._log import log
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestLog:
|
| 8 |
+
def test_non_ascii(self, caplog):
|
| 9 |
+
caplog.set_level(logging.DEBUG)
|
| 10 |
+
log.debug('Dεbug\tMėssãge')
|
| 11 |
+
log.fatal('Fαtal\tÈrrōr')
|
| 12 |
+
assert caplog.messages == ['Dεbug\tMėssãge', 'Fαtal\tÈrrōr']
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/tests/test_sysconfig.py
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.sysconfig."""
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import distutils
|
| 5 |
+
import os
|
| 6 |
+
import pathlib
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
from distutils import sysconfig
|
| 10 |
+
from distutils.ccompiler import new_compiler # noqa: F401
|
| 11 |
+
from distutils.unixccompiler import UnixCCompiler
|
| 12 |
+
|
| 13 |
+
import jaraco.envs
|
| 14 |
+
import path
|
| 15 |
+
import pytest
|
| 16 |
+
from jaraco.text import trim
|
| 17 |
+
from test.support import swap_item
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _gen_makefile(root, contents):
|
| 21 |
+
jaraco.path.build({'Makefile': trim(contents)}, root)
|
| 22 |
+
return root / 'Makefile'
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@pytest.mark.usefixtures('save_env')
|
| 26 |
+
class TestSysconfig:
|
| 27 |
+
def test_get_config_h_filename(self):
|
| 28 |
+
config_h = sysconfig.get_config_h_filename()
|
| 29 |
+
assert os.path.isfile(config_h)
|
| 30 |
+
|
| 31 |
+
@pytest.mark.skipif("platform.system() == 'Windows'")
|
| 32 |
+
@pytest.mark.skipif("sys.implementation.name != 'cpython'")
|
| 33 |
+
def test_get_makefile_filename(self):
|
| 34 |
+
makefile = sysconfig.get_makefile_filename()
|
| 35 |
+
assert os.path.isfile(makefile)
|
| 36 |
+
|
| 37 |
+
def test_get_python_lib(self, tmp_path):
|
| 38 |
+
assert sysconfig.get_python_lib() != sysconfig.get_python_lib(prefix=tmp_path)
|
| 39 |
+
|
| 40 |
+
def test_get_config_vars(self):
|
| 41 |
+
cvars = sysconfig.get_config_vars()
|
| 42 |
+
assert isinstance(cvars, dict)
|
| 43 |
+
assert cvars
|
| 44 |
+
|
| 45 |
+
@pytest.mark.skipif('sysconfig.IS_PYPY')
|
| 46 |
+
@pytest.mark.skipif('sysconfig.python_build')
|
| 47 |
+
@pytest.mark.xfail('platform.system() == "Windows"')
|
| 48 |
+
def test_srcdir_simple(self):
|
| 49 |
+
# See #15364.
|
| 50 |
+
srcdir = pathlib.Path(sysconfig.get_config_var('srcdir'))
|
| 51 |
+
|
| 52 |
+
assert srcdir.absolute()
|
| 53 |
+
assert srcdir.is_dir()
|
| 54 |
+
|
| 55 |
+
makefile = pathlib.Path(sysconfig.get_makefile_filename())
|
| 56 |
+
assert makefile.parent.samefile(srcdir)
|
| 57 |
+
|
| 58 |
+
@pytest.mark.skipif('sysconfig.IS_PYPY')
|
| 59 |
+
@pytest.mark.skipif('not sysconfig.python_build')
|
| 60 |
+
def test_srcdir_python_build(self):
|
| 61 |
+
# See #15364.
|
| 62 |
+
srcdir = pathlib.Path(sysconfig.get_config_var('srcdir'))
|
| 63 |
+
|
| 64 |
+
# The python executable has not been installed so srcdir
|
| 65 |
+
# should be a full source checkout.
|
| 66 |
+
Python_h = srcdir.joinpath('Include', 'Python.h')
|
| 67 |
+
assert Python_h.is_file()
|
| 68 |
+
assert sysconfig._is_python_source_dir(srcdir)
|
| 69 |
+
assert sysconfig._is_python_source_dir(str(srcdir))
|
| 70 |
+
|
| 71 |
+
def test_srcdir_independent_of_cwd(self):
|
| 72 |
+
"""
|
| 73 |
+
srcdir should be independent of the current working directory
|
| 74 |
+
"""
|
| 75 |
+
# See #15364.
|
| 76 |
+
srcdir = sysconfig.get_config_var('srcdir')
|
| 77 |
+
with path.Path('..'):
|
| 78 |
+
srcdir2 = sysconfig.get_config_var('srcdir')
|
| 79 |
+
assert srcdir == srcdir2
|
| 80 |
+
|
| 81 |
+
def customize_compiler(self):
|
| 82 |
+
# make sure AR gets caught
|
| 83 |
+
class compiler:
|
| 84 |
+
compiler_type = 'unix'
|
| 85 |
+
executables = UnixCCompiler.executables
|
| 86 |
+
|
| 87 |
+
def __init__(self):
|
| 88 |
+
self.exes = {}
|
| 89 |
+
|
| 90 |
+
def set_executables(self, **kw):
|
| 91 |
+
for k, v in kw.items():
|
| 92 |
+
self.exes[k] = v
|
| 93 |
+
|
| 94 |
+
sysconfig_vars = {
|
| 95 |
+
'AR': 'sc_ar',
|
| 96 |
+
'CC': 'sc_cc',
|
| 97 |
+
'CXX': 'sc_cxx',
|
| 98 |
+
'ARFLAGS': '--sc-arflags',
|
| 99 |
+
'CFLAGS': '--sc-cflags',
|
| 100 |
+
'CCSHARED': '--sc-ccshared',
|
| 101 |
+
'LDSHARED': 'sc_ldshared',
|
| 102 |
+
'SHLIB_SUFFIX': 'sc_shutil_suffix',
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
comp = compiler()
|
| 106 |
+
with contextlib.ExitStack() as cm:
|
| 107 |
+
for key, value in sysconfig_vars.items():
|
| 108 |
+
cm.enter_context(swap_item(sysconfig._config_vars, key, value))
|
| 109 |
+
sysconfig.customize_compiler(comp)
|
| 110 |
+
|
| 111 |
+
return comp
|
| 112 |
+
|
| 113 |
+
@pytest.mark.skipif("not isinstance(new_compiler(), UnixCCompiler)")
|
| 114 |
+
@pytest.mark.usefixtures('disable_macos_customization')
|
| 115 |
+
def test_customize_compiler(self):
|
| 116 |
+
# Make sure that sysconfig._config_vars is initialized
|
| 117 |
+
sysconfig.get_config_vars()
|
| 118 |
+
|
| 119 |
+
os.environ['AR'] = 'env_ar'
|
| 120 |
+
os.environ['CC'] = 'env_cc'
|
| 121 |
+
os.environ['CPP'] = 'env_cpp'
|
| 122 |
+
os.environ['CXX'] = 'env_cxx --env-cxx-flags'
|
| 123 |
+
os.environ['LDSHARED'] = 'env_ldshared'
|
| 124 |
+
os.environ['LDFLAGS'] = '--env-ldflags'
|
| 125 |
+
os.environ['ARFLAGS'] = '--env-arflags'
|
| 126 |
+
os.environ['CFLAGS'] = '--env-cflags'
|
| 127 |
+
os.environ['CPPFLAGS'] = '--env-cppflags'
|
| 128 |
+
os.environ['RANLIB'] = 'env_ranlib'
|
| 129 |
+
|
| 130 |
+
comp = self.customize_compiler()
|
| 131 |
+
assert comp.exes['archiver'] == 'env_ar --env-arflags'
|
| 132 |
+
assert comp.exes['preprocessor'] == 'env_cpp --env-cppflags'
|
| 133 |
+
assert comp.exes['compiler'] == 'env_cc --env-cflags --env-cppflags'
|
| 134 |
+
assert comp.exes['compiler_so'] == (
|
| 135 |
+
'env_cc --env-cflags --env-cppflags --sc-ccshared'
|
| 136 |
+
)
|
| 137 |
+
assert (
|
| 138 |
+
comp.exes['compiler_cxx']
|
| 139 |
+
== 'env_cxx --env-cxx-flags --sc-cflags --env-cppflags'
|
| 140 |
+
)
|
| 141 |
+
assert comp.exes['linker_exe'] == 'env_cc'
|
| 142 |
+
assert comp.exes['linker_so'] == (
|
| 143 |
+
'env_ldshared --env-ldflags --env-cflags --env-cppflags'
|
| 144 |
+
)
|
| 145 |
+
assert comp.shared_lib_extension == 'sc_shutil_suffix'
|
| 146 |
+
|
| 147 |
+
if sys.platform == "darwin":
|
| 148 |
+
assert comp.exes['ranlib'] == 'env_ranlib'
|
| 149 |
+
else:
|
| 150 |
+
assert 'ranlib' not in comp.exes
|
| 151 |
+
|
| 152 |
+
del os.environ['AR']
|
| 153 |
+
del os.environ['CC']
|
| 154 |
+
del os.environ['CPP']
|
| 155 |
+
del os.environ['CXX']
|
| 156 |
+
del os.environ['LDSHARED']
|
| 157 |
+
del os.environ['LDFLAGS']
|
| 158 |
+
del os.environ['ARFLAGS']
|
| 159 |
+
del os.environ['CFLAGS']
|
| 160 |
+
del os.environ['CPPFLAGS']
|
| 161 |
+
del os.environ['RANLIB']
|
| 162 |
+
|
| 163 |
+
comp = self.customize_compiler()
|
| 164 |
+
assert comp.exes['archiver'] == 'sc_ar --sc-arflags'
|
| 165 |
+
assert comp.exes['preprocessor'] == 'sc_cc -E'
|
| 166 |
+
assert comp.exes['compiler'] == 'sc_cc --sc-cflags'
|
| 167 |
+
assert comp.exes['compiler_so'] == 'sc_cc --sc-cflags --sc-ccshared'
|
| 168 |
+
assert comp.exes['compiler_cxx'] == 'sc_cxx --sc-cflags'
|
| 169 |
+
assert comp.exes['linker_exe'] == 'sc_cc'
|
| 170 |
+
assert comp.exes['linker_so'] == 'sc_ldshared'
|
| 171 |
+
assert comp.shared_lib_extension == 'sc_shutil_suffix'
|
| 172 |
+
assert 'ranlib' not in comp.exes
|
| 173 |
+
|
| 174 |
+
def test_parse_makefile_base(self, tmp_path):
|
| 175 |
+
makefile = _gen_makefile(
|
| 176 |
+
tmp_path,
|
| 177 |
+
"""
|
| 178 |
+
CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'
|
| 179 |
+
VAR=$OTHER
|
| 180 |
+
OTHER=foo
|
| 181 |
+
""",
|
| 182 |
+
)
|
| 183 |
+
d = sysconfig.parse_makefile(makefile)
|
| 184 |
+
assert d == {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'", 'OTHER': 'foo'}
|
| 185 |
+
|
| 186 |
+
def test_parse_makefile_literal_dollar(self, tmp_path):
|
| 187 |
+
makefile = _gen_makefile(
|
| 188 |
+
tmp_path,
|
| 189 |
+
"""
|
| 190 |
+
CONFIG_ARGS= '--arg1=optarg1' 'ENV=\\$$LIB'
|
| 191 |
+
VAR=$OTHER
|
| 192 |
+
OTHER=foo
|
| 193 |
+
""",
|
| 194 |
+
)
|
| 195 |
+
d = sysconfig.parse_makefile(makefile)
|
| 196 |
+
assert d == {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'", 'OTHER': 'foo'}
|
| 197 |
+
|
| 198 |
+
def test_sysconfig_module(self):
|
| 199 |
+
import sysconfig as global_sysconfig
|
| 200 |
+
|
| 201 |
+
assert global_sysconfig.get_config_var('CFLAGS') == sysconfig.get_config_var(
|
| 202 |
+
'CFLAGS'
|
| 203 |
+
)
|
| 204 |
+
assert global_sysconfig.get_config_var('LDFLAGS') == sysconfig.get_config_var(
|
| 205 |
+
'LDFLAGS'
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
# On macOS, binary installers support extension module building on
|
| 209 |
+
# various levels of the operating system with differing Xcode
|
| 210 |
+
# configurations, requiring customization of some of the
|
| 211 |
+
# compiler configuration directives to suit the environment on
|
| 212 |
+
# the installed machine. Some of these customizations may require
|
| 213 |
+
# running external programs and are thus deferred until needed by
|
| 214 |
+
# the first extension module build. Only
|
| 215 |
+
# the Distutils version of sysconfig is used for extension module
|
| 216 |
+
# builds, which happens earlier in the Distutils tests. This may
|
| 217 |
+
# cause the following tests to fail since no tests have caused
|
| 218 |
+
# the global version of sysconfig to call the customization yet.
|
| 219 |
+
# The solution for now is to simply skip this test in this case.
|
| 220 |
+
# The longer-term solution is to only have one version of sysconfig.
|
| 221 |
+
@pytest.mark.skipif("sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER')")
|
| 222 |
+
def test_sysconfig_compiler_vars(self):
|
| 223 |
+
import sysconfig as global_sysconfig
|
| 224 |
+
|
| 225 |
+
if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
|
| 226 |
+
pytest.skip('compiler flags customized')
|
| 227 |
+
assert global_sysconfig.get_config_var('LDSHARED') == sysconfig.get_config_var(
|
| 228 |
+
'LDSHARED'
|
| 229 |
+
)
|
| 230 |
+
assert global_sysconfig.get_config_var('CC') == sysconfig.get_config_var('CC')
|
| 231 |
+
|
| 232 |
+
@pytest.mark.skipif("not sysconfig.get_config_var('EXT_SUFFIX')")
|
| 233 |
+
def test_SO_deprecation(self):
|
| 234 |
+
with pytest.warns(DeprecationWarning):
|
| 235 |
+
sysconfig.get_config_var('SO')
|
| 236 |
+
|
| 237 |
+
def test_customize_compiler_before_get_config_vars(self, tmp_path):
|
| 238 |
+
# Issue #21923: test that a Distribution compiler
|
| 239 |
+
# instance can be called without an explicit call to
|
| 240 |
+
# get_config_vars().
|
| 241 |
+
jaraco.path.build(
|
| 242 |
+
{
|
| 243 |
+
'file': trim("""
|
| 244 |
+
from distutils.core import Distribution
|
| 245 |
+
config = Distribution().get_command_obj('config')
|
| 246 |
+
# try_compile may pass or it may fail if no compiler
|
| 247 |
+
# is found but it should not raise an exception.
|
| 248 |
+
rc = config.try_compile('int x;')
|
| 249 |
+
""")
|
| 250 |
+
},
|
| 251 |
+
tmp_path,
|
| 252 |
+
)
|
| 253 |
+
p = subprocess.Popen(
|
| 254 |
+
[sys.executable, tmp_path / 'file'],
|
| 255 |
+
stdout=subprocess.PIPE,
|
| 256 |
+
stderr=subprocess.STDOUT,
|
| 257 |
+
universal_newlines=True,
|
| 258 |
+
encoding='utf-8',
|
| 259 |
+
)
|
| 260 |
+
outs, errs = p.communicate()
|
| 261 |
+
assert 0 == p.returncode, "Subprocess failed: " + outs
|
| 262 |
+
|
| 263 |
+
def test_parse_config_h(self):
|
| 264 |
+
config_h = sysconfig.get_config_h_filename()
|
| 265 |
+
input = {}
|
| 266 |
+
with open(config_h, encoding="utf-8") as f:
|
| 267 |
+
result = sysconfig.parse_config_h(f, g=input)
|
| 268 |
+
assert input is result
|
| 269 |
+
with open(config_h, encoding="utf-8") as f:
|
| 270 |
+
result = sysconfig.parse_config_h(f)
|
| 271 |
+
assert isinstance(result, dict)
|
| 272 |
+
|
| 273 |
+
@pytest.mark.skipif("platform.system() != 'Windows'")
|
| 274 |
+
@pytest.mark.skipif("sys.implementation.name != 'cpython'")
|
| 275 |
+
def test_win_ext_suffix(self):
|
| 276 |
+
assert sysconfig.get_config_var("EXT_SUFFIX").endswith(".pyd")
|
| 277 |
+
assert sysconfig.get_config_var("EXT_SUFFIX") != ".pyd"
|
| 278 |
+
|
| 279 |
+
@pytest.mark.skipif("platform.system() != 'Windows'")
|
| 280 |
+
@pytest.mark.skipif("sys.implementation.name != 'cpython'")
|
| 281 |
+
@pytest.mark.skipif(
|
| 282 |
+
'\\PCbuild\\'.casefold() not in sys.executable.casefold(),
|
| 283 |
+
reason='Need sys.executable to be in a source tree',
|
| 284 |
+
)
|
| 285 |
+
def test_win_build_venv_from_source_tree(self, tmp_path):
|
| 286 |
+
"""Ensure distutils.sysconfig detects venvs from source tree builds."""
|
| 287 |
+
env = jaraco.envs.VEnv()
|
| 288 |
+
env.create_opts = env.clean_opts
|
| 289 |
+
env.root = tmp_path
|
| 290 |
+
env.ensure_env()
|
| 291 |
+
cmd = [
|
| 292 |
+
env.exe(),
|
| 293 |
+
"-c",
|
| 294 |
+
"import distutils.sysconfig; print(distutils.sysconfig.python_build)",
|
| 295 |
+
]
|
| 296 |
+
distutils_path = os.path.dirname(os.path.dirname(distutils.__file__))
|
| 297 |
+
out = subprocess.check_output(
|
| 298 |
+
cmd, env={**os.environ, "PYTHONPATH": distutils_path}
|
| 299 |
+
)
|
| 300 |
+
assert out == "True"
|
| 301 |
+
|
| 302 |
+
def test_get_python_inc_missing_config_dir(self, monkeypatch):
|
| 303 |
+
"""
|
| 304 |
+
In portable Python installations, the sysconfig will be broken,
|
| 305 |
+
pointing to the directories where the installation was built and
|
| 306 |
+
not where it currently is. In this case, ensure that the missing
|
| 307 |
+
directory isn't used for get_python_inc.
|
| 308 |
+
|
| 309 |
+
See pypa/distutils#178.
|
| 310 |
+
"""
|
| 311 |
+
|
| 312 |
+
def override(name):
|
| 313 |
+
if name == 'INCLUDEPY':
|
| 314 |
+
return '/does-not-exist'
|
| 315 |
+
return sysconfig.get_config_var(name)
|
| 316 |
+
|
| 317 |
+
monkeypatch.setattr(sysconfig, 'get_config_var', override)
|
| 318 |
+
|
| 319 |
+
assert os.path.exists(sysconfig.get_python_inc())
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/version.py
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# distutils/version.py
|
| 3 |
+
#
|
| 4 |
+
# Implements multiple version numbering conventions for the
|
| 5 |
+
# Python Module Distribution Utilities.
|
| 6 |
+
#
|
| 7 |
+
# $Id$
|
| 8 |
+
#
|
| 9 |
+
|
| 10 |
+
"""Provides classes to represent module version numbers (one class for
|
| 11 |
+
each style of version numbering). There are currently two such classes
|
| 12 |
+
implemented: StrictVersion and LooseVersion.
|
| 13 |
+
|
| 14 |
+
Every version number class implements the following interface:
|
| 15 |
+
* the 'parse' method takes a string and parses it to some internal
|
| 16 |
+
representation; if the string is an invalid version number,
|
| 17 |
+
'parse' raises a ValueError exception
|
| 18 |
+
* the class constructor takes an optional string argument which,
|
| 19 |
+
if supplied, is passed to 'parse'
|
| 20 |
+
* __str__ reconstructs the string that was passed to 'parse' (or
|
| 21 |
+
an equivalent string -- ie. one that will generate an equivalent
|
| 22 |
+
version number instance)
|
| 23 |
+
* __repr__ generates Python code to recreate the version number instance
|
| 24 |
+
* _cmp compares the current instance with either another instance
|
| 25 |
+
of the same class or a string (which will be parsed to an instance
|
| 26 |
+
of the same class, thus must follow the same rules)
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
import contextlib
|
| 30 |
+
import re
|
| 31 |
+
import warnings
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@contextlib.contextmanager
|
| 35 |
+
def suppress_known_deprecation():
|
| 36 |
+
with warnings.catch_warnings(record=True) as ctx:
|
| 37 |
+
warnings.filterwarnings(
|
| 38 |
+
action='default',
|
| 39 |
+
category=DeprecationWarning,
|
| 40 |
+
message="distutils Version classes are deprecated.",
|
| 41 |
+
)
|
| 42 |
+
yield ctx
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class Version:
|
| 46 |
+
"""Abstract base class for version numbering classes. Just provides
|
| 47 |
+
constructor (__init__) and reproducer (__repr__), because those
|
| 48 |
+
seem to be the same for all version numbering classes; and route
|
| 49 |
+
rich comparisons to _cmp.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def __init__(self, vstring=None):
|
| 53 |
+
if vstring:
|
| 54 |
+
self.parse(vstring)
|
| 55 |
+
warnings.warn(
|
| 56 |
+
"distutils Version classes are deprecated. Use packaging.version instead.",
|
| 57 |
+
DeprecationWarning,
|
| 58 |
+
stacklevel=2,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
def __repr__(self):
|
| 62 |
+
return f"{self.__class__.__name__} ('{self}')"
|
| 63 |
+
|
| 64 |
+
def __eq__(self, other):
|
| 65 |
+
c = self._cmp(other)
|
| 66 |
+
if c is NotImplemented:
|
| 67 |
+
return c
|
| 68 |
+
return c == 0
|
| 69 |
+
|
| 70 |
+
def __lt__(self, other):
|
| 71 |
+
c = self._cmp(other)
|
| 72 |
+
if c is NotImplemented:
|
| 73 |
+
return c
|
| 74 |
+
return c < 0
|
| 75 |
+
|
| 76 |
+
def __le__(self, other):
|
| 77 |
+
c = self._cmp(other)
|
| 78 |
+
if c is NotImplemented:
|
| 79 |
+
return c
|
| 80 |
+
return c <= 0
|
| 81 |
+
|
| 82 |
+
def __gt__(self, other):
|
| 83 |
+
c = self._cmp(other)
|
| 84 |
+
if c is NotImplemented:
|
| 85 |
+
return c
|
| 86 |
+
return c > 0
|
| 87 |
+
|
| 88 |
+
def __ge__(self, other):
|
| 89 |
+
c = self._cmp(other)
|
| 90 |
+
if c is NotImplemented:
|
| 91 |
+
return c
|
| 92 |
+
return c >= 0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# Interface for version-number classes -- must be implemented
|
| 96 |
+
# by the following classes (the concrete ones -- Version should
|
| 97 |
+
# be treated as an abstract class).
|
| 98 |
+
# __init__ (string) - create and take same action as 'parse'
|
| 99 |
+
# (string parameter is optional)
|
| 100 |
+
# parse (string) - convert a string representation to whatever
|
| 101 |
+
# internal representation is appropriate for
|
| 102 |
+
# this style of version numbering
|
| 103 |
+
# __str__ (self) - convert back to a string; should be very similar
|
| 104 |
+
# (if not identical to) the string supplied to parse
|
| 105 |
+
# __repr__ (self) - generate Python code to recreate
|
| 106 |
+
# the instance
|
| 107 |
+
# _cmp (self, other) - compare two version numbers ('other' may
|
| 108 |
+
# be an unparsed version string, or another
|
| 109 |
+
# instance of your version class)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class StrictVersion(Version):
|
| 113 |
+
"""Version numbering for anal retentives and software idealists.
|
| 114 |
+
Implements the standard interface for version number classes as
|
| 115 |
+
described above. A version number consists of two or three
|
| 116 |
+
dot-separated numeric components, with an optional "pre-release" tag
|
| 117 |
+
on the end. The pre-release tag consists of the letter 'a' or 'b'
|
| 118 |
+
followed by a number. If the numeric components of two version
|
| 119 |
+
numbers are equal, then one with a pre-release tag will always
|
| 120 |
+
be deemed earlier (lesser) than one without.
|
| 121 |
+
|
| 122 |
+
The following are valid version numbers (shown in the order that
|
| 123 |
+
would be obtained by sorting according to the supplied cmp function):
|
| 124 |
+
|
| 125 |
+
0.4 0.4.0 (these two are equivalent)
|
| 126 |
+
0.4.1
|
| 127 |
+
0.5a1
|
| 128 |
+
0.5b3
|
| 129 |
+
0.5
|
| 130 |
+
0.9.6
|
| 131 |
+
1.0
|
| 132 |
+
1.0.4a3
|
| 133 |
+
1.0.4b1
|
| 134 |
+
1.0.4
|
| 135 |
+
|
| 136 |
+
The following are examples of invalid version numbers:
|
| 137 |
+
|
| 138 |
+
1
|
| 139 |
+
2.7.2.2
|
| 140 |
+
1.3.a4
|
| 141 |
+
1.3pl1
|
| 142 |
+
1.3c4
|
| 143 |
+
|
| 144 |
+
The rationale for this version numbering system will be explained
|
| 145 |
+
in the distutils documentation.
|
| 146 |
+
"""
|
| 147 |
+
|
| 148 |
+
version_re = re.compile(
|
| 149 |
+
r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$', re.VERBOSE | re.ASCII
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
def parse(self, vstring):
|
| 153 |
+
match = self.version_re.match(vstring)
|
| 154 |
+
if not match:
|
| 155 |
+
raise ValueError(f"invalid version number '{vstring}'")
|
| 156 |
+
|
| 157 |
+
(major, minor, patch, prerelease, prerelease_num) = match.group(1, 2, 4, 5, 6)
|
| 158 |
+
|
| 159 |
+
if patch:
|
| 160 |
+
self.version = tuple(map(int, [major, minor, patch]))
|
| 161 |
+
else:
|
| 162 |
+
self.version = tuple(map(int, [major, minor])) + (0,)
|
| 163 |
+
|
| 164 |
+
if prerelease:
|
| 165 |
+
self.prerelease = (prerelease[0], int(prerelease_num))
|
| 166 |
+
else:
|
| 167 |
+
self.prerelease = None
|
| 168 |
+
|
| 169 |
+
def __str__(self):
|
| 170 |
+
if self.version[2] == 0:
|
| 171 |
+
vstring = '.'.join(map(str, self.version[0:2]))
|
| 172 |
+
else:
|
| 173 |
+
vstring = '.'.join(map(str, self.version))
|
| 174 |
+
|
| 175 |
+
if self.prerelease:
|
| 176 |
+
vstring = vstring + self.prerelease[0] + str(self.prerelease[1])
|
| 177 |
+
|
| 178 |
+
return vstring
|
| 179 |
+
|
| 180 |
+
def _cmp(self, other):
|
| 181 |
+
if isinstance(other, str):
|
| 182 |
+
with suppress_known_deprecation():
|
| 183 |
+
other = StrictVersion(other)
|
| 184 |
+
elif not isinstance(other, StrictVersion):
|
| 185 |
+
return NotImplemented
|
| 186 |
+
|
| 187 |
+
if self.version == other.version:
|
| 188 |
+
# versions match; pre-release drives the comparison
|
| 189 |
+
return self._cmp_prerelease(other)
|
| 190 |
+
|
| 191 |
+
return -1 if self.version < other.version else 1
|
| 192 |
+
|
| 193 |
+
def _cmp_prerelease(self, other):
|
| 194 |
+
"""
|
| 195 |
+
case 1: self has prerelease, other doesn't; other is greater
|
| 196 |
+
case 2: self doesn't have prerelease, other does: self is greater
|
| 197 |
+
case 3: both or neither have prerelease: compare them!
|
| 198 |
+
"""
|
| 199 |
+
if self.prerelease and not other.prerelease:
|
| 200 |
+
return -1
|
| 201 |
+
elif not self.prerelease and other.prerelease:
|
| 202 |
+
return 1
|
| 203 |
+
|
| 204 |
+
if self.prerelease == other.prerelease:
|
| 205 |
+
return 0
|
| 206 |
+
elif self.prerelease < other.prerelease:
|
| 207 |
+
return -1
|
| 208 |
+
else:
|
| 209 |
+
return 1
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
# end class StrictVersion
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
# The rules according to Greg Stein:
|
| 216 |
+
# 1) a version number has 1 or more numbers separated by a period or by
|
| 217 |
+
# sequences of letters. If only periods, then these are compared
|
| 218 |
+
# left-to-right to determine an ordering.
|
| 219 |
+
# 2) sequences of letters are part of the tuple for comparison and are
|
| 220 |
+
# compared lexicographically
|
| 221 |
+
# 3) recognize the numeric components may have leading zeroes
|
| 222 |
+
#
|
| 223 |
+
# The LooseVersion class below implements these rules: a version number
|
| 224 |
+
# string is split up into a tuple of integer and string components, and
|
| 225 |
+
# comparison is a simple tuple comparison. This means that version
|
| 226 |
+
# numbers behave in a predictable and obvious way, but a way that might
|
| 227 |
+
# not necessarily be how people *want* version numbers to behave. There
|
| 228 |
+
# wouldn't be a problem if people could stick to purely numeric version
|
| 229 |
+
# numbers: just split on period and compare the numbers as tuples.
|
| 230 |
+
# However, people insist on putting letters into their version numbers;
|
| 231 |
+
# the most common purpose seems to be:
|
| 232 |
+
# - indicating a "pre-release" version
|
| 233 |
+
# ('alpha', 'beta', 'a', 'b', 'pre', 'p')
|
| 234 |
+
# - indicating a post-release patch ('p', 'pl', 'patch')
|
| 235 |
+
# but of course this can't cover all version number schemes, and there's
|
| 236 |
+
# no way to know what a programmer means without asking him.
|
| 237 |
+
#
|
| 238 |
+
# The problem is what to do with letters (and other non-numeric
|
| 239 |
+
# characters) in a version number. The current implementation does the
|
| 240 |
+
# obvious and predictable thing: keep them as strings and compare
|
| 241 |
+
# lexically within a tuple comparison. This has the desired effect if
|
| 242 |
+
# an appended letter sequence implies something "post-release":
|
| 243 |
+
# eg. "0.99" < "0.99pl14" < "1.0", and "5.001" < "5.001m" < "5.002".
|
| 244 |
+
#
|
| 245 |
+
# However, if letters in a version number imply a pre-release version,
|
| 246 |
+
# the "obvious" thing isn't correct. Eg. you would expect that
|
| 247 |
+
# "1.5.1" < "1.5.2a2" < "1.5.2", but under the tuple/lexical comparison
|
| 248 |
+
# implemented here, this just isn't so.
|
| 249 |
+
#
|
| 250 |
+
# Two possible solutions come to mind. The first is to tie the
|
| 251 |
+
# comparison algorithm to a particular set of semantic rules, as has
|
| 252 |
+
# been done in the StrictVersion class above. This works great as long
|
| 253 |
+
# as everyone can go along with bondage and discipline. Hopefully a
|
| 254 |
+
# (large) subset of Python module programmers will agree that the
|
| 255 |
+
# particular flavour of bondage and discipline provided by StrictVersion
|
| 256 |
+
# provides enough benefit to be worth using, and will submit their
|
| 257 |
+
# version numbering scheme to its domination. The free-thinking
|
| 258 |
+
# anarchists in the lot will never give in, though, and something needs
|
| 259 |
+
# to be done to accommodate them.
|
| 260 |
+
#
|
| 261 |
+
# Perhaps a "moderately strict" version class could be implemented that
|
| 262 |
+
# lets almost anything slide (syntactically), and makes some heuristic
|
| 263 |
+
# assumptions about non-digits in version number strings. This could
|
| 264 |
+
# sink into special-case-hell, though; if I was as talented and
|
| 265 |
+
# idiosyncratic as Larry Wall, I'd go ahead and implement a class that
|
| 266 |
+
# somehow knows that "1.2.1" < "1.2.2a2" < "1.2.2" < "1.2.2pl3", and is
|
| 267 |
+
# just as happy dealing with things like "2g6" and "1.13++". I don't
|
| 268 |
+
# think I'm smart enough to do it right though.
|
| 269 |
+
#
|
| 270 |
+
# In any case, I've coded the test suite for this module (see
|
| 271 |
+
# ../test/test_version.py) specifically to fail on things like comparing
|
| 272 |
+
# "1.2a2" and "1.2". That's not because the *code* is doing anything
|
| 273 |
+
# wrong, it's because the simple, obvious design doesn't match my
|
| 274 |
+
# complicated, hairy expectations for real-world version numbers. It
|
| 275 |
+
# would be a snap to fix the test suite to say, "Yep, LooseVersion does
|
| 276 |
+
# the Right Thing" (ie. the code matches the conception). But I'd rather
|
| 277 |
+
# have a conception that matches common notions about version numbers.
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
class LooseVersion(Version):
|
| 281 |
+
"""Version numbering for anarchists and software realists.
|
| 282 |
+
Implements the standard interface for version number classes as
|
| 283 |
+
described above. A version number consists of a series of numbers,
|
| 284 |
+
separated by either periods or strings of letters. When comparing
|
| 285 |
+
version numbers, the numeric components will be compared
|
| 286 |
+
numerically, and the alphabetic components lexically. The following
|
| 287 |
+
are all valid version numbers, in no particular order:
|
| 288 |
+
|
| 289 |
+
1.5.1
|
| 290 |
+
1.5.2b2
|
| 291 |
+
161
|
| 292 |
+
3.10a
|
| 293 |
+
8.02
|
| 294 |
+
3.4j
|
| 295 |
+
1996.07.12
|
| 296 |
+
3.2.pl0
|
| 297 |
+
3.1.1.6
|
| 298 |
+
2g6
|
| 299 |
+
11g
|
| 300 |
+
0.960923
|
| 301 |
+
2.2beta29
|
| 302 |
+
1.13++
|
| 303 |
+
5.5.kw
|
| 304 |
+
2.0b1pl0
|
| 305 |
+
|
| 306 |
+
In fact, there is no such thing as an invalid version number under
|
| 307 |
+
this scheme; the rules for comparison are simple and predictable,
|
| 308 |
+
but may not always give the results you want (for some definition
|
| 309 |
+
of "want").
|
| 310 |
+
"""
|
| 311 |
+
|
| 312 |
+
component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
|
| 313 |
+
|
| 314 |
+
def parse(self, vstring):
|
| 315 |
+
# I've given up on thinking I can reconstruct the version string
|
| 316 |
+
# from the parsed tuple -- so I just store the string here for
|
| 317 |
+
# use by __str__
|
| 318 |
+
self.vstring = vstring
|
| 319 |
+
components = [x for x in self.component_re.split(vstring) if x and x != '.']
|
| 320 |
+
for i, obj in enumerate(components):
|
| 321 |
+
try:
|
| 322 |
+
components[i] = int(obj)
|
| 323 |
+
except ValueError:
|
| 324 |
+
pass
|
| 325 |
+
|
| 326 |
+
self.version = components
|
| 327 |
+
|
| 328 |
+
def __str__(self):
|
| 329 |
+
return self.vstring
|
| 330 |
+
|
| 331 |
+
def __repr__(self):
|
| 332 |
+
return f"LooseVersion ('{self}')"
|
| 333 |
+
|
| 334 |
+
def _cmp(self, other):
|
| 335 |
+
if isinstance(other, str):
|
| 336 |
+
other = LooseVersion(other)
|
| 337 |
+
elif not isinstance(other, LooseVersion):
|
| 338 |
+
return NotImplemented
|
| 339 |
+
|
| 340 |
+
if self.version == other.version:
|
| 341 |
+
return 0
|
| 342 |
+
if self.version < other.version:
|
| 343 |
+
return -1
|
| 344 |
+
if self.version > other.version:
|
| 345 |
+
return 1
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
# end class LooseVersion
|
videollama2/lib/python3.10/site-packages/setuptools/_distutils/versionpredicate.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Module for parsing and testing package version predicate strings."""
|
| 2 |
+
|
| 3 |
+
import operator
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
from . import version
|
| 7 |
+
|
| 8 |
+
re_validPackage = re.compile(r"(?i)^\s*([a-z_]\w*(?:\.[a-z_]\w*)*)(.*)", re.ASCII)
|
| 9 |
+
# (package) (rest)
|
| 10 |
+
|
| 11 |
+
re_paren = re.compile(r"^\s*\((.*)\)\s*$") # (list) inside of parentheses
|
| 12 |
+
re_splitComparison = re.compile(r"^\s*(<=|>=|<|>|!=|==)\s*([^\s,]+)\s*$")
|
| 13 |
+
# (comp) (version)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def splitUp(pred):
|
| 17 |
+
"""Parse a single version comparison.
|
| 18 |
+
|
| 19 |
+
Return (comparison string, StrictVersion)
|
| 20 |
+
"""
|
| 21 |
+
res = re_splitComparison.match(pred)
|
| 22 |
+
if not res:
|
| 23 |
+
raise ValueError(f"bad package restriction syntax: {pred!r}")
|
| 24 |
+
comp, verStr = res.groups()
|
| 25 |
+
with version.suppress_known_deprecation():
|
| 26 |
+
other = version.StrictVersion(verStr)
|
| 27 |
+
return (comp, other)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
compmap = {
|
| 31 |
+
"<": operator.lt,
|
| 32 |
+
"<=": operator.le,
|
| 33 |
+
"==": operator.eq,
|
| 34 |
+
">": operator.gt,
|
| 35 |
+
">=": operator.ge,
|
| 36 |
+
"!=": operator.ne,
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class VersionPredicate:
|
| 41 |
+
"""Parse and test package version predicates.
|
| 42 |
+
|
| 43 |
+
>>> v = VersionPredicate('pyepat.abc (>1.0, <3333.3a1, !=1555.1b3)')
|
| 44 |
+
|
| 45 |
+
The `name` attribute provides the full dotted name that is given::
|
| 46 |
+
|
| 47 |
+
>>> v.name
|
| 48 |
+
'pyepat.abc'
|
| 49 |
+
|
| 50 |
+
The str() of a `VersionPredicate` provides a normalized
|
| 51 |
+
human-readable version of the expression::
|
| 52 |
+
|
| 53 |
+
>>> print(v)
|
| 54 |
+
pyepat.abc (> 1.0, < 3333.3a1, != 1555.1b3)
|
| 55 |
+
|
| 56 |
+
The `satisfied_by()` method can be used to determine with a given
|
| 57 |
+
version number is included in the set described by the version
|
| 58 |
+
restrictions::
|
| 59 |
+
|
| 60 |
+
>>> v.satisfied_by('1.1')
|
| 61 |
+
True
|
| 62 |
+
>>> v.satisfied_by('1.4')
|
| 63 |
+
True
|
| 64 |
+
>>> v.satisfied_by('1.0')
|
| 65 |
+
False
|
| 66 |
+
>>> v.satisfied_by('4444.4')
|
| 67 |
+
False
|
| 68 |
+
>>> v.satisfied_by('1555.1b3')
|
| 69 |
+
False
|
| 70 |
+
|
| 71 |
+
`VersionPredicate` is flexible in accepting extra whitespace::
|
| 72 |
+
|
| 73 |
+
>>> v = VersionPredicate(' pat( == 0.1 ) ')
|
| 74 |
+
>>> v.name
|
| 75 |
+
'pat'
|
| 76 |
+
>>> v.satisfied_by('0.1')
|
| 77 |
+
True
|
| 78 |
+
>>> v.satisfied_by('0.2')
|
| 79 |
+
False
|
| 80 |
+
|
| 81 |
+
If any version numbers passed in do not conform to the
|
| 82 |
+
restrictions of `StrictVersion`, a `ValueError` is raised::
|
| 83 |
+
|
| 84 |
+
>>> v = VersionPredicate('p1.p2.p3.p4(>=1.0, <=1.3a1, !=1.2zb3)')
|
| 85 |
+
Traceback (most recent call last):
|
| 86 |
+
...
|
| 87 |
+
ValueError: invalid version number '1.2zb3'
|
| 88 |
+
|
| 89 |
+
It the module or package name given does not conform to what's
|
| 90 |
+
allowed as a legal module or package name, `ValueError` is
|
| 91 |
+
raised::
|
| 92 |
+
|
| 93 |
+
>>> v = VersionPredicate('foo-bar')
|
| 94 |
+
Traceback (most recent call last):
|
| 95 |
+
...
|
| 96 |
+
ValueError: expected parenthesized list: '-bar'
|
| 97 |
+
|
| 98 |
+
>>> v = VersionPredicate('foo bar (12.21)')
|
| 99 |
+
Traceback (most recent call last):
|
| 100 |
+
...
|
| 101 |
+
ValueError: expected parenthesized list: 'bar (12.21)'
|
| 102 |
+
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
def __init__(self, versionPredicateStr):
|
| 106 |
+
"""Parse a version predicate string."""
|
| 107 |
+
# Fields:
|
| 108 |
+
# name: package name
|
| 109 |
+
# pred: list of (comparison string, StrictVersion)
|
| 110 |
+
|
| 111 |
+
versionPredicateStr = versionPredicateStr.strip()
|
| 112 |
+
if not versionPredicateStr:
|
| 113 |
+
raise ValueError("empty package restriction")
|
| 114 |
+
match = re_validPackage.match(versionPredicateStr)
|
| 115 |
+
if not match:
|
| 116 |
+
raise ValueError(f"bad package name in {versionPredicateStr!r}")
|
| 117 |
+
self.name, paren = match.groups()
|
| 118 |
+
paren = paren.strip()
|
| 119 |
+
if paren:
|
| 120 |
+
match = re_paren.match(paren)
|
| 121 |
+
if not match:
|
| 122 |
+
raise ValueError(f"expected parenthesized list: {paren!r}")
|
| 123 |
+
str = match.groups()[0]
|
| 124 |
+
self.pred = [splitUp(aPred) for aPred in str.split(",")]
|
| 125 |
+
if not self.pred:
|
| 126 |
+
raise ValueError(f"empty parenthesized list in {versionPredicateStr!r}")
|
| 127 |
+
else:
|
| 128 |
+
self.pred = []
|
| 129 |
+
|
| 130 |
+
def __str__(self):
|
| 131 |
+
if self.pred:
|
| 132 |
+
seq = [cond + " " + str(ver) for cond, ver in self.pred]
|
| 133 |
+
return self.name + " (" + ", ".join(seq) + ")"
|
| 134 |
+
else:
|
| 135 |
+
return self.name
|
| 136 |
+
|
| 137 |
+
def satisfied_by(self, version):
|
| 138 |
+
"""True if version is compatible with all the predicates in self.
|
| 139 |
+
The parameter version must be acceptable to the StrictVersion
|
| 140 |
+
constructor. It may be either a string or StrictVersion.
|
| 141 |
+
"""
|
| 142 |
+
for cond, ver in self.pred:
|
| 143 |
+
if not compmap[cond](version, ver):
|
| 144 |
+
return False
|
| 145 |
+
return True
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
_provision_rx = None
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def split_provision(value):
|
| 152 |
+
"""Return the name and optional version number of a provision.
|
| 153 |
+
|
| 154 |
+
The version number, if given, will be returned as a `StrictVersion`
|
| 155 |
+
instance, otherwise it will be `None`.
|
| 156 |
+
|
| 157 |
+
>>> split_provision('mypkg')
|
| 158 |
+
('mypkg', None)
|
| 159 |
+
>>> split_provision(' mypkg( 1.2 ) ')
|
| 160 |
+
('mypkg', StrictVersion ('1.2'))
|
| 161 |
+
"""
|
| 162 |
+
global _provision_rx
|
| 163 |
+
if _provision_rx is None:
|
| 164 |
+
_provision_rx = re.compile(
|
| 165 |
+
r"([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$", re.ASCII
|
| 166 |
+
)
|
| 167 |
+
value = value.strip()
|
| 168 |
+
m = _provision_rx.match(value)
|
| 169 |
+
if not m:
|
| 170 |
+
raise ValueError(f"illegal provides specification: {value!r}")
|
| 171 |
+
ver = m.group(2) or None
|
| 172 |
+
if ver:
|
| 173 |
+
with version.suppress_known_deprecation():
|
| 174 |
+
ver = version.StrictVersion(ver)
|
| 175 |
+
return m.group(1), ver
|
vllm/lib/python3.10/site-packages/torch/include/THC/THCDeviceUtils.cuh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// TODO: Remove this header
|
| 3 |
+
#include <ATen/cuda/DeviceUtils.cuh>
|
vllm/lib/python3.10/site-packages/torch/include/kineto/ClientInterface.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
namespace libkineto {
|
| 12 |
+
|
| 13 |
+
class ClientInterface {
|
| 14 |
+
public:
|
| 15 |
+
virtual ~ClientInterface() {}
|
| 16 |
+
virtual void init() = 0;
|
| 17 |
+
virtual void prepare(bool, bool, bool, bool, bool) = 0;
|
| 18 |
+
virtual void start() = 0;
|
| 19 |
+
virtual void stop() = 0;
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
} // namespace libkineto
|
vllm/lib/python3.10/site-packages/torch/include/kineto/LoggingAPI.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
namespace libkineto {
|
| 12 |
+
int getLogSeverityLevel();
|
| 13 |
+
void setLogSeverityLevel(int level);
|
| 14 |
+
} // namespace libkineto
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/channel/basic/factory.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/channel/context.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace channel {
|
| 17 |
+
namespace basic {
|
| 18 |
+
|
| 19 |
+
std::shared_ptr<Context> create();
|
| 20 |
+
|
| 21 |
+
} // namespace basic
|
| 22 |
+
} // namespace channel
|
| 23 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/channel/cma/factory.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/channel/context.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace channel {
|
| 17 |
+
namespace cma {
|
| 18 |
+
|
| 19 |
+
std::shared_ptr<Context> create();
|
| 20 |
+
|
| 21 |
+
} // namespace cma
|
| 22 |
+
} // namespace channel
|
| 23 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/channel/mpt/factory.h
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
#include <vector>
|
| 13 |
+
|
| 14 |
+
#include <tensorpipe/channel/context.h>
|
| 15 |
+
#include <tensorpipe/transport/context.h>
|
| 16 |
+
|
| 17 |
+
namespace tensorpipe {
|
| 18 |
+
namespace channel {
|
| 19 |
+
namespace mpt {
|
| 20 |
+
|
| 21 |
+
std::shared_ptr<Context> create(
|
| 22 |
+
std::vector<std::shared_ptr<transport::Context>> contexts,
|
| 23 |
+
std::vector<std::shared_ptr<transport::Listener>> listeners);
|
| 24 |
+
|
| 25 |
+
} // namespace mpt
|
| 26 |
+
} // namespace channel
|
| 27 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/buffer.h
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <cstddef>
|
| 12 |
+
#include <stdexcept>
|
| 13 |
+
#include <type_traits>
|
| 14 |
+
#include <utility>
|
| 15 |
+
|
| 16 |
+
#include <tensorpipe/common/cpu_buffer.h>
|
| 17 |
+
#include <tensorpipe/common/device.h>
|
| 18 |
+
|
| 19 |
+
namespace tensorpipe {
|
| 20 |
+
|
| 21 |
+
class Buffer {
|
| 22 |
+
class AbstractBufferWrapper {
|
| 23 |
+
public:
|
| 24 |
+
virtual Device device() const = 0;
|
| 25 |
+
virtual void copyConstructInto(void* ptr) const = 0;
|
| 26 |
+
virtual void moveConstructInto(void* ptr) = 0;
|
| 27 |
+
virtual ~AbstractBufferWrapper() = default;
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
template <typename TBuffer>
|
| 31 |
+
class BufferWrapper : public AbstractBufferWrapper {
|
| 32 |
+
static_assert(
|
| 33 |
+
std::is_trivially_copyable<TBuffer>::value,
|
| 34 |
+
"wrapping non-trivially copyable class");
|
| 35 |
+
|
| 36 |
+
public:
|
| 37 |
+
TBuffer buffer;
|
| 38 |
+
|
| 39 |
+
explicit BufferWrapper(TBuffer buffer) : buffer(std::move(buffer)) {}
|
| 40 |
+
|
| 41 |
+
Device device() const override {
|
| 42 |
+
return buffer.getDevice();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void copyConstructInto(void* ptr) const override {
|
| 46 |
+
new (ptr) BufferWrapper(*this);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void moveConstructInto(void* ptr) override {
|
| 50 |
+
new (ptr) BufferWrapper(std::move(*this));
|
| 51 |
+
}
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
public:
|
| 55 |
+
template <typename TBuffer>
|
| 56 |
+
/* implicit */ Buffer(TBuffer b) {
|
| 57 |
+
static_assert(
|
| 58 |
+
sizeof(BufferWrapper<TBuffer>) <= kStructSize, "kStructSize too small");
|
| 59 |
+
static_assert(
|
| 60 |
+
alignof(BufferWrapper<TBuffer>) <= kStructAlign,
|
| 61 |
+
"kStructAlign too small");
|
| 62 |
+
new (&raw_) BufferWrapper<TBuffer>(std::move(b));
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
Buffer() : Buffer(CpuBuffer{}) {}
|
| 66 |
+
|
| 67 |
+
Buffer(const Buffer& other) {
|
| 68 |
+
other.ptr()->copyConstructInto(&raw_);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
Buffer& operator=(const Buffer& other) {
|
| 72 |
+
if (this != &other) {
|
| 73 |
+
ptr()->~AbstractBufferWrapper();
|
| 74 |
+
other.ptr()->copyConstructInto(&raw_);
|
| 75 |
+
}
|
| 76 |
+
return *this;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
Buffer(Buffer&& other) noexcept {
|
| 80 |
+
other.ptr()->moveConstructInto(&raw_);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
Buffer& operator=(Buffer&& other) {
|
| 84 |
+
if (this != &other) {
|
| 85 |
+
ptr()->~AbstractBufferWrapper();
|
| 86 |
+
other.ptr()->moveConstructInto(&raw_);
|
| 87 |
+
}
|
| 88 |
+
return *this;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
~Buffer() {
|
| 92 |
+
ptr()->~AbstractBufferWrapper();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
template <typename TBuffer>
|
| 96 |
+
TBuffer& unwrap() {
|
| 97 |
+
BufferWrapper<TBuffer>* wrapperPtr =
|
| 98 |
+
dynamic_cast<BufferWrapper<TBuffer>*>(ptr());
|
| 99 |
+
if (wrapperPtr == nullptr) {
|
| 100 |
+
throw std::runtime_error("Invalid unwrapping of tensorpipe::Buffer");
|
| 101 |
+
}
|
| 102 |
+
return wrapperPtr->buffer;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
template <typename TBuffer>
|
| 106 |
+
const TBuffer& unwrap() const {
|
| 107 |
+
const BufferWrapper<TBuffer>* wrapperPtr =
|
| 108 |
+
dynamic_cast<const BufferWrapper<TBuffer>*>(ptr());
|
| 109 |
+
if (wrapperPtr == nullptr) {
|
| 110 |
+
throw std::runtime_error("Invalid unwrapping of tensorpipe::Buffer");
|
| 111 |
+
}
|
| 112 |
+
return wrapperPtr->buffer;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
Device device() const {
|
| 116 |
+
return ptr()->device();
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
private:
|
| 120 |
+
static constexpr int kStructSize = 32;
|
| 121 |
+
static constexpr int kStructAlign = 8;
|
| 122 |
+
std::aligned_storage<kStructSize, kStructAlign>::type raw_{};
|
| 123 |
+
|
| 124 |
+
const AbstractBufferWrapper* ptr() const {
|
| 125 |
+
// FIXME: Once we go C++17, use std::launder on the returned pointer.
|
| 126 |
+
return reinterpret_cast<const AbstractBufferWrapper*>(&raw_);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
AbstractBufferWrapper* ptr() {
|
| 130 |
+
// FIXME: Once we go C++17, use std::launder on the returned pointer.
|
| 131 |
+
return reinterpret_cast<AbstractBufferWrapper*>(&raw_);
|
| 132 |
+
}
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/cpu_buffer.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <tensorpipe/common/device.h>
|
| 12 |
+
|
| 13 |
+
namespace tensorpipe {
|
| 14 |
+
|
| 15 |
+
struct CpuBuffer {
|
| 16 |
+
void* ptr{nullptr};
|
| 17 |
+
|
| 18 |
+
Device getDevice() const {
|
| 19 |
+
return Device{kCpuDeviceType, 0};
|
| 20 |
+
}
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/cuda_buffer.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <cuda_runtime.h>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/common/device.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
|
| 17 |
+
struct CudaBuffer {
|
| 18 |
+
void* ptr{nullptr};
|
| 19 |
+
cudaStream_t stream{cudaStreamDefault};
|
| 20 |
+
|
| 21 |
+
Device getDevice() const;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/device.h
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <sstream>
|
| 12 |
+
#include <stdexcept>
|
| 13 |
+
#include <string>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
|
| 17 |
+
const std::string kCpuDeviceType{"cpu"};
|
| 18 |
+
const std::string kCudaDeviceType{"cuda"};
|
| 19 |
+
|
| 20 |
+
struct Device {
|
| 21 |
+
std::string type;
|
| 22 |
+
int index;
|
| 23 |
+
|
| 24 |
+
// This pointless constructor is needed to work around a bug in GCC 5.5 (and
|
| 25 |
+
// possibly other versions). It appears to be needed in the nop types that
|
| 26 |
+
// are used inside nop::Optional.
|
| 27 |
+
Device() {}
|
| 28 |
+
|
| 29 |
+
Device(std::string type, int index) : type(std::move(type)), index(index) {}
|
| 30 |
+
|
| 31 |
+
std::string toString() const {
|
| 32 |
+
std::stringstream ss;
|
| 33 |
+
ss << type << ":" << index;
|
| 34 |
+
return ss.str();
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
bool operator==(const Device& other) const {
|
| 38 |
+
return type == other.type && index == other.index;
|
| 39 |
+
}
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
} // namespace tensorpipe
|
| 43 |
+
|
| 44 |
+
namespace std {
|
| 45 |
+
|
| 46 |
+
template <>
|
| 47 |
+
struct hash<::tensorpipe::Device> {
|
| 48 |
+
size_t operator()(const ::tensorpipe::Device& device) const noexcept {
|
| 49 |
+
return std::hash<std::string>{}(device.toString());
|
| 50 |
+
}
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
template <>
|
| 54 |
+
struct hash<std::pair<::tensorpipe::Device, ::tensorpipe::Device>> {
|
| 55 |
+
size_t operator()(const std::pair<::tensorpipe::Device, ::tensorpipe::Device>&
|
| 56 |
+
p) const noexcept {
|
| 57 |
+
size_t h1 = std::hash<::tensorpipe::Device>{}(p.first);
|
| 58 |
+
size_t h2 = std::hash<::tensorpipe::Device>{}(p.second);
|
| 59 |
+
// Shifting one hash to avoid collisions between (a, b) and (b, a).
|
| 60 |
+
return h1 ^ (h2 << 1);
|
| 61 |
+
}
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
} // namespace std
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/error.h
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
#include <string>
|
| 13 |
+
|
| 14 |
+
namespace tensorpipe {
|
| 15 |
+
|
| 16 |
+
// Base class for actual errors.
|
| 17 |
+
class BaseError {
|
| 18 |
+
public:
|
| 19 |
+
virtual ~BaseError() = default;
|
| 20 |
+
|
| 21 |
+
// Returns an explanatory string.
|
| 22 |
+
// Like `std::exception` but returns a `std::string`.
|
| 23 |
+
virtual std::string what() const = 0;
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
// Wrapper class for errors.
|
| 27 |
+
//
|
| 28 |
+
// Background: we wish to not use exceptions yet need an error
|
| 29 |
+
// representation that can propagate across function and thread
|
| 30 |
+
// boundaries. This representation must be copyable (so we can store
|
| 31 |
+
// and return it at a later point in time) and retain downstream type
|
| 32 |
+
// information. This implies a heap allocation because it's the
|
| 33 |
+
// easiest way to deal with variable size objects (barring a union of
|
| 34 |
+
// all downstream error classes and a lot of custom code). Instead of
|
| 35 |
+
// passing a shared_ptr around directly, we use this wrapper class to
|
| 36 |
+
// keep implementation details hidden from calling code.
|
| 37 |
+
//
|
| 38 |
+
class Error final {
|
| 39 |
+
public:
|
| 40 |
+
// Constant instance that indicates success.
|
| 41 |
+
static const Error kSuccess;
|
| 42 |
+
|
| 43 |
+
// Default constructor for error that is not an error.
|
| 44 |
+
Error() {}
|
| 45 |
+
|
| 46 |
+
Error(std::shared_ptr<BaseError> error, std::string file, int line)
|
| 47 |
+
: error_(std::move(error)), file_(std::move(file)), line_(line) {}
|
| 48 |
+
|
| 49 |
+
virtual ~Error() = default;
|
| 50 |
+
|
| 51 |
+
// Converting to boolean means checking if there is an error. This
|
| 52 |
+
// means we don't need to use an `std::optional` and allows for a
|
| 53 |
+
// snippet like the following:
|
| 54 |
+
//
|
| 55 |
+
// if (error) {
|
| 56 |
+
// // Deal with it.
|
| 57 |
+
// }
|
| 58 |
+
//
|
| 59 |
+
operator bool() const {
|
| 60 |
+
return static_cast<bool>(error_);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
template <typename T>
|
| 64 |
+
std::shared_ptr<T> castToType() const {
|
| 65 |
+
return std::dynamic_pointer_cast<T>(error_);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
template <typename T>
|
| 69 |
+
bool isOfType() const {
|
| 70 |
+
return castToType<T>() != nullptr;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// Like `std::exception` but returns a `std::string`.
|
| 74 |
+
std::string what() const;
|
| 75 |
+
|
| 76 |
+
private:
|
| 77 |
+
std::shared_ptr<BaseError> error_;
|
| 78 |
+
std::string file_;
|
| 79 |
+
int line_;
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
class SystemError final : public BaseError {
|
| 83 |
+
public:
|
| 84 |
+
explicit SystemError(const char* syscall, int error)
|
| 85 |
+
: syscall_(syscall), error_(error) {}
|
| 86 |
+
|
| 87 |
+
std::string what() const override;
|
| 88 |
+
|
| 89 |
+
int errorCode() const;
|
| 90 |
+
|
| 91 |
+
private:
|
| 92 |
+
const char* syscall_;
|
| 93 |
+
const int error_;
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
class ShortReadError final : public BaseError {
|
| 97 |
+
public:
|
| 98 |
+
ShortReadError(ssize_t expected, ssize_t actual)
|
| 99 |
+
: expected_(expected), actual_(actual) {}
|
| 100 |
+
|
| 101 |
+
std::string what() const override;
|
| 102 |
+
|
| 103 |
+
private:
|
| 104 |
+
const ssize_t expected_;
|
| 105 |
+
const ssize_t actual_;
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
class ShortWriteError final : public BaseError {
|
| 109 |
+
public:
|
| 110 |
+
ShortWriteError(ssize_t expected, ssize_t actual)
|
| 111 |
+
: expected_(expected), actual_(actual) {}
|
| 112 |
+
|
| 113 |
+
std::string what() const override;
|
| 114 |
+
|
| 115 |
+
private:
|
| 116 |
+
const ssize_t expected_;
|
| 117 |
+
const ssize_t actual_;
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
class EOFError final : public BaseError {
|
| 121 |
+
public:
|
| 122 |
+
EOFError() {}
|
| 123 |
+
|
| 124 |
+
std::string what() const override;
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/common/optional.h
ADDED
|
@@ -0,0 +1,1020 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (C) 2011 - 2012 Andrzej Krzemienski.
|
| 2 |
+
//
|
| 3 |
+
// Use, modification, and distribution is subject to the Boost Software
|
| 4 |
+
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
| 5 |
+
// http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
+
//
|
| 7 |
+
// The idea and interface is based on Boost.Optional library
|
| 8 |
+
// authored by Fernando Luis Cacciola Carballal
|
| 9 |
+
|
| 10 |
+
#pragma once
|
| 11 |
+
|
| 12 |
+
#include <cassert>
|
| 13 |
+
#include <functional>
|
| 14 |
+
#include <initializer_list>
|
| 15 |
+
#include <stdexcept>
|
| 16 |
+
#include <string>
|
| 17 |
+
#include <type_traits>
|
| 18 |
+
#include <utility>
|
| 19 |
+
|
| 20 |
+
#define TR2_OPTIONAL_REQUIRES(...) \
|
| 21 |
+
typename std::enable_if<__VA_ARGS__::value, bool>::type = false
|
| 22 |
+
|
| 23 |
+
#if defined __GNUC__ // NOTE: GNUC is also defined for Clang
|
| 24 |
+
#if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)
|
| 25 |
+
#define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
|
| 26 |
+
#elif (__GNUC__ > 4)
|
| 27 |
+
#define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
|
| 28 |
+
#endif
|
| 29 |
+
#
|
| 30 |
+
#if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)
|
| 31 |
+
#define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
|
| 32 |
+
#elif (__GNUC__ > 4)
|
| 33 |
+
#define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
|
| 34 |
+
#endif
|
| 35 |
+
#
|
| 36 |
+
#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1)
|
| 37 |
+
#define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
|
| 38 |
+
#elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)
|
| 39 |
+
#define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
|
| 40 |
+
#elif (__GNUC__ > 4)
|
| 41 |
+
#define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
|
| 42 |
+
#endif
|
| 43 |
+
#endif
|
| 44 |
+
#
|
| 45 |
+
#if defined __clang_major__
|
| 46 |
+
#if (__clang_major__ == 3 && __clang_minor__ >= 5)
|
| 47 |
+
#define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
|
| 48 |
+
#elif (__clang_major__ > 3)
|
| 49 |
+
#define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
|
| 50 |
+
#endif
|
| 51 |
+
#if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
|
| 52 |
+
#define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
|
| 53 |
+
#elif ( \
|
| 54 |
+
__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2)
|
| 55 |
+
#define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
|
| 56 |
+
#endif
|
| 57 |
+
#endif
|
| 58 |
+
#
|
| 59 |
+
#if defined _MSC_VER
|
| 60 |
+
#if (_MSC_VER >= 1900)
|
| 61 |
+
#define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
|
| 62 |
+
#endif
|
| 63 |
+
#endif
|
| 64 |
+
|
| 65 |
+
#if defined __clang__
|
| 66 |
+
#if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9)
|
| 67 |
+
#define OPTIONAL_HAS_THIS_RVALUE_REFS 1
|
| 68 |
+
#else
|
| 69 |
+
#define OPTIONAL_HAS_THIS_RVALUE_REFS 0
|
| 70 |
+
#endif
|
| 71 |
+
#elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
|
| 72 |
+
#define OPTIONAL_HAS_THIS_RVALUE_REFS 1
|
| 73 |
+
#elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
|
| 74 |
+
#define OPTIONAL_HAS_THIS_RVALUE_REFS 1
|
| 75 |
+
#else
|
| 76 |
+
#define OPTIONAL_HAS_THIS_RVALUE_REFS 0
|
| 77 |
+
#endif
|
| 78 |
+
|
| 79 |
+
#if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
|
| 80 |
+
#define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1
|
| 81 |
+
#define OPTIONAL_CONSTEXPR_INIT_LIST constexpr
|
| 82 |
+
#else
|
| 83 |
+
#define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0
|
| 84 |
+
#define OPTIONAL_CONSTEXPR_INIT_LIST
|
| 85 |
+
#endif
|
| 86 |
+
|
| 87 |
+
#if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && \
|
| 88 |
+
(__cplusplus != 201103L)
|
| 89 |
+
#define OPTIONAL_HAS_MOVE_ACCESSORS 1
|
| 90 |
+
#else
|
| 91 |
+
#define OPTIONAL_HAS_MOVE_ACCESSORS 0
|
| 92 |
+
#endif
|
| 93 |
+
|
| 94 |
+
#// In C++11 constexpr implies const, so we need to make non-const members also non-constexpr
|
| 95 |
+
#if (defined __cplusplus) && (__cplusplus == 201103L)
|
| 96 |
+
#define OPTIONAL_MUTABLE_CONSTEXPR
|
| 97 |
+
#else
|
| 98 |
+
#define OPTIONAL_MUTABLE_CONSTEXPR constexpr
|
| 99 |
+
#endif
|
| 100 |
+
|
| 101 |
+
namespace tensorpipe {
|
| 102 |
+
|
| 103 |
+
// 20.5.4, optional for object types
|
| 104 |
+
template <class T>
|
| 105 |
+
class optional;
|
| 106 |
+
|
| 107 |
+
// 20.5.5, optional for lvalue reference types
|
| 108 |
+
template <class T>
|
| 109 |
+
class optional<T&>;
|
| 110 |
+
|
| 111 |
+
// workaround: std utility functions aren't constexpr yet
|
| 112 |
+
template <class T>
|
| 113 |
+
inline constexpr T&& constexpr_forward(
|
| 114 |
+
typename std::remove_reference<T>::type& t) noexcept {
|
| 115 |
+
return static_cast<T&&>(t);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
template <class T>
|
| 119 |
+
inline constexpr T&& constexpr_forward(
|
| 120 |
+
typename std::remove_reference<T>::type&& t) noexcept {
|
| 121 |
+
static_assert(!std::is_lvalue_reference<T>::value, "!!");
|
| 122 |
+
return static_cast<T&&>(t);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
template <class T>
|
| 126 |
+
inline constexpr typename std::remove_reference<T>::type&& constexpr_move(
|
| 127 |
+
T&& t) noexcept {
|
| 128 |
+
return static_cast<typename std::remove_reference<T>::type&&>(t);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
#if defined NDEBUG
|
| 132 |
+
#define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)
|
| 133 |
+
#else
|
| 134 |
+
#define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) \
|
| 135 |
+
((CHECK) ? (EXPR) : ([] { assert(!#CHECK); }(), (EXPR)))
|
| 136 |
+
#endif
|
| 137 |
+
|
| 138 |
+
namespace detail_ {
|
| 139 |
+
|
| 140 |
+
// static_addressof: a constexpr version of addressof
|
| 141 |
+
template <typename T>
|
| 142 |
+
struct has_overloaded_addressof {
|
| 143 |
+
template <class X>
|
| 144 |
+
constexpr static bool has_overload(...) {
|
| 145 |
+
return false;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
template <class X, size_t S = sizeof(std::declval<X&>().operator&())>
|
| 149 |
+
constexpr static bool has_overload(bool) {
|
| 150 |
+
return true;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
constexpr static bool value = has_overload<T>(true);
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
+
template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)>
|
| 157 |
+
constexpr T* static_addressof(T& ref) {
|
| 158 |
+
return &ref;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
template <typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)>
|
| 162 |
+
T* static_addressof(T& ref) {
|
| 163 |
+
return std::addressof(ref);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
// the call to convert<A>(b) has return type A and converts b to type A iff b
|
| 167 |
+
// decltype(b) is implicitly convertible to A
|
| 168 |
+
template <class U>
|
| 169 |
+
constexpr U convert(U v) {
|
| 170 |
+
return v;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
} // namespace detail_
|
| 174 |
+
|
| 175 |
+
constexpr struct trivial_init_t {
|
| 176 |
+
} trivial_init{};
|
| 177 |
+
|
| 178 |
+
// 20.5.6, In-place construction
|
| 179 |
+
constexpr struct in_place_t {
|
| 180 |
+
} in_place{};
|
| 181 |
+
|
| 182 |
+
// 20.5.7, Disengaged state indicator
|
| 183 |
+
struct nullopt_t {
|
| 184 |
+
struct init {};
|
| 185 |
+
constexpr explicit nullopt_t(init) {}
|
| 186 |
+
};
|
| 187 |
+
constexpr nullopt_t nullopt{nullopt_t::init()};
|
| 188 |
+
|
| 189 |
+
// 20.5.8, class bad_optional_access
|
| 190 |
+
class bad_optional_access : public std::logic_error {
|
| 191 |
+
public:
|
| 192 |
+
explicit bad_optional_access(const std::string& what_arg)
|
| 193 |
+
: logic_error{what_arg} {}
|
| 194 |
+
explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} {}
|
| 195 |
+
};
|
| 196 |
+
|
| 197 |
+
template <class T>
|
| 198 |
+
union storage_t {
|
| 199 |
+
unsigned char dummy_;
|
| 200 |
+
T value_;
|
| 201 |
+
|
| 202 |
+
constexpr storage_t(trivial_init_t) noexcept : dummy_(){};
|
| 203 |
+
|
| 204 |
+
template <class... Args>
|
| 205 |
+
constexpr storage_t(Args&&... args)
|
| 206 |
+
: value_(constexpr_forward<Args>(args)...) {}
|
| 207 |
+
|
| 208 |
+
~storage_t() {}
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
template <class T>
|
| 212 |
+
union constexpr_storage_t {
|
| 213 |
+
unsigned char dummy_;
|
| 214 |
+
T value_;
|
| 215 |
+
|
| 216 |
+
constexpr constexpr_storage_t(trivial_init_t) noexcept : dummy_(){};
|
| 217 |
+
|
| 218 |
+
template <class... Args>
|
| 219 |
+
constexpr constexpr_storage_t(Args&&... args)
|
| 220 |
+
: value_(constexpr_forward<Args>(args)...) {}
|
| 221 |
+
|
| 222 |
+
~constexpr_storage_t() = default;
|
| 223 |
+
};
|
| 224 |
+
|
| 225 |
+
template <class T>
|
| 226 |
+
struct optional_base {
|
| 227 |
+
bool init_;
|
| 228 |
+
storage_t<T> storage_;
|
| 229 |
+
|
| 230 |
+
constexpr optional_base() noexcept : init_(false), storage_(trivial_init){};
|
| 231 |
+
|
| 232 |
+
explicit constexpr optional_base(const T& v) : init_(true), storage_(v) {}
|
| 233 |
+
|
| 234 |
+
explicit constexpr optional_base(T&& v)
|
| 235 |
+
: init_(true), storage_(constexpr_move(v)) {}
|
| 236 |
+
|
| 237 |
+
template <class... Args>
|
| 238 |
+
explicit optional_base(in_place_t, Args&&... args)
|
| 239 |
+
: init_(true), storage_(constexpr_forward<Args>(args)...) {}
|
| 240 |
+
|
| 241 |
+
template <
|
| 242 |
+
class U,
|
| 243 |
+
class... Args,
|
| 244 |
+
TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)>
|
| 245 |
+
explicit optional_base(
|
| 246 |
+
in_place_t,
|
| 247 |
+
std::initializer_list<U> il,
|
| 248 |
+
Args&&... args)
|
| 249 |
+
: init_(true), storage_(il, std::forward<Args>(args)...) {}
|
| 250 |
+
|
| 251 |
+
~optional_base() {
|
| 252 |
+
if (init_)
|
| 253 |
+
storage_.value_.T::~T();
|
| 254 |
+
}
|
| 255 |
+
};
|
| 256 |
+
|
| 257 |
+
template <class T>
|
| 258 |
+
struct constexpr_optional_base {
|
| 259 |
+
bool init_;
|
| 260 |
+
constexpr_storage_t<T> storage_;
|
| 261 |
+
|
| 262 |
+
constexpr constexpr_optional_base() noexcept
|
| 263 |
+
: init_(false), storage_(trivial_init){};
|
| 264 |
+
|
| 265 |
+
explicit constexpr constexpr_optional_base(const T& v)
|
| 266 |
+
: init_(true), storage_(v) {}
|
| 267 |
+
|
| 268 |
+
explicit constexpr constexpr_optional_base(T&& v)
|
| 269 |
+
: init_(true), storage_(constexpr_move(v)) {}
|
| 270 |
+
|
| 271 |
+
template <class... Args>
|
| 272 |
+
explicit constexpr constexpr_optional_base(in_place_t, Args&&... args)
|
| 273 |
+
: init_(true), storage_(constexpr_forward<Args>(args)...) {}
|
| 274 |
+
|
| 275 |
+
template <
|
| 276 |
+
class U,
|
| 277 |
+
class... Args,
|
| 278 |
+
TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)>
|
| 279 |
+
OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(
|
| 280 |
+
in_place_t,
|
| 281 |
+
std::initializer_list<U> il,
|
| 282 |
+
Args&&... args)
|
| 283 |
+
: init_(true), storage_(il, std::forward<Args>(args)...) {}
|
| 284 |
+
|
| 285 |
+
~constexpr_optional_base() = default;
|
| 286 |
+
};
|
| 287 |
+
|
| 288 |
+
template <class T>
|
| 289 |
+
using OptionalBase = typename std::conditional<
|
| 290 |
+
std::is_trivially_destructible<T>::value, // if possible
|
| 291 |
+
constexpr_optional_base<typename std::remove_const<
|
| 292 |
+
T>::type>, // use base with trivial destructor
|
| 293 |
+
optional_base<typename std::remove_const<T>::type>>::type;
|
| 294 |
+
|
| 295 |
+
template <class T>
|
| 296 |
+
class optional : private OptionalBase<T> {
|
| 297 |
+
static_assert(
|
| 298 |
+
!std::is_same<typename std::decay<T>::type, nullopt_t>::value,
|
| 299 |
+
"bad T");
|
| 300 |
+
static_assert(
|
| 301 |
+
!std::is_same<typename std::decay<T>::type, in_place_t>::value,
|
| 302 |
+
"bad T");
|
| 303 |
+
|
| 304 |
+
constexpr bool initialized() const noexcept {
|
| 305 |
+
return OptionalBase<T>::init_;
|
| 306 |
+
}
|
| 307 |
+
typename std::remove_const<T>::type* dataptr() {
|
| 308 |
+
return std::addressof(OptionalBase<T>::storage_.value_);
|
| 309 |
+
}
|
| 310 |
+
constexpr const T* dataptr() const {
|
| 311 |
+
return detail_::static_addressof(OptionalBase<T>::storage_.value_);
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
#if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
|
| 315 |
+
constexpr const T& contained_val() const& {
|
| 316 |
+
return OptionalBase<T>::storage_.value_;
|
| 317 |
+
}
|
| 318 |
+
#if OPTIONAL_HAS_MOVE_ACCESSORS == 1
|
| 319 |
+
OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && {
|
| 320 |
+
return std::move(OptionalBase<T>::storage_.value_);
|
| 321 |
+
}
|
| 322 |
+
OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & {
|
| 323 |
+
return OptionalBase<T>::storage_.value_;
|
| 324 |
+
}
|
| 325 |
+
#else
|
| 326 |
+
T& contained_val() & {
|
| 327 |
+
return OptionalBase<T>::storage_.value_;
|
| 328 |
+
}
|
| 329 |
+
T&& contained_val() && {
|
| 330 |
+
return std::move(OptionalBase<T>::storage_.value_);
|
| 331 |
+
}
|
| 332 |
+
#endif
|
| 333 |
+
#else
|
| 334 |
+
constexpr const T& contained_val() const {
|
| 335 |
+
return OptionalBase<T>::storage_.value_;
|
| 336 |
+
}
|
| 337 |
+
T& contained_val() {
|
| 338 |
+
return OptionalBase<T>::storage_.value_;
|
| 339 |
+
}
|
| 340 |
+
#endif
|
| 341 |
+
|
| 342 |
+
void clear() noexcept {
|
| 343 |
+
if (initialized())
|
| 344 |
+
dataptr()->T::~T();
|
| 345 |
+
OptionalBase<T>::init_ = false;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
template <class... Args>
|
| 349 |
+
void initialize(Args&&... args) noexcept(
|
| 350 |
+
noexcept(T(std::forward<Args>(args)...))) {
|
| 351 |
+
assert(!OptionalBase<T>::init_);
|
| 352 |
+
::new (static_cast<void*>(dataptr())) T(std::forward<Args>(args)...);
|
| 353 |
+
OptionalBase<T>::init_ = true;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
template <class U, class... Args>
|
| 357 |
+
void initialize(std::initializer_list<U> il, Args&&... args) noexcept(
|
| 358 |
+
noexcept(T(il, std::forward<Args>(args)...))) {
|
| 359 |
+
assert(!OptionalBase<T>::init_);
|
| 360 |
+
::new (static_cast<void*>(dataptr())) T(il, std::forward<Args>(args)...);
|
| 361 |
+
OptionalBase<T>::init_ = true;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
public:
|
| 365 |
+
typedef T value_type;
|
| 366 |
+
|
| 367 |
+
// 20.5.5.1, constructors
|
| 368 |
+
constexpr optional() noexcept : OptionalBase<T>(){};
|
| 369 |
+
constexpr optional(nullopt_t) noexcept : OptionalBase<T>(){};
|
| 370 |
+
|
| 371 |
+
optional(const optional& rhs) : OptionalBase<T>() {
|
| 372 |
+
if (rhs.initialized()) {
|
| 373 |
+
::new (static_cast<void*>(dataptr())) T(*rhs);
|
| 374 |
+
OptionalBase<T>::init_ = true;
|
| 375 |
+
}
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
optional(optional&& rhs) noexcept(
|
| 379 |
+
std::is_nothrow_move_constructible<T>::value)
|
| 380 |
+
: OptionalBase<T>() {
|
| 381 |
+
if (rhs.initialized()) {
|
| 382 |
+
::new (static_cast<void*>(dataptr())) T(std::move(*rhs));
|
| 383 |
+
OptionalBase<T>::init_ = true;
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
constexpr optional(const T& v) : OptionalBase<T>(v) {}
|
| 388 |
+
|
| 389 |
+
constexpr optional(T&& v) : OptionalBase<T>(constexpr_move(v)) {}
|
| 390 |
+
|
| 391 |
+
template <class... Args>
|
| 392 |
+
explicit constexpr optional(in_place_t, Args&&... args)
|
| 393 |
+
: OptionalBase<T>(in_place_t{}, constexpr_forward<Args>(args)...) {}
|
| 394 |
+
|
| 395 |
+
template <
|
| 396 |
+
class U,
|
| 397 |
+
class... Args,
|
| 398 |
+
TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)>
|
| 399 |
+
OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(
|
| 400 |
+
in_place_t,
|
| 401 |
+
std::initializer_list<U> il,
|
| 402 |
+
Args&&... args)
|
| 403 |
+
: OptionalBase<T>(in_place_t{}, il, constexpr_forward<Args>(args)...) {}
|
| 404 |
+
|
| 405 |
+
// 20.5.4.2, Destructor
|
| 406 |
+
~optional() = default;
|
| 407 |
+
|
| 408 |
+
// 20.5.4.3, assignment
|
| 409 |
+
optional& operator=(nullopt_t) noexcept {
|
| 410 |
+
clear();
|
| 411 |
+
return *this;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
optional& operator=(const optional& rhs) {
|
| 415 |
+
if (initialized() == true && rhs.initialized() == false)
|
| 416 |
+
clear();
|
| 417 |
+
else if (initialized() == false && rhs.initialized() == true)
|
| 418 |
+
initialize(*rhs);
|
| 419 |
+
else if (initialized() == true && rhs.initialized() == true)
|
| 420 |
+
contained_val() = *rhs;
|
| 421 |
+
return *this;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
optional& operator=(optional&& rhs) noexcept(
|
| 425 |
+
std::is_nothrow_move_assignable<T>::value&&
|
| 426 |
+
std::is_nothrow_move_constructible<T>::value) {
|
| 427 |
+
if (initialized() == true && rhs.initialized() == false)
|
| 428 |
+
clear();
|
| 429 |
+
else if (initialized() == false && rhs.initialized() == true)
|
| 430 |
+
initialize(std::move(*rhs));
|
| 431 |
+
else if (initialized() == true && rhs.initialized() == true)
|
| 432 |
+
contained_val() = std::move(*rhs);
|
| 433 |
+
return *this;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
template <class U>
|
| 437 |
+
auto operator=(U&& v) -> typename std::enable_if<
|
| 438 |
+
std::is_same<typename std::decay<U>::type, T>::value,
|
| 439 |
+
optional&>::type {
|
| 440 |
+
if (initialized()) {
|
| 441 |
+
contained_val() = std::forward<U>(v);
|
| 442 |
+
} else {
|
| 443 |
+
initialize(std::forward<U>(v));
|
| 444 |
+
}
|
| 445 |
+
return *this;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
template <class... Args>
|
| 449 |
+
void emplace(Args&&... args) {
|
| 450 |
+
clear();
|
| 451 |
+
initialize(std::forward<Args>(args)...);
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
template <class U, class... Args>
|
| 455 |
+
void emplace(std::initializer_list<U> il, Args&&... args) {
|
| 456 |
+
clear();
|
| 457 |
+
initialize<U, Args...>(il, std::forward<Args>(args)...);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
// 20.5.4.4, Swap
|
| 461 |
+
void swap(optional<T>& rhs) noexcept(
|
| 462 |
+
std::is_nothrow_move_constructible<T>::value&& noexcept(
|
| 463 |
+
std::swap(std::declval<T&>(), std::declval<T&>()))) {
|
| 464 |
+
if (initialized() == true && rhs.initialized() == false) {
|
| 465 |
+
rhs.initialize(std::move(**this));
|
| 466 |
+
clear();
|
| 467 |
+
} else if (initialized() == false && rhs.initialized() == true) {
|
| 468 |
+
initialize(std::move(*rhs));
|
| 469 |
+
rhs.clear();
|
| 470 |
+
} else if (initialized() == true && rhs.initialized() == true) {
|
| 471 |
+
using std::swap;
|
| 472 |
+
swap(**this, *rhs);
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
// 20.5.4.5, Observers
|
| 477 |
+
|
| 478 |
+
explicit constexpr operator bool() const noexcept {
|
| 479 |
+
return initialized();
|
| 480 |
+
}
|
| 481 |
+
constexpr bool has_value() const noexcept {
|
| 482 |
+
return initialized();
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
constexpr T const* operator->() const {
|
| 486 |
+
return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr());
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
#if OPTIONAL_HAS_MOVE_ACCESSORS == 1
|
| 490 |
+
|
| 491 |
+
OPTIONAL_MUTABLE_CONSTEXPR T* operator->() {
|
| 492 |
+
assert(initialized());
|
| 493 |
+
return dataptr();
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
constexpr T const& operator*() const& {
|
| 497 |
+
return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
OPTIONAL_MUTABLE_CONSTEXPR T& operator*() & {
|
| 501 |
+
assert(initialized());
|
| 502 |
+
return contained_val();
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
OPTIONAL_MUTABLE_CONSTEXPR T&& operator*() && {
|
| 506 |
+
assert(initialized());
|
| 507 |
+
return constexpr_move(contained_val());
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
constexpr T const& value() const& {
|
| 511 |
+
return initialized()
|
| 512 |
+
? contained_val()
|
| 513 |
+
: (throw bad_optional_access("bad optional access"), contained_val());
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
OPTIONAL_MUTABLE_CONSTEXPR T& value() & {
|
| 517 |
+
return initialized()
|
| 518 |
+
? contained_val()
|
| 519 |
+
: (throw bad_optional_access("bad optional access"), contained_val());
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
OPTIONAL_MUTABLE_CONSTEXPR T&& value() && {
|
| 523 |
+
if (!initialized())
|
| 524 |
+
throw bad_optional_access("bad optional access");
|
| 525 |
+
return std::move(contained_val());
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
#else
|
| 529 |
+
|
| 530 |
+
T* operator->() {
|
| 531 |
+
assert(initialized());
|
| 532 |
+
return dataptr();
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
constexpr T const& operator*() const {
|
| 536 |
+
return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
T& operator*() {
|
| 540 |
+
assert(initialized());
|
| 541 |
+
return contained_val();
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
constexpr T const& value() const {
|
| 545 |
+
return initialized()
|
| 546 |
+
? contained_val()
|
| 547 |
+
: (throw bad_optional_access("bad optional access"), contained_val());
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
T& value() {
|
| 551 |
+
return initialized()
|
| 552 |
+
? contained_val()
|
| 553 |
+
: (throw bad_optional_access("bad optional access"), contained_val());
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
#endif
|
| 557 |
+
|
| 558 |
+
#if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
|
| 559 |
+
|
| 560 |
+
template <class V>
|
| 561 |
+
constexpr T value_or(V&& v) const& {
|
| 562 |
+
return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
#if OPTIONAL_HAS_MOVE_ACCESSORS == 1
|
| 566 |
+
|
| 567 |
+
template <class V>
|
| 568 |
+
OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) && {
|
| 569 |
+
return *this
|
| 570 |
+
? constexpr_move(const_cast<optional<T>&>(*this).contained_val())
|
| 571 |
+
: detail_::convert<T>(constexpr_forward<V>(v));
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
#else
|
| 575 |
+
|
| 576 |
+
template <class V>
|
| 577 |
+
T value_or(V&& v) && {
|
| 578 |
+
return *this
|
| 579 |
+
? constexpr_move(const_cast<optional<T>&>(*this).contained_val())
|
| 580 |
+
: detail_::convert<T>(constexpr_forward<V>(v));
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
#endif
|
| 584 |
+
|
| 585 |
+
#else
|
| 586 |
+
|
| 587 |
+
template <class V>
|
| 588 |
+
constexpr T value_or(V&& v) const {
|
| 589 |
+
return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
#endif
|
| 593 |
+
|
| 594 |
+
// 20.6.3.6, modifiers
|
| 595 |
+
void reset() noexcept {
|
| 596 |
+
clear();
|
| 597 |
+
}
|
| 598 |
+
};
|
| 599 |
+
|
| 600 |
+
template <class T>
|
| 601 |
+
class optional<T&> {
|
| 602 |
+
static_assert(!std::is_same<T, nullopt_t>::value, "bad T");
|
| 603 |
+
static_assert(!std::is_same<T, in_place_t>::value, "bad T");
|
| 604 |
+
T* ref;
|
| 605 |
+
|
| 606 |
+
public:
|
| 607 |
+
// 20.5.5.1, construction/destruction
|
| 608 |
+
constexpr optional() noexcept : ref(nullptr) {}
|
| 609 |
+
|
| 610 |
+
constexpr optional(nullopt_t) noexcept : ref(nullptr) {}
|
| 611 |
+
|
| 612 |
+
constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) {}
|
| 613 |
+
|
| 614 |
+
optional(T&&) = delete;
|
| 615 |
+
|
| 616 |
+
constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {}
|
| 617 |
+
|
| 618 |
+
explicit constexpr optional(in_place_t, T& v) noexcept
|
| 619 |
+
: ref(detail_::static_addressof(v)) {}
|
| 620 |
+
|
| 621 |
+
explicit optional(in_place_t, T&&) = delete;
|
| 622 |
+
|
| 623 |
+
~optional() = default;
|
| 624 |
+
|
| 625 |
+
// 20.5.5.2, mutation
|
| 626 |
+
optional& operator=(nullopt_t) noexcept {
|
| 627 |
+
ref = nullptr;
|
| 628 |
+
return *this;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
// optional& operator=(const optional& rhs) noexcept {
|
| 632 |
+
// ref = rhs.ref;
|
| 633 |
+
// return *this;
|
| 634 |
+
// }
|
| 635 |
+
|
| 636 |
+
// optional& operator=(optional&& rhs) noexcept {
|
| 637 |
+
// ref = rhs.ref;
|
| 638 |
+
// return *this;
|
| 639 |
+
// }
|
| 640 |
+
|
| 641 |
+
template <typename U>
|
| 642 |
+
auto operator=(U&& rhs) noexcept -> typename std::enable_if<
|
| 643 |
+
std::is_same<typename std::decay<U>::type, optional<T&>>::value,
|
| 644 |
+
optional&>::type {
|
| 645 |
+
ref = rhs.ref;
|
| 646 |
+
return *this;
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
template <typename U>
|
| 650 |
+
auto operator=(U&& rhs) noexcept -> typename std::enable_if<
|
| 651 |
+
!std::is_same<typename std::decay<U>::type, optional<T&>>::value,
|
| 652 |
+
optional&>::type = delete;
|
| 653 |
+
|
| 654 |
+
void emplace(T& v) noexcept {
|
| 655 |
+
ref = detail_::static_addressof(v);
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
void emplace(T&&) = delete;
|
| 659 |
+
|
| 660 |
+
void swap(optional<T&>& rhs) noexcept {
|
| 661 |
+
std::swap(ref, rhs.ref);
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
// 20.5.5.3, observers
|
| 665 |
+
constexpr T* operator->() const {
|
| 666 |
+
return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref);
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
constexpr T& operator*() const {
|
| 670 |
+
return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref);
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
constexpr T& value() const {
|
| 674 |
+
return ref ? *ref
|
| 675 |
+
: (throw bad_optional_access("bad optional access"), *ref);
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
explicit constexpr operator bool() const noexcept {
|
| 679 |
+
return ref != nullptr;
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
constexpr bool has_value() const noexcept {
|
| 683 |
+
return ref != nullptr;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
template <class V>
|
| 687 |
+
constexpr typename std::decay<T>::type value_or(V&& v) const {
|
| 688 |
+
return *this ? **this
|
| 689 |
+
: detail_::convert<typename std::decay<T>::type>(
|
| 690 |
+
constexpr_forward<V>(v));
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
// x.x.x.x, modifiers
|
| 694 |
+
void reset() noexcept {
|
| 695 |
+
ref = nullptr;
|
| 696 |
+
}
|
| 697 |
+
};
|
| 698 |
+
|
| 699 |
+
template <class T>
|
| 700 |
+
class optional<T&&> {
|
| 701 |
+
static_assert(sizeof(T) == 0, "optional rvalue references disallowed");
|
| 702 |
+
};
|
| 703 |
+
|
| 704 |
+
// 20.5.8, Relational operators
|
| 705 |
+
template <class T>
|
| 706 |
+
constexpr bool operator==(const optional<T>& x, const optional<T>& y) {
|
| 707 |
+
return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y;
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
template <class T>
|
| 711 |
+
constexpr bool operator!=(const optional<T>& x, const optional<T>& y) {
|
| 712 |
+
return !(x == y);
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
template <class T>
|
| 716 |
+
constexpr bool operator<(const optional<T>& x, const optional<T>& y) {
|
| 717 |
+
return (!y) ? false : (!x) ? true : *x < *y;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
template <class T>
|
| 721 |
+
constexpr bool operator>(const optional<T>& x, const optional<T>& y) {
|
| 722 |
+
return (y < x);
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
template <class T>
|
| 726 |
+
constexpr bool operator<=(const optional<T>& x, const optional<T>& y) {
|
| 727 |
+
return !(y < x);
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
template <class T>
|
| 731 |
+
constexpr bool operator>=(const optional<T>& x, const optional<T>& y) {
|
| 732 |
+
return !(x < y);
|
| 733 |
+
}
|
| 734 |
+
|
| 735 |
+
// 20.5.9, Comparison with nullopt
|
| 736 |
+
template <class T>
|
| 737 |
+
constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept {
|
| 738 |
+
return (!x);
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
template <class T>
|
| 742 |
+
constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept {
|
| 743 |
+
return (!x);
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
template <class T>
|
| 747 |
+
constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept {
|
| 748 |
+
return bool(x);
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
template <class T>
|
| 752 |
+
constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept {
|
| 753 |
+
return bool(x);
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
template <class T>
|
| 757 |
+
constexpr bool operator<(const optional<T>&, nullopt_t) noexcept {
|
| 758 |
+
return false;
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
template <class T>
|
| 762 |
+
constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept {
|
| 763 |
+
return bool(x);
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
template <class T>
|
| 767 |
+
constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept {
|
| 768 |
+
return (!x);
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
template <class T>
|
| 772 |
+
constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept {
|
| 773 |
+
return true;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
template <class T>
|
| 777 |
+
constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept {
|
| 778 |
+
return bool(x);
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
template <class T>
|
| 782 |
+
constexpr bool operator>(nullopt_t, const optional<T>&) noexcept {
|
| 783 |
+
return false;
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
template <class T>
|
| 787 |
+
constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept {
|
| 788 |
+
return true;
|
| 789 |
+
}
|
| 790 |
+
|
| 791 |
+
template <class T>
|
| 792 |
+
constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept {
|
| 793 |
+
return (!x);
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
// 20.5.10, Comparison with T
|
| 797 |
+
template <class T>
|
| 798 |
+
constexpr bool operator==(const optional<T>& x, const T& v) {
|
| 799 |
+
return bool(x) ? *x == v : false;
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
template <class T>
|
| 803 |
+
constexpr bool operator==(const T& v, const optional<T>& x) {
|
| 804 |
+
return bool(x) ? v == *x : false;
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
template <class T>
|
| 808 |
+
constexpr bool operator!=(const optional<T>& x, const T& v) {
|
| 809 |
+
return bool(x) ? *x != v : true;
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
template <class T>
|
| 813 |
+
constexpr bool operator!=(const T& v, const optional<T>& x) {
|
| 814 |
+
return bool(x) ? v != *x : true;
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
template <class T>
|
| 818 |
+
constexpr bool operator<(const optional<T>& x, const T& v) {
|
| 819 |
+
return bool(x) ? *x < v : true;
|
| 820 |
+
}
|
| 821 |
+
|
| 822 |
+
template <class T>
|
| 823 |
+
constexpr bool operator>(const T& v, const optional<T>& x) {
|
| 824 |
+
return bool(x) ? v > *x : true;
|
| 825 |
+
}
|
| 826 |
+
|
| 827 |
+
template <class T>
|
| 828 |
+
constexpr bool operator>(const optional<T>& x, const T& v) {
|
| 829 |
+
return bool(x) ? *x > v : false;
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
+
template <class T>
|
| 833 |
+
constexpr bool operator<(const T& v, const optional<T>& x) {
|
| 834 |
+
return bool(x) ? v < *x : false;
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
template <class T>
|
| 838 |
+
constexpr bool operator>=(const optional<T>& x, const T& v) {
|
| 839 |
+
return bool(x) ? *x >= v : false;
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
template <class T>
|
| 843 |
+
constexpr bool operator<=(const T& v, const optional<T>& x) {
|
| 844 |
+
return bool(x) ? v <= *x : false;
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
template <class T>
|
| 848 |
+
constexpr bool operator<=(const optional<T>& x, const T& v) {
|
| 849 |
+
return bool(x) ? *x <= v : true;
|
| 850 |
+
}
|
| 851 |
+
|
| 852 |
+
template <class T>
|
| 853 |
+
constexpr bool operator>=(const T& v, const optional<T>& x) {
|
| 854 |
+
return bool(x) ? v >= *x : true;
|
| 855 |
+
}
|
| 856 |
+
|
| 857 |
+
// Comparison of optional<T&> with T
|
| 858 |
+
template <class T>
|
| 859 |
+
constexpr bool operator==(const optional<T&>& x, const T& v) {
|
| 860 |
+
return bool(x) ? *x == v : false;
|
| 861 |
+
}
|
| 862 |
+
|
| 863 |
+
template <class T>
|
| 864 |
+
constexpr bool operator==(const T& v, const optional<T&>& x) {
|
| 865 |
+
return bool(x) ? v == *x : false;
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
template <class T>
|
| 869 |
+
constexpr bool operator!=(const optional<T&>& x, const T& v) {
|
| 870 |
+
return bool(x) ? *x != v : true;
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
template <class T>
|
| 874 |
+
constexpr bool operator!=(const T& v, const optional<T&>& x) {
|
| 875 |
+
return bool(x) ? v != *x : true;
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
template <class T>
|
| 879 |
+
constexpr bool operator<(const optional<T&>& x, const T& v) {
|
| 880 |
+
return bool(x) ? *x < v : true;
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
template <class T>
|
| 884 |
+
constexpr bool operator>(const T& v, const optional<T&>& x) {
|
| 885 |
+
return bool(x) ? v > *x : true;
|
| 886 |
+
}
|
| 887 |
+
|
| 888 |
+
template <class T>
|
| 889 |
+
constexpr bool operator>(const optional<T&>& x, const T& v) {
|
| 890 |
+
return bool(x) ? *x > v : false;
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
template <class T>
|
| 894 |
+
constexpr bool operator<(const T& v, const optional<T&>& x) {
|
| 895 |
+
return bool(x) ? v < *x : false;
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
template <class T>
|
| 899 |
+
constexpr bool operator>=(const optional<T&>& x, const T& v) {
|
| 900 |
+
return bool(x) ? *x >= v : false;
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
template <class T>
|
| 904 |
+
constexpr bool operator<=(const T& v, const optional<T&>& x) {
|
| 905 |
+
return bool(x) ? v <= *x : false;
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
template <class T>
|
| 909 |
+
constexpr bool operator<=(const optional<T&>& x, const T& v) {
|
| 910 |
+
return bool(x) ? *x <= v : true;
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
template <class T>
|
| 914 |
+
constexpr bool operator>=(const T& v, const optional<T&>& x) {
|
| 915 |
+
return bool(x) ? v >= *x : true;
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
// Comparison of optional<T const&> with T
|
| 919 |
+
template <class T>
|
| 920 |
+
constexpr bool operator==(const optional<const T&>& x, const T& v) {
|
| 921 |
+
return bool(x) ? *x == v : false;
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
template <class T>
|
| 925 |
+
constexpr bool operator==(const T& v, const optional<const T&>& x) {
|
| 926 |
+
return bool(x) ? v == *x : false;
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
template <class T>
|
| 930 |
+
constexpr bool operator!=(const optional<const T&>& x, const T& v) {
|
| 931 |
+
return bool(x) ? *x != v : true;
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
template <class T>
|
| 935 |
+
constexpr bool operator!=(const T& v, const optional<const T&>& x) {
|
| 936 |
+
return bool(x) ? v != *x : true;
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
template <class T>
|
| 940 |
+
constexpr bool operator<(const optional<const T&>& x, const T& v) {
|
| 941 |
+
return bool(x) ? *x < v : true;
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
template <class T>
|
| 945 |
+
constexpr bool operator>(const T& v, const optional<const T&>& x) {
|
| 946 |
+
return bool(x) ? v > *x : true;
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
template <class T>
|
| 950 |
+
constexpr bool operator>(const optional<const T&>& x, const T& v) {
|
| 951 |
+
return bool(x) ? *x > v : false;
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
template <class T>
|
| 955 |
+
constexpr bool operator<(const T& v, const optional<const T&>& x) {
|
| 956 |
+
return bool(x) ? v < *x : false;
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
template <class T>
|
| 960 |
+
constexpr bool operator>=(const optional<const T&>& x, const T& v) {
|
| 961 |
+
return bool(x) ? *x >= v : false;
|
| 962 |
+
}
|
| 963 |
+
|
| 964 |
+
template <class T>
|
| 965 |
+
constexpr bool operator<=(const T& v, const optional<const T&>& x) {
|
| 966 |
+
return bool(x) ? v <= *x : false;
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
+
template <class T>
|
| 970 |
+
constexpr bool operator<=(const optional<const T&>& x, const T& v) {
|
| 971 |
+
return bool(x) ? *x <= v : true;
|
| 972 |
+
}
|
| 973 |
+
|
| 974 |
+
template <class T>
|
| 975 |
+
constexpr bool operator>=(const T& v, const optional<const T&>& x) {
|
| 976 |
+
return bool(x) ? v >= *x : true;
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
// 20.5.12, Specialized algorithms
|
| 980 |
+
template <class T>
|
| 981 |
+
void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y))) {
|
| 982 |
+
x.swap(y);
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
template <class T>
|
| 986 |
+
constexpr optional<typename std::decay<T>::type> make_optional(T&& v) {
|
| 987 |
+
return optional<typename std::decay<T>::type>(constexpr_forward<T>(v));
|
| 988 |
+
}
|
| 989 |
+
|
| 990 |
+
template <class X>
|
| 991 |
+
constexpr optional<X&> make_optional(std::reference_wrapper<X> v) {
|
| 992 |
+
return optional<X&>(v.get());
|
| 993 |
+
}
|
| 994 |
+
|
| 995 |
+
} // namespace tensorpipe
|
| 996 |
+
|
| 997 |
+
namespace std {
|
| 998 |
+
template <typename T>
|
| 999 |
+
struct hash<tensorpipe::optional<T>> {
|
| 1000 |
+
typedef typename hash<T>::result_type result_type;
|
| 1001 |
+
typedef tensorpipe::optional<T> argument_type;
|
| 1002 |
+
|
| 1003 |
+
constexpr result_type operator()(argument_type const& arg) const {
|
| 1004 |
+
return arg ? std::hash<T>{}(*arg) : result_type{};
|
| 1005 |
+
}
|
| 1006 |
+
};
|
| 1007 |
+
|
| 1008 |
+
template <typename T>
|
| 1009 |
+
struct hash<tensorpipe::optional<T&>> {
|
| 1010 |
+
typedef typename hash<T>::result_type result_type;
|
| 1011 |
+
typedef tensorpipe::optional<T&> argument_type;
|
| 1012 |
+
|
| 1013 |
+
constexpr result_type operator()(argument_type const& arg) const {
|
| 1014 |
+
return arg ? std::hash<T>{}(*arg) : result_type{};
|
| 1015 |
+
}
|
| 1016 |
+
};
|
| 1017 |
+
} // namespace std
|
| 1018 |
+
|
| 1019 |
+
#undef TR2_OPTIONAL_REQUIRES
|
| 1020 |
+
#undef TR2_OPTIONAL_ASSERTED_EXPRESSION
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/config.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#define TENSORPIPE_HAS_SHM_TRANSPORT 1
|
| 12 |
+
#define TENSORPIPE_HAS_IBV_TRANSPORT 1
|
| 13 |
+
|
| 14 |
+
#define TENSORPIPE_HAS_CMA_CHANNEL 1
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/core/context.h
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
#include <string>
|
| 13 |
+
#include <utility>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
#include <tensorpipe/transport/context.h>
|
| 17 |
+
|
| 18 |
+
#include <tensorpipe/channel/context.h>
|
| 19 |
+
|
| 20 |
+
namespace tensorpipe {
|
| 21 |
+
|
| 22 |
+
class ContextImpl;
|
| 23 |
+
class Listener;
|
| 24 |
+
class Pipe;
|
| 25 |
+
|
| 26 |
+
class ContextOptions {
|
| 27 |
+
public:
|
| 28 |
+
// The name should be a semantically meaningful description of this context.
|
| 29 |
+
// It will only be used for logging and debugging purposes, to identify the
|
| 30 |
+
// endpoints of a pipe.
|
| 31 |
+
ContextOptions&& name(std::string name) && {
|
| 32 |
+
name_ = std::move(name);
|
| 33 |
+
return std::move(*this);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
private:
|
| 37 |
+
std::string name_;
|
| 38 |
+
|
| 39 |
+
friend ContextImpl;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
class PipeOptions {
|
| 43 |
+
public:
|
| 44 |
+
// The name should be a semantically meaningful description of the context
|
| 45 |
+
// that the pipe is connecting to. It will only be used for logging and
|
| 46 |
+
// debugging purposes, to identify the endpoints of a pipe.
|
| 47 |
+
PipeOptions&& remoteName(std::string remoteName) && {
|
| 48 |
+
remoteName_ = std::move(remoteName);
|
| 49 |
+
return std::move(*this);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
private:
|
| 53 |
+
std::string remoteName_;
|
| 54 |
+
|
| 55 |
+
friend ContextImpl;
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
class Context final {
|
| 59 |
+
public:
|
| 60 |
+
explicit Context(ContextOptions opts = ContextOptions());
|
| 61 |
+
|
| 62 |
+
void registerTransport(
|
| 63 |
+
int64_t priority,
|
| 64 |
+
std::string transport,
|
| 65 |
+
std::shared_ptr<transport::Context> context);
|
| 66 |
+
|
| 67 |
+
void registerChannel(
|
| 68 |
+
int64_t priority,
|
| 69 |
+
std::string channel,
|
| 70 |
+
std::shared_ptr<channel::Context> context);
|
| 71 |
+
|
| 72 |
+
std::shared_ptr<Listener> listen(const std::vector<std::string>& urls);
|
| 73 |
+
|
| 74 |
+
std::shared_ptr<Pipe> connect(
|
| 75 |
+
const std::string& url,
|
| 76 |
+
PipeOptions opts = PipeOptions());
|
| 77 |
+
|
| 78 |
+
// Put the context in a terminal state, in turn closing all of its pipes and
|
| 79 |
+
// listeners, and release its resources. This may be done asynchronously, in
|
| 80 |
+
// background.
|
| 81 |
+
void close();
|
| 82 |
+
|
| 83 |
+
// Wait for all resources to be released and all background activity to stop.
|
| 84 |
+
void join();
|
| 85 |
+
|
| 86 |
+
~Context();
|
| 87 |
+
|
| 88 |
+
private:
|
| 89 |
+
// The implementation is managed by a shared_ptr because each child object
|
| 90 |
+
// will also hold a shared_ptr to it. However, its lifetime is tied to the one
|
| 91 |
+
// of this public object since when the latter is destroyed the implementation
|
| 92 |
+
// is closed and joined.
|
| 93 |
+
const std::shared_ptr<ContextImpl> impl_;
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/tensorpipe.h
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <tensorpipe/config.h>
|
| 12 |
+
|
| 13 |
+
// High-level API
|
| 14 |
+
|
| 15 |
+
#include <tensorpipe/core/context.h>
|
| 16 |
+
#include <tensorpipe/core/error.h>
|
| 17 |
+
#include <tensorpipe/core/listener.h>
|
| 18 |
+
#include <tensorpipe/core/message.h>
|
| 19 |
+
#include <tensorpipe/core/pipe.h>
|
| 20 |
+
|
| 21 |
+
#include <tensorpipe/common/buffer.h>
|
| 22 |
+
|
| 23 |
+
#include <tensorpipe/common/cpu_buffer.h>
|
| 24 |
+
|
| 25 |
+
// Transports
|
| 26 |
+
|
| 27 |
+
#include <tensorpipe/transport/context.h>
|
| 28 |
+
#include <tensorpipe/transport/error.h>
|
| 29 |
+
|
| 30 |
+
#include <tensorpipe/transport/uv/error.h>
|
| 31 |
+
#include <tensorpipe/transport/uv/factory.h>
|
| 32 |
+
#include <tensorpipe/transport/uv/utility.h>
|
| 33 |
+
|
| 34 |
+
#if TENSORPIPE_HAS_SHM_TRANSPORT
|
| 35 |
+
#include <tensorpipe/transport/shm/factory.h>
|
| 36 |
+
#endif // TENSORPIPE_HAS_SHM_TRANSPORT
|
| 37 |
+
|
| 38 |
+
#if TENSORPIPE_HAS_IBV_TRANSPORT
|
| 39 |
+
#include <tensorpipe/transport/ibv/error.h>
|
| 40 |
+
#include <tensorpipe/transport/ibv/factory.h>
|
| 41 |
+
#include <tensorpipe/transport/ibv/utility.h>
|
| 42 |
+
#endif // TENSORPIPE_HAS_IBV_TRANSPORT
|
| 43 |
+
|
| 44 |
+
// Channels
|
| 45 |
+
|
| 46 |
+
#include <tensorpipe/channel/context.h>
|
| 47 |
+
#include <tensorpipe/channel/error.h>
|
| 48 |
+
|
| 49 |
+
#include <tensorpipe/channel/basic/factory.h>
|
| 50 |
+
#include <tensorpipe/channel/mpt/factory.h>
|
| 51 |
+
#include <tensorpipe/channel/xth/factory.h>
|
| 52 |
+
|
| 53 |
+
#if TENSORPIPE_HAS_CMA_CHANNEL
|
| 54 |
+
#include <tensorpipe/channel/cma/factory.h>
|
| 55 |
+
#endif // TENSORPIPE_HAS_CMA_CHANNEL
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/context.h
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
#include <string>
|
| 13 |
+
|
| 14 |
+
namespace tensorpipe {
|
| 15 |
+
namespace transport {
|
| 16 |
+
|
| 17 |
+
class Connection;
|
| 18 |
+
class Listener;
|
| 19 |
+
|
| 20 |
+
class Context {
|
| 21 |
+
public:
|
| 22 |
+
virtual std::shared_ptr<Connection> connect(std::string addr) = 0;
|
| 23 |
+
|
| 24 |
+
virtual std::shared_ptr<Listener> listen(std::string addr) = 0;
|
| 25 |
+
|
| 26 |
+
// Return whether the context is able to operate correctly.
|
| 27 |
+
//
|
| 28 |
+
// Some transport types may be unable to perform as intended under
|
| 29 |
+
// some circumstances (e.g., specialized hardware unavailable, lack
|
| 30 |
+
// of permissions). They can report it through this method in order
|
| 31 |
+
// for the core context to avoid registering them in the first place.
|
| 32 |
+
//
|
| 33 |
+
virtual bool isViable() const = 0;
|
| 34 |
+
|
| 35 |
+
// Return string to describe the domain for this context.
|
| 36 |
+
//
|
| 37 |
+
// Two processes with a context of the same type can connect to each
|
| 38 |
+
// other if one side's domain descriptor is "accepted" by the other
|
| 39 |
+
// one, using the canCommunicateWithRemote method below. That method
|
| 40 |
+
// must be symmetric, and unless overridden defaults to string
|
| 41 |
+
// comparison.
|
| 42 |
+
//
|
| 43 |
+
// For example, for a transport that leverages TCP/IP, this may be
|
| 44 |
+
// as simple as the address family (assuming we can route between
|
| 45 |
+
// any two processes). For a transport that leverages shared memory,
|
| 46 |
+
// this descriptor must uniquely identify the machine, such that
|
| 47 |
+
// only co-located processes generate the same domain descriptor.
|
| 48 |
+
//
|
| 49 |
+
virtual const std::string& domainDescriptor() const = 0;
|
| 50 |
+
|
| 51 |
+
// Compare local and remote domain descriptor for compatibility.
|
| 52 |
+
//
|
| 53 |
+
// Determine whether a connection can be opened between this context
|
| 54 |
+
// and a remote one that has the given domain descriptor. This
|
| 55 |
+
// function needs to be symmetric: if we called this method on the
|
| 56 |
+
// remote context with the local descriptor we should get the same
|
| 57 |
+
// answer. Unless overridden it defaults to string comparison.
|
| 58 |
+
//
|
| 59 |
+
virtual bool canCommunicateWithRemote(
|
| 60 |
+
const std::string& remoteDomainDescriptor) const {
|
| 61 |
+
return domainDescriptor() == remoteDomainDescriptor;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Tell the context what its identifier is.
|
| 65 |
+
//
|
| 66 |
+
// This is only supposed to be called from the high-level context or from
|
| 67 |
+
// channel contexts. It will only used for logging and debugging purposes.
|
| 68 |
+
virtual void setId(std::string id) = 0;
|
| 69 |
+
|
| 70 |
+
virtual void close() = 0;
|
| 71 |
+
|
| 72 |
+
virtual void join() = 0;
|
| 73 |
+
|
| 74 |
+
virtual ~Context() = default;
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
} // namespace transport
|
| 78 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/error.h
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <string>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/common/error.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace transport {
|
| 17 |
+
|
| 18 |
+
class ContextClosedError final : public BaseError {
|
| 19 |
+
public:
|
| 20 |
+
ContextClosedError() {}
|
| 21 |
+
|
| 22 |
+
std::string what() const override;
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
class ListenerClosedError final : public BaseError {
|
| 26 |
+
public:
|
| 27 |
+
ListenerClosedError() {}
|
| 28 |
+
|
| 29 |
+
std::string what() const override;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
class ConnectionClosedError final : public BaseError {
|
| 33 |
+
public:
|
| 34 |
+
ConnectionClosedError() {}
|
| 35 |
+
|
| 36 |
+
std::string what() const override;
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
class ContextNotViableError final : public BaseError {
|
| 40 |
+
public:
|
| 41 |
+
ContextNotViableError() {}
|
| 42 |
+
|
| 43 |
+
std::string what() const override;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
} // namespace transport
|
| 47 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/ibv/error.h
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <string>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/transport/error.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace transport {
|
| 17 |
+
namespace ibv {
|
| 18 |
+
|
| 19 |
+
class IbvError final : public BaseError {
|
| 20 |
+
public:
|
| 21 |
+
explicit IbvError(std::string error) : error_(error) {}
|
| 22 |
+
|
| 23 |
+
std::string what() const override;
|
| 24 |
+
|
| 25 |
+
private:
|
| 26 |
+
std::string error_;
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
class GetaddrinfoError final : public BaseError {
|
| 30 |
+
public:
|
| 31 |
+
explicit GetaddrinfoError(int error) : error_(error) {}
|
| 32 |
+
|
| 33 |
+
std::string what() const override;
|
| 34 |
+
|
| 35 |
+
private:
|
| 36 |
+
int error_;
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
class NoAddrFoundError final : public BaseError {
|
| 40 |
+
public:
|
| 41 |
+
NoAddrFoundError() {}
|
| 42 |
+
|
| 43 |
+
std::string what() const override;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
} // namespace ibv
|
| 47 |
+
} // namespace transport
|
| 48 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/ibv/factory.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/transport/context.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace transport {
|
| 17 |
+
namespace ibv {
|
| 18 |
+
|
| 19 |
+
std::shared_ptr<Context> create();
|
| 20 |
+
|
| 21 |
+
} // namespace ibv
|
| 22 |
+
} // namespace transport
|
| 23 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/ibv/utility.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <string>
|
| 12 |
+
#include <tuple>
|
| 13 |
+
|
| 14 |
+
#include <tensorpipe/common/error.h>
|
| 15 |
+
|
| 16 |
+
namespace tensorpipe {
|
| 17 |
+
namespace transport {
|
| 18 |
+
namespace ibv {
|
| 19 |
+
|
| 20 |
+
std::tuple<Error, std::string> lookupAddrForIface(std::string iface);
|
| 21 |
+
|
| 22 |
+
std::tuple<Error, std::string> lookupAddrForHostname();
|
| 23 |
+
|
| 24 |
+
} // namespace ibv
|
| 25 |
+
} // namespace transport
|
| 26 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/shm/factory.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/transport/context.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace transport {
|
| 17 |
+
namespace shm {
|
| 18 |
+
|
| 19 |
+
std::shared_ptr<Context> create();
|
| 20 |
+
|
| 21 |
+
} // namespace shm
|
| 22 |
+
} // namespace transport
|
| 23 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/uv/error.h
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <string>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/transport/error.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace transport {
|
| 17 |
+
namespace uv {
|
| 18 |
+
|
| 19 |
+
class UVError final : public BaseError {
|
| 20 |
+
public:
|
| 21 |
+
explicit UVError(int error) : error_(error) {}
|
| 22 |
+
|
| 23 |
+
std::string what() const override;
|
| 24 |
+
|
| 25 |
+
private:
|
| 26 |
+
int error_;
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
class NoAddrFoundError final : public BaseError {
|
| 30 |
+
public:
|
| 31 |
+
NoAddrFoundError() {}
|
| 32 |
+
|
| 33 |
+
std::string what() const override;
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
} // namespace uv
|
| 37 |
+
} // namespace transport
|
| 38 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/uv/factory.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <memory>
|
| 12 |
+
|
| 13 |
+
#include <tensorpipe/transport/context.h>
|
| 14 |
+
|
| 15 |
+
namespace tensorpipe {
|
| 16 |
+
namespace transport {
|
| 17 |
+
namespace uv {
|
| 18 |
+
|
| 19 |
+
std::shared_ptr<Context> create();
|
| 20 |
+
|
| 21 |
+
} // namespace uv
|
| 22 |
+
} // namespace transport
|
| 23 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/tensorpipe/transport/uv/utility.h
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under the BSD-style license found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#pragma once
|
| 10 |
+
|
| 11 |
+
#include <string>
|
| 12 |
+
#include <tuple>
|
| 13 |
+
|
| 14 |
+
#include <sys/socket.h>
|
| 15 |
+
|
| 16 |
+
#include <tensorpipe/common/error.h>
|
| 17 |
+
#include <tensorpipe/common/optional.h>
|
| 18 |
+
|
| 19 |
+
namespace tensorpipe {
|
| 20 |
+
namespace transport {
|
| 21 |
+
namespace uv {
|
| 22 |
+
|
| 23 |
+
std::tuple<Error, std::string> lookupAddrForIface(std::string iface);
|
| 24 |
+
|
| 25 |
+
std::tuple<Error, std::string> lookupAddrForHostname();
|
| 26 |
+
|
| 27 |
+
// Try to replicate the same logic used by NCCL to find a node's own address.
|
| 28 |
+
// Roughly, it returns the "first" usable address it can find, and prioritizes
|
| 29 |
+
// the interfaces with an `ib` prefix and de-prioritizes those with a `docker`
|
| 30 |
+
// or `lo` prefix. It can optionally only return only IPv4 or IPv4 addresses.
|
| 31 |
+
std::tuple<Error, std::string> lookupAddrLikeNccl(
|
| 32 |
+
optional<sa_family_t> familyFilter = nullopt);
|
| 33 |
+
|
| 34 |
+
} // namespace uv
|
| 35 |
+
} // namespace transport
|
| 36 |
+
} // namespace tensorpipe
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/base.h
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ator.h>
|
| 7 |
+
#include <torch/data/samplers/random.h>
|
| 8 |
+
#include <torch/data/worker_exception.h>
|
| 9 |
+
#include <torch/types.h>
|
| 10 |
+
|
| 11 |
+
#include <torch/csrc/utils/variadic.h>
|
| 12 |
+
|
| 13 |
+
#include <c10/util/Exception.h>
|
| 14 |
+
#include <c10/util/irange.h>
|
| 15 |
+
|
| 16 |
+
#include <cstddef>
|
| 17 |
+
#include <exception>
|
| 18 |
+
#include <memory>
|
| 19 |
+
#include <thread>
|
| 20 |
+
#include <type_traits>
|
| 21 |
+
#include <utility>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
namespace torch {
|
| 25 |
+
namespace data {
|
| 26 |
+
template <typename Dataset, typename Batch, typename BatchRequest>
|
| 27 |
+
class DataLoaderBase {
|
| 28 |
+
public:
|
| 29 |
+
using BatchType = Batch;
|
| 30 |
+
using BatchRequestType = BatchRequest;
|
| 31 |
+
|
| 32 |
+
/// Constructs a new DataLoader from a `dataset` to sample from, `options`
|
| 33 |
+
/// to configure the DataLoader with, and a `sampler` that specifies the
|
| 34 |
+
/// sampling strategy.
|
| 35 |
+
DataLoaderBase(
|
| 36 |
+
DataLoaderOptions options,
|
| 37 |
+
std::unique_ptr<Dataset> main_thread_dataset = nullptr)
|
| 38 |
+
: options_(std::move(options)),
|
| 39 |
+
main_thread_dataset_(std::move(main_thread_dataset)),
|
| 40 |
+
sequencer_(new_sequencer()) {}
|
| 41 |
+
|
| 42 |
+
// NOLINTNEXTLINE(bugprone-exception-escape)
|
| 43 |
+
virtual ~DataLoaderBase() {
|
| 44 |
+
join();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/// Returns an iterator into the DataLoader. The lifetime of the iterator is
|
| 48 |
+
/// bound to the DataLoader. In C++ standards language, the category of the
|
| 49 |
+
/// iterator is `OutputIterator`. See
|
| 50 |
+
/// https://en.cppreference.com/w/cpp/named_req/OutputIterator for what this
|
| 51 |
+
/// means. In short: you may increment the iterator and dereference it, but
|
| 52 |
+
/// cannot go back, or step forward more than one position at a time. When the
|
| 53 |
+
/// DataLoader is exhausted, it will compare equal with the special
|
| 54 |
+
/// "sentinel" iterator returned by `DataLoader::end()`. Most of the time, you
|
| 55 |
+
/// should only use range-for loops to loop over the DataLoader, but
|
| 56 |
+
/// standard algorithms like `std::copy(dataloader.begin(), dataloader.end(),
|
| 57 |
+
/// output_iterator)` are supported too.
|
| 58 |
+
Iterator<Batch> begin() {
|
| 59 |
+
TORCH_CHECK(
|
| 60 |
+
shuttle_.in_flight_jobs() == 0,
|
| 61 |
+
"Attempted to get a new DataLoader iterator "
|
| 62 |
+
"while another iterator is not yet exhausted");
|
| 63 |
+
reset();
|
| 64 |
+
return Iterator<Batch>(std::make_unique<detail::ValidIterator<Batch>>(
|
| 65 |
+
[this] { return this->next(); }));
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/// Returns a special "sentinel" iterator that compares equal with a
|
| 69 |
+
/// non-sentinel iterator once the DataLoader is exhausted.
|
| 70 |
+
Iterator<Batch> end() {
|
| 71 |
+
return Iterator<Batch>(std::make_unique<detail::SentinelIterator<Batch>>());
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/// Joins the DataLoader's worker threads and drains internal queues.
|
| 75 |
+
/// This function may only be invoked from the main thread (in which the
|
| 76 |
+
/// DataLoader lives).
|
| 77 |
+
void join() {
|
| 78 |
+
if (joined_) {
|
| 79 |
+
return;
|
| 80 |
+
}
|
| 81 |
+
shuttle_.drain();
|
| 82 |
+
// Send one 'quit' message per worker. Since a worker dies (exits its
|
| 83 |
+
// thread) after receiving this message, each `QuitWorker()` message will be
|
| 84 |
+
// read by exactly one worker.
|
| 85 |
+
for (const auto w : c10::irange(options_.workers)) {
|
| 86 |
+
(void)w; // Suppress unused variable warning
|
| 87 |
+
push_job(QuitWorker());
|
| 88 |
+
}
|
| 89 |
+
for (auto& worker : workers_) {
|
| 90 |
+
worker.join();
|
| 91 |
+
}
|
| 92 |
+
joined_ = true;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/// Returns the options with which the DataLoader was configured.
|
| 96 |
+
const FullDataLoaderOptions& options() const noexcept {
|
| 97 |
+
return options_;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
protected:
|
| 101 |
+
/// Simple mix-in to give something a sequence number.
|
| 102 |
+
struct Sequenced {
|
| 103 |
+
Sequenced() = default;
|
| 104 |
+
Sequenced(size_t sqn) : sequence_number(sqn) {}
|
| 105 |
+
size_t sequence_number;
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
struct QuitWorker {};
|
| 109 |
+
|
| 110 |
+
/// A `Job` is either a `BatchRequest` (new indices to fetch data at) or a
|
| 111 |
+
/// `QuitWorker` object, to indicate the worker should shut down.
|
| 112 |
+
struct Job : Sequenced {
|
| 113 |
+
Job() = default;
|
| 114 |
+
Job(QuitWorker q, size_t sqn) : Sequenced(sqn), quit(q) {}
|
| 115 |
+
Job(BatchRequest&& i, size_t sqn)
|
| 116 |
+
: Sequenced(sqn), batch_request(std::move(i)) {}
|
| 117 |
+
std::optional<QuitWorker> quit;
|
| 118 |
+
std::optional<BatchRequest> batch_request;
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
/// The finished result of a job.
|
| 122 |
+
struct Result : Sequenced {
|
| 123 |
+
Result() = default;
|
| 124 |
+
Result(std::optional<Batch>&& b, size_t sqn)
|
| 125 |
+
: Sequenced(sqn), batch(std::move(b)) {}
|
| 126 |
+
Result(std::exception_ptr exception, size_t sqn)
|
| 127 |
+
: Sequenced(sqn), exception(std::move(exception)) {}
|
| 128 |
+
std::optional<Batch> batch;
|
| 129 |
+
std::exception_ptr exception;
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
/// Subclass hook for getting the next batch request. The stateless case will
|
| 133 |
+
/// ask the sampler for a new batch request (e.g. a vector of indices), while
|
| 134 |
+
/// the stateful one will simply return the batch size.
|
| 135 |
+
virtual std::optional<BatchRequestType> get_batch_request() = 0;
|
| 136 |
+
|
| 137 |
+
/// Resets the internal state of the DataLoader, optionally pre-fetching
|
| 138 |
+
/// new jobs.
|
| 139 |
+
virtual void reset() {
|
| 140 |
+
shuttle_.drain();
|
| 141 |
+
sequence_number_ = 0;
|
| 142 |
+
sequencer_ = new_sequencer();
|
| 143 |
+
prefetch();
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/// Schedules `requested_jobs` many new batches to be fetched. The actual
|
| 147 |
+
/// number of jobs scheduled may be less if the DataLoader exhausts.
|
| 148 |
+
void prefetch(size_t requested_jobs) {
|
| 149 |
+
for (const auto r : c10::irange(requested_jobs)) {
|
| 150 |
+
(void)r; // Suppress unused variable
|
| 151 |
+
if (auto batch_request = get_batch_request()) {
|
| 152 |
+
this->push_job(std::move(*batch_request));
|
| 153 |
+
} else {
|
| 154 |
+
break;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/// Schedules the maximum number of jobs (based on the `max_jobs` option).
|
| 160 |
+
void prefetch() {
|
| 161 |
+
prefetch(options_.max_jobs);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/// Returns the next batch of data, or an empty `optional` if the DataLoader
|
| 165 |
+
/// is exhausted. This operation will block until a batch is available if one
|
| 166 |
+
/// is still expected.
|
| 167 |
+
std::optional<BatchType> next() {
|
| 168 |
+
if (options_.workers > 0) {
|
| 169 |
+
while (std::optional<Result> result = this->pop_result()) {
|
| 170 |
+
if (result->exception) {
|
| 171 |
+
throw WorkerException(result->exception);
|
| 172 |
+
} else if (result->batch) {
|
| 173 |
+
prefetch(1);
|
| 174 |
+
return std::move(result->batch);
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
} else if (auto batch_request = get_batch_request()) {
|
| 178 |
+
return this->main_thread_dataset_->get_batch(std::move(*batch_request));
|
| 179 |
+
}
|
| 180 |
+
return nullopt;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
/// The function that worker threads run.
|
| 184 |
+
void worker_thread(Dataset& dataset) {
|
| 185 |
+
while (true) {
|
| 186 |
+
auto job = shuttle_.pop_job();
|
| 187 |
+
if (job.quit) {
|
| 188 |
+
break;
|
| 189 |
+
}
|
| 190 |
+
try {
|
| 191 |
+
auto batch = dataset.get_batch(std::move(*job.batch_request));
|
| 192 |
+
shuttle_.push_result({std::move(batch), job.sequence_number});
|
| 193 |
+
} catch (...) {
|
| 194 |
+
shuttle_.push_result({std::current_exception(), job.sequence_number});
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/// Convenience method that calls `shuttle_.push_job()` with the next sequence
|
| 200 |
+
/// number.
|
| 201 |
+
template <typename T>
|
| 202 |
+
void push_job(T value) {
|
| 203 |
+
shuttle_.push_job({std::move(value), sequence_number_++});
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/// Convenience method that gets the next result from the sequencer.
|
| 207 |
+
std::optional<Result> pop_result() {
|
| 208 |
+
return sequencer_->next(
|
| 209 |
+
[this] { return this->shuttle_.pop_result(this->options_.timeout); });
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
/// Convenience method that creates a new sequencer based on the
|
| 213 |
+
/// `enforce_ordering` option.
|
| 214 |
+
std::unique_ptr<detail::sequencers::Sequencer<Result>> new_sequencer() {
|
| 215 |
+
if (options_.enforce_ordering) {
|
| 216 |
+
return std::make_unique<detail::sequencers::OrderedSequencer<Result>>(
|
| 217 |
+
options_.max_jobs);
|
| 218 |
+
}
|
| 219 |
+
return std::make_unique<detail::sequencers::NoSequencer<Result>>();
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/// The options the DataLoader was configured with.
|
| 223 |
+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
| 224 |
+
const FullDataLoaderOptions options_;
|
| 225 |
+
|
| 226 |
+
/// The dataset for the main thread, only has a value if the number of
|
| 227 |
+
/// worker threads was configured as zero, meaning the main thread has to do
|
| 228 |
+
/// all the work (synchronously). NOTE: Really want this to be on the heap
|
| 229 |
+
/// when empty, therefore `unique_ptr` and not `optional`.
|
| 230 |
+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
| 231 |
+
std::unique_ptr<Dataset> main_thread_dataset_;
|
| 232 |
+
|
| 233 |
+
/// The sequence number for the *next* batch to be retrieved from the
|
| 234 |
+
/// dataset.
|
| 235 |
+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
| 236 |
+
size_t sequence_number_ = 0;
|
| 237 |
+
|
| 238 |
+
/// The worker threads, running the `worker_thread()` method.
|
| 239 |
+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
| 240 |
+
std::vector<std::thread> workers_;
|
| 241 |
+
|
| 242 |
+
/// The `DataShuttle` which takes care of the life cycle of a job.
|
| 243 |
+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
| 244 |
+
detail::DataShuttle<Job, Result> shuttle_;
|
| 245 |
+
|
| 246 |
+
/// The `Sequencer`, which handles optional ordering of batches.
|
| 247 |
+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
| 248 |
+
std::unique_ptr<detail::sequencers::Sequencer<Result>> sequencer_;
|
| 249 |
+
|
| 250 |
+
/// True if the DataLoader has joined its worker threads.
|
| 251 |
+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
| 252 |
+
bool joined_ = false;
|
| 253 |
+
};
|
| 254 |
+
} // namespace data
|
| 255 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/irange.h>
|
| 4 |
+
#include <torch/data/dataloader/base.h>
|
| 5 |
+
|
| 6 |
+
#include <cstddef>
|
| 7 |
+
#include <thread>
|
| 8 |
+
#include <utility>
|
| 9 |
+
|
| 10 |
+
namespace torch {
|
| 11 |
+
namespace data {
|
| 12 |
+
|
| 13 |
+
/// A dataloader for stateful datasets.
|
| 14 |
+
///
|
| 15 |
+
/// A dataloader for stateful datatasets differs from one for stateless
|
| 16 |
+
/// datasets one in that the dataset is shared among worker threads, and that
|
| 17 |
+
/// this dataset is itself responsible for producing batches rather than
|
| 18 |
+
/// depending on a sampler. The statefulness here actually refers to the
|
| 19 |
+
/// dataset. The StatefulDataLoader simply alters the data loading algorithm to
|
| 20 |
+
/// accommodate the stateful, shared nature of the dataset. Note that the
|
| 21 |
+
/// dataset must be thread safe if more than one worker thread is used.
|
| 22 |
+
///
|
| 23 |
+
/// A stateful dataloader is created by calling `make_data_loader` with a
|
| 24 |
+
/// stateful dataset.
|
| 25 |
+
template <typename Dataset>
|
| 26 |
+
class StatefulDataLoader : public DataLoaderBase<
|
| 27 |
+
Dataset,
|
| 28 |
+
typename Dataset::BatchType::value_type,
|
| 29 |
+
typename Dataset::BatchRequestType> {
|
| 30 |
+
public:
|
| 31 |
+
using super = DataLoaderBase<
|
| 32 |
+
Dataset,
|
| 33 |
+
typename Dataset::BatchType::value_type,
|
| 34 |
+
typename Dataset::BatchRequestType>;
|
| 35 |
+
using typename super::BatchRequestType;
|
| 36 |
+
|
| 37 |
+
/// Constructs the `StatefulDataLoader` from a `dataset` and some `options`.
|
| 38 |
+
StatefulDataLoader(Dataset dataset, DataLoaderOptions options)
|
| 39 |
+
: super(options, std::make_unique<Dataset>(std::move(dataset))) {
|
| 40 |
+
for ([[maybe_unused]] const auto _ : c10::irange(this->options_.workers)) {
|
| 41 |
+
// As opposed to the stateless case, here all worker threads access the
|
| 42 |
+
// same underlying dataset.
|
| 43 |
+
this->workers_.emplace_back(
|
| 44 |
+
[this] { this->worker_thread(*this->main_thread_dataset_); });
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
private:
|
| 49 |
+
/// Resets the internal state of the dataloader and the dataset.
|
| 50 |
+
void reset() override {
|
| 51 |
+
this->main_thread_dataset_->reset();
|
| 52 |
+
// Call the base class method last because it calls `prefetch()`
|
| 53 |
+
super::reset();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/// For stateful datasets, the batch request is always the batch size. The
|
| 57 |
+
/// dataset is responsible for determining what goes into the batch next.
|
| 58 |
+
std::optional<BatchRequestType> get_batch_request() override {
|
| 59 |
+
return this->options_.batch_size;
|
| 60 |
+
}
|
| 61 |
+
};
|
| 62 |
+
} // namespace data
|
| 63 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/stateless.h
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/data/dataloader/base.h>
|
| 4 |
+
#include <torch/data/worker_exception.h>
|
| 5 |
+
|
| 6 |
+
#include <c10/util/Exception.h>
|
| 7 |
+
#include <c10/util/irange.h>
|
| 8 |
+
|
| 9 |
+
#include <cstddef>
|
| 10 |
+
#include <thread>
|
| 11 |
+
#include <utility>
|
| 12 |
+
|
| 13 |
+
namespace torch {
|
| 14 |
+
namespace data {
|
| 15 |
+
|
| 16 |
+
/// A dataloader for stateless datasets.
|
| 17 |
+
///
|
| 18 |
+
/// This dataloader follows the traditional PyTorch dataloader design, whereby a
|
| 19 |
+
/// (posssibly) stateful sampler produces *batch requests* for a stateless
|
| 20 |
+
/// dataset, which acts as a simple batch request to batch mapping. The batch
|
| 21 |
+
/// request will often be an array of indices, and if the dataset is a simple
|
| 22 |
+
/// image dataset, the dataset would produce the images at those indices.
|
| 23 |
+
template <typename Dataset, typename Sampler>
|
| 24 |
+
class StatelessDataLoader : public DataLoaderBase<
|
| 25 |
+
Dataset,
|
| 26 |
+
typename Dataset::BatchType,
|
| 27 |
+
typename Sampler::BatchRequestType> {
|
| 28 |
+
public:
|
| 29 |
+
using super = DataLoaderBase<
|
| 30 |
+
Dataset,
|
| 31 |
+
typename Dataset::BatchType,
|
| 32 |
+
typename Sampler::BatchRequestType>;
|
| 33 |
+
using typename super::BatchRequestType;
|
| 34 |
+
|
| 35 |
+
/// Constructs the `StatelessDataLoader` from a `dataset`, a `sampler` and
|
| 36 |
+
/// some `options`.
|
| 37 |
+
StatelessDataLoader(
|
| 38 |
+
Dataset dataset,
|
| 39 |
+
Sampler sampler,
|
| 40 |
+
DataLoaderOptions options)
|
| 41 |
+
: super(std::move(options)), sampler_(std::move(sampler)) {
|
| 42 |
+
for (const auto w : c10::irange(this->options_.workers)) {
|
| 43 |
+
// Here we copy the dataset into the worker thread closure. Each worker
|
| 44 |
+
// has its own copy of the dataset. This means the dataset must be
|
| 45 |
+
// trivially copiable, or else we don't expect more than one worker to
|
| 46 |
+
// be in use.
|
| 47 |
+
(void)w; // Suppress unused variable warning
|
| 48 |
+
this->workers_.emplace_back(
|
| 49 |
+
[this, dataset]() mutable { this->worker_thread(dataset); });
|
| 50 |
+
}
|
| 51 |
+
if (this->options_.workers == 0) {
|
| 52 |
+
this->main_thread_dataset_ =
|
| 53 |
+
std::make_unique<Dataset>(std::move(dataset));
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
private:
|
| 58 |
+
/// Resets the internal state of the dataloader and the sampler.
|
| 59 |
+
void reset() override {
|
| 60 |
+
sampler_.reset();
|
| 61 |
+
// Call the base class method last because it calls `prefetch()`
|
| 62 |
+
super::reset();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/// Queries the sampler for the next batch request (possibly progressing its
|
| 66 |
+
/// internal state).
|
| 67 |
+
std::optional<BatchRequestType> get_batch_request() override {
|
| 68 |
+
auto indices = sampler_.next(this->options_.batch_size);
|
| 69 |
+
if (!indices ||
|
| 70 |
+
(indices->size() < this->options_.batch_size &&
|
| 71 |
+
this->options_.drop_last)) {
|
| 72 |
+
return nullopt;
|
| 73 |
+
}
|
| 74 |
+
AT_ASSERT(indices->size() > 0);
|
| 75 |
+
return indices;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/// The `Sampler` used to produce batch requests.
|
| 79 |
+
Sampler sampler_;
|
| 80 |
+
};
|
| 81 |
+
} // namespace data
|
| 82 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader_options.h
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/arg.h>
|
| 4 |
+
#include <torch/types.h>
|
| 5 |
+
|
| 6 |
+
#include <chrono>
|
| 7 |
+
#include <cstddef>
|
| 8 |
+
|
| 9 |
+
namespace torch {
|
| 10 |
+
namespace data {
|
| 11 |
+
|
| 12 |
+
/// Options to configure a `DataLoader`.
|
| 13 |
+
struct DataLoaderOptions {
|
| 14 |
+
DataLoaderOptions() = default;
|
| 15 |
+
/* implicit */ DataLoaderOptions(size_t batch_size)
|
| 16 |
+
: batch_size_(batch_size) {}
|
| 17 |
+
|
| 18 |
+
/// The size of each batch to fetch.
|
| 19 |
+
TORCH_ARG(size_t, batch_size) = 1;
|
| 20 |
+
|
| 21 |
+
/// The number of worker threads to launch. If zero, the main thread will
|
| 22 |
+
/// synchronously perform the data loading.
|
| 23 |
+
TORCH_ARG(size_t, workers) = 0;
|
| 24 |
+
|
| 25 |
+
/// The maximum number of jobs to enqueue for fetching by worker threads.
|
| 26 |
+
/// Defaults to two times the number of worker threads.
|
| 27 |
+
TORCH_ARG(std::optional<size_t>, max_jobs);
|
| 28 |
+
|
| 29 |
+
/// An optional limit on the time to wait for the next batch.
|
| 30 |
+
TORCH_ARG(std::optional<std::chrono::milliseconds>, timeout);
|
| 31 |
+
|
| 32 |
+
/// Whether to enforce ordering of batches when multiple are loaded
|
| 33 |
+
/// asynchronously by worker threads. Set to `false` for better performance if
|
| 34 |
+
/// you do not care about determinism.
|
| 35 |
+
TORCH_ARG(bool, enforce_ordering) = true;
|
| 36 |
+
|
| 37 |
+
/// Whether to omit the last batch if it contains less than `batch_size`
|
| 38 |
+
/// examples.
|
| 39 |
+
TORCH_ARG(bool, drop_last) = false;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
/// Like `DataLoaderOptions`, but without any unconfigured state.
|
| 43 |
+
/// `DataLoaderOptions` has some options that depend on other options
|
| 44 |
+
/// (`max_jobs` => `2 * workers`). In the spirit of properly using the C++ type
|
| 45 |
+
/// system, `DataLoaderOptions` allows only setting values. To access values,
|
| 46 |
+
/// you must create a `FullDataLoaderOptions` from a `DataLoaderOptions`
|
| 47 |
+
/// instance, which will do any necessary coalescing.
|
| 48 |
+
struct FullDataLoaderOptions {
|
| 49 |
+
explicit FullDataLoaderOptions(DataLoaderOptions options)
|
| 50 |
+
: batch_size(options.batch_size()),
|
| 51 |
+
workers(options.workers()),
|
| 52 |
+
max_jobs(options.max_jobs().value_or(2 * workers)),
|
| 53 |
+
timeout(options.timeout()),
|
| 54 |
+
enforce_ordering(options.enforce_ordering()),
|
| 55 |
+
drop_last(options.drop_last()) {}
|
| 56 |
+
|
| 57 |
+
size_t batch_size;
|
| 58 |
+
size_t workers;
|
| 59 |
+
size_t max_jobs;
|
| 60 |
+
std::optional<std::chrono::milliseconds> timeout;
|
| 61 |
+
bool enforce_ordering;
|
| 62 |
+
bool drop_last;
|
| 63 |
+
};
|
| 64 |
+
} // namespace data
|
| 65 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/datasets/base.h
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/data/example.h>
|
| 4 |
+
#include <torch/types.h>
|
| 5 |
+
|
| 6 |
+
#include <c10/util/ArrayRef.h>
|
| 7 |
+
|
| 8 |
+
#include <cstddef>
|
| 9 |
+
#include <cstdint>
|
| 10 |
+
#include <type_traits>
|
| 11 |
+
#include <utility>
|
| 12 |
+
#include <vector>
|
| 13 |
+
|
| 14 |
+
namespace torch {
|
| 15 |
+
namespace data {
|
| 16 |
+
namespace datasets {
|
| 17 |
+
template <typename S, typename T>
|
| 18 |
+
class MapDataset;
|
| 19 |
+
template <typename D, typename T>
|
| 20 |
+
MapDataset<D, T> map(D, T); // NOLINT
|
| 21 |
+
} // namespace datasets
|
| 22 |
+
} // namespace data
|
| 23 |
+
} // namespace torch
|
| 24 |
+
|
| 25 |
+
namespace torch {
|
| 26 |
+
namespace data {
|
| 27 |
+
namespace datasets {
|
| 28 |
+
namespace detail {
|
| 29 |
+
template <typename T>
|
| 30 |
+
struct is_optional : std::false_type {};
|
| 31 |
+
template <typename T>
|
| 32 |
+
struct is_optional<std::optional<T>> : std::true_type {};
|
| 33 |
+
} // namespace detail
|
| 34 |
+
|
| 35 |
+
/// A dataset that can yield data only in batches.
|
| 36 |
+
template <
|
| 37 |
+
typename Self,
|
| 38 |
+
typename Batch = std::vector<Example<>>,
|
| 39 |
+
typename BatchRequest = ArrayRef<size_t>>
|
| 40 |
+
class BatchDataset {
|
| 41 |
+
public:
|
| 42 |
+
using SelfType = Self;
|
| 43 |
+
using BatchType = Batch;
|
| 44 |
+
using BatchRequestType = BatchRequest;
|
| 45 |
+
constexpr static bool is_stateful = detail::is_optional<BatchType>::value;
|
| 46 |
+
|
| 47 |
+
virtual ~BatchDataset() = default;
|
| 48 |
+
|
| 49 |
+
/// Returns a batch of data given an index.
|
| 50 |
+
virtual Batch get_batch(BatchRequest request) = 0;
|
| 51 |
+
|
| 52 |
+
/// Returns the size of the dataset, or an empty std::optional if it is
|
| 53 |
+
/// unsized.
|
| 54 |
+
virtual std::optional<size_t> size() const = 0;
|
| 55 |
+
|
| 56 |
+
/// Creates a `MapDataset` that applies the given `transform` to this dataset.
|
| 57 |
+
template <typename TransformType>
|
| 58 |
+
MapDataset<Self, TransformType> map(TransformType transform) & {
|
| 59 |
+
return datasets::map(static_cast<Self&>(*this), std::move(transform));
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/// Creates a `MapDataset` that applies the given `transform` to this dataset.
|
| 63 |
+
template <typename TransformType>
|
| 64 |
+
MapDataset<Self, TransformType> map(TransformType transform) && {
|
| 65 |
+
return datasets::map(
|
| 66 |
+
std::move(static_cast<Self&>(*this)), std::move(transform));
|
| 67 |
+
}
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
/// A dataset that can yield data in batches, or as individual examples.
|
| 71 |
+
///
|
| 72 |
+
/// A `Dataset` is a `BatchDataset`, because it supports random access and
|
| 73 |
+
/// therefore batched access is implemented (by default) by calling the random
|
| 74 |
+
/// access indexing function for each index in the requested batch of indices.
|
| 75 |
+
/// This can be customized.
|
| 76 |
+
template <typename Self, typename SingleExample = Example<>>
|
| 77 |
+
class Dataset : public BatchDataset<Self, std::vector<SingleExample>> {
|
| 78 |
+
public:
|
| 79 |
+
using ExampleType = SingleExample;
|
| 80 |
+
|
| 81 |
+
/// Returns the example at the given index.
|
| 82 |
+
virtual ExampleType get(size_t index) = 0;
|
| 83 |
+
|
| 84 |
+
/// Returns a batch of data.
|
| 85 |
+
/// The default implementation calls `get()` for every requested index
|
| 86 |
+
/// in the batch.
|
| 87 |
+
std::vector<ExampleType> get_batch(ArrayRef<size_t> indices) override {
|
| 88 |
+
std::vector<ExampleType> batch;
|
| 89 |
+
batch.reserve(indices.size());
|
| 90 |
+
for (const auto i : indices) {
|
| 91 |
+
batch.push_back(get(i));
|
| 92 |
+
}
|
| 93 |
+
return batch;
|
| 94 |
+
}
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
/// A `StreamDataset` represents a dataset that is a potentially infinite
|
| 98 |
+
/// stream. It takes as batch index only a number, which is the batch size, and
|
| 99 |
+
/// yields that many elements from the stream.
|
| 100 |
+
template <typename Self, typename Batch = std::vector<Example<>>>
|
| 101 |
+
using StreamDataset = BatchDataset<Self, Batch, /*BatchRequest=*/size_t>;
|
| 102 |
+
} // namespace datasets
|
| 103 |
+
} // namespace data
|
| 104 |
+
} // namespace torch
|
vllm/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/data/datasets/chunk.h
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/irange.h>
|
| 4 |
+
#include <torch/arg.h>
|
| 5 |
+
#include <torch/data/datasets/stateful.h>
|
| 6 |
+
#include <torch/data/samplers.h>
|
| 7 |
+
#include <queue>
|
| 8 |
+
#include <thread>
|
| 9 |
+
|
| 10 |
+
#include <torch/serialize.h>
|
| 11 |
+
|
| 12 |
+
namespace torch {
|
| 13 |
+
namespace data {
|
| 14 |
+
namespace datasets {
|
| 15 |
+
|
| 16 |
+
/// Interface for chunk reader, which performs data chunking and reading of
|
| 17 |
+
/// entire chunks.
|
| 18 |
+
///
|
| 19 |
+
/// A chunk could be an entire file, such as an audio data file or an image,
|
| 20 |
+
/// or part of a file in the case of a large text-file split based on seek
|
| 21 |
+
/// positions.
|
| 22 |
+
template <
|
| 23 |
+
typename ExampleType_,
|
| 24 |
+
typename ChunkType_ = std::vector<ExampleType_>>
|
| 25 |
+
class ChunkDataReader {
|
| 26 |
+
public:
|
| 27 |
+
virtual ~ChunkDataReader() = default;
|
| 28 |
+
|
| 29 |
+
using ChunkType = ChunkType_;
|
| 30 |
+
using ExampleType = ExampleType_;
|
| 31 |
+
|
| 32 |
+
/// Read an entire chunk.
|
| 33 |
+
virtual ChunkType read_chunk(size_t chunk_index) = 0;
|
| 34 |
+
|
| 35 |
+
/// Returns the number of chunks available in this reader.
|
| 36 |
+
virtual size_t chunk_count() = 0;
|
| 37 |
+
|
| 38 |
+
/// This will clear any internal state associate with this reader.
|
| 39 |
+
virtual void reset() = 0;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
namespace detail {
|
| 43 |
+
/// BatchDataBuffer manages a queue of UnwrappedBatchData. After a new chunk is
|
| 44 |
+
/// loaded, BatchDataBuffer splits it into small batches and push them into the
|
| 45 |
+
/// queue. When get_batch is called from data loader, it pops cached batches and
|
| 46 |
+
/// return. If the cache is empty, it either waits to load more chunks or return
|
| 47 |
+
/// null if all chunks are loaded.
|
| 48 |
+
template <
|
| 49 |
+
typename UnwrappedBatch,
|
| 50 |
+
typename ExampleSampler = samplers::RandomSampler>
|
| 51 |
+
class BatchDataBuffer {
|
| 52 |
+
public:
|
| 53 |
+
using UnwrappedBatchType = UnwrappedBatch;
|
| 54 |
+
using BatchType = torch::optional<UnwrappedBatchType>;
|
| 55 |
+
using BatchRequestType = typename ExampleSampler::BatchRequestType;
|
| 56 |
+
|
| 57 |
+
BatchDataBuffer(
|
| 58 |
+
size_t batch_size,
|
| 59 |
+
ExampleSampler& example_sampler,
|
| 60 |
+
size_t queue_capacity)
|
| 61 |
+
: batch_size_(batch_size),
|
| 62 |
+
example_sampler_(example_sampler),
|
| 63 |
+
queue_capacity_(queue_capacity) {}
|
| 64 |
+
|
| 65 |
+
/// Return batch data from the queue. Called from the ChunkDataset main
|
| 66 |
+
/// thread.
|
| 67 |
+
BatchType get_batch() {
|
| 68 |
+
std::unique_lock<std::mutex> lock(queue_mutex_);
|
| 69 |
+
cv_read_.wait(lock, [this] {
|
| 70 |
+
// wait till there is available data in the queue or if all chunks are
|
| 71 |
+
// loaded (i.e. the dataset is exhausted for this epoch)
|
| 72 |
+
return (
|
| 73 |
+
this->total_example_count_in_queue_ >= batch_size_ || this->stop_);
|
| 74 |
+
});
|
| 75 |
+
if (batch_queue_.empty()) {
|
| 76 |
+
AT_ASSERT(stop_);
|
| 77 |
+
// All batches have been retrieved. Return an empty batch.
|
| 78 |
+
return nullopt;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
UnwrappedBatchData batch = std::move(batch_queue_.front());
|
| 82 |
+
batch_queue_.pop();
|
| 83 |
+
if (batch.exception) {
|
| 84 |
+
throw WorkerException(batch.exception);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
total_example_count_in_queue_ -= batch.batch_data.size();
|
| 88 |
+
lock.unlock();
|
| 89 |
+
cv_write_.notify_all();
|
| 90 |
+
|
| 91 |
+
return batch.batch_data;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/// Push preloaded chunks to batch queue. Called from the ChunkDataset worker
|
| 95 |
+
/// threads.
|
| 96 |
+
void add_chunk_data(UnwrappedBatchType data) {
|
| 97 |
+
std::unique_lock<std::mutex> lock(queue_mutex_);
|
| 98 |
+
cv_write_.wait(lock, [this] {
|
| 99 |
+
// stop loading if we have preloaded enough data.
|
| 100 |
+
return this->total_example_count_in_queue_ < this->queue_capacity_ ||
|
| 101 |
+
this->stop_;
|
| 102 |
+
});
|
| 103 |
+
if (stop_) {
|
| 104 |
+
// When stop_ is true, it means no further chunk loading is necessary.
|
| 105 |
+
// Return without any further processing.
|
| 106 |
+
return;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
auto data_size = data.size();
|
| 110 |
+
auto remaining_size = data_size;
|
| 111 |
+
example_sampler_.reset(data_size);
|
| 112 |
+
|
| 113 |
+
auto fill_batch = [&](size_t example_count, UnwrappedBatchType& batch) {
|
| 114 |
+
auto batch_example_indices = this->example_sampler_.next(example_count);
|
| 115 |
+
AT_ASSERT(
|
| 116 |
+
batch_example_indices &&
|
| 117 |
+
batch_example_indices.value().size() == example_count);
|
| 118 |
+
BatchRequestType& indices = batch_example_indices.value();
|
| 119 |
+
for (size_t i : indices) {
|
| 120 |
+
TORCH_CHECK(i < data_size, "Index out of range");
|
| 121 |
+
batch.emplace_back(std::move(data[i]));
|
| 122 |
+
}
|
| 123 |
+
remaining_size -= example_count;
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
if (!batch_queue_.empty()) {
|
| 127 |
+
// if the queue has existing data, and the last batch doesn't have enough
|
| 128 |
+
// examples to fill a batch_size batch, add more example to this batch
|
| 129 |
+
// first.
|
| 130 |
+
auto& batch = batch_queue_.back();
|
| 131 |
+
size_t current_count = batch.batch_data.size();
|
| 132 |
+
if (current_count < batch_size_) {
|
| 133 |
+
auto example_count =
|
| 134 |
+
std::min(remaining_size, batch_size_ - current_count);
|
| 135 |
+
fill_batch(example_count, batch.batch_data);
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// If we still have data remaining after filling the last pushed batch, add
|
| 140 |
+
// them to the queue too.
|
| 141 |
+
// NOLINTNEXTLINE(bugprone-infinite-loop)
|
| 142 |
+
while (remaining_size > 0) {
|
| 143 |
+
UnwrappedBatchType current_batch;
|
| 144 |
+
|
| 145 |
+
// Allocate the batch memory ahead of time.
|
| 146 |
+
current_batch.reserve(batch_size_);
|
| 147 |
+
|
| 148 |
+
auto example_count = std::min(remaining_size, batch_size_);
|
| 149 |
+
fill_batch(example_count, current_batch);
|
| 150 |
+
batch_queue_.emplace(std::move(current_batch));
|
| 151 |
+
}
|
| 152 |
+
total_example_count_in_queue_ += data_size;
|
| 153 |
+
lock.unlock();
|
| 154 |
+
cv_read_.notify_all();
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/// Push exceptions thrown during preloading into batch queue. Called from
|
| 158 |
+
/// the ChunkDataset worker threads.
|
| 159 |
+
void add_chunk_data(std::exception_ptr e_ptr) {
|
| 160 |
+
std::unique_lock<std::mutex> lock(queue_mutex_);
|
| 161 |
+
cv_write_.wait(lock, [this] {
|
| 162 |
+
// stop loading if we have preloaded enough data.
|
| 163 |
+
return (
|
| 164 |
+
this->total_example_count_in_queue_ < this->queue_capacity_ ||
|
| 165 |
+
this->stop_);
|
| 166 |
+
});
|
| 167 |
+
if (stop_) {
|
| 168 |
+
// When stop_ is true, it means this current thread needs to be tore down,
|
| 169 |
+
// the batch buffer will be discarded, so no need to enqueue any new
|
| 170 |
+
// exceptions.
|
| 171 |
+
return;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
batch_queue_.emplace(e_ptr);
|
| 175 |
+
lock.unlock();
|
| 176 |
+
cv_read_.notify_all();
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
void stop() {
|
| 180 |
+
{
|
| 181 |
+
// Hold the lock before changing stop_ to prevent a race condition which
|
| 182 |
+
// can cause a deadlock. To be more specific, conditional variable
|
| 183 |
+
// cv_write_ waits on predicate stop_ in add_chunk_data(). The wait
|
| 184 |
+
// happens in two steps: 1) while still holding the lock, check if
|
| 185 |
+
// predicate is true; 2) if it is true, proceeds, otherwise, release the
|
| 186 |
+
// lock and wait until notified. Without holding a lock, cv_write_'s
|
| 187 |
+
// notification can happen in between step 1) and 2). In that case, as
|
| 188 |
+
// cv_write_ is not in waiting status yet, so the notification is lost and
|
| 189 |
+
// cv_write_ will sleep forever. By taking a lock before changing
|
| 190 |
+
// predicate stop_, it is ensured updating and evaluating stop_ always
|
| 191 |
+
// happen in a synchronized way
|
| 192 |
+
std::lock_guard<std::mutex> lock(queue_mutex_);
|
| 193 |
+
stop_ = true;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// notify all writers, wake them from wait to exit current method.
|
| 197 |
+
cv_write_.notify_all();
|
| 198 |
+
// notify all readers too.
|
| 199 |
+
cv_read_.notify_all();
|
| 200 |
+
}
|
| 201 |
+
/// The batch size is needed to create batches from the chunk data. Similar to
|
| 202 |
+
/// regular dataloader where the batches are created with prefetches,
|
| 203 |
+
/// BatchDataBuffer perform the batch creation using the provided batch size.
|
| 204 |
+
size_t batch_size_ = 0;
|
| 205 |
+
|
| 206 |
+
/// count of total example stored in the queue
|
| 207 |
+
size_t total_example_count_in_queue_ = 0;
|
| 208 |
+
|
| 209 |
+
/// struct that contains a raw unwrapped batch unit. An unwrapped batch unit
|
| 210 |
+
/// is the raw data without 'optional' wrapper. It can be a collection of
|
| 211 |
+
/// images, utterances, e.t.c.
|
| 212 |
+
struct UnwrappedBatchData {
|
| 213 |
+
explicit UnwrappedBatchData(UnwrappedBatchType data)
|
| 214 |
+
: batch_data(std::move(data)) {}
|
| 215 |
+
|
| 216 |
+
// NOLINTNEXTLINE(modernize-pass-by-value)
|
| 217 |
+
explicit UnwrappedBatchData(std::exception_ptr e) : exception(e) {}
|
| 218 |
+
|
| 219 |
+
/// batch data to return
|
| 220 |
+
UnwrappedBatchType batch_data;
|
| 221 |
+
|
| 222 |
+
/// exception pointer which captures any abnormal exceptions while creating
|
| 223 |
+
/// the batch.
|
| 224 |
+
std::exception_ptr exception;
|
| 225 |
+
};
|
| 226 |
+
|
| 227 |
+
/// local cache to store example batches from loaded chunk
|
| 228 |
+
std::queue<UnwrappedBatchData> batch_queue_;
|
| 229 |
+
|
| 230 |
+
// sync batch_queue_ update.
|
| 231 |
+
std::mutex queue_mutex_;
|
| 232 |
+
|
| 233 |
+
std::condition_variable cv_read_;
|
| 234 |
+
std::condition_variable cv_write_;
|
| 235 |
+
|
| 236 |
+
ExampleSampler& example_sampler_;
|
| 237 |
+
|
| 238 |
+
// configurable maximun number of elements the queue can hold at one time.
|
| 239 |
+
size_t queue_capacity_;
|
| 240 |
+
|
| 241 |
+
// When set to true, it wakes the writer threads from the wait and exit
|
| 242 |
+
// current function call. This is needed when ChunkDataSet.Reset is called
|
| 243 |
+
// while the previous epoch is not exhausted yet. When ChunkDataset is waiting
|
| 244 |
+
// its preloader to finish previous work before tearing down the thread, the
|
| 245 |
+
// preloader could be still waiting for the conditional variable, thus cause
|
| 246 |
+
// the program to hang. This boolean is used to break this waiting condition.
|
| 247 |
+
bool stop_ = false;
|
| 248 |
+
};
|
| 249 |
+
} // namespace detail
|
| 250 |
+
|
| 251 |
+
/// Options to configure a `ChunkDataset`.
|
| 252 |
+
struct ChunkDatasetOptions {
|
| 253 |
+
ChunkDatasetOptions() = delete;
|
| 254 |
+
ChunkDatasetOptions(
|
| 255 |
+
size_t preloader_count,
|
| 256 |
+
size_t batch_size,
|
| 257 |
+
size_t cache_size = 2048,
|
| 258 |
+
size_t cross_chunk_shuffle_count = 1)
|
| 259 |
+
: preloader_count_(preloader_count),
|
| 260 |
+
batch_size_(batch_size),
|
| 261 |
+
cache_size_(cache_size),
|
| 262 |
+
cross_chunk_shuffle_count_(cross_chunk_shuffle_count) {
|
| 263 |
+
TORCH_CHECK(
|
| 264 |
+
preloader_count_ > 0,
|
| 265 |
+
"Preloader count is 0. At least one preloader needs to be specified.");
|
| 266 |
+
TORCH_CHECK(
|
| 267 |
+
batch_size_ > 0,
|
| 268 |
+
"Batch size is 0. A positive batch size needs to be specified.");
|
| 269 |
+
TORCH_CHECK(
|
| 270 |
+
cache_size_ > 0,
|
| 271 |
+
"Cache size is 0. A positive cache size needs to be specified.");
|
| 272 |
+
TORCH_CHECK(
|
| 273 |
+
cache_size_ >= batch_size_,
|
| 274 |
+
"Cache size is less than batch size. Cache needs to be large enough to "
|
| 275 |
+
"hold at least one batch.");
|
| 276 |
+
TORCH_CHECK(
|
| 277 |
+
cross_chunk_shuffle_count_ > 0,
|
| 278 |
+
"cross_chunk_shuffle_count needs to be greater than 0.");
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
/// The number of worker thread to preload chunk data.
|
| 282 |
+
TORCH_ARG(size_t, preloader_count);
|
| 283 |
+
|
| 284 |
+
/// The size of each batch.
|
| 285 |
+
TORCH_ARG(size_t, batch_size);
|
| 286 |
+
|
| 287 |
+
/// The capacity of the queue for batch caching.
|
| 288 |
+
TORCH_ARG(size_t, cache_size) = 2048;
|
| 289 |
+
|
| 290 |
+
// The number of chunks to perfrom cross-chunk shuffling. Default to 1 meaning
|
| 291 |
+
// no cross-chunk shuffling. When it is equal to n (n > 1), n random
|
| 292 |
+
// chunks will be loaded at once and example shuffling will be performed
|
| 293 |
+
// across all those n chunks.
|
| 294 |
+
// Note: Usually the default config (1 chunk shuffle + example shuffle) is
|
| 295 |
+
// good enough to generate random distributed data. Use this parameter only if
|
| 296 |
+
// you know cross-shuffle is needed in your case. Also there is a performance
|
| 297 |
+
// penalty when this value is greater than 1, as we need to do extra merge
|
| 298 |
+
// between multiple chunks before performing example sampling.
|
| 299 |
+
TORCH_ARG(size_t, cross_chunk_shuffle_count) = 1;
|
| 300 |
+
};
|
| 301 |
+
|
| 302 |
+
/// A stateful dataset that support hierarchical sampling and prefetching of
|
| 303 |
+
/// entre chunks.
|
| 304 |
+
///
|
| 305 |
+
/// Unlike regular dataset, chunk dataset require two samplers to operate and
|
| 306 |
+
/// keeps an internal state. `ChunkSampler` selects, which chunk to load next,
|
| 307 |
+
/// while the `ExampleSampler` determins the order of Examples that are returned
|
| 308 |
+
/// in each `get_batch` call. The hierarchical sampling approach used here is
|
| 309 |
+
/// inspired by this paper http://martin.zinkevich.org/publications/nips2010.pdf
|
| 310 |
+
template <
|
| 311 |
+
typename ChunkReader,
|
| 312 |
+
typename ChunkSampler = samplers::RandomSampler,
|
| 313 |
+
typename ExampleSampler = samplers::RandomSampler>
|
| 314 |
+
class ChunkDataset final
|
| 315 |
+
: public StatefulDataset<
|
| 316 |
+
ChunkDataset<ChunkReader, ChunkSampler, ExampleSampler>,
|
| 317 |
+
typename ChunkReader::BatchType,
|
| 318 |
+
size_t> {
|
| 319 |
+
public:
|
| 320 |
+
using BatchType = torch::optional<typename ChunkReader::BatchType>;
|
| 321 |
+
using UnwrappedBatchType = typename ChunkReader::BatchType;
|
| 322 |
+
using BatchRequestType = size_t;
|
| 323 |
+
using ChunkSamplerType = ChunkSampler;
|
| 324 |
+
using ExampleSamplerType = ExampleSampler;
|
| 325 |
+
|
| 326 |
+
ChunkDataset(
|
| 327 |
+
ChunkReader chunk_reader,
|
| 328 |
+
ChunkSampler chunk_sampler,
|
| 329 |
+
ExampleSampler example_sampler,
|
| 330 |
+
ChunkDatasetOptions options,
|
| 331 |
+
std::function<void(UnwrappedBatchType&)> preprocessing_policy =
|
| 332 |
+
std::function<void(UnwrappedBatchType&)>())
|
| 333 |
+
: chunk_reader_(std::move(chunk_reader)),
|
| 334 |
+
chunk_sampler_(std::move(chunk_sampler)),
|
| 335 |
+
example_sampler_(std::move(example_sampler)),
|
| 336 |
+
options_(std::move(options)),
|
| 337 |
+
preprocessing_policy_(std::move(preprocessing_policy)),
|
| 338 |
+
quit_worker_(false),
|
| 339 |
+
running_preloaders_(0),
|
| 340 |
+
load_checkpoint_(false) {}
|
| 341 |
+
|
| 342 |
+
~ChunkDataset() override {
|
| 343 |
+
// stop batch buffer first.
|
| 344 |
+
if (batch_buffer_) {
|
| 345 |
+
batch_buffer_->stop();
|
| 346 |
+
}
|
| 347 |
+
free_workers();
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
/// Default get_batch method of BatchDataset. This method returns
|
| 351 |
+
/// Example batches created from the preloaded chunks. The implemenation
|
| 352 |
+
/// is dataset agnostic and does not need overriding in different chunk
|
| 353 |
+
/// datasets.
|
| 354 |
+
BatchType get_batch(size_t batch_size) override {
|
| 355 |
+
TORCH_CHECK(
|
| 356 |
+
batch_buffer_ != nullptr,
|
| 357 |
+
"Dataset needs to call reset() before calling get_batch().");
|
| 358 |
+
|
| 359 |
+
TORCH_CHECK(
|
| 360 |
+
batch_size == options_.batch_size(),
|
| 361 |
+
"The requested batch size does not match with the initialized batch size.\n"
|
| 362 |
+
" The requested batch size is ",
|
| 363 |
+
batch_size,
|
| 364 |
+
", while the dataset is created with batch size equal to ",
|
| 365 |
+
options_.batch_size());
|
| 366 |
+
return batch_buffer_->get_batch();
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
/// Helper method around get_batch as `batch_size` is not strictly necessary
|
| 370 |
+
BatchType get_batch() {
|
| 371 |
+
return get_batch(options_.batch_size());
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
/// This will clear any internal state and starts the internal prefetching
|
| 375 |
+
/// mechanism for the chunk dataset.
|
| 376 |
+
void reset() override {
|
| 377 |
+
// We need this to support partial data reads via dataloader iterator.
|
| 378 |
+
if (batch_buffer_) {
|
| 379 |
+
batch_buffer_->stop();
|
| 380 |
+
}
|
| 381 |
+
// free workers from previous reset if there is any.
|
| 382 |
+
free_workers();
|
| 383 |
+
preload_threads_.clear();
|
| 384 |
+
|
| 385 |
+
if (!load_checkpoint_) {
|
| 386 |
+
chunk_reader_.reset();
|
| 387 |
+
chunk_sampler_.reset(chunk_reader_.chunk_count());
|
| 388 |
+
load_checkpoint_ = false;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
// Throw out any existing cached batch in the buffer and re-creates a new
|
| 392 |
+
// chunk buffer.
|
| 393 |
+
batch_buffer_ = std::make_unique<
|
| 394 |
+
detail::BatchDataBuffer<UnwrappedBatchType, ExampleSamplerType>>(
|
| 395 |
+
options_.batch_size(), example_sampler_, options_.cache_size());
|
| 396 |
+
|
| 397 |
+
// create new workers for this new epoch.
|
| 398 |
+
quit_worker_ = false;
|
| 399 |
+
|
| 400 |
+
AT_ASSERT(running_preloaders_ == 0);
|
| 401 |
+
running_preloaders_ = options_.preloader_count();
|
| 402 |
+
for (const auto i : c10::irange(options_.preloader_count())) {
|
| 403 |
+
preload_threads_.emplace_back([this, i]() { this->preloader(i); });
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
/// size is not used for chunk dataset.
|
| 408 |
+
std::optional<size_t> size() const override {
|
| 409 |
+
return torch::nullopt;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
// provide a references to chunk sampler. Used mainly in distributed data
|
| 413 |
+
// loading to set the epoch number for the sampler.
|
| 414 |
+
ChunkSamplerType& chunk_sampler() {
|
| 415 |
+
return chunk_sampler_;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
void save(serialize::OutputArchive& archive) const override {
|
| 419 |
+
std::lock_guard<std::mutex> lock(chunk_index_guard_);
|
| 420 |
+
chunk_sampler_.save(archive);
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
void load(serialize::InputArchive& archive) override {
|
| 424 |
+
std::lock_guard<std::mutex> lock(chunk_index_guard_);
|
| 425 |
+
chunk_sampler_.load(archive);
|
| 426 |
+
load_checkpoint_ = true;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
private:
|
| 430 |
+
/// running on worker thread to preload chunk data.
|
| 431 |
+
void preloader(size_t id) {
|
| 432 |
+
while (!quit_worker_.load()) {
|
| 433 |
+
try {
|
| 434 |
+
std::vector<size_t> chunk_idx;
|
| 435 |
+
{
|
| 436 |
+
std::lock_guard<std::mutex> lock(chunk_index_guard_);
|
| 437 |
+
if (auto chunk_sampler_result = chunk_sampler_.next(
|
| 438 |
+
this->options_.cross_chunk_shuffle_count())) {
|
| 439 |
+
chunk_idx = chunk_sampler_result.value();
|
| 440 |
+
} else {
|
| 441 |
+
break;
|
| 442 |
+
}
|
| 443 |
+
}
|
| 444 |
+
UnwrappedBatchType data = chunk_reader_.read_chunk(chunk_idx[0]);
|
| 445 |
+
for (const auto i : c10::irange(1, chunk_idx.size())) {
|
| 446 |
+
auto chunk_data = chunk_reader_.read_chunk(chunk_idx[i]);
|
| 447 |
+
std::move(
|
| 448 |
+
chunk_data.begin(), chunk_data.end(), std::back_inserter(data));
|
| 449 |
+
}
|
| 450 |
+
if (preprocessing_policy_) {
|
| 451 |
+
preprocessing_policy_(data);
|
| 452 |
+
}
|
| 453 |
+
if (!data.empty()) { // skip empty chunks.
|
| 454 |
+
batch_buffer_->add_chunk_data(std::move(data));
|
| 455 |
+
}
|
| 456 |
+
} catch (...) {
|
| 457 |
+
batch_buffer_->add_chunk_data(std::current_exception());
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
AT_ASSERT(running_preloaders_.load() > 0);
|
| 461 |
+
--running_preloaders_;
|
| 462 |
+
if (running_preloaders_.load() == 0) {
|
| 463 |
+
// all preloaders are completed, so we can notify the batch_buffer.
|
| 464 |
+
batch_buffer_->stop();
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
/// Block the current thread until the workers finish execution and exit.
|
| 469 |
+
void free_workers() {
|
| 470 |
+
if (!quit_worker_.load()) {
|
| 471 |
+
quit_worker_ = true;
|
| 472 |
+
for (auto& worker_thread : preload_threads_) {
|
| 473 |
+
worker_thread.join();
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
private:
|
| 479 |
+
// Templated class that defines what is a chunk and how to read chunk data.
|
| 480 |
+
// When a chunk is returned by chunk_reader_, ChunkDataset split it into
|
| 481 |
+
// batches and caches them in batch_buffer_.
|
| 482 |
+
ChunkReader chunk_reader_;
|
| 483 |
+
|
| 484 |
+
// chunk sampler to shuffle different chunks
|
| 485 |
+
ChunkSamplerType chunk_sampler_;
|
| 486 |
+
|
| 487 |
+
// example sampler to shuffle examples in a specific chunk
|
| 488 |
+
ExampleSamplerType example_sampler_;
|
| 489 |
+
|
| 490 |
+
// batch data buffer which holds chunk data from preloading thread.
|
| 491 |
+
std::shared_ptr<
|
| 492 |
+
detail::BatchDataBuffer<UnwrappedBatchType, ExampleSamplerType>>
|
| 493 |
+
batch_buffer_;
|
| 494 |
+
|
| 495 |
+
// worker thread pool
|
| 496 |
+
std::vector<std::thread> preload_threads_;
|
| 497 |
+
|
| 498 |
+
/// The options the Dataset was configured with.
|
| 499 |
+
const ChunkDatasetOptions options_;
|
| 500 |
+
|
| 501 |
+
// function pointer wrapper to apply custom processing over chunk data. This
|
| 502 |
+
// is considered an advanced parameter for developers who want to apply a
|
| 503 |
+
// pre-process to the chunk data before sampling into minibatch.
|
| 504 |
+
// Different than the collate function, this policy is applied on the chunk
|
| 505 |
+
// level, instead of minibatch level. When a chunk of data is loaded (multiple
|
| 506 |
+
// chunks if cross_chunk_shuffle_count_ is greater than 1), this policy is
|
| 507 |
+
// applied to the full loaded data. It is useful if developers want to
|
| 508 |
+
// perform pre-processing (like bucketing) to the chunk data before
|
| 509 |
+
// example sampler samples the data. By default it's an empty pointer and no
|
| 510 |
+
// action will be taken.
|
| 511 |
+
std::function<void(UnwrappedBatchType&)> preprocessing_policy_;
|
| 512 |
+
|
| 513 |
+
// indicate whether the worker thread can be teared down
|
| 514 |
+
std::atomic<bool> quit_worker_;
|
| 515 |
+
|
| 516 |
+
// keep track of running preloaders to notify batch buffer. A value 0
|
| 517 |
+
// indicates that the chunk loading is completed.
|
| 518 |
+
std::atomic<size_t> running_preloaders_;
|
| 519 |
+
|
| 520 |
+
// mutex to synchronize chunk sampler next() call.
|
| 521 |
+
mutable std::mutex chunk_index_guard_;
|
| 522 |
+
|
| 523 |
+
// boolean value to indicate whether we need to load the checkpoint for
|
| 524 |
+
// chunk_sampler_.
|
| 525 |
+
bool load_checkpoint_;
|
| 526 |
+
};
|
| 527 |
+
} // namespace datasets
|
| 528 |
+
} // namespace data
|
| 529 |
+
} // namespace torch
|