applied-ai-018 commited on
Commit
9a4972f
·
verified ·
1 Parent(s): 1f99b4d

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. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/bleu_score.cpython-310.pyc +0 -0
  2. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/gale_church.cpython-310.pyc +0 -0
  3. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/gdfa.cpython-310.pyc +0 -0
  4. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/gleu_score.cpython-310.pyc +0 -0
  5. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/ibm2.cpython-310.pyc +0 -0
  6. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/ibm4.cpython-310.pyc +0 -0
  7. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/ibm_model.cpython-310.pyc +0 -0
  8. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/meteor_score.cpython-310.pyc +0 -0
  9. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/metrics.cpython-310.pyc +0 -0
  10. env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/stack_decoder.cpython-310.pyc +0 -0
  11. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__init__.py +24 -0
  12. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-310.pyc +0 -0
  13. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc +0 -0
  14. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/bcppcompiler.cpython-310.pyc +0 -0
  15. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc +0 -0
  16. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-310.pyc +0 -0
  17. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/core.cpython-310.pyc +0 -0
  18. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc +0 -0
  19. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc +0 -0
  20. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dep_util.cpython-310.pyc +0 -0
  21. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dir_util.cpython-310.pyc +0 -0
  22. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dist.cpython-310.pyc +0 -0
  23. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-310.pyc +0 -0
  24. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/file_util.cpython-310.pyc +0 -0
  25. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-310.pyc +0 -0
  26. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/log.cpython-310.pyc +0 -0
  27. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/msvc9compiler.cpython-310.pyc +0 -0
  28. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/msvccompiler.cpython-310.pyc +0 -0
  29. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/py35compat.cpython-310.pyc +0 -0
  30. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/py38compat.cpython-310.pyc +0 -0
  31. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-310.pyc +0 -0
  32. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-310.pyc +0 -0
  33. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/text_file.cpython-310.pyc +0 -0
  34. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/unixccompiler.cpython-310.pyc +0 -0
  35. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/version.cpython-310.pyc +0 -0
  36. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc +0 -0
  37. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/_msvccompiler.py +561 -0
  38. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/archive_util.py +256 -0
  39. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/bcppcompiler.py +393 -0
  40. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/ccompiler.py +1123 -0
  41. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/cmd.py +403 -0
  42. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/config.py +130 -0
  43. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/core.py +249 -0
  44. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.py +425 -0
  45. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/debug.py +5 -0
  46. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/dep_util.py +92 -0
  47. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/dir_util.py +210 -0
  48. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/dist.py +1257 -0
  49. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/errors.py +97 -0
  50. env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/extension.py +240 -0
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/bleu_score.cpython-310.pyc ADDED
Binary file (26.7 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/gale_church.cpython-310.pyc ADDED
Binary file (7.95 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/gdfa.cpython-310.pyc ADDED
Binary file (5.14 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/gleu_score.cpython-310.pyc ADDED
Binary file (7.63 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/ibm2.cpython-310.pyc ADDED
Binary file (11.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/ibm4.cpython-310.pyc ADDED
Binary file (16.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/ibm_model.cpython-310.pyc ADDED
Binary file (16.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/meteor_score.cpython-310.pyc ADDED
Binary file (15.1 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/metrics.cpython-310.pyc ADDED
Binary file (1.28 kB). View file
 
env-llmeval/lib/python3.10/site-packages/nltk/translate/__pycache__/stack_decoder.cpython-310.pyc ADDED
Binary file (17.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__init__.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils
2
+
3
+ The main package for the Python Module Distribution Utilities. Normally
4
+ used from a setup script as
5
+
6
+ from distutils.core import setup
7
+
8
+ setup (...)
9
+ """
10
+
11
+ import sys
12
+ import importlib
13
+
14
+ __version__ = sys.version[:sys.version.index(' ')]
15
+
16
+
17
+ try:
18
+ # Allow Debian and pkgsrc (only) to customize system
19
+ # behavior. Ref pypa/distutils#2 and pypa/distutils#16.
20
+ # This hook is deprecated and no other environments
21
+ # should use it.
22
+ importlib.import_module('_distutils_system_mod')
23
+ except ImportError:
24
+ pass
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-310.pyc ADDED
Binary file (13.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc ADDED
Binary file (6.56 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/bcppcompiler.cpython-310.pyc ADDED
Binary file (6.55 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc ADDED
Binary file (33.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-310.pyc ADDED
Binary file (13.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/core.cpython-310.pyc ADDED
Binary file (7.09 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc ADDED
Binary file (8.99 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc ADDED
Binary file (249 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dep_util.cpython-310.pyc ADDED
Binary file (2.77 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dir_util.cpython-310.pyc ADDED
Binary file (5.88 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/dist.cpython-310.pyc ADDED
Binary file (34 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-310.pyc ADDED
Binary file (10.6 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/file_util.cpython-310.pyc ADDED
Binary file (5.98 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-310.pyc ADDED
Binary file (10.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/log.cpython-310.pyc ADDED
Binary file (2.31 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/msvc9compiler.cpython-310.pyc ADDED
Binary file (17.6 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/msvccompiler.cpython-310.pyc ADDED
Binary file (14.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/py35compat.cpython-310.pyc ADDED
Binary file (625 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/py38compat.cpython-310.pyc ADDED
Binary file (422 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-310.pyc ADDED
Binary file (2.89 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-310.pyc ADDED
Binary file (12.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/text_file.cpython-310.pyc ADDED
Binary file (8.47 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/unixccompiler.cpython-310.pyc ADDED
Binary file (6.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/version.cpython-310.pyc ADDED
Binary file (7.84 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc ADDED
Binary file (5.34 kB). View file
 
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/_msvccompiler.py ADDED
@@ -0,0 +1,561 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils._msvccompiler
2
+
3
+ Contains MSVCCompiler, an implementation of the abstract CCompiler class
4
+ for Microsoft Visual Studio 2015.
5
+
6
+ The module is compatible with VS 2015 and later. You can find legacy support
7
+ for older versions in distutils.msvc9compiler and distutils.msvccompiler.
8
+ """
9
+
10
+ # Written by Perry Stoll
11
+ # hacked by Robin Becker and Thomas Heller to do a better job of
12
+ # finding DevStudio (through the registry)
13
+ # ported to VS 2005 and VS 2008 by Christian Heimes
14
+ # ported to VS 2015 by Steve Dower
15
+
16
+ import os
17
+ import subprocess
18
+ import contextlib
19
+ import warnings
20
+ import unittest.mock
21
+ with contextlib.suppress(ImportError):
22
+ import winreg
23
+
24
+ from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
25
+ CompileError, LibError, LinkError
26
+ from distutils.ccompiler import CCompiler, gen_lib_options
27
+ from distutils import log
28
+ from distutils.util import get_platform
29
+
30
+ from itertools import count
31
+
32
+ def _find_vc2015():
33
+ try:
34
+ key = winreg.OpenKeyEx(
35
+ winreg.HKEY_LOCAL_MACHINE,
36
+ r"Software\Microsoft\VisualStudio\SxS\VC7",
37
+ access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
38
+ )
39
+ except OSError:
40
+ log.debug("Visual C++ is not registered")
41
+ return None, None
42
+
43
+ best_version = 0
44
+ best_dir = None
45
+ with key:
46
+ for i in count():
47
+ try:
48
+ v, vc_dir, vt = winreg.EnumValue(key, i)
49
+ except OSError:
50
+ break
51
+ if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
52
+ try:
53
+ version = int(float(v))
54
+ except (ValueError, TypeError):
55
+ continue
56
+ if version >= 14 and version > best_version:
57
+ best_version, best_dir = version, vc_dir
58
+ return best_version, best_dir
59
+
60
+ def _find_vc2017():
61
+ """Returns "15, path" based on the result of invoking vswhere.exe
62
+ If no install is found, returns "None, None"
63
+
64
+ The version is returned to avoid unnecessarily changing the function
65
+ result. It may be ignored when the path is not None.
66
+
67
+ If vswhere.exe is not available, by definition, VS 2017 is not
68
+ installed.
69
+ """
70
+ root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
71
+ if not root:
72
+ return None, None
73
+
74
+ try:
75
+ path = subprocess.check_output([
76
+ os.path.join(root, "Microsoft Visual Studio", "Installer", "vswhere.exe"),
77
+ "-latest",
78
+ "-prerelease",
79
+ "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
80
+ "-property", "installationPath",
81
+ "-products", "*",
82
+ ], encoding="mbcs", errors="strict").strip()
83
+ except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
84
+ return None, None
85
+
86
+ path = os.path.join(path, "VC", "Auxiliary", "Build")
87
+ if os.path.isdir(path):
88
+ return 15, path
89
+
90
+ return None, None
91
+
92
+ PLAT_SPEC_TO_RUNTIME = {
93
+ 'x86' : 'x86',
94
+ 'x86_amd64' : 'x64',
95
+ 'x86_arm' : 'arm',
96
+ 'x86_arm64' : 'arm64'
97
+ }
98
+
99
+ def _find_vcvarsall(plat_spec):
100
+ # bpo-38597: Removed vcruntime return value
101
+ _, best_dir = _find_vc2017()
102
+
103
+ if not best_dir:
104
+ best_version, best_dir = _find_vc2015()
105
+
106
+ if not best_dir:
107
+ log.debug("No suitable Visual C++ version found")
108
+ return None, None
109
+
110
+ vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
111
+ if not os.path.isfile(vcvarsall):
112
+ log.debug("%s cannot be found", vcvarsall)
113
+ return None, None
114
+
115
+ return vcvarsall, None
116
+
117
+ def _get_vc_env(plat_spec):
118
+ if os.getenv("DISTUTILS_USE_SDK"):
119
+ return {
120
+ key.lower(): value
121
+ for key, value in os.environ.items()
122
+ }
123
+
124
+ vcvarsall, _ = _find_vcvarsall(plat_spec)
125
+ if not vcvarsall:
126
+ raise DistutilsPlatformError("Unable to find vcvarsall.bat")
127
+
128
+ try:
129
+ out = subprocess.check_output(
130
+ 'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
131
+ stderr=subprocess.STDOUT,
132
+ ).decode('utf-16le', errors='replace')
133
+ except subprocess.CalledProcessError as exc:
134
+ log.error(exc.output)
135
+ raise DistutilsPlatformError("Error executing {}"
136
+ .format(exc.cmd))
137
+
138
+ env = {
139
+ key.lower(): value
140
+ for key, _, value in
141
+ (line.partition('=') for line in out.splitlines())
142
+ if key and value
143
+ }
144
+
145
+ return env
146
+
147
+ def _find_exe(exe, paths=None):
148
+ """Return path to an MSVC executable program.
149
+
150
+ Tries to find the program in several places: first, one of the
151
+ MSVC program search paths from the registry; next, the directories
152
+ in the PATH environment variable. If any of those work, return an
153
+ absolute path that is known to exist. If none of them work, just
154
+ return the original program name, 'exe'.
155
+ """
156
+ if not paths:
157
+ paths = os.getenv('path').split(os.pathsep)
158
+ for p in paths:
159
+ fn = os.path.join(os.path.abspath(p), exe)
160
+ if os.path.isfile(fn):
161
+ return fn
162
+ return exe
163
+
164
+ # A map keyed by get_platform() return values to values accepted by
165
+ # 'vcvarsall.bat'. Always cross-compile from x86 to work with the
166
+ # lighter-weight MSVC installs that do not include native 64-bit tools.
167
+ PLAT_TO_VCVARS = {
168
+ 'win32' : 'x86',
169
+ 'win-amd64' : 'x86_amd64',
170
+ 'win-arm32' : 'x86_arm',
171
+ 'win-arm64' : 'x86_arm64'
172
+ }
173
+
174
+ class MSVCCompiler(CCompiler) :
175
+ """Concrete class that implements an interface to Microsoft Visual C++,
176
+ as defined by the CCompiler abstract class."""
177
+
178
+ compiler_type = 'msvc'
179
+
180
+ # Just set this so CCompiler's constructor doesn't barf. We currently
181
+ # don't use the 'set_executables()' bureaucracy provided by CCompiler,
182
+ # as it really isn't necessary for this sort of single-compiler class.
183
+ # Would be nice to have a consistent interface with UnixCCompiler,
184
+ # though, so it's worth thinking about.
185
+ executables = {}
186
+
187
+ # Private class data (need to distinguish C from C++ source for compiler)
188
+ _c_extensions = ['.c']
189
+ _cpp_extensions = ['.cc', '.cpp', '.cxx']
190
+ _rc_extensions = ['.rc']
191
+ _mc_extensions = ['.mc']
192
+
193
+ # Needed for the filename generation methods provided by the
194
+ # base class, CCompiler.
195
+ src_extensions = (_c_extensions + _cpp_extensions +
196
+ _rc_extensions + _mc_extensions)
197
+ res_extension = '.res'
198
+ obj_extension = '.obj'
199
+ static_lib_extension = '.lib'
200
+ shared_lib_extension = '.dll'
201
+ static_lib_format = shared_lib_format = '%s%s'
202
+ exe_extension = '.exe'
203
+
204
+
205
+ def __init__(self, verbose=0, dry_run=0, force=0):
206
+ CCompiler.__init__ (self, verbose, dry_run, force)
207
+ # target platform (.plat_name is consistent with 'bdist')
208
+ self.plat_name = None
209
+ self.initialized = False
210
+
211
+ def initialize(self, plat_name=None):
212
+ # multi-init means we would need to check platform same each time...
213
+ assert not self.initialized, "don't init multiple times"
214
+ if plat_name is None:
215
+ plat_name = get_platform()
216
+ # sanity check for platforms to prevent obscure errors later.
217
+ if plat_name not in PLAT_TO_VCVARS:
218
+ raise DistutilsPlatformError("--plat-name must be one of {}"
219
+ .format(tuple(PLAT_TO_VCVARS)))
220
+
221
+ # Get the vcvarsall.bat spec for the requested platform.
222
+ plat_spec = PLAT_TO_VCVARS[plat_name]
223
+
224
+ vc_env = _get_vc_env(plat_spec)
225
+ if not vc_env:
226
+ raise DistutilsPlatformError("Unable to find a compatible "
227
+ "Visual Studio installation.")
228
+
229
+ self._paths = vc_env.get('path', '')
230
+ paths = self._paths.split(os.pathsep)
231
+ self.cc = _find_exe("cl.exe", paths)
232
+ self.linker = _find_exe("link.exe", paths)
233
+ self.lib = _find_exe("lib.exe", paths)
234
+ self.rc = _find_exe("rc.exe", paths) # resource compiler
235
+ self.mc = _find_exe("mc.exe", paths) # message compiler
236
+ self.mt = _find_exe("mt.exe", paths) # message compiler
237
+
238
+ for dir in vc_env.get('include', '').split(os.pathsep):
239
+ if dir:
240
+ self.add_include_dir(dir.rstrip(os.sep))
241
+
242
+ for dir in vc_env.get('lib', '').split(os.pathsep):
243
+ if dir:
244
+ self.add_library_dir(dir.rstrip(os.sep))
245
+
246
+ self.preprocess_options = None
247
+ # bpo-38597: Always compile with dynamic linking
248
+ # Future releases of Python 3.x will include all past
249
+ # versions of vcruntime*.dll for compatibility.
250
+ self.compile_options = [
251
+ '/nologo', '/O2', '/W3', '/GL', '/DNDEBUG', '/MD'
252
+ ]
253
+
254
+ self.compile_options_debug = [
255
+ '/nologo', '/Od', '/MDd', '/Zi', '/W3', '/D_DEBUG'
256
+ ]
257
+
258
+ ldflags = [
259
+ '/nologo', '/INCREMENTAL:NO', '/LTCG'
260
+ ]
261
+
262
+ ldflags_debug = [
263
+ '/nologo', '/INCREMENTAL:NO', '/LTCG', '/DEBUG:FULL'
264
+ ]
265
+
266
+ self.ldflags_exe = [*ldflags, '/MANIFEST:EMBED,ID=1']
267
+ self.ldflags_exe_debug = [*ldflags_debug, '/MANIFEST:EMBED,ID=1']
268
+ self.ldflags_shared = [*ldflags, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
269
+ self.ldflags_shared_debug = [*ldflags_debug, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
270
+ self.ldflags_static = [*ldflags]
271
+ self.ldflags_static_debug = [*ldflags_debug]
272
+
273
+ self._ldflags = {
274
+ (CCompiler.EXECUTABLE, None): self.ldflags_exe,
275
+ (CCompiler.EXECUTABLE, False): self.ldflags_exe,
276
+ (CCompiler.EXECUTABLE, True): self.ldflags_exe_debug,
277
+ (CCompiler.SHARED_OBJECT, None): self.ldflags_shared,
278
+ (CCompiler.SHARED_OBJECT, False): self.ldflags_shared,
279
+ (CCompiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
280
+ (CCompiler.SHARED_LIBRARY, None): self.ldflags_static,
281
+ (CCompiler.SHARED_LIBRARY, False): self.ldflags_static,
282
+ (CCompiler.SHARED_LIBRARY, True): self.ldflags_static_debug,
283
+ }
284
+
285
+ self.initialized = True
286
+
287
+ # -- Worker methods ------------------------------------------------
288
+
289
+ def object_filenames(self,
290
+ source_filenames,
291
+ strip_dir=0,
292
+ output_dir=''):
293
+ ext_map = {
294
+ **{ext: self.obj_extension for ext in self.src_extensions},
295
+ **{ext: self.res_extension for ext in self._rc_extensions + self._mc_extensions},
296
+ }
297
+
298
+ output_dir = output_dir or ''
299
+
300
+ def make_out_path(p):
301
+ base, ext = os.path.splitext(p)
302
+ if strip_dir:
303
+ base = os.path.basename(base)
304
+ else:
305
+ _, base = os.path.splitdrive(base)
306
+ if base.startswith((os.path.sep, os.path.altsep)):
307
+ base = base[1:]
308
+ try:
309
+ # XXX: This may produce absurdly long paths. We should check
310
+ # the length of the result and trim base until we fit within
311
+ # 260 characters.
312
+ return os.path.join(output_dir, base + ext_map[ext])
313
+ except LookupError:
314
+ # Better to raise an exception instead of silently continuing
315
+ # and later complain about sources and targets having
316
+ # different lengths
317
+ raise CompileError("Don't know how to compile {}".format(p))
318
+
319
+ return list(map(make_out_path, source_filenames))
320
+
321
+
322
+ def compile(self, sources,
323
+ output_dir=None, macros=None, include_dirs=None, debug=0,
324
+ extra_preargs=None, extra_postargs=None, depends=None):
325
+
326
+ if not self.initialized:
327
+ self.initialize()
328
+ compile_info = self._setup_compile(output_dir, macros, include_dirs,
329
+ sources, depends, extra_postargs)
330
+ macros, objects, extra_postargs, pp_opts, build = compile_info
331
+
332
+ compile_opts = extra_preargs or []
333
+ compile_opts.append('/c')
334
+ if debug:
335
+ compile_opts.extend(self.compile_options_debug)
336
+ else:
337
+ compile_opts.extend(self.compile_options)
338
+
339
+
340
+ add_cpp_opts = False
341
+
342
+ for obj in objects:
343
+ try:
344
+ src, ext = build[obj]
345
+ except KeyError:
346
+ continue
347
+ if debug:
348
+ # pass the full pathname to MSVC in debug mode,
349
+ # this allows the debugger to find the source file
350
+ # without asking the user to browse for it
351
+ src = os.path.abspath(src)
352
+
353
+ if ext in self._c_extensions:
354
+ input_opt = "/Tc" + src
355
+ elif ext in self._cpp_extensions:
356
+ input_opt = "/Tp" + src
357
+ add_cpp_opts = True
358
+ elif ext in self._rc_extensions:
359
+ # compile .RC to .RES file
360
+ input_opt = src
361
+ output_opt = "/fo" + obj
362
+ try:
363
+ self.spawn([self.rc] + pp_opts + [output_opt, input_opt])
364
+ except DistutilsExecError as msg:
365
+ raise CompileError(msg)
366
+ continue
367
+ elif ext in self._mc_extensions:
368
+ # Compile .MC to .RC file to .RES file.
369
+ # * '-h dir' specifies the directory for the
370
+ # generated include file
371
+ # * '-r dir' specifies the target directory of the
372
+ # generated RC file and the binary message resource
373
+ # it includes
374
+ #
375
+ # For now (since there are no options to change this),
376
+ # we use the source-directory for the include file and
377
+ # the build directory for the RC file and message
378
+ # resources. This works at least for win32all.
379
+ h_dir = os.path.dirname(src)
380
+ rc_dir = os.path.dirname(obj)
381
+ try:
382
+ # first compile .MC to .RC and .H file
383
+ self.spawn([self.mc, '-h', h_dir, '-r', rc_dir, src])
384
+ base, _ = os.path.splitext(os.path.basename (src))
385
+ rc_file = os.path.join(rc_dir, base + '.rc')
386
+ # then compile .RC to .RES file
387
+ self.spawn([self.rc, "/fo" + obj, rc_file])
388
+
389
+ except DistutilsExecError as msg:
390
+ raise CompileError(msg)
391
+ continue
392
+ else:
393
+ # how to handle this file?
394
+ raise CompileError("Don't know how to compile {} to {}"
395
+ .format(src, obj))
396
+
397
+ args = [self.cc] + compile_opts + pp_opts
398
+ if add_cpp_opts:
399
+ args.append('/EHsc')
400
+ args.append(input_opt)
401
+ args.append("/Fo" + obj)
402
+ args.extend(extra_postargs)
403
+
404
+ try:
405
+ self.spawn(args)
406
+ except DistutilsExecError as msg:
407
+ raise CompileError(msg)
408
+
409
+ return objects
410
+
411
+
412
+ def create_static_lib(self,
413
+ objects,
414
+ output_libname,
415
+ output_dir=None,
416
+ debug=0,
417
+ target_lang=None):
418
+
419
+ if not self.initialized:
420
+ self.initialize()
421
+ objects, output_dir = self._fix_object_args(objects, output_dir)
422
+ output_filename = self.library_filename(output_libname,
423
+ output_dir=output_dir)
424
+
425
+ if self._need_link(objects, output_filename):
426
+ lib_args = objects + ['/OUT:' + output_filename]
427
+ if debug:
428
+ pass # XXX what goes here?
429
+ try:
430
+ log.debug('Executing "%s" %s', self.lib, ' '.join(lib_args))
431
+ self.spawn([self.lib] + lib_args)
432
+ except DistutilsExecError as msg:
433
+ raise LibError(msg)
434
+ else:
435
+ log.debug("skipping %s (up-to-date)", output_filename)
436
+
437
+
438
+ def link(self,
439
+ target_desc,
440
+ objects,
441
+ output_filename,
442
+ output_dir=None,
443
+ libraries=None,
444
+ library_dirs=None,
445
+ runtime_library_dirs=None,
446
+ export_symbols=None,
447
+ debug=0,
448
+ extra_preargs=None,
449
+ extra_postargs=None,
450
+ build_temp=None,
451
+ target_lang=None):
452
+
453
+ if not self.initialized:
454
+ self.initialize()
455
+ objects, output_dir = self._fix_object_args(objects, output_dir)
456
+ fixed_args = self._fix_lib_args(libraries, library_dirs,
457
+ runtime_library_dirs)
458
+ libraries, library_dirs, runtime_library_dirs = fixed_args
459
+
460
+ if runtime_library_dirs:
461
+ self.warn("I don't know what to do with 'runtime_library_dirs': "
462
+ + str(runtime_library_dirs))
463
+
464
+ lib_opts = gen_lib_options(self,
465
+ library_dirs, runtime_library_dirs,
466
+ libraries)
467
+ if output_dir is not None:
468
+ output_filename = os.path.join(output_dir, output_filename)
469
+
470
+ if self._need_link(objects, output_filename):
471
+ ldflags = self._ldflags[target_desc, debug]
472
+
473
+ export_opts = ["/EXPORT:" + sym for sym in (export_symbols or [])]
474
+
475
+ ld_args = (ldflags + lib_opts + export_opts +
476
+ objects + ['/OUT:' + output_filename])
477
+
478
+ # The MSVC linker generates .lib and .exp files, which cannot be
479
+ # suppressed by any linker switches. The .lib files may even be
480
+ # needed! Make sure they are generated in the temporary build
481
+ # directory. Since they have different names for debug and release
482
+ # builds, they can go into the same directory.
483
+ build_temp = os.path.dirname(objects[0])
484
+ if export_symbols is not None:
485
+ (dll_name, dll_ext) = os.path.splitext(
486
+ os.path.basename(output_filename))
487
+ implib_file = os.path.join(
488
+ build_temp,
489
+ self.library_filename(dll_name))
490
+ ld_args.append ('/IMPLIB:' + implib_file)
491
+
492
+ if extra_preargs:
493
+ ld_args[:0] = extra_preargs
494
+ if extra_postargs:
495
+ ld_args.extend(extra_postargs)
496
+
497
+ output_dir = os.path.dirname(os.path.abspath(output_filename))
498
+ self.mkpath(output_dir)
499
+ try:
500
+ log.debug('Executing "%s" %s', self.linker, ' '.join(ld_args))
501
+ self.spawn([self.linker] + ld_args)
502
+ except DistutilsExecError as msg:
503
+ raise LinkError(msg)
504
+ else:
505
+ log.debug("skipping %s (up-to-date)", output_filename)
506
+
507
+ def spawn(self, cmd):
508
+ env = dict(os.environ, PATH=self._paths)
509
+ with self._fallback_spawn(cmd, env) as fallback:
510
+ return super().spawn(cmd, env=env)
511
+ return fallback.value
512
+
513
+ @contextlib.contextmanager
514
+ def _fallback_spawn(self, cmd, env):
515
+ """
516
+ Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
517
+ so the 'env' kwarg causes a TypeError. Detect this condition and
518
+ restore the legacy, unsafe behavior.
519
+ """
520
+ bag = type('Bag', (), {})()
521
+ try:
522
+ yield bag
523
+ except TypeError as exc:
524
+ if "unexpected keyword argument 'env'" not in str(exc):
525
+ raise
526
+ else:
527
+ return
528
+ warnings.warn(
529
+ "Fallback spawn triggered. Please update distutils monkeypatch.")
530
+ with unittest.mock.patch('os.environ', env):
531
+ bag.value = super().spawn(cmd)
532
+
533
+ # -- Miscellaneous methods -----------------------------------------
534
+ # These are all used by the 'gen_lib_options() function, in
535
+ # ccompiler.py.
536
+
537
+ def library_dir_option(self, dir):
538
+ return "/LIBPATH:" + dir
539
+
540
+ def runtime_library_dir_option(self, dir):
541
+ raise DistutilsPlatformError(
542
+ "don't know how to set runtime library search path for MSVC")
543
+
544
+ def library_option(self, lib):
545
+ return self.library_filename(lib)
546
+
547
+ def find_library_file(self, dirs, lib, debug=0):
548
+ # Prefer a debugging library if found (and requested), but deal
549
+ # with it if we don't have one.
550
+ if debug:
551
+ try_names = [lib + "_d", lib]
552
+ else:
553
+ try_names = [lib]
554
+ for dir in dirs:
555
+ for name in try_names:
556
+ libfile = os.path.join(dir, self.library_filename(name))
557
+ if os.path.isfile(libfile):
558
+ return libfile
559
+ else:
560
+ # Oops, didn't find it in *any* of 'dirs'
561
+ return None
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/archive_util.py ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.archive_util
2
+
3
+ Utility functions for creating archive files (tarballs, zip files,
4
+ that sort of thing)."""
5
+
6
+ import os
7
+ from warnings import warn
8
+ import sys
9
+
10
+ try:
11
+ import zipfile
12
+ except ImportError:
13
+ zipfile = None
14
+
15
+
16
+ from distutils.errors import DistutilsExecError
17
+ from distutils.spawn import spawn
18
+ from distutils.dir_util import mkpath
19
+ from distutils import log
20
+
21
+ try:
22
+ from pwd import getpwnam
23
+ except ImportError:
24
+ getpwnam = None
25
+
26
+ try:
27
+ from grp import getgrnam
28
+ except ImportError:
29
+ getgrnam = None
30
+
31
+ def _get_gid(name):
32
+ """Returns a gid, given a group name."""
33
+ if getgrnam is None or name is None:
34
+ return None
35
+ try:
36
+ result = getgrnam(name)
37
+ except KeyError:
38
+ result = None
39
+ if result is not None:
40
+ return result[2]
41
+ return None
42
+
43
+ def _get_uid(name):
44
+ """Returns an uid, given a user name."""
45
+ if getpwnam is None or name is None:
46
+ return None
47
+ try:
48
+ result = getpwnam(name)
49
+ except KeyError:
50
+ result = None
51
+ if result is not None:
52
+ return result[2]
53
+ return None
54
+
55
+ def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
56
+ owner=None, group=None):
57
+ """Create a (possibly compressed) tar file from all the files under
58
+ 'base_dir'.
59
+
60
+ 'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or
61
+ None. ("compress" will be deprecated in Python 3.2)
62
+
63
+ 'owner' and 'group' can be used to define an owner and a group for the
64
+ archive that is being built. If not provided, the current owner and group
65
+ will be used.
66
+
67
+ The output tar file will be named 'base_dir' + ".tar", possibly plus
68
+ the appropriate compression extension (".gz", ".bz2", ".xz" or ".Z").
69
+
70
+ Returns the output filename.
71
+ """
72
+ tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', 'xz': 'xz', None: '',
73
+ 'compress': ''}
74
+ compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz',
75
+ 'compress': '.Z'}
76
+
77
+ # flags for compression program, each element of list will be an argument
78
+ if compress is not None and compress not in compress_ext.keys():
79
+ raise ValueError(
80
+ "bad value for 'compress': must be None, 'gzip', 'bzip2', "
81
+ "'xz' or 'compress'")
82
+
83
+ archive_name = base_name + '.tar'
84
+ if compress != 'compress':
85
+ archive_name += compress_ext.get(compress, '')
86
+
87
+ mkpath(os.path.dirname(archive_name), dry_run=dry_run)
88
+
89
+ # creating the tarball
90
+ import tarfile # late import so Python build itself doesn't break
91
+
92
+ log.info('Creating tar archive')
93
+
94
+ uid = _get_uid(owner)
95
+ gid = _get_gid(group)
96
+
97
+ def _set_uid_gid(tarinfo):
98
+ if gid is not None:
99
+ tarinfo.gid = gid
100
+ tarinfo.gname = group
101
+ if uid is not None:
102
+ tarinfo.uid = uid
103
+ tarinfo.uname = owner
104
+ return tarinfo
105
+
106
+ if not dry_run:
107
+ tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
108
+ try:
109
+ tar.add(base_dir, filter=_set_uid_gid)
110
+ finally:
111
+ tar.close()
112
+
113
+ # compression using `compress`
114
+ if compress == 'compress':
115
+ warn("'compress' will be deprecated.", PendingDeprecationWarning)
116
+ # the option varies depending on the platform
117
+ compressed_name = archive_name + compress_ext[compress]
118
+ if sys.platform == 'win32':
119
+ cmd = [compress, archive_name, compressed_name]
120
+ else:
121
+ cmd = [compress, '-f', archive_name]
122
+ spawn(cmd, dry_run=dry_run)
123
+ return compressed_name
124
+
125
+ return archive_name
126
+
127
+ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
128
+ """Create a zip file from all the files under 'base_dir'.
129
+
130
+ The output zip file will be named 'base_name' + ".zip". Uses either the
131
+ "zipfile" Python module (if available) or the InfoZIP "zip" utility
132
+ (if installed and found on the default search path). If neither tool is
133
+ available, raises DistutilsExecError. Returns the name of the output zip
134
+ file.
135
+ """
136
+ zip_filename = base_name + ".zip"
137
+ mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
138
+
139
+ # If zipfile module is not available, try spawning an external
140
+ # 'zip' command.
141
+ if zipfile is None:
142
+ if verbose:
143
+ zipoptions = "-r"
144
+ else:
145
+ zipoptions = "-rq"
146
+
147
+ try:
148
+ spawn(["zip", zipoptions, zip_filename, base_dir],
149
+ dry_run=dry_run)
150
+ except DistutilsExecError:
151
+ # XXX really should distinguish between "couldn't find
152
+ # external 'zip' command" and "zip failed".
153
+ raise DistutilsExecError(("unable to create zip file '%s': "
154
+ "could neither import the 'zipfile' module nor "
155
+ "find a standalone zip utility") % zip_filename)
156
+
157
+ else:
158
+ log.info("creating '%s' and adding '%s' to it",
159
+ zip_filename, base_dir)
160
+
161
+ if not dry_run:
162
+ try:
163
+ zip = zipfile.ZipFile(zip_filename, "w",
164
+ compression=zipfile.ZIP_DEFLATED)
165
+ except RuntimeError:
166
+ zip = zipfile.ZipFile(zip_filename, "w",
167
+ compression=zipfile.ZIP_STORED)
168
+
169
+ with zip:
170
+ if base_dir != os.curdir:
171
+ path = os.path.normpath(os.path.join(base_dir, ''))
172
+ zip.write(path, path)
173
+ log.info("adding '%s'", path)
174
+ for dirpath, dirnames, filenames in os.walk(base_dir):
175
+ for name in dirnames:
176
+ path = os.path.normpath(os.path.join(dirpath, name, ''))
177
+ zip.write(path, path)
178
+ log.info("adding '%s'", path)
179
+ for name in filenames:
180
+ path = os.path.normpath(os.path.join(dirpath, name))
181
+ if os.path.isfile(path):
182
+ zip.write(path, path)
183
+ log.info("adding '%s'", path)
184
+
185
+ return zip_filename
186
+
187
+ ARCHIVE_FORMATS = {
188
+ 'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
189
+ 'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
190
+ 'xztar': (make_tarball, [('compress', 'xz')], "xz'ed tar-file"),
191
+ 'ztar': (make_tarball, [('compress', 'compress')], "compressed tar file"),
192
+ 'tar': (make_tarball, [('compress', None)], "uncompressed tar file"),
193
+ 'zip': (make_zipfile, [],"ZIP file")
194
+ }
195
+
196
+ def check_archive_formats(formats):
197
+ """Returns the first format from the 'format' list that is unknown.
198
+
199
+ If all formats are known, returns None
200
+ """
201
+ for format in formats:
202
+ if format not in ARCHIVE_FORMATS:
203
+ return format
204
+ return None
205
+
206
+ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
207
+ dry_run=0, owner=None, group=None):
208
+ """Create an archive file (eg. zip or tar).
209
+
210
+ 'base_name' is the name of the file to create, minus any format-specific
211
+ extension; 'format' is the archive format: one of "zip", "tar", "gztar",
212
+ "bztar", "xztar", or "ztar".
213
+
214
+ 'root_dir' is a directory that will be the root directory of the
215
+ archive; ie. we typically chdir into 'root_dir' before creating the
216
+ archive. 'base_dir' is the directory where we start archiving from;
217
+ ie. 'base_dir' will be the common prefix of all files and
218
+ directories in the archive. 'root_dir' and 'base_dir' both default
219
+ to the current directory. Returns the name of the archive file.
220
+
221
+ 'owner' and 'group' are used when creating a tar archive. By default,
222
+ uses the current owner and group.
223
+ """
224
+ save_cwd = os.getcwd()
225
+ if root_dir is not None:
226
+ log.debug("changing into '%s'", root_dir)
227
+ base_name = os.path.abspath(base_name)
228
+ if not dry_run:
229
+ os.chdir(root_dir)
230
+
231
+ if base_dir is None:
232
+ base_dir = os.curdir
233
+
234
+ kwargs = {'dry_run': dry_run}
235
+
236
+ try:
237
+ format_info = ARCHIVE_FORMATS[format]
238
+ except KeyError:
239
+ raise ValueError("unknown archive format '%s'" % format)
240
+
241
+ func = format_info[0]
242
+ for arg, val in format_info[1]:
243
+ kwargs[arg] = val
244
+
245
+ if format != 'zip':
246
+ kwargs['owner'] = owner
247
+ kwargs['group'] = group
248
+
249
+ try:
250
+ filename = func(base_name, base_dir, **kwargs)
251
+ finally:
252
+ if root_dir is not None:
253
+ log.debug("changing back to '%s'", save_cwd)
254
+ os.chdir(save_cwd)
255
+
256
+ return filename
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/bcppcompiler.py ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.bcppcompiler
2
+
3
+ Contains BorlandCCompiler, an implementation of the abstract CCompiler class
4
+ for the Borland C++ compiler.
5
+ """
6
+
7
+ # This implementation by Lyle Johnson, based on the original msvccompiler.py
8
+ # module and using the directions originally published by Gordon Williams.
9
+
10
+ # XXX looks like there's a LOT of overlap between these two classes:
11
+ # someone should sit down and factor out the common code as
12
+ # WindowsCCompiler! --GPW
13
+
14
+
15
+ import os
16
+ from distutils.errors import \
17
+ DistutilsExecError, \
18
+ CompileError, LibError, LinkError, UnknownFileError
19
+ from distutils.ccompiler import \
20
+ CCompiler, gen_preprocess_options
21
+ from distutils.file_util import write_file
22
+ from distutils.dep_util import newer
23
+ from distutils import log
24
+
25
+ class BCPPCompiler(CCompiler) :
26
+ """Concrete class that implements an interface to the Borland C/C++
27
+ compiler, as defined by the CCompiler abstract class.
28
+ """
29
+
30
+ compiler_type = 'bcpp'
31
+
32
+ # Just set this so CCompiler's constructor doesn't barf. We currently
33
+ # don't use the 'set_executables()' bureaucracy provided by CCompiler,
34
+ # as it really isn't necessary for this sort of single-compiler class.
35
+ # Would be nice to have a consistent interface with UnixCCompiler,
36
+ # though, so it's worth thinking about.
37
+ executables = {}
38
+
39
+ # Private class data (need to distinguish C from C++ source for compiler)
40
+ _c_extensions = ['.c']
41
+ _cpp_extensions = ['.cc', '.cpp', '.cxx']
42
+
43
+ # Needed for the filename generation methods provided by the
44
+ # base class, CCompiler.
45
+ src_extensions = _c_extensions + _cpp_extensions
46
+ obj_extension = '.obj'
47
+ static_lib_extension = '.lib'
48
+ shared_lib_extension = '.dll'
49
+ static_lib_format = shared_lib_format = '%s%s'
50
+ exe_extension = '.exe'
51
+
52
+
53
+ def __init__ (self,
54
+ verbose=0,
55
+ dry_run=0,
56
+ force=0):
57
+
58
+ CCompiler.__init__ (self, verbose, dry_run, force)
59
+
60
+ # These executables are assumed to all be in the path.
61
+ # Borland doesn't seem to use any special registry settings to
62
+ # indicate their installation locations.
63
+
64
+ self.cc = "bcc32.exe"
65
+ self.linker = "ilink32.exe"
66
+ self.lib = "tlib.exe"
67
+
68
+ self.preprocess_options = None
69
+ self.compile_options = ['/tWM', '/O2', '/q', '/g0']
70
+ self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']
71
+
72
+ self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']
73
+ self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
74
+ self.ldflags_static = []
75
+ self.ldflags_exe = ['/Gn', '/q', '/x']
76
+ self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r']
77
+
78
+
79
+ # -- Worker methods ------------------------------------------------
80
+
81
+ def compile(self, sources,
82
+ output_dir=None, macros=None, include_dirs=None, debug=0,
83
+ extra_preargs=None, extra_postargs=None, depends=None):
84
+
85
+ macros, objects, extra_postargs, pp_opts, build = \
86
+ self._setup_compile(output_dir, macros, include_dirs, sources,
87
+ depends, extra_postargs)
88
+ compile_opts = extra_preargs or []
89
+ compile_opts.append ('-c')
90
+ if debug:
91
+ compile_opts.extend (self.compile_options_debug)
92
+ else:
93
+ compile_opts.extend (self.compile_options)
94
+
95
+ for obj in objects:
96
+ try:
97
+ src, ext = build[obj]
98
+ except KeyError:
99
+ continue
100
+ # XXX why do the normpath here?
101
+ src = os.path.normpath(src)
102
+ obj = os.path.normpath(obj)
103
+ # XXX _setup_compile() did a mkpath() too but before the normpath.
104
+ # Is it possible to skip the normpath?
105
+ self.mkpath(os.path.dirname(obj))
106
+
107
+ if ext == '.res':
108
+ # This is already a binary file -- skip it.
109
+ continue # the 'for' loop
110
+ if ext == '.rc':
111
+ # This needs to be compiled to a .res file -- do it now.
112
+ try:
113
+ self.spawn (["brcc32", "-fo", obj, src])
114
+ except DistutilsExecError as msg:
115
+ raise CompileError(msg)
116
+ continue # the 'for' loop
117
+
118
+ # The next two are both for the real compiler.
119
+ if ext in self._c_extensions:
120
+ input_opt = ""
121
+ elif ext in self._cpp_extensions:
122
+ input_opt = "-P"
123
+ else:
124
+ # Unknown file type -- no extra options. The compiler
125
+ # will probably fail, but let it just in case this is a
126
+ # file the compiler recognizes even if we don't.
127
+ input_opt = ""
128
+
129
+ output_opt = "-o" + obj
130
+
131
+ # Compiler command line syntax is: "bcc32 [options] file(s)".
132
+ # Note that the source file names must appear at the end of
133
+ # the command line.
134
+ try:
135
+ self.spawn ([self.cc] + compile_opts + pp_opts +
136
+ [input_opt, output_opt] +
137
+ extra_postargs + [src])
138
+ except DistutilsExecError as msg:
139
+ raise CompileError(msg)
140
+
141
+ return objects
142
+
143
+ # compile ()
144
+
145
+
146
+ def create_static_lib (self,
147
+ objects,
148
+ output_libname,
149
+ output_dir=None,
150
+ debug=0,
151
+ target_lang=None):
152
+
153
+ (objects, output_dir) = self._fix_object_args (objects, output_dir)
154
+ output_filename = \
155
+ self.library_filename (output_libname, output_dir=output_dir)
156
+
157
+ if self._need_link (objects, output_filename):
158
+ lib_args = [output_filename, '/u'] + objects
159
+ if debug:
160
+ pass # XXX what goes here?
161
+ try:
162
+ self.spawn ([self.lib] + lib_args)
163
+ except DistutilsExecError as msg:
164
+ raise LibError(msg)
165
+ else:
166
+ log.debug("skipping %s (up-to-date)", output_filename)
167
+
168
+ # create_static_lib ()
169
+
170
+
171
+ def link (self,
172
+ target_desc,
173
+ objects,
174
+ output_filename,
175
+ output_dir=None,
176
+ libraries=None,
177
+ library_dirs=None,
178
+ runtime_library_dirs=None,
179
+ export_symbols=None,
180
+ debug=0,
181
+ extra_preargs=None,
182
+ extra_postargs=None,
183
+ build_temp=None,
184
+ target_lang=None):
185
+
186
+ # XXX this ignores 'build_temp'! should follow the lead of
187
+ # msvccompiler.py
188
+
189
+ (objects, output_dir) = self._fix_object_args (objects, output_dir)
190
+ (libraries, library_dirs, runtime_library_dirs) = \
191
+ self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
192
+
193
+ if runtime_library_dirs:
194
+ log.warn("I don't know what to do with 'runtime_library_dirs': %s",
195
+ str(runtime_library_dirs))
196
+
197
+ if output_dir is not None:
198
+ output_filename = os.path.join (output_dir, output_filename)
199
+
200
+ if self._need_link (objects, output_filename):
201
+
202
+ # Figure out linker args based on type of target.
203
+ if target_desc == CCompiler.EXECUTABLE:
204
+ startup_obj = 'c0w32'
205
+ if debug:
206
+ ld_args = self.ldflags_exe_debug[:]
207
+ else:
208
+ ld_args = self.ldflags_exe[:]
209
+ else:
210
+ startup_obj = 'c0d32'
211
+ if debug:
212
+ ld_args = self.ldflags_shared_debug[:]
213
+ else:
214
+ ld_args = self.ldflags_shared[:]
215
+
216
+
217
+ # Create a temporary exports file for use by the linker
218
+ if export_symbols is None:
219
+ def_file = ''
220
+ else:
221
+ head, tail = os.path.split (output_filename)
222
+ modname, ext = os.path.splitext (tail)
223
+ temp_dir = os.path.dirname(objects[0]) # preserve tree structure
224
+ def_file = os.path.join (temp_dir, '%s.def' % modname)
225
+ contents = ['EXPORTS']
226
+ for sym in (export_symbols or []):
227
+ contents.append(' %s=_%s' % (sym, sym))
228
+ self.execute(write_file, (def_file, contents),
229
+ "writing %s" % def_file)
230
+
231
+ # Borland C++ has problems with '/' in paths
232
+ objects2 = map(os.path.normpath, objects)
233
+ # split objects in .obj and .res files
234
+ # Borland C++ needs them at different positions in the command line
235
+ objects = [startup_obj]
236
+ resources = []
237
+ for file in objects2:
238
+ (base, ext) = os.path.splitext(os.path.normcase(file))
239
+ if ext == '.res':
240
+ resources.append(file)
241
+ else:
242
+ objects.append(file)
243
+
244
+
245
+ for l in library_dirs:
246
+ ld_args.append("/L%s" % os.path.normpath(l))
247
+ ld_args.append("/L.") # we sometimes use relative paths
248
+
249
+ # list of object files
250
+ ld_args.extend(objects)
251
+
252
+ # XXX the command-line syntax for Borland C++ is a bit wonky;
253
+ # certain filenames are jammed together in one big string, but
254
+ # comma-delimited. This doesn't mesh too well with the
255
+ # Unix-centric attitude (with a DOS/Windows quoting hack) of
256
+ # 'spawn()', so constructing the argument list is a bit
257
+ # awkward. Note that doing the obvious thing and jamming all
258
+ # the filenames and commas into one argument would be wrong,
259
+ # because 'spawn()' would quote any filenames with spaces in
260
+ # them. Arghghh!. Apparently it works fine as coded...
261
+
262
+ # name of dll/exe file
263
+ ld_args.extend([',',output_filename])
264
+ # no map file and start libraries
265
+ ld_args.append(',,')
266
+
267
+ for lib in libraries:
268
+ # see if we find it and if there is a bcpp specific lib
269
+ # (xxx_bcpp.lib)
270
+ libfile = self.find_library_file(library_dirs, lib, debug)
271
+ if libfile is None:
272
+ ld_args.append(lib)
273
+ # probably a BCPP internal library -- don't warn
274
+ else:
275
+ # full name which prefers bcpp_xxx.lib over xxx.lib
276
+ ld_args.append(libfile)
277
+
278
+ # some default libraries
279
+ ld_args.append ('import32')
280
+ ld_args.append ('cw32mt')
281
+
282
+ # def file for export symbols
283
+ ld_args.extend([',',def_file])
284
+ # add resource files
285
+ ld_args.append(',')
286
+ ld_args.extend(resources)
287
+
288
+
289
+ if extra_preargs:
290
+ ld_args[:0] = extra_preargs
291
+ if extra_postargs:
292
+ ld_args.extend(extra_postargs)
293
+
294
+ self.mkpath (os.path.dirname (output_filename))
295
+ try:
296
+ self.spawn ([self.linker] + ld_args)
297
+ except DistutilsExecError as msg:
298
+ raise LinkError(msg)
299
+
300
+ else:
301
+ log.debug("skipping %s (up-to-date)", output_filename)
302
+
303
+ # link ()
304
+
305
+ # -- Miscellaneous methods -----------------------------------------
306
+
307
+
308
+ def find_library_file (self, dirs, lib, debug=0):
309
+ # List of effective library names to try, in order of preference:
310
+ # xxx_bcpp.lib is better than xxx.lib
311
+ # and xxx_d.lib is better than xxx.lib if debug is set
312
+ #
313
+ # The "_bcpp" suffix is to handle a Python installation for people
314
+ # with multiple compilers (primarily Distutils hackers, I suspect
315
+ # ;-). The idea is they'd have one static library for each
316
+ # compiler they care about, since (almost?) every Windows compiler
317
+ # seems to have a different format for static libraries.
318
+ if debug:
319
+ dlib = (lib + "_d")
320
+ try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib)
321
+ else:
322
+ try_names = (lib + "_bcpp", lib)
323
+
324
+ for dir in dirs:
325
+ for name in try_names:
326
+ libfile = os.path.join(dir, self.library_filename(name))
327
+ if os.path.exists(libfile):
328
+ return libfile
329
+ else:
330
+ # Oops, didn't find it in *any* of 'dirs'
331
+ return None
332
+
333
+ # overwrite the one from CCompiler to support rc and res-files
334
+ def object_filenames (self,
335
+ source_filenames,
336
+ strip_dir=0,
337
+ output_dir=''):
338
+ if output_dir is None: output_dir = ''
339
+ obj_names = []
340
+ for src_name in source_filenames:
341
+ # use normcase to make sure '.rc' is really '.rc' and not '.RC'
342
+ (base, ext) = os.path.splitext (os.path.normcase(src_name))
343
+ if ext not in (self.src_extensions + ['.rc','.res']):
344
+ raise UnknownFileError("unknown file type '%s' (from '%s')" % \
345
+ (ext, src_name))
346
+ if strip_dir:
347
+ base = os.path.basename (base)
348
+ if ext == '.res':
349
+ # these can go unchanged
350
+ obj_names.append (os.path.join (output_dir, base + ext))
351
+ elif ext == '.rc':
352
+ # these need to be compiled to .res-files
353
+ obj_names.append (os.path.join (output_dir, base + '.res'))
354
+ else:
355
+ obj_names.append (os.path.join (output_dir,
356
+ base + self.obj_extension))
357
+ return obj_names
358
+
359
+ # object_filenames ()
360
+
361
+ def preprocess (self,
362
+ source,
363
+ output_file=None,
364
+ macros=None,
365
+ include_dirs=None,
366
+ extra_preargs=None,
367
+ extra_postargs=None):
368
+
369
+ (_, macros, include_dirs) = \
370
+ self._fix_compile_args(None, macros, include_dirs)
371
+ pp_opts = gen_preprocess_options(macros, include_dirs)
372
+ pp_args = ['cpp32.exe'] + pp_opts
373
+ if output_file is not None:
374
+ pp_args.append('-o' + output_file)
375
+ if extra_preargs:
376
+ pp_args[:0] = extra_preargs
377
+ if extra_postargs:
378
+ pp_args.extend(extra_postargs)
379
+ pp_args.append(source)
380
+
381
+ # We need to preprocess: either we're being forced to, or the
382
+ # source file is newer than the target (or the target doesn't
383
+ # exist).
384
+ if self.force or output_file is None or newer(source, output_file):
385
+ if output_file:
386
+ self.mkpath(os.path.dirname(output_file))
387
+ try:
388
+ self.spawn(pp_args)
389
+ except DistutilsExecError as msg:
390
+ print(msg)
391
+ raise CompileError(msg)
392
+
393
+ # preprocess()
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/ccompiler.py ADDED
@@ -0,0 +1,1123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.ccompiler
2
+
3
+ Contains CCompiler, an abstract base class that defines the interface
4
+ for the Distutils compiler abstraction model."""
5
+
6
+ import sys, os, re
7
+ from distutils.errors import *
8
+ from distutils.spawn import spawn
9
+ from distutils.file_util import move_file
10
+ from distutils.dir_util import mkpath
11
+ from distutils.dep_util import newer_group
12
+ from distutils.util import split_quoted, execute
13
+ from distutils import log
14
+
15
+ class CCompiler:
16
+ """Abstract base class to define the interface that must be implemented
17
+ by real compiler classes. Also has some utility methods used by
18
+ several compiler classes.
19
+
20
+ The basic idea behind a compiler abstraction class is that each
21
+ instance can be used for all the compile/link steps in building a
22
+ single project. Thus, attributes common to all of those compile and
23
+ link steps -- include directories, macros to define, libraries to link
24
+ against, etc. -- are attributes of the compiler instance. To allow for
25
+ variability in how individual files are treated, most of those
26
+ attributes may be varied on a per-compilation or per-link basis.
27
+ """
28
+
29
+ # 'compiler_type' is a class attribute that identifies this class. It
30
+ # keeps code that wants to know what kind of compiler it's dealing with
31
+ # from having to import all possible compiler classes just to do an
32
+ # 'isinstance'. In concrete CCompiler subclasses, 'compiler_type'
33
+ # should really, really be one of the keys of the 'compiler_class'
34
+ # dictionary (see below -- used by the 'new_compiler()' factory
35
+ # function) -- authors of new compiler interface classes are
36
+ # responsible for updating 'compiler_class'!
37
+ compiler_type = None
38
+
39
+ # XXX things not handled by this compiler abstraction model:
40
+ # * client can't provide additional options for a compiler,
41
+ # e.g. warning, optimization, debugging flags. Perhaps this
42
+ # should be the domain of concrete compiler abstraction classes
43
+ # (UnixCCompiler, MSVCCompiler, etc.) -- or perhaps the base
44
+ # class should have methods for the common ones.
45
+ # * can't completely override the include or library searchg
46
+ # path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2".
47
+ # I'm not sure how widely supported this is even by Unix
48
+ # compilers, much less on other platforms. And I'm even less
49
+ # sure how useful it is; maybe for cross-compiling, but
50
+ # support for that is a ways off. (And anyways, cross
51
+ # compilers probably have a dedicated binary with the
52
+ # right paths compiled in. I hope.)
53
+ # * can't do really freaky things with the library list/library
54
+ # dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against
55
+ # different versions of libfoo.a in different locations. I
56
+ # think this is useless without the ability to null out the
57
+ # library search path anyways.
58
+
59
+
60
+ # Subclasses that rely on the standard filename generation methods
61
+ # implemented below should override these; see the comment near
62
+ # those methods ('object_filenames()' et. al.) for details:
63
+ src_extensions = None # list of strings
64
+ obj_extension = None # string
65
+ static_lib_extension = None
66
+ shared_lib_extension = None # string
67
+ static_lib_format = None # format string
68
+ shared_lib_format = None # prob. same as static_lib_format
69
+ exe_extension = None # string
70
+
71
+ # Default language settings. language_map is used to detect a source
72
+ # file or Extension target language, checking source filenames.
73
+ # language_order is used to detect the language precedence, when deciding
74
+ # what language to use when mixing source types. For example, if some
75
+ # extension has two files with ".c" extension, and one with ".cpp", it
76
+ # is still linked as c++.
77
+ language_map = {".c" : "c",
78
+ ".cc" : "c++",
79
+ ".cpp" : "c++",
80
+ ".cxx" : "c++",
81
+ ".m" : "objc",
82
+ }
83
+ language_order = ["c++", "objc", "c"]
84
+
85
+ def __init__(self, verbose=0, dry_run=0, force=0):
86
+ self.dry_run = dry_run
87
+ self.force = force
88
+ self.verbose = verbose
89
+
90
+ # 'output_dir': a common output directory for object, library,
91
+ # shared object, and shared library files
92
+ self.output_dir = None
93
+
94
+ # 'macros': a list of macro definitions (or undefinitions). A
95
+ # macro definition is a 2-tuple (name, value), where the value is
96
+ # either a string or None (no explicit value). A macro
97
+ # undefinition is a 1-tuple (name,).
98
+ self.macros = []
99
+
100
+ # 'include_dirs': a list of directories to search for include files
101
+ self.include_dirs = []
102
+
103
+ # 'libraries': a list of libraries to include in any link
104
+ # (library names, not filenames: eg. "foo" not "libfoo.a")
105
+ self.libraries = []
106
+
107
+ # 'library_dirs': a list of directories to search for libraries
108
+ self.library_dirs = []
109
+
110
+ # 'runtime_library_dirs': a list of directories to search for
111
+ # shared libraries/objects at runtime
112
+ self.runtime_library_dirs = []
113
+
114
+ # 'objects': a list of object files (or similar, such as explicitly
115
+ # named library files) to include on any link
116
+ self.objects = []
117
+
118
+ for key in self.executables.keys():
119
+ self.set_executable(key, self.executables[key])
120
+
121
+ def set_executables(self, **kwargs):
122
+ """Define the executables (and options for them) that will be run
123
+ to perform the various stages of compilation. The exact set of
124
+ executables that may be specified here depends on the compiler
125
+ class (via the 'executables' class attribute), but most will have:
126
+ compiler the C/C++ compiler
127
+ linker_so linker used to create shared objects and libraries
128
+ linker_exe linker used to create binary executables
129
+ archiver static library creator
130
+
131
+ On platforms with a command-line (Unix, DOS/Windows), each of these
132
+ is a string that will be split into executable name and (optional)
133
+ list of arguments. (Splitting the string is done similarly to how
134
+ Unix shells operate: words are delimited by spaces, but quotes and
135
+ backslashes can override this. See
136
+ 'distutils.util.split_quoted()'.)
137
+ """
138
+
139
+ # Note that some CCompiler implementation classes will define class
140
+ # attributes 'cpp', 'cc', etc. with hard-coded executable names;
141
+ # this is appropriate when a compiler class is for exactly one
142
+ # compiler/OS combination (eg. MSVCCompiler). Other compiler
143
+ # classes (UnixCCompiler, in particular) are driven by information
144
+ # discovered at run-time, since there are many different ways to do
145
+ # basically the same things with Unix C compilers.
146
+
147
+ for key in kwargs:
148
+ if key not in self.executables:
149
+ raise ValueError("unknown executable '%s' for class %s" %
150
+ (key, self.__class__.__name__))
151
+ self.set_executable(key, kwargs[key])
152
+
153
+ def set_executable(self, key, value):
154
+ if isinstance(value, str):
155
+ setattr(self, key, split_quoted(value))
156
+ else:
157
+ setattr(self, key, value)
158
+
159
+ def _find_macro(self, name):
160
+ i = 0
161
+ for defn in self.macros:
162
+ if defn[0] == name:
163
+ return i
164
+ i += 1
165
+ return None
166
+
167
+ def _check_macro_definitions(self, definitions):
168
+ """Ensures that every element of 'definitions' is a valid macro
169
+ definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
170
+ nothing if all definitions are OK, raise TypeError otherwise.
171
+ """
172
+ for defn in definitions:
173
+ if not (isinstance(defn, tuple) and
174
+ (len(defn) in (1, 2) and
175
+ (isinstance (defn[1], str) or defn[1] is None)) and
176
+ isinstance (defn[0], str)):
177
+ raise TypeError(("invalid macro definition '%s': " % defn) + \
178
+ "must be tuple (string,), (string, string), or " + \
179
+ "(string, None)")
180
+
181
+
182
+ # -- Bookkeeping methods -------------------------------------------
183
+
184
+ def define_macro(self, name, value=None):
185
+ """Define a preprocessor macro for all compilations driven by this
186
+ compiler object. The optional parameter 'value' should be a
187
+ string; if it is not supplied, then the macro will be defined
188
+ without an explicit value and the exact outcome depends on the
189
+ compiler used (XXX true? does ANSI say anything about this?)
190
+ """
191
+ # Delete from the list of macro definitions/undefinitions if
192
+ # already there (so that this one will take precedence).
193
+ i = self._find_macro (name)
194
+ if i is not None:
195
+ del self.macros[i]
196
+
197
+ self.macros.append((name, value))
198
+
199
+ def undefine_macro(self, name):
200
+ """Undefine a preprocessor macro for all compilations driven by
201
+ this compiler object. If the same macro is defined by
202
+ 'define_macro()' and undefined by 'undefine_macro()' the last call
203
+ takes precedence (including multiple redefinitions or
204
+ undefinitions). If the macro is redefined/undefined on a
205
+ per-compilation basis (ie. in the call to 'compile()'), then that
206
+ takes precedence.
207
+ """
208
+ # Delete from the list of macro definitions/undefinitions if
209
+ # already there (so that this one will take precedence).
210
+ i = self._find_macro (name)
211
+ if i is not None:
212
+ del self.macros[i]
213
+
214
+ undefn = (name,)
215
+ self.macros.append(undefn)
216
+
217
+ def add_include_dir(self, dir):
218
+ """Add 'dir' to the list of directories that will be searched for
219
+ header files. The compiler is instructed to search directories in
220
+ the order in which they are supplied by successive calls to
221
+ 'add_include_dir()'.
222
+ """
223
+ self.include_dirs.append(dir)
224
+
225
+ def set_include_dirs(self, dirs):
226
+ """Set the list of directories that will be searched to 'dirs' (a
227
+ list of strings). Overrides any preceding calls to
228
+ 'add_include_dir()'; subsequence calls to 'add_include_dir()' add
229
+ to the list passed to 'set_include_dirs()'. This does not affect
230
+ any list of standard include directories that the compiler may
231
+ search by default.
232
+ """
233
+ self.include_dirs = dirs[:]
234
+
235
+ def add_library(self, libname):
236
+ """Add 'libname' to the list of libraries that will be included in
237
+ all links driven by this compiler object. Note that 'libname'
238
+ should *not* be the name of a file containing a library, but the
239
+ name of the library itself: the actual filename will be inferred by
240
+ the linker, the compiler, or the compiler class (depending on the
241
+ platform).
242
+
243
+ The linker will be instructed to link against libraries in the
244
+ order they were supplied to 'add_library()' and/or
245
+ 'set_libraries()'. It is perfectly valid to duplicate library
246
+ names; the linker will be instructed to link against libraries as
247
+ many times as they are mentioned.
248
+ """
249
+ self.libraries.append(libname)
250
+
251
+ def set_libraries(self, libnames):
252
+ """Set the list of libraries to be included in all links driven by
253
+ this compiler object to 'libnames' (a list of strings). This does
254
+ not affect any standard system libraries that the linker may
255
+ include by default.
256
+ """
257
+ self.libraries = libnames[:]
258
+
259
+ def add_library_dir(self, dir):
260
+ """Add 'dir' to the list of directories that will be searched for
261
+ libraries specified to 'add_library()' and 'set_libraries()'. The
262
+ linker will be instructed to search for libraries in the order they
263
+ are supplied to 'add_library_dir()' and/or 'set_library_dirs()'.
264
+ """
265
+ self.library_dirs.append(dir)
266
+
267
+ def set_library_dirs(self, dirs):
268
+ """Set the list of library search directories to 'dirs' (a list of
269
+ strings). This does not affect any standard library search path
270
+ that the linker may search by default.
271
+ """
272
+ self.library_dirs = dirs[:]
273
+
274
+ def add_runtime_library_dir(self, dir):
275
+ """Add 'dir' to the list of directories that will be searched for
276
+ shared libraries at runtime.
277
+ """
278
+ self.runtime_library_dirs.append(dir)
279
+
280
+ def set_runtime_library_dirs(self, dirs):
281
+ """Set the list of directories to search for shared libraries at
282
+ runtime to 'dirs' (a list of strings). This does not affect any
283
+ standard search path that the runtime linker may search by
284
+ default.
285
+ """
286
+ self.runtime_library_dirs = dirs[:]
287
+
288
+ def add_link_object(self, object):
289
+ """Add 'object' to the list of object files (or analogues, such as
290
+ explicitly named library files or the output of "resource
291
+ compilers") to be included in every link driven by this compiler
292
+ object.
293
+ """
294
+ self.objects.append(object)
295
+
296
+ def set_link_objects(self, objects):
297
+ """Set the list of object files (or analogues) to be included in
298
+ every link to 'objects'. This does not affect any standard object
299
+ files that the linker may include by default (such as system
300
+ libraries).
301
+ """
302
+ self.objects = objects[:]
303
+
304
+
305
+ # -- Private utility methods --------------------------------------
306
+ # (here for the convenience of subclasses)
307
+
308
+ # Helper method to prep compiler in subclass compile() methods
309
+
310
+ def _setup_compile(self, outdir, macros, incdirs, sources, depends,
311
+ extra):
312
+ """Process arguments and decide which source files to compile."""
313
+ if outdir is None:
314
+ outdir = self.output_dir
315
+ elif not isinstance(outdir, str):
316
+ raise TypeError("'output_dir' must be a string or None")
317
+
318
+ if macros is None:
319
+ macros = self.macros
320
+ elif isinstance(macros, list):
321
+ macros = macros + (self.macros or [])
322
+ else:
323
+ raise TypeError("'macros' (if supplied) must be a list of tuples")
324
+
325
+ if incdirs is None:
326
+ incdirs = self.include_dirs
327
+ elif isinstance(incdirs, (list, tuple)):
328
+ incdirs = list(incdirs) + (self.include_dirs or [])
329
+ else:
330
+ raise TypeError(
331
+ "'include_dirs' (if supplied) must be a list of strings")
332
+
333
+ if extra is None:
334
+ extra = []
335
+
336
+ # Get the list of expected output (object) files
337
+ objects = self.object_filenames(sources, strip_dir=0,
338
+ output_dir=outdir)
339
+ assert len(objects) == len(sources)
340
+
341
+ pp_opts = gen_preprocess_options(macros, incdirs)
342
+
343
+ build = {}
344
+ for i in range(len(sources)):
345
+ src = sources[i]
346
+ obj = objects[i]
347
+ ext = os.path.splitext(src)[1]
348
+ self.mkpath(os.path.dirname(obj))
349
+ build[obj] = (src, ext)
350
+
351
+ return macros, objects, extra, pp_opts, build
352
+
353
+ def _get_cc_args(self, pp_opts, debug, before):
354
+ # works for unixccompiler, cygwinccompiler
355
+ cc_args = pp_opts + ['-c']
356
+ if debug:
357
+ cc_args[:0] = ['-g']
358
+ if before:
359
+ cc_args[:0] = before
360
+ return cc_args
361
+
362
+ def _fix_compile_args(self, output_dir, macros, include_dirs):
363
+ """Typecheck and fix-up some of the arguments to the 'compile()'
364
+ method, and return fixed-up values. Specifically: if 'output_dir'
365
+ is None, replaces it with 'self.output_dir'; ensures that 'macros'
366
+ is a list, and augments it with 'self.macros'; ensures that
367
+ 'include_dirs' is a list, and augments it with 'self.include_dirs'.
368
+ Guarantees that the returned values are of the correct type,
369
+ i.e. for 'output_dir' either string or None, and for 'macros' and
370
+ 'include_dirs' either list or None.
371
+ """
372
+ if output_dir is None:
373
+ output_dir = self.output_dir
374
+ elif not isinstance(output_dir, str):
375
+ raise TypeError("'output_dir' must be a string or None")
376
+
377
+ if macros is None:
378
+ macros = self.macros
379
+ elif isinstance(macros, list):
380
+ macros = macros + (self.macros or [])
381
+ else:
382
+ raise TypeError("'macros' (if supplied) must be a list of tuples")
383
+
384
+ if include_dirs is None:
385
+ include_dirs = self.include_dirs
386
+ elif isinstance(include_dirs, (list, tuple)):
387
+ include_dirs = list(include_dirs) + (self.include_dirs or [])
388
+ else:
389
+ raise TypeError(
390
+ "'include_dirs' (if supplied) must be a list of strings")
391
+
392
+ return output_dir, macros, include_dirs
393
+
394
+ def _prep_compile(self, sources, output_dir, depends=None):
395
+ """Decide which source files must be recompiled.
396
+
397
+ Determine the list of object files corresponding to 'sources',
398
+ and figure out which ones really need to be recompiled.
399
+ Return a list of all object files and a dictionary telling
400
+ which source files can be skipped.
401
+ """
402
+ # Get the list of expected output (object) files
403
+ objects = self.object_filenames(sources, output_dir=output_dir)
404
+ assert len(objects) == len(sources)
405
+
406
+ # Return an empty dict for the "which source files can be skipped"
407
+ # return value to preserve API compatibility.
408
+ return objects, {}
409
+
410
+ def _fix_object_args(self, objects, output_dir):
411
+ """Typecheck and fix up some arguments supplied to various methods.
412
+ Specifically: ensure that 'objects' is a list; if output_dir is
413
+ None, replace with self.output_dir. Return fixed versions of
414
+ 'objects' and 'output_dir'.
415
+ """
416
+ if not isinstance(objects, (list, tuple)):
417
+ raise TypeError("'objects' must be a list or tuple of strings")
418
+ objects = list(objects)
419
+
420
+ if output_dir is None:
421
+ output_dir = self.output_dir
422
+ elif not isinstance(output_dir, str):
423
+ raise TypeError("'output_dir' must be a string or None")
424
+
425
+ return (objects, output_dir)
426
+
427
+ def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
428
+ """Typecheck and fix up some of the arguments supplied to the
429
+ 'link_*' methods. Specifically: ensure that all arguments are
430
+ lists, and augment them with their permanent versions
431
+ (eg. 'self.libraries' augments 'libraries'). Return a tuple with
432
+ fixed versions of all arguments.
433
+ """
434
+ if libraries is None:
435
+ libraries = self.libraries
436
+ elif isinstance(libraries, (list, tuple)):
437
+ libraries = list (libraries) + (self.libraries or [])
438
+ else:
439
+ raise TypeError(
440
+ "'libraries' (if supplied) must be a list of strings")
441
+
442
+ if library_dirs is None:
443
+ library_dirs = self.library_dirs
444
+ elif isinstance(library_dirs, (list, tuple)):
445
+ library_dirs = list (library_dirs) + (self.library_dirs or [])
446
+ else:
447
+ raise TypeError(
448
+ "'library_dirs' (if supplied) must be a list of strings")
449
+
450
+ if runtime_library_dirs is None:
451
+ runtime_library_dirs = self.runtime_library_dirs
452
+ elif isinstance(runtime_library_dirs, (list, tuple)):
453
+ runtime_library_dirs = (list(runtime_library_dirs) +
454
+ (self.runtime_library_dirs or []))
455
+ else:
456
+ raise TypeError("'runtime_library_dirs' (if supplied) "
457
+ "must be a list of strings")
458
+
459
+ return (libraries, library_dirs, runtime_library_dirs)
460
+
461
+ def _need_link(self, objects, output_file):
462
+ """Return true if we need to relink the files listed in 'objects'
463
+ to recreate 'output_file'.
464
+ """
465
+ if self.force:
466
+ return True
467
+ else:
468
+ if self.dry_run:
469
+ newer = newer_group (objects, output_file, missing='newer')
470
+ else:
471
+ newer = newer_group (objects, output_file)
472
+ return newer
473
+
474
+ def detect_language(self, sources):
475
+ """Detect the language of a given file, or list of files. Uses
476
+ language_map, and language_order to do the job.
477
+ """
478
+ if not isinstance(sources, list):
479
+ sources = [sources]
480
+ lang = None
481
+ index = len(self.language_order)
482
+ for source in sources:
483
+ base, ext = os.path.splitext(source)
484
+ extlang = self.language_map.get(ext)
485
+ try:
486
+ extindex = self.language_order.index(extlang)
487
+ if extindex < index:
488
+ lang = extlang
489
+ index = extindex
490
+ except ValueError:
491
+ pass
492
+ return lang
493
+
494
+
495
+ # -- Worker methods ------------------------------------------------
496
+ # (must be implemented by subclasses)
497
+
498
+ def preprocess(self, source, output_file=None, macros=None,
499
+ include_dirs=None, extra_preargs=None, extra_postargs=None):
500
+ """Preprocess a single C/C++ source file, named in 'source'.
501
+ Output will be written to file named 'output_file', or stdout if
502
+ 'output_file' not supplied. 'macros' is a list of macro
503
+ definitions as for 'compile()', which will augment the macros set
504
+ with 'define_macro()' and 'undefine_macro()'. 'include_dirs' is a
505
+ list of directory names that will be added to the default list.
506
+
507
+ Raises PreprocessError on failure.
508
+ """
509
+ pass
510
+
511
+ def compile(self, sources, output_dir=None, macros=None,
512
+ include_dirs=None, debug=0, extra_preargs=None,
513
+ extra_postargs=None, depends=None):
514
+ """Compile one or more source files.
515
+
516
+ 'sources' must be a list of filenames, most likely C/C++
517
+ files, but in reality anything that can be handled by a
518
+ particular compiler and compiler class (eg. MSVCCompiler can
519
+ handle resource files in 'sources'). Return a list of object
520
+ filenames, one per source filename in 'sources'. Depending on
521
+ the implementation, not all source files will necessarily be
522
+ compiled, but all corresponding object filenames will be
523
+ returned.
524
+
525
+ If 'output_dir' is given, object files will be put under it, while
526
+ retaining their original path component. That is, "foo/bar.c"
527
+ normally compiles to "foo/bar.o" (for a Unix implementation); if
528
+ 'output_dir' is "build", then it would compile to
529
+ "build/foo/bar.o".
530
+
531
+ 'macros', if given, must be a list of macro definitions. A macro
532
+ definition is either a (name, value) 2-tuple or a (name,) 1-tuple.
533
+ The former defines a macro; if the value is None, the macro is
534
+ defined without an explicit value. The 1-tuple case undefines a
535
+ macro. Later definitions/redefinitions/ undefinitions take
536
+ precedence.
537
+
538
+ 'include_dirs', if given, must be a list of strings, the
539
+ directories to add to the default include file search path for this
540
+ compilation only.
541
+
542
+ 'debug' is a boolean; if true, the compiler will be instructed to
543
+ output debug symbols in (or alongside) the object file(s).
544
+
545
+ 'extra_preargs' and 'extra_postargs' are implementation- dependent.
546
+ On platforms that have the notion of a command-line (e.g. Unix,
547
+ DOS/Windows), they are most likely lists of strings: extra
548
+ command-line arguments to prepend/append to the compiler command
549
+ line. On other platforms, consult the implementation class
550
+ documentation. In any event, they are intended as an escape hatch
551
+ for those occasions when the abstract compiler framework doesn't
552
+ cut the mustard.
553
+
554
+ 'depends', if given, is a list of filenames that all targets
555
+ depend on. If a source file is older than any file in
556
+ depends, then the source file will be recompiled. This
557
+ supports dependency tracking, but only at a coarse
558
+ granularity.
559
+
560
+ Raises CompileError on failure.
561
+ """
562
+ # A concrete compiler class can either override this method
563
+ # entirely or implement _compile().
564
+ macros, objects, extra_postargs, pp_opts, build = \
565
+ self._setup_compile(output_dir, macros, include_dirs, sources,
566
+ depends, extra_postargs)
567
+ cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
568
+
569
+ for obj in objects:
570
+ try:
571
+ src, ext = build[obj]
572
+ except KeyError:
573
+ continue
574
+ self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
575
+
576
+ # Return *all* object filenames, not just the ones we just built.
577
+ return objects
578
+
579
+ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
580
+ """Compile 'src' to product 'obj'."""
581
+ # A concrete compiler class that does not override compile()
582
+ # should implement _compile().
583
+ pass
584
+
585
+ def create_static_lib(self, objects, output_libname, output_dir=None,
586
+ debug=0, target_lang=None):
587
+ """Link a bunch of stuff together to create a static library file.
588
+ The "bunch of stuff" consists of the list of object files supplied
589
+ as 'objects', the extra object files supplied to
590
+ 'add_link_object()' and/or 'set_link_objects()', the libraries
591
+ supplied to 'add_library()' and/or 'set_libraries()', and the
592
+ libraries supplied as 'libraries' (if any).
593
+
594
+ 'output_libname' should be a library name, not a filename; the
595
+ filename will be inferred from the library name. 'output_dir' is
596
+ the directory where the library file will be put.
597
+
598
+ 'debug' is a boolean; if true, debugging information will be
599
+ included in the library (note that on most platforms, it is the
600
+ compile step where this matters: the 'debug' flag is included here
601
+ just for consistency).
602
+
603
+ 'target_lang' is the target language for which the given objects
604
+ are being compiled. This allows specific linkage time treatment of
605
+ certain languages.
606
+
607
+ Raises LibError on failure.
608
+ """
609
+ pass
610
+
611
+
612
+ # values for target_desc parameter in link()
613
+ SHARED_OBJECT = "shared_object"
614
+ SHARED_LIBRARY = "shared_library"
615
+ EXECUTABLE = "executable"
616
+
617
+ def link(self,
618
+ target_desc,
619
+ objects,
620
+ output_filename,
621
+ output_dir=None,
622
+ libraries=None,
623
+ library_dirs=None,
624
+ runtime_library_dirs=None,
625
+ export_symbols=None,
626
+ debug=0,
627
+ extra_preargs=None,
628
+ extra_postargs=None,
629
+ build_temp=None,
630
+ target_lang=None):
631
+ """Link a bunch of stuff together to create an executable or
632
+ shared library file.
633
+
634
+ The "bunch of stuff" consists of the list of object files supplied
635
+ as 'objects'. 'output_filename' should be a filename. If
636
+ 'output_dir' is supplied, 'output_filename' is relative to it
637
+ (i.e. 'output_filename' can provide directory components if
638
+ needed).
639
+
640
+ 'libraries' is a list of libraries to link against. These are
641
+ library names, not filenames, since they're translated into
642
+ filenames in a platform-specific way (eg. "foo" becomes "libfoo.a"
643
+ on Unix and "foo.lib" on DOS/Windows). However, they can include a
644
+ directory component, which means the linker will look in that
645
+ specific directory rather than searching all the normal locations.
646
+
647
+ 'library_dirs', if supplied, should be a list of directories to
648
+ search for libraries that were specified as bare library names
649
+ (ie. no directory component). These are on top of the system
650
+ default and those supplied to 'add_library_dir()' and/or
651
+ 'set_library_dirs()'. 'runtime_library_dirs' is a list of
652
+ directories that will be embedded into the shared library and used
653
+ to search for other shared libraries that *it* depends on at
654
+ run-time. (This may only be relevant on Unix.)
655
+
656
+ 'export_symbols' is a list of symbols that the shared library will
657
+ export. (This appears to be relevant only on Windows.)
658
+
659
+ 'debug' is as for 'compile()' and 'create_static_lib()', with the
660
+ slight distinction that it actually matters on most platforms (as
661
+ opposed to 'create_static_lib()', which includes a 'debug' flag
662
+ mostly for form's sake).
663
+
664
+ 'extra_preargs' and 'extra_postargs' are as for 'compile()' (except
665
+ of course that they supply command-line arguments for the
666
+ particular linker being used).
667
+
668
+ 'target_lang' is the target language for which the given objects
669
+ are being compiled. This allows specific linkage time treatment of
670
+ certain languages.
671
+
672
+ Raises LinkError on failure.
673
+ """
674
+ raise NotImplementedError
675
+
676
+
677
+ # Old 'link_*()' methods, rewritten to use the new 'link()' method.
678
+
679
+ def link_shared_lib(self,
680
+ objects,
681
+ output_libname,
682
+ output_dir=None,
683
+ libraries=None,
684
+ library_dirs=None,
685
+ runtime_library_dirs=None,
686
+ export_symbols=None,
687
+ debug=0,
688
+ extra_preargs=None,
689
+ extra_postargs=None,
690
+ build_temp=None,
691
+ target_lang=None):
692
+ self.link(CCompiler.SHARED_LIBRARY, objects,
693
+ self.library_filename(output_libname, lib_type='shared'),
694
+ output_dir,
695
+ libraries, library_dirs, runtime_library_dirs,
696
+ export_symbols, debug,
697
+ extra_preargs, extra_postargs, build_temp, target_lang)
698
+
699
+
700
+ def link_shared_object(self,
701
+ objects,
702
+ output_filename,
703
+ output_dir=None,
704
+ libraries=None,
705
+ library_dirs=None,
706
+ runtime_library_dirs=None,
707
+ export_symbols=None,
708
+ debug=0,
709
+ extra_preargs=None,
710
+ extra_postargs=None,
711
+ build_temp=None,
712
+ target_lang=None):
713
+ self.link(CCompiler.SHARED_OBJECT, objects,
714
+ output_filename, output_dir,
715
+ libraries, library_dirs, runtime_library_dirs,
716
+ export_symbols, debug,
717
+ extra_preargs, extra_postargs, build_temp, target_lang)
718
+
719
+
720
+ def link_executable(self,
721
+ objects,
722
+ output_progname,
723
+ output_dir=None,
724
+ libraries=None,
725
+ library_dirs=None,
726
+ runtime_library_dirs=None,
727
+ debug=0,
728
+ extra_preargs=None,
729
+ extra_postargs=None,
730
+ target_lang=None):
731
+ self.link(CCompiler.EXECUTABLE, objects,
732
+ self.executable_filename(output_progname), output_dir,
733
+ libraries, library_dirs, runtime_library_dirs, None,
734
+ debug, extra_preargs, extra_postargs, None, target_lang)
735
+
736
+
737
+ # -- Miscellaneous methods -----------------------------------------
738
+ # These are all used by the 'gen_lib_options() function; there is
739
+ # no appropriate default implementation so subclasses should
740
+ # implement all of these.
741
+
742
+ def library_dir_option(self, dir):
743
+ """Return the compiler option to add 'dir' to the list of
744
+ directories searched for libraries.
745
+ """
746
+ raise NotImplementedError
747
+
748
+ def runtime_library_dir_option(self, dir):
749
+ """Return the compiler option to add 'dir' to the list of
750
+ directories searched for runtime libraries.
751
+ """
752
+ raise NotImplementedError
753
+
754
+ def library_option(self, lib):
755
+ """Return the compiler option to add 'lib' to the list of libraries
756
+ linked into the shared library or executable.
757
+ """
758
+ raise NotImplementedError
759
+
760
+ def has_function(self, funcname, includes=None, include_dirs=None,
761
+ libraries=None, library_dirs=None):
762
+ """Return a boolean indicating whether funcname is supported on
763
+ the current platform. The optional arguments can be used to
764
+ augment the compilation environment.
765
+ """
766
+ # this can't be included at module scope because it tries to
767
+ # import math which might not be available at that point - maybe
768
+ # the necessary logic should just be inlined?
769
+ import tempfile
770
+ if includes is None:
771
+ includes = []
772
+ if include_dirs is None:
773
+ include_dirs = []
774
+ if libraries is None:
775
+ libraries = []
776
+ if library_dirs is None:
777
+ library_dirs = []
778
+ fd, fname = tempfile.mkstemp(".c", funcname, text=True)
779
+ f = os.fdopen(fd, "w")
780
+ try:
781
+ for incl in includes:
782
+ f.write("""#include "%s"\n""" % incl)
783
+ f.write("""\
784
+ int main (int argc, char **argv) {
785
+ %s();
786
+ return 0;
787
+ }
788
+ """ % funcname)
789
+ finally:
790
+ f.close()
791
+ try:
792
+ objects = self.compile([fname], include_dirs=include_dirs)
793
+ except CompileError:
794
+ return False
795
+ finally:
796
+ os.remove(fname)
797
+
798
+ try:
799
+ self.link_executable(objects, "a.out",
800
+ libraries=libraries,
801
+ library_dirs=library_dirs)
802
+ except (LinkError, TypeError):
803
+ return False
804
+ else:
805
+ os.remove(os.path.join(self.output_dir or '', "a.out"))
806
+ finally:
807
+ for fn in objects:
808
+ os.remove(fn)
809
+ return True
810
+
811
+ def find_library_file (self, dirs, lib, debug=0):
812
+ """Search the specified list of directories for a static or shared
813
+ library file 'lib' and return the full path to that file. If
814
+ 'debug' true, look for a debugging version (if that makes sense on
815
+ the current platform). Return None if 'lib' wasn't found in any of
816
+ the specified directories.
817
+ """
818
+ raise NotImplementedError
819
+
820
+ # -- Filename generation methods -----------------------------------
821
+
822
+ # The default implementation of the filename generating methods are
823
+ # prejudiced towards the Unix/DOS/Windows view of the world:
824
+ # * object files are named by replacing the source file extension
825
+ # (eg. .c/.cpp -> .o/.obj)
826
+ # * library files (shared or static) are named by plugging the
827
+ # library name and extension into a format string, eg.
828
+ # "lib%s.%s" % (lib_name, ".a") for Unix static libraries
829
+ # * executables are named by appending an extension (possibly
830
+ # empty) to the program name: eg. progname + ".exe" for
831
+ # Windows
832
+ #
833
+ # To reduce redundant code, these methods expect to find
834
+ # several attributes in the current object (presumably defined
835
+ # as class attributes):
836
+ # * src_extensions -
837
+ # list of C/C++ source file extensions, eg. ['.c', '.cpp']
838
+ # * obj_extension -
839
+ # object file extension, eg. '.o' or '.obj'
840
+ # * static_lib_extension -
841
+ # extension for static library files, eg. '.a' or '.lib'
842
+ # * shared_lib_extension -
843
+ # extension for shared library/object files, eg. '.so', '.dll'
844
+ # * static_lib_format -
845
+ # format string for generating static library filenames,
846
+ # eg. 'lib%s.%s' or '%s.%s'
847
+ # * shared_lib_format
848
+ # format string for generating shared library filenames
849
+ # (probably same as static_lib_format, since the extension
850
+ # is one of the intended parameters to the format string)
851
+ # * exe_extension -
852
+ # extension for executable files, eg. '' or '.exe'
853
+
854
+ def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
855
+ if output_dir is None:
856
+ output_dir = ''
857
+ obj_names = []
858
+ for src_name in source_filenames:
859
+ base, ext = os.path.splitext(src_name)
860
+ base = os.path.splitdrive(base)[1] # Chop off the drive
861
+ base = base[os.path.isabs(base):] # If abs, chop off leading /
862
+ if ext not in self.src_extensions:
863
+ raise UnknownFileError(
864
+ "unknown file type '%s' (from '%s')" % (ext, src_name))
865
+ if strip_dir:
866
+ base = os.path.basename(base)
867
+ obj_names.append(os.path.join(output_dir,
868
+ base + self.obj_extension))
869
+ return obj_names
870
+
871
+ def shared_object_filename(self, basename, strip_dir=0, output_dir=''):
872
+ assert output_dir is not None
873
+ if strip_dir:
874
+ basename = os.path.basename(basename)
875
+ return os.path.join(output_dir, basename + self.shared_lib_extension)
876
+
877
+ def executable_filename(self, basename, strip_dir=0, output_dir=''):
878
+ assert output_dir is not None
879
+ if strip_dir:
880
+ basename = os.path.basename(basename)
881
+ return os.path.join(output_dir, basename + (self.exe_extension or ''))
882
+
883
+ def library_filename(self, libname, lib_type='static', # or 'shared'
884
+ strip_dir=0, output_dir=''):
885
+ assert output_dir is not None
886
+ if lib_type not in ("static", "shared", "dylib", "xcode_stub"):
887
+ raise ValueError(
888
+ "'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"")
889
+ fmt = getattr(self, lib_type + "_lib_format")
890
+ ext = getattr(self, lib_type + "_lib_extension")
891
+
892
+ dir, base = os.path.split(libname)
893
+ filename = fmt % (base, ext)
894
+ if strip_dir:
895
+ dir = ''
896
+
897
+ return os.path.join(output_dir, dir, filename)
898
+
899
+
900
+ # -- Utility methods -----------------------------------------------
901
+
902
+ def announce(self, msg, level=1):
903
+ log.debug(msg)
904
+
905
+ def debug_print(self, msg):
906
+ from distutils.debug import DEBUG
907
+ if DEBUG:
908
+ print(msg)
909
+
910
+ def warn(self, msg):
911
+ sys.stderr.write("warning: %s\n" % msg)
912
+
913
+ def execute(self, func, args, msg=None, level=1):
914
+ execute(func, args, msg, self.dry_run)
915
+
916
+ def spawn(self, cmd, **kwargs):
917
+ spawn(cmd, dry_run=self.dry_run, **kwargs)
918
+
919
+ def move_file(self, src, dst):
920
+ return move_file(src, dst, dry_run=self.dry_run)
921
+
922
+ def mkpath (self, name, mode=0o777):
923
+ mkpath(name, mode, dry_run=self.dry_run)
924
+
925
+
926
+ # Map a sys.platform/os.name ('posix', 'nt') to the default compiler
927
+ # type for that platform. Keys are interpreted as re match
928
+ # patterns. Order is important; platform mappings are preferred over
929
+ # OS names.
930
+ _default_compilers = (
931
+
932
+ # Platform string mappings
933
+
934
+ # on a cygwin built python we can use gcc like an ordinary UNIXish
935
+ # compiler
936
+ ('cygwin.*', 'unix'),
937
+
938
+ # OS name mappings
939
+ ('posix', 'unix'),
940
+ ('nt', 'msvc'),
941
+
942
+ )
943
+
944
+ def get_default_compiler(osname=None, platform=None):
945
+ """Determine the default compiler to use for the given platform.
946
+
947
+ osname should be one of the standard Python OS names (i.e. the
948
+ ones returned by os.name) and platform the common value
949
+ returned by sys.platform for the platform in question.
950
+
951
+ The default values are os.name and sys.platform in case the
952
+ parameters are not given.
953
+ """
954
+ if osname is None:
955
+ osname = os.name
956
+ if platform is None:
957
+ platform = sys.platform
958
+ for pattern, compiler in _default_compilers:
959
+ if re.match(pattern, platform) is not None or \
960
+ re.match(pattern, osname) is not None:
961
+ return compiler
962
+ # Default to Unix compiler
963
+ return 'unix'
964
+
965
+ # Map compiler types to (module_name, class_name) pairs -- ie. where to
966
+ # find the code that implements an interface to this compiler. (The module
967
+ # is assumed to be in the 'distutils' package.)
968
+ compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler',
969
+ "standard UNIX-style compiler"),
970
+ 'msvc': ('_msvccompiler', 'MSVCCompiler',
971
+ "Microsoft Visual C++"),
972
+ 'cygwin': ('cygwinccompiler', 'CygwinCCompiler',
973
+ "Cygwin port of GNU C Compiler for Win32"),
974
+ 'mingw32': ('cygwinccompiler', 'Mingw32CCompiler',
975
+ "Mingw32 port of GNU C Compiler for Win32"),
976
+ 'bcpp': ('bcppcompiler', 'BCPPCompiler',
977
+ "Borland C++ Compiler"),
978
+ }
979
+
980
+ def show_compilers():
981
+ """Print list of available compilers (used by the "--help-compiler"
982
+ options to "build", "build_ext", "build_clib").
983
+ """
984
+ # XXX this "knows" that the compiler option it's describing is
985
+ # "--compiler", which just happens to be the case for the three
986
+ # commands that use it.
987
+ from distutils.fancy_getopt import FancyGetopt
988
+ compilers = []
989
+ for compiler in compiler_class.keys():
990
+ compilers.append(("compiler="+compiler, None,
991
+ compiler_class[compiler][2]))
992
+ compilers.sort()
993
+ pretty_printer = FancyGetopt(compilers)
994
+ pretty_printer.print_help("List of available compilers:")
995
+
996
+
997
+ def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
998
+ """Generate an instance of some CCompiler subclass for the supplied
999
+ platform/compiler combination. 'plat' defaults to 'os.name'
1000
+ (eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler
1001
+ for that platform. Currently only 'posix' and 'nt' are supported, and
1002
+ the default compilers are "traditional Unix interface" (UnixCCompiler
1003
+ class) and Visual C++ (MSVCCompiler class). Note that it's perfectly
1004
+ possible to ask for a Unix compiler object under Windows, and a
1005
+ Microsoft compiler object under Unix -- if you supply a value for
1006
+ 'compiler', 'plat' is ignored.
1007
+ """
1008
+ if plat is None:
1009
+ plat = os.name
1010
+
1011
+ try:
1012
+ if compiler is None:
1013
+ compiler = get_default_compiler(plat)
1014
+
1015
+ (module_name, class_name, long_description) = compiler_class[compiler]
1016
+ except KeyError:
1017
+ msg = "don't know how to compile C/C++ code on platform '%s'" % plat
1018
+ if compiler is not None:
1019
+ msg = msg + " with '%s' compiler" % compiler
1020
+ raise DistutilsPlatformError(msg)
1021
+
1022
+ try:
1023
+ module_name = "distutils." + module_name
1024
+ __import__ (module_name)
1025
+ module = sys.modules[module_name]
1026
+ klass = vars(module)[class_name]
1027
+ except ImportError:
1028
+ raise DistutilsModuleError(
1029
+ "can't compile C/C++ code: unable to load module '%s'" % \
1030
+ module_name)
1031
+ except KeyError:
1032
+ raise DistutilsModuleError(
1033
+ "can't compile C/C++ code: unable to find class '%s' "
1034
+ "in module '%s'" % (class_name, module_name))
1035
+
1036
+ # XXX The None is necessary to preserve backwards compatibility
1037
+ # with classes that expect verbose to be the first positional
1038
+ # argument.
1039
+ return klass(None, dry_run, force)
1040
+
1041
+
1042
+ def gen_preprocess_options(macros, include_dirs):
1043
+ """Generate C pre-processor options (-D, -U, -I) as used by at least
1044
+ two types of compilers: the typical Unix compiler and Visual C++.
1045
+ 'macros' is the usual thing, a list of 1- or 2-tuples, where (name,)
1046
+ means undefine (-U) macro 'name', and (name,value) means define (-D)
1047
+ macro 'name' to 'value'. 'include_dirs' is just a list of directory
1048
+ names to be added to the header file search path (-I). Returns a list
1049
+ of command-line options suitable for either Unix compilers or Visual
1050
+ C++.
1051
+ """
1052
+ # XXX it would be nice (mainly aesthetic, and so we don't generate
1053
+ # stupid-looking command lines) to go over 'macros' and eliminate
1054
+ # redundant definitions/undefinitions (ie. ensure that only the
1055
+ # latest mention of a particular macro winds up on the command
1056
+ # line). I don't think it's essential, though, since most (all?)
1057
+ # Unix C compilers only pay attention to the latest -D or -U
1058
+ # mention of a macro on their command line. Similar situation for
1059
+ # 'include_dirs'. I'm punting on both for now. Anyways, weeding out
1060
+ # redundancies like this should probably be the province of
1061
+ # CCompiler, since the data structures used are inherited from it
1062
+ # and therefore common to all CCompiler classes.
1063
+ pp_opts = []
1064
+ for macro in macros:
1065
+ if not (isinstance(macro, tuple) and 1 <= len(macro) <= 2):
1066
+ raise TypeError(
1067
+ "bad macro definition '%s': "
1068
+ "each element of 'macros' list must be a 1- or 2-tuple"
1069
+ % macro)
1070
+
1071
+ if len(macro) == 1: # undefine this macro
1072
+ pp_opts.append("-U%s" % macro[0])
1073
+ elif len(macro) == 2:
1074
+ if macro[1] is None: # define with no explicit value
1075
+ pp_opts.append("-D%s" % macro[0])
1076
+ else:
1077
+ # XXX *don't* need to be clever about quoting the
1078
+ # macro value here, because we're going to avoid the
1079
+ # shell at all costs when we spawn the command!
1080
+ pp_opts.append("-D%s=%s" % macro)
1081
+
1082
+ for dir in include_dirs:
1083
+ pp_opts.append("-I%s" % dir)
1084
+ return pp_opts
1085
+
1086
+
1087
+ def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
1088
+ """Generate linker options for searching library directories and
1089
+ linking with specific libraries. 'libraries' and 'library_dirs' are,
1090
+ respectively, lists of library names (not filenames!) and search
1091
+ directories. Returns a list of command-line options suitable for use
1092
+ with some compiler (depending on the two format strings passed in).
1093
+ """
1094
+ lib_opts = []
1095
+
1096
+ for dir in library_dirs:
1097
+ lib_opts.append(compiler.library_dir_option(dir))
1098
+
1099
+ for dir in runtime_library_dirs:
1100
+ opt = compiler.runtime_library_dir_option(dir)
1101
+ if isinstance(opt, list):
1102
+ lib_opts = lib_opts + opt
1103
+ else:
1104
+ lib_opts.append(opt)
1105
+
1106
+ # XXX it's important that we *not* remove redundant library mentions!
1107
+ # sometimes you really do have to say "-lfoo -lbar -lfoo" in order to
1108
+ # resolve all symbols. I just hope we never have to say "-lfoo obj.o
1109
+ # -lbar" to get things to work -- that's certainly a possibility, but a
1110
+ # pretty nasty way to arrange your C code.
1111
+
1112
+ for lib in libraries:
1113
+ (lib_dir, lib_name) = os.path.split(lib)
1114
+ if lib_dir:
1115
+ lib_file = compiler.find_library_file([lib_dir], lib_name)
1116
+ if lib_file:
1117
+ lib_opts.append(lib_file)
1118
+ else:
1119
+ compiler.warn("no library file corresponding to "
1120
+ "'%s' found (skipping)" % lib)
1121
+ else:
1122
+ lib_opts.append(compiler.library_option (lib))
1123
+ return lib_opts
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/cmd.py ADDED
@@ -0,0 +1,403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.cmd
2
+
3
+ Provides the Command class, the base class for the command classes
4
+ in the distutils.command package.
5
+ """
6
+
7
+ import sys, os, re
8
+ from distutils.errors import DistutilsOptionError
9
+ from distutils import util, dir_util, file_util, archive_util, dep_util
10
+ from distutils import log
11
+
12
+ class Command:
13
+ """Abstract base class for defining command classes, the "worker bees"
14
+ of the Distutils. A useful analogy for command classes is to think of
15
+ them as subroutines with local variables called "options". The options
16
+ are "declared" in 'initialize_options()' and "defined" (given their
17
+ final values, aka "finalized") in 'finalize_options()', both of which
18
+ must be defined by every command class. The distinction between the
19
+ two is necessary because option values might come from the outside
20
+ world (command line, config file, ...), and any options dependent on
21
+ other options must be computed *after* these outside influences have
22
+ been processed -- hence 'finalize_options()'. The "body" of the
23
+ subroutine, where it does all its work based on the values of its
24
+ options, is the 'run()' method, which must also be implemented by every
25
+ command class.
26
+ """
27
+
28
+ # 'sub_commands' formalizes the notion of a "family" of commands,
29
+ # eg. "install" as the parent with sub-commands "install_lib",
30
+ # "install_headers", etc. The parent of a family of commands
31
+ # defines 'sub_commands' as a class attribute; it's a list of
32
+ # (command_name : string, predicate : unbound_method | string | None)
33
+ # tuples, where 'predicate' is a method of the parent command that
34
+ # determines whether the corresponding command is applicable in the
35
+ # current situation. (Eg. we "install_headers" is only applicable if
36
+ # we have any C header files to install.) If 'predicate' is None,
37
+ # that command is always applicable.
38
+ #
39
+ # 'sub_commands' is usually defined at the *end* of a class, because
40
+ # predicates can be unbound methods, so they must already have been
41
+ # defined. The canonical example is the "install" command.
42
+ sub_commands = []
43
+
44
+
45
+ # -- Creation/initialization methods -------------------------------
46
+
47
+ def __init__(self, dist):
48
+ """Create and initialize a new Command object. Most importantly,
49
+ invokes the 'initialize_options()' method, which is the real
50
+ initializer and depends on the actual command being
51
+ instantiated.
52
+ """
53
+ # late import because of mutual dependence between these classes
54
+ from distutils.dist import Distribution
55
+
56
+ if not isinstance(dist, Distribution):
57
+ raise TypeError("dist must be a Distribution instance")
58
+ if self.__class__ is Command:
59
+ raise RuntimeError("Command is an abstract class")
60
+
61
+ self.distribution = dist
62
+ self.initialize_options()
63
+
64
+ # Per-command versions of the global flags, so that the user can
65
+ # customize Distutils' behaviour command-by-command and let some
66
+ # commands fall back on the Distribution's behaviour. None means
67
+ # "not defined, check self.distribution's copy", while 0 or 1 mean
68
+ # false and true (duh). Note that this means figuring out the real
69
+ # value of each flag is a touch complicated -- hence "self._dry_run"
70
+ # will be handled by __getattr__, below.
71
+ # XXX This needs to be fixed.
72
+ self._dry_run = None
73
+
74
+ # verbose is largely ignored, but needs to be set for
75
+ # backwards compatibility (I think)?
76
+ self.verbose = dist.verbose
77
+
78
+ # Some commands define a 'self.force' option to ignore file
79
+ # timestamps, but methods defined *here* assume that
80
+ # 'self.force' exists for all commands. So define it here
81
+ # just to be safe.
82
+ self.force = None
83
+
84
+ # The 'help' flag is just used for command-line parsing, so
85
+ # none of that complicated bureaucracy is needed.
86
+ self.help = 0
87
+
88
+ # 'finalized' records whether or not 'finalize_options()' has been
89
+ # called. 'finalize_options()' itself should not pay attention to
90
+ # this flag: it is the business of 'ensure_finalized()', which
91
+ # always calls 'finalize_options()', to respect/update it.
92
+ self.finalized = 0
93
+
94
+ # XXX A more explicit way to customize dry_run would be better.
95
+ def __getattr__(self, attr):
96
+ if attr == 'dry_run':
97
+ myval = getattr(self, "_" + attr)
98
+ if myval is None:
99
+ return getattr(self.distribution, attr)
100
+ else:
101
+ return myval
102
+ else:
103
+ raise AttributeError(attr)
104
+
105
+ def ensure_finalized(self):
106
+ if not self.finalized:
107
+ self.finalize_options()
108
+ self.finalized = 1
109
+
110
+ # Subclasses must define:
111
+ # initialize_options()
112
+ # provide default values for all options; may be customized by
113
+ # setup script, by options from config file(s), or by command-line
114
+ # options
115
+ # finalize_options()
116
+ # decide on the final values for all options; this is called
117
+ # after all possible intervention from the outside world
118
+ # (command-line, option file, etc.) has been processed
119
+ # run()
120
+ # run the command: do whatever it is we're here to do,
121
+ # controlled by the command's various option values
122
+
123
+ def initialize_options(self):
124
+ """Set default values for all the options that this command
125
+ supports. Note that these defaults may be overridden by other
126
+ commands, by the setup script, by config files, or by the
127
+ command-line. Thus, this is not the place to code dependencies
128
+ between options; generally, 'initialize_options()' implementations
129
+ are just a bunch of "self.foo = None" assignments.
130
+
131
+ This method must be implemented by all command classes.
132
+ """
133
+ raise RuntimeError("abstract method -- subclass %s must override"
134
+ % self.__class__)
135
+
136
+ def finalize_options(self):
137
+ """Set final values for all the options that this command supports.
138
+ This is always called as late as possible, ie. after any option
139
+ assignments from the command-line or from other commands have been
140
+ done. Thus, this is the place to code option dependencies: if
141
+ 'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as
142
+ long as 'foo' still has the same value it was assigned in
143
+ 'initialize_options()'.
144
+
145
+ This method must be implemented by all command classes.
146
+ """
147
+ raise RuntimeError("abstract method -- subclass %s must override"
148
+ % self.__class__)
149
+
150
+
151
+ def dump_options(self, header=None, indent=""):
152
+ from distutils.fancy_getopt import longopt_xlate
153
+ if header is None:
154
+ header = "command options for '%s':" % self.get_command_name()
155
+ self.announce(indent + header, level=log.INFO)
156
+ indent = indent + " "
157
+ for (option, _, _) in self.user_options:
158
+ option = option.translate(longopt_xlate)
159
+ if option[-1] == "=":
160
+ option = option[:-1]
161
+ value = getattr(self, option)
162
+ self.announce(indent + "%s = %s" % (option, value),
163
+ level=log.INFO)
164
+
165
+ def run(self):
166
+ """A command's raison d'etre: carry out the action it exists to
167
+ perform, controlled by the options initialized in
168
+ 'initialize_options()', customized by other commands, the setup
169
+ script, the command-line, and config files, and finalized in
170
+ 'finalize_options()'. All terminal output and filesystem
171
+ interaction should be done by 'run()'.
172
+
173
+ This method must be implemented by all command classes.
174
+ """
175
+ raise RuntimeError("abstract method -- subclass %s must override"
176
+ % self.__class__)
177
+
178
+ def announce(self, msg, level=1):
179
+ """If the current verbosity level is of greater than or equal to
180
+ 'level' print 'msg' to stdout.
181
+ """
182
+ log.log(level, msg)
183
+
184
+ def debug_print(self, msg):
185
+ """Print 'msg' to stdout if the global DEBUG (taken from the
186
+ DISTUTILS_DEBUG environment variable) flag is true.
187
+ """
188
+ from distutils.debug import DEBUG
189
+ if DEBUG:
190
+ print(msg)
191
+ sys.stdout.flush()
192
+
193
+
194
+ # -- Option validation methods -------------------------------------
195
+ # (these are very handy in writing the 'finalize_options()' method)
196
+ #
197
+ # NB. the general philosophy here is to ensure that a particular option
198
+ # value meets certain type and value constraints. If not, we try to
199
+ # force it into conformance (eg. if we expect a list but have a string,
200
+ # split the string on comma and/or whitespace). If we can't force the
201
+ # option into conformance, raise DistutilsOptionError. Thus, command
202
+ # classes need do nothing more than (eg.)
203
+ # self.ensure_string_list('foo')
204
+ # and they can be guaranteed that thereafter, self.foo will be
205
+ # a list of strings.
206
+
207
+ def _ensure_stringlike(self, option, what, default=None):
208
+ val = getattr(self, option)
209
+ if val is None:
210
+ setattr(self, option, default)
211
+ return default
212
+ elif not isinstance(val, str):
213
+ raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
214
+ % (option, what, val))
215
+ return val
216
+
217
+ def ensure_string(self, option, default=None):
218
+ """Ensure that 'option' is a string; if not defined, set it to
219
+ 'default'.
220
+ """
221
+ self._ensure_stringlike(option, "string", default)
222
+
223
+ def ensure_string_list(self, option):
224
+ r"""Ensure that 'option' is a list of strings. If 'option' is
225
+ currently a string, we split it either on /,\s*/ or /\s+/, so
226
+ "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
227
+ ["foo", "bar", "baz"].
228
+ """
229
+ val = getattr(self, option)
230
+ if val is None:
231
+ return
232
+ elif isinstance(val, str):
233
+ setattr(self, option, re.split(r',\s*|\s+', val))
234
+ else:
235
+ if isinstance(val, list):
236
+ ok = all(isinstance(v, str) for v in val)
237
+ else:
238
+ ok = False
239
+ if not ok:
240
+ raise DistutilsOptionError(
241
+ "'%s' must be a list of strings (got %r)"
242
+ % (option, val))
243
+
244
+ def _ensure_tested_string(self, option, tester, what, error_fmt,
245
+ default=None):
246
+ val = self._ensure_stringlike(option, what, default)
247
+ if val is not None and not tester(val):
248
+ raise DistutilsOptionError(("error in '%s' option: " + error_fmt)
249
+ % (option, val))
250
+
251
+ def ensure_filename(self, option):
252
+ """Ensure that 'option' is the name of an existing file."""
253
+ self._ensure_tested_string(option, os.path.isfile,
254
+ "filename",
255
+ "'%s' does not exist or is not a file")
256
+
257
+ def ensure_dirname(self, option):
258
+ self._ensure_tested_string(option, os.path.isdir,
259
+ "directory name",
260
+ "'%s' does not exist or is not a directory")
261
+
262
+
263
+ # -- Convenience methods for commands ------------------------------
264
+
265
+ def get_command_name(self):
266
+ if hasattr(self, 'command_name'):
267
+ return self.command_name
268
+ else:
269
+ return self.__class__.__name__
270
+
271
+ def set_undefined_options(self, src_cmd, *option_pairs):
272
+ """Set the values of any "undefined" options from corresponding
273
+ option values in some other command object. "Undefined" here means
274
+ "is None", which is the convention used to indicate that an option
275
+ has not been changed between 'initialize_options()' and
276
+ 'finalize_options()'. Usually called from 'finalize_options()' for
277
+ options that depend on some other command rather than another
278
+ option of the same command. 'src_cmd' is the other command from
279
+ which option values will be taken (a command object will be created
280
+ for it if necessary); the remaining arguments are
281
+ '(src_option,dst_option)' tuples which mean "take the value of
282
+ 'src_option' in the 'src_cmd' command object, and copy it to
283
+ 'dst_option' in the current command object".
284
+ """
285
+ # Option_pairs: list of (src_option, dst_option) tuples
286
+ src_cmd_obj = self.distribution.get_command_obj(src_cmd)
287
+ src_cmd_obj.ensure_finalized()
288
+ for (src_option, dst_option) in option_pairs:
289
+ if getattr(self, dst_option) is None:
290
+ setattr(self, dst_option, getattr(src_cmd_obj, src_option))
291
+
292
+ def get_finalized_command(self, command, create=1):
293
+ """Wrapper around Distribution's 'get_command_obj()' method: find
294
+ (create if necessary and 'create' is true) the command object for
295
+ 'command', call its 'ensure_finalized()' method, and return the
296
+ finalized command object.
297
+ """
298
+ cmd_obj = self.distribution.get_command_obj(command, create)
299
+ cmd_obj.ensure_finalized()
300
+ return cmd_obj
301
+
302
+ # XXX rename to 'get_reinitialized_command()'? (should do the
303
+ # same in dist.py, if so)
304
+ def reinitialize_command(self, command, reinit_subcommands=0):
305
+ return self.distribution.reinitialize_command(command,
306
+ reinit_subcommands)
307
+
308
+ def run_command(self, command):
309
+ """Run some other command: uses the 'run_command()' method of
310
+ Distribution, which creates and finalizes the command object if
311
+ necessary and then invokes its 'run()' method.
312
+ """
313
+ self.distribution.run_command(command)
314
+
315
+ def get_sub_commands(self):
316
+ """Determine the sub-commands that are relevant in the current
317
+ distribution (ie., that need to be run). This is based on the
318
+ 'sub_commands' class attribute: each tuple in that list may include
319
+ a method that we call to determine if the subcommand needs to be
320
+ run for the current distribution. Return a list of command names.
321
+ """
322
+ commands = []
323
+ for (cmd_name, method) in self.sub_commands:
324
+ if method is None or method(self):
325
+ commands.append(cmd_name)
326
+ return commands
327
+
328
+
329
+ # -- External world manipulation -----------------------------------
330
+
331
+ def warn(self, msg):
332
+ log.warn("warning: %s: %s\n", self.get_command_name(), msg)
333
+
334
+ def execute(self, func, args, msg=None, level=1):
335
+ util.execute(func, args, msg, dry_run=self.dry_run)
336
+
337
+ def mkpath(self, name, mode=0o777):
338
+ dir_util.mkpath(name, mode, dry_run=self.dry_run)
339
+
340
+ def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
341
+ link=None, level=1):
342
+ """Copy a file respecting verbose, dry-run and force flags. (The
343
+ former two default to whatever is in the Distribution object, and
344
+ the latter defaults to false for commands that don't define it.)"""
345
+ return file_util.copy_file(infile, outfile, preserve_mode,
346
+ preserve_times, not self.force, link,
347
+ dry_run=self.dry_run)
348
+
349
+ def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1,
350
+ preserve_symlinks=0, level=1):
351
+ """Copy an entire directory tree respecting verbose, dry-run,
352
+ and force flags.
353
+ """
354
+ return dir_util.copy_tree(infile, outfile, preserve_mode,
355
+ preserve_times, preserve_symlinks,
356
+ not self.force, dry_run=self.dry_run)
357
+
358
+ def move_file (self, src, dst, level=1):
359
+ """Move a file respecting dry-run flag."""
360
+ return file_util.move_file(src, dst, dry_run=self.dry_run)
361
+
362
+ def spawn(self, cmd, search_path=1, level=1):
363
+ """Spawn an external command respecting dry-run flag."""
364
+ from distutils.spawn import spawn
365
+ spawn(cmd, search_path, dry_run=self.dry_run)
366
+
367
+ def make_archive(self, base_name, format, root_dir=None, base_dir=None,
368
+ owner=None, group=None):
369
+ return archive_util.make_archive(base_name, format, root_dir, base_dir,
370
+ dry_run=self.dry_run,
371
+ owner=owner, group=group)
372
+
373
+ def make_file(self, infiles, outfile, func, args,
374
+ exec_msg=None, skip_msg=None, level=1):
375
+ """Special case of 'execute()' for operations that process one or
376
+ more input files and generate one output file. Works just like
377
+ 'execute()', except the operation is skipped and a different
378
+ message printed if 'outfile' already exists and is newer than all
379
+ files listed in 'infiles'. If the command defined 'self.force',
380
+ and it is true, then the command is unconditionally run -- does no
381
+ timestamp checks.
382
+ """
383
+ if skip_msg is None:
384
+ skip_msg = "skipping %s (inputs unchanged)" % outfile
385
+
386
+ # Allow 'infiles' to be a single string
387
+ if isinstance(infiles, str):
388
+ infiles = (infiles,)
389
+ elif not isinstance(infiles, (list, tuple)):
390
+ raise TypeError(
391
+ "'infiles' must be a string, or a list or tuple of strings")
392
+
393
+ if exec_msg is None:
394
+ exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles))
395
+
396
+ # If 'outfile' must be regenerated (either because it doesn't
397
+ # exist, is out-of-date, or the 'force' flag is true) then
398
+ # perform the action that presumably regenerates it
399
+ if self.force or dep_util.newer_group(infiles, outfile):
400
+ self.execute(func, args, exec_msg, level)
401
+ # Otherwise, print the "skip" message
402
+ else:
403
+ log.debug(skip_msg)
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/config.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.pypirc
2
+
3
+ Provides the PyPIRCCommand class, the base class for the command classes
4
+ that uses .pypirc in the distutils.command package.
5
+ """
6
+ import os
7
+ from configparser import RawConfigParser
8
+
9
+ from distutils.cmd import Command
10
+
11
+ DEFAULT_PYPIRC = """\
12
+ [distutils]
13
+ index-servers =
14
+ pypi
15
+
16
+ [pypi]
17
+ username:%s
18
+ password:%s
19
+ """
20
+
21
+ class PyPIRCCommand(Command):
22
+ """Base command that knows how to handle the .pypirc file
23
+ """
24
+ DEFAULT_REPOSITORY = 'https://upload.pypi.org/legacy/'
25
+ DEFAULT_REALM = 'pypi'
26
+ repository = None
27
+ realm = None
28
+
29
+ user_options = [
30
+ ('repository=', 'r',
31
+ "url of repository [default: %s]" % \
32
+ DEFAULT_REPOSITORY),
33
+ ('show-response', None,
34
+ 'display full response text from server')]
35
+
36
+ boolean_options = ['show-response']
37
+
38
+ def _get_rc_file(self):
39
+ """Returns rc file path."""
40
+ return os.path.join(os.path.expanduser('~'), '.pypirc')
41
+
42
+ def _store_pypirc(self, username, password):
43
+ """Creates a default .pypirc file."""
44
+ rc = self._get_rc_file()
45
+ with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
46
+ f.write(DEFAULT_PYPIRC % (username, password))
47
+
48
+ def _read_pypirc(self):
49
+ """Reads the .pypirc file."""
50
+ rc = self._get_rc_file()
51
+ if os.path.exists(rc):
52
+ self.announce('Using PyPI login from %s' % rc)
53
+ repository = self.repository or self.DEFAULT_REPOSITORY
54
+
55
+ config = RawConfigParser()
56
+ config.read(rc)
57
+ sections = config.sections()
58
+ if 'distutils' in sections:
59
+ # let's get the list of servers
60
+ index_servers = config.get('distutils', 'index-servers')
61
+ _servers = [server.strip() for server in
62
+ index_servers.split('\n')
63
+ if server.strip() != '']
64
+ if _servers == []:
65
+ # nothing set, let's try to get the default pypi
66
+ if 'pypi' in sections:
67
+ _servers = ['pypi']
68
+ else:
69
+ # the file is not properly defined, returning
70
+ # an empty dict
71
+ return {}
72
+ for server in _servers:
73
+ current = {'server': server}
74
+ current['username'] = config.get(server, 'username')
75
+
76
+ # optional params
77
+ for key, default in (('repository',
78
+ self.DEFAULT_REPOSITORY),
79
+ ('realm', self.DEFAULT_REALM),
80
+ ('password', None)):
81
+ if config.has_option(server, key):
82
+ current[key] = config.get(server, key)
83
+ else:
84
+ current[key] = default
85
+
86
+ # work around people having "repository" for the "pypi"
87
+ # section of their config set to the HTTP (rather than
88
+ # HTTPS) URL
89
+ if (server == 'pypi' and
90
+ repository in (self.DEFAULT_REPOSITORY, 'pypi')):
91
+ current['repository'] = self.DEFAULT_REPOSITORY
92
+ return current
93
+
94
+ if (current['server'] == repository or
95
+ current['repository'] == repository):
96
+ return current
97
+ elif 'server-login' in sections:
98
+ # old format
99
+ server = 'server-login'
100
+ if config.has_option(server, 'repository'):
101
+ repository = config.get(server, 'repository')
102
+ else:
103
+ repository = self.DEFAULT_REPOSITORY
104
+ return {'username': config.get(server, 'username'),
105
+ 'password': config.get(server, 'password'),
106
+ 'repository': repository,
107
+ 'server': server,
108
+ 'realm': self.DEFAULT_REALM}
109
+
110
+ return {}
111
+
112
+ def _read_pypi_response(self, response):
113
+ """Read and decode a PyPI HTTP response."""
114
+ import cgi
115
+ content_type = response.getheader('content-type', 'text/plain')
116
+ encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
117
+ return response.read().decode(encoding)
118
+
119
+ def initialize_options(self):
120
+ """Initialize options."""
121
+ self.repository = None
122
+ self.realm = None
123
+ self.show_response = 0
124
+
125
+ def finalize_options(self):
126
+ """Finalizes options."""
127
+ if self.repository is None:
128
+ self.repository = self.DEFAULT_REPOSITORY
129
+ if self.realm is None:
130
+ self.realm = self.DEFAULT_REALM
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/core.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.core
2
+
3
+ The only module that needs to be imported to use the Distutils; provides
4
+ the 'setup' function (which is to be called from the setup script). Also
5
+ indirectly provides the Distribution and Command classes, although they are
6
+ really defined in distutils.dist and distutils.cmd.
7
+ """
8
+
9
+ import os
10
+ import sys
11
+ import tokenize
12
+
13
+ from distutils.debug import DEBUG
14
+ from distutils.errors import *
15
+
16
+ # Mainly import these so setup scripts can "from distutils.core import" them.
17
+ from distutils.dist import Distribution
18
+ from distutils.cmd import Command
19
+ from distutils.config import PyPIRCCommand
20
+ from distutils.extension import Extension
21
+
22
+ # This is a barebones help message generated displayed when the user
23
+ # runs the setup script with no arguments at all. More useful help
24
+ # is generated with various --help options: global help, list commands,
25
+ # and per-command help.
26
+ USAGE = """\
27
+ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
28
+ or: %(script)s --help [cmd1 cmd2 ...]
29
+ or: %(script)s --help-commands
30
+ or: %(script)s cmd --help
31
+ """
32
+
33
+ def gen_usage (script_name):
34
+ script = os.path.basename(script_name)
35
+ return USAGE % vars()
36
+
37
+
38
+ # Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
39
+ _setup_stop_after = None
40
+ _setup_distribution = None
41
+
42
+ # Legal keyword arguments for the setup() function
43
+ setup_keywords = ('distclass', 'script_name', 'script_args', 'options',
44
+ 'name', 'version', 'author', 'author_email',
45
+ 'maintainer', 'maintainer_email', 'url', 'license',
46
+ 'description', 'long_description', 'keywords',
47
+ 'platforms', 'classifiers', 'download_url',
48
+ 'requires', 'provides', 'obsoletes',
49
+ )
50
+
51
+ # Legal keyword arguments for the Extension constructor
52
+ extension_keywords = ('name', 'sources', 'include_dirs',
53
+ 'define_macros', 'undef_macros',
54
+ 'library_dirs', 'libraries', 'runtime_library_dirs',
55
+ 'extra_objects', 'extra_compile_args', 'extra_link_args',
56
+ 'swig_opts', 'export_symbols', 'depends', 'language')
57
+
58
+ def setup (**attrs):
59
+ """The gateway to the Distutils: do everything your setup script needs
60
+ to do, in a highly flexible and user-driven way. Briefly: create a
61
+ Distribution instance; find and parse config files; parse the command
62
+ line; run each Distutils command found there, customized by the options
63
+ supplied to 'setup()' (as keyword arguments), in config files, and on
64
+ the command line.
65
+
66
+ The Distribution instance might be an instance of a class supplied via
67
+ the 'distclass' keyword argument to 'setup'; if no such class is
68
+ supplied, then the Distribution class (in dist.py) is instantiated.
69
+ All other arguments to 'setup' (except for 'cmdclass') are used to set
70
+ attributes of the Distribution instance.
71
+
72
+ The 'cmdclass' argument, if supplied, is a dictionary mapping command
73
+ names to command classes. Each command encountered on the command line
74
+ will be turned into a command class, which is in turn instantiated; any
75
+ class found in 'cmdclass' is used in place of the default, which is
76
+ (for command 'foo_bar') class 'foo_bar' in module
77
+ 'distutils.command.foo_bar'. The command class must provide a
78
+ 'user_options' attribute which is a list of option specifiers for
79
+ 'distutils.fancy_getopt'. Any command-line options between the current
80
+ and the next command are used to set attributes of the current command
81
+ object.
82
+
83
+ When the entire command-line has been successfully parsed, calls the
84
+ 'run()' method on each command object in turn. This method will be
85
+ driven entirely by the Distribution object (which each command object
86
+ has a reference to, thanks to its constructor), and the
87
+ command-specific options that became attributes of each command
88
+ object.
89
+ """
90
+
91
+ global _setup_stop_after, _setup_distribution
92
+
93
+ # Determine the distribution class -- either caller-supplied or
94
+ # our Distribution (see below).
95
+ klass = attrs.get('distclass')
96
+ if klass:
97
+ del attrs['distclass']
98
+ else:
99
+ klass = Distribution
100
+
101
+ if 'script_name' not in attrs:
102
+ attrs['script_name'] = os.path.basename(sys.argv[0])
103
+ if 'script_args' not in attrs:
104
+ attrs['script_args'] = sys.argv[1:]
105
+
106
+ # Create the Distribution instance, using the remaining arguments
107
+ # (ie. everything except distclass) to initialize it
108
+ try:
109
+ _setup_distribution = dist = klass(attrs)
110
+ except DistutilsSetupError as msg:
111
+ if 'name' not in attrs:
112
+ raise SystemExit("error in setup command: %s" % msg)
113
+ else:
114
+ raise SystemExit("error in %s setup command: %s" % \
115
+ (attrs['name'], msg))
116
+
117
+ if _setup_stop_after == "init":
118
+ return dist
119
+
120
+ # Find and parse the config file(s): they will override options from
121
+ # the setup script, but be overridden by the command line.
122
+ dist.parse_config_files()
123
+
124
+ if DEBUG:
125
+ print("options (after parsing config files):")
126
+ dist.dump_option_dicts()
127
+
128
+ if _setup_stop_after == "config":
129
+ return dist
130
+
131
+ # Parse the command line and override config files; any
132
+ # command-line errors are the end user's fault, so turn them into
133
+ # SystemExit to suppress tracebacks.
134
+ try:
135
+ ok = dist.parse_command_line()
136
+ except DistutilsArgError as msg:
137
+ raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg)
138
+
139
+ if DEBUG:
140
+ print("options (after parsing command line):")
141
+ dist.dump_option_dicts()
142
+
143
+ if _setup_stop_after == "commandline":
144
+ return dist
145
+
146
+ # And finally, run all the commands found on the command line.
147
+ if ok:
148
+ return run_commands(dist)
149
+
150
+ return dist
151
+
152
+ # setup ()
153
+
154
+
155
+ def run_commands (dist):
156
+ """Given a Distribution object run all the commands,
157
+ raising ``SystemExit`` errors in the case of failure.
158
+
159
+ This function assumes that either ``sys.argv`` or ``dist.script_args``
160
+ is already set accordingly.
161
+ """
162
+ try:
163
+ dist.run_commands()
164
+ except KeyboardInterrupt:
165
+ raise SystemExit("interrupted")
166
+ except OSError as exc:
167
+ if DEBUG:
168
+ sys.stderr.write("error: %s\n" % (exc,))
169
+ raise
170
+ else:
171
+ raise SystemExit("error: %s" % (exc,))
172
+
173
+ except (DistutilsError,
174
+ CCompilerError) as msg:
175
+ if DEBUG:
176
+ raise
177
+ else:
178
+ raise SystemExit("error: " + str(msg))
179
+
180
+ return dist
181
+
182
+
183
+ def run_setup (script_name, script_args=None, stop_after="run"):
184
+ """Run a setup script in a somewhat controlled environment, and
185
+ return the Distribution instance that drives things. This is useful
186
+ if you need to find out the distribution meta-data (passed as
187
+ keyword args from 'script' to 'setup()', or the contents of the
188
+ config files or command-line.
189
+
190
+ 'script_name' is a file that will be read and run with 'exec()';
191
+ 'sys.argv[0]' will be replaced with 'script' for the duration of the
192
+ call. 'script_args' is a list of strings; if supplied,
193
+ 'sys.argv[1:]' will be replaced by 'script_args' for the duration of
194
+ the call.
195
+
196
+ 'stop_after' tells 'setup()' when to stop processing; possible
197
+ values:
198
+ init
199
+ stop after the Distribution instance has been created and
200
+ populated with the keyword arguments to 'setup()'
201
+ config
202
+ stop after config files have been parsed (and their data
203
+ stored in the Distribution instance)
204
+ commandline
205
+ stop after the command-line ('sys.argv[1:]' or 'script_args')
206
+ have been parsed (and the data stored in the Distribution)
207
+ run [default]
208
+ stop after all commands have been run (the same as if 'setup()'
209
+ had been called in the usual way
210
+
211
+ Returns the Distribution instance, which provides all information
212
+ used to drive the Distutils.
213
+ """
214
+ if stop_after not in ('init', 'config', 'commandline', 'run'):
215
+ raise ValueError("invalid value for 'stop_after': %r" % (stop_after,))
216
+
217
+ global _setup_stop_after, _setup_distribution
218
+ _setup_stop_after = stop_after
219
+
220
+ save_argv = sys.argv.copy()
221
+ g = {'__file__': script_name, '__name__': '__main__'}
222
+ try:
223
+ try:
224
+ sys.argv[0] = script_name
225
+ if script_args is not None:
226
+ sys.argv[1:] = script_args
227
+ # tokenize.open supports automatic encoding detection
228
+ with tokenize.open(script_name) as f:
229
+ code = f.read().replace(r'\r\n', r'\n')
230
+ exec(code, g)
231
+ finally:
232
+ sys.argv = save_argv
233
+ _setup_stop_after = None
234
+ except SystemExit:
235
+ # Hmm, should we do something if exiting with a non-zero code
236
+ # (ie. error)?
237
+ pass
238
+
239
+ if _setup_distribution is None:
240
+ raise RuntimeError(("'distutils.core.setup()' was never called -- "
241
+ "perhaps '%s' is not a Distutils setup script?") % \
242
+ script_name)
243
+
244
+ # I wonder if the setup script's namespace -- g and l -- would be of
245
+ # any interest to callers?
246
+ #print "_setup_distribution:", _setup_distribution
247
+ return _setup_distribution
248
+
249
+ # run_setup ()
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.py ADDED
@@ -0,0 +1,425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.cygwinccompiler
2
+
3
+ Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
4
+ handles the Cygwin port of the GNU C compiler to Windows. It also contains
5
+ the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
6
+ cygwin in no-cygwin mode).
7
+ """
8
+
9
+ # problems:
10
+ #
11
+ # * if you use a msvc compiled python version (1.5.2)
12
+ # 1. you have to insert a __GNUC__ section in its config.h
13
+ # 2. you have to generate an import library for its dll
14
+ # - create a def-file for python??.dll
15
+ # - create an import library using
16
+ # dlltool --dllname python15.dll --def python15.def \
17
+ # --output-lib libpython15.a
18
+ #
19
+ # see also http://starship.python.net/crew/kernr/mingw32/Notes.html
20
+ #
21
+ # * We put export_symbols in a def-file, and don't use
22
+ # --export-all-symbols because it doesn't worked reliable in some
23
+ # tested configurations. And because other windows compilers also
24
+ # need their symbols specified this no serious problem.
25
+ #
26
+ # tested configurations:
27
+ #
28
+ # * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works
29
+ # (after patching python's config.h and for C++ some other include files)
30
+ # see also http://starship.python.net/crew/kernr/mingw32/Notes.html
31
+ # * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works
32
+ # (ld doesn't support -shared, so we use dllwrap)
33
+ # * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now
34
+ # - its dllwrap doesn't work, there is a bug in binutils 2.10.90
35
+ # see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html
36
+ # - using gcc -mdll instead dllwrap doesn't work without -static because
37
+ # it tries to link against dlls instead their import libraries. (If
38
+ # it finds the dll first.)
39
+ # By specifying -static we force ld to link against the import libraries,
40
+ # this is windows standard and there are normally not the necessary symbols
41
+ # in the dlls.
42
+ # *** only the version of June 2000 shows these problems
43
+ # * cygwin gcc 3.2/ld 2.13.90 works
44
+ # (ld supports -shared)
45
+ # * mingw gcc 3.2/ld 2.13 works
46
+ # (ld supports -shared)
47
+ # * llvm-mingw with Clang 11 works
48
+ # (lld supports -shared)
49
+
50
+ import os
51
+ import sys
52
+ import copy
53
+ from subprocess import Popen, PIPE, check_output
54
+ import re
55
+
56
+ import distutils.version
57
+ from distutils.unixccompiler import UnixCCompiler
58
+ from distutils.file_util import write_file
59
+ from distutils.errors import (DistutilsExecError, CCompilerError,
60
+ CompileError, UnknownFileError)
61
+ from distutils.version import LooseVersion
62
+ from distutils.spawn import find_executable
63
+
64
+ def get_msvcr():
65
+ """Include the appropriate MSVC runtime library if Python was built
66
+ with MSVC 7.0 or later.
67
+ """
68
+ msc_pos = sys.version.find('MSC v.')
69
+ if msc_pos != -1:
70
+ msc_ver = sys.version[msc_pos+6:msc_pos+10]
71
+ if msc_ver == '1300':
72
+ # MSVC 7.0
73
+ return ['msvcr70']
74
+ elif msc_ver == '1310':
75
+ # MSVC 7.1
76
+ return ['msvcr71']
77
+ elif msc_ver == '1400':
78
+ # VS2005 / MSVC 8.0
79
+ return ['msvcr80']
80
+ elif msc_ver == '1500':
81
+ # VS2008 / MSVC 9.0
82
+ return ['msvcr90']
83
+ elif msc_ver == '1600':
84
+ # VS2010 / MSVC 10.0
85
+ return ['msvcr100']
86
+ elif msc_ver == '1700':
87
+ # VS2012 / MSVC 11.0
88
+ return ['msvcr110']
89
+ elif msc_ver == '1800':
90
+ # VS2013 / MSVC 12.0
91
+ return ['msvcr120']
92
+ elif 1900 <= int(msc_ver) < 2000:
93
+ # VS2015 / MSVC 14.0
94
+ return ['ucrt', 'vcruntime140']
95
+ else:
96
+ raise ValueError("Unknown MS Compiler version %s " % msc_ver)
97
+
98
+
99
+ class CygwinCCompiler(UnixCCompiler):
100
+ """ Handles the Cygwin port of the GNU C compiler to Windows.
101
+ """
102
+ compiler_type = 'cygwin'
103
+ obj_extension = ".o"
104
+ static_lib_extension = ".a"
105
+ shared_lib_extension = ".dll"
106
+ static_lib_format = "lib%s%s"
107
+ shared_lib_format = "%s%s"
108
+ exe_extension = ".exe"
109
+
110
+ def __init__(self, verbose=0, dry_run=0, force=0):
111
+
112
+ UnixCCompiler.__init__(self, verbose, dry_run, force)
113
+
114
+ status, details = check_config_h()
115
+ self.debug_print("Python's GCC status: %s (details: %s)" %
116
+ (status, details))
117
+ if status is not CONFIG_H_OK:
118
+ self.warn(
119
+ "Python's pyconfig.h doesn't seem to support your compiler. "
120
+ "Reason: %s. "
121
+ "Compiling may fail because of undefined preprocessor macros."
122
+ % details)
123
+
124
+ self.cc = os.environ.get('CC', 'gcc')
125
+ self.cxx = os.environ.get('CXX', 'g++')
126
+
127
+ if ('gcc' in self.cc): # Start gcc workaround
128
+ self.gcc_version, self.ld_version, self.dllwrap_version = \
129
+ get_versions()
130
+ self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
131
+ (self.gcc_version,
132
+ self.ld_version,
133
+ self.dllwrap_version) )
134
+
135
+ # ld_version >= "2.10.90" and < "2.13" should also be able to use
136
+ # gcc -mdll instead of dllwrap
137
+ # Older dllwraps had own version numbers, newer ones use the
138
+ # same as the rest of binutils ( also ld )
139
+ # dllwrap 2.10.90 is buggy
140
+ if self.ld_version >= "2.10.90":
141
+ self.linker_dll = self.cc
142
+ else:
143
+ self.linker_dll = "dllwrap"
144
+
145
+ # ld_version >= "2.13" support -shared so use it instead of
146
+ # -mdll -static
147
+ if self.ld_version >= "2.13":
148
+ shared_option = "-shared"
149
+ else:
150
+ shared_option = "-mdll -static"
151
+ else: # Assume linker is up to date
152
+ self.linker_dll = self.cc
153
+ shared_option = "-shared"
154
+
155
+ self.set_executables(compiler='%s -mcygwin -O -Wall' % self.cc,
156
+ compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc,
157
+ compiler_cxx='%s -mcygwin -O -Wall' % self.cxx,
158
+ linker_exe='%s -mcygwin' % self.cc,
159
+ linker_so=('%s -mcygwin %s' %
160
+ (self.linker_dll, shared_option)))
161
+
162
+ # cygwin and mingw32 need different sets of libraries
163
+ if ('gcc' in self.cc and self.gcc_version == "2.91.57"):
164
+ # cygwin shouldn't need msvcrt, but without the dlls will crash
165
+ # (gcc version 2.91.57) -- perhaps something about initialization
166
+ self.dll_libraries=["msvcrt"]
167
+ self.warn(
168
+ "Consider upgrading to a newer version of gcc")
169
+ else:
170
+ # Include the appropriate MSVC runtime library if Python was built
171
+ # with MSVC 7.0 or later.
172
+ self.dll_libraries = get_msvcr()
173
+
174
+ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
175
+ """Compiles the source by spawning GCC and windres if needed."""
176
+ if ext == '.rc' or ext == '.res':
177
+ # gcc needs '.res' and '.rc' compiled to object files !!!
178
+ try:
179
+ self.spawn(["windres", "-i", src, "-o", obj])
180
+ except DistutilsExecError as msg:
181
+ raise CompileError(msg)
182
+ else: # for other files use the C-compiler
183
+ try:
184
+ self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
185
+ extra_postargs)
186
+ except DistutilsExecError as msg:
187
+ raise CompileError(msg)
188
+
189
+ def link(self, target_desc, objects, output_filename, output_dir=None,
190
+ libraries=None, library_dirs=None, runtime_library_dirs=None,
191
+ export_symbols=None, debug=0, extra_preargs=None,
192
+ extra_postargs=None, build_temp=None, target_lang=None):
193
+ """Link the objects."""
194
+ # use separate copies, so we can modify the lists
195
+ extra_preargs = copy.copy(extra_preargs or [])
196
+ libraries = copy.copy(libraries or [])
197
+ objects = copy.copy(objects or [])
198
+
199
+ # Additional libraries
200
+ libraries.extend(self.dll_libraries)
201
+
202
+ # handle export symbols by creating a def-file
203
+ # with executables this only works with gcc/ld as linker
204
+ if ((export_symbols is not None) and
205
+ (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
206
+ # (The linker doesn't do anything if output is up-to-date.
207
+ # So it would probably better to check if we really need this,
208
+ # but for this we had to insert some unchanged parts of
209
+ # UnixCCompiler, and this is not what we want.)
210
+
211
+ # we want to put some files in the same directory as the
212
+ # object files are, build_temp doesn't help much
213
+ # where are the object files
214
+ temp_dir = os.path.dirname(objects[0])
215
+ # name of dll to give the helper files the same base name
216
+ (dll_name, dll_extension) = os.path.splitext(
217
+ os.path.basename(output_filename))
218
+
219
+ # generate the filenames for these files
220
+ def_file = os.path.join(temp_dir, dll_name + ".def")
221
+ lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
222
+
223
+ # Generate .def file
224
+ contents = [
225
+ "LIBRARY %s" % os.path.basename(output_filename),
226
+ "EXPORTS"]
227
+ for sym in export_symbols:
228
+ contents.append(sym)
229
+ self.execute(write_file, (def_file, contents),
230
+ "writing %s" % def_file)
231
+
232
+ # next add options for def-file and to creating import libraries
233
+
234
+ # dllwrap uses different options than gcc/ld
235
+ if self.linker_dll == "dllwrap":
236
+ extra_preargs.extend(["--output-lib", lib_file])
237
+ # for dllwrap we have to use a special option
238
+ extra_preargs.extend(["--def", def_file])
239
+ # we use gcc/ld here and can be sure ld is >= 2.9.10
240
+ else:
241
+ # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
242
+ #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
243
+ # for gcc/ld the def-file is specified as any object files
244
+ objects.append(def_file)
245
+
246
+ #end: if ((export_symbols is not None) and
247
+ # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
248
+
249
+ # who wants symbols and a many times larger output file
250
+ # should explicitly switch the debug mode on
251
+ # otherwise we let dllwrap/ld strip the output file
252
+ # (On my machine: 10KiB < stripped_file < ??100KiB
253
+ # unstripped_file = stripped_file + XXX KiB
254
+ # ( XXX=254 for a typical python extension))
255
+ if not debug:
256
+ extra_preargs.append("-s")
257
+
258
+ UnixCCompiler.link(self, target_desc, objects, output_filename,
259
+ output_dir, libraries, library_dirs,
260
+ runtime_library_dirs,
261
+ None, # export_symbols, we do this in our def-file
262
+ debug, extra_preargs, extra_postargs, build_temp,
263
+ target_lang)
264
+
265
+ # -- Miscellaneous methods -----------------------------------------
266
+
267
+ def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
268
+ """Adds supports for rc and res files."""
269
+ if output_dir is None:
270
+ output_dir = ''
271
+ obj_names = []
272
+ for src_name in source_filenames:
273
+ # use normcase to make sure '.rc' is really '.rc' and not '.RC'
274
+ base, ext = os.path.splitext(os.path.normcase(src_name))
275
+ if ext not in (self.src_extensions + ['.rc','.res']):
276
+ raise UnknownFileError("unknown file type '%s' (from '%s')" % \
277
+ (ext, src_name))
278
+ if strip_dir:
279
+ base = os.path.basename (base)
280
+ if ext in ('.res', '.rc'):
281
+ # these need to be compiled to object files
282
+ obj_names.append (os.path.join(output_dir,
283
+ base + ext + self.obj_extension))
284
+ else:
285
+ obj_names.append (os.path.join(output_dir,
286
+ base + self.obj_extension))
287
+ return obj_names
288
+
289
+ # the same as cygwin plus some additional parameters
290
+ class Mingw32CCompiler(CygwinCCompiler):
291
+ """ Handles the Mingw32 port of the GNU C compiler to Windows.
292
+ """
293
+ compiler_type = 'mingw32'
294
+
295
+ def __init__(self, verbose=0, dry_run=0, force=0):
296
+
297
+ CygwinCCompiler.__init__ (self, verbose, dry_run, force)
298
+
299
+ # ld_version >= "2.13" support -shared so use it instead of
300
+ # -mdll -static
301
+ if ('gcc' in self.cc and self.ld_version < "2.13"):
302
+ shared_option = "-mdll -static"
303
+ else:
304
+ shared_option = "-shared"
305
+
306
+ # A real mingw32 doesn't need to specify a different entry point,
307
+ # but cygwin 2.91.57 in no-cygwin-mode needs it.
308
+ if ('gcc' in self.cc and self.gcc_version <= "2.91.57"):
309
+ entry_point = '--entry _DllMain@12'
310
+ else:
311
+ entry_point = ''
312
+
313
+ if is_cygwincc(self.cc):
314
+ raise CCompilerError(
315
+ 'Cygwin gcc cannot be used with --compiler=mingw32')
316
+
317
+ self.set_executables(compiler='%s -O -Wall' % self.cc,
318
+ compiler_so='%s -mdll -O -Wall' % self.cc,
319
+ compiler_cxx='%s -O -Wall' % self.cxx,
320
+ linker_exe='%s' % self.cc,
321
+ linker_so='%s %s %s'
322
+ % (self.linker_dll, shared_option,
323
+ entry_point))
324
+ # Maybe we should also append -mthreads, but then the finished
325
+ # dlls need another dll (mingwm10.dll see Mingw32 docs)
326
+ # (-mthreads: Support thread-safe exception handling on `Mingw32')
327
+
328
+ # no additional libraries needed
329
+ self.dll_libraries=[]
330
+
331
+ # Include the appropriate MSVC runtime library if Python was built
332
+ # with MSVC 7.0 or later.
333
+ self.dll_libraries = get_msvcr()
334
+
335
+ # Because these compilers aren't configured in Python's pyconfig.h file by
336
+ # default, we should at least warn the user if he is using an unmodified
337
+ # version.
338
+
339
+ CONFIG_H_OK = "ok"
340
+ CONFIG_H_NOTOK = "not ok"
341
+ CONFIG_H_UNCERTAIN = "uncertain"
342
+
343
+ def check_config_h():
344
+ """Check if the current Python installation appears amenable to building
345
+ extensions with GCC.
346
+
347
+ Returns a tuple (status, details), where 'status' is one of the following
348
+ constants:
349
+
350
+ - CONFIG_H_OK: all is well, go ahead and compile
351
+ - CONFIG_H_NOTOK: doesn't look good
352
+ - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
353
+
354
+ 'details' is a human-readable string explaining the situation.
355
+
356
+ Note there are two ways to conclude "OK": either 'sys.version' contains
357
+ the string "GCC" (implying that this Python was built with GCC), or the
358
+ installed "pyconfig.h" contains the string "__GNUC__".
359
+ """
360
+
361
+ # XXX since this function also checks sys.version, it's not strictly a
362
+ # "pyconfig.h" check -- should probably be renamed...
363
+
364
+ from distutils import sysconfig
365
+
366
+ # if sys.version contains GCC then python was compiled with GCC, and the
367
+ # pyconfig.h file should be OK
368
+ if "GCC" in sys.version:
369
+ return CONFIG_H_OK, "sys.version mentions 'GCC'"
370
+
371
+ # Clang would also work
372
+ if "Clang" in sys.version:
373
+ return CONFIG_H_OK, "sys.version mentions 'Clang'"
374
+
375
+ # let's see if __GNUC__ is mentioned in python.h
376
+ fn = sysconfig.get_config_h_filename()
377
+ try:
378
+ config_h = open(fn)
379
+ try:
380
+ if "__GNUC__" in config_h.read():
381
+ return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn
382
+ else:
383
+ return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
384
+ finally:
385
+ config_h.close()
386
+ except OSError as exc:
387
+ return (CONFIG_H_UNCERTAIN,
388
+ "couldn't read '%s': %s" % (fn, exc.strerror))
389
+
390
+ RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
391
+
392
+ def _find_exe_version(cmd):
393
+ """Find the version of an executable by running `cmd` in the shell.
394
+
395
+ If the command is not found, or the output does not match
396
+ `RE_VERSION`, returns None.
397
+ """
398
+ executable = cmd.split()[0]
399
+ if find_executable(executable) is None:
400
+ return None
401
+ out = Popen(cmd, shell=True, stdout=PIPE).stdout
402
+ try:
403
+ out_string = out.read()
404
+ finally:
405
+ out.close()
406
+ result = RE_VERSION.search(out_string)
407
+ if result is None:
408
+ return None
409
+ # LooseVersion works with strings; decode
410
+ ver_str = result.group(1).decode()
411
+ with distutils.version.suppress_known_deprecation():
412
+ return LooseVersion(ver_str)
413
+
414
+ def get_versions():
415
+ """ Try to find out the versions of gcc, ld and dllwrap.
416
+
417
+ If not possible it returns None for it.
418
+ """
419
+ commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
420
+ return tuple([_find_exe_version(cmd) for cmd in commands])
421
+
422
+ def is_cygwincc(cc):
423
+ '''Try to determine if the compiler that would be used is from cygwin.'''
424
+ out_string = check_output([cc, '-dumpmachine'])
425
+ return out_string.strip().endswith(b'cygwin')
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/debug.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import os
2
+
3
+ # If DISTUTILS_DEBUG is anything other than the empty string, we run in
4
+ # debug mode.
5
+ DEBUG = os.environ.get('DISTUTILS_DEBUG')
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/dep_util.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.dep_util
2
+
3
+ Utility functions for simple, timestamp-based dependency of files
4
+ and groups of files; also, function based entirely on such
5
+ timestamp dependency analysis."""
6
+
7
+ import os
8
+ from distutils.errors import DistutilsFileError
9
+
10
+
11
+ def newer (source, target):
12
+ """Return true if 'source' exists and is more recently modified than
13
+ 'target', or if 'source' exists and 'target' doesn't. Return false if
14
+ both exist and 'target' is the same age or younger than 'source'.
15
+ Raise DistutilsFileError if 'source' does not exist.
16
+ """
17
+ if not os.path.exists(source):
18
+ raise DistutilsFileError("file '%s' does not exist" %
19
+ os.path.abspath(source))
20
+ if not os.path.exists(target):
21
+ return 1
22
+
23
+ from stat import ST_MTIME
24
+ mtime1 = os.stat(source)[ST_MTIME]
25
+ mtime2 = os.stat(target)[ST_MTIME]
26
+
27
+ return mtime1 > mtime2
28
+
29
+ # newer ()
30
+
31
+
32
+ def newer_pairwise (sources, targets):
33
+ """Walk two filename lists in parallel, testing if each source is newer
34
+ than its corresponding target. Return a pair of lists (sources,
35
+ targets) where source is newer than target, according to the semantics
36
+ of 'newer()'.
37
+ """
38
+ if len(sources) != len(targets):
39
+ raise ValueError("'sources' and 'targets' must be same length")
40
+
41
+ # build a pair of lists (sources, targets) where source is newer
42
+ n_sources = []
43
+ n_targets = []
44
+ for i in range(len(sources)):
45
+ if newer(sources[i], targets[i]):
46
+ n_sources.append(sources[i])
47
+ n_targets.append(targets[i])
48
+
49
+ return (n_sources, n_targets)
50
+
51
+ # newer_pairwise ()
52
+
53
+
54
+ def newer_group (sources, target, missing='error'):
55
+ """Return true if 'target' is out-of-date with respect to any file
56
+ listed in 'sources'. In other words, if 'target' exists and is newer
57
+ than every file in 'sources', return false; otherwise return true.
58
+ 'missing' controls what we do when a source file is missing; the
59
+ default ("error") is to blow up with an OSError from inside 'stat()';
60
+ if it is "ignore", we silently drop any missing source files; if it is
61
+ "newer", any missing source files make us assume that 'target' is
62
+ out-of-date (this is handy in "dry-run" mode: it'll make you pretend to
63
+ carry out commands that wouldn't work because inputs are missing, but
64
+ that doesn't matter because you're not actually going to run the
65
+ commands).
66
+ """
67
+ # If the target doesn't even exist, then it's definitely out-of-date.
68
+ if not os.path.exists(target):
69
+ return 1
70
+
71
+ # Otherwise we have to find out the hard way: if *any* source file
72
+ # is more recent than 'target', then 'target' is out-of-date and
73
+ # we can immediately return true. If we fall through to the end
74
+ # of the loop, then 'target' is up-to-date and we return false.
75
+ from stat import ST_MTIME
76
+ target_mtime = os.stat(target)[ST_MTIME]
77
+ for source in sources:
78
+ if not os.path.exists(source):
79
+ if missing == 'error': # blow up when we stat() the file
80
+ pass
81
+ elif missing == 'ignore': # missing source dropped from
82
+ continue # target's dependency list
83
+ elif missing == 'newer': # missing source means target is
84
+ return 1 # out-of-date
85
+
86
+ source_mtime = os.stat(source)[ST_MTIME]
87
+ if source_mtime > target_mtime:
88
+ return 1
89
+ else:
90
+ return 0
91
+
92
+ # newer_group ()
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/dir_util.py ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.dir_util
2
+
3
+ Utility functions for manipulating directories and directory trees."""
4
+
5
+ import os
6
+ import errno
7
+ from distutils.errors import DistutilsFileError, DistutilsInternalError
8
+ from distutils import log
9
+
10
+ # cache for by mkpath() -- in addition to cheapening redundant calls,
11
+ # eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
12
+ _path_created = {}
13
+
14
+ # I don't use os.makedirs because a) it's new to Python 1.5.2, and
15
+ # b) it blows up if the directory already exists (I want to silently
16
+ # succeed in that case).
17
+ def mkpath(name, mode=0o777, verbose=1, dry_run=0):
18
+ """Create a directory and any missing ancestor directories.
19
+
20
+ If the directory already exists (or if 'name' is the empty string, which
21
+ means the current directory, which of course exists), then do nothing.
22
+ Raise DistutilsFileError if unable to create some directory along the way
23
+ (eg. some sub-path exists, but is a file rather than a directory).
24
+ If 'verbose' is true, print a one-line summary of each mkdir to stdout.
25
+ Return the list of directories actually created.
26
+ """
27
+
28
+ global _path_created
29
+
30
+ # Detect a common bug -- name is None
31
+ if not isinstance(name, str):
32
+ raise DistutilsInternalError(
33
+ "mkpath: 'name' must be a string (got %r)" % (name,))
34
+
35
+ # XXX what's the better way to handle verbosity? print as we create
36
+ # each directory in the path (the current behaviour), or only announce
37
+ # the creation of the whole path? (quite easy to do the latter since
38
+ # we're not using a recursive algorithm)
39
+
40
+ name = os.path.normpath(name)
41
+ created_dirs = []
42
+ if os.path.isdir(name) or name == '':
43
+ return created_dirs
44
+ if _path_created.get(os.path.abspath(name)):
45
+ return created_dirs
46
+
47
+ (head, tail) = os.path.split(name)
48
+ tails = [tail] # stack of lone dirs to create
49
+
50
+ while head and tail and not os.path.isdir(head):
51
+ (head, tail) = os.path.split(head)
52
+ tails.insert(0, tail) # push next higher dir onto stack
53
+
54
+ # now 'head' contains the deepest directory that already exists
55
+ # (that is, the child of 'head' in 'name' is the highest directory
56
+ # that does *not* exist)
57
+ for d in tails:
58
+ #print "head = %s, d = %s: " % (head, d),
59
+ head = os.path.join(head, d)
60
+ abs_head = os.path.abspath(head)
61
+
62
+ if _path_created.get(abs_head):
63
+ continue
64
+
65
+ if verbose >= 1:
66
+ log.info("creating %s", head)
67
+
68
+ if not dry_run:
69
+ try:
70
+ os.mkdir(head, mode)
71
+ except OSError as exc:
72
+ if not (exc.errno == errno.EEXIST and os.path.isdir(head)):
73
+ raise DistutilsFileError(
74
+ "could not create '%s': %s" % (head, exc.args[-1]))
75
+ created_dirs.append(head)
76
+
77
+ _path_created[abs_head] = 1
78
+ return created_dirs
79
+
80
+ def create_tree(base_dir, files, mode=0o777, verbose=1, dry_run=0):
81
+ """Create all the empty directories under 'base_dir' needed to put 'files'
82
+ there.
83
+
84
+ 'base_dir' is just the name of a directory which doesn't necessarily
85
+ exist yet; 'files' is a list of filenames to be interpreted relative to
86
+ 'base_dir'. 'base_dir' + the directory portion of every file in 'files'
87
+ will be created if it doesn't already exist. 'mode', 'verbose' and
88
+ 'dry_run' flags are as for 'mkpath()'.
89
+ """
90
+ # First get the list of directories to create
91
+ need_dir = set()
92
+ for file in files:
93
+ need_dir.add(os.path.join(base_dir, os.path.dirname(file)))
94
+
95
+ # Now create them
96
+ for dir in sorted(need_dir):
97
+ mkpath(dir, mode, verbose=verbose, dry_run=dry_run)
98
+
99
+ def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
100
+ preserve_symlinks=0, update=0, verbose=1, dry_run=0):
101
+ """Copy an entire directory tree 'src' to a new location 'dst'.
102
+
103
+ Both 'src' and 'dst' must be directory names. If 'src' is not a
104
+ directory, raise DistutilsFileError. If 'dst' does not exist, it is
105
+ created with 'mkpath()'. The end result of the copy is that every
106
+ file in 'src' is copied to 'dst', and directories under 'src' are
107
+ recursively copied to 'dst'. Return the list of files that were
108
+ copied or might have been copied, using their output name. The
109
+ return value is unaffected by 'update' or 'dry_run': it is simply
110
+ the list of all files under 'src', with the names changed to be
111
+ under 'dst'.
112
+
113
+ 'preserve_mode' and 'preserve_times' are the same as for
114
+ 'copy_file'; note that they only apply to regular files, not to
115
+ directories. If 'preserve_symlinks' is true, symlinks will be
116
+ copied as symlinks (on platforms that support them!); otherwise
117
+ (the default), the destination of the symlink will be copied.
118
+ 'update' and 'verbose' are the same as for 'copy_file'.
119
+ """
120
+ from distutils.file_util import copy_file
121
+
122
+ if not dry_run and not os.path.isdir(src):
123
+ raise DistutilsFileError(
124
+ "cannot copy tree '%s': not a directory" % src)
125
+ try:
126
+ names = os.listdir(src)
127
+ except OSError as e:
128
+ if dry_run:
129
+ names = []
130
+ else:
131
+ raise DistutilsFileError(
132
+ "error listing files in '%s': %s" % (src, e.strerror))
133
+
134
+ if not dry_run:
135
+ mkpath(dst, verbose=verbose)
136
+
137
+ outputs = []
138
+
139
+ for n in names:
140
+ src_name = os.path.join(src, n)
141
+ dst_name = os.path.join(dst, n)
142
+
143
+ if n.startswith('.nfs'):
144
+ # skip NFS rename files
145
+ continue
146
+
147
+ if preserve_symlinks and os.path.islink(src_name):
148
+ link_dest = os.readlink(src_name)
149
+ if verbose >= 1:
150
+ log.info("linking %s -> %s", dst_name, link_dest)
151
+ if not dry_run:
152
+ os.symlink(link_dest, dst_name)
153
+ outputs.append(dst_name)
154
+
155
+ elif os.path.isdir(src_name):
156
+ outputs.extend(
157
+ copy_tree(src_name, dst_name, preserve_mode,
158
+ preserve_times, preserve_symlinks, update,
159
+ verbose=verbose, dry_run=dry_run))
160
+ else:
161
+ copy_file(src_name, dst_name, preserve_mode,
162
+ preserve_times, update, verbose=verbose,
163
+ dry_run=dry_run)
164
+ outputs.append(dst_name)
165
+
166
+ return outputs
167
+
168
+ def _build_cmdtuple(path, cmdtuples):
169
+ """Helper for remove_tree()."""
170
+ for f in os.listdir(path):
171
+ real_f = os.path.join(path,f)
172
+ if os.path.isdir(real_f) and not os.path.islink(real_f):
173
+ _build_cmdtuple(real_f, cmdtuples)
174
+ else:
175
+ cmdtuples.append((os.remove, real_f))
176
+ cmdtuples.append((os.rmdir, path))
177
+
178
+ def remove_tree(directory, verbose=1, dry_run=0):
179
+ """Recursively remove an entire directory tree.
180
+
181
+ Any errors are ignored (apart from being reported to stdout if 'verbose'
182
+ is true).
183
+ """
184
+ global _path_created
185
+
186
+ if verbose >= 1:
187
+ log.info("removing '%s' (and everything under it)", directory)
188
+ if dry_run:
189
+ return
190
+ cmdtuples = []
191
+ _build_cmdtuple(directory, cmdtuples)
192
+ for cmd in cmdtuples:
193
+ try:
194
+ cmd[0](cmd[1])
195
+ # remove dir from cache if it's already there
196
+ abspath = os.path.abspath(cmd[1])
197
+ if abspath in _path_created:
198
+ del _path_created[abspath]
199
+ except OSError as exc:
200
+ log.warn("error removing %s: %s", directory, exc)
201
+
202
+ def ensure_relative(path):
203
+ """Take the full path 'path', and make it a relative path.
204
+
205
+ This is useful to make 'path' the second argument to os.path.join().
206
+ """
207
+ drive, path = os.path.splitdrive(path)
208
+ if path[0:1] == os.sep:
209
+ path = drive + path[1:]
210
+ return path
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/dist.py ADDED
@@ -0,0 +1,1257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.dist
2
+
3
+ Provides the Distribution class, which represents the module distribution
4
+ being built/installed/distributed.
5
+ """
6
+
7
+ import sys
8
+ import os
9
+ import re
10
+ from email import message_from_file
11
+
12
+ try:
13
+ import warnings
14
+ except ImportError:
15
+ warnings = None
16
+
17
+ from distutils.errors import *
18
+ from distutils.fancy_getopt import FancyGetopt, translate_longopt
19
+ from distutils.util import check_environ, strtobool, rfc822_escape
20
+ from distutils import log
21
+ from distutils.debug import DEBUG
22
+
23
+ # Regex to define acceptable Distutils command names. This is not *quite*
24
+ # the same as a Python NAME -- I don't allow leading underscores. The fact
25
+ # that they're very similar is no coincidence; the default naming scheme is
26
+ # to look for a Python module named after the command.
27
+ command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
28
+
29
+
30
+ def _ensure_list(value, fieldname):
31
+ if isinstance(value, str):
32
+ # a string containing comma separated values is okay. It will
33
+ # be converted to a list by Distribution.finalize_options().
34
+ pass
35
+ elif not isinstance(value, list):
36
+ # passing a tuple or an iterator perhaps, warn and convert
37
+ typename = type(value).__name__
38
+ msg = "Warning: '{fieldname}' should be a list, got type '{typename}'"
39
+ msg = msg.format(**locals())
40
+ log.log(log.WARN, msg)
41
+ value = list(value)
42
+ return value
43
+
44
+
45
+ class Distribution:
46
+ """The core of the Distutils. Most of the work hiding behind 'setup'
47
+ is really done within a Distribution instance, which farms the work out
48
+ to the Distutils commands specified on the command line.
49
+
50
+ Setup scripts will almost never instantiate Distribution directly,
51
+ unless the 'setup()' function is totally inadequate to their needs.
52
+ However, it is conceivable that a setup script might wish to subclass
53
+ Distribution for some specialized purpose, and then pass the subclass
54
+ to 'setup()' as the 'distclass' keyword argument. If so, it is
55
+ necessary to respect the expectations that 'setup' has of Distribution.
56
+ See the code for 'setup()', in core.py, for details.
57
+ """
58
+
59
+ # 'global_options' describes the command-line options that may be
60
+ # supplied to the setup script prior to any actual commands.
61
+ # Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
62
+ # these global options. This list should be kept to a bare minimum,
63
+ # since every global option is also valid as a command option -- and we
64
+ # don't want to pollute the commands with too many options that they
65
+ # have minimal control over.
66
+ # The fourth entry for verbose means that it can be repeated.
67
+ global_options = [
68
+ ('verbose', 'v', "run verbosely (default)", 1),
69
+ ('quiet', 'q', "run quietly (turns verbosity off)"),
70
+ ('dry-run', 'n', "don't actually do anything"),
71
+ ('help', 'h', "show detailed help message"),
72
+ ('no-user-cfg', None,
73
+ 'ignore pydistutils.cfg in your home directory'),
74
+ ]
75
+
76
+ # 'common_usage' is a short (2-3 line) string describing the common
77
+ # usage of the setup script.
78
+ common_usage = """\
79
+ Common commands: (see '--help-commands' for more)
80
+
81
+ setup.py build will build the package underneath 'build/'
82
+ setup.py install will install the package
83
+ """
84
+
85
+ # options that are not propagated to the commands
86
+ display_options = [
87
+ ('help-commands', None,
88
+ "list all available commands"),
89
+ ('name', None,
90
+ "print package name"),
91
+ ('version', 'V',
92
+ "print package version"),
93
+ ('fullname', None,
94
+ "print <package name>-<version>"),
95
+ ('author', None,
96
+ "print the author's name"),
97
+ ('author-email', None,
98
+ "print the author's email address"),
99
+ ('maintainer', None,
100
+ "print the maintainer's name"),
101
+ ('maintainer-email', None,
102
+ "print the maintainer's email address"),
103
+ ('contact', None,
104
+ "print the maintainer's name if known, else the author's"),
105
+ ('contact-email', None,
106
+ "print the maintainer's email address if known, else the author's"),
107
+ ('url', None,
108
+ "print the URL for this package"),
109
+ ('license', None,
110
+ "print the license of the package"),
111
+ ('licence', None,
112
+ "alias for --license"),
113
+ ('description', None,
114
+ "print the package description"),
115
+ ('long-description', None,
116
+ "print the long package description"),
117
+ ('platforms', None,
118
+ "print the list of platforms"),
119
+ ('classifiers', None,
120
+ "print the list of classifiers"),
121
+ ('keywords', None,
122
+ "print the list of keywords"),
123
+ ('provides', None,
124
+ "print the list of packages/modules provided"),
125
+ ('requires', None,
126
+ "print the list of packages/modules required"),
127
+ ('obsoletes', None,
128
+ "print the list of packages/modules made obsolete")
129
+ ]
130
+ display_option_names = [translate_longopt(x[0]) for x in display_options]
131
+
132
+ # negative options are options that exclude other options
133
+ negative_opt = {'quiet': 'verbose'}
134
+
135
+ # -- Creation/initialization methods -------------------------------
136
+
137
+ def __init__(self, attrs=None):
138
+ """Construct a new Distribution instance: initialize all the
139
+ attributes of a Distribution, and then use 'attrs' (a dictionary
140
+ mapping attribute names to values) to assign some of those
141
+ attributes their "real" values. (Any attributes not mentioned in
142
+ 'attrs' will be assigned to some null value: 0, None, an empty list
143
+ or dictionary, etc.) Most importantly, initialize the
144
+ 'command_obj' attribute to the empty dictionary; this will be
145
+ filled in with real command objects by 'parse_command_line()'.
146
+ """
147
+
148
+ # Default values for our command-line options
149
+ self.verbose = 1
150
+ self.dry_run = 0
151
+ self.help = 0
152
+ for attr in self.display_option_names:
153
+ setattr(self, attr, 0)
154
+
155
+ # Store the distribution meta-data (name, version, author, and so
156
+ # forth) in a separate object -- we're getting to have enough
157
+ # information here (and enough command-line options) that it's
158
+ # worth it. Also delegate 'get_XXX()' methods to the 'metadata'
159
+ # object in a sneaky and underhanded (but efficient!) way.
160
+ self.metadata = DistributionMetadata()
161
+ for basename in self.metadata._METHOD_BASENAMES:
162
+ method_name = "get_" + basename
163
+ setattr(self, method_name, getattr(self.metadata, method_name))
164
+
165
+ # 'cmdclass' maps command names to class objects, so we
166
+ # can 1) quickly figure out which class to instantiate when
167
+ # we need to create a new command object, and 2) have a way
168
+ # for the setup script to override command classes
169
+ self.cmdclass = {}
170
+
171
+ # 'command_packages' is a list of packages in which commands
172
+ # are searched for. The factory for command 'foo' is expected
173
+ # to be named 'foo' in the module 'foo' in one of the packages
174
+ # named here. This list is searched from the left; an error
175
+ # is raised if no named package provides the command being
176
+ # searched for. (Always access using get_command_packages().)
177
+ self.command_packages = None
178
+
179
+ # 'script_name' and 'script_args' are usually set to sys.argv[0]
180
+ # and sys.argv[1:], but they can be overridden when the caller is
181
+ # not necessarily a setup script run from the command-line.
182
+ self.script_name = None
183
+ self.script_args = None
184
+
185
+ # 'command_options' is where we store command options between
186
+ # parsing them (from config files, the command-line, etc.) and when
187
+ # they are actually needed -- ie. when the command in question is
188
+ # instantiated. It is a dictionary of dictionaries of 2-tuples:
189
+ # command_options = { command_name : { option : (source, value) } }
190
+ self.command_options = {}
191
+
192
+ # 'dist_files' is the list of (command, pyversion, file) that
193
+ # have been created by any dist commands run so far. This is
194
+ # filled regardless of whether the run is dry or not. pyversion
195
+ # gives sysconfig.get_python_version() if the dist file is
196
+ # specific to a Python version, 'any' if it is good for all
197
+ # Python versions on the target platform, and '' for a source
198
+ # file. pyversion should not be used to specify minimum or
199
+ # maximum required Python versions; use the metainfo for that
200
+ # instead.
201
+ self.dist_files = []
202
+
203
+ # These options are really the business of various commands, rather
204
+ # than of the Distribution itself. We provide aliases for them in
205
+ # Distribution as a convenience to the developer.
206
+ self.packages = None
207
+ self.package_data = {}
208
+ self.package_dir = None
209
+ self.py_modules = None
210
+ self.libraries = None
211
+ self.headers = None
212
+ self.ext_modules = None
213
+ self.ext_package = None
214
+ self.include_dirs = None
215
+ self.extra_path = None
216
+ self.scripts = None
217
+ self.data_files = None
218
+ self.password = ''
219
+
220
+ # And now initialize bookkeeping stuff that can't be supplied by
221
+ # the caller at all. 'command_obj' maps command names to
222
+ # Command instances -- that's how we enforce that every command
223
+ # class is a singleton.
224
+ self.command_obj = {}
225
+
226
+ # 'have_run' maps command names to boolean values; it keeps track
227
+ # of whether we have actually run a particular command, to make it
228
+ # cheap to "run" a command whenever we think we might need to -- if
229
+ # it's already been done, no need for expensive filesystem
230
+ # operations, we just check the 'have_run' dictionary and carry on.
231
+ # It's only safe to query 'have_run' for a command class that has
232
+ # been instantiated -- a false value will be inserted when the
233
+ # command object is created, and replaced with a true value when
234
+ # the command is successfully run. Thus it's probably best to use
235
+ # '.get()' rather than a straight lookup.
236
+ self.have_run = {}
237
+
238
+ # Now we'll use the attrs dictionary (ultimately, keyword args from
239
+ # the setup script) to possibly override any or all of these
240
+ # distribution options.
241
+
242
+ if attrs:
243
+ # Pull out the set of command options and work on them
244
+ # specifically. Note that this order guarantees that aliased
245
+ # command options will override any supplied redundantly
246
+ # through the general options dictionary.
247
+ options = attrs.get('options')
248
+ if options is not None:
249
+ del attrs['options']
250
+ for (command, cmd_options) in options.items():
251
+ opt_dict = self.get_option_dict(command)
252
+ for (opt, val) in cmd_options.items():
253
+ opt_dict[opt] = ("setup script", val)
254
+
255
+ if 'licence' in attrs:
256
+ attrs['license'] = attrs['licence']
257
+ del attrs['licence']
258
+ msg = "'licence' distribution option is deprecated; use 'license'"
259
+ if warnings is not None:
260
+ warnings.warn(msg)
261
+ else:
262
+ sys.stderr.write(msg + "\n")
263
+
264
+ # Now work on the rest of the attributes. Any attribute that's
265
+ # not already defined is invalid!
266
+ for (key, val) in attrs.items():
267
+ if hasattr(self.metadata, "set_" + key):
268
+ getattr(self.metadata, "set_" + key)(val)
269
+ elif hasattr(self.metadata, key):
270
+ setattr(self.metadata, key, val)
271
+ elif hasattr(self, key):
272
+ setattr(self, key, val)
273
+ else:
274
+ msg = "Unknown distribution option: %s" % repr(key)
275
+ warnings.warn(msg)
276
+
277
+ # no-user-cfg is handled before other command line args
278
+ # because other args override the config files, and this
279
+ # one is needed before we can load the config files.
280
+ # If attrs['script_args'] wasn't passed, assume false.
281
+ #
282
+ # This also make sure we just look at the global options
283
+ self.want_user_cfg = True
284
+
285
+ if self.script_args is not None:
286
+ for arg in self.script_args:
287
+ if not arg.startswith('-'):
288
+ break
289
+ if arg == '--no-user-cfg':
290
+ self.want_user_cfg = False
291
+ break
292
+
293
+ self.finalize_options()
294
+
295
+ def get_option_dict(self, command):
296
+ """Get the option dictionary for a given command. If that
297
+ command's option dictionary hasn't been created yet, then create it
298
+ and return the new dictionary; otherwise, return the existing
299
+ option dictionary.
300
+ """
301
+ dict = self.command_options.get(command)
302
+ if dict is None:
303
+ dict = self.command_options[command] = {}
304
+ return dict
305
+
306
+ def dump_option_dicts(self, header=None, commands=None, indent=""):
307
+ from pprint import pformat
308
+
309
+ if commands is None: # dump all command option dicts
310
+ commands = sorted(self.command_options.keys())
311
+
312
+ if header is not None:
313
+ self.announce(indent + header)
314
+ indent = indent + " "
315
+
316
+ if not commands:
317
+ self.announce(indent + "no commands known yet")
318
+ return
319
+
320
+ for cmd_name in commands:
321
+ opt_dict = self.command_options.get(cmd_name)
322
+ if opt_dict is None:
323
+ self.announce(indent +
324
+ "no option dict for '%s' command" % cmd_name)
325
+ else:
326
+ self.announce(indent +
327
+ "option dict for '%s' command:" % cmd_name)
328
+ out = pformat(opt_dict)
329
+ for line in out.split('\n'):
330
+ self.announce(indent + " " + line)
331
+
332
+ # -- Config file finding/parsing methods ---------------------------
333
+
334
+ def find_config_files(self):
335
+ """Find as many configuration files as should be processed for this
336
+ platform, and return a list of filenames in the order in which they
337
+ should be parsed. The filenames returned are guaranteed to exist
338
+ (modulo nasty race conditions).
339
+
340
+ There are three possible config files: distutils.cfg in the
341
+ Distutils installation directory (ie. where the top-level
342
+ Distutils __inst__.py file lives), a file in the user's home
343
+ directory named .pydistutils.cfg on Unix and pydistutils.cfg
344
+ on Windows/Mac; and setup.cfg in the current directory.
345
+
346
+ The file in the user's home directory can be disabled with the
347
+ --no-user-cfg option.
348
+ """
349
+ files = []
350
+ check_environ()
351
+
352
+ # Where to look for the system-wide Distutils config file
353
+ sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
354
+
355
+ # Look for the system config file
356
+ sys_file = os.path.join(sys_dir, "distutils.cfg")
357
+ if os.path.isfile(sys_file):
358
+ files.append(sys_file)
359
+
360
+ # What to call the per-user config file
361
+ if os.name == 'posix':
362
+ user_filename = ".pydistutils.cfg"
363
+ else:
364
+ user_filename = "pydistutils.cfg"
365
+
366
+ # And look for the user config file
367
+ if self.want_user_cfg:
368
+ user_file = os.path.join(os.path.expanduser('~'), user_filename)
369
+ if os.path.isfile(user_file):
370
+ files.append(user_file)
371
+
372
+ # All platforms support local setup.cfg
373
+ local_file = "setup.cfg"
374
+ if os.path.isfile(local_file):
375
+ files.append(local_file)
376
+
377
+ if DEBUG:
378
+ self.announce("using config files: %s" % ', '.join(files))
379
+
380
+ return files
381
+
382
+ def parse_config_files(self, filenames=None):
383
+ from configparser import ConfigParser
384
+
385
+ # Ignore install directory options if we have a venv
386
+ if sys.prefix != sys.base_prefix:
387
+ ignore_options = [
388
+ 'install-base', 'install-platbase', 'install-lib',
389
+ 'install-platlib', 'install-purelib', 'install-headers',
390
+ 'install-scripts', 'install-data', 'prefix', 'exec-prefix',
391
+ 'home', 'user', 'root']
392
+ else:
393
+ ignore_options = []
394
+
395
+ ignore_options = frozenset(ignore_options)
396
+
397
+ if filenames is None:
398
+ filenames = self.find_config_files()
399
+
400
+ if DEBUG:
401
+ self.announce("Distribution.parse_config_files():")
402
+
403
+ parser = ConfigParser()
404
+ for filename in filenames:
405
+ if DEBUG:
406
+ self.announce(" reading %s" % filename)
407
+ parser.read(filename)
408
+ for section in parser.sections():
409
+ options = parser.options(section)
410
+ opt_dict = self.get_option_dict(section)
411
+
412
+ for opt in options:
413
+ if opt != '__name__' and opt not in ignore_options:
414
+ val = parser.get(section,opt)
415
+ opt = opt.replace('-', '_')
416
+ opt_dict[opt] = (filename, val)
417
+
418
+ # Make the ConfigParser forget everything (so we retain
419
+ # the original filenames that options come from)
420
+ parser.__init__()
421
+
422
+ # If there was a "global" section in the config file, use it
423
+ # to set Distribution options.
424
+
425
+ if 'global' in self.command_options:
426
+ for (opt, (src, val)) in self.command_options['global'].items():
427
+ alias = self.negative_opt.get(opt)
428
+ try:
429
+ if alias:
430
+ setattr(self, alias, not strtobool(val))
431
+ elif opt in ('verbose', 'dry_run'): # ugh!
432
+ setattr(self, opt, strtobool(val))
433
+ else:
434
+ setattr(self, opt, val)
435
+ except ValueError as msg:
436
+ raise DistutilsOptionError(msg)
437
+
438
+ # -- Command-line parsing methods ----------------------------------
439
+
440
+ def parse_command_line(self):
441
+ """Parse the setup script's command line, taken from the
442
+ 'script_args' instance attribute (which defaults to 'sys.argv[1:]'
443
+ -- see 'setup()' in core.py). This list is first processed for
444
+ "global options" -- options that set attributes of the Distribution
445
+ instance. Then, it is alternately scanned for Distutils commands
446
+ and options for that command. Each new command terminates the
447
+ options for the previous command. The allowed options for a
448
+ command are determined by the 'user_options' attribute of the
449
+ command class -- thus, we have to be able to load command classes
450
+ in order to parse the command line. Any error in that 'options'
451
+ attribute raises DistutilsGetoptError; any error on the
452
+ command-line raises DistutilsArgError. If no Distutils commands
453
+ were found on the command line, raises DistutilsArgError. Return
454
+ true if command-line was successfully parsed and we should carry
455
+ on with executing commands; false if no errors but we shouldn't
456
+ execute commands (currently, this only happens if user asks for
457
+ help).
458
+ """
459
+ #
460
+ # We now have enough information to show the Macintosh dialog
461
+ # that allows the user to interactively specify the "command line".
462
+ #
463
+ toplevel_options = self._get_toplevel_options()
464
+
465
+ # We have to parse the command line a bit at a time -- global
466
+ # options, then the first command, then its options, and so on --
467
+ # because each command will be handled by a different class, and
468
+ # the options that are valid for a particular class aren't known
469
+ # until we have loaded the command class, which doesn't happen
470
+ # until we know what the command is.
471
+
472
+ self.commands = []
473
+ parser = FancyGetopt(toplevel_options + self.display_options)
474
+ parser.set_negative_aliases(self.negative_opt)
475
+ parser.set_aliases({'licence': 'license'})
476
+ args = parser.getopt(args=self.script_args, object=self)
477
+ option_order = parser.get_option_order()
478
+ log.set_verbosity(self.verbose)
479
+
480
+ # for display options we return immediately
481
+ if self.handle_display_options(option_order):
482
+ return
483
+ while args:
484
+ args = self._parse_command_opts(parser, args)
485
+ if args is None: # user asked for help (and got it)
486
+ return
487
+
488
+ # Handle the cases of --help as a "global" option, ie.
489
+ # "setup.py --help" and "setup.py --help command ...". For the
490
+ # former, we show global options (--verbose, --dry-run, etc.)
491
+ # and display-only options (--name, --version, etc.); for the
492
+ # latter, we omit the display-only options and show help for
493
+ # each command listed on the command line.
494
+ if self.help:
495
+ self._show_help(parser,
496
+ display_options=len(self.commands) == 0,
497
+ commands=self.commands)
498
+ return
499
+
500
+ # Oops, no commands found -- an end-user error
501
+ if not self.commands:
502
+ raise DistutilsArgError("no commands supplied")
503
+
504
+ # All is well: return true
505
+ return True
506
+
507
+ def _get_toplevel_options(self):
508
+ """Return the non-display options recognized at the top level.
509
+
510
+ This includes options that are recognized *only* at the top
511
+ level as well as options recognized for commands.
512
+ """
513
+ return self.global_options + [
514
+ ("command-packages=", None,
515
+ "list of packages that provide distutils commands"),
516
+ ]
517
+
518
+ def _parse_command_opts(self, parser, args):
519
+ """Parse the command-line options for a single command.
520
+ 'parser' must be a FancyGetopt instance; 'args' must be the list
521
+ of arguments, starting with the current command (whose options
522
+ we are about to parse). Returns a new version of 'args' with
523
+ the next command at the front of the list; will be the empty
524
+ list if there are no more commands on the command line. Returns
525
+ None if the user asked for help on this command.
526
+ """
527
+ # late import because of mutual dependence between these modules
528
+ from distutils.cmd import Command
529
+
530
+ # Pull the current command from the head of the command line
531
+ command = args[0]
532
+ if not command_re.match(command):
533
+ raise SystemExit("invalid command name '%s'" % command)
534
+ self.commands.append(command)
535
+
536
+ # Dig up the command class that implements this command, so we
537
+ # 1) know that it's a valid command, and 2) know which options
538
+ # it takes.
539
+ try:
540
+ cmd_class = self.get_command_class(command)
541
+ except DistutilsModuleError as msg:
542
+ raise DistutilsArgError(msg)
543
+
544
+ # Require that the command class be derived from Command -- want
545
+ # to be sure that the basic "command" interface is implemented.
546
+ if not issubclass(cmd_class, Command):
547
+ raise DistutilsClassError(
548
+ "command class %s must subclass Command" % cmd_class)
549
+
550
+ # Also make sure that the command object provides a list of its
551
+ # known options.
552
+ if not (hasattr(cmd_class, 'user_options') and
553
+ isinstance(cmd_class.user_options, list)):
554
+ msg = ("command class %s must provide "
555
+ "'user_options' attribute (a list of tuples)")
556
+ raise DistutilsClassError(msg % cmd_class)
557
+
558
+ # If the command class has a list of negative alias options,
559
+ # merge it in with the global negative aliases.
560
+ negative_opt = self.negative_opt
561
+ if hasattr(cmd_class, 'negative_opt'):
562
+ negative_opt = negative_opt.copy()
563
+ negative_opt.update(cmd_class.negative_opt)
564
+
565
+ # Check for help_options in command class. They have a different
566
+ # format (tuple of four) so we need to preprocess them here.
567
+ if (hasattr(cmd_class, 'help_options') and
568
+ isinstance(cmd_class.help_options, list)):
569
+ help_options = fix_help_options(cmd_class.help_options)
570
+ else:
571
+ help_options = []
572
+
573
+ # All commands support the global options too, just by adding
574
+ # in 'global_options'.
575
+ parser.set_option_table(self.global_options +
576
+ cmd_class.user_options +
577
+ help_options)
578
+ parser.set_negative_aliases(negative_opt)
579
+ (args, opts) = parser.getopt(args[1:])
580
+ if hasattr(opts, 'help') and opts.help:
581
+ self._show_help(parser, display_options=0, commands=[cmd_class])
582
+ return
583
+
584
+ if (hasattr(cmd_class, 'help_options') and
585
+ isinstance(cmd_class.help_options, list)):
586
+ help_option_found=0
587
+ for (help_option, short, desc, func) in cmd_class.help_options:
588
+ if hasattr(opts, parser.get_attr_name(help_option)):
589
+ help_option_found=1
590
+ if callable(func):
591
+ func()
592
+ else:
593
+ raise DistutilsClassError(
594
+ "invalid help function %r for help option '%s': "
595
+ "must be a callable object (function, etc.)"
596
+ % (func, help_option))
597
+
598
+ if help_option_found:
599
+ return
600
+
601
+ # Put the options from the command-line into their official
602
+ # holding pen, the 'command_options' dictionary.
603
+ opt_dict = self.get_option_dict(command)
604
+ for (name, value) in vars(opts).items():
605
+ opt_dict[name] = ("command line", value)
606
+
607
+ return args
608
+
609
+ def finalize_options(self):
610
+ """Set final values for all the options on the Distribution
611
+ instance, analogous to the .finalize_options() method of Command
612
+ objects.
613
+ """
614
+ for attr in ('keywords', 'platforms'):
615
+ value = getattr(self.metadata, attr)
616
+ if value is None:
617
+ continue
618
+ if isinstance(value, str):
619
+ value = [elm.strip() for elm in value.split(',')]
620
+ setattr(self.metadata, attr, value)
621
+
622
+ def _show_help(self, parser, global_options=1, display_options=1,
623
+ commands=[]):
624
+ """Show help for the setup script command-line in the form of
625
+ several lists of command-line options. 'parser' should be a
626
+ FancyGetopt instance; do not expect it to be returned in the
627
+ same state, as its option table will be reset to make it
628
+ generate the correct help text.
629
+
630
+ If 'global_options' is true, lists the global options:
631
+ --verbose, --dry-run, etc. If 'display_options' is true, lists
632
+ the "display-only" options: --name, --version, etc. Finally,
633
+ lists per-command help for every command name or command class
634
+ in 'commands'.
635
+ """
636
+ # late import because of mutual dependence between these modules
637
+ from distutils.core import gen_usage
638
+ from distutils.cmd import Command
639
+
640
+ if global_options:
641
+ if display_options:
642
+ options = self._get_toplevel_options()
643
+ else:
644
+ options = self.global_options
645
+ parser.set_option_table(options)
646
+ parser.print_help(self.common_usage + "\nGlobal options:")
647
+ print('')
648
+
649
+ if display_options:
650
+ parser.set_option_table(self.display_options)
651
+ parser.print_help(
652
+ "Information display options (just display " +
653
+ "information, ignore any commands)")
654
+ print('')
655
+
656
+ for command in self.commands:
657
+ if isinstance(command, type) and issubclass(command, Command):
658
+ klass = command
659
+ else:
660
+ klass = self.get_command_class(command)
661
+ if (hasattr(klass, 'help_options') and
662
+ isinstance(klass.help_options, list)):
663
+ parser.set_option_table(klass.user_options +
664
+ fix_help_options(klass.help_options))
665
+ else:
666
+ parser.set_option_table(klass.user_options)
667
+ parser.print_help("Options for '%s' command:" % klass.__name__)
668
+ print('')
669
+
670
+ print(gen_usage(self.script_name))
671
+
672
+ def handle_display_options(self, option_order):
673
+ """If there were any non-global "display-only" options
674
+ (--help-commands or the metadata display options) on the command
675
+ line, display the requested info and return true; else return
676
+ false.
677
+ """
678
+ from distutils.core import gen_usage
679
+
680
+ # User just wants a list of commands -- we'll print it out and stop
681
+ # processing now (ie. if they ran "setup --help-commands foo bar",
682
+ # we ignore "foo bar").
683
+ if self.help_commands:
684
+ self.print_commands()
685
+ print('')
686
+ print(gen_usage(self.script_name))
687
+ return 1
688
+
689
+ # If user supplied any of the "display metadata" options, then
690
+ # display that metadata in the order in which the user supplied the
691
+ # metadata options.
692
+ any_display_options = 0
693
+ is_display_option = {}
694
+ for option in self.display_options:
695
+ is_display_option[option[0]] = 1
696
+
697
+ for (opt, val) in option_order:
698
+ if val and is_display_option.get(opt):
699
+ opt = translate_longopt(opt)
700
+ value = getattr(self.metadata, "get_"+opt)()
701
+ if opt in ['keywords', 'platforms']:
702
+ print(','.join(value))
703
+ elif opt in ('classifiers', 'provides', 'requires',
704
+ 'obsoletes'):
705
+ print('\n'.join(value))
706
+ else:
707
+ print(value)
708
+ any_display_options = 1
709
+
710
+ return any_display_options
711
+
712
+ def print_command_list(self, commands, header, max_length):
713
+ """Print a subset of the list of all commands -- used by
714
+ 'print_commands()'.
715
+ """
716
+ print(header + ":")
717
+
718
+ for cmd in commands:
719
+ klass = self.cmdclass.get(cmd)
720
+ if not klass:
721
+ klass = self.get_command_class(cmd)
722
+ try:
723
+ description = klass.description
724
+ except AttributeError:
725
+ description = "(no description available)"
726
+
727
+ print(" %-*s %s" % (max_length, cmd, description))
728
+
729
+ def print_commands(self):
730
+ """Print out a help message listing all available commands with a
731
+ description of each. The list is divided into "standard commands"
732
+ (listed in distutils.command.__all__) and "extra commands"
733
+ (mentioned in self.cmdclass, but not a standard command). The
734
+ descriptions come from the command class attribute
735
+ 'description'.
736
+ """
737
+ import distutils.command
738
+ std_commands = distutils.command.__all__
739
+ is_std = {}
740
+ for cmd in std_commands:
741
+ is_std[cmd] = 1
742
+
743
+ extra_commands = []
744
+ for cmd in self.cmdclass.keys():
745
+ if not is_std.get(cmd):
746
+ extra_commands.append(cmd)
747
+
748
+ max_length = 0
749
+ for cmd in (std_commands + extra_commands):
750
+ if len(cmd) > max_length:
751
+ max_length = len(cmd)
752
+
753
+ self.print_command_list(std_commands,
754
+ "Standard commands",
755
+ max_length)
756
+ if extra_commands:
757
+ print()
758
+ self.print_command_list(extra_commands,
759
+ "Extra commands",
760
+ max_length)
761
+
762
+ def get_command_list(self):
763
+ """Get a list of (command, description) tuples.
764
+ The list is divided into "standard commands" (listed in
765
+ distutils.command.__all__) and "extra commands" (mentioned in
766
+ self.cmdclass, but not a standard command). The descriptions come
767
+ from the command class attribute 'description'.
768
+ """
769
+ # Currently this is only used on Mac OS, for the Mac-only GUI
770
+ # Distutils interface (by Jack Jansen)
771
+ import distutils.command
772
+ std_commands = distutils.command.__all__
773
+ is_std = {}
774
+ for cmd in std_commands:
775
+ is_std[cmd] = 1
776
+
777
+ extra_commands = []
778
+ for cmd in self.cmdclass.keys():
779
+ if not is_std.get(cmd):
780
+ extra_commands.append(cmd)
781
+
782
+ rv = []
783
+ for cmd in (std_commands + extra_commands):
784
+ klass = self.cmdclass.get(cmd)
785
+ if not klass:
786
+ klass = self.get_command_class(cmd)
787
+ try:
788
+ description = klass.description
789
+ except AttributeError:
790
+ description = "(no description available)"
791
+ rv.append((cmd, description))
792
+ return rv
793
+
794
+ # -- Command class/object methods ----------------------------------
795
+
796
+ def get_command_packages(self):
797
+ """Return a list of packages from which commands are loaded."""
798
+ pkgs = self.command_packages
799
+ if not isinstance(pkgs, list):
800
+ if pkgs is None:
801
+ pkgs = ''
802
+ pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
803
+ if "distutils.command" not in pkgs:
804
+ pkgs.insert(0, "distutils.command")
805
+ self.command_packages = pkgs
806
+ return pkgs
807
+
808
+ def get_command_class(self, command):
809
+ """Return the class that implements the Distutils command named by
810
+ 'command'. First we check the 'cmdclass' dictionary; if the
811
+ command is mentioned there, we fetch the class object from the
812
+ dictionary and return it. Otherwise we load the command module
813
+ ("distutils.command." + command) and fetch the command class from
814
+ the module. The loaded class is also stored in 'cmdclass'
815
+ to speed future calls to 'get_command_class()'.
816
+
817
+ Raises DistutilsModuleError if the expected module could not be
818
+ found, or if that module does not define the expected class.
819
+ """
820
+ klass = self.cmdclass.get(command)
821
+ if klass:
822
+ return klass
823
+
824
+ for pkgname in self.get_command_packages():
825
+ module_name = "%s.%s" % (pkgname, command)
826
+ klass_name = command
827
+
828
+ try:
829
+ __import__(module_name)
830
+ module = sys.modules[module_name]
831
+ except ImportError:
832
+ continue
833
+
834
+ try:
835
+ klass = getattr(module, klass_name)
836
+ except AttributeError:
837
+ raise DistutilsModuleError(
838
+ "invalid command '%s' (no class '%s' in module '%s')"
839
+ % (command, klass_name, module_name))
840
+
841
+ self.cmdclass[command] = klass
842
+ return klass
843
+
844
+ raise DistutilsModuleError("invalid command '%s'" % command)
845
+
846
+ def get_command_obj(self, command, create=1):
847
+ """Return the command object for 'command'. Normally this object
848
+ is cached on a previous call to 'get_command_obj()'; if no command
849
+ object for 'command' is in the cache, then we either create and
850
+ return it (if 'create' is true) or return None.
851
+ """
852
+ cmd_obj = self.command_obj.get(command)
853
+ if not cmd_obj and create:
854
+ if DEBUG:
855
+ self.announce("Distribution.get_command_obj(): "
856
+ "creating '%s' command object" % command)
857
+
858
+ klass = self.get_command_class(command)
859
+ cmd_obj = self.command_obj[command] = klass(self)
860
+ self.have_run[command] = 0
861
+
862
+ # Set any options that were supplied in config files
863
+ # or on the command line. (NB. support for error
864
+ # reporting is lame here: any errors aren't reported
865
+ # until 'finalize_options()' is called, which means
866
+ # we won't report the source of the error.)
867
+ options = self.command_options.get(command)
868
+ if options:
869
+ self._set_command_options(cmd_obj, options)
870
+
871
+ return cmd_obj
872
+
873
+ def _set_command_options(self, command_obj, option_dict=None):
874
+ """Set the options for 'command_obj' from 'option_dict'. Basically
875
+ this means copying elements of a dictionary ('option_dict') to
876
+ attributes of an instance ('command').
877
+
878
+ 'command_obj' must be a Command instance. If 'option_dict' is not
879
+ supplied, uses the standard option dictionary for this command
880
+ (from 'self.command_options').
881
+ """
882
+ command_name = command_obj.get_command_name()
883
+ if option_dict is None:
884
+ option_dict = self.get_option_dict(command_name)
885
+
886
+ if DEBUG:
887
+ self.announce(" setting options for '%s' command:" % command_name)
888
+ for (option, (source, value)) in option_dict.items():
889
+ if DEBUG:
890
+ self.announce(" %s = %s (from %s)" % (option, value,
891
+ source))
892
+ try:
893
+ bool_opts = [translate_longopt(o)
894
+ for o in command_obj.boolean_options]
895
+ except AttributeError:
896
+ bool_opts = []
897
+ try:
898
+ neg_opt = command_obj.negative_opt
899
+ except AttributeError:
900
+ neg_opt = {}
901
+
902
+ try:
903
+ is_string = isinstance(value, str)
904
+ if option in neg_opt and is_string:
905
+ setattr(command_obj, neg_opt[option], not strtobool(value))
906
+ elif option in bool_opts and is_string:
907
+ setattr(command_obj, option, strtobool(value))
908
+ elif hasattr(command_obj, option):
909
+ setattr(command_obj, option, value)
910
+ else:
911
+ raise DistutilsOptionError(
912
+ "error in %s: command '%s' has no such option '%s'"
913
+ % (source, command_name, option))
914
+ except ValueError as msg:
915
+ raise DistutilsOptionError(msg)
916
+
917
+ def reinitialize_command(self, command, reinit_subcommands=0):
918
+ """Reinitializes a command to the state it was in when first
919
+ returned by 'get_command_obj()': ie., initialized but not yet
920
+ finalized. This provides the opportunity to sneak option
921
+ values in programmatically, overriding or supplementing
922
+ user-supplied values from the config files and command line.
923
+ You'll have to re-finalize the command object (by calling
924
+ 'finalize_options()' or 'ensure_finalized()') before using it for
925
+ real.
926
+
927
+ 'command' should be a command name (string) or command object. If
928
+ 'reinit_subcommands' is true, also reinitializes the command's
929
+ sub-commands, as declared by the 'sub_commands' class attribute (if
930
+ it has one). See the "install" command for an example. Only
931
+ reinitializes the sub-commands that actually matter, ie. those
932
+ whose test predicates return true.
933
+
934
+ Returns the reinitialized command object.
935
+ """
936
+ from distutils.cmd import Command
937
+ if not isinstance(command, Command):
938
+ command_name = command
939
+ command = self.get_command_obj(command_name)
940
+ else:
941
+ command_name = command.get_command_name()
942
+
943
+ if not command.finalized:
944
+ return command
945
+ command.initialize_options()
946
+ command.finalized = 0
947
+ self.have_run[command_name] = 0
948
+ self._set_command_options(command)
949
+
950
+ if reinit_subcommands:
951
+ for sub in command.get_sub_commands():
952
+ self.reinitialize_command(sub, reinit_subcommands)
953
+
954
+ return command
955
+
956
+ # -- Methods that operate on the Distribution ----------------------
957
+
958
+ def announce(self, msg, level=log.INFO):
959
+ log.log(level, msg)
960
+
961
+ def run_commands(self):
962
+ """Run each command that was seen on the setup script command line.
963
+ Uses the list of commands found and cache of command objects
964
+ created by 'get_command_obj()'.
965
+ """
966
+ for cmd in self.commands:
967
+ self.run_command(cmd)
968
+
969
+ # -- Methods that operate on its Commands --------------------------
970
+
971
+ def run_command(self, command):
972
+ """Do whatever it takes to run a command (including nothing at all,
973
+ if the command has already been run). Specifically: if we have
974
+ already created and run the command named by 'command', return
975
+ silently without doing anything. If the command named by 'command'
976
+ doesn't even have a command object yet, create one. Then invoke
977
+ 'run()' on that command object (or an existing one).
978
+ """
979
+ # Already been here, done that? then return silently.
980
+ if self.have_run.get(command):
981
+ return
982
+
983
+ log.info("running %s", command)
984
+ cmd_obj = self.get_command_obj(command)
985
+ cmd_obj.ensure_finalized()
986
+ cmd_obj.run()
987
+ self.have_run[command] = 1
988
+
989
+ # -- Distribution query methods ------------------------------------
990
+
991
+ def has_pure_modules(self):
992
+ return len(self.packages or self.py_modules or []) > 0
993
+
994
+ def has_ext_modules(self):
995
+ return self.ext_modules and len(self.ext_modules) > 0
996
+
997
+ def has_c_libraries(self):
998
+ return self.libraries and len(self.libraries) > 0
999
+
1000
+ def has_modules(self):
1001
+ return self.has_pure_modules() or self.has_ext_modules()
1002
+
1003
+ def has_headers(self):
1004
+ return self.headers and len(self.headers) > 0
1005
+
1006
+ def has_scripts(self):
1007
+ return self.scripts and len(self.scripts) > 0
1008
+
1009
+ def has_data_files(self):
1010
+ return self.data_files and len(self.data_files) > 0
1011
+
1012
+ def is_pure(self):
1013
+ return (self.has_pure_modules() and
1014
+ not self.has_ext_modules() and
1015
+ not self.has_c_libraries())
1016
+
1017
+ # -- Metadata query methods ----------------------------------------
1018
+
1019
+ # If you're looking for 'get_name()', 'get_version()', and so forth,
1020
+ # they are defined in a sneaky way: the constructor binds self.get_XXX
1021
+ # to self.metadata.get_XXX. The actual code is in the
1022
+ # DistributionMetadata class, below.
1023
+
1024
+ class DistributionMetadata:
1025
+ """Dummy class to hold the distribution meta-data: name, version,
1026
+ author, and so forth.
1027
+ """
1028
+
1029
+ _METHOD_BASENAMES = ("name", "version", "author", "author_email",
1030
+ "maintainer", "maintainer_email", "url",
1031
+ "license", "description", "long_description",
1032
+ "keywords", "platforms", "fullname", "contact",
1033
+ "contact_email", "classifiers", "download_url",
1034
+ # PEP 314
1035
+ "provides", "requires", "obsoletes",
1036
+ )
1037
+
1038
+ def __init__(self, path=None):
1039
+ if path is not None:
1040
+ self.read_pkg_file(open(path))
1041
+ else:
1042
+ self.name = None
1043
+ self.version = None
1044
+ self.author = None
1045
+ self.author_email = None
1046
+ self.maintainer = None
1047
+ self.maintainer_email = None
1048
+ self.url = None
1049
+ self.license = None
1050
+ self.description = None
1051
+ self.long_description = None
1052
+ self.keywords = None
1053
+ self.platforms = None
1054
+ self.classifiers = None
1055
+ self.download_url = None
1056
+ # PEP 314
1057
+ self.provides = None
1058
+ self.requires = None
1059
+ self.obsoletes = None
1060
+
1061
+ def read_pkg_file(self, file):
1062
+ """Reads the metadata values from a file object."""
1063
+ msg = message_from_file(file)
1064
+
1065
+ def _read_field(name):
1066
+ value = msg[name]
1067
+ if value == 'UNKNOWN':
1068
+ return None
1069
+ return value
1070
+
1071
+ def _read_list(name):
1072
+ values = msg.get_all(name, None)
1073
+ if values == []:
1074
+ return None
1075
+ return values
1076
+
1077
+ metadata_version = msg['metadata-version']
1078
+ self.name = _read_field('name')
1079
+ self.version = _read_field('version')
1080
+ self.description = _read_field('summary')
1081
+ # we are filling author only.
1082
+ self.author = _read_field('author')
1083
+ self.maintainer = None
1084
+ self.author_email = _read_field('author-email')
1085
+ self.maintainer_email = None
1086
+ self.url = _read_field('home-page')
1087
+ self.license = _read_field('license')
1088
+
1089
+ if 'download-url' in msg:
1090
+ self.download_url = _read_field('download-url')
1091
+ else:
1092
+ self.download_url = None
1093
+
1094
+ self.long_description = _read_field('description')
1095
+ self.description = _read_field('summary')
1096
+
1097
+ if 'keywords' in msg:
1098
+ self.keywords = _read_field('keywords').split(',')
1099
+
1100
+ self.platforms = _read_list('platform')
1101
+ self.classifiers = _read_list('classifier')
1102
+
1103
+ # PEP 314 - these fields only exist in 1.1
1104
+ if metadata_version == '1.1':
1105
+ self.requires = _read_list('requires')
1106
+ self.provides = _read_list('provides')
1107
+ self.obsoletes = _read_list('obsoletes')
1108
+ else:
1109
+ self.requires = None
1110
+ self.provides = None
1111
+ self.obsoletes = None
1112
+
1113
+ def write_pkg_info(self, base_dir):
1114
+ """Write the PKG-INFO file into the release tree.
1115
+ """
1116
+ with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
1117
+ encoding='UTF-8') as pkg_info:
1118
+ self.write_pkg_file(pkg_info)
1119
+
1120
+ def write_pkg_file(self, file):
1121
+ """Write the PKG-INFO format data to a file object.
1122
+ """
1123
+ version = '1.0'
1124
+ if (self.provides or self.requires or self.obsoletes or
1125
+ self.classifiers or self.download_url):
1126
+ version = '1.1'
1127
+
1128
+ file.write('Metadata-Version: %s\n' % version)
1129
+ file.write('Name: %s\n' % self.get_name())
1130
+ file.write('Version: %s\n' % self.get_version())
1131
+ file.write('Summary: %s\n' % self.get_description())
1132
+ file.write('Home-page: %s\n' % self.get_url())
1133
+ file.write('Author: %s\n' % self.get_contact())
1134
+ file.write('Author-email: %s\n' % self.get_contact_email())
1135
+ file.write('License: %s\n' % self.get_license())
1136
+ if self.download_url:
1137
+ file.write('Download-URL: %s\n' % self.download_url)
1138
+
1139
+ long_desc = rfc822_escape(self.get_long_description())
1140
+ file.write('Description: %s\n' % long_desc)
1141
+
1142
+ keywords = ','.join(self.get_keywords())
1143
+ if keywords:
1144
+ file.write('Keywords: %s\n' % keywords)
1145
+
1146
+ self._write_list(file, 'Platform', self.get_platforms())
1147
+ self._write_list(file, 'Classifier', self.get_classifiers())
1148
+
1149
+ # PEP 314
1150
+ self._write_list(file, 'Requires', self.get_requires())
1151
+ self._write_list(file, 'Provides', self.get_provides())
1152
+ self._write_list(file, 'Obsoletes', self.get_obsoletes())
1153
+
1154
+ def _write_list(self, file, name, values):
1155
+ for value in values:
1156
+ file.write('%s: %s\n' % (name, value))
1157
+
1158
+ # -- Metadata query methods ----------------------------------------
1159
+
1160
+ def get_name(self):
1161
+ return self.name or "UNKNOWN"
1162
+
1163
+ def get_version(self):
1164
+ return self.version or "0.0.0"
1165
+
1166
+ def get_fullname(self):
1167
+ return "%s-%s" % (self.get_name(), self.get_version())
1168
+
1169
+ def get_author(self):
1170
+ return self.author or "UNKNOWN"
1171
+
1172
+ def get_author_email(self):
1173
+ return self.author_email or "UNKNOWN"
1174
+
1175
+ def get_maintainer(self):
1176
+ return self.maintainer or "UNKNOWN"
1177
+
1178
+ def get_maintainer_email(self):
1179
+ return self.maintainer_email or "UNKNOWN"
1180
+
1181
+ def get_contact(self):
1182
+ return self.maintainer or self.author or "UNKNOWN"
1183
+
1184
+ def get_contact_email(self):
1185
+ return self.maintainer_email or self.author_email or "UNKNOWN"
1186
+
1187
+ def get_url(self):
1188
+ return self.url or "UNKNOWN"
1189
+
1190
+ def get_license(self):
1191
+ return self.license or "UNKNOWN"
1192
+ get_licence = get_license
1193
+
1194
+ def get_description(self):
1195
+ return self.description or "UNKNOWN"
1196
+
1197
+ def get_long_description(self):
1198
+ return self.long_description or "UNKNOWN"
1199
+
1200
+ def get_keywords(self):
1201
+ return self.keywords or []
1202
+
1203
+ def set_keywords(self, value):
1204
+ self.keywords = _ensure_list(value, 'keywords')
1205
+
1206
+ def get_platforms(self):
1207
+ return self.platforms or ["UNKNOWN"]
1208
+
1209
+ def set_platforms(self, value):
1210
+ self.platforms = _ensure_list(value, 'platforms')
1211
+
1212
+ def get_classifiers(self):
1213
+ return self.classifiers or []
1214
+
1215
+ def set_classifiers(self, value):
1216
+ self.classifiers = _ensure_list(value, 'classifiers')
1217
+
1218
+ def get_download_url(self):
1219
+ return self.download_url or "UNKNOWN"
1220
+
1221
+ # PEP 314
1222
+ def get_requires(self):
1223
+ return self.requires or []
1224
+
1225
+ def set_requires(self, value):
1226
+ import distutils.versionpredicate
1227
+ for v in value:
1228
+ distutils.versionpredicate.VersionPredicate(v)
1229
+ self.requires = list(value)
1230
+
1231
+ def get_provides(self):
1232
+ return self.provides or []
1233
+
1234
+ def set_provides(self, value):
1235
+ value = [v.strip() for v in value]
1236
+ for v in value:
1237
+ import distutils.versionpredicate
1238
+ distutils.versionpredicate.split_provision(v)
1239
+ self.provides = value
1240
+
1241
+ def get_obsoletes(self):
1242
+ return self.obsoletes or []
1243
+
1244
+ def set_obsoletes(self, value):
1245
+ import distutils.versionpredicate
1246
+ for v in value:
1247
+ distutils.versionpredicate.VersionPredicate(v)
1248
+ self.obsoletes = list(value)
1249
+
1250
+ def fix_help_options(options):
1251
+ """Convert a 4-tuple 'help_options' list as found in various command
1252
+ classes to the 3-tuple form required by FancyGetopt.
1253
+ """
1254
+ new_options = []
1255
+ for help_tuple in options:
1256
+ new_options.append(help_tuple[0:3])
1257
+ return new_options
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/errors.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.errors
2
+
3
+ Provides exceptions used by the Distutils modules. Note that Distutils
4
+ modules may raise standard exceptions; in particular, SystemExit is
5
+ usually raised for errors that are obviously the end-user's fault
6
+ (eg. bad command-line arguments).
7
+
8
+ This module is safe to use in "from ... import *" mode; it only exports
9
+ symbols whose names start with "Distutils" and end with "Error"."""
10
+
11
+ class DistutilsError (Exception):
12
+ """The root of all Distutils evil."""
13
+ pass
14
+
15
+ class DistutilsModuleError (DistutilsError):
16
+ """Unable to load an expected module, or to find an expected class
17
+ within some module (in particular, command modules and classes)."""
18
+ pass
19
+
20
+ class DistutilsClassError (DistutilsError):
21
+ """Some command class (or possibly distribution class, if anyone
22
+ feels a need to subclass Distribution) is found not to be holding
23
+ up its end of the bargain, ie. implementing some part of the
24
+ "command "interface."""
25
+ pass
26
+
27
+ class DistutilsGetoptError (DistutilsError):
28
+ """The option table provided to 'fancy_getopt()' is bogus."""
29
+ pass
30
+
31
+ class DistutilsArgError (DistutilsError):
32
+ """Raised by fancy_getopt in response to getopt.error -- ie. an
33
+ error in the command line usage."""
34
+ pass
35
+
36
+ class DistutilsFileError (DistutilsError):
37
+ """Any problems in the filesystem: expected file not found, etc.
38
+ Typically this is for problems that we detect before OSError
39
+ could be raised."""
40
+ pass
41
+
42
+ class DistutilsOptionError (DistutilsError):
43
+ """Syntactic/semantic errors in command options, such as use of
44
+ mutually conflicting options, or inconsistent options,
45
+ badly-spelled values, etc. No distinction is made between option
46
+ values originating in the setup script, the command line, config
47
+ files, or what-have-you -- but if we *know* something originated in
48
+ the setup script, we'll raise DistutilsSetupError instead."""
49
+ pass
50
+
51
+ class DistutilsSetupError (DistutilsError):
52
+ """For errors that can be definitely blamed on the setup script,
53
+ such as invalid keyword arguments to 'setup()'."""
54
+ pass
55
+
56
+ class DistutilsPlatformError (DistutilsError):
57
+ """We don't know how to do something on the current platform (but
58
+ we do know how to do it on some platform) -- eg. trying to compile
59
+ C files on a platform not supported by a CCompiler subclass."""
60
+ pass
61
+
62
+ class DistutilsExecError (DistutilsError):
63
+ """Any problems executing an external program (such as the C
64
+ compiler, when compiling C files)."""
65
+ pass
66
+
67
+ class DistutilsInternalError (DistutilsError):
68
+ """Internal inconsistencies or impossibilities (obviously, this
69
+ should never be seen if the code is working!)."""
70
+ pass
71
+
72
+ class DistutilsTemplateError (DistutilsError):
73
+ """Syntax error in a file list template."""
74
+
75
+ class DistutilsByteCompileError(DistutilsError):
76
+ """Byte compile error."""
77
+
78
+ # Exception classes used by the CCompiler implementation classes
79
+ class CCompilerError (Exception):
80
+ """Some compile/link operation failed."""
81
+
82
+ class PreprocessError (CCompilerError):
83
+ """Failure to preprocess one or more C/C++ files."""
84
+
85
+ class CompileError (CCompilerError):
86
+ """Failure to compile one or more C/C++ source files."""
87
+
88
+ class LibError (CCompilerError):
89
+ """Failure to create a static library from one or more C/C++ object
90
+ files."""
91
+
92
+ class LinkError (CCompilerError):
93
+ """Failure to link one or more C/C++ object files into an executable
94
+ or shared library file."""
95
+
96
+ class UnknownFileError (CCompilerError):
97
+ """Attempt to process an unknown file type."""
env-llmeval/lib/python3.10/site-packages/setuptools/_distutils/extension.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.extension
2
+
3
+ Provides the Extension class, used to describe C/C++ extension
4
+ modules in setup scripts."""
5
+
6
+ import os
7
+ import warnings
8
+
9
+ # This class is really only used by the "build_ext" command, so it might
10
+ # make sense to put it in distutils.command.build_ext. However, that
11
+ # module is already big enough, and I want to make this class a bit more
12
+ # complex to simplify some common cases ("foo" module in "foo.c") and do
13
+ # better error-checking ("foo.c" actually exists).
14
+ #
15
+ # Also, putting this in build_ext.py means every setup script would have to
16
+ # import that large-ish module (indirectly, through distutils.core) in
17
+ # order to do anything.
18
+
19
+ class Extension:
20
+ """Just a collection of attributes that describes an extension
21
+ module and everything needed to build it (hopefully in a portable
22
+ way, but there are hooks that let you be as unportable as you need).
23
+
24
+ Instance attributes:
25
+ name : string
26
+ the full name of the extension, including any packages -- ie.
27
+ *not* a filename or pathname, but Python dotted name
28
+ sources : [string]
29
+ list of source filenames, relative to the distribution root
30
+ (where the setup script lives), in Unix form (slash-separated)
31
+ for portability. Source files may be C, C++, SWIG (.i),
32
+ platform-specific resource files, or whatever else is recognized
33
+ by the "build_ext" command as source for a Python extension.
34
+ include_dirs : [string]
35
+ list of directories to search for C/C++ header files (in Unix
36
+ form for portability)
37
+ define_macros : [(name : string, value : string|None)]
38
+ list of macros to define; each macro is defined using a 2-tuple,
39
+ where 'value' is either the string to define it to or None to
40
+ define it without a particular value (equivalent of "#define
41
+ FOO" in source or -DFOO on Unix C compiler command line)
42
+ undef_macros : [string]
43
+ list of macros to undefine explicitly
44
+ library_dirs : [string]
45
+ list of directories to search for C/C++ libraries at link time
46
+ libraries : [string]
47
+ list of library names (not filenames or paths) to link against
48
+ runtime_library_dirs : [string]
49
+ list of directories to search for C/C++ libraries at run time
50
+ (for shared extensions, this is when the extension is loaded)
51
+ extra_objects : [string]
52
+ list of extra files to link with (eg. object files not implied
53
+ by 'sources', static library that must be explicitly specified,
54
+ binary resource files, etc.)
55
+ extra_compile_args : [string]
56
+ any extra platform- and compiler-specific information to use
57
+ when compiling the source files in 'sources'. For platforms and
58
+ compilers where "command line" makes sense, this is typically a
59
+ list of command-line arguments, but for other platforms it could
60
+ be anything.
61
+ extra_link_args : [string]
62
+ any extra platform- and compiler-specific information to use
63
+ when linking object files together to create the extension (or
64
+ to create a new static Python interpreter). Similar
65
+ interpretation as for 'extra_compile_args'.
66
+ export_symbols : [string]
67
+ list of symbols to be exported from a shared extension. Not
68
+ used on all platforms, and not generally necessary for Python
69
+ extensions, which typically export exactly one symbol: "init" +
70
+ extension_name.
71
+ swig_opts : [string]
72
+ any extra options to pass to SWIG if a source file has the .i
73
+ extension.
74
+ depends : [string]
75
+ list of files that the extension depends on
76
+ language : string
77
+ extension language (i.e. "c", "c++", "objc"). Will be detected
78
+ from the source extensions if not provided.
79
+ optional : boolean
80
+ specifies that a build failure in the extension should not abort the
81
+ build process, but simply not install the failing extension.
82
+ """
83
+
84
+ # When adding arguments to this constructor, be sure to update
85
+ # setup_keywords in core.py.
86
+ def __init__(self, name, sources,
87
+ include_dirs=None,
88
+ define_macros=None,
89
+ undef_macros=None,
90
+ library_dirs=None,
91
+ libraries=None,
92
+ runtime_library_dirs=None,
93
+ extra_objects=None,
94
+ extra_compile_args=None,
95
+ extra_link_args=None,
96
+ export_symbols=None,
97
+ swig_opts = None,
98
+ depends=None,
99
+ language=None,
100
+ optional=None,
101
+ **kw # To catch unknown keywords
102
+ ):
103
+ if not isinstance(name, str):
104
+ raise AssertionError("'name' must be a string")
105
+ if not (isinstance(sources, list) and
106
+ all(isinstance(v, str) for v in sources)):
107
+ raise AssertionError("'sources' must be a list of strings")
108
+
109
+ self.name = name
110
+ self.sources = sources
111
+ self.include_dirs = include_dirs or []
112
+ self.define_macros = define_macros or []
113
+ self.undef_macros = undef_macros or []
114
+ self.library_dirs = library_dirs or []
115
+ self.libraries = libraries or []
116
+ self.runtime_library_dirs = runtime_library_dirs or []
117
+ self.extra_objects = extra_objects or []
118
+ self.extra_compile_args = extra_compile_args or []
119
+ self.extra_link_args = extra_link_args or []
120
+ self.export_symbols = export_symbols or []
121
+ self.swig_opts = swig_opts or []
122
+ self.depends = depends or []
123
+ self.language = language
124
+ self.optional = optional
125
+
126
+ # If there are unknown keyword options, warn about them
127
+ if len(kw) > 0:
128
+ options = [repr(option) for option in kw]
129
+ options = ', '.join(sorted(options))
130
+ msg = "Unknown Extension options: %s" % options
131
+ warnings.warn(msg)
132
+
133
+ def __repr__(self):
134
+ return '<%s.%s(%r) at %#x>' % (
135
+ self.__class__.__module__,
136
+ self.__class__.__qualname__,
137
+ self.name,
138
+ id(self))
139
+
140
+
141
+ def read_setup_file(filename):
142
+ """Reads a Setup file and returns Extension instances."""
143
+ from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
144
+ _variable_rx)
145
+
146
+ from distutils.text_file import TextFile
147
+ from distutils.util import split_quoted
148
+
149
+ # First pass over the file to gather "VAR = VALUE" assignments.
150
+ vars = parse_makefile(filename)
151
+
152
+ # Second pass to gobble up the real content: lines of the form
153
+ # <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
154
+ file = TextFile(filename,
155
+ strip_comments=1, skip_blanks=1, join_lines=1,
156
+ lstrip_ws=1, rstrip_ws=1)
157
+ try:
158
+ extensions = []
159
+
160
+ while True:
161
+ line = file.readline()
162
+ if line is None: # eof
163
+ break
164
+ if _variable_rx.match(line): # VAR=VALUE, handled in first pass
165
+ continue
166
+
167
+ if line[0] == line[-1] == "*":
168
+ file.warn("'%s' lines not handled yet" % line)
169
+ continue
170
+
171
+ line = expand_makefile_vars(line, vars)
172
+ words = split_quoted(line)
173
+
174
+ # NB. this parses a slightly different syntax than the old
175
+ # makesetup script: here, there must be exactly one extension per
176
+ # line, and it must be the first word of the line. I have no idea
177
+ # why the old syntax supported multiple extensions per line, as
178
+ # they all wind up being the same.
179
+
180
+ module = words[0]
181
+ ext = Extension(module, [])
182
+ append_next_word = None
183
+
184
+ for word in words[1:]:
185
+ if append_next_word is not None:
186
+ append_next_word.append(word)
187
+ append_next_word = None
188
+ continue
189
+
190
+ suffix = os.path.splitext(word)[1]
191
+ switch = word[0:2] ; value = word[2:]
192
+
193
+ if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"):
194
+ # hmm, should we do something about C vs. C++ sources?
195
+ # or leave it up to the CCompiler implementation to
196
+ # worry about?
197
+ ext.sources.append(word)
198
+ elif switch == "-I":
199
+ ext.include_dirs.append(value)
200
+ elif switch == "-D":
201
+ equals = value.find("=")
202
+ if equals == -1: # bare "-DFOO" -- no value
203
+ ext.define_macros.append((value, None))
204
+ else: # "-DFOO=blah"
205
+ ext.define_macros.append((value[0:equals],
206
+ value[equals+2:]))
207
+ elif switch == "-U":
208
+ ext.undef_macros.append(value)
209
+ elif switch == "-C": # only here 'cause makesetup has it!
210
+ ext.extra_compile_args.append(word)
211
+ elif switch == "-l":
212
+ ext.libraries.append(value)
213
+ elif switch == "-L":
214
+ ext.library_dirs.append(value)
215
+ elif switch == "-R":
216
+ ext.runtime_library_dirs.append(value)
217
+ elif word == "-rpath":
218
+ append_next_word = ext.runtime_library_dirs
219
+ elif word == "-Xlinker":
220
+ append_next_word = ext.extra_link_args
221
+ elif word == "-Xcompiler":
222
+ append_next_word = ext.extra_compile_args
223
+ elif switch == "-u":
224
+ ext.extra_link_args.append(word)
225
+ if not value:
226
+ append_next_word = ext.extra_link_args
227
+ elif suffix in (".a", ".so", ".sl", ".o", ".dylib"):
228
+ # NB. a really faithful emulation of makesetup would
229
+ # append a .o file to extra_objects only if it
230
+ # had a slash in it; otherwise, it would s/.o/.c/
231
+ # and append it to sources. Hmmmm.
232
+ ext.extra_objects.append(word)
233
+ else:
234
+ file.warn("unrecognized argument '%s'" % word)
235
+
236
+ extensions.append(ext)
237
+ finally:
238
+ file.close()
239
+
240
+ return extensions