ZTWHHH commited on
Commit
5c04d0b
·
verified ·
1 Parent(s): 857ae05

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/__init__.cpython-310.pyc +0 -0
  2. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_log.cpython-310.pyc +0 -0
  3. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_macos_compat.cpython-310.pyc +0 -0
  4. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_modified.cpython-310.pyc +0 -0
  5. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-310.pyc +0 -0
  6. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc +0 -0
  7. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc +0 -0
  8. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-310.pyc +0 -0
  9. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/core.cpython-310.pyc +0 -0
  10. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc +0 -0
  11. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc +0 -0
  12. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dep_util.cpython-310.pyc +0 -0
  13. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dir_util.cpython-310.pyc +0 -0
  14. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dist.cpython-310.pyc +0 -0
  15. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/errors.cpython-310.pyc +0 -0
  16. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/extension.cpython-310.pyc +0 -0
  17. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-310.pyc +0 -0
  18. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/file_util.cpython-310.pyc +0 -0
  19. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-310.pyc +0 -0
  20. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/log.cpython-310.pyc +0 -0
  21. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-310.pyc +0 -0
  22. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-310.pyc +0 -0
  23. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/text_file.cpython-310.pyc +0 -0
  24. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/util.cpython-310.pyc +0 -0
  25. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/version.cpython-310.pyc +0 -0
  26. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc +0 -0
  27. videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/zosccompiler.cpython-310.pyc +0 -0
  28. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__init__.py +23 -0
  29. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-310.pyc +0 -0
  30. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/_framework_compat.cpython-310.pyc +0 -0
  31. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_rpm.cpython-310.pyc +0 -0
  32. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build.cpython-310.pyc +0 -0
  33. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_py.cpython-310.pyc +0 -0
  34. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-310.pyc +0 -0
  35. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/config.cpython-310.pyc +0 -0
  36. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install.cpython-310.pyc +0 -0
  37. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/_framework_compat.py +54 -0
  38. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_dumb.py +140 -0
  39. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_rpm.py +597 -0
  40. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build.py +157 -0
  41. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_clib.py +208 -0
  42. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py +800 -0
  43. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.py +406 -0
  44. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.py +171 -0
  45. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/check.py +152 -0
  46. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/clean.py +76 -0
  47. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/config.py +369 -0
  48. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/install.py +811 -0
  49. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/install_data.py +93 -0
  50. videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/install_egg_info.py +91 -0
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (345 Bytes). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_log.cpython-310.pyc ADDED
Binary file (196 Bytes). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_macos_compat.cpython-310.pyc ADDED
Binary file (419 Bytes). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_modified.cpython-310.pyc ADDED
Binary file (2.95 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-310.pyc ADDED
Binary file (14.8 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc ADDED
Binary file (6.11 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc ADDED
Binary file (36 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-310.pyc ADDED
Binary file (14.6 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/core.cpython-310.pyc ADDED
Binary file (7.18 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc ADDED
Binary file (8.13 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc ADDED
Binary file (218 Bytes). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dep_util.cpython-310.pyc ADDED
Binary file (554 Bytes). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dir_util.cpython-310.pyc ADDED
Binary file (7.23 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dist.cpython-310.pyc ADDED
Binary file (36.7 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/errors.cpython-310.pyc ADDED
Binary file (4.69 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/extension.cpython-310.pyc ADDED
Binary file (7.19 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-310.pyc ADDED
Binary file (10.9 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/file_util.cpython-310.pyc ADDED
Binary file (6.01 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-310.pyc ADDED
Binary file (10.8 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/log.cpython-310.pyc ADDED
Binary file (1.67 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-310.pyc ADDED
Binary file (3.48 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-310.pyc ADDED
Binary file (14.5 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/text_file.cpython-310.pyc ADDED
Binary file (8.24 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/util.cpython-310.pyc ADDED
Binary file (13.4 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/version.cpython-310.pyc ADDED
Binary file (8.09 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc ADDED
Binary file (5.27 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/zosccompiler.cpython-310.pyc ADDED
Binary file (4.25 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__init__.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command
2
+
3
+ Package containing implementation of all the standard Distutils
4
+ commands."""
5
+
6
+ __all__ = [
7
+ 'build',
8
+ 'build_py',
9
+ 'build_ext',
10
+ 'build_clib',
11
+ 'build_scripts',
12
+ 'clean',
13
+ 'install',
14
+ 'install_lib',
15
+ 'install_headers',
16
+ 'install_scripts',
17
+ 'install_data',
18
+ 'sdist',
19
+ 'bdist',
20
+ 'bdist_dumb',
21
+ 'bdist_rpm',
22
+ 'check',
23
+ ]
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (464 Bytes). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/_framework_compat.cpython-310.pyc ADDED
Binary file (1.89 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_rpm.cpython-310.pyc ADDED
Binary file (12.2 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build.cpython-310.pyc ADDED
Binary file (3.93 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_py.cpython-310.pyc ADDED
Binary file (9.77 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-310.pyc ADDED
Binary file (2.09 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/config.cpython-310.pyc ADDED
Binary file (10.6 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install.cpython-310.pyc ADDED
Binary file (17.1 kB). View file
 
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/_framework_compat.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Backward compatibility for homebrew builds on macOS.
3
+ """
4
+
5
+ import functools
6
+ import os
7
+ import subprocess
8
+ import sys
9
+ import sysconfig
10
+
11
+
12
+ @functools.lru_cache
13
+ def enabled():
14
+ """
15
+ Only enabled for Python 3.9 framework homebrew builds
16
+ except ensurepip and venv.
17
+ """
18
+ PY39 = (3, 9) < sys.version_info < (3, 10)
19
+ framework = sys.platform == 'darwin' and sys._framework
20
+ homebrew = "Cellar" in sysconfig.get_config_var('projectbase')
21
+ venv = sys.prefix != sys.base_prefix
22
+ ensurepip = os.environ.get("ENSUREPIP_OPTIONS")
23
+ return PY39 and framework and homebrew and not venv and not ensurepip
24
+
25
+
26
+ schemes = dict(
27
+ osx_framework_library=dict(
28
+ stdlib='{installed_base}/{platlibdir}/python{py_version_short}',
29
+ platstdlib='{platbase}/{platlibdir}/python{py_version_short}',
30
+ purelib='{homebrew_prefix}/lib/python{py_version_short}/site-packages',
31
+ platlib='{homebrew_prefix}/{platlibdir}/python{py_version_short}/site-packages',
32
+ include='{installed_base}/include/python{py_version_short}{abiflags}',
33
+ platinclude='{installed_platbase}/include/python{py_version_short}{abiflags}',
34
+ scripts='{homebrew_prefix}/bin',
35
+ data='{homebrew_prefix}',
36
+ )
37
+ )
38
+
39
+
40
+ @functools.lru_cache
41
+ def vars():
42
+ if not enabled():
43
+ return {}
44
+ homebrew_prefix = subprocess.check_output(['brew', '--prefix'], text=True).strip()
45
+ return locals()
46
+
47
+
48
+ def scheme(name):
49
+ """
50
+ Override the selected scheme for posix_prefix.
51
+ """
52
+ if not enabled() or not name.endswith('_prefix'):
53
+ return name
54
+ return 'osx_framework_library'
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_dumb.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.bdist_dumb
2
+
3
+ Implements the Distutils 'bdist_dumb' command (create a "dumb" built
4
+ distribution -- i.e., just an archive to be unpacked under $prefix or
5
+ $exec_prefix)."""
6
+
7
+ import os
8
+ from distutils._log import log
9
+
10
+ from ..core import Command
11
+ from ..dir_util import ensure_relative, remove_tree
12
+ from ..errors import DistutilsPlatformError
13
+ from ..sysconfig import get_python_version
14
+ from ..util import get_platform
15
+
16
+
17
+ class bdist_dumb(Command):
18
+ description = "create a \"dumb\" built distribution"
19
+
20
+ user_options = [
21
+ ('bdist-dir=', 'd', "temporary directory for creating the distribution"),
22
+ (
23
+ 'plat-name=',
24
+ 'p',
25
+ "platform name to embed in generated filenames "
26
+ f"[default: {get_platform()}]",
27
+ ),
28
+ (
29
+ 'format=',
30
+ 'f',
31
+ "archive format to create (tar, gztar, bztar, xztar, ztar, zip)",
32
+ ),
33
+ (
34
+ 'keep-temp',
35
+ 'k',
36
+ "keep the pseudo-installation tree around after creating the distribution archive",
37
+ ),
38
+ ('dist-dir=', 'd', "directory to put final built distributions in"),
39
+ ('skip-build', None, "skip rebuilding everything (for testing/debugging)"),
40
+ (
41
+ 'relative',
42
+ None,
43
+ "build the archive using relative paths [default: false]",
44
+ ),
45
+ (
46
+ 'owner=',
47
+ 'u',
48
+ "Owner name used when creating a tar file [default: current user]",
49
+ ),
50
+ (
51
+ 'group=',
52
+ 'g',
53
+ "Group name used when creating a tar file [default: current group]",
54
+ ),
55
+ ]
56
+
57
+ boolean_options = ['keep-temp', 'skip-build', 'relative']
58
+
59
+ default_format = {'posix': 'gztar', 'nt': 'zip'}
60
+
61
+ def initialize_options(self):
62
+ self.bdist_dir = None
63
+ self.plat_name = None
64
+ self.format = None
65
+ self.keep_temp = False
66
+ self.dist_dir = None
67
+ self.skip_build = None
68
+ self.relative = False
69
+ self.owner = None
70
+ self.group = None
71
+
72
+ def finalize_options(self):
73
+ if self.bdist_dir is None:
74
+ bdist_base = self.get_finalized_command('bdist').bdist_base
75
+ self.bdist_dir = os.path.join(bdist_base, 'dumb')
76
+
77
+ if self.format is None:
78
+ try:
79
+ self.format = self.default_format[os.name]
80
+ except KeyError:
81
+ raise DistutilsPlatformError(
82
+ "don't know how to create dumb built distributions "
83
+ f"on platform {os.name}"
84
+ )
85
+
86
+ self.set_undefined_options(
87
+ 'bdist',
88
+ ('dist_dir', 'dist_dir'),
89
+ ('plat_name', 'plat_name'),
90
+ ('skip_build', 'skip_build'),
91
+ )
92
+
93
+ def run(self):
94
+ if not self.skip_build:
95
+ self.run_command('build')
96
+
97
+ install = self.reinitialize_command('install', reinit_subcommands=True)
98
+ install.root = self.bdist_dir
99
+ install.skip_build = self.skip_build
100
+ install.warn_dir = False
101
+
102
+ log.info("installing to %s", self.bdist_dir)
103
+ self.run_command('install')
104
+
105
+ # And make an archive relative to the root of the
106
+ # pseudo-installation tree.
107
+ archive_basename = f"{self.distribution.get_fullname()}.{self.plat_name}"
108
+
109
+ pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
110
+ if not self.relative:
111
+ archive_root = self.bdist_dir
112
+ else:
113
+ if self.distribution.has_ext_modules() and (
114
+ install.install_base != install.install_platbase
115
+ ):
116
+ raise DistutilsPlatformError(
117
+ "can't make a dumb built distribution where "
118
+ f"base and platbase are different ({install.install_base!r}, {install.install_platbase!r})"
119
+ )
120
+ else:
121
+ archive_root = os.path.join(
122
+ self.bdist_dir, ensure_relative(install.install_base)
123
+ )
124
+
125
+ # Make the archive
126
+ filename = self.make_archive(
127
+ pseudoinstall_root,
128
+ self.format,
129
+ root_dir=archive_root,
130
+ owner=self.owner,
131
+ group=self.group,
132
+ )
133
+ if self.distribution.has_ext_modules():
134
+ pyversion = get_python_version()
135
+ else:
136
+ pyversion = 'any'
137
+ self.distribution.dist_files.append(('bdist_dumb', pyversion, filename))
138
+
139
+ if not self.keep_temp:
140
+ remove_tree(self.bdist_dir, dry_run=self.dry_run)
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_rpm.py ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.bdist_rpm
2
+
3
+ Implements the Distutils 'bdist_rpm' command (create RPM source and binary
4
+ distributions)."""
5
+
6
+ import os
7
+ import subprocess
8
+ import sys
9
+ from distutils._log import log
10
+
11
+ from ..core import Command
12
+ from ..debug import DEBUG
13
+ from ..errors import (
14
+ DistutilsExecError,
15
+ DistutilsFileError,
16
+ DistutilsOptionError,
17
+ DistutilsPlatformError,
18
+ )
19
+ from ..file_util import write_file
20
+ from ..sysconfig import get_python_version
21
+
22
+
23
+ class bdist_rpm(Command):
24
+ description = "create an RPM distribution"
25
+
26
+ user_options = [
27
+ ('bdist-base=', None, "base directory for creating built distributions"),
28
+ (
29
+ 'rpm-base=',
30
+ None,
31
+ "base directory for creating RPMs (defaults to \"rpm\" under "
32
+ "--bdist-base; must be specified for RPM 2)",
33
+ ),
34
+ (
35
+ 'dist-dir=',
36
+ 'd',
37
+ "directory to put final RPM files in (and .spec files if --spec-only)",
38
+ ),
39
+ (
40
+ 'python=',
41
+ None,
42
+ "path to Python interpreter to hard-code in the .spec file "
43
+ "[default: \"python\"]",
44
+ ),
45
+ (
46
+ 'fix-python',
47
+ None,
48
+ "hard-code the exact path to the current Python interpreter in "
49
+ "the .spec file",
50
+ ),
51
+ ('spec-only', None, "only regenerate spec file"),
52
+ ('source-only', None, "only generate source RPM"),
53
+ ('binary-only', None, "only generate binary RPM"),
54
+ ('use-bzip2', None, "use bzip2 instead of gzip to create source distribution"),
55
+ # More meta-data: too RPM-specific to put in the setup script,
56
+ # but needs to go in the .spec file -- so we make these options
57
+ # to "bdist_rpm". The idea is that packagers would put this
58
+ # info in setup.cfg, although they are of course free to
59
+ # supply it on the command line.
60
+ (
61
+ 'distribution-name=',
62
+ None,
63
+ "name of the (Linux) distribution to which this "
64
+ "RPM applies (*not* the name of the module distribution!)",
65
+ ),
66
+ ('group=', None, "package classification [default: \"Development/Libraries\"]"),
67
+ ('release=', None, "RPM release number"),
68
+ ('serial=', None, "RPM serial number"),
69
+ (
70
+ 'vendor=',
71
+ None,
72
+ "RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") "
73
+ "[default: maintainer or author from setup script]",
74
+ ),
75
+ (
76
+ 'packager=',
77
+ None,
78
+ "RPM packager (eg. \"Jane Doe <jane@example.net>\") [default: vendor]",
79
+ ),
80
+ ('doc-files=', None, "list of documentation files (space or comma-separated)"),
81
+ ('changelog=', None, "RPM changelog"),
82
+ ('icon=', None, "name of icon file"),
83
+ ('provides=', None, "capabilities provided by this package"),
84
+ ('requires=', None, "capabilities required by this package"),
85
+ ('conflicts=', None, "capabilities which conflict with this package"),
86
+ ('build-requires=', None, "capabilities required to build this package"),
87
+ ('obsoletes=', None, "capabilities made obsolete by this package"),
88
+ ('no-autoreq', None, "do not automatically calculate dependencies"),
89
+ # Actions to take when building RPM
90
+ ('keep-temp', 'k', "don't clean up RPM build directory"),
91
+ ('no-keep-temp', None, "clean up RPM build directory [default]"),
92
+ (
93
+ 'use-rpm-opt-flags',
94
+ None,
95
+ "compile with RPM_OPT_FLAGS when building from source RPM",
96
+ ),
97
+ ('no-rpm-opt-flags', None, "do not pass any RPM CFLAGS to compiler"),
98
+ ('rpm3-mode', None, "RPM 3 compatibility mode (default)"),
99
+ ('rpm2-mode', None, "RPM 2 compatibility mode"),
100
+ # Add the hooks necessary for specifying custom scripts
101
+ ('prep-script=', None, "Specify a script for the PREP phase of RPM building"),
102
+ ('build-script=', None, "Specify a script for the BUILD phase of RPM building"),
103
+ (
104
+ 'pre-install=',
105
+ None,
106
+ "Specify a script for the pre-INSTALL phase of RPM building",
107
+ ),
108
+ (
109
+ 'install-script=',
110
+ None,
111
+ "Specify a script for the INSTALL phase of RPM building",
112
+ ),
113
+ (
114
+ 'post-install=',
115
+ None,
116
+ "Specify a script for the post-INSTALL phase of RPM building",
117
+ ),
118
+ (
119
+ 'pre-uninstall=',
120
+ None,
121
+ "Specify a script for the pre-UNINSTALL phase of RPM building",
122
+ ),
123
+ (
124
+ 'post-uninstall=',
125
+ None,
126
+ "Specify a script for the post-UNINSTALL phase of RPM building",
127
+ ),
128
+ ('clean-script=', None, "Specify a script for the CLEAN phase of RPM building"),
129
+ (
130
+ 'verify-script=',
131
+ None,
132
+ "Specify a script for the VERIFY phase of the RPM build",
133
+ ),
134
+ # Allow a packager to explicitly force an architecture
135
+ ('force-arch=', None, "Force an architecture onto the RPM build process"),
136
+ ('quiet', 'q', "Run the INSTALL phase of RPM building in quiet mode"),
137
+ ]
138
+
139
+ boolean_options = [
140
+ 'keep-temp',
141
+ 'use-rpm-opt-flags',
142
+ 'rpm3-mode',
143
+ 'no-autoreq',
144
+ 'quiet',
145
+ ]
146
+
147
+ negative_opt = {
148
+ 'no-keep-temp': 'keep-temp',
149
+ 'no-rpm-opt-flags': 'use-rpm-opt-flags',
150
+ 'rpm2-mode': 'rpm3-mode',
151
+ }
152
+
153
+ def initialize_options(self):
154
+ self.bdist_base = None
155
+ self.rpm_base = None
156
+ self.dist_dir = None
157
+ self.python = None
158
+ self.fix_python = None
159
+ self.spec_only = None
160
+ self.binary_only = None
161
+ self.source_only = None
162
+ self.use_bzip2 = None
163
+
164
+ self.distribution_name = None
165
+ self.group = None
166
+ self.release = None
167
+ self.serial = None
168
+ self.vendor = None
169
+ self.packager = None
170
+ self.doc_files = None
171
+ self.changelog = None
172
+ self.icon = None
173
+
174
+ self.prep_script = None
175
+ self.build_script = None
176
+ self.install_script = None
177
+ self.clean_script = None
178
+ self.verify_script = None
179
+ self.pre_install = None
180
+ self.post_install = None
181
+ self.pre_uninstall = None
182
+ self.post_uninstall = None
183
+ self.prep = None
184
+ self.provides = None
185
+ self.requires = None
186
+ self.conflicts = None
187
+ self.build_requires = None
188
+ self.obsoletes = None
189
+
190
+ self.keep_temp = False
191
+ self.use_rpm_opt_flags = True
192
+ self.rpm3_mode = True
193
+ self.no_autoreq = False
194
+
195
+ self.force_arch = None
196
+ self.quiet = False
197
+
198
+ def finalize_options(self):
199
+ self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
200
+ if self.rpm_base is None:
201
+ if not self.rpm3_mode:
202
+ raise DistutilsOptionError("you must specify --rpm-base in RPM 2 mode")
203
+ self.rpm_base = os.path.join(self.bdist_base, "rpm")
204
+
205
+ if self.python is None:
206
+ if self.fix_python:
207
+ self.python = sys.executable
208
+ else:
209
+ self.python = "python3"
210
+ elif self.fix_python:
211
+ raise DistutilsOptionError(
212
+ "--python and --fix-python are mutually exclusive options"
213
+ )
214
+
215
+ if os.name != 'posix':
216
+ raise DistutilsPlatformError(
217
+ f"don't know how to create RPM distributions on platform {os.name}"
218
+ )
219
+ if self.binary_only and self.source_only:
220
+ raise DistutilsOptionError(
221
+ "cannot supply both '--source-only' and '--binary-only'"
222
+ )
223
+
224
+ # don't pass CFLAGS to pure python distributions
225
+ if not self.distribution.has_ext_modules():
226
+ self.use_rpm_opt_flags = False
227
+
228
+ self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
229
+ self.finalize_package_data()
230
+
231
+ def finalize_package_data(self):
232
+ self.ensure_string('group', "Development/Libraries")
233
+ self.ensure_string(
234
+ 'vendor',
235
+ f"{self.distribution.get_contact()} <{self.distribution.get_contact_email()}>",
236
+ )
237
+ self.ensure_string('packager')
238
+ self.ensure_string_list('doc_files')
239
+ if isinstance(self.doc_files, list):
240
+ for readme in ('README', 'README.txt'):
241
+ if os.path.exists(readme) and readme not in self.doc_files:
242
+ self.doc_files.append(readme)
243
+
244
+ self.ensure_string('release', "1")
245
+ self.ensure_string('serial') # should it be an int?
246
+
247
+ self.ensure_string('distribution_name')
248
+
249
+ self.ensure_string('changelog')
250
+ # Format changelog correctly
251
+ self.changelog = self._format_changelog(self.changelog)
252
+
253
+ self.ensure_filename('icon')
254
+
255
+ self.ensure_filename('prep_script')
256
+ self.ensure_filename('build_script')
257
+ self.ensure_filename('install_script')
258
+ self.ensure_filename('clean_script')
259
+ self.ensure_filename('verify_script')
260
+ self.ensure_filename('pre_install')
261
+ self.ensure_filename('post_install')
262
+ self.ensure_filename('pre_uninstall')
263
+ self.ensure_filename('post_uninstall')
264
+
265
+ # XXX don't forget we punted on summaries and descriptions -- they
266
+ # should be handled here eventually!
267
+
268
+ # Now *this* is some meta-data that belongs in the setup script...
269
+ self.ensure_string_list('provides')
270
+ self.ensure_string_list('requires')
271
+ self.ensure_string_list('conflicts')
272
+ self.ensure_string_list('build_requires')
273
+ self.ensure_string_list('obsoletes')
274
+
275
+ self.ensure_string('force_arch')
276
+
277
+ def run(self): # noqa: C901
278
+ if DEBUG:
279
+ print("before _get_package_data():")
280
+ print("vendor =", self.vendor)
281
+ print("packager =", self.packager)
282
+ print("doc_files =", self.doc_files)
283
+ print("changelog =", self.changelog)
284
+
285
+ # make directories
286
+ if self.spec_only:
287
+ spec_dir = self.dist_dir
288
+ self.mkpath(spec_dir)
289
+ else:
290
+ rpm_dir = {}
291
+ for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
292
+ rpm_dir[d] = os.path.join(self.rpm_base, d)
293
+ self.mkpath(rpm_dir[d])
294
+ spec_dir = rpm_dir['SPECS']
295
+
296
+ # Spec file goes into 'dist_dir' if '--spec-only specified',
297
+ # build/rpm.<plat> otherwise.
298
+ spec_path = os.path.join(spec_dir, f"{self.distribution.get_name()}.spec")
299
+ self.execute(
300
+ write_file, (spec_path, self._make_spec_file()), f"writing '{spec_path}'"
301
+ )
302
+
303
+ if self.spec_only: # stop if requested
304
+ return
305
+
306
+ # Make a source distribution and copy to SOURCES directory with
307
+ # optional icon.
308
+ saved_dist_files = self.distribution.dist_files[:]
309
+ sdist = self.reinitialize_command('sdist')
310
+ if self.use_bzip2:
311
+ sdist.formats = ['bztar']
312
+ else:
313
+ sdist.formats = ['gztar']
314
+ self.run_command('sdist')
315
+ self.distribution.dist_files = saved_dist_files
316
+
317
+ source = sdist.get_archive_files()[0]
318
+ source_dir = rpm_dir['SOURCES']
319
+ self.copy_file(source, source_dir)
320
+
321
+ if self.icon:
322
+ if os.path.exists(self.icon):
323
+ self.copy_file(self.icon, source_dir)
324
+ else:
325
+ raise DistutilsFileError(f"icon file '{self.icon}' does not exist")
326
+
327
+ # build package
328
+ log.info("building RPMs")
329
+ rpm_cmd = ['rpmbuild']
330
+
331
+ if self.source_only: # what kind of RPMs?
332
+ rpm_cmd.append('-bs')
333
+ elif self.binary_only:
334
+ rpm_cmd.append('-bb')
335
+ else:
336
+ rpm_cmd.append('-ba')
337
+ rpm_cmd.extend(['--define', f'__python {self.python}'])
338
+ if self.rpm3_mode:
339
+ rpm_cmd.extend(['--define', f'_topdir {os.path.abspath(self.rpm_base)}'])
340
+ if not self.keep_temp:
341
+ rpm_cmd.append('--clean')
342
+
343
+ if self.quiet:
344
+ rpm_cmd.append('--quiet')
345
+
346
+ rpm_cmd.append(spec_path)
347
+ # Determine the binary rpm names that should be built out of this spec
348
+ # file
349
+ # Note that some of these may not be really built (if the file
350
+ # list is empty)
351
+ nvr_string = "%{name}-%{version}-%{release}"
352
+ src_rpm = nvr_string + ".src.rpm"
353
+ non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
354
+ q_cmd = rf"rpm -q --qf '{src_rpm} {non_src_rpm}\n' --specfile '{spec_path}'"
355
+
356
+ out = os.popen(q_cmd)
357
+ try:
358
+ binary_rpms = []
359
+ source_rpm = None
360
+ while True:
361
+ line = out.readline()
362
+ if not line:
363
+ break
364
+ ell = line.strip().split()
365
+ assert len(ell) == 2
366
+ binary_rpms.append(ell[1])
367
+ # The source rpm is named after the first entry in the spec file
368
+ if source_rpm is None:
369
+ source_rpm = ell[0]
370
+
371
+ status = out.close()
372
+ if status:
373
+ raise DistutilsExecError(f"Failed to execute: {q_cmd!r}")
374
+
375
+ finally:
376
+ out.close()
377
+
378
+ self.spawn(rpm_cmd)
379
+
380
+ if not self.dry_run:
381
+ if self.distribution.has_ext_modules():
382
+ pyversion = get_python_version()
383
+ else:
384
+ pyversion = 'any'
385
+
386
+ if not self.binary_only:
387
+ srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
388
+ assert os.path.exists(srpm)
389
+ self.move_file(srpm, self.dist_dir)
390
+ filename = os.path.join(self.dist_dir, source_rpm)
391
+ self.distribution.dist_files.append(('bdist_rpm', pyversion, filename))
392
+
393
+ if not self.source_only:
394
+ for rpm in binary_rpms:
395
+ rpm = os.path.join(rpm_dir['RPMS'], rpm)
396
+ if os.path.exists(rpm):
397
+ self.move_file(rpm, self.dist_dir)
398
+ filename = os.path.join(self.dist_dir, os.path.basename(rpm))
399
+ self.distribution.dist_files.append((
400
+ 'bdist_rpm',
401
+ pyversion,
402
+ filename,
403
+ ))
404
+
405
+ def _dist_path(self, path):
406
+ return os.path.join(self.dist_dir, os.path.basename(path))
407
+
408
+ def _make_spec_file(self): # noqa: C901
409
+ """Generate the text of an RPM spec file and return it as a
410
+ list of strings (one per line).
411
+ """
412
+ # definitions and headers
413
+ spec_file = [
414
+ '%define name ' + self.distribution.get_name(),
415
+ '%define version ' + self.distribution.get_version().replace('-', '_'),
416
+ '%define unmangled_version ' + self.distribution.get_version(),
417
+ '%define release ' + self.release.replace('-', '_'),
418
+ '',
419
+ 'Summary: ' + (self.distribution.get_description() or "UNKNOWN"),
420
+ ]
421
+
422
+ # Workaround for #14443 which affects some RPM based systems such as
423
+ # RHEL6 (and probably derivatives)
424
+ vendor_hook = subprocess.getoutput('rpm --eval %{__os_install_post}')
425
+ # Generate a potential replacement value for __os_install_post (whilst
426
+ # normalizing the whitespace to simplify the test for whether the
427
+ # invocation of brp-python-bytecompile passes in __python):
428
+ vendor_hook = '\n'.join([
429
+ f' {line.strip()} \\' for line in vendor_hook.splitlines()
430
+ ])
431
+ problem = "brp-python-bytecompile \\\n"
432
+ fixed = "brp-python-bytecompile %{__python} \\\n"
433
+ fixed_hook = vendor_hook.replace(problem, fixed)
434
+ if fixed_hook != vendor_hook:
435
+ spec_file.append('# Workaround for https://bugs.python.org/issue14443')
436
+ spec_file.append('%define __os_install_post ' + fixed_hook + '\n')
437
+
438
+ # put locale summaries into spec file
439
+ # XXX not supported for now (hard to put a dictionary
440
+ # in a config file -- arg!)
441
+ # for locale in self.summaries.keys():
442
+ # spec_file.append('Summary(%s): %s' % (locale,
443
+ # self.summaries[locale]))
444
+
445
+ spec_file.extend([
446
+ 'Name: %{name}',
447
+ 'Version: %{version}',
448
+ 'Release: %{release}',
449
+ ])
450
+
451
+ # XXX yuck! this filename is available from the "sdist" command,
452
+ # but only after it has run: and we create the spec file before
453
+ # running "sdist", in case of --spec-only.
454
+ if self.use_bzip2:
455
+ spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2')
456
+ else:
457
+ spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')
458
+
459
+ spec_file.extend([
460
+ 'License: ' + (self.distribution.get_license() or "UNKNOWN"),
461
+ 'Group: ' + self.group,
462
+ 'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
463
+ 'Prefix: %{_prefix}',
464
+ ])
465
+
466
+ if not self.force_arch:
467
+ # noarch if no extension modules
468
+ if not self.distribution.has_ext_modules():
469
+ spec_file.append('BuildArch: noarch')
470
+ else:
471
+ spec_file.append(f'BuildArch: {self.force_arch}')
472
+
473
+ for field in (
474
+ 'Vendor',
475
+ 'Packager',
476
+ 'Provides',
477
+ 'Requires',
478
+ 'Conflicts',
479
+ 'Obsoletes',
480
+ ):
481
+ val = getattr(self, field.lower())
482
+ if isinstance(val, list):
483
+ spec_file.append('{}: {}'.format(field, ' '.join(val)))
484
+ elif val is not None:
485
+ spec_file.append(f'{field}: {val}')
486
+
487
+ if self.distribution.get_url():
488
+ spec_file.append('Url: ' + self.distribution.get_url())
489
+
490
+ if self.distribution_name:
491
+ spec_file.append('Distribution: ' + self.distribution_name)
492
+
493
+ if self.build_requires:
494
+ spec_file.append('BuildRequires: ' + ' '.join(self.build_requires))
495
+
496
+ if self.icon:
497
+ spec_file.append('Icon: ' + os.path.basename(self.icon))
498
+
499
+ if self.no_autoreq:
500
+ spec_file.append('AutoReq: 0')
501
+
502
+ spec_file.extend([
503
+ '',
504
+ '%description',
505
+ self.distribution.get_long_description() or "",
506
+ ])
507
+
508
+ # put locale descriptions into spec file
509
+ # XXX again, suppressed because config file syntax doesn't
510
+ # easily support this ;-(
511
+ # for locale in self.descriptions.keys():
512
+ # spec_file.extend([
513
+ # '',
514
+ # '%description -l ' + locale,
515
+ # self.descriptions[locale],
516
+ # ])
517
+
518
+ # rpm scripts
519
+ # figure out default build script
520
+ def_setup_call = f"{self.python} {os.path.basename(sys.argv[0])}"
521
+ def_build = f"{def_setup_call} build"
522
+ if self.use_rpm_opt_flags:
523
+ def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
524
+
525
+ # insert contents of files
526
+
527
+ # XXX this is kind of misleading: user-supplied options are files
528
+ # that we open and interpolate into the spec file, but the defaults
529
+ # are just text that we drop in as-is. Hmmm.
530
+
531
+ install_cmd = f'{def_setup_call} install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES'
532
+
533
+ script_options = [
534
+ ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"),
535
+ ('build', 'build_script', def_build),
536
+ ('install', 'install_script', install_cmd),
537
+ ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
538
+ ('verifyscript', 'verify_script', None),
539
+ ('pre', 'pre_install', None),
540
+ ('post', 'post_install', None),
541
+ ('preun', 'pre_uninstall', None),
542
+ ('postun', 'post_uninstall', None),
543
+ ]
544
+
545
+ for rpm_opt, attr, default in script_options:
546
+ # Insert contents of file referred to, if no file is referred to
547
+ # use 'default' as contents of script
548
+ val = getattr(self, attr)
549
+ if val or default:
550
+ spec_file.extend([
551
+ '',
552
+ '%' + rpm_opt,
553
+ ])
554
+ if val:
555
+ with open(val) as f:
556
+ spec_file.extend(f.read().split('\n'))
557
+ else:
558
+ spec_file.append(default)
559
+
560
+ # files section
561
+ spec_file.extend([
562
+ '',
563
+ '%files -f INSTALLED_FILES',
564
+ '%defattr(-,root,root)',
565
+ ])
566
+
567
+ if self.doc_files:
568
+ spec_file.append('%doc ' + ' '.join(self.doc_files))
569
+
570
+ if self.changelog:
571
+ spec_file.extend([
572
+ '',
573
+ '%changelog',
574
+ ])
575
+ spec_file.extend(self.changelog)
576
+
577
+ return spec_file
578
+
579
+ def _format_changelog(self, changelog):
580
+ """Format the changelog correctly and convert it to a list of strings"""
581
+ if not changelog:
582
+ return changelog
583
+ new_changelog = []
584
+ for line in changelog.strip().split('\n'):
585
+ line = line.strip()
586
+ if line[0] == '*':
587
+ new_changelog.extend(['', line])
588
+ elif line[0] == '-':
589
+ new_changelog.append(line)
590
+ else:
591
+ new_changelog.append(' ' + line)
592
+
593
+ # strip trailing newline inserted by first changelog entry
594
+ if not new_changelog[0]:
595
+ del new_changelog[0]
596
+
597
+ return new_changelog
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build
2
+
3
+ Implements the Distutils 'build' command."""
4
+
5
+ import os
6
+ import sys
7
+ import sysconfig
8
+
9
+ from ..core import Command
10
+ from ..errors import DistutilsOptionError
11
+ from ..util import get_platform
12
+
13
+
14
+ def show_compilers():
15
+ from ..ccompiler import show_compilers
16
+
17
+ show_compilers()
18
+
19
+
20
+ class build(Command):
21
+ description = "build everything needed to install"
22
+
23
+ user_options = [
24
+ ('build-base=', 'b', "base directory for build library"),
25
+ ('build-purelib=', None, "build directory for platform-neutral distributions"),
26
+ ('build-platlib=', None, "build directory for platform-specific distributions"),
27
+ (
28
+ 'build-lib=',
29
+ None,
30
+ "build directory for all distribution (defaults to either build-purelib or build-platlib",
31
+ ),
32
+ ('build-scripts=', None, "build directory for scripts"),
33
+ ('build-temp=', 't', "temporary build directory"),
34
+ (
35
+ 'plat-name=',
36
+ 'p',
37
+ f"platform name to build for, if supported [default: {get_platform()}]",
38
+ ),
39
+ ('compiler=', 'c', "specify the compiler type"),
40
+ ('parallel=', 'j', "number of parallel build jobs"),
41
+ ('debug', 'g', "compile extensions and libraries with debugging information"),
42
+ ('force', 'f', "forcibly build everything (ignore file timestamps)"),
43
+ ('executable=', 'e', "specify final destination interpreter path (build.py)"),
44
+ ]
45
+
46
+ boolean_options = ['debug', 'force']
47
+
48
+ help_options = [
49
+ ('help-compiler', None, "list available compilers", show_compilers),
50
+ ]
51
+
52
+ def initialize_options(self):
53
+ self.build_base = 'build'
54
+ # these are decided only after 'build_base' has its final value
55
+ # (unless overridden by the user or client)
56
+ self.build_purelib = None
57
+ self.build_platlib = None
58
+ self.build_lib = None
59
+ self.build_temp = None
60
+ self.build_scripts = None
61
+ self.compiler = None
62
+ self.plat_name = None
63
+ self.debug = None
64
+ self.force = False
65
+ self.executable = None
66
+ self.parallel = None
67
+
68
+ def finalize_options(self): # noqa: C901
69
+ if self.plat_name is None:
70
+ self.plat_name = get_platform()
71
+ else:
72
+ # plat-name only supported for windows (other platforms are
73
+ # supported via ./configure flags, if at all). Avoid misleading
74
+ # other platforms.
75
+ if os.name != 'nt':
76
+ raise DistutilsOptionError(
77
+ "--plat-name only supported on Windows (try "
78
+ "using './configure --help' on your platform)"
79
+ )
80
+
81
+ plat_specifier = f".{self.plat_name}-{sys.implementation.cache_tag}"
82
+
83
+ # Python 3.13+ with --disable-gil shouldn't share build directories
84
+ if sysconfig.get_config_var('Py_GIL_DISABLED'):
85
+ plat_specifier += 't'
86
+
87
+ # Make it so Python 2.x and Python 2.x with --with-pydebug don't
88
+ # share the same build directories. Doing so confuses the build
89
+ # process for C modules
90
+ if hasattr(sys, 'gettotalrefcount'):
91
+ plat_specifier += '-pydebug'
92
+
93
+ # 'build_purelib' and 'build_platlib' just default to 'lib' and
94
+ # 'lib.<plat>' under the base build directory. We only use one of
95
+ # them for a given distribution, though --
96
+ if self.build_purelib is None:
97
+ self.build_purelib = os.path.join(self.build_base, 'lib')
98
+ if self.build_platlib is None:
99
+ self.build_platlib = os.path.join(self.build_base, 'lib' + plat_specifier)
100
+
101
+ # 'build_lib' is the actual directory that we will use for this
102
+ # particular module distribution -- if user didn't supply it, pick
103
+ # one of 'build_purelib' or 'build_platlib'.
104
+ if self.build_lib is None:
105
+ if self.distribution.has_ext_modules():
106
+ self.build_lib = self.build_platlib
107
+ else:
108
+ self.build_lib = self.build_purelib
109
+
110
+ # 'build_temp' -- temporary directory for compiler turds,
111
+ # "build/temp.<plat>"
112
+ if self.build_temp is None:
113
+ self.build_temp = os.path.join(self.build_base, 'temp' + plat_specifier)
114
+ if self.build_scripts is None:
115
+ self.build_scripts = os.path.join(
116
+ self.build_base,
117
+ f'scripts-{sys.version_info.major}.{sys.version_info.minor}',
118
+ )
119
+
120
+ if self.executable is None and sys.executable:
121
+ self.executable = os.path.normpath(sys.executable)
122
+
123
+ if isinstance(self.parallel, str):
124
+ try:
125
+ self.parallel = int(self.parallel)
126
+ except ValueError:
127
+ raise DistutilsOptionError("parallel should be an integer")
128
+
129
+ def run(self):
130
+ # Run all relevant sub-commands. This will be some subset of:
131
+ # - build_py - pure Python modules
132
+ # - build_clib - standalone C libraries
133
+ # - build_ext - Python extensions
134
+ # - build_scripts - (Python) scripts
135
+ for cmd_name in self.get_sub_commands():
136
+ self.run_command(cmd_name)
137
+
138
+ # -- Predicates for the sub-command list ---------------------------
139
+
140
+ def has_pure_modules(self):
141
+ return self.distribution.has_pure_modules()
142
+
143
+ def has_c_libraries(self):
144
+ return self.distribution.has_c_libraries()
145
+
146
+ def has_ext_modules(self):
147
+ return self.distribution.has_ext_modules()
148
+
149
+ def has_scripts(self):
150
+ return self.distribution.has_scripts()
151
+
152
+ sub_commands = [
153
+ ('build_py', has_pure_modules),
154
+ ('build_clib', has_c_libraries),
155
+ ('build_ext', has_ext_modules),
156
+ ('build_scripts', has_scripts),
157
+ ]
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_clib.py ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_clib
2
+
3
+ Implements the Distutils 'build_clib' command, to build a C/C++ library
4
+ that is included in the module distribution and needed by an extension
5
+ module."""
6
+
7
+
8
+ # XXX this module has *lots* of code ripped-off quite transparently from
9
+ # build_ext.py -- not surprisingly really, as the work required to build
10
+ # a static library from a collection of C source files is not really all
11
+ # that different from what's required to build a shared object file from
12
+ # a collection of C source files. Nevertheless, I haven't done the
13
+ # necessary refactoring to account for the overlap in code between the
14
+ # two modules, mainly because a number of subtle details changed in the
15
+ # cut 'n paste. Sigh.
16
+
17
+ import os
18
+ from distutils._log import log
19
+ from typing import ClassVar
20
+
21
+ from ..core import Command
22
+ from ..errors import DistutilsSetupError
23
+ from ..sysconfig import customize_compiler
24
+
25
+
26
+ def show_compilers():
27
+ from ..ccompiler import show_compilers
28
+
29
+ show_compilers()
30
+
31
+
32
+ class build_clib(Command):
33
+ description = "build C/C++ libraries used by Python extensions"
34
+
35
+ user_options: ClassVar[list[tuple[str, str, str]]] = [
36
+ ('build-clib=', 'b', "directory to build C/C++ libraries to"),
37
+ ('build-temp=', 't', "directory to put temporary build by-products"),
38
+ ('debug', 'g', "compile with debugging information"),
39
+ ('force', 'f', "forcibly build everything (ignore file timestamps)"),
40
+ ('compiler=', 'c', "specify the compiler type"),
41
+ ]
42
+
43
+ boolean_options = ['debug', 'force']
44
+
45
+ help_options = [
46
+ ('help-compiler', None, "list available compilers", show_compilers),
47
+ ]
48
+
49
+ def initialize_options(self):
50
+ self.build_clib = None
51
+ self.build_temp = None
52
+
53
+ # List of libraries to build
54
+ self.libraries = None
55
+
56
+ # Compilation options for all libraries
57
+ self.include_dirs = None
58
+ self.define = None
59
+ self.undef = None
60
+ self.debug = None
61
+ self.force = False
62
+ self.compiler = None
63
+
64
+ def finalize_options(self):
65
+ # This might be confusing: both build-clib and build-temp default
66
+ # to build-temp as defined by the "build" command. This is because
67
+ # I think that C libraries are really just temporary build
68
+ # by-products, at least from the point of view of building Python
69
+ # extensions -- but I want to keep my options open.
70
+ self.set_undefined_options(
71
+ 'build',
72
+ ('build_temp', 'build_clib'),
73
+ ('build_temp', 'build_temp'),
74
+ ('compiler', 'compiler'),
75
+ ('debug', 'debug'),
76
+ ('force', 'force'),
77
+ )
78
+
79
+ self.libraries = self.distribution.libraries
80
+ if self.libraries:
81
+ self.check_library_list(self.libraries)
82
+
83
+ if self.include_dirs is None:
84
+ self.include_dirs = self.distribution.include_dirs or []
85
+ if isinstance(self.include_dirs, str):
86
+ self.include_dirs = self.include_dirs.split(os.pathsep)
87
+
88
+ # XXX same as for build_ext -- what about 'self.define' and
89
+ # 'self.undef' ?
90
+
91
+ def run(self):
92
+ if not self.libraries:
93
+ return
94
+
95
+ # Yech -- this is cut 'n pasted from build_ext.py!
96
+ from ..ccompiler import new_compiler
97
+
98
+ self.compiler = new_compiler(
99
+ compiler=self.compiler, dry_run=self.dry_run, force=self.force
100
+ )
101
+ customize_compiler(self.compiler)
102
+
103
+ if self.include_dirs is not None:
104
+ self.compiler.set_include_dirs(self.include_dirs)
105
+ if self.define is not None:
106
+ # 'define' option is a list of (name,value) tuples
107
+ for name, value in self.define:
108
+ self.compiler.define_macro(name, value)
109
+ if self.undef is not None:
110
+ for macro in self.undef:
111
+ self.compiler.undefine_macro(macro)
112
+
113
+ self.build_libraries(self.libraries)
114
+
115
+ def check_library_list(self, libraries):
116
+ """Ensure that the list of libraries is valid.
117
+
118
+ `library` is presumably provided as a command option 'libraries'.
119
+ This method checks that it is a list of 2-tuples, where the tuples
120
+ are (library_name, build_info_dict).
121
+
122
+ Raise DistutilsSetupError if the structure is invalid anywhere;
123
+ just returns otherwise.
124
+ """
125
+ if not isinstance(libraries, list):
126
+ raise DistutilsSetupError("'libraries' option must be a list of tuples")
127
+
128
+ for lib in libraries:
129
+ if not isinstance(lib, tuple) and len(lib) != 2:
130
+ raise DistutilsSetupError("each element of 'libraries' must a 2-tuple")
131
+
132
+ name, build_info = lib
133
+
134
+ if not isinstance(name, str):
135
+ raise DistutilsSetupError(
136
+ "first element of each tuple in 'libraries' "
137
+ "must be a string (the library name)"
138
+ )
139
+
140
+ if '/' in name or (os.sep != '/' and os.sep in name):
141
+ raise DistutilsSetupError(
142
+ f"bad library name '{lib[0]}': may not contain directory separators"
143
+ )
144
+
145
+ if not isinstance(build_info, dict):
146
+ raise DistutilsSetupError(
147
+ "second element of each tuple in 'libraries' "
148
+ "must be a dictionary (build info)"
149
+ )
150
+
151
+ def get_library_names(self):
152
+ # Assume the library list is valid -- 'check_library_list()' is
153
+ # called from 'finalize_options()', so it should be!
154
+ if not self.libraries:
155
+ return None
156
+
157
+ lib_names = []
158
+ for lib_name, _build_info in self.libraries:
159
+ lib_names.append(lib_name)
160
+ return lib_names
161
+
162
+ def get_source_files(self):
163
+ self.check_library_list(self.libraries)
164
+ filenames = []
165
+ for lib_name, build_info in self.libraries:
166
+ sources = build_info.get('sources')
167
+ if sources is None or not isinstance(sources, (list, tuple)):
168
+ raise DistutilsSetupError(
169
+ f"in 'libraries' option (library '{lib_name}'), "
170
+ "'sources' must be present and must be "
171
+ "a list of source filenames"
172
+ )
173
+
174
+ filenames.extend(sources)
175
+ return filenames
176
+
177
+ def build_libraries(self, libraries):
178
+ for lib_name, build_info in libraries:
179
+ sources = build_info.get('sources')
180
+ if sources is None or not isinstance(sources, (list, tuple)):
181
+ raise DistutilsSetupError(
182
+ f"in 'libraries' option (library '{lib_name}'), "
183
+ "'sources' must be present and must be "
184
+ "a list of source filenames"
185
+ )
186
+ sources = list(sources)
187
+
188
+ log.info("building '%s' library", lib_name)
189
+
190
+ # First, compile the source code to object files in the library
191
+ # directory. (This should probably change to putting object
192
+ # files in a temporary build directory.)
193
+ macros = build_info.get('macros')
194
+ include_dirs = build_info.get('include_dirs')
195
+ objects = self.compiler.compile(
196
+ sources,
197
+ output_dir=self.build_temp,
198
+ macros=macros,
199
+ include_dirs=include_dirs,
200
+ debug=self.debug,
201
+ )
202
+
203
+ # Now "link" the object files together into a static library.
204
+ # (On Unix at least, this isn't really linking -- it just
205
+ # builds an archive. Whatever.)
206
+ self.compiler.create_static_lib(
207
+ objects, lib_name, output_dir=self.build_clib, debug=self.debug
208
+ )
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py ADDED
@@ -0,0 +1,800 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_ext
2
+
3
+ Implements the Distutils 'build_ext' command, for building extension
4
+ modules (currently limited to C extensions, should accommodate C++
5
+ extensions ASAP)."""
6
+
7
+ import contextlib
8
+ import os
9
+ import re
10
+ import sys
11
+ from distutils._log import log
12
+ from site import USER_BASE
13
+
14
+ from .._modified import newer_group
15
+ from ..core import Command
16
+ from ..errors import (
17
+ CCompilerError,
18
+ CompileError,
19
+ DistutilsError,
20
+ DistutilsOptionError,
21
+ DistutilsPlatformError,
22
+ DistutilsSetupError,
23
+ )
24
+ from ..extension import Extension
25
+ from ..sysconfig import customize_compiler, get_config_h_filename, get_python_version
26
+ from ..util import get_platform, is_freethreaded, is_mingw
27
+
28
+ # An extension name is just a dot-separated list of Python NAMEs (ie.
29
+ # the same as a fully-qualified module name).
30
+ extension_name_re = re.compile(r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
31
+
32
+
33
+ def show_compilers():
34
+ from ..ccompiler import show_compilers
35
+
36
+ show_compilers()
37
+
38
+
39
+ class build_ext(Command):
40
+ description = "build C/C++ extensions (compile/link to build directory)"
41
+
42
+ # XXX thoughts on how to deal with complex command-line options like
43
+ # these, i.e. how to make it so fancy_getopt can suck them off the
44
+ # command line and make it look like setup.py defined the appropriate
45
+ # lists of tuples of what-have-you.
46
+ # - each command needs a callback to process its command-line options
47
+ # - Command.__init__() needs access to its share of the whole
48
+ # command line (must ultimately come from
49
+ # Distribution.parse_command_line())
50
+ # - it then calls the current command class' option-parsing
51
+ # callback to deal with weird options like -D, which have to
52
+ # parse the option text and churn out some custom data
53
+ # structure
54
+ # - that data structure (in this case, a list of 2-tuples)
55
+ # will then be present in the command object by the time
56
+ # we get to finalize_options() (i.e. the constructor
57
+ # takes care of both command-line and client options
58
+ # in between initialize_options() and finalize_options())
59
+
60
+ sep_by = f" (separated by '{os.pathsep}')"
61
+ user_options = [
62
+ ('build-lib=', 'b', "directory for compiled extension modules"),
63
+ ('build-temp=', 't', "directory for temporary files (build by-products)"),
64
+ (
65
+ 'plat-name=',
66
+ 'p',
67
+ "platform name to cross-compile for, if supported "
68
+ f"[default: {get_platform()}]",
69
+ ),
70
+ (
71
+ 'inplace',
72
+ 'i',
73
+ "ignore build-lib and put compiled extensions into the source "
74
+ "directory alongside your pure Python modules",
75
+ ),
76
+ (
77
+ 'include-dirs=',
78
+ 'I',
79
+ "list of directories to search for header files" + sep_by,
80
+ ),
81
+ ('define=', 'D', "C preprocessor macros to define"),
82
+ ('undef=', 'U', "C preprocessor macros to undefine"),
83
+ ('libraries=', 'l', "external C libraries to link with"),
84
+ (
85
+ 'library-dirs=',
86
+ 'L',
87
+ "directories to search for external C libraries" + sep_by,
88
+ ),
89
+ ('rpath=', 'R', "directories to search for shared C libraries at runtime"),
90
+ ('link-objects=', 'O', "extra explicit link objects to include in the link"),
91
+ ('debug', 'g', "compile/link with debugging information"),
92
+ ('force', 'f', "forcibly build everything (ignore file timestamps)"),
93
+ ('compiler=', 'c', "specify the compiler type"),
94
+ ('parallel=', 'j', "number of parallel build jobs"),
95
+ ('swig-cpp', None, "make SWIG create C++ files (default is C)"),
96
+ ('swig-opts=', None, "list of SWIG command line options"),
97
+ ('swig=', None, "path to the SWIG executable"),
98
+ ('user', None, "add user include, library and rpath"),
99
+ ]
100
+
101
+ boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user']
102
+
103
+ help_options = [
104
+ ('help-compiler', None, "list available compilers", show_compilers),
105
+ ]
106
+
107
+ def initialize_options(self):
108
+ self.extensions = None
109
+ self.build_lib = None
110
+ self.plat_name = None
111
+ self.build_temp = None
112
+ self.inplace = False
113
+ self.package = None
114
+
115
+ self.include_dirs = None
116
+ self.define = None
117
+ self.undef = None
118
+ self.libraries = None
119
+ self.library_dirs = None
120
+ self.rpath = None
121
+ self.link_objects = None
122
+ self.debug = None
123
+ self.force = None
124
+ self.compiler = None
125
+ self.swig = None
126
+ self.swig_cpp = None
127
+ self.swig_opts = None
128
+ self.user = None
129
+ self.parallel = None
130
+
131
+ @staticmethod
132
+ def _python_lib_dir(sysconfig):
133
+ """
134
+ Resolve Python's library directory for building extensions
135
+ that rely on a shared Python library.
136
+
137
+ See python/cpython#44264 and python/cpython#48686
138
+ """
139
+ if not sysconfig.get_config_var('Py_ENABLE_SHARED'):
140
+ return
141
+
142
+ if sysconfig.python_build:
143
+ yield '.'
144
+ return
145
+
146
+ if sys.platform == 'zos':
147
+ # On z/OS, a user is not required to install Python to
148
+ # a predetermined path, but can use Python portably
149
+ installed_dir = sysconfig.get_config_var('base')
150
+ lib_dir = sysconfig.get_config_var('platlibdir')
151
+ yield os.path.join(installed_dir, lib_dir)
152
+ else:
153
+ # building third party extensions
154
+ yield sysconfig.get_config_var('LIBDIR')
155
+
156
+ def finalize_options(self): # noqa: C901
157
+ from distutils import sysconfig
158
+
159
+ self.set_undefined_options(
160
+ 'build',
161
+ ('build_lib', 'build_lib'),
162
+ ('build_temp', 'build_temp'),
163
+ ('compiler', 'compiler'),
164
+ ('debug', 'debug'),
165
+ ('force', 'force'),
166
+ ('parallel', 'parallel'),
167
+ ('plat_name', 'plat_name'),
168
+ )
169
+
170
+ if self.package is None:
171
+ self.package = self.distribution.ext_package
172
+
173
+ self.extensions = self.distribution.ext_modules
174
+
175
+ # Make sure Python's include directories (for Python.h, pyconfig.h,
176
+ # etc.) are in the include search path.
177
+ py_include = sysconfig.get_python_inc()
178
+ plat_py_include = sysconfig.get_python_inc(plat_specific=True)
179
+ if self.include_dirs is None:
180
+ self.include_dirs = self.distribution.include_dirs or []
181
+ if isinstance(self.include_dirs, str):
182
+ self.include_dirs = self.include_dirs.split(os.pathsep)
183
+
184
+ # If in a virtualenv, add its include directory
185
+ # Issue 16116
186
+ if sys.exec_prefix != sys.base_exec_prefix:
187
+ self.include_dirs.append(os.path.join(sys.exec_prefix, 'include'))
188
+
189
+ # Put the Python "system" include dir at the end, so that
190
+ # any local include dirs take precedence.
191
+ self.include_dirs.extend(py_include.split(os.path.pathsep))
192
+ if plat_py_include != py_include:
193
+ self.include_dirs.extend(plat_py_include.split(os.path.pathsep))
194
+
195
+ self.ensure_string_list('libraries')
196
+ self.ensure_string_list('link_objects')
197
+
198
+ # Life is easier if we're not forever checking for None, so
199
+ # simplify these options to empty lists if unset
200
+ if self.libraries is None:
201
+ self.libraries = []
202
+ if self.library_dirs is None:
203
+ self.library_dirs = []
204
+ elif isinstance(self.library_dirs, str):
205
+ self.library_dirs = self.library_dirs.split(os.pathsep)
206
+
207
+ if self.rpath is None:
208
+ self.rpath = []
209
+ elif isinstance(self.rpath, str):
210
+ self.rpath = self.rpath.split(os.pathsep)
211
+
212
+ # for extensions under windows use different directories
213
+ # for Release and Debug builds.
214
+ # also Python's library directory must be appended to library_dirs
215
+ if os.name == 'nt' and not is_mingw():
216
+ # the 'libs' directory is for binary installs - we assume that
217
+ # must be the *native* platform. But we don't really support
218
+ # cross-compiling via a binary install anyway, so we let it go.
219
+ self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
220
+ if sys.base_exec_prefix != sys.prefix: # Issue 16116
221
+ self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
222
+ if self.debug:
223
+ self.build_temp = os.path.join(self.build_temp, "Debug")
224
+ else:
225
+ self.build_temp = os.path.join(self.build_temp, "Release")
226
+
227
+ # Append the source distribution include and library directories,
228
+ # this allows distutils on windows to work in the source tree
229
+ self.include_dirs.append(os.path.dirname(get_config_h_filename()))
230
+ self.library_dirs.append(sys.base_exec_prefix)
231
+
232
+ # Use the .lib files for the correct architecture
233
+ if self.plat_name == 'win32':
234
+ suffix = 'win32'
235
+ else:
236
+ # win-amd64
237
+ suffix = self.plat_name[4:]
238
+ new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
239
+ if suffix:
240
+ new_lib = os.path.join(new_lib, suffix)
241
+ self.library_dirs.append(new_lib)
242
+
243
+ # For extensions under Cygwin, Python's library directory must be
244
+ # appended to library_dirs
245
+ if sys.platform[:6] == 'cygwin':
246
+ if not sysconfig.python_build:
247
+ # building third party extensions
248
+ self.library_dirs.append(
249
+ os.path.join(
250
+ sys.prefix, "lib", "python" + get_python_version(), "config"
251
+ )
252
+ )
253
+ else:
254
+ # building python standard extensions
255
+ self.library_dirs.append('.')
256
+
257
+ self.library_dirs.extend(self._python_lib_dir(sysconfig))
258
+
259
+ # The argument parsing will result in self.define being a string, but
260
+ # it has to be a list of 2-tuples. All the preprocessor symbols
261
+ # specified by the 'define' option will be set to '1'. Multiple
262
+ # symbols can be separated with commas.
263
+
264
+ if self.define:
265
+ defines = self.define.split(',')
266
+ self.define = [(symbol, '1') for symbol in defines]
267
+
268
+ # The option for macros to undefine is also a string from the
269
+ # option parsing, but has to be a list. Multiple symbols can also
270
+ # be separated with commas here.
271
+ if self.undef:
272
+ self.undef = self.undef.split(',')
273
+
274
+ if self.swig_opts is None:
275
+ self.swig_opts = []
276
+ else:
277
+ self.swig_opts = self.swig_opts.split(' ')
278
+
279
+ # Finally add the user include and library directories if requested
280
+ if self.user:
281
+ user_include = os.path.join(USER_BASE, "include")
282
+ user_lib = os.path.join(USER_BASE, "lib")
283
+ if os.path.isdir(user_include):
284
+ self.include_dirs.append(user_include)
285
+ if os.path.isdir(user_lib):
286
+ self.library_dirs.append(user_lib)
287
+ self.rpath.append(user_lib)
288
+
289
+ if isinstance(self.parallel, str):
290
+ try:
291
+ self.parallel = int(self.parallel)
292
+ except ValueError:
293
+ raise DistutilsOptionError("parallel should be an integer")
294
+
295
+ def run(self): # noqa: C901
296
+ from ..ccompiler import new_compiler
297
+
298
+ # 'self.extensions', as supplied by setup.py, is a list of
299
+ # Extension instances. See the documentation for Extension (in
300
+ # distutils.extension) for details.
301
+ #
302
+ # For backwards compatibility with Distutils 0.8.2 and earlier, we
303
+ # also allow the 'extensions' list to be a list of tuples:
304
+ # (ext_name, build_info)
305
+ # where build_info is a dictionary containing everything that
306
+ # Extension instances do except the name, with a few things being
307
+ # differently named. We convert these 2-tuples to Extension
308
+ # instances as needed.
309
+
310
+ if not self.extensions:
311
+ return
312
+
313
+ # If we were asked to build any C/C++ libraries, make sure that the
314
+ # directory where we put them is in the library search path for
315
+ # linking extensions.
316
+ if self.distribution.has_c_libraries():
317
+ build_clib = self.get_finalized_command('build_clib')
318
+ self.libraries.extend(build_clib.get_library_names() or [])
319
+ self.library_dirs.append(build_clib.build_clib)
320
+
321
+ # Setup the CCompiler object that we'll use to do all the
322
+ # compiling and linking
323
+ self.compiler = new_compiler(
324
+ compiler=self.compiler,
325
+ verbose=self.verbose,
326
+ dry_run=self.dry_run,
327
+ force=self.force,
328
+ )
329
+ customize_compiler(self.compiler)
330
+ # If we are cross-compiling, init the compiler now (if we are not
331
+ # cross-compiling, init would not hurt, but people may rely on
332
+ # late initialization of compiler even if they shouldn't...)
333
+ if os.name == 'nt' and self.plat_name != get_platform():
334
+ self.compiler.initialize(self.plat_name)
335
+
336
+ # The official Windows free threaded Python installer doesn't set
337
+ # Py_GIL_DISABLED because its pyconfig.h is shared with the
338
+ # default build, so define it here (pypa/setuptools#4662).
339
+ if os.name == 'nt' and is_freethreaded():
340
+ self.compiler.define_macro('Py_GIL_DISABLED', '1')
341
+
342
+ # And make sure that any compile/link-related options (which might
343
+ # come from the command-line or from the setup script) are set in
344
+ # that CCompiler object -- that way, they automatically apply to
345
+ # all compiling and linking done here.
346
+ if self.include_dirs is not None:
347
+ self.compiler.set_include_dirs(self.include_dirs)
348
+ if self.define is not None:
349
+ # 'define' option is a list of (name,value) tuples
350
+ for name, value in self.define:
351
+ self.compiler.define_macro(name, value)
352
+ if self.undef is not None:
353
+ for macro in self.undef:
354
+ self.compiler.undefine_macro(macro)
355
+ if self.libraries is not None:
356
+ self.compiler.set_libraries(self.libraries)
357
+ if self.library_dirs is not None:
358
+ self.compiler.set_library_dirs(self.library_dirs)
359
+ if self.rpath is not None:
360
+ self.compiler.set_runtime_library_dirs(self.rpath)
361
+ if self.link_objects is not None:
362
+ self.compiler.set_link_objects(self.link_objects)
363
+
364
+ # Now actually compile and link everything.
365
+ self.build_extensions()
366
+
367
+ def check_extensions_list(self, extensions): # noqa: C901
368
+ """Ensure that the list of extensions (presumably provided as a
369
+ command option 'extensions') is valid, i.e. it is a list of
370
+ Extension objects. We also support the old-style list of 2-tuples,
371
+ where the tuples are (ext_name, build_info), which are converted to
372
+ Extension instances here.
373
+
374
+ Raise DistutilsSetupError if the structure is invalid anywhere;
375
+ just returns otherwise.
376
+ """
377
+ if not isinstance(extensions, list):
378
+ raise DistutilsSetupError(
379
+ "'ext_modules' option must be a list of Extension instances"
380
+ )
381
+
382
+ for i, ext in enumerate(extensions):
383
+ if isinstance(ext, Extension):
384
+ continue # OK! (assume type-checking done
385
+ # by Extension constructor)
386
+
387
+ if not isinstance(ext, tuple) or len(ext) != 2:
388
+ raise DistutilsSetupError(
389
+ "each element of 'ext_modules' option must be an "
390
+ "Extension instance or 2-tuple"
391
+ )
392
+
393
+ ext_name, build_info = ext
394
+
395
+ log.warning(
396
+ "old-style (ext_name, build_info) tuple found in "
397
+ "ext_modules for extension '%s' "
398
+ "-- please convert to Extension instance",
399
+ ext_name,
400
+ )
401
+
402
+ if not (isinstance(ext_name, str) and extension_name_re.match(ext_name)):
403
+ raise DistutilsSetupError(
404
+ "first element of each tuple in 'ext_modules' "
405
+ "must be the extension name (a string)"
406
+ )
407
+
408
+ if not isinstance(build_info, dict):
409
+ raise DistutilsSetupError(
410
+ "second element of each tuple in 'ext_modules' "
411
+ "must be a dictionary (build info)"
412
+ )
413
+
414
+ # OK, the (ext_name, build_info) dict is type-safe: convert it
415
+ # to an Extension instance.
416
+ ext = Extension(ext_name, build_info['sources'])
417
+
418
+ # Easy stuff: one-to-one mapping from dict elements to
419
+ # instance attributes.
420
+ for key in (
421
+ 'include_dirs',
422
+ 'library_dirs',
423
+ 'libraries',
424
+ 'extra_objects',
425
+ 'extra_compile_args',
426
+ 'extra_link_args',
427
+ ):
428
+ val = build_info.get(key)
429
+ if val is not None:
430
+ setattr(ext, key, val)
431
+
432
+ # Medium-easy stuff: same syntax/semantics, different names.
433
+ ext.runtime_library_dirs = build_info.get('rpath')
434
+ if 'def_file' in build_info:
435
+ log.warning("'def_file' element of build info dict no longer supported")
436
+
437
+ # Non-trivial stuff: 'macros' split into 'define_macros'
438
+ # and 'undef_macros'.
439
+ macros = build_info.get('macros')
440
+ if macros:
441
+ ext.define_macros = []
442
+ ext.undef_macros = []
443
+ for macro in macros:
444
+ if not (isinstance(macro, tuple) and len(macro) in (1, 2)):
445
+ raise DistutilsSetupError(
446
+ "'macros' element of build info dict must be 1- or 2-tuple"
447
+ )
448
+ if len(macro) == 1:
449
+ ext.undef_macros.append(macro[0])
450
+ elif len(macro) == 2:
451
+ ext.define_macros.append(macro)
452
+
453
+ extensions[i] = ext
454
+
455
+ def get_source_files(self):
456
+ self.check_extensions_list(self.extensions)
457
+ filenames = []
458
+
459
+ # Wouldn't it be neat if we knew the names of header files too...
460
+ for ext in self.extensions:
461
+ filenames.extend(ext.sources)
462
+ return filenames
463
+
464
+ def get_outputs(self):
465
+ # Sanity check the 'extensions' list -- can't assume this is being
466
+ # done in the same run as a 'build_extensions()' call (in fact, we
467
+ # can probably assume that it *isn't*!).
468
+ self.check_extensions_list(self.extensions)
469
+
470
+ # And build the list of output (built) filenames. Note that this
471
+ # ignores the 'inplace' flag, and assumes everything goes in the
472
+ # "build" tree.
473
+ return [self.get_ext_fullpath(ext.name) for ext in self.extensions]
474
+
475
+ def build_extensions(self):
476
+ # First, sanity-check the 'extensions' list
477
+ self.check_extensions_list(self.extensions)
478
+ if self.parallel:
479
+ self._build_extensions_parallel()
480
+ else:
481
+ self._build_extensions_serial()
482
+
483
+ def _build_extensions_parallel(self):
484
+ workers = self.parallel
485
+ if self.parallel is True:
486
+ workers = os.cpu_count() # may return None
487
+ try:
488
+ from concurrent.futures import ThreadPoolExecutor
489
+ except ImportError:
490
+ workers = None
491
+
492
+ if workers is None:
493
+ self._build_extensions_serial()
494
+ return
495
+
496
+ with ThreadPoolExecutor(max_workers=workers) as executor:
497
+ futures = [
498
+ executor.submit(self.build_extension, ext) for ext in self.extensions
499
+ ]
500
+ for ext, fut in zip(self.extensions, futures):
501
+ with self._filter_build_errors(ext):
502
+ fut.result()
503
+
504
+ def _build_extensions_serial(self):
505
+ for ext in self.extensions:
506
+ with self._filter_build_errors(ext):
507
+ self.build_extension(ext)
508
+
509
+ @contextlib.contextmanager
510
+ def _filter_build_errors(self, ext):
511
+ try:
512
+ yield
513
+ except (CCompilerError, DistutilsError, CompileError) as e:
514
+ if not ext.optional:
515
+ raise
516
+ self.warn(f'building extension "{ext.name}" failed: {e}')
517
+
518
+ def build_extension(self, ext):
519
+ sources = ext.sources
520
+ if sources is None or not isinstance(sources, (list, tuple)):
521
+ raise DistutilsSetupError(
522
+ f"in 'ext_modules' option (extension '{ext.name}'), "
523
+ "'sources' must be present and must be "
524
+ "a list of source filenames"
525
+ )
526
+ # sort to make the resulting .so file build reproducible
527
+ sources = sorted(sources)
528
+
529
+ ext_path = self.get_ext_fullpath(ext.name)
530
+ depends = sources + ext.depends
531
+ if not (self.force or newer_group(depends, ext_path, 'newer')):
532
+ log.debug("skipping '%s' extension (up-to-date)", ext.name)
533
+ return
534
+ else:
535
+ log.info("building '%s' extension", ext.name)
536
+
537
+ # First, scan the sources for SWIG definition files (.i), run
538
+ # SWIG on 'em to create .c files, and modify the sources list
539
+ # accordingly.
540
+ sources = self.swig_sources(sources, ext)
541
+
542
+ # Next, compile the source code to object files.
543
+
544
+ # XXX not honouring 'define_macros' or 'undef_macros' -- the
545
+ # CCompiler API needs to change to accommodate this, and I
546
+ # want to do one thing at a time!
547
+
548
+ # Two possible sources for extra compiler arguments:
549
+ # - 'extra_compile_args' in Extension object
550
+ # - CFLAGS environment variable (not particularly
551
+ # elegant, but people seem to expect it and I
552
+ # guess it's useful)
553
+ # The environment variable should take precedence, and
554
+ # any sensible compiler will give precedence to later
555
+ # command line args. Hence we combine them in order:
556
+ extra_args = ext.extra_compile_args or []
557
+
558
+ macros = ext.define_macros[:]
559
+ for undef in ext.undef_macros:
560
+ macros.append((undef,))
561
+
562
+ objects = self.compiler.compile(
563
+ sources,
564
+ output_dir=self.build_temp,
565
+ macros=macros,
566
+ include_dirs=ext.include_dirs,
567
+ debug=self.debug,
568
+ extra_postargs=extra_args,
569
+ depends=ext.depends,
570
+ )
571
+
572
+ # XXX outdated variable, kept here in case third-part code
573
+ # needs it.
574
+ self._built_objects = objects[:]
575
+
576
+ # Now link the object files together into a "shared object" --
577
+ # of course, first we have to figure out all the other things
578
+ # that go into the mix.
579
+ if ext.extra_objects:
580
+ objects.extend(ext.extra_objects)
581
+ extra_args = ext.extra_link_args or []
582
+
583
+ # Detect target language, if not provided
584
+ language = ext.language or self.compiler.detect_language(sources)
585
+
586
+ self.compiler.link_shared_object(
587
+ objects,
588
+ ext_path,
589
+ libraries=self.get_libraries(ext),
590
+ library_dirs=ext.library_dirs,
591
+ runtime_library_dirs=ext.runtime_library_dirs,
592
+ extra_postargs=extra_args,
593
+ export_symbols=self.get_export_symbols(ext),
594
+ debug=self.debug,
595
+ build_temp=self.build_temp,
596
+ target_lang=language,
597
+ )
598
+
599
+ def swig_sources(self, sources, extension):
600
+ """Walk the list of source files in 'sources', looking for SWIG
601
+ interface (.i) files. Run SWIG on all that are found, and
602
+ return a modified 'sources' list with SWIG source files replaced
603
+ by the generated C (or C++) files.
604
+ """
605
+ new_sources = []
606
+ swig_sources = []
607
+ swig_targets = {}
608
+
609
+ # XXX this drops generated C/C++ files into the source tree, which
610
+ # is fine for developers who want to distribute the generated
611
+ # source -- but there should be an option to put SWIG output in
612
+ # the temp dir.
613
+
614
+ if self.swig_cpp:
615
+ log.warning("--swig-cpp is deprecated - use --swig-opts=-c++")
616
+
617
+ if (
618
+ self.swig_cpp
619
+ or ('-c++' in self.swig_opts)
620
+ or ('-c++' in extension.swig_opts)
621
+ ):
622
+ target_ext = '.cpp'
623
+ else:
624
+ target_ext = '.c'
625
+
626
+ for source in sources:
627
+ (base, ext) = os.path.splitext(source)
628
+ if ext == ".i": # SWIG interface file
629
+ new_sources.append(base + '_wrap' + target_ext)
630
+ swig_sources.append(source)
631
+ swig_targets[source] = new_sources[-1]
632
+ else:
633
+ new_sources.append(source)
634
+
635
+ if not swig_sources:
636
+ return new_sources
637
+
638
+ swig = self.swig or self.find_swig()
639
+ swig_cmd = [swig, "-python"]
640
+ swig_cmd.extend(self.swig_opts)
641
+ if self.swig_cpp:
642
+ swig_cmd.append("-c++")
643
+
644
+ # Do not override commandline arguments
645
+ if not self.swig_opts:
646
+ swig_cmd.extend(extension.swig_opts)
647
+
648
+ for source in swig_sources:
649
+ target = swig_targets[source]
650
+ log.info("swigging %s to %s", source, target)
651
+ self.spawn(swig_cmd + ["-o", target, source])
652
+
653
+ return new_sources
654
+
655
+ def find_swig(self):
656
+ """Return the name of the SWIG executable. On Unix, this is
657
+ just "swig" -- it should be in the PATH. Tries a bit harder on
658
+ Windows.
659
+ """
660
+ if os.name == "posix":
661
+ return "swig"
662
+ elif os.name == "nt":
663
+ # Look for SWIG in its standard installation directory on
664
+ # Windows (or so I presume!). If we find it there, great;
665
+ # if not, act like Unix and assume it's in the PATH.
666
+ for vers in ("1.3", "1.2", "1.1"):
667
+ fn = os.path.join(f"c:\\swig{vers}", "swig.exe")
668
+ if os.path.isfile(fn):
669
+ return fn
670
+ else:
671
+ return "swig.exe"
672
+ else:
673
+ raise DistutilsPlatformError(
674
+ f"I don't know how to find (much less run) SWIG on platform '{os.name}'"
675
+ )
676
+
677
+ # -- Name generators -----------------------------------------------
678
+ # (extension names, filenames, whatever)
679
+ def get_ext_fullpath(self, ext_name):
680
+ """Returns the path of the filename for a given extension.
681
+
682
+ The file is located in `build_lib` or directly in the package
683
+ (inplace option).
684
+ """
685
+ fullname = self.get_ext_fullname(ext_name)
686
+ modpath = fullname.split('.')
687
+ filename = self.get_ext_filename(modpath[-1])
688
+
689
+ if not self.inplace:
690
+ # no further work needed
691
+ # returning :
692
+ # build_dir/package/path/filename
693
+ filename = os.path.join(*modpath[:-1] + [filename])
694
+ return os.path.join(self.build_lib, filename)
695
+
696
+ # the inplace option requires to find the package directory
697
+ # using the build_py command for that
698
+ package = '.'.join(modpath[0:-1])
699
+ build_py = self.get_finalized_command('build_py')
700
+ package_dir = os.path.abspath(build_py.get_package_dir(package))
701
+
702
+ # returning
703
+ # package_dir/filename
704
+ return os.path.join(package_dir, filename)
705
+
706
+ def get_ext_fullname(self, ext_name):
707
+ """Returns the fullname of a given extension name.
708
+
709
+ Adds the `package.` prefix"""
710
+ if self.package is None:
711
+ return ext_name
712
+ else:
713
+ return self.package + '.' + ext_name
714
+
715
+ def get_ext_filename(self, ext_name):
716
+ r"""Convert the name of an extension (eg. "foo.bar") into the name
717
+ of the file from which it will be loaded (eg. "foo/bar.so", or
718
+ "foo\bar.pyd").
719
+ """
720
+ from ..sysconfig import get_config_var
721
+
722
+ ext_path = ext_name.split('.')
723
+ ext_suffix = get_config_var('EXT_SUFFIX')
724
+ return os.path.join(*ext_path) + ext_suffix
725
+
726
+ def get_export_symbols(self, ext):
727
+ """Return the list of symbols that a shared extension has to
728
+ export. This either uses 'ext.export_symbols' or, if it's not
729
+ provided, "PyInit_" + module_name. Only relevant on Windows, where
730
+ the .pyd file (DLL) must export the module "PyInit_" function.
731
+ """
732
+ name = ext.name.split('.')[-1]
733
+ try:
734
+ # Unicode module name support as defined in PEP-489
735
+ # https://peps.python.org/pep-0489/#export-hook-name
736
+ name.encode('ascii')
737
+ except UnicodeEncodeError:
738
+ suffix = 'U_' + name.encode('punycode').replace(b'-', b'_').decode('ascii')
739
+ else:
740
+ suffix = "_" + name
741
+
742
+ initfunc_name = "PyInit" + suffix
743
+ if initfunc_name not in ext.export_symbols:
744
+ ext.export_symbols.append(initfunc_name)
745
+ return ext.export_symbols
746
+
747
+ def get_libraries(self, ext): # noqa: C901
748
+ """Return the list of libraries to link against when building a
749
+ shared extension. On most platforms, this is just 'ext.libraries';
750
+ on Windows, we add the Python library (eg. python20.dll).
751
+ """
752
+ # The python library is always needed on Windows. For MSVC, this
753
+ # is redundant, since the library is mentioned in a pragma in
754
+ # pyconfig.h that MSVC groks. The other Windows compilers all seem
755
+ # to need it mentioned explicitly, though, so that's what we do.
756
+ # Append '_d' to the python import library on debug builds.
757
+ if sys.platform == "win32" and not is_mingw():
758
+ from .._msvccompiler import MSVCCompiler
759
+
760
+ if not isinstance(self.compiler, MSVCCompiler):
761
+ template = "python%d%d"
762
+ if self.debug:
763
+ template = template + '_d'
764
+ pythonlib = template % (
765
+ sys.hexversion >> 24,
766
+ (sys.hexversion >> 16) & 0xFF,
767
+ )
768
+ # don't extend ext.libraries, it may be shared with other
769
+ # extensions, it is a reference to the original list
770
+ return ext.libraries + [pythonlib]
771
+ else:
772
+ # On Android only the main executable and LD_PRELOADs are considered
773
+ # to be RTLD_GLOBAL, all the dependencies of the main executable
774
+ # remain RTLD_LOCAL and so the shared libraries must be linked with
775
+ # libpython when python is built with a shared python library (issue
776
+ # bpo-21536).
777
+ # On Cygwin (and if required, other POSIX-like platforms based on
778
+ # Windows like MinGW) it is simply necessary that all symbols in
779
+ # shared libraries are resolved at link time.
780
+ from ..sysconfig import get_config_var
781
+
782
+ link_libpython = False
783
+ if get_config_var('Py_ENABLE_SHARED'):
784
+ # A native build on an Android device or on Cygwin
785
+ if hasattr(sys, 'getandroidapilevel'):
786
+ link_libpython = True
787
+ elif sys.platform == 'cygwin' or is_mingw():
788
+ link_libpython = True
789
+ elif '_PYTHON_HOST_PLATFORM' in os.environ:
790
+ # We are cross-compiling for one of the relevant platforms
791
+ if get_config_var('ANDROID_API_LEVEL') != 0:
792
+ link_libpython = True
793
+ elif get_config_var('MACHDEP') == 'cygwin':
794
+ link_libpython = True
795
+
796
+ if link_libpython:
797
+ ldversion = get_config_var('LDVERSION')
798
+ return ext.libraries + ['python' + ldversion]
799
+
800
+ return ext.libraries
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.py ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_py
2
+
3
+ Implements the Distutils 'build_py' command."""
4
+
5
+ import glob
6
+ import importlib.util
7
+ import os
8
+ import sys
9
+ from distutils._log import log
10
+
11
+ from ..core import Command
12
+ from ..errors import DistutilsFileError, DistutilsOptionError
13
+ from ..util import convert_path
14
+
15
+
16
+ class build_py(Command):
17
+ description = "\"build\" pure Python modules (copy to build directory)"
18
+
19
+ user_options = [
20
+ ('build-lib=', 'd', "directory to \"build\" (copy) to"),
21
+ ('compile', 'c', "compile .py to .pyc"),
22
+ ('no-compile', None, "don't compile .py files [default]"),
23
+ (
24
+ 'optimize=',
25
+ 'O',
26
+ "also compile with optimization: -O1 for \"python -O\", "
27
+ "-O2 for \"python -OO\", and -O0 to disable [default: -O0]",
28
+ ),
29
+ ('force', 'f', "forcibly build everything (ignore file timestamps)"),
30
+ ]
31
+
32
+ boolean_options = ['compile', 'force']
33
+ negative_opt = {'no-compile': 'compile'}
34
+
35
+ def initialize_options(self):
36
+ self.build_lib = None
37
+ self.py_modules = None
38
+ self.package = None
39
+ self.package_data = None
40
+ self.package_dir = None
41
+ self.compile = False
42
+ self.optimize = 0
43
+ self.force = None
44
+
45
+ def finalize_options(self):
46
+ self.set_undefined_options(
47
+ 'build', ('build_lib', 'build_lib'), ('force', 'force')
48
+ )
49
+
50
+ # Get the distribution options that are aliases for build_py
51
+ # options -- list of packages and list of modules.
52
+ self.packages = self.distribution.packages
53
+ self.py_modules = self.distribution.py_modules
54
+ self.package_data = self.distribution.package_data
55
+ self.package_dir = {}
56
+ if self.distribution.package_dir:
57
+ for name, path in self.distribution.package_dir.items():
58
+ self.package_dir[name] = convert_path(path)
59
+ self.data_files = self.get_data_files()
60
+
61
+ # Ick, copied straight from install_lib.py (fancy_getopt needs a
62
+ # type system! Hell, *everything* needs a type system!!!)
63
+ if not isinstance(self.optimize, int):
64
+ try:
65
+ self.optimize = int(self.optimize)
66
+ assert 0 <= self.optimize <= 2
67
+ except (ValueError, AssertionError):
68
+ raise DistutilsOptionError("optimize must be 0, 1, or 2")
69
+
70
+ def run(self):
71
+ # XXX copy_file by default preserves atime and mtime. IMHO this is
72
+ # the right thing to do, but perhaps it should be an option -- in
73
+ # particular, a site administrator might want installed files to
74
+ # reflect the time of installation rather than the last
75
+ # modification time before the installed release.
76
+
77
+ # XXX copy_file by default preserves mode, which appears to be the
78
+ # wrong thing to do: if a file is read-only in the working
79
+ # directory, we want it to be installed read/write so that the next
80
+ # installation of the same module distribution can overwrite it
81
+ # without problems. (This might be a Unix-specific issue.) Thus
82
+ # we turn off 'preserve_mode' when copying to the build directory,
83
+ # since the build directory is supposed to be exactly what the
84
+ # installation will look like (ie. we preserve mode when
85
+ # installing).
86
+
87
+ # Two options control which modules will be installed: 'packages'
88
+ # and 'py_modules'. The former lets us work with whole packages, not
89
+ # specifying individual modules at all; the latter is for
90
+ # specifying modules one-at-a-time.
91
+
92
+ if self.py_modules:
93
+ self.build_modules()
94
+ if self.packages:
95
+ self.build_packages()
96
+ self.build_package_data()
97
+
98
+ self.byte_compile(self.get_outputs(include_bytecode=False))
99
+
100
+ def get_data_files(self):
101
+ """Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
102
+ data = []
103
+ if not self.packages:
104
+ return data
105
+ for package in self.packages:
106
+ # Locate package source directory
107
+ src_dir = self.get_package_dir(package)
108
+
109
+ # Compute package build directory
110
+ build_dir = os.path.join(*([self.build_lib] + package.split('.')))
111
+
112
+ # Length of path to strip from found files
113
+ plen = 0
114
+ if src_dir:
115
+ plen = len(src_dir) + 1
116
+
117
+ # Strip directory from globbed filenames
118
+ filenames = [file[plen:] for file in self.find_data_files(package, src_dir)]
119
+ data.append((package, src_dir, build_dir, filenames))
120
+ return data
121
+
122
+ def find_data_files(self, package, src_dir):
123
+ """Return filenames for package's data files in 'src_dir'"""
124
+ globs = self.package_data.get('', []) + self.package_data.get(package, [])
125
+ files = []
126
+ for pattern in globs:
127
+ # Each pattern has to be converted to a platform-specific path
128
+ filelist = glob.glob(
129
+ os.path.join(glob.escape(src_dir), convert_path(pattern))
130
+ )
131
+ # Files that match more than one pattern are only added once
132
+ files.extend([
133
+ fn for fn in filelist if fn not in files and os.path.isfile(fn)
134
+ ])
135
+ return files
136
+
137
+ def build_package_data(self):
138
+ """Copy data files into build directory"""
139
+ for _package, src_dir, build_dir, filenames in self.data_files:
140
+ for filename in filenames:
141
+ target = os.path.join(build_dir, filename)
142
+ self.mkpath(os.path.dirname(target))
143
+ self.copy_file(
144
+ os.path.join(src_dir, filename), target, preserve_mode=False
145
+ )
146
+
147
+ def get_package_dir(self, package):
148
+ """Return the directory, relative to the top of the source
149
+ distribution, where package 'package' should be found
150
+ (at least according to the 'package_dir' option, if any)."""
151
+ path = package.split('.')
152
+
153
+ if not self.package_dir:
154
+ if path:
155
+ return os.path.join(*path)
156
+ else:
157
+ return ''
158
+ else:
159
+ tail = []
160
+ while path:
161
+ try:
162
+ pdir = self.package_dir['.'.join(path)]
163
+ except KeyError:
164
+ tail.insert(0, path[-1])
165
+ del path[-1]
166
+ else:
167
+ tail.insert(0, pdir)
168
+ return os.path.join(*tail)
169
+ else:
170
+ # Oops, got all the way through 'path' without finding a
171
+ # match in package_dir. If package_dir defines a directory
172
+ # for the root (nameless) package, then fallback on it;
173
+ # otherwise, we might as well have not consulted
174
+ # package_dir at all, as we just use the directory implied
175
+ # by 'tail' (which should be the same as the original value
176
+ # of 'path' at this point).
177
+ pdir = self.package_dir.get('')
178
+ if pdir is not None:
179
+ tail.insert(0, pdir)
180
+
181
+ if tail:
182
+ return os.path.join(*tail)
183
+ else:
184
+ return ''
185
+
186
+ def check_package(self, package, package_dir):
187
+ # Empty dir name means current directory, which we can probably
188
+ # assume exists. Also, os.path.exists and isdir don't know about
189
+ # my "empty string means current dir" convention, so we have to
190
+ # circumvent them.
191
+ if package_dir != "":
192
+ if not os.path.exists(package_dir):
193
+ raise DistutilsFileError(
194
+ f"package directory '{package_dir}' does not exist"
195
+ )
196
+ if not os.path.isdir(package_dir):
197
+ raise DistutilsFileError(
198
+ f"supposed package directory '{package_dir}' exists, "
199
+ "but is not a directory"
200
+ )
201
+
202
+ # Directories without __init__.py are namespace packages (PEP 420).
203
+ if package:
204
+ init_py = os.path.join(package_dir, "__init__.py")
205
+ if os.path.isfile(init_py):
206
+ return init_py
207
+
208
+ # Either not in a package at all (__init__.py not expected), or
209
+ # __init__.py doesn't exist -- so don't return the filename.
210
+ return None
211
+
212
+ def check_module(self, module, module_file):
213
+ if not os.path.isfile(module_file):
214
+ log.warning("file %s (for module %s) not found", module_file, module)
215
+ return False
216
+ else:
217
+ return True
218
+
219
+ def find_package_modules(self, package, package_dir):
220
+ self.check_package(package, package_dir)
221
+ module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
222
+ modules = []
223
+ setup_script = os.path.abspath(self.distribution.script_name)
224
+
225
+ for f in module_files:
226
+ abs_f = os.path.abspath(f)
227
+ if abs_f != setup_script:
228
+ module = os.path.splitext(os.path.basename(f))[0]
229
+ modules.append((package, module, f))
230
+ else:
231
+ self.debug_print(f"excluding {setup_script}")
232
+ return modules
233
+
234
+ def find_modules(self):
235
+ """Finds individually-specified Python modules, ie. those listed by
236
+ module name in 'self.py_modules'. Returns a list of tuples (package,
237
+ module_base, filename): 'package' is a tuple of the path through
238
+ package-space to the module; 'module_base' is the bare (no
239
+ packages, no dots) module name, and 'filename' is the path to the
240
+ ".py" file (relative to the distribution root) that implements the
241
+ module.
242
+ """
243
+ # Map package names to tuples of useful info about the package:
244
+ # (package_dir, checked)
245
+ # package_dir - the directory where we'll find source files for
246
+ # this package
247
+ # checked - true if we have checked that the package directory
248
+ # is valid (exists, contains __init__.py, ... ?)
249
+ packages = {}
250
+
251
+ # List of (package, module, filename) tuples to return
252
+ modules = []
253
+
254
+ # We treat modules-in-packages almost the same as toplevel modules,
255
+ # just the "package" for a toplevel is empty (either an empty
256
+ # string or empty list, depending on context). Differences:
257
+ # - don't check for __init__.py in directory for empty package
258
+ for module in self.py_modules:
259
+ path = module.split('.')
260
+ package = '.'.join(path[0:-1])
261
+ module_base = path[-1]
262
+
263
+ try:
264
+ (package_dir, checked) = packages[package]
265
+ except KeyError:
266
+ package_dir = self.get_package_dir(package)
267
+ checked = False
268
+
269
+ if not checked:
270
+ init_py = self.check_package(package, package_dir)
271
+ packages[package] = (package_dir, 1)
272
+ if init_py:
273
+ modules.append((package, "__init__", init_py))
274
+
275
+ # XXX perhaps we should also check for just .pyc files
276
+ # (so greedy closed-source bastards can distribute Python
277
+ # modules too)
278
+ module_file = os.path.join(package_dir, module_base + ".py")
279
+ if not self.check_module(module, module_file):
280
+ continue
281
+
282
+ modules.append((package, module_base, module_file))
283
+
284
+ return modules
285
+
286
+ def find_all_modules(self):
287
+ """Compute the list of all modules that will be built, whether
288
+ they are specified one-module-at-a-time ('self.py_modules') or
289
+ by whole packages ('self.packages'). Return a list of tuples
290
+ (package, module, module_file), just like 'find_modules()' and
291
+ 'find_package_modules()' do."""
292
+ modules = []
293
+ if self.py_modules:
294
+ modules.extend(self.find_modules())
295
+ if self.packages:
296
+ for package in self.packages:
297
+ package_dir = self.get_package_dir(package)
298
+ m = self.find_package_modules(package, package_dir)
299
+ modules.extend(m)
300
+ return modules
301
+
302
+ def get_source_files(self):
303
+ return [module[-1] for module in self.find_all_modules()]
304
+
305
+ def get_module_outfile(self, build_dir, package, module):
306
+ outfile_path = [build_dir] + list(package) + [module + ".py"]
307
+ return os.path.join(*outfile_path)
308
+
309
+ def get_outputs(self, include_bytecode=True):
310
+ modules = self.find_all_modules()
311
+ outputs = []
312
+ for package, module, _module_file in modules:
313
+ package = package.split('.')
314
+ filename = self.get_module_outfile(self.build_lib, package, module)
315
+ outputs.append(filename)
316
+ if include_bytecode:
317
+ if self.compile:
318
+ outputs.append(
319
+ importlib.util.cache_from_source(filename, optimization='')
320
+ )
321
+ if self.optimize > 0:
322
+ outputs.append(
323
+ importlib.util.cache_from_source(
324
+ filename, optimization=self.optimize
325
+ )
326
+ )
327
+
328
+ outputs += [
329
+ os.path.join(build_dir, filename)
330
+ for package, src_dir, build_dir, filenames in self.data_files
331
+ for filename in filenames
332
+ ]
333
+
334
+ return outputs
335
+
336
+ def build_module(self, module, module_file, package):
337
+ if isinstance(package, str):
338
+ package = package.split('.')
339
+ elif not isinstance(package, (list, tuple)):
340
+ raise TypeError(
341
+ "'package' must be a string (dot-separated), list, or tuple"
342
+ )
343
+
344
+ # Now put the module source file into the "build" area -- this is
345
+ # easy, we just copy it somewhere under self.build_lib (the build
346
+ # directory for Python source).
347
+ outfile = self.get_module_outfile(self.build_lib, package, module)
348
+ dir = os.path.dirname(outfile)
349
+ self.mkpath(dir)
350
+ return self.copy_file(module_file, outfile, preserve_mode=False)
351
+
352
+ def build_modules(self):
353
+ modules = self.find_modules()
354
+ for package, module, module_file in modules:
355
+ # Now "build" the module -- ie. copy the source file to
356
+ # self.build_lib (the build directory for Python source).
357
+ # (Actually, it gets copied to the directory for this package
358
+ # under self.build_lib.)
359
+ self.build_module(module, module_file, package)
360
+
361
+ def build_packages(self):
362
+ for package in self.packages:
363
+ # Get list of (package, module, module_file) tuples based on
364
+ # scanning the package directory. 'package' is only included
365
+ # in the tuple so that 'find_modules()' and
366
+ # 'find_package_tuples()' have a consistent interface; it's
367
+ # ignored here (apart from a sanity check). Also, 'module' is
368
+ # the *unqualified* module name (ie. no dots, no package -- we
369
+ # already know its package!), and 'module_file' is the path to
370
+ # the .py file, relative to the current directory
371
+ # (ie. including 'package_dir').
372
+ package_dir = self.get_package_dir(package)
373
+ modules = self.find_package_modules(package, package_dir)
374
+
375
+ # Now loop over the modules we found, "building" each one (just
376
+ # copy it to self.build_lib).
377
+ for package_, module, module_file in modules:
378
+ assert package == package_
379
+ self.build_module(module, module_file, package)
380
+
381
+ def byte_compile(self, files):
382
+ if sys.dont_write_bytecode:
383
+ self.warn('byte-compiling is disabled, skipping.')
384
+ return
385
+
386
+ from ..util import byte_compile
387
+
388
+ prefix = self.build_lib
389
+ if prefix[-1] != os.sep:
390
+ prefix = prefix + os.sep
391
+
392
+ # XXX this code is essentially the same as the 'byte_compile()
393
+ # method of the "install_lib" command, except for the determination
394
+ # of the 'prefix' string. Hmmm.
395
+ if self.compile:
396
+ byte_compile(
397
+ files, optimize=0, force=self.force, prefix=prefix, dry_run=self.dry_run
398
+ )
399
+ if self.optimize > 0:
400
+ byte_compile(
401
+ files,
402
+ optimize=self.optimize,
403
+ force=self.force,
404
+ prefix=prefix,
405
+ dry_run=self.dry_run,
406
+ )
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_scripts
2
+
3
+ Implements the Distutils 'build_scripts' command."""
4
+
5
+ import os
6
+ import re
7
+ import tokenize
8
+ from distutils import sysconfig
9
+ from distutils._log import log
10
+ from stat import ST_MODE
11
+ from typing import ClassVar
12
+
13
+ from .._modified import newer
14
+ from ..core import Command
15
+ from ..util import convert_path
16
+
17
+ shebang_pattern = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
18
+ """
19
+ Pattern matching a Python interpreter indicated in first line of a script.
20
+ """
21
+
22
+ # for Setuptools compatibility
23
+ first_line_re = shebang_pattern
24
+
25
+
26
+ class build_scripts(Command):
27
+ description = "\"build\" scripts (copy and fixup #! line)"
28
+
29
+ user_options: ClassVar[list[tuple[str, str, str]]] = [
30
+ ('build-dir=', 'd', "directory to \"build\" (copy) to"),
31
+ ('force', 'f', "forcibly build everything (ignore file timestamps"),
32
+ ('executable=', 'e', "specify final destination interpreter path"),
33
+ ]
34
+
35
+ boolean_options = ['force']
36
+
37
+ def initialize_options(self):
38
+ self.build_dir = None
39
+ self.scripts = None
40
+ self.force = None
41
+ self.executable = None
42
+
43
+ def finalize_options(self):
44
+ self.set_undefined_options(
45
+ 'build',
46
+ ('build_scripts', 'build_dir'),
47
+ ('force', 'force'),
48
+ ('executable', 'executable'),
49
+ )
50
+ self.scripts = self.distribution.scripts
51
+
52
+ def get_source_files(self):
53
+ return self.scripts
54
+
55
+ def run(self):
56
+ if not self.scripts:
57
+ return
58
+ self.copy_scripts()
59
+
60
+ def copy_scripts(self):
61
+ """
62
+ Copy each script listed in ``self.scripts``.
63
+
64
+ If a script is marked as a Python script (first line matches
65
+ 'shebang_pattern', i.e. starts with ``#!`` and contains
66
+ "python"), then adjust in the copy the first line to refer to
67
+ the current Python interpreter.
68
+ """
69
+ self.mkpath(self.build_dir)
70
+ outfiles = []
71
+ updated_files = []
72
+ for script in self.scripts:
73
+ self._copy_script(script, outfiles, updated_files)
74
+
75
+ self._change_modes(outfiles)
76
+
77
+ return outfiles, updated_files
78
+
79
+ def _copy_script(self, script, outfiles, updated_files): # noqa: C901
80
+ shebang_match = None
81
+ script = convert_path(script)
82
+ outfile = os.path.join(self.build_dir, os.path.basename(script))
83
+ outfiles.append(outfile)
84
+
85
+ if not self.force and not newer(script, outfile):
86
+ log.debug("not copying %s (up-to-date)", script)
87
+ return
88
+
89
+ # Always open the file, but ignore failures in dry-run mode
90
+ # in order to attempt to copy directly.
91
+ try:
92
+ f = tokenize.open(script)
93
+ except OSError:
94
+ if not self.dry_run:
95
+ raise
96
+ f = None
97
+ else:
98
+ first_line = f.readline()
99
+ if not first_line:
100
+ self.warn(f"{script} is an empty file (skipping)")
101
+ return
102
+
103
+ shebang_match = shebang_pattern.match(first_line)
104
+
105
+ updated_files.append(outfile)
106
+ if shebang_match:
107
+ log.info("copying and adjusting %s -> %s", script, self.build_dir)
108
+ if not self.dry_run:
109
+ if not sysconfig.python_build:
110
+ executable = self.executable
111
+ else:
112
+ executable = os.path.join(
113
+ sysconfig.get_config_var("BINDIR"),
114
+ "python{}{}".format(
115
+ sysconfig.get_config_var("VERSION"),
116
+ sysconfig.get_config_var("EXE"),
117
+ ),
118
+ )
119
+ post_interp = shebang_match.group(1) or ''
120
+ shebang = "#!" + executable + post_interp + "\n"
121
+ self._validate_shebang(shebang, f.encoding)
122
+ with open(outfile, "w", encoding=f.encoding) as outf:
123
+ outf.write(shebang)
124
+ outf.writelines(f.readlines())
125
+ if f:
126
+ f.close()
127
+ else:
128
+ if f:
129
+ f.close()
130
+ self.copy_file(script, outfile)
131
+
132
+ def _change_modes(self, outfiles):
133
+ if os.name != 'posix':
134
+ return
135
+
136
+ for file in outfiles:
137
+ self._change_mode(file)
138
+
139
+ def _change_mode(self, file):
140
+ if self.dry_run:
141
+ log.info("changing mode of %s", file)
142
+ return
143
+
144
+ oldmode = os.stat(file)[ST_MODE] & 0o7777
145
+ newmode = (oldmode | 0o555) & 0o7777
146
+ if newmode != oldmode:
147
+ log.info("changing mode of %s from %o to %o", file, oldmode, newmode)
148
+ os.chmod(file, newmode)
149
+
150
+ @staticmethod
151
+ def _validate_shebang(shebang, encoding):
152
+ # Python parser starts to read a script using UTF-8 until
153
+ # it gets a #coding:xxx cookie. The shebang has to be the
154
+ # first line of a file, the #coding:xxx cookie cannot be
155
+ # written before. So the shebang has to be encodable to
156
+ # UTF-8.
157
+ try:
158
+ shebang.encode('utf-8')
159
+ except UnicodeEncodeError:
160
+ raise ValueError(f"The shebang ({shebang!r}) is not encodable to utf-8")
161
+
162
+ # If the script is encoded to a custom encoding (use a
163
+ # #coding:xxx cookie), the shebang has to be encodable to
164
+ # the script encoding too.
165
+ try:
166
+ shebang.encode(encoding)
167
+ except UnicodeEncodeError:
168
+ raise ValueError(
169
+ f"The shebang ({shebang!r}) is not encodable "
170
+ f"to the script encoding ({encoding})"
171
+ )
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/check.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.check
2
+
3
+ Implements the Distutils 'check' command.
4
+ """
5
+
6
+ import contextlib
7
+ from typing import ClassVar
8
+
9
+ from ..core import Command
10
+ from ..errors import DistutilsSetupError
11
+
12
+ with contextlib.suppress(ImportError):
13
+ import docutils.frontend
14
+ import docutils.nodes
15
+ import docutils.parsers.rst
16
+ import docutils.utils
17
+
18
+ class SilentReporter(docutils.utils.Reporter):
19
+ def __init__(
20
+ self,
21
+ source,
22
+ report_level,
23
+ halt_level,
24
+ stream=None,
25
+ debug=False,
26
+ encoding='ascii',
27
+ error_handler='replace',
28
+ ):
29
+ self.messages = []
30
+ super().__init__(
31
+ source, report_level, halt_level, stream, debug, encoding, error_handler
32
+ )
33
+
34
+ def system_message(self, level, message, *children, **kwargs):
35
+ self.messages.append((level, message, children, kwargs))
36
+ return docutils.nodes.system_message(
37
+ message, *children, level=level, type=self.levels[level], **kwargs
38
+ )
39
+
40
+
41
+ class check(Command):
42
+ """This command checks the meta-data of the package."""
43
+
44
+ description = "perform some checks on the package"
45
+ user_options: ClassVar[list[tuple[str, str, str]]] = [
46
+ ('metadata', 'm', 'Verify meta-data'),
47
+ (
48
+ 'restructuredtext',
49
+ 'r',
50
+ 'Checks if long string meta-data syntax are reStructuredText-compliant',
51
+ ),
52
+ ('strict', 's', 'Will exit with an error if a check fails'),
53
+ ]
54
+
55
+ boolean_options = ['metadata', 'restructuredtext', 'strict']
56
+
57
+ def initialize_options(self):
58
+ """Sets default values for options."""
59
+ self.restructuredtext = False
60
+ self.metadata = 1
61
+ self.strict = False
62
+ self._warnings = 0
63
+
64
+ def finalize_options(self):
65
+ pass
66
+
67
+ def warn(self, msg):
68
+ """Counts the number of warnings that occurs."""
69
+ self._warnings += 1
70
+ return Command.warn(self, msg)
71
+
72
+ def run(self):
73
+ """Runs the command."""
74
+ # perform the various tests
75
+ if self.metadata:
76
+ self.check_metadata()
77
+ if self.restructuredtext:
78
+ if 'docutils' in globals():
79
+ try:
80
+ self.check_restructuredtext()
81
+ except TypeError as exc:
82
+ raise DistutilsSetupError(str(exc))
83
+ elif self.strict:
84
+ raise DistutilsSetupError('The docutils package is needed.')
85
+
86
+ # let's raise an error in strict mode, if we have at least
87
+ # one warning
88
+ if self.strict and self._warnings > 0:
89
+ raise DistutilsSetupError('Please correct your package.')
90
+
91
+ def check_metadata(self):
92
+ """Ensures that all required elements of meta-data are supplied.
93
+
94
+ Required fields:
95
+ name, version
96
+
97
+ Warns if any are missing.
98
+ """
99
+ metadata = self.distribution.metadata
100
+
101
+ missing = [
102
+ attr for attr in ('name', 'version') if not getattr(metadata, attr, None)
103
+ ]
104
+
105
+ if missing:
106
+ self.warn("missing required meta-data: {}".format(', '.join(missing)))
107
+
108
+ def check_restructuredtext(self):
109
+ """Checks if the long string fields are reST-compliant."""
110
+ data = self.distribution.get_long_description()
111
+ for warning in self._check_rst_data(data):
112
+ line = warning[-1].get('line')
113
+ if line is None:
114
+ warning = warning[1]
115
+ else:
116
+ warning = f'{warning[1]} (line {line})'
117
+ self.warn(warning)
118
+
119
+ def _check_rst_data(self, data):
120
+ """Returns warnings when the provided data doesn't compile."""
121
+ # the include and csv_table directives need this to be a path
122
+ source_path = self.distribution.script_name or 'setup.py'
123
+ parser = docutils.parsers.rst.Parser()
124
+ settings = docutils.frontend.OptionParser(
125
+ components=(docutils.parsers.rst.Parser,)
126
+ ).get_default_values()
127
+ settings.tab_width = 4
128
+ settings.pep_references = None
129
+ settings.rfc_references = None
130
+ reporter = SilentReporter(
131
+ source_path,
132
+ settings.report_level,
133
+ settings.halt_level,
134
+ stream=settings.warning_stream,
135
+ debug=settings.debug,
136
+ encoding=settings.error_encoding,
137
+ error_handler=settings.error_encoding_error_handler,
138
+ )
139
+
140
+ document = docutils.nodes.document(settings, reporter, source=source_path)
141
+ document.note_source(source_path, -1)
142
+ try:
143
+ parser.parse(data, document)
144
+ except AttributeError as e:
145
+ reporter.messages.append((
146
+ -1,
147
+ f'Could not finish the parsing: {e}.',
148
+ '',
149
+ {},
150
+ ))
151
+
152
+ return reporter.messages
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/clean.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.clean
2
+
3
+ Implements the Distutils 'clean' command."""
4
+
5
+ # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
6
+
7
+ import os
8
+ from distutils._log import log
9
+
10
+ from ..core import Command
11
+ from ..dir_util import remove_tree
12
+
13
+
14
+ class clean(Command):
15
+ description = "clean up temporary files from 'build' command"
16
+ user_options = [
17
+ ('build-base=', 'b', "base build directory [default: 'build.build-base']"),
18
+ (
19
+ 'build-lib=',
20
+ None,
21
+ "build directory for all modules [default: 'build.build-lib']",
22
+ ),
23
+ ('build-temp=', 't', "temporary build directory [default: 'build.build-temp']"),
24
+ (
25
+ 'build-scripts=',
26
+ None,
27
+ "build directory for scripts [default: 'build.build-scripts']",
28
+ ),
29
+ ('bdist-base=', None, "temporary directory for built distributions"),
30
+ ('all', 'a', "remove all build output, not just temporary by-products"),
31
+ ]
32
+
33
+ boolean_options = ['all']
34
+
35
+ def initialize_options(self):
36
+ self.build_base = None
37
+ self.build_lib = None
38
+ self.build_temp = None
39
+ self.build_scripts = None
40
+ self.bdist_base = None
41
+ self.all = None
42
+
43
+ def finalize_options(self):
44
+ self.set_undefined_options(
45
+ 'build',
46
+ ('build_base', 'build_base'),
47
+ ('build_lib', 'build_lib'),
48
+ ('build_scripts', 'build_scripts'),
49
+ ('build_temp', 'build_temp'),
50
+ )
51
+ self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
52
+
53
+ def run(self):
54
+ # remove the build/temp.<plat> directory (unless it's already
55
+ # gone)
56
+ if os.path.exists(self.build_temp):
57
+ remove_tree(self.build_temp, dry_run=self.dry_run)
58
+ else:
59
+ log.debug("'%s' does not exist -- can't clean it", self.build_temp)
60
+
61
+ if self.all:
62
+ # remove build directories
63
+ for directory in (self.build_lib, self.bdist_base, self.build_scripts):
64
+ if os.path.exists(directory):
65
+ remove_tree(directory, dry_run=self.dry_run)
66
+ else:
67
+ log.warning("'%s' does not exist -- can't clean it", directory)
68
+
69
+ # just for the heck of it, try to remove the base build directory:
70
+ # we might have emptied it right now, but if not we don't care
71
+ if not self.dry_run:
72
+ try:
73
+ os.rmdir(self.build_base)
74
+ log.info("removing '%s'", self.build_base)
75
+ except OSError:
76
+ pass
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/config.py ADDED
@@ -0,0 +1,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.config
2
+
3
+ Implements the Distutils 'config' command, a (mostly) empty command class
4
+ that exists mainly to be sub-classed by specific module distributions and
5
+ applications. The idea is that while every "config" command is different,
6
+ at least they're all named the same, and users always see "config" in the
7
+ list of standard commands. Also, this is a good place to put common
8
+ configure-like tasks: "try to compile this C code", or "figure out where
9
+ this header file lives".
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import os
15
+ import pathlib
16
+ import re
17
+ from collections.abc import Sequence
18
+ from distutils._log import log
19
+
20
+ from ..core import Command
21
+ from ..errors import DistutilsExecError
22
+ from ..sysconfig import customize_compiler
23
+
24
+ LANG_EXT = {"c": ".c", "c++": ".cxx"}
25
+
26
+
27
+ class config(Command):
28
+ description = "prepare to build"
29
+
30
+ user_options = [
31
+ ('compiler=', None, "specify the compiler type"),
32
+ ('cc=', None, "specify the compiler executable"),
33
+ ('include-dirs=', 'I', "list of directories to search for header files"),
34
+ ('define=', 'D', "C preprocessor macros to define"),
35
+ ('undef=', 'U', "C preprocessor macros to undefine"),
36
+ ('libraries=', 'l', "external C libraries to link with"),
37
+ ('library-dirs=', 'L', "directories to search for external C libraries"),
38
+ ('noisy', None, "show every action (compile, link, run, ...) taken"),
39
+ (
40
+ 'dump-source',
41
+ None,
42
+ "dump generated source files before attempting to compile them",
43
+ ),
44
+ ]
45
+
46
+ # The three standard command methods: since the "config" command
47
+ # does nothing by default, these are empty.
48
+
49
+ def initialize_options(self):
50
+ self.compiler = None
51
+ self.cc = None
52
+ self.include_dirs = None
53
+ self.libraries = None
54
+ self.library_dirs = None
55
+
56
+ # maximal output for now
57
+ self.noisy = 1
58
+ self.dump_source = 1
59
+
60
+ # list of temporary files generated along-the-way that we have
61
+ # to clean at some point
62
+ self.temp_files = []
63
+
64
+ def finalize_options(self):
65
+ if self.include_dirs is None:
66
+ self.include_dirs = self.distribution.include_dirs or []
67
+ elif isinstance(self.include_dirs, str):
68
+ self.include_dirs = self.include_dirs.split(os.pathsep)
69
+
70
+ if self.libraries is None:
71
+ self.libraries = []
72
+ elif isinstance(self.libraries, str):
73
+ self.libraries = [self.libraries]
74
+
75
+ if self.library_dirs is None:
76
+ self.library_dirs = []
77
+ elif isinstance(self.library_dirs, str):
78
+ self.library_dirs = self.library_dirs.split(os.pathsep)
79
+
80
+ def run(self):
81
+ pass
82
+
83
+ # Utility methods for actual "config" commands. The interfaces are
84
+ # loosely based on Autoconf macros of similar names. Sub-classes
85
+ # may use these freely.
86
+
87
+ def _check_compiler(self):
88
+ """Check that 'self.compiler' really is a CCompiler object;
89
+ if not, make it one.
90
+ """
91
+ # We do this late, and only on-demand, because this is an expensive
92
+ # import.
93
+ from ..ccompiler import CCompiler, new_compiler
94
+
95
+ if not isinstance(self.compiler, CCompiler):
96
+ self.compiler = new_compiler(
97
+ compiler=self.compiler, dry_run=self.dry_run, force=True
98
+ )
99
+ customize_compiler(self.compiler)
100
+ if self.include_dirs:
101
+ self.compiler.set_include_dirs(self.include_dirs)
102
+ if self.libraries:
103
+ self.compiler.set_libraries(self.libraries)
104
+ if self.library_dirs:
105
+ self.compiler.set_library_dirs(self.library_dirs)
106
+
107
+ def _gen_temp_sourcefile(self, body, headers, lang):
108
+ filename = "_configtest" + LANG_EXT[lang]
109
+ with open(filename, "w", encoding='utf-8') as file:
110
+ if headers:
111
+ for header in headers:
112
+ file.write(f"#include <{header}>\n")
113
+ file.write("\n")
114
+ file.write(body)
115
+ if body[-1] != "\n":
116
+ file.write("\n")
117
+ return filename
118
+
119
+ def _preprocess(self, body, headers, include_dirs, lang):
120
+ src = self._gen_temp_sourcefile(body, headers, lang)
121
+ out = "_configtest.i"
122
+ self.temp_files.extend([src, out])
123
+ self.compiler.preprocess(src, out, include_dirs=include_dirs)
124
+ return (src, out)
125
+
126
+ def _compile(self, body, headers, include_dirs, lang):
127
+ src = self._gen_temp_sourcefile(body, headers, lang)
128
+ if self.dump_source:
129
+ dump_file(src, f"compiling '{src}':")
130
+ (obj,) = self.compiler.object_filenames([src])
131
+ self.temp_files.extend([src, obj])
132
+ self.compiler.compile([src], include_dirs=include_dirs)
133
+ return (src, obj)
134
+
135
+ def _link(self, body, headers, include_dirs, libraries, library_dirs, lang):
136
+ (src, obj) = self._compile(body, headers, include_dirs, lang)
137
+ prog = os.path.splitext(os.path.basename(src))[0]
138
+ self.compiler.link_executable(
139
+ [obj],
140
+ prog,
141
+ libraries=libraries,
142
+ library_dirs=library_dirs,
143
+ target_lang=lang,
144
+ )
145
+
146
+ if self.compiler.exe_extension is not None:
147
+ prog = prog + self.compiler.exe_extension
148
+ self.temp_files.append(prog)
149
+
150
+ return (src, obj, prog)
151
+
152
+ def _clean(self, *filenames):
153
+ if not filenames:
154
+ filenames = self.temp_files
155
+ self.temp_files = []
156
+ log.info("removing: %s", ' '.join(filenames))
157
+ for filename in filenames:
158
+ try:
159
+ os.remove(filename)
160
+ except OSError:
161
+ pass
162
+
163
+ # XXX these ignore the dry-run flag: what to do, what to do? even if
164
+ # you want a dry-run build, you still need some sort of configuration
165
+ # info. My inclination is to make it up to the real config command to
166
+ # consult 'dry_run', and assume a default (minimal) configuration if
167
+ # true. The problem with trying to do it here is that you'd have to
168
+ # return either true or false from all the 'try' methods, neither of
169
+ # which is correct.
170
+
171
+ # XXX need access to the header search path and maybe default macros.
172
+
173
+ def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"):
174
+ """Construct a source file from 'body' (a string containing lines
175
+ of C/C++ code) and 'headers' (a list of header files to include)
176
+ and run it through the preprocessor. Return true if the
177
+ preprocessor succeeded, false if there were any errors.
178
+ ('body' probably isn't of much use, but what the heck.)
179
+ """
180
+ from ..ccompiler import CompileError
181
+
182
+ self._check_compiler()
183
+ ok = True
184
+ try:
185
+ self._preprocess(body, headers, include_dirs, lang)
186
+ except CompileError:
187
+ ok = False
188
+
189
+ self._clean()
190
+ return ok
191
+
192
+ def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, lang="c"):
193
+ """Construct a source file (just like 'try_cpp()'), run it through
194
+ the preprocessor, and return true if any line of the output matches
195
+ 'pattern'. 'pattern' should either be a compiled regex object or a
196
+ string containing a regex. If both 'body' and 'headers' are None,
197
+ preprocesses an empty file -- which can be useful to determine the
198
+ symbols the preprocessor and compiler set by default.
199
+ """
200
+ self._check_compiler()
201
+ src, out = self._preprocess(body, headers, include_dirs, lang)
202
+
203
+ if isinstance(pattern, str):
204
+ pattern = re.compile(pattern)
205
+
206
+ with open(out, encoding='utf-8') as file:
207
+ match = any(pattern.search(line) for line in file)
208
+
209
+ self._clean()
210
+ return match
211
+
212
+ def try_compile(self, body, headers=None, include_dirs=None, lang="c"):
213
+ """Try to compile a source file built from 'body' and 'headers'.
214
+ Return true on success, false otherwise.
215
+ """
216
+ from ..ccompiler import CompileError
217
+
218
+ self._check_compiler()
219
+ try:
220
+ self._compile(body, headers, include_dirs, lang)
221
+ ok = True
222
+ except CompileError:
223
+ ok = False
224
+
225
+ log.info(ok and "success!" or "failure.")
226
+ self._clean()
227
+ return ok
228
+
229
+ def try_link(
230
+ self,
231
+ body,
232
+ headers=None,
233
+ include_dirs=None,
234
+ libraries=None,
235
+ library_dirs=None,
236
+ lang="c",
237
+ ):
238
+ """Try to compile and link a source file, built from 'body' and
239
+ 'headers', to executable form. Return true on success, false
240
+ otherwise.
241
+ """
242
+ from ..ccompiler import CompileError, LinkError
243
+
244
+ self._check_compiler()
245
+ try:
246
+ self._link(body, headers, include_dirs, libraries, library_dirs, lang)
247
+ ok = True
248
+ except (CompileError, LinkError):
249
+ ok = False
250
+
251
+ log.info(ok and "success!" or "failure.")
252
+ self._clean()
253
+ return ok
254
+
255
+ def try_run(
256
+ self,
257
+ body,
258
+ headers=None,
259
+ include_dirs=None,
260
+ libraries=None,
261
+ library_dirs=None,
262
+ lang="c",
263
+ ):
264
+ """Try to compile, link to an executable, and run a program
265
+ built from 'body' and 'headers'. Return true on success, false
266
+ otherwise.
267
+ """
268
+ from ..ccompiler import CompileError, LinkError
269
+
270
+ self._check_compiler()
271
+ try:
272
+ src, obj, exe = self._link(
273
+ body, headers, include_dirs, libraries, library_dirs, lang
274
+ )
275
+ self.spawn([exe])
276
+ ok = True
277
+ except (CompileError, LinkError, DistutilsExecError):
278
+ ok = False
279
+
280
+ log.info(ok and "success!" or "failure.")
281
+ self._clean()
282
+ return ok
283
+
284
+ # -- High-level methods --------------------------------------------
285
+ # (these are the ones that are actually likely to be useful
286
+ # when implementing a real-world config command!)
287
+
288
+ def check_func(
289
+ self,
290
+ func,
291
+ headers=None,
292
+ include_dirs=None,
293
+ libraries=None,
294
+ library_dirs=None,
295
+ decl=False,
296
+ call=False,
297
+ ):
298
+ """Determine if function 'func' is available by constructing a
299
+ source file that refers to 'func', and compiles and links it.
300
+ If everything succeeds, returns true; otherwise returns false.
301
+
302
+ The constructed source file starts out by including the header
303
+ files listed in 'headers'. If 'decl' is true, it then declares
304
+ 'func' (as "int func()"); you probably shouldn't supply 'headers'
305
+ and set 'decl' true in the same call, or you might get errors about
306
+ a conflicting declarations for 'func'. Finally, the constructed
307
+ 'main()' function either references 'func' or (if 'call' is true)
308
+ calls it. 'libraries' and 'library_dirs' are used when
309
+ linking.
310
+ """
311
+ self._check_compiler()
312
+ body = []
313
+ if decl:
314
+ body.append(f"int {func} ();")
315
+ body.append("int main () {")
316
+ if call:
317
+ body.append(f" {func}();")
318
+ else:
319
+ body.append(f" {func};")
320
+ body.append("}")
321
+ body = "\n".join(body) + "\n"
322
+
323
+ return self.try_link(body, headers, include_dirs, libraries, library_dirs)
324
+
325
+ def check_lib(
326
+ self,
327
+ library,
328
+ library_dirs=None,
329
+ headers=None,
330
+ include_dirs=None,
331
+ other_libraries: Sequence[str] = [],
332
+ ):
333
+ """Determine if 'library' is available to be linked against,
334
+ without actually checking that any particular symbols are provided
335
+ by it. 'headers' will be used in constructing the source file to
336
+ be compiled, but the only effect of this is to check if all the
337
+ header files listed are available. Any libraries listed in
338
+ 'other_libraries' will be included in the link, in case 'library'
339
+ has symbols that depend on other libraries.
340
+ """
341
+ self._check_compiler()
342
+ return self.try_link(
343
+ "int main (void) { }",
344
+ headers,
345
+ include_dirs,
346
+ [library] + list(other_libraries),
347
+ library_dirs,
348
+ )
349
+
350
+ def check_header(self, header, include_dirs=None, library_dirs=None, lang="c"):
351
+ """Determine if the system header file named by 'header_file'
352
+ exists and can be found by the preprocessor; return true if so,
353
+ false otherwise.
354
+ """
355
+ return self.try_cpp(
356
+ body="/* No body */", headers=[header], include_dirs=include_dirs
357
+ )
358
+
359
+
360
+ def dump_file(filename, head=None):
361
+ """Dumps a file content into log.info.
362
+
363
+ If head is not None, will be dumped before the file content.
364
+ """
365
+ if head is None:
366
+ log.info('%s', filename)
367
+ else:
368
+ log.info(head)
369
+ log.info(pathlib.Path(filename).read_text(encoding='utf-8'))
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/install.py ADDED
@@ -0,0 +1,811 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.install
2
+
3
+ Implements the Distutils 'install' command."""
4
+
5
+ import contextlib
6
+ import itertools
7
+ import os
8
+ import sys
9
+ import sysconfig
10
+ from distutils._log import log
11
+ from site import USER_BASE, USER_SITE
12
+
13
+ import jaraco.collections
14
+
15
+ from ..core import Command
16
+ from ..debug import DEBUG
17
+ from ..errors import DistutilsOptionError, DistutilsPlatformError
18
+ from ..file_util import write_file
19
+ from ..sysconfig import get_config_vars
20
+ from ..util import change_root, convert_path, get_platform, subst_vars
21
+ from . import _framework_compat as fw
22
+
23
+ HAS_USER_SITE = True
24
+
25
+ WINDOWS_SCHEME = {
26
+ 'purelib': '{base}/Lib/site-packages',
27
+ 'platlib': '{base}/Lib/site-packages',
28
+ 'headers': '{base}/Include/{dist_name}',
29
+ 'scripts': '{base}/Scripts',
30
+ 'data': '{base}',
31
+ }
32
+
33
+ INSTALL_SCHEMES = {
34
+ 'posix_prefix': {
35
+ 'purelib': '{base}/lib/{implementation_lower}{py_version_short}/site-packages',
36
+ 'platlib': '{platbase}/{platlibdir}/{implementation_lower}'
37
+ '{py_version_short}/site-packages',
38
+ 'headers': '{base}/include/{implementation_lower}'
39
+ '{py_version_short}{abiflags}/{dist_name}',
40
+ 'scripts': '{base}/bin',
41
+ 'data': '{base}',
42
+ },
43
+ 'posix_home': {
44
+ 'purelib': '{base}/lib/{implementation_lower}',
45
+ 'platlib': '{base}/{platlibdir}/{implementation_lower}',
46
+ 'headers': '{base}/include/{implementation_lower}/{dist_name}',
47
+ 'scripts': '{base}/bin',
48
+ 'data': '{base}',
49
+ },
50
+ 'nt': WINDOWS_SCHEME,
51
+ 'pypy': {
52
+ 'purelib': '{base}/site-packages',
53
+ 'platlib': '{base}/site-packages',
54
+ 'headers': '{base}/include/{dist_name}',
55
+ 'scripts': '{base}/bin',
56
+ 'data': '{base}',
57
+ },
58
+ 'pypy_nt': {
59
+ 'purelib': '{base}/site-packages',
60
+ 'platlib': '{base}/site-packages',
61
+ 'headers': '{base}/include/{dist_name}',
62
+ 'scripts': '{base}/Scripts',
63
+ 'data': '{base}',
64
+ },
65
+ }
66
+
67
+ # user site schemes
68
+ if HAS_USER_SITE:
69
+ INSTALL_SCHEMES['nt_user'] = {
70
+ 'purelib': '{usersite}',
71
+ 'platlib': '{usersite}',
72
+ 'headers': '{userbase}/{implementation}{py_version_nodot_plat}'
73
+ '/Include/{dist_name}',
74
+ 'scripts': '{userbase}/{implementation}{py_version_nodot_plat}/Scripts',
75
+ 'data': '{userbase}',
76
+ }
77
+
78
+ INSTALL_SCHEMES['posix_user'] = {
79
+ 'purelib': '{usersite}',
80
+ 'platlib': '{usersite}',
81
+ 'headers': '{userbase}/include/{implementation_lower}'
82
+ '{py_version_short}{abiflags}/{dist_name}',
83
+ 'scripts': '{userbase}/bin',
84
+ 'data': '{userbase}',
85
+ }
86
+
87
+
88
+ INSTALL_SCHEMES.update(fw.schemes)
89
+
90
+
91
+ # The keys to an installation scheme; if any new types of files are to be
92
+ # installed, be sure to add an entry to every installation scheme above,
93
+ # and to SCHEME_KEYS here.
94
+ SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
95
+
96
+
97
+ def _load_sysconfig_schemes():
98
+ with contextlib.suppress(AttributeError):
99
+ return {
100
+ scheme: sysconfig.get_paths(scheme, expand=False)
101
+ for scheme in sysconfig.get_scheme_names()
102
+ }
103
+
104
+
105
+ def _load_schemes():
106
+ """
107
+ Extend default schemes with schemes from sysconfig.
108
+ """
109
+
110
+ sysconfig_schemes = _load_sysconfig_schemes() or {}
111
+
112
+ return {
113
+ scheme: {
114
+ **INSTALL_SCHEMES.get(scheme, {}),
115
+ **sysconfig_schemes.get(scheme, {}),
116
+ }
117
+ for scheme in set(itertools.chain(INSTALL_SCHEMES, sysconfig_schemes))
118
+ }
119
+
120
+
121
+ def _get_implementation():
122
+ if hasattr(sys, 'pypy_version_info'):
123
+ return 'PyPy'
124
+ else:
125
+ return 'Python'
126
+
127
+
128
+ def _select_scheme(ob, name):
129
+ scheme = _inject_headers(name, _load_scheme(_resolve_scheme(name)))
130
+ vars(ob).update(_remove_set(ob, _scheme_attrs(scheme)))
131
+
132
+
133
+ def _remove_set(ob, attrs):
134
+ """
135
+ Include only attrs that are None in ob.
136
+ """
137
+ return {key: value for key, value in attrs.items() if getattr(ob, key) is None}
138
+
139
+
140
+ def _resolve_scheme(name):
141
+ os_name, sep, key = name.partition('_')
142
+ try:
143
+ resolved = sysconfig.get_preferred_scheme(key)
144
+ except Exception:
145
+ resolved = fw.scheme(_pypy_hack(name))
146
+ return resolved
147
+
148
+
149
+ def _load_scheme(name):
150
+ return _load_schemes()[name]
151
+
152
+
153
+ def _inject_headers(name, scheme):
154
+ """
155
+ Given a scheme name and the resolved scheme,
156
+ if the scheme does not include headers, resolve
157
+ the fallback scheme for the name and use headers
158
+ from it. pypa/distutils#88
159
+ """
160
+ # Bypass the preferred scheme, which may not
161
+ # have defined headers.
162
+ fallback = _load_scheme(_pypy_hack(name))
163
+ scheme.setdefault('headers', fallback['headers'])
164
+ return scheme
165
+
166
+
167
+ def _scheme_attrs(scheme):
168
+ """Resolve install directories by applying the install schemes."""
169
+ return {f'install_{key}': scheme[key] for key in SCHEME_KEYS}
170
+
171
+
172
+ def _pypy_hack(name):
173
+ PY37 = sys.version_info < (3, 8)
174
+ old_pypy = hasattr(sys, 'pypy_version_info') and PY37
175
+ prefix = not name.endswith(('_user', '_home'))
176
+ pypy_name = 'pypy' + '_nt' * (os.name == 'nt')
177
+ return pypy_name if old_pypy and prefix else name
178
+
179
+
180
+ class install(Command):
181
+ description = "install everything from build directory"
182
+
183
+ user_options = [
184
+ # Select installation scheme and set base director(y|ies)
185
+ ('prefix=', None, "installation prefix"),
186
+ ('exec-prefix=', None, "(Unix only) prefix for platform-specific files"),
187
+ ('home=', None, "(Unix only) home directory to install under"),
188
+ # Or, just set the base director(y|ies)
189
+ (
190
+ 'install-base=',
191
+ None,
192
+ "base installation directory (instead of --prefix or --home)",
193
+ ),
194
+ (
195
+ 'install-platbase=',
196
+ None,
197
+ "base installation directory for platform-specific files (instead of --exec-prefix or --home)",
198
+ ),
199
+ ('root=', None, "install everything relative to this alternate root directory"),
200
+ # Or, explicitly set the installation scheme
201
+ (
202
+ 'install-purelib=',
203
+ None,
204
+ "installation directory for pure Python module distributions",
205
+ ),
206
+ (
207
+ 'install-platlib=',
208
+ None,
209
+ "installation directory for non-pure module distributions",
210
+ ),
211
+ (
212
+ 'install-lib=',
213
+ None,
214
+ "installation directory for all module distributions (overrides --install-purelib and --install-platlib)",
215
+ ),
216
+ ('install-headers=', None, "installation directory for C/C++ headers"),
217
+ ('install-scripts=', None, "installation directory for Python scripts"),
218
+ ('install-data=', None, "installation directory for data files"),
219
+ # Byte-compilation options -- see install_lib.py for details, as
220
+ # these are duplicated from there (but only install_lib does
221
+ # anything with them).
222
+ ('compile', 'c', "compile .py to .pyc [default]"),
223
+ ('no-compile', None, "don't compile .py files"),
224
+ (
225
+ 'optimize=',
226
+ 'O',
227
+ "also compile with optimization: -O1 for \"python -O\", "
228
+ "-O2 for \"python -OO\", and -O0 to disable [default: -O0]",
229
+ ),
230
+ # Miscellaneous control options
231
+ ('force', 'f', "force installation (overwrite any existing files)"),
232
+ ('skip-build', None, "skip rebuilding everything (for testing/debugging)"),
233
+ # Where to install documentation (eventually!)
234
+ # ('doc-format=', None, "format of documentation to generate"),
235
+ # ('install-man=', None, "directory for Unix man pages"),
236
+ # ('install-html=', None, "directory for HTML documentation"),
237
+ # ('install-info=', None, "directory for GNU info files"),
238
+ ('record=', None, "filename in which to record list of installed files"),
239
+ ]
240
+
241
+ boolean_options = ['compile', 'force', 'skip-build']
242
+
243
+ if HAS_USER_SITE:
244
+ user_options.append((
245
+ 'user',
246
+ None,
247
+ f"install in user site-package '{USER_SITE}'",
248
+ ))
249
+ boolean_options.append('user')
250
+
251
+ negative_opt = {'no-compile': 'compile'}
252
+
253
+ def initialize_options(self):
254
+ """Initializes options."""
255
+ # High-level options: these select both an installation base
256
+ # and scheme.
257
+ self.prefix = None
258
+ self.exec_prefix = None
259
+ self.home = None
260
+ self.user = False
261
+
262
+ # These select only the installation base; it's up to the user to
263
+ # specify the installation scheme (currently, that means supplying
264
+ # the --install-{platlib,purelib,scripts,data} options).
265
+ self.install_base = None
266
+ self.install_platbase = None
267
+ self.root = None
268
+
269
+ # These options are the actual installation directories; if not
270
+ # supplied by the user, they are filled in using the installation
271
+ # scheme implied by prefix/exec-prefix/home and the contents of
272
+ # that installation scheme.
273
+ self.install_purelib = None # for pure module distributions
274
+ self.install_platlib = None # non-pure (dists w/ extensions)
275
+ self.install_headers = None # for C/C++ headers
276
+ self.install_lib = None # set to either purelib or platlib
277
+ self.install_scripts = None
278
+ self.install_data = None
279
+ self.install_userbase = USER_BASE
280
+ self.install_usersite = USER_SITE
281
+
282
+ self.compile = None
283
+ self.optimize = None
284
+
285
+ # Deprecated
286
+ # These two are for putting non-packagized distributions into their
287
+ # own directory and creating a .pth file if it makes sense.
288
+ # 'extra_path' comes from the setup file; 'install_path_file' can
289
+ # be turned off if it makes no sense to install a .pth file. (But
290
+ # better to install it uselessly than to guess wrong and not
291
+ # install it when it's necessary and would be used!) Currently,
292
+ # 'install_path_file' is always true unless some outsider meddles
293
+ # with it.
294
+ self.extra_path = None
295
+ self.install_path_file = True
296
+
297
+ # 'force' forces installation, even if target files are not
298
+ # out-of-date. 'skip_build' skips running the "build" command,
299
+ # handy if you know it's not necessary. 'warn_dir' (which is *not*
300
+ # a user option, it's just there so the bdist_* commands can turn
301
+ # it off) determines whether we warn about installing to a
302
+ # directory not in sys.path.
303
+ self.force = False
304
+ self.skip_build = False
305
+ self.warn_dir = True
306
+
307
+ # These are only here as a conduit from the 'build' command to the
308
+ # 'install_*' commands that do the real work. ('build_base' isn't
309
+ # actually used anywhere, but it might be useful in future.) They
310
+ # are not user options, because if the user told the install
311
+ # command where the build directory is, that wouldn't affect the
312
+ # build command.
313
+ self.build_base = None
314
+ self.build_lib = None
315
+
316
+ # Not defined yet because we don't know anything about
317
+ # documentation yet.
318
+ # self.install_man = None
319
+ # self.install_html = None
320
+ # self.install_info = None
321
+
322
+ self.record = None
323
+
324
+ # -- Option finalizing methods -------------------------------------
325
+ # (This is rather more involved than for most commands,
326
+ # because this is where the policy for installing third-
327
+ # party Python modules on various platforms given a wide
328
+ # array of user input is decided. Yes, it's quite complex!)
329
+
330
+ def finalize_options(self): # noqa: C901
331
+ """Finalizes options."""
332
+ # This method (and its helpers, like 'finalize_unix()',
333
+ # 'finalize_other()', and 'select_scheme()') is where the default
334
+ # installation directories for modules, extension modules, and
335
+ # anything else we care to install from a Python module
336
+ # distribution. Thus, this code makes a pretty important policy
337
+ # statement about how third-party stuff is added to a Python
338
+ # installation! Note that the actual work of installation is done
339
+ # by the relatively simple 'install_*' commands; they just take
340
+ # their orders from the installation directory options determined
341
+ # here.
342
+
343
+ # Check for errors/inconsistencies in the options; first, stuff
344
+ # that's wrong on any platform.
345
+
346
+ if (self.prefix or self.exec_prefix or self.home) and (
347
+ self.install_base or self.install_platbase
348
+ ):
349
+ raise DistutilsOptionError(
350
+ "must supply either prefix/exec-prefix/home or install-base/install-platbase -- not both"
351
+ )
352
+
353
+ if self.home and (self.prefix or self.exec_prefix):
354
+ raise DistutilsOptionError(
355
+ "must supply either home or prefix/exec-prefix -- not both"
356
+ )
357
+
358
+ if self.user and (
359
+ self.prefix
360
+ or self.exec_prefix
361
+ or self.home
362
+ or self.install_base
363
+ or self.install_platbase
364
+ ):
365
+ raise DistutilsOptionError(
366
+ "can't combine user with prefix, "
367
+ "exec_prefix/home, or install_(plat)base"
368
+ )
369
+
370
+ # Next, stuff that's wrong (or dubious) only on certain platforms.
371
+ if os.name != "posix":
372
+ if self.exec_prefix:
373
+ self.warn("exec-prefix option ignored on this platform")
374
+ self.exec_prefix = None
375
+
376
+ # Now the interesting logic -- so interesting that we farm it out
377
+ # to other methods. The goal of these methods is to set the final
378
+ # values for the install_{lib,scripts,data,...} options, using as
379
+ # input a heady brew of prefix, exec_prefix, home, install_base,
380
+ # install_platbase, user-supplied versions of
381
+ # install_{purelib,platlib,lib,scripts,data,...}, and the
382
+ # install schemes. Phew!
383
+
384
+ self.dump_dirs("pre-finalize_{unix,other}")
385
+
386
+ if os.name == 'posix':
387
+ self.finalize_unix()
388
+ else:
389
+ self.finalize_other()
390
+
391
+ self.dump_dirs("post-finalize_{unix,other}()")
392
+
393
+ # Expand configuration variables, tilde, etc. in self.install_base
394
+ # and self.install_platbase -- that way, we can use $base or
395
+ # $platbase in the other installation directories and not worry
396
+ # about needing recursive variable expansion (shudder).
397
+
398
+ py_version = sys.version.split()[0]
399
+ (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
400
+ try:
401
+ abiflags = sys.abiflags
402
+ except AttributeError:
403
+ # sys.abiflags may not be defined on all platforms.
404
+ abiflags = ''
405
+ local_vars = {
406
+ 'dist_name': self.distribution.get_name(),
407
+ 'dist_version': self.distribution.get_version(),
408
+ 'dist_fullname': self.distribution.get_fullname(),
409
+ 'py_version': py_version,
410
+ 'py_version_short': f'{sys.version_info.major}.{sys.version_info.minor}',
411
+ 'py_version_nodot': f'{sys.version_info.major}{sys.version_info.minor}',
412
+ 'sys_prefix': prefix,
413
+ 'prefix': prefix,
414
+ 'sys_exec_prefix': exec_prefix,
415
+ 'exec_prefix': exec_prefix,
416
+ 'abiflags': abiflags,
417
+ 'platlibdir': getattr(sys, 'platlibdir', 'lib'),
418
+ 'implementation_lower': _get_implementation().lower(),
419
+ 'implementation': _get_implementation(),
420
+ }
421
+
422
+ # vars for compatibility on older Pythons
423
+ compat_vars = dict(
424
+ # Python 3.9 and earlier
425
+ py_version_nodot_plat=getattr(sys, 'winver', '').replace('.', ''),
426
+ )
427
+
428
+ if HAS_USER_SITE:
429
+ local_vars['userbase'] = self.install_userbase
430
+ local_vars['usersite'] = self.install_usersite
431
+
432
+ self.config_vars = jaraco.collections.DictStack([
433
+ fw.vars(),
434
+ compat_vars,
435
+ sysconfig.get_config_vars(),
436
+ local_vars,
437
+ ])
438
+
439
+ self.expand_basedirs()
440
+
441
+ self.dump_dirs("post-expand_basedirs()")
442
+
443
+ # Now define config vars for the base directories so we can expand
444
+ # everything else.
445
+ local_vars['base'] = self.install_base
446
+ local_vars['platbase'] = self.install_platbase
447
+
448
+ if DEBUG:
449
+ from pprint import pprint
450
+
451
+ print("config vars:")
452
+ pprint(dict(self.config_vars))
453
+
454
+ # Expand "~" and configuration variables in the installation
455
+ # directories.
456
+ self.expand_dirs()
457
+
458
+ self.dump_dirs("post-expand_dirs()")
459
+
460
+ # Create directories in the home dir:
461
+ if self.user:
462
+ self.create_home_path()
463
+
464
+ # Pick the actual directory to install all modules to: either
465
+ # install_purelib or install_platlib, depending on whether this
466
+ # module distribution is pure or not. Of course, if the user
467
+ # already specified install_lib, use their selection.
468
+ if self.install_lib is None:
469
+ if self.distribution.has_ext_modules(): # has extensions: non-pure
470
+ self.install_lib = self.install_platlib
471
+ else:
472
+ self.install_lib = self.install_purelib
473
+
474
+ # Convert directories from Unix /-separated syntax to the local
475
+ # convention.
476
+ self.convert_paths(
477
+ 'lib',
478
+ 'purelib',
479
+ 'platlib',
480
+ 'scripts',
481
+ 'data',
482
+ 'headers',
483
+ 'userbase',
484
+ 'usersite',
485
+ )
486
+
487
+ # Deprecated
488
+ # Well, we're not actually fully completely finalized yet: we still
489
+ # have to deal with 'extra_path', which is the hack for allowing
490
+ # non-packagized module distributions (hello, Numerical Python!) to
491
+ # get their own directories.
492
+ self.handle_extra_path()
493
+ self.install_libbase = self.install_lib # needed for .pth file
494
+ self.install_lib = os.path.join(self.install_lib, self.extra_dirs)
495
+
496
+ # If a new root directory was supplied, make all the installation
497
+ # dirs relative to it.
498
+ if self.root is not None:
499
+ self.change_roots(
500
+ 'libbase', 'lib', 'purelib', 'platlib', 'scripts', 'data', 'headers'
501
+ )
502
+
503
+ self.dump_dirs("after prepending root")
504
+
505
+ # Find out the build directories, ie. where to install from.
506
+ self.set_undefined_options(
507
+ 'build', ('build_base', 'build_base'), ('build_lib', 'build_lib')
508
+ )
509
+
510
+ # Punt on doc directories for now -- after all, we're punting on
511
+ # documentation completely!
512
+
513
+ def dump_dirs(self, msg):
514
+ """Dumps the list of user options."""
515
+ if not DEBUG:
516
+ return
517
+ from ..fancy_getopt import longopt_xlate
518
+
519
+ log.debug(msg + ":")
520
+ for opt in self.user_options:
521
+ opt_name = opt[0]
522
+ if opt_name[-1] == "=":
523
+ opt_name = opt_name[0:-1]
524
+ if opt_name in self.negative_opt:
525
+ opt_name = self.negative_opt[opt_name]
526
+ opt_name = opt_name.translate(longopt_xlate)
527
+ val = not getattr(self, opt_name)
528
+ else:
529
+ opt_name = opt_name.translate(longopt_xlate)
530
+ val = getattr(self, opt_name)
531
+ log.debug(" %s: %s", opt_name, val)
532
+
533
+ def finalize_unix(self):
534
+ """Finalizes options for posix platforms."""
535
+ if self.install_base is not None or self.install_platbase is not None:
536
+ incomplete_scheme = (
537
+ (
538
+ self.install_lib is None
539
+ and self.install_purelib is None
540
+ and self.install_platlib is None
541
+ )
542
+ or self.install_headers is None
543
+ or self.install_scripts is None
544
+ or self.install_data is None
545
+ )
546
+ if incomplete_scheme:
547
+ raise DistutilsOptionError(
548
+ "install-base or install-platbase supplied, but "
549
+ "installation scheme is incomplete"
550
+ )
551
+ return
552
+
553
+ if self.user:
554
+ if self.install_userbase is None:
555
+ raise DistutilsPlatformError("User base directory is not specified")
556
+ self.install_base = self.install_platbase = self.install_userbase
557
+ self.select_scheme("posix_user")
558
+ elif self.home is not None:
559
+ self.install_base = self.install_platbase = self.home
560
+ self.select_scheme("posix_home")
561
+ else:
562
+ if self.prefix is None:
563
+ if self.exec_prefix is not None:
564
+ raise DistutilsOptionError(
565
+ "must not supply exec-prefix without prefix"
566
+ )
567
+
568
+ # Allow Fedora to add components to the prefix
569
+ _prefix_addition = getattr(sysconfig, '_prefix_addition', "")
570
+
571
+ self.prefix = os.path.normpath(sys.prefix) + _prefix_addition
572
+ self.exec_prefix = os.path.normpath(sys.exec_prefix) + _prefix_addition
573
+
574
+ else:
575
+ if self.exec_prefix is None:
576
+ self.exec_prefix = self.prefix
577
+
578
+ self.install_base = self.prefix
579
+ self.install_platbase = self.exec_prefix
580
+ self.select_scheme("posix_prefix")
581
+
582
+ def finalize_other(self):
583
+ """Finalizes options for non-posix platforms"""
584
+ if self.user:
585
+ if self.install_userbase is None:
586
+ raise DistutilsPlatformError("User base directory is not specified")
587
+ self.install_base = self.install_platbase = self.install_userbase
588
+ self.select_scheme(os.name + "_user")
589
+ elif self.home is not None:
590
+ self.install_base = self.install_platbase = self.home
591
+ self.select_scheme("posix_home")
592
+ else:
593
+ if self.prefix is None:
594
+ self.prefix = os.path.normpath(sys.prefix)
595
+
596
+ self.install_base = self.install_platbase = self.prefix
597
+ try:
598
+ self.select_scheme(os.name)
599
+ except KeyError:
600
+ raise DistutilsPlatformError(
601
+ f"I don't know how to install stuff on '{os.name}'"
602
+ )
603
+
604
+ def select_scheme(self, name):
605
+ _select_scheme(self, name)
606
+
607
+ def _expand_attrs(self, attrs):
608
+ for attr in attrs:
609
+ val = getattr(self, attr)
610
+ if val is not None:
611
+ if os.name in ('posix', 'nt'):
612
+ val = os.path.expanduser(val)
613
+ val = subst_vars(val, self.config_vars)
614
+ setattr(self, attr, val)
615
+
616
+ def expand_basedirs(self):
617
+ """Calls `os.path.expanduser` on install_base, install_platbase and
618
+ root."""
619
+ self._expand_attrs(['install_base', 'install_platbase', 'root'])
620
+
621
+ def expand_dirs(self):
622
+ """Calls `os.path.expanduser` on install dirs."""
623
+ self._expand_attrs([
624
+ 'install_purelib',
625
+ 'install_platlib',
626
+ 'install_lib',
627
+ 'install_headers',
628
+ 'install_scripts',
629
+ 'install_data',
630
+ ])
631
+
632
+ def convert_paths(self, *names):
633
+ """Call `convert_path` over `names`."""
634
+ for name in names:
635
+ attr = "install_" + name
636
+ setattr(self, attr, convert_path(getattr(self, attr)))
637
+
638
+ def handle_extra_path(self):
639
+ """Set `path_file` and `extra_dirs` using `extra_path`."""
640
+ if self.extra_path is None:
641
+ self.extra_path = self.distribution.extra_path
642
+
643
+ if self.extra_path is not None:
644
+ log.warning(
645
+ "Distribution option extra_path is deprecated. "
646
+ "See issue27919 for details."
647
+ )
648
+ if isinstance(self.extra_path, str):
649
+ self.extra_path = self.extra_path.split(',')
650
+
651
+ if len(self.extra_path) == 1:
652
+ path_file = extra_dirs = self.extra_path[0]
653
+ elif len(self.extra_path) == 2:
654
+ path_file, extra_dirs = self.extra_path
655
+ else:
656
+ raise DistutilsOptionError(
657
+ "'extra_path' option must be a list, tuple, or "
658
+ "comma-separated string with 1 or 2 elements"
659
+ )
660
+
661
+ # convert to local form in case Unix notation used (as it
662
+ # should be in setup scripts)
663
+ extra_dirs = convert_path(extra_dirs)
664
+ else:
665
+ path_file = None
666
+ extra_dirs = ''
667
+
668
+ # XXX should we warn if path_file and not extra_dirs? (in which
669
+ # case the path file would be harmless but pointless)
670
+ self.path_file = path_file
671
+ self.extra_dirs = extra_dirs
672
+
673
+ def change_roots(self, *names):
674
+ """Change the install directories pointed by name using root."""
675
+ for name in names:
676
+ attr = "install_" + name
677
+ setattr(self, attr, change_root(self.root, getattr(self, attr)))
678
+
679
+ def create_home_path(self):
680
+ """Create directories under ~."""
681
+ if not self.user:
682
+ return
683
+ home = convert_path(os.path.expanduser("~"))
684
+ for path in self.config_vars.values():
685
+ if str(path).startswith(home) and not os.path.isdir(path):
686
+ self.debug_print(f"os.makedirs('{path}', 0o700)")
687
+ os.makedirs(path, 0o700)
688
+
689
+ # -- Command execution methods -------------------------------------
690
+
691
+ def run(self):
692
+ """Runs the command."""
693
+ # Obviously have to build before we can install
694
+ if not self.skip_build:
695
+ self.run_command('build')
696
+ # If we built for any other platform, we can't install.
697
+ build_plat = self.distribution.get_command_obj('build').plat_name
698
+ # check warn_dir - it is a clue that the 'install' is happening
699
+ # internally, and not to sys.path, so we don't check the platform
700
+ # matches what we are running.
701
+ if self.warn_dir and build_plat != get_platform():
702
+ raise DistutilsPlatformError("Can't install when cross-compiling")
703
+
704
+ # Run all sub-commands (at least those that need to be run)
705
+ for cmd_name in self.get_sub_commands():
706
+ self.run_command(cmd_name)
707
+
708
+ if self.path_file:
709
+ self.create_path_file()
710
+
711
+ # write list of installed files, if requested.
712
+ if self.record:
713
+ outputs = self.get_outputs()
714
+ if self.root: # strip any package prefix
715
+ root_len = len(self.root)
716
+ for counter in range(len(outputs)):
717
+ outputs[counter] = outputs[counter][root_len:]
718
+ self.execute(
719
+ write_file,
720
+ (self.record, outputs),
721
+ f"writing list of installed files to '{self.record}'",
722
+ )
723
+
724
+ sys_path = map(os.path.normpath, sys.path)
725
+ sys_path = map(os.path.normcase, sys_path)
726
+ install_lib = os.path.normcase(os.path.normpath(self.install_lib))
727
+ if (
728
+ self.warn_dir
729
+ and not (self.path_file and self.install_path_file)
730
+ and install_lib not in sys_path
731
+ ):
732
+ log.debug(
733
+ (
734
+ "modules installed to '%s', which is not in "
735
+ "Python's module search path (sys.path) -- "
736
+ "you'll have to change the search path yourself"
737
+ ),
738
+ self.install_lib,
739
+ )
740
+
741
+ def create_path_file(self):
742
+ """Creates the .pth file"""
743
+ filename = os.path.join(self.install_libbase, self.path_file + ".pth")
744
+ if self.install_path_file:
745
+ self.execute(
746
+ write_file, (filename, [self.extra_dirs]), f"creating {filename}"
747
+ )
748
+ else:
749
+ self.warn(f"path file '{filename}' not created")
750
+
751
+ # -- Reporting methods ---------------------------------------------
752
+
753
+ def get_outputs(self):
754
+ """Assembles the outputs of all the sub-commands."""
755
+ outputs = []
756
+ for cmd_name in self.get_sub_commands():
757
+ cmd = self.get_finalized_command(cmd_name)
758
+ # Add the contents of cmd.get_outputs(), ensuring
759
+ # that outputs doesn't contain duplicate entries
760
+ for filename in cmd.get_outputs():
761
+ if filename not in outputs:
762
+ outputs.append(filename)
763
+
764
+ if self.path_file and self.install_path_file:
765
+ outputs.append(os.path.join(self.install_libbase, self.path_file + ".pth"))
766
+
767
+ return outputs
768
+
769
+ def get_inputs(self):
770
+ """Returns the inputs of all the sub-commands"""
771
+ # XXX gee, this looks familiar ;-(
772
+ inputs = []
773
+ for cmd_name in self.get_sub_commands():
774
+ cmd = self.get_finalized_command(cmd_name)
775
+ inputs.extend(cmd.get_inputs())
776
+
777
+ return inputs
778
+
779
+ # -- Predicates for sub-command list -------------------------------
780
+
781
+ def has_lib(self):
782
+ """Returns true if the current distribution has any Python
783
+ modules to install."""
784
+ return (
785
+ self.distribution.has_pure_modules() or self.distribution.has_ext_modules()
786
+ )
787
+
788
+ def has_headers(self):
789
+ """Returns true if the current distribution has any headers to
790
+ install."""
791
+ return self.distribution.has_headers()
792
+
793
+ def has_scripts(self):
794
+ """Returns true if the current distribution has any scripts to.
795
+ install."""
796
+ return self.distribution.has_scripts()
797
+
798
+ def has_data(self):
799
+ """Returns true if the current distribution has any data to.
800
+ install."""
801
+ return self.distribution.has_data_files()
802
+
803
+ # 'sub_commands': a list of commands this command might have to run to
804
+ # get its work done. See cmd.py for more info.
805
+ sub_commands = [
806
+ ('install_lib', has_lib),
807
+ ('install_headers', has_headers),
808
+ ('install_scripts', has_scripts),
809
+ ('install_data', has_data),
810
+ ('install_egg_info', lambda self: True),
811
+ ]
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/install_data.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.install_data
2
+
3
+ Implements the Distutils 'install_data' command, for installing
4
+ platform-independent data files."""
5
+
6
+ # contributed by Bastian Kleineidam
7
+
8
+ from __future__ import annotations
9
+
10
+ import functools
11
+ import os
12
+ from collections.abc import Iterable
13
+
14
+ from ..core import Command
15
+ from ..util import change_root, convert_path
16
+
17
+
18
+ class install_data(Command):
19
+ description = "install data files"
20
+
21
+ user_options = [
22
+ (
23
+ 'install-dir=',
24
+ 'd',
25
+ "base directory for installing data files [default: installation base dir]",
26
+ ),
27
+ ('root=', None, "install everything relative to this alternate root directory"),
28
+ ('force', 'f', "force installation (overwrite existing files)"),
29
+ ]
30
+
31
+ boolean_options = ['force']
32
+
33
+ def initialize_options(self):
34
+ self.install_dir = None
35
+ self.outfiles = []
36
+ self.root = None
37
+ self.force = False
38
+ self.data_files = self.distribution.data_files
39
+ self.warn_dir = True
40
+
41
+ def finalize_options(self):
42
+ self.set_undefined_options(
43
+ 'install',
44
+ ('install_data', 'install_dir'),
45
+ ('root', 'root'),
46
+ ('force', 'force'),
47
+ )
48
+
49
+ def run(self):
50
+ self.mkpath(self.install_dir)
51
+ for f in self.data_files:
52
+ self._copy(f)
53
+
54
+ @functools.singledispatchmethod
55
+ def _copy(self, f: tuple[str | os.PathLike, Iterable[str | os.PathLike]]):
56
+ # it's a tuple with path to install to and a list of files
57
+ dir = convert_path(f[0])
58
+ if not os.path.isabs(dir):
59
+ dir = os.path.join(self.install_dir, dir)
60
+ elif self.root:
61
+ dir = change_root(self.root, dir)
62
+ self.mkpath(dir)
63
+
64
+ if f[1] == []:
65
+ # If there are no files listed, the user must be
66
+ # trying to create an empty directory, so add the
67
+ # directory to the list of output files.
68
+ self.outfiles.append(dir)
69
+ else:
70
+ # Copy files, adding them to the list of output files.
71
+ for data in f[1]:
72
+ data = convert_path(data)
73
+ (out, _) = self.copy_file(data, dir)
74
+ self.outfiles.append(out)
75
+
76
+ @_copy.register(str)
77
+ @_copy.register(os.PathLike)
78
+ def _(self, f: str | os.PathLike):
79
+ # it's a simple file, so copy it
80
+ f = convert_path(f)
81
+ if self.warn_dir:
82
+ self.warn(
83
+ "setup script did not provide a directory for "
84
+ f"'{f}' -- installing right in '{self.install_dir}'"
85
+ )
86
+ (out, _) = self.copy_file(f, self.install_dir)
87
+ self.outfiles.append(out)
88
+
89
+ def get_inputs(self):
90
+ return self.data_files or []
91
+
92
+ def get_outputs(self):
93
+ return self.outfiles
videollama2/lib/python3.10/site-packages/setuptools/_distutils/command/install_egg_info.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ distutils.command.install_egg_info
3
+
4
+ Implements the Distutils 'install_egg_info' command, for installing
5
+ a package's PKG-INFO metadata.
6
+ """
7
+
8
+ import os
9
+ import re
10
+ import sys
11
+ from typing import ClassVar
12
+
13
+ from .. import dir_util
14
+ from .._log import log
15
+ from ..cmd import Command
16
+
17
+
18
+ class install_egg_info(Command):
19
+ """Install an .egg-info file for the package"""
20
+
21
+ description = "Install package's PKG-INFO metadata as an .egg-info file"
22
+ user_options: ClassVar[list[tuple[str, str, str]]] = [
23
+ ('install-dir=', 'd', "directory to install to"),
24
+ ]
25
+
26
+ def initialize_options(self):
27
+ self.install_dir = None
28
+
29
+ @property
30
+ def basename(self):
31
+ """
32
+ Allow basename to be overridden by child class.
33
+ Ref pypa/distutils#2.
34
+ """
35
+ name = to_filename(safe_name(self.distribution.get_name()))
36
+ version = to_filename(safe_version(self.distribution.get_version()))
37
+ return f"{name}-{version}-py{sys.version_info.major}.{sys.version_info.minor}.egg-info"
38
+
39
+ def finalize_options(self):
40
+ self.set_undefined_options('install_lib', ('install_dir', 'install_dir'))
41
+ self.target = os.path.join(self.install_dir, self.basename)
42
+ self.outputs = [self.target]
43
+
44
+ def run(self):
45
+ target = self.target
46
+ if os.path.isdir(target) and not os.path.islink(target):
47
+ dir_util.remove_tree(target, dry_run=self.dry_run)
48
+ elif os.path.exists(target):
49
+ self.execute(os.unlink, (self.target,), "Removing " + target)
50
+ elif not os.path.isdir(self.install_dir):
51
+ self.execute(
52
+ os.makedirs, (self.install_dir,), "Creating " + self.install_dir
53
+ )
54
+ log.info("Writing %s", target)
55
+ if not self.dry_run:
56
+ with open(target, 'w', encoding='UTF-8') as f:
57
+ self.distribution.metadata.write_pkg_file(f)
58
+
59
+ def get_outputs(self):
60
+ return self.outputs
61
+
62
+
63
+ # The following routines are taken from setuptools' pkg_resources module and
64
+ # can be replaced by importing them from pkg_resources once it is included
65
+ # in the stdlib.
66
+
67
+
68
+ def safe_name(name):
69
+ """Convert an arbitrary string to a standard distribution name
70
+
71
+ Any runs of non-alphanumeric/. characters are replaced with a single '-'.
72
+ """
73
+ return re.sub('[^A-Za-z0-9.]+', '-', name)
74
+
75
+
76
+ def safe_version(version):
77
+ """Convert an arbitrary string to a standard version string
78
+
79
+ Spaces become dots, and all other non-alphanumeric characters become
80
+ dashes, with runs of multiple dashes condensed to a single dash.
81
+ """
82
+ version = version.replace(' ', '.')
83
+ return re.sub('[^A-Za-z0-9.]+', '-', version)
84
+
85
+
86
+ def to_filename(name):
87
+ """Convert a project or version name to its filename-escaped form
88
+
89
+ Any '-' characters are currently replaced with '_'.
90
+ """
91
+ return name.replace('-', '_')