applied-ai-018 commited on
Commit
c3bd9f3
·
verified ·
1 Parent(s): 56c22c4

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. scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/archive_util.cpython-310.pyc +0 -0
  2. scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/dist.cpython-310.pyc +0 -0
  3. scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/glob.cpython-310.pyc +0 -0
  4. scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/package_index.cpython-310.pyc +0 -0
  5. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc +0 -0
  6. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/bcppcompiler.cpython-310.pyc +0 -0
  7. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc +0 -0
  8. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/core.cpython-310.pyc +0 -0
  9. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc +0 -0
  10. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc +0 -0
  11. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-310.pyc +0 -0
  12. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-310.pyc +0 -0
  13. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-310.pyc +0 -0
  14. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc +0 -0
  15. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/archive_util.py +256 -0
  16. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/ccompiler.py +1123 -0
  17. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/cmd.py +403 -0
  18. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__init__.py +31 -0
  19. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-310.pyc +0 -0
  20. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist.cpython-310.pyc +0 -0
  21. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_dumb.cpython-310.pyc +0 -0
  22. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_msi.cpython-310.pyc +0 -0
  23. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_rpm.cpython-310.pyc +0 -0
  24. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_wininst.cpython-310.pyc +0 -0
  25. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build.cpython-310.pyc +0 -0
  26. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_clib.cpython-310.pyc +0 -0
  27. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_ext.cpython-310.pyc +0 -0
  28. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_py.cpython-310.pyc +0 -0
  29. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_scripts.cpython-310.pyc +0 -0
  30. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/check.cpython-310.pyc +0 -0
  31. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-310.pyc +0 -0
  32. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/config.cpython-310.pyc +0 -0
  33. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install.cpython-310.pyc +0 -0
  34. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_data.cpython-310.pyc +0 -0
  35. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_egg_info.cpython-310.pyc +0 -0
  36. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_headers.cpython-310.pyc +0 -0
  37. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_scripts.cpython-310.pyc +0 -0
  38. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/py37compat.cpython-310.pyc +0 -0
  39. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/register.cpython-310.pyc +0 -0
  40. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/sdist.cpython-310.pyc +0 -0
  41. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist.py +143 -0
  42. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_dumb.py +123 -0
  43. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_msi.py +749 -0
  44. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_rpm.py +579 -0
  45. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_wininst.py +377 -0
  46. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build.py +157 -0
  47. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_clib.py +209 -0
  48. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py +755 -0
  49. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.py +392 -0
  50. scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.py +152 -0
scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/archive_util.cpython-310.pyc ADDED
Binary file (5.85 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/dist.cpython-310.pyc ADDED
Binary file (36.3 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/glob.cpython-310.pyc ADDED
Binary file (3.74 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/__pycache__/package_index.cpython-310.pyc ADDED
Binary file (32.7 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc ADDED
Binary file (6.57 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/bcppcompiler.cpython-310.pyc ADDED
Binary file (6.56 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc ADDED
Binary file (33.3 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/core.cpython-310.pyc ADDED
Binary file (7.1 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc ADDED
Binary file (9 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc ADDED
Binary file (259 Bytes). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-310.pyc ADDED
Binary file (10.6 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-310.pyc ADDED
Binary file (10.8 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-310.pyc ADDED
Binary file (2.9 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc ADDED
Binary file (5.35 kB). View file
 
scripts/myenv/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
scripts/myenv/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
scripts/myenv/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)
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__init__.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command
2
+
3
+ Package containing implementation of all the standard Distutils
4
+ commands."""
5
+
6
+ __all__ = ['build',
7
+ 'build_py',
8
+ 'build_ext',
9
+ 'build_clib',
10
+ 'build_scripts',
11
+ 'clean',
12
+ 'install',
13
+ 'install_lib',
14
+ 'install_headers',
15
+ 'install_scripts',
16
+ 'install_data',
17
+ 'sdist',
18
+ 'register',
19
+ 'bdist',
20
+ 'bdist_dumb',
21
+ 'bdist_rpm',
22
+ 'bdist_wininst',
23
+ 'check',
24
+ 'upload',
25
+ # These two are reserved for future use:
26
+ #'bdist_sdux',
27
+ #'bdist_pkgtool',
28
+ # Note:
29
+ # bdist_packager is not included because it only provides
30
+ # an abstract base class
31
+ ]
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (538 Bytes). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist.cpython-310.pyc ADDED
Binary file (3.67 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_dumb.cpython-310.pyc ADDED
Binary file (3.65 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_msi.cpython-310.pyc ADDED
Binary file (19.7 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_rpm.cpython-310.pyc ADDED
Binary file (12.3 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/bdist_wininst.cpython-310.pyc ADDED
Binary file (8.64 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build.cpython-310.pyc ADDED
Binary file (3.9 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_clib.cpython-310.pyc ADDED
Binary file (4.88 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_ext.cpython-310.pyc ADDED
Binary file (16.2 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_py.cpython-310.pyc ADDED
Binary file (9.9 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_scripts.cpython-310.pyc ADDED
Binary file (4.02 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/check.cpython-310.pyc ADDED
Binary file (5.02 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-310.pyc ADDED
Binary file (2.16 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/config.cpython-310.pyc ADDED
Binary file (10.3 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install.cpython-310.pyc ADDED
Binary file (15.3 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_data.cpython-310.pyc ADDED
Binary file (2.35 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_egg_info.cpython-310.pyc ADDED
Binary file (3.32 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_headers.cpython-310.pyc ADDED
Binary file (1.78 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_scripts.cpython-310.pyc ADDED
Binary file (2.21 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/py37compat.cpython-310.pyc ADDED
Binary file (1.05 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/register.cpython-310.pyc ADDED
Binary file (8.69 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/sdist.cpython-310.pyc ADDED
Binary file (14.5 kB). View file
 
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.bdist
2
+
3
+ Implements the Distutils 'bdist' command (create a built [binary]
4
+ distribution)."""
5
+
6
+ import os
7
+ from distutils.core import Command
8
+ from distutils.errors import *
9
+ from distutils.util import get_platform
10
+
11
+
12
+ def show_formats():
13
+ """Print list of available formats (arguments to "--format" option).
14
+ """
15
+ from distutils.fancy_getopt import FancyGetopt
16
+ formats = []
17
+ for format in bdist.format_commands:
18
+ formats.append(("formats=" + format, None,
19
+ bdist.format_command[format][1]))
20
+ pretty_printer = FancyGetopt(formats)
21
+ pretty_printer.print_help("List of available distribution formats:")
22
+
23
+
24
+ class bdist(Command):
25
+
26
+ description = "create a built (binary) distribution"
27
+
28
+ user_options = [('bdist-base=', 'b',
29
+ "temporary directory for creating built distributions"),
30
+ ('plat-name=', 'p',
31
+ "platform name to embed in generated filenames "
32
+ "(default: %s)" % get_platform()),
33
+ ('formats=', None,
34
+ "formats for distribution (comma-separated list)"),
35
+ ('dist-dir=', 'd',
36
+ "directory to put final built distributions in "
37
+ "[default: dist]"),
38
+ ('skip-build', None,
39
+ "skip rebuilding everything (for testing/debugging)"),
40
+ ('owner=', 'u',
41
+ "Owner name used when creating a tar file"
42
+ " [default: current user]"),
43
+ ('group=', 'g',
44
+ "Group name used when creating a tar file"
45
+ " [default: current group]"),
46
+ ]
47
+
48
+ boolean_options = ['skip-build']
49
+
50
+ help_options = [
51
+ ('help-formats', None,
52
+ "lists available distribution formats", show_formats),
53
+ ]
54
+
55
+ # The following commands do not take a format option from bdist
56
+ no_format_option = ('bdist_rpm',)
57
+
58
+ # This won't do in reality: will need to distinguish RPM-ish Linux,
59
+ # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
60
+ default_format = {'posix': 'gztar',
61
+ 'nt': 'zip'}
62
+
63
+ # Establish the preferred order (for the --help-formats option).
64
+ format_commands = ['rpm', 'gztar', 'bztar', 'xztar', 'ztar', 'tar',
65
+ 'wininst', 'zip', 'msi']
66
+
67
+ # And the real information.
68
+ format_command = {'rpm': ('bdist_rpm', "RPM distribution"),
69
+ 'gztar': ('bdist_dumb', "gzip'ed tar file"),
70
+ 'bztar': ('bdist_dumb', "bzip2'ed tar file"),
71
+ 'xztar': ('bdist_dumb', "xz'ed tar file"),
72
+ 'ztar': ('bdist_dumb', "compressed tar file"),
73
+ 'tar': ('bdist_dumb', "tar file"),
74
+ 'wininst': ('bdist_wininst',
75
+ "Windows executable installer"),
76
+ 'zip': ('bdist_dumb', "ZIP file"),
77
+ 'msi': ('bdist_msi', "Microsoft Installer")
78
+ }
79
+
80
+
81
+ def initialize_options(self):
82
+ self.bdist_base = None
83
+ self.plat_name = None
84
+ self.formats = None
85
+ self.dist_dir = None
86
+ self.skip_build = 0
87
+ self.group = None
88
+ self.owner = None
89
+
90
+ def finalize_options(self):
91
+ # have to finalize 'plat_name' before 'bdist_base'
92
+ if self.plat_name is None:
93
+ if self.skip_build:
94
+ self.plat_name = get_platform()
95
+ else:
96
+ self.plat_name = self.get_finalized_command('build').plat_name
97
+
98
+ # 'bdist_base' -- parent of per-built-distribution-format
99
+ # temporary directories (eg. we'll probably have
100
+ # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
101
+ if self.bdist_base is None:
102
+ build_base = self.get_finalized_command('build').build_base
103
+ self.bdist_base = os.path.join(build_base,
104
+ 'bdist.' + self.plat_name)
105
+
106
+ self.ensure_string_list('formats')
107
+ if self.formats is None:
108
+ try:
109
+ self.formats = [self.default_format[os.name]]
110
+ except KeyError:
111
+ raise DistutilsPlatformError(
112
+ "don't know how to create built distributions "
113
+ "on platform %s" % os.name)
114
+
115
+ if self.dist_dir is None:
116
+ self.dist_dir = "dist"
117
+
118
+ def run(self):
119
+ # Figure out which sub-commands we need to run.
120
+ commands = []
121
+ for format in self.formats:
122
+ try:
123
+ commands.append(self.format_command[format][0])
124
+ except KeyError:
125
+ raise DistutilsOptionError("invalid format '%s'" % format)
126
+
127
+ # Reinitialize and run each command.
128
+ for i in range(len(self.formats)):
129
+ cmd_name = commands[i]
130
+ sub_cmd = self.reinitialize_command(cmd_name)
131
+ if cmd_name not in self.no_format_option:
132
+ sub_cmd.format = self.formats[i]
133
+
134
+ # passing the owner and group names for tar archiving
135
+ if cmd_name == 'bdist_dumb':
136
+ sub_cmd.owner = self.owner
137
+ sub_cmd.group = self.group
138
+
139
+ # If we're going to need to run this command again, tell it to
140
+ # keep its temporary files around so subsequent runs go faster.
141
+ if cmd_name in commands[i+1:]:
142
+ sub_cmd.keep_temp = 1
143
+ self.run_command(cmd_name)
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_dumb.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.bdist_dumb
2
+
3
+ Implements the Distutils 'bdist_dumb' command (create a "dumb" built
4
+ distribution -- i.e., just an archive to be unpacked under $prefix or
5
+ $exec_prefix)."""
6
+
7
+ import os
8
+ from distutils.core import Command
9
+ from distutils.util import get_platform
10
+ from distutils.dir_util import remove_tree, ensure_relative
11
+ from distutils.errors import *
12
+ from distutils.sysconfig import get_python_version
13
+ from distutils import log
14
+
15
+ class bdist_dumb(Command):
16
+
17
+ description = "create a \"dumb\" built distribution"
18
+
19
+ user_options = [('bdist-dir=', 'd',
20
+ "temporary directory for creating the distribution"),
21
+ ('plat-name=', 'p',
22
+ "platform name to embed in generated filenames "
23
+ "(default: %s)" % get_platform()),
24
+ ('format=', 'f',
25
+ "archive format to create (tar, gztar, bztar, xztar, "
26
+ "ztar, zip)"),
27
+ ('keep-temp', 'k',
28
+ "keep the pseudo-installation tree around after " +
29
+ "creating the distribution archive"),
30
+ ('dist-dir=', 'd',
31
+ "directory to put final built distributions in"),
32
+ ('skip-build', None,
33
+ "skip rebuilding everything (for testing/debugging)"),
34
+ ('relative', None,
35
+ "build the archive using relative paths "
36
+ "(default: false)"),
37
+ ('owner=', 'u',
38
+ "Owner name used when creating a tar file"
39
+ " [default: current user]"),
40
+ ('group=', 'g',
41
+ "Group name used when creating a tar file"
42
+ " [default: current group]"),
43
+ ]
44
+
45
+ boolean_options = ['keep-temp', 'skip-build', 'relative']
46
+
47
+ default_format = { 'posix': 'gztar',
48
+ 'nt': 'zip' }
49
+
50
+ def initialize_options(self):
51
+ self.bdist_dir = None
52
+ self.plat_name = None
53
+ self.format = None
54
+ self.keep_temp = 0
55
+ self.dist_dir = None
56
+ self.skip_build = None
57
+ self.relative = 0
58
+ self.owner = None
59
+ self.group = None
60
+
61
+ def finalize_options(self):
62
+ if self.bdist_dir is None:
63
+ bdist_base = self.get_finalized_command('bdist').bdist_base
64
+ self.bdist_dir = os.path.join(bdist_base, 'dumb')
65
+
66
+ if self.format is None:
67
+ try:
68
+ self.format = self.default_format[os.name]
69
+ except KeyError:
70
+ raise DistutilsPlatformError(
71
+ "don't know how to create dumb built distributions "
72
+ "on platform %s" % os.name)
73
+
74
+ self.set_undefined_options('bdist',
75
+ ('dist_dir', 'dist_dir'),
76
+ ('plat_name', 'plat_name'),
77
+ ('skip_build', 'skip_build'))
78
+
79
+ def run(self):
80
+ if not self.skip_build:
81
+ self.run_command('build')
82
+
83
+ install = self.reinitialize_command('install', reinit_subcommands=1)
84
+ install.root = self.bdist_dir
85
+ install.skip_build = self.skip_build
86
+ install.warn_dir = 0
87
+
88
+ log.info("installing to %s", self.bdist_dir)
89
+ self.run_command('install')
90
+
91
+ # And make an archive relative to the root of the
92
+ # pseudo-installation tree.
93
+ archive_basename = "%s.%s" % (self.distribution.get_fullname(),
94
+ self.plat_name)
95
+
96
+ pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
97
+ if not self.relative:
98
+ archive_root = self.bdist_dir
99
+ else:
100
+ if (self.distribution.has_ext_modules() and
101
+ (install.install_base != install.install_platbase)):
102
+ raise DistutilsPlatformError(
103
+ "can't make a dumb built distribution where "
104
+ "base and platbase are different (%s, %s)"
105
+ % (repr(install.install_base),
106
+ repr(install.install_platbase)))
107
+ else:
108
+ archive_root = os.path.join(self.bdist_dir,
109
+ ensure_relative(install.install_base))
110
+
111
+ # Make the archive
112
+ filename = self.make_archive(pseudoinstall_root,
113
+ self.format, root_dir=archive_root,
114
+ owner=self.owner, group=self.group)
115
+ if self.distribution.has_ext_modules():
116
+ pyversion = get_python_version()
117
+ else:
118
+ pyversion = 'any'
119
+ self.distribution.dist_files.append(('bdist_dumb', pyversion,
120
+ filename))
121
+
122
+ if not self.keep_temp:
123
+ remove_tree(self.bdist_dir, dry_run=self.dry_run)
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_msi.py ADDED
@@ -0,0 +1,749 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2005, 2006 Martin von Löwis
2
+ # Licensed to PSF under a Contributor Agreement.
3
+ # The bdist_wininst command proper
4
+ # based on bdist_wininst
5
+ """
6
+ Implements the bdist_msi command.
7
+ """
8
+
9
+ import os
10
+ import sys
11
+ import warnings
12
+ from distutils.core import Command
13
+ from distutils.dir_util import remove_tree
14
+ from distutils.sysconfig import get_python_version
15
+ from distutils.version import StrictVersion
16
+ from distutils.errors import DistutilsOptionError
17
+ from distutils.util import get_platform
18
+ from distutils import log
19
+ import msilib
20
+ from msilib import schema, sequence, text
21
+ from msilib import Directory, Feature, Dialog, add_data
22
+
23
+ class PyDialog(Dialog):
24
+ """Dialog class with a fixed layout: controls at the top, then a ruler,
25
+ then a list of buttons: back, next, cancel. Optionally a bitmap at the
26
+ left."""
27
+ def __init__(self, *args, **kw):
28
+ """Dialog(database, name, x, y, w, h, attributes, title, first,
29
+ default, cancel, bitmap=true)"""
30
+ Dialog.__init__(self, *args)
31
+ ruler = self.h - 36
32
+ bmwidth = 152*ruler/328
33
+ #if kw.get("bitmap", True):
34
+ # self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin")
35
+ self.line("BottomLine", 0, ruler, self.w, 0)
36
+
37
+ def title(self, title):
38
+ "Set the title text of the dialog at the top."
39
+ # name, x, y, w, h, flags=Visible|Enabled|Transparent|NoPrefix,
40
+ # text, in VerdanaBold10
41
+ self.text("Title", 15, 10, 320, 60, 0x30003,
42
+ r"{\VerdanaBold10}%s" % title)
43
+
44
+ def back(self, title, next, name = "Back", active = 1):
45
+ """Add a back button with a given title, the tab-next button,
46
+ its name in the Control table, possibly initially disabled.
47
+
48
+ Return the button, so that events can be associated"""
49
+ if active:
50
+ flags = 3 # Visible|Enabled
51
+ else:
52
+ flags = 1 # Visible
53
+ return self.pushbutton(name, 180, self.h-27 , 56, 17, flags, title, next)
54
+
55
+ def cancel(self, title, next, name = "Cancel", active = 1):
56
+ """Add a cancel button with a given title, the tab-next button,
57
+ its name in the Control table, possibly initially disabled.
58
+
59
+ Return the button, so that events can be associated"""
60
+ if active:
61
+ flags = 3 # Visible|Enabled
62
+ else:
63
+ flags = 1 # Visible
64
+ return self.pushbutton(name, 304, self.h-27, 56, 17, flags, title, next)
65
+
66
+ def next(self, title, next, name = "Next", active = 1):
67
+ """Add a Next button with a given title, the tab-next button,
68
+ its name in the Control table, possibly initially disabled.
69
+
70
+ Return the button, so that events can be associated"""
71
+ if active:
72
+ flags = 3 # Visible|Enabled
73
+ else:
74
+ flags = 1 # Visible
75
+ return self.pushbutton(name, 236, self.h-27, 56, 17, flags, title, next)
76
+
77
+ def xbutton(self, name, title, next, xpos):
78
+ """Add a button with a given title, the tab-next button,
79
+ its name in the Control table, giving its x position; the
80
+ y-position is aligned with the other buttons.
81
+
82
+ Return the button, so that events can be associated"""
83
+ return self.pushbutton(name, int(self.w*xpos - 28), self.h-27, 56, 17, 3, title, next)
84
+
85
+ class bdist_msi(Command):
86
+
87
+ description = "create a Microsoft Installer (.msi) binary distribution"
88
+
89
+ user_options = [('bdist-dir=', None,
90
+ "temporary directory for creating the distribution"),
91
+ ('plat-name=', 'p',
92
+ "platform name to embed in generated filenames "
93
+ "(default: %s)" % get_platform()),
94
+ ('keep-temp', 'k',
95
+ "keep the pseudo-installation tree around after " +
96
+ "creating the distribution archive"),
97
+ ('target-version=', None,
98
+ "require a specific python version" +
99
+ " on the target system"),
100
+ ('no-target-compile', 'c',
101
+ "do not compile .py to .pyc on the target system"),
102
+ ('no-target-optimize', 'o',
103
+ "do not compile .py to .pyo (optimized) "
104
+ "on the target system"),
105
+ ('dist-dir=', 'd',
106
+ "directory to put final built distributions in"),
107
+ ('skip-build', None,
108
+ "skip rebuilding everything (for testing/debugging)"),
109
+ ('install-script=', None,
110
+ "basename of installation script to be run after "
111
+ "installation or before deinstallation"),
112
+ ('pre-install-script=', None,
113
+ "Fully qualified filename of a script to be run before "
114
+ "any files are installed. This script need not be in the "
115
+ "distribution"),
116
+ ]
117
+
118
+ boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
119
+ 'skip-build']
120
+
121
+ all_versions = ['2.0', '2.1', '2.2', '2.3', '2.4',
122
+ '2.5', '2.6', '2.7', '2.8', '2.9',
123
+ '3.0', '3.1', '3.2', '3.3', '3.4',
124
+ '3.5', '3.6', '3.7', '3.8', '3.9']
125
+ other_version = 'X'
126
+
127
+ def __init__(self, *args, **kw):
128
+ super().__init__(*args, **kw)
129
+ warnings.warn("bdist_msi command is deprecated since Python 3.9, "
130
+ "use bdist_wheel (wheel packages) instead",
131
+ DeprecationWarning, 2)
132
+
133
+ def initialize_options(self):
134
+ self.bdist_dir = None
135
+ self.plat_name = None
136
+ self.keep_temp = 0
137
+ self.no_target_compile = 0
138
+ self.no_target_optimize = 0
139
+ self.target_version = None
140
+ self.dist_dir = None
141
+ self.skip_build = None
142
+ self.install_script = None
143
+ self.pre_install_script = None
144
+ self.versions = None
145
+
146
+ def finalize_options(self):
147
+ self.set_undefined_options('bdist', ('skip_build', 'skip_build'))
148
+
149
+ if self.bdist_dir is None:
150
+ bdist_base = self.get_finalized_command('bdist').bdist_base
151
+ self.bdist_dir = os.path.join(bdist_base, 'msi')
152
+
153
+ short_version = get_python_version()
154
+ if (not self.target_version) and self.distribution.has_ext_modules():
155
+ self.target_version = short_version
156
+
157
+ if self.target_version:
158
+ self.versions = [self.target_version]
159
+ if not self.skip_build and self.distribution.has_ext_modules()\
160
+ and self.target_version != short_version:
161
+ raise DistutilsOptionError(
162
+ "target version can only be %s, or the '--skip-build'"
163
+ " option must be specified" % (short_version,))
164
+ else:
165
+ self.versions = list(self.all_versions)
166
+
167
+ self.set_undefined_options('bdist',
168
+ ('dist_dir', 'dist_dir'),
169
+ ('plat_name', 'plat_name'),
170
+ )
171
+
172
+ if self.pre_install_script:
173
+ raise DistutilsOptionError(
174
+ "the pre-install-script feature is not yet implemented")
175
+
176
+ if self.install_script:
177
+ for script in self.distribution.scripts:
178
+ if self.install_script == os.path.basename(script):
179
+ break
180
+ else:
181
+ raise DistutilsOptionError(
182
+ "install_script '%s' not found in scripts"
183
+ % self.install_script)
184
+ self.install_script_key = None
185
+
186
+ def run(self):
187
+ if not self.skip_build:
188
+ self.run_command('build')
189
+
190
+ install = self.reinitialize_command('install', reinit_subcommands=1)
191
+ install.prefix = self.bdist_dir
192
+ install.skip_build = self.skip_build
193
+ install.warn_dir = 0
194
+
195
+ install_lib = self.reinitialize_command('install_lib')
196
+ # we do not want to include pyc or pyo files
197
+ install_lib.compile = 0
198
+ install_lib.optimize = 0
199
+
200
+ if self.distribution.has_ext_modules():
201
+ # If we are building an installer for a Python version other
202
+ # than the one we are currently running, then we need to ensure
203
+ # our build_lib reflects the other Python version rather than ours.
204
+ # Note that for target_version!=sys.version, we must have skipped the
205
+ # build step, so there is no issue with enforcing the build of this
206
+ # version.
207
+ target_version = self.target_version
208
+ if not target_version:
209
+ assert self.skip_build, "Should have already checked this"
210
+ target_version = '%d.%d' % sys.version_info[:2]
211
+ plat_specifier = ".%s-%s" % (self.plat_name, target_version)
212
+ build = self.get_finalized_command('build')
213
+ build.build_lib = os.path.join(build.build_base,
214
+ 'lib' + plat_specifier)
215
+
216
+ log.info("installing to %s", self.bdist_dir)
217
+ install.ensure_finalized()
218
+
219
+ # avoid warning of 'install_lib' about installing
220
+ # into a directory not in sys.path
221
+ sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB'))
222
+
223
+ install.run()
224
+
225
+ del sys.path[0]
226
+
227
+ self.mkpath(self.dist_dir)
228
+ fullname = self.distribution.get_fullname()
229
+ installer_name = self.get_installer_filename(fullname)
230
+ installer_name = os.path.abspath(installer_name)
231
+ if os.path.exists(installer_name): os.unlink(installer_name)
232
+
233
+ metadata = self.distribution.metadata
234
+ author = metadata.author
235
+ if not author:
236
+ author = metadata.maintainer
237
+ if not author:
238
+ author = "UNKNOWN"
239
+ version = metadata.get_version()
240
+ # ProductVersion must be strictly numeric
241
+ # XXX need to deal with prerelease versions
242
+ sversion = "%d.%d.%d" % StrictVersion(version).version
243
+ # Prefix ProductName with Python x.y, so that
244
+ # it sorts together with the other Python packages
245
+ # in Add-Remove-Programs (APR)
246
+ fullname = self.distribution.get_fullname()
247
+ if self.target_version:
248
+ product_name = "Python %s %s" % (self.target_version, fullname)
249
+ else:
250
+ product_name = "Python %s" % (fullname)
251
+ self.db = msilib.init_database(installer_name, schema,
252
+ product_name, msilib.gen_uuid(),
253
+ sversion, author)
254
+ msilib.add_tables(self.db, sequence)
255
+ props = [('DistVersion', version)]
256
+ email = metadata.author_email or metadata.maintainer_email
257
+ if email:
258
+ props.append(("ARPCONTACT", email))
259
+ if metadata.url:
260
+ props.append(("ARPURLINFOABOUT", metadata.url))
261
+ if props:
262
+ add_data(self.db, 'Property', props)
263
+
264
+ self.add_find_python()
265
+ self.add_files()
266
+ self.add_scripts()
267
+ self.add_ui()
268
+ self.db.Commit()
269
+
270
+ if hasattr(self.distribution, 'dist_files'):
271
+ tup = 'bdist_msi', self.target_version or 'any', fullname
272
+ self.distribution.dist_files.append(tup)
273
+
274
+ if not self.keep_temp:
275
+ remove_tree(self.bdist_dir, dry_run=self.dry_run)
276
+
277
+ def add_files(self):
278
+ db = self.db
279
+ cab = msilib.CAB("distfiles")
280
+ rootdir = os.path.abspath(self.bdist_dir)
281
+
282
+ root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir")
283
+ f = Feature(db, "Python", "Python", "Everything",
284
+ 0, 1, directory="TARGETDIR")
285
+
286
+ items = [(f, root, '')]
287
+ for version in self.versions + [self.other_version]:
288
+ target = "TARGETDIR" + version
289
+ name = default = "Python" + version
290
+ desc = "Everything"
291
+ if version is self.other_version:
292
+ title = "Python from another location"
293
+ level = 2
294
+ else:
295
+ title = "Python %s from registry" % version
296
+ level = 1
297
+ f = Feature(db, name, title, desc, 1, level, directory=target)
298
+ dir = Directory(db, cab, root, rootdir, target, default)
299
+ items.append((f, dir, version))
300
+ db.Commit()
301
+
302
+ seen = {}
303
+ for feature, dir, version in items:
304
+ todo = [dir]
305
+ while todo:
306
+ dir = todo.pop()
307
+ for file in os.listdir(dir.absolute):
308
+ afile = os.path.join(dir.absolute, file)
309
+ if os.path.isdir(afile):
310
+ short = "%s|%s" % (dir.make_short(file), file)
311
+ default = file + version
312
+ newdir = Directory(db, cab, dir, file, default, short)
313
+ todo.append(newdir)
314
+ else:
315
+ if not dir.component:
316
+ dir.start_component(dir.logical, feature, 0)
317
+ if afile not in seen:
318
+ key = seen[afile] = dir.add_file(file)
319
+ if file==self.install_script:
320
+ if self.install_script_key:
321
+ raise DistutilsOptionError(
322
+ "Multiple files with name %s" % file)
323
+ self.install_script_key = '[#%s]' % key
324
+ else:
325
+ key = seen[afile]
326
+ add_data(self.db, "DuplicateFile",
327
+ [(key + version, dir.component, key, None, dir.logical)])
328
+ db.Commit()
329
+ cab.commit(db)
330
+
331
+ def add_find_python(self):
332
+ """Adds code to the installer to compute the location of Python.
333
+
334
+ Properties PYTHON.MACHINE.X.Y and PYTHON.USER.X.Y will be set from the
335
+ registry for each version of Python.
336
+
337
+ Properties TARGETDIRX.Y will be set from PYTHON.USER.X.Y if defined,
338
+ else from PYTHON.MACHINE.X.Y.
339
+
340
+ Properties PYTHONX.Y will be set to TARGETDIRX.Y\\python.exe"""
341
+
342
+ start = 402
343
+ for ver in self.versions:
344
+ install_path = r"SOFTWARE\Python\PythonCore\%s\InstallPath" % ver
345
+ machine_reg = "python.machine." + ver
346
+ user_reg = "python.user." + ver
347
+ machine_prop = "PYTHON.MACHINE." + ver
348
+ user_prop = "PYTHON.USER." + ver
349
+ machine_action = "PythonFromMachine" + ver
350
+ user_action = "PythonFromUser" + ver
351
+ exe_action = "PythonExe" + ver
352
+ target_dir_prop = "TARGETDIR" + ver
353
+ exe_prop = "PYTHON" + ver
354
+ if msilib.Win64:
355
+ # type: msidbLocatorTypeRawValue + msidbLocatorType64bit
356
+ Type = 2+16
357
+ else:
358
+ Type = 2
359
+ add_data(self.db, "RegLocator",
360
+ [(machine_reg, 2, install_path, None, Type),
361
+ (user_reg, 1, install_path, None, Type)])
362
+ add_data(self.db, "AppSearch",
363
+ [(machine_prop, machine_reg),
364
+ (user_prop, user_reg)])
365
+ add_data(self.db, "CustomAction",
366
+ [(machine_action, 51+256, target_dir_prop, "[" + machine_prop + "]"),
367
+ (user_action, 51+256, target_dir_prop, "[" + user_prop + "]"),
368
+ (exe_action, 51+256, exe_prop, "[" + target_dir_prop + "]\\python.exe"),
369
+ ])
370
+ add_data(self.db, "InstallExecuteSequence",
371
+ [(machine_action, machine_prop, start),
372
+ (user_action, user_prop, start + 1),
373
+ (exe_action, None, start + 2),
374
+ ])
375
+ add_data(self.db, "InstallUISequence",
376
+ [(machine_action, machine_prop, start),
377
+ (user_action, user_prop, start + 1),
378
+ (exe_action, None, start + 2),
379
+ ])
380
+ add_data(self.db, "Condition",
381
+ [("Python" + ver, 0, "NOT TARGETDIR" + ver)])
382
+ start += 4
383
+ assert start < 500
384
+
385
+ def add_scripts(self):
386
+ if self.install_script:
387
+ start = 6800
388
+ for ver in self.versions + [self.other_version]:
389
+ install_action = "install_script." + ver
390
+ exe_prop = "PYTHON" + ver
391
+ add_data(self.db, "CustomAction",
392
+ [(install_action, 50, exe_prop, self.install_script_key)])
393
+ add_data(self.db, "InstallExecuteSequence",
394
+ [(install_action, "&Python%s=3" % ver, start)])
395
+ start += 1
396
+ # XXX pre-install scripts are currently refused in finalize_options()
397
+ # but if this feature is completed, it will also need to add
398
+ # entries for each version as the above code does
399
+ if self.pre_install_script:
400
+ scriptfn = os.path.join(self.bdist_dir, "preinstall.bat")
401
+ with open(scriptfn, "w") as f:
402
+ # The batch file will be executed with [PYTHON], so that %1
403
+ # is the path to the Python interpreter; %0 will be the path
404
+ # of the batch file.
405
+ # rem ="""
406
+ # %1 %0
407
+ # exit
408
+ # """
409
+ # <actual script>
410
+ f.write('rem ="""\n%1 %0\nexit\n"""\n')
411
+ with open(self.pre_install_script) as fin:
412
+ f.write(fin.read())
413
+ add_data(self.db, "Binary",
414
+ [("PreInstall", msilib.Binary(scriptfn))
415
+ ])
416
+ add_data(self.db, "CustomAction",
417
+ [("PreInstall", 2, "PreInstall", None)
418
+ ])
419
+ add_data(self.db, "InstallExecuteSequence",
420
+ [("PreInstall", "NOT Installed", 450)])
421
+
422
+
423
+ def add_ui(self):
424
+ db = self.db
425
+ x = y = 50
426
+ w = 370
427
+ h = 300
428
+ title = "[ProductName] Setup"
429
+
430
+ # see "Dialog Style Bits"
431
+ modal = 3 # visible | modal
432
+ modeless = 1 # visible
433
+ track_disk_space = 32
434
+
435
+ # UI customization properties
436
+ add_data(db, "Property",
437
+ # See "DefaultUIFont Property"
438
+ [("DefaultUIFont", "DlgFont8"),
439
+ # See "ErrorDialog Style Bit"
440
+ ("ErrorDialog", "ErrorDlg"),
441
+ ("Progress1", "Install"), # modified in maintenance type dlg
442
+ ("Progress2", "installs"),
443
+ ("MaintenanceForm_Action", "Repair"),
444
+ # possible values: ALL, JUSTME
445
+ ("WhichUsers", "ALL")
446
+ ])
447
+
448
+ # Fonts, see "TextStyle Table"
449
+ add_data(db, "TextStyle",
450
+ [("DlgFont8", "Tahoma", 9, None, 0),
451
+ ("DlgFontBold8", "Tahoma", 8, None, 1), #bold
452
+ ("VerdanaBold10", "Verdana", 10, None, 1),
453
+ ("VerdanaRed9", "Verdana", 9, 255, 0),
454
+ ])
455
+
456
+ # UI Sequences, see "InstallUISequence Table", "Using a Sequence Table"
457
+ # Numbers indicate sequence; see sequence.py for how these action integrate
458
+ add_data(db, "InstallUISequence",
459
+ [("PrepareDlg", "Not Privileged or Windows9x or Installed", 140),
460
+ ("WhichUsersDlg", "Privileged and not Windows9x and not Installed", 141),
461
+ # In the user interface, assume all-users installation if privileged.
462
+ ("SelectFeaturesDlg", "Not Installed", 1230),
463
+ # XXX no support for resume installations yet
464
+ #("ResumeDlg", "Installed AND (RESUME OR Preselected)", 1240),
465
+ ("MaintenanceTypeDlg", "Installed AND NOT RESUME AND NOT Preselected", 1250),
466
+ ("ProgressDlg", None, 1280)])
467
+
468
+ add_data(db, 'ActionText', text.ActionText)
469
+ add_data(db, 'UIText', text.UIText)
470
+ #####################################################################
471
+ # Standard dialogs: FatalError, UserExit, ExitDialog
472
+ fatal=PyDialog(db, "FatalError", x, y, w, h, modal, title,
473
+ "Finish", "Finish", "Finish")
474
+ fatal.title("[ProductName] Installer ended prematurely")
475
+ fatal.back("< Back", "Finish", active = 0)
476
+ fatal.cancel("Cancel", "Back", active = 0)
477
+ fatal.text("Description1", 15, 70, 320, 80, 0x30003,
478
+ "[ProductName] setup ended prematurely because of an error. Your system has not been modified. To install this program at a later time, please run the installation again.")
479
+ fatal.text("Description2", 15, 155, 320, 20, 0x30003,
480
+ "Click the Finish button to exit the Installer.")
481
+ c=fatal.next("Finish", "Cancel", name="Finish")
482
+ c.event("EndDialog", "Exit")
483
+
484
+ user_exit=PyDialog(db, "UserExit", x, y, w, h, modal, title,
485
+ "Finish", "Finish", "Finish")
486
+ user_exit.title("[ProductName] Installer was interrupted")
487
+ user_exit.back("< Back", "Finish", active = 0)
488
+ user_exit.cancel("Cancel", "Back", active = 0)
489
+ user_exit.text("Description1", 15, 70, 320, 80, 0x30003,
490
+ "[ProductName] setup was interrupted. Your system has not been modified. "
491
+ "To install this program at a later time, please run the installation again.")
492
+ user_exit.text("Description2", 15, 155, 320, 20, 0x30003,
493
+ "Click the Finish button to exit the Installer.")
494
+ c = user_exit.next("Finish", "Cancel", name="Finish")
495
+ c.event("EndDialog", "Exit")
496
+
497
+ exit_dialog = PyDialog(db, "ExitDialog", x, y, w, h, modal, title,
498
+ "Finish", "Finish", "Finish")
499
+ exit_dialog.title("Completing the [ProductName] Installer")
500
+ exit_dialog.back("< Back", "Finish", active = 0)
501
+ exit_dialog.cancel("Cancel", "Back", active = 0)
502
+ exit_dialog.text("Description", 15, 235, 320, 20, 0x30003,
503
+ "Click the Finish button to exit the Installer.")
504
+ c = exit_dialog.next("Finish", "Cancel", name="Finish")
505
+ c.event("EndDialog", "Return")
506
+
507
+ #####################################################################
508
+ # Required dialog: FilesInUse, ErrorDlg
509
+ inuse = PyDialog(db, "FilesInUse",
510
+ x, y, w, h,
511
+ 19, # KeepModeless|Modal|Visible
512
+ title,
513
+ "Retry", "Retry", "Retry", bitmap=False)
514
+ inuse.text("Title", 15, 6, 200, 15, 0x30003,
515
+ r"{\DlgFontBold8}Files in Use")
516
+ inuse.text("Description", 20, 23, 280, 20, 0x30003,
517
+ "Some files that need to be updated are currently in use.")
518
+ inuse.text("Text", 20, 55, 330, 50, 3,
519
+ "The following applications are using files that need to be updated by this setup. Close these applications and then click Retry to continue the installation or Cancel to exit it.")
520
+ inuse.control("List", "ListBox", 20, 107, 330, 130, 7, "FileInUseProcess",
521
+ None, None, None)
522
+ c=inuse.back("Exit", "Ignore", name="Exit")
523
+ c.event("EndDialog", "Exit")
524
+ c=inuse.next("Ignore", "Retry", name="Ignore")
525
+ c.event("EndDialog", "Ignore")
526
+ c=inuse.cancel("Retry", "Exit", name="Retry")
527
+ c.event("EndDialog","Retry")
528
+
529
+ # See "Error Dialog". See "ICE20" for the required names of the controls.
530
+ error = Dialog(db, "ErrorDlg",
531
+ 50, 10, 330, 101,
532
+ 65543, # Error|Minimize|Modal|Visible
533
+ title,
534
+ "ErrorText", None, None)
535
+ error.text("ErrorText", 50,9,280,48,3, "")
536
+ #error.control("ErrorIcon", "Icon", 15, 9, 24, 24, 5242881, None, "py.ico", None, None)
537
+ error.pushbutton("N",120,72,81,21,3,"No",None).event("EndDialog","ErrorNo")
538
+ error.pushbutton("Y",240,72,81,21,3,"Yes",None).event("EndDialog","ErrorYes")
539
+ error.pushbutton("A",0,72,81,21,3,"Abort",None).event("EndDialog","ErrorAbort")
540
+ error.pushbutton("C",42,72,81,21,3,"Cancel",None).event("EndDialog","ErrorCancel")
541
+ error.pushbutton("I",81,72,81,21,3,"Ignore",None).event("EndDialog","ErrorIgnore")
542
+ error.pushbutton("O",159,72,81,21,3,"Ok",None).event("EndDialog","ErrorOk")
543
+ error.pushbutton("R",198,72,81,21,3,"Retry",None).event("EndDialog","ErrorRetry")
544
+
545
+ #####################################################################
546
+ # Global "Query Cancel" dialog
547
+ cancel = Dialog(db, "CancelDlg", 50, 10, 260, 85, 3, title,
548
+ "No", "No", "No")
549
+ cancel.text("Text", 48, 15, 194, 30, 3,
550
+ "Are you sure you want to cancel [ProductName] installation?")
551
+ #cancel.control("Icon", "Icon", 15, 15, 24, 24, 5242881, None,
552
+ # "py.ico", None, None)
553
+ c=cancel.pushbutton("Yes", 72, 57, 56, 17, 3, "Yes", "No")
554
+ c.event("EndDialog", "Exit")
555
+
556
+ c=cancel.pushbutton("No", 132, 57, 56, 17, 3, "No", "Yes")
557
+ c.event("EndDialog", "Return")
558
+
559
+ #####################################################################
560
+ # Global "Wait for costing" dialog
561
+ costing = Dialog(db, "WaitForCostingDlg", 50, 10, 260, 85, modal, title,
562
+ "Return", "Return", "Return")
563
+ costing.text("Text", 48, 15, 194, 30, 3,
564
+ "Please wait while the installer finishes determining your disk space requirements.")
565
+ c = costing.pushbutton("Return", 102, 57, 56, 17, 3, "Return", None)
566
+ c.event("EndDialog", "Exit")
567
+
568
+ #####################################################################
569
+ # Preparation dialog: no user input except cancellation
570
+ prep = PyDialog(db, "PrepareDlg", x, y, w, h, modeless, title,
571
+ "Cancel", "Cancel", "Cancel")
572
+ prep.text("Description", 15, 70, 320, 40, 0x30003,
573
+ "Please wait while the Installer prepares to guide you through the installation.")
574
+ prep.title("Welcome to the [ProductName] Installer")
575
+ c=prep.text("ActionText", 15, 110, 320, 20, 0x30003, "Pondering...")
576
+ c.mapping("ActionText", "Text")
577
+ c=prep.text("ActionData", 15, 135, 320, 30, 0x30003, None)
578
+ c.mapping("ActionData", "Text")
579
+ prep.back("Back", None, active=0)
580
+ prep.next("Next", None, active=0)
581
+ c=prep.cancel("Cancel", None)
582
+ c.event("SpawnDialog", "CancelDlg")
583
+
584
+ #####################################################################
585
+ # Feature (Python directory) selection
586
+ seldlg = PyDialog(db, "SelectFeaturesDlg", x, y, w, h, modal, title,
587
+ "Next", "Next", "Cancel")
588
+ seldlg.title("Select Python Installations")
589
+
590
+ seldlg.text("Hint", 15, 30, 300, 20, 3,
591
+ "Select the Python locations where %s should be installed."
592
+ % self.distribution.get_fullname())
593
+
594
+ seldlg.back("< Back", None, active=0)
595
+ c = seldlg.next("Next >", "Cancel")
596
+ order = 1
597
+ c.event("[TARGETDIR]", "[SourceDir]", ordering=order)
598
+ for version in self.versions + [self.other_version]:
599
+ order += 1
600
+ c.event("[TARGETDIR]", "[TARGETDIR%s]" % version,
601
+ "FEATURE_SELECTED AND &Python%s=3" % version,
602
+ ordering=order)
603
+ c.event("SpawnWaitDialog", "WaitForCostingDlg", ordering=order + 1)
604
+ c.event("EndDialog", "Return", ordering=order + 2)
605
+ c = seldlg.cancel("Cancel", "Features")
606
+ c.event("SpawnDialog", "CancelDlg")
607
+
608
+ c = seldlg.control("Features", "SelectionTree", 15, 60, 300, 120, 3,
609
+ "FEATURE", None, "PathEdit", None)
610
+ c.event("[FEATURE_SELECTED]", "1")
611
+ ver = self.other_version
612
+ install_other_cond = "FEATURE_SELECTED AND &Python%s=3" % ver
613
+ dont_install_other_cond = "FEATURE_SELECTED AND &Python%s<>3" % ver
614
+
615
+ c = seldlg.text("Other", 15, 200, 300, 15, 3,
616
+ "Provide an alternate Python location")
617
+ c.condition("Enable", install_other_cond)
618
+ c.condition("Show", install_other_cond)
619
+ c.condition("Disable", dont_install_other_cond)
620
+ c.condition("Hide", dont_install_other_cond)
621
+
622
+ c = seldlg.control("PathEdit", "PathEdit", 15, 215, 300, 16, 1,
623
+ "TARGETDIR" + ver, None, "Next", None)
624
+ c.condition("Enable", install_other_cond)
625
+ c.condition("Show", install_other_cond)
626
+ c.condition("Disable", dont_install_other_cond)
627
+ c.condition("Hide", dont_install_other_cond)
628
+
629
+ #####################################################################
630
+ # Disk cost
631
+ cost = PyDialog(db, "DiskCostDlg", x, y, w, h, modal, title,
632
+ "OK", "OK", "OK", bitmap=False)
633
+ cost.text("Title", 15, 6, 200, 15, 0x30003,
634
+ r"{\DlgFontBold8}Disk Space Requirements")
635
+ cost.text("Description", 20, 20, 280, 20, 0x30003,
636
+ "The disk space required for the installation of the selected features.")
637
+ cost.text("Text", 20, 53, 330, 60, 3,
638
+ "The highlighted volumes (if any) do not have enough disk space "
639
+ "available for the currently selected features. You can either "
640
+ "remove some files from the highlighted volumes, or choose to "
641
+ "install less features onto local drive(s), or select different "
642
+ "destination drive(s).")
643
+ cost.control("VolumeList", "VolumeCostList", 20, 100, 330, 150, 393223,
644
+ None, "{120}{70}{70}{70}{70}", None, None)
645
+ cost.xbutton("OK", "Ok", None, 0.5).event("EndDialog", "Return")
646
+
647
+ #####################################################################
648
+ # WhichUsers Dialog. Only available on NT, and for privileged users.
649
+ # This must be run before FindRelatedProducts, because that will
650
+ # take into account whether the previous installation was per-user
651
+ # or per-machine. We currently don't support going back to this
652
+ # dialog after "Next" was selected; to support this, we would need to
653
+ # find how to reset the ALLUSERS property, and how to re-run
654
+ # FindRelatedProducts.
655
+ # On Windows9x, the ALLUSERS property is ignored on the command line
656
+ # and in the Property table, but installer fails according to the documentation
657
+ # if a dialog attempts to set ALLUSERS.
658
+ whichusers = PyDialog(db, "WhichUsersDlg", x, y, w, h, modal, title,
659
+ "AdminInstall", "Next", "Cancel")
660
+ whichusers.title("Select whether to install [ProductName] for all users of this computer.")
661
+ # A radio group with two options: allusers, justme
662
+ g = whichusers.radiogroup("AdminInstall", 15, 60, 260, 50, 3,
663
+ "WhichUsers", "", "Next")
664
+ g.add("ALL", 0, 5, 150, 20, "Install for all users")
665
+ g.add("JUSTME", 0, 25, 150, 20, "Install just for me")
666
+
667
+ whichusers.back("Back", None, active=0)
668
+
669
+ c = whichusers.next("Next >", "Cancel")
670
+ c.event("[ALLUSERS]", "1", 'WhichUsers="ALL"', 1)
671
+ c.event("EndDialog", "Return", ordering = 2)
672
+
673
+ c = whichusers.cancel("Cancel", "AdminInstall")
674
+ c.event("SpawnDialog", "CancelDlg")
675
+
676
+ #####################################################################
677
+ # Installation Progress dialog (modeless)
678
+ progress = PyDialog(db, "ProgressDlg", x, y, w, h, modeless, title,
679
+ "Cancel", "Cancel", "Cancel", bitmap=False)
680
+ progress.text("Title", 20, 15, 200, 15, 0x30003,
681
+ r"{\DlgFontBold8}[Progress1] [ProductName]")
682
+ progress.text("Text", 35, 65, 300, 30, 3,
683
+ "Please wait while the Installer [Progress2] [ProductName]. "
684
+ "This may take several minutes.")
685
+ progress.text("StatusLabel", 35, 100, 35, 20, 3, "Status:")
686
+
687
+ c=progress.text("ActionText", 70, 100, w-70, 20, 3, "Pondering...")
688
+ c.mapping("ActionText", "Text")
689
+
690
+ #c=progress.text("ActionData", 35, 140, 300, 20, 3, None)
691
+ #c.mapping("ActionData", "Text")
692
+
693
+ c=progress.control("ProgressBar", "ProgressBar", 35, 120, 300, 10, 65537,
694
+ None, "Progress done", None, None)
695
+ c.mapping("SetProgress", "Progress")
696
+
697
+ progress.back("< Back", "Next", active=False)
698
+ progress.next("Next >", "Cancel", active=False)
699
+ progress.cancel("Cancel", "Back").event("SpawnDialog", "CancelDlg")
700
+
701
+ ###################################################################
702
+ # Maintenance type: repair/uninstall
703
+ maint = PyDialog(db, "MaintenanceTypeDlg", x, y, w, h, modal, title,
704
+ "Next", "Next", "Cancel")
705
+ maint.title("Welcome to the [ProductName] Setup Wizard")
706
+ maint.text("BodyText", 15, 63, 330, 42, 3,
707
+ "Select whether you want to repair or remove [ProductName].")
708
+ g=maint.radiogroup("RepairRadioGroup", 15, 108, 330, 60, 3,
709
+ "MaintenanceForm_Action", "", "Next")
710
+ #g.add("Change", 0, 0, 200, 17, "&Change [ProductName]")
711
+ g.add("Repair", 0, 18, 200, 17, "&Repair [ProductName]")
712
+ g.add("Remove", 0, 36, 200, 17, "Re&move [ProductName]")
713
+
714
+ maint.back("< Back", None, active=False)
715
+ c=maint.next("Finish", "Cancel")
716
+ # Change installation: Change progress dialog to "Change", then ask
717
+ # for feature selection
718
+ #c.event("[Progress1]", "Change", 'MaintenanceForm_Action="Change"', 1)
719
+ #c.event("[Progress2]", "changes", 'MaintenanceForm_Action="Change"', 2)
720
+
721
+ # Reinstall: Change progress dialog to "Repair", then invoke reinstall
722
+ # Also set list of reinstalled features to "ALL"
723
+ c.event("[REINSTALL]", "ALL", 'MaintenanceForm_Action="Repair"', 5)
724
+ c.event("[Progress1]", "Repairing", 'MaintenanceForm_Action="Repair"', 6)
725
+ c.event("[Progress2]", "repairs", 'MaintenanceForm_Action="Repair"', 7)
726
+ c.event("Reinstall", "ALL", 'MaintenanceForm_Action="Repair"', 8)
727
+
728
+ # Uninstall: Change progress to "Remove", then invoke uninstall
729
+ # Also set list of removed features to "ALL"
730
+ c.event("[REMOVE]", "ALL", 'MaintenanceForm_Action="Remove"', 11)
731
+ c.event("[Progress1]", "Removing", 'MaintenanceForm_Action="Remove"', 12)
732
+ c.event("[Progress2]", "removes", 'MaintenanceForm_Action="Remove"', 13)
733
+ c.event("Remove", "ALL", 'MaintenanceForm_Action="Remove"', 14)
734
+
735
+ # Close dialog when maintenance action scheduled
736
+ c.event("EndDialog", "Return", 'MaintenanceForm_Action<>"Change"', 20)
737
+ #c.event("NewDialog", "SelectFeaturesDlg", 'MaintenanceForm_Action="Change"', 21)
738
+
739
+ maint.cancel("Cancel", "RepairRadioGroup").event("SpawnDialog", "CancelDlg")
740
+
741
+ def get_installer_filename(self, fullname):
742
+ # Factored out to allow overriding in subclasses
743
+ if self.target_version:
744
+ base_name = "%s.%s-py%s.msi" % (fullname, self.plat_name,
745
+ self.target_version)
746
+ else:
747
+ base_name = "%s.%s.msi" % (fullname, self.plat_name)
748
+ installer_name = os.path.join(self.dist_dir, base_name)
749
+ return installer_name
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_rpm.py ADDED
@@ -0,0 +1,579 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.bdist_rpm
2
+
3
+ Implements the Distutils 'bdist_rpm' command (create RPM source and binary
4
+ distributions)."""
5
+
6
+ import subprocess, sys, os
7
+ from distutils.core import Command
8
+ from distutils.debug import DEBUG
9
+ from distutils.file_util import write_file
10
+ from distutils.errors import *
11
+ from distutils.sysconfig import get_python_version
12
+ from distutils import log
13
+
14
+ class bdist_rpm(Command):
15
+
16
+ description = "create an RPM distribution"
17
+
18
+ user_options = [
19
+ ('bdist-base=', None,
20
+ "base directory for creating built distributions"),
21
+ ('rpm-base=', None,
22
+ "base directory for creating RPMs (defaults to \"rpm\" under "
23
+ "--bdist-base; must be specified for RPM 2)"),
24
+ ('dist-dir=', 'd',
25
+ "directory to put final RPM files in "
26
+ "(and .spec files if --spec-only)"),
27
+ ('python=', None,
28
+ "path to Python interpreter to hard-code in the .spec file "
29
+ "(default: \"python\")"),
30
+ ('fix-python', None,
31
+ "hard-code the exact path to the current Python interpreter in "
32
+ "the .spec file"),
33
+ ('spec-only', None,
34
+ "only regenerate spec file"),
35
+ ('source-only', None,
36
+ "only generate source RPM"),
37
+ ('binary-only', None,
38
+ "only generate binary RPM"),
39
+ ('use-bzip2', None,
40
+ "use bzip2 instead of gzip to create source distribution"),
41
+
42
+ # More meta-data: too RPM-specific to put in the setup script,
43
+ # but needs to go in the .spec file -- so we make these options
44
+ # to "bdist_rpm". The idea is that packagers would put this
45
+ # info in setup.cfg, although they are of course free to
46
+ # supply it on the command line.
47
+ ('distribution-name=', None,
48
+ "name of the (Linux) distribution to which this "
49
+ "RPM applies (*not* the name of the module distribution!)"),
50
+ ('group=', None,
51
+ "package classification [default: \"Development/Libraries\"]"),
52
+ ('release=', None,
53
+ "RPM release number"),
54
+ ('serial=', None,
55
+ "RPM serial number"),
56
+ ('vendor=', None,
57
+ "RPM \"vendor\" (eg. \"Joe Blow <[email protected]>\") "
58
+ "[default: maintainer or author from setup script]"),
59
+ ('packager=', None,
60
+ "RPM packager (eg. \"Jane Doe <[email protected]>\") "
61
+ "[default: vendor]"),
62
+ ('doc-files=', None,
63
+ "list of documentation files (space or comma-separated)"),
64
+ ('changelog=', None,
65
+ "RPM changelog"),
66
+ ('icon=', None,
67
+ "name of icon file"),
68
+ ('provides=', None,
69
+ "capabilities provided by this package"),
70
+ ('requires=', None,
71
+ "capabilities required by this package"),
72
+ ('conflicts=', None,
73
+ "capabilities which conflict with this package"),
74
+ ('build-requires=', None,
75
+ "capabilities required to build this package"),
76
+ ('obsoletes=', None,
77
+ "capabilities made obsolete by this package"),
78
+ ('no-autoreq', None,
79
+ "do not automatically calculate dependencies"),
80
+
81
+ # Actions to take when building RPM
82
+ ('keep-temp', 'k',
83
+ "don't clean up RPM build directory"),
84
+ ('no-keep-temp', None,
85
+ "clean up RPM build directory [default]"),
86
+ ('use-rpm-opt-flags', None,
87
+ "compile with RPM_OPT_FLAGS when building from source RPM"),
88
+ ('no-rpm-opt-flags', None,
89
+ "do not pass any RPM CFLAGS to compiler"),
90
+ ('rpm3-mode', None,
91
+ "RPM 3 compatibility mode (default)"),
92
+ ('rpm2-mode', None,
93
+ "RPM 2 compatibility mode"),
94
+
95
+ # Add the hooks necessary for specifying custom scripts
96
+ ('prep-script=', None,
97
+ "Specify a script for the PREP phase of RPM building"),
98
+ ('build-script=', None,
99
+ "Specify a script for the BUILD phase of RPM building"),
100
+
101
+ ('pre-install=', None,
102
+ "Specify a script for the pre-INSTALL phase of RPM building"),
103
+ ('install-script=', None,
104
+ "Specify a script for the INSTALL phase of RPM building"),
105
+ ('post-install=', None,
106
+ "Specify a script for the post-INSTALL phase of RPM building"),
107
+
108
+ ('pre-uninstall=', None,
109
+ "Specify a script for the pre-UNINSTALL phase of RPM building"),
110
+ ('post-uninstall=', None,
111
+ "Specify a script for the post-UNINSTALL phase of RPM building"),
112
+
113
+ ('clean-script=', None,
114
+ "Specify a script for the CLEAN phase of RPM building"),
115
+
116
+ ('verify-script=', None,
117
+ "Specify a script for the VERIFY phase of the RPM build"),
118
+
119
+ # Allow a packager to explicitly force an architecture
120
+ ('force-arch=', None,
121
+ "Force an architecture onto the RPM build process"),
122
+
123
+ ('quiet', 'q',
124
+ "Run the INSTALL phase of RPM building in quiet mode"),
125
+ ]
126
+
127
+ boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode',
128
+ 'no-autoreq', 'quiet']
129
+
130
+ negative_opt = {'no-keep-temp': 'keep-temp',
131
+ 'no-rpm-opt-flags': 'use-rpm-opt-flags',
132
+ 'rpm2-mode': 'rpm3-mode'}
133
+
134
+
135
+ def initialize_options(self):
136
+ self.bdist_base = None
137
+ self.rpm_base = None
138
+ self.dist_dir = None
139
+ self.python = None
140
+ self.fix_python = None
141
+ self.spec_only = None
142
+ self.binary_only = None
143
+ self.source_only = None
144
+ self.use_bzip2 = None
145
+
146
+ self.distribution_name = None
147
+ self.group = None
148
+ self.release = None
149
+ self.serial = None
150
+ self.vendor = None
151
+ self.packager = None
152
+ self.doc_files = None
153
+ self.changelog = None
154
+ self.icon = None
155
+
156
+ self.prep_script = None
157
+ self.build_script = None
158
+ self.install_script = None
159
+ self.clean_script = None
160
+ self.verify_script = None
161
+ self.pre_install = None
162
+ self.post_install = None
163
+ self.pre_uninstall = None
164
+ self.post_uninstall = None
165
+ self.prep = None
166
+ self.provides = None
167
+ self.requires = None
168
+ self.conflicts = None
169
+ self.build_requires = None
170
+ self.obsoletes = None
171
+
172
+ self.keep_temp = 0
173
+ self.use_rpm_opt_flags = 1
174
+ self.rpm3_mode = 1
175
+ self.no_autoreq = 0
176
+
177
+ self.force_arch = None
178
+ self.quiet = 0
179
+
180
+ def finalize_options(self):
181
+ self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
182
+ if self.rpm_base is None:
183
+ if not self.rpm3_mode:
184
+ raise DistutilsOptionError(
185
+ "you must specify --rpm-base in RPM 2 mode")
186
+ self.rpm_base = os.path.join(self.bdist_base, "rpm")
187
+
188
+ if self.python is None:
189
+ if self.fix_python:
190
+ self.python = sys.executable
191
+ else:
192
+ self.python = "python3"
193
+ elif self.fix_python:
194
+ raise DistutilsOptionError(
195
+ "--python and --fix-python are mutually exclusive options")
196
+
197
+ if os.name != 'posix':
198
+ raise DistutilsPlatformError("don't know how to create RPM "
199
+ "distributions on platform %s" % os.name)
200
+ if self.binary_only and self.source_only:
201
+ raise DistutilsOptionError(
202
+ "cannot supply both '--source-only' and '--binary-only'")
203
+
204
+ # don't pass CFLAGS to pure python distributions
205
+ if not self.distribution.has_ext_modules():
206
+ self.use_rpm_opt_flags = 0
207
+
208
+ self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
209
+ self.finalize_package_data()
210
+
211
+ def finalize_package_data(self):
212
+ self.ensure_string('group', "Development/Libraries")
213
+ self.ensure_string('vendor',
214
+ "%s <%s>" % (self.distribution.get_contact(),
215
+ self.distribution.get_contact_email()))
216
+ self.ensure_string('packager')
217
+ self.ensure_string_list('doc_files')
218
+ if isinstance(self.doc_files, list):
219
+ for readme in ('README', 'README.txt'):
220
+ if os.path.exists(readme) and readme not in self.doc_files:
221
+ self.doc_files.append(readme)
222
+
223
+ self.ensure_string('release', "1")
224
+ self.ensure_string('serial') # should it be an int?
225
+
226
+ self.ensure_string('distribution_name')
227
+
228
+ self.ensure_string('changelog')
229
+ # Format changelog correctly
230
+ self.changelog = self._format_changelog(self.changelog)
231
+
232
+ self.ensure_filename('icon')
233
+
234
+ self.ensure_filename('prep_script')
235
+ self.ensure_filename('build_script')
236
+ self.ensure_filename('install_script')
237
+ self.ensure_filename('clean_script')
238
+ self.ensure_filename('verify_script')
239
+ self.ensure_filename('pre_install')
240
+ self.ensure_filename('post_install')
241
+ self.ensure_filename('pre_uninstall')
242
+ self.ensure_filename('post_uninstall')
243
+
244
+ # XXX don't forget we punted on summaries and descriptions -- they
245
+ # should be handled here eventually!
246
+
247
+ # Now *this* is some meta-data that belongs in the setup script...
248
+ self.ensure_string_list('provides')
249
+ self.ensure_string_list('requires')
250
+ self.ensure_string_list('conflicts')
251
+ self.ensure_string_list('build_requires')
252
+ self.ensure_string_list('obsoletes')
253
+
254
+ self.ensure_string('force_arch')
255
+
256
+ def run(self):
257
+ if DEBUG:
258
+ print("before _get_package_data():")
259
+ print("vendor =", self.vendor)
260
+ print("packager =", self.packager)
261
+ print("doc_files =", self.doc_files)
262
+ print("changelog =", self.changelog)
263
+
264
+ # make directories
265
+ if self.spec_only:
266
+ spec_dir = self.dist_dir
267
+ self.mkpath(spec_dir)
268
+ else:
269
+ rpm_dir = {}
270
+ for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
271
+ rpm_dir[d] = os.path.join(self.rpm_base, d)
272
+ self.mkpath(rpm_dir[d])
273
+ spec_dir = rpm_dir['SPECS']
274
+
275
+ # Spec file goes into 'dist_dir' if '--spec-only specified',
276
+ # build/rpm.<plat> otherwise.
277
+ spec_path = os.path.join(spec_dir,
278
+ "%s.spec" % self.distribution.get_name())
279
+ self.execute(write_file,
280
+ (spec_path,
281
+ self._make_spec_file()),
282
+ "writing '%s'" % spec_path)
283
+
284
+ if self.spec_only: # stop if requested
285
+ return
286
+
287
+ # Make a source distribution and copy to SOURCES directory with
288
+ # optional icon.
289
+ saved_dist_files = self.distribution.dist_files[:]
290
+ sdist = self.reinitialize_command('sdist')
291
+ if self.use_bzip2:
292
+ sdist.formats = ['bztar']
293
+ else:
294
+ sdist.formats = ['gztar']
295
+ self.run_command('sdist')
296
+ self.distribution.dist_files = saved_dist_files
297
+
298
+ source = sdist.get_archive_files()[0]
299
+ source_dir = rpm_dir['SOURCES']
300
+ self.copy_file(source, source_dir)
301
+
302
+ if self.icon:
303
+ if os.path.exists(self.icon):
304
+ self.copy_file(self.icon, source_dir)
305
+ else:
306
+ raise DistutilsFileError(
307
+ "icon file '%s' does not exist" % self.icon)
308
+
309
+ # build package
310
+ log.info("building RPMs")
311
+ rpm_cmd = ['rpmbuild']
312
+
313
+ if self.source_only: # what kind of RPMs?
314
+ rpm_cmd.append('-bs')
315
+ elif self.binary_only:
316
+ rpm_cmd.append('-bb')
317
+ else:
318
+ rpm_cmd.append('-ba')
319
+ rpm_cmd.extend(['--define', '__python %s' % self.python])
320
+ if self.rpm3_mode:
321
+ rpm_cmd.extend(['--define',
322
+ '_topdir %s' % os.path.abspath(self.rpm_base)])
323
+ if not self.keep_temp:
324
+ rpm_cmd.append('--clean')
325
+
326
+ if self.quiet:
327
+ rpm_cmd.append('--quiet')
328
+
329
+ rpm_cmd.append(spec_path)
330
+ # Determine the binary rpm names that should be built out of this spec
331
+ # file
332
+ # Note that some of these may not be really built (if the file
333
+ # list is empty)
334
+ nvr_string = "%{name}-%{version}-%{release}"
335
+ src_rpm = nvr_string + ".src.rpm"
336
+ non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
337
+ q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
338
+ src_rpm, non_src_rpm, spec_path)
339
+
340
+ out = os.popen(q_cmd)
341
+ try:
342
+ binary_rpms = []
343
+ source_rpm = None
344
+ while True:
345
+ line = out.readline()
346
+ if not line:
347
+ break
348
+ l = line.strip().split()
349
+ assert(len(l) == 2)
350
+ binary_rpms.append(l[1])
351
+ # The source rpm is named after the first entry in the spec file
352
+ if source_rpm is None:
353
+ source_rpm = l[0]
354
+
355
+ status = out.close()
356
+ if status:
357
+ raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
358
+
359
+ finally:
360
+ out.close()
361
+
362
+ self.spawn(rpm_cmd)
363
+
364
+ if not self.dry_run:
365
+ if self.distribution.has_ext_modules():
366
+ pyversion = get_python_version()
367
+ else:
368
+ pyversion = 'any'
369
+
370
+ if not self.binary_only:
371
+ srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
372
+ assert(os.path.exists(srpm))
373
+ self.move_file(srpm, self.dist_dir)
374
+ filename = os.path.join(self.dist_dir, source_rpm)
375
+ self.distribution.dist_files.append(
376
+ ('bdist_rpm', pyversion, filename))
377
+
378
+ if not self.source_only:
379
+ for rpm in binary_rpms:
380
+ rpm = os.path.join(rpm_dir['RPMS'], rpm)
381
+ if os.path.exists(rpm):
382
+ self.move_file(rpm, self.dist_dir)
383
+ filename = os.path.join(self.dist_dir,
384
+ os.path.basename(rpm))
385
+ self.distribution.dist_files.append(
386
+ ('bdist_rpm', pyversion, filename))
387
+
388
+ def _dist_path(self, path):
389
+ return os.path.join(self.dist_dir, os.path.basename(path))
390
+
391
+ def _make_spec_file(self):
392
+ """Generate the text of an RPM spec file and return it as a
393
+ list of strings (one per line).
394
+ """
395
+ # definitions and headers
396
+ spec_file = [
397
+ '%define name ' + self.distribution.get_name(),
398
+ '%define version ' + self.distribution.get_version().replace('-','_'),
399
+ '%define unmangled_version ' + self.distribution.get_version(),
400
+ '%define release ' + self.release.replace('-','_'),
401
+ '',
402
+ 'Summary: ' + self.distribution.get_description(),
403
+ ]
404
+
405
+ # Workaround for #14443 which affects some RPM based systems such as
406
+ # RHEL6 (and probably derivatives)
407
+ vendor_hook = subprocess.getoutput('rpm --eval %{__os_install_post}')
408
+ # Generate a potential replacement value for __os_install_post (whilst
409
+ # normalizing the whitespace to simplify the test for whether the
410
+ # invocation of brp-python-bytecompile passes in __python):
411
+ vendor_hook = '\n'.join([' %s \\' % line.strip()
412
+ for line in vendor_hook.splitlines()])
413
+ problem = "brp-python-bytecompile \\\n"
414
+ fixed = "brp-python-bytecompile %{__python} \\\n"
415
+ fixed_hook = vendor_hook.replace(problem, fixed)
416
+ if fixed_hook != vendor_hook:
417
+ spec_file.append('# Workaround for http://bugs.python.org/issue14443')
418
+ spec_file.append('%define __os_install_post ' + fixed_hook + '\n')
419
+
420
+ # put locale summaries into spec file
421
+ # XXX not supported for now (hard to put a dictionary
422
+ # in a config file -- arg!)
423
+ #for locale in self.summaries.keys():
424
+ # spec_file.append('Summary(%s): %s' % (locale,
425
+ # self.summaries[locale]))
426
+
427
+ spec_file.extend([
428
+ 'Name: %{name}',
429
+ 'Version: %{version}',
430
+ 'Release: %{release}',])
431
+
432
+ # XXX yuck! this filename is available from the "sdist" command,
433
+ # but only after it has run: and we create the spec file before
434
+ # running "sdist", in case of --spec-only.
435
+ if self.use_bzip2:
436
+ spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2')
437
+ else:
438
+ spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')
439
+
440
+ spec_file.extend([
441
+ 'License: ' + self.distribution.get_license(),
442
+ 'Group: ' + self.group,
443
+ 'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
444
+ 'Prefix: %{_prefix}', ])
445
+
446
+ if not self.force_arch:
447
+ # noarch if no extension modules
448
+ if not self.distribution.has_ext_modules():
449
+ spec_file.append('BuildArch: noarch')
450
+ else:
451
+ spec_file.append( 'BuildArch: %s' % self.force_arch )
452
+
453
+ for field in ('Vendor',
454
+ 'Packager',
455
+ 'Provides',
456
+ 'Requires',
457
+ 'Conflicts',
458
+ 'Obsoletes',
459
+ ):
460
+ val = getattr(self, field.lower())
461
+ if isinstance(val, list):
462
+ spec_file.append('%s: %s' % (field, ' '.join(val)))
463
+ elif val is not None:
464
+ spec_file.append('%s: %s' % (field, val))
465
+
466
+
467
+ if self.distribution.get_url() != 'UNKNOWN':
468
+ spec_file.append('Url: ' + self.distribution.get_url())
469
+
470
+ if self.distribution_name:
471
+ spec_file.append('Distribution: ' + self.distribution_name)
472
+
473
+ if self.build_requires:
474
+ spec_file.append('BuildRequires: ' +
475
+ ' '.join(self.build_requires))
476
+
477
+ if self.icon:
478
+ spec_file.append('Icon: ' + os.path.basename(self.icon))
479
+
480
+ if self.no_autoreq:
481
+ spec_file.append('AutoReq: 0')
482
+
483
+ spec_file.extend([
484
+ '',
485
+ '%description',
486
+ self.distribution.get_long_description()
487
+ ])
488
+
489
+ # put locale descriptions into spec file
490
+ # XXX again, suppressed because config file syntax doesn't
491
+ # easily support this ;-(
492
+ #for locale in self.descriptions.keys():
493
+ # spec_file.extend([
494
+ # '',
495
+ # '%description -l ' + locale,
496
+ # self.descriptions[locale],
497
+ # ])
498
+
499
+ # rpm scripts
500
+ # figure out default build script
501
+ def_setup_call = "%s %s" % (self.python,os.path.basename(sys.argv[0]))
502
+ def_build = "%s build" % def_setup_call
503
+ if self.use_rpm_opt_flags:
504
+ def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
505
+
506
+ # insert contents of files
507
+
508
+ # XXX this is kind of misleading: user-supplied options are files
509
+ # that we open and interpolate into the spec file, but the defaults
510
+ # are just text that we drop in as-is. Hmmm.
511
+
512
+ install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT '
513
+ '--record=INSTALLED_FILES') % def_setup_call
514
+
515
+ script_options = [
516
+ ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"),
517
+ ('build', 'build_script', def_build),
518
+ ('install', 'install_script', install_cmd),
519
+ ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
520
+ ('verifyscript', 'verify_script', None),
521
+ ('pre', 'pre_install', None),
522
+ ('post', 'post_install', None),
523
+ ('preun', 'pre_uninstall', None),
524
+ ('postun', 'post_uninstall', None),
525
+ ]
526
+
527
+ for (rpm_opt, attr, default) in script_options:
528
+ # Insert contents of file referred to, if no file is referred to
529
+ # use 'default' as contents of script
530
+ val = getattr(self, attr)
531
+ if val or default:
532
+ spec_file.extend([
533
+ '',
534
+ '%' + rpm_opt,])
535
+ if val:
536
+ with open(val) as f:
537
+ spec_file.extend(f.read().split('\n'))
538
+ else:
539
+ spec_file.append(default)
540
+
541
+
542
+ # files section
543
+ spec_file.extend([
544
+ '',
545
+ '%files -f INSTALLED_FILES',
546
+ '%defattr(-,root,root)',
547
+ ])
548
+
549
+ if self.doc_files:
550
+ spec_file.append('%doc ' + ' '.join(self.doc_files))
551
+
552
+ if self.changelog:
553
+ spec_file.extend([
554
+ '',
555
+ '%changelog',])
556
+ spec_file.extend(self.changelog)
557
+
558
+ return spec_file
559
+
560
+ def _format_changelog(self, changelog):
561
+ """Format the changelog correctly and convert it to a list of strings
562
+ """
563
+ if not changelog:
564
+ return changelog
565
+ new_changelog = []
566
+ for line in changelog.strip().split('\n'):
567
+ line = line.strip()
568
+ if line[0] == '*':
569
+ new_changelog.extend(['', line])
570
+ elif line[0] == '-':
571
+ new_changelog.append(line)
572
+ else:
573
+ new_changelog.append(' ' + line)
574
+
575
+ # strip trailing newline inserted by first changelog entry
576
+ if not new_changelog[0]:
577
+ del new_changelog[0]
578
+
579
+ return new_changelog
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_wininst.py ADDED
@@ -0,0 +1,377 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.bdist_wininst
2
+
3
+ Implements the Distutils 'bdist_wininst' command: create a windows installer
4
+ exe-program."""
5
+
6
+ import os
7
+ import sys
8
+ import warnings
9
+ from distutils.core import Command
10
+ from distutils.util import get_platform
11
+ from distutils.dir_util import remove_tree
12
+ from distutils.errors import *
13
+ from distutils.sysconfig import get_python_version
14
+ from distutils import log
15
+
16
+ class bdist_wininst(Command):
17
+
18
+ description = "create an executable installer for MS Windows"
19
+
20
+ user_options = [('bdist-dir=', None,
21
+ "temporary directory for creating the distribution"),
22
+ ('plat-name=', 'p',
23
+ "platform name to embed in generated filenames "
24
+ "(default: %s)" % get_platform()),
25
+ ('keep-temp', 'k',
26
+ "keep the pseudo-installation tree around after " +
27
+ "creating the distribution archive"),
28
+ ('target-version=', None,
29
+ "require a specific python version" +
30
+ " on the target system"),
31
+ ('no-target-compile', 'c',
32
+ "do not compile .py to .pyc on the target system"),
33
+ ('no-target-optimize', 'o',
34
+ "do not compile .py to .pyo (optimized) "
35
+ "on the target system"),
36
+ ('dist-dir=', 'd',
37
+ "directory to put final built distributions in"),
38
+ ('bitmap=', 'b',
39
+ "bitmap to use for the installer instead of python-powered logo"),
40
+ ('title=', 't',
41
+ "title to display on the installer background instead of default"),
42
+ ('skip-build', None,
43
+ "skip rebuilding everything (for testing/debugging)"),
44
+ ('install-script=', None,
45
+ "basename of installation script to be run after "
46
+ "installation or before deinstallation"),
47
+ ('pre-install-script=', None,
48
+ "Fully qualified filename of a script to be run before "
49
+ "any files are installed. This script need not be in the "
50
+ "distribution"),
51
+ ('user-access-control=', None,
52
+ "specify Vista's UAC handling - 'none'/default=no "
53
+ "handling, 'auto'=use UAC if target Python installed for "
54
+ "all users, 'force'=always use UAC"),
55
+ ]
56
+
57
+ boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
58
+ 'skip-build']
59
+
60
+ # bpo-10945: bdist_wininst requires mbcs encoding only available on Windows
61
+ _unsupported = (sys.platform != "win32")
62
+
63
+ def __init__(self, *args, **kw):
64
+ super().__init__(*args, **kw)
65
+ warnings.warn("bdist_wininst command is deprecated since Python 3.8, "
66
+ "use bdist_wheel (wheel packages) instead",
67
+ DeprecationWarning, 2)
68
+
69
+ def initialize_options(self):
70
+ self.bdist_dir = None
71
+ self.plat_name = None
72
+ self.keep_temp = 0
73
+ self.no_target_compile = 0
74
+ self.no_target_optimize = 0
75
+ self.target_version = None
76
+ self.dist_dir = None
77
+ self.bitmap = None
78
+ self.title = None
79
+ self.skip_build = None
80
+ self.install_script = None
81
+ self.pre_install_script = None
82
+ self.user_access_control = None
83
+
84
+
85
+ def finalize_options(self):
86
+ self.set_undefined_options('bdist', ('skip_build', 'skip_build'))
87
+
88
+ if self.bdist_dir is None:
89
+ if self.skip_build and self.plat_name:
90
+ # If build is skipped and plat_name is overridden, bdist will
91
+ # not see the correct 'plat_name' - so set that up manually.
92
+ bdist = self.distribution.get_command_obj('bdist')
93
+ bdist.plat_name = self.plat_name
94
+ # next the command will be initialized using that name
95
+ bdist_base = self.get_finalized_command('bdist').bdist_base
96
+ self.bdist_dir = os.path.join(bdist_base, 'wininst')
97
+
98
+ if not self.target_version:
99
+ self.target_version = ""
100
+
101
+ if not self.skip_build and self.distribution.has_ext_modules():
102
+ short_version = get_python_version()
103
+ if self.target_version and self.target_version != short_version:
104
+ raise DistutilsOptionError(
105
+ "target version can only be %s, or the '--skip-build'" \
106
+ " option must be specified" % (short_version,))
107
+ self.target_version = short_version
108
+
109
+ self.set_undefined_options('bdist',
110
+ ('dist_dir', 'dist_dir'),
111
+ ('plat_name', 'plat_name'),
112
+ )
113
+
114
+ if self.install_script:
115
+ for script in self.distribution.scripts:
116
+ if self.install_script == os.path.basename(script):
117
+ break
118
+ else:
119
+ raise DistutilsOptionError(
120
+ "install_script '%s' not found in scripts"
121
+ % self.install_script)
122
+
123
+ def run(self):
124
+ if (sys.platform != "win32" and
125
+ (self.distribution.has_ext_modules() or
126
+ self.distribution.has_c_libraries())):
127
+ raise DistutilsPlatformError \
128
+ ("distribution contains extensions and/or C libraries; "
129
+ "must be compiled on a Windows 32 platform")
130
+
131
+ if not self.skip_build:
132
+ self.run_command('build')
133
+
134
+ install = self.reinitialize_command('install', reinit_subcommands=1)
135
+ install.root = self.bdist_dir
136
+ install.skip_build = self.skip_build
137
+ install.warn_dir = 0
138
+ install.plat_name = self.plat_name
139
+
140
+ install_lib = self.reinitialize_command('install_lib')
141
+ # we do not want to include pyc or pyo files
142
+ install_lib.compile = 0
143
+ install_lib.optimize = 0
144
+
145
+ if self.distribution.has_ext_modules():
146
+ # If we are building an installer for a Python version other
147
+ # than the one we are currently running, then we need to ensure
148
+ # our build_lib reflects the other Python version rather than ours.
149
+ # Note that for target_version!=sys.version, we must have skipped the
150
+ # build step, so there is no issue with enforcing the build of this
151
+ # version.
152
+ target_version = self.target_version
153
+ if not target_version:
154
+ assert self.skip_build, "Should have already checked this"
155
+ target_version = '%d.%d' % sys.version_info[:2]
156
+ plat_specifier = ".%s-%s" % (self.plat_name, target_version)
157
+ build = self.get_finalized_command('build')
158
+ build.build_lib = os.path.join(build.build_base,
159
+ 'lib' + plat_specifier)
160
+
161
+ # Use a custom scheme for the zip-file, because we have to decide
162
+ # at installation time which scheme to use.
163
+ for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'):
164
+ value = key.upper()
165
+ if key == 'headers':
166
+ value = value + '/Include/$dist_name'
167
+ setattr(install,
168
+ 'install_' + key,
169
+ value)
170
+
171
+ log.info("installing to %s", self.bdist_dir)
172
+ install.ensure_finalized()
173
+
174
+ # avoid warning of 'install_lib' about installing
175
+ # into a directory not in sys.path
176
+ sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB'))
177
+
178
+ install.run()
179
+
180
+ del sys.path[0]
181
+
182
+ # And make an archive relative to the root of the
183
+ # pseudo-installation tree.
184
+ from tempfile import mktemp
185
+ archive_basename = mktemp()
186
+ fullname = self.distribution.get_fullname()
187
+ arcname = self.make_archive(archive_basename, "zip",
188
+ root_dir=self.bdist_dir)
189
+ # create an exe containing the zip-file
190
+ self.create_exe(arcname, fullname, self.bitmap)
191
+ if self.distribution.has_ext_modules():
192
+ pyversion = get_python_version()
193
+ else:
194
+ pyversion = 'any'
195
+ self.distribution.dist_files.append(('bdist_wininst', pyversion,
196
+ self.get_installer_filename(fullname)))
197
+ # remove the zip-file again
198
+ log.debug("removing temporary file '%s'", arcname)
199
+ os.remove(arcname)
200
+
201
+ if not self.keep_temp:
202
+ remove_tree(self.bdist_dir, dry_run=self.dry_run)
203
+
204
+ def get_inidata(self):
205
+ # Return data describing the installation.
206
+ lines = []
207
+ metadata = self.distribution.metadata
208
+
209
+ # Write the [metadata] section.
210
+ lines.append("[metadata]")
211
+
212
+ # 'info' will be displayed in the installer's dialog box,
213
+ # describing the items to be installed.
214
+ info = (metadata.long_description or '') + '\n'
215
+
216
+ # Escape newline characters
217
+ def escape(s):
218
+ return s.replace("\n", "\\n")
219
+
220
+ for name in ["author", "author_email", "description", "maintainer",
221
+ "maintainer_email", "name", "url", "version"]:
222
+ data = getattr(metadata, name, "")
223
+ if data:
224
+ info = info + ("\n %s: %s" % \
225
+ (name.capitalize(), escape(data)))
226
+ lines.append("%s=%s" % (name, escape(data)))
227
+
228
+ # The [setup] section contains entries controlling
229
+ # the installer runtime.
230
+ lines.append("\n[Setup]")
231
+ if self.install_script:
232
+ lines.append("install_script=%s" % self.install_script)
233
+ lines.append("info=%s" % escape(info))
234
+ lines.append("target_compile=%d" % (not self.no_target_compile))
235
+ lines.append("target_optimize=%d" % (not self.no_target_optimize))
236
+ if self.target_version:
237
+ lines.append("target_version=%s" % self.target_version)
238
+ if self.user_access_control:
239
+ lines.append("user_access_control=%s" % self.user_access_control)
240
+
241
+ title = self.title or self.distribution.get_fullname()
242
+ lines.append("title=%s" % escape(title))
243
+ import time
244
+ import distutils
245
+ build_info = "Built %s with distutils-%s" % \
246
+ (time.ctime(time.time()), distutils.__version__)
247
+ lines.append("build_info=%s" % build_info)
248
+ return "\n".join(lines)
249
+
250
+ def create_exe(self, arcname, fullname, bitmap=None):
251
+ import struct
252
+
253
+ self.mkpath(self.dist_dir)
254
+
255
+ cfgdata = self.get_inidata()
256
+
257
+ installer_name = self.get_installer_filename(fullname)
258
+ self.announce("creating %s" % installer_name)
259
+
260
+ if bitmap:
261
+ with open(bitmap, "rb") as f:
262
+ bitmapdata = f.read()
263
+ bitmaplen = len(bitmapdata)
264
+ else:
265
+ bitmaplen = 0
266
+
267
+ with open(installer_name, "wb") as file:
268
+ file.write(self.get_exe_bytes())
269
+ if bitmap:
270
+ file.write(bitmapdata)
271
+
272
+ # Convert cfgdata from unicode to ascii, mbcs encoded
273
+ if isinstance(cfgdata, str):
274
+ cfgdata = cfgdata.encode("mbcs")
275
+
276
+ # Append the pre-install script
277
+ cfgdata = cfgdata + b"\0"
278
+ if self.pre_install_script:
279
+ # We need to normalize newlines, so we open in text mode and
280
+ # convert back to bytes. "latin-1" simply avoids any possible
281
+ # failures.
282
+ with open(self.pre_install_script, "r",
283
+ encoding="latin-1") as script:
284
+ script_data = script.read().encode("latin-1")
285
+ cfgdata = cfgdata + script_data + b"\n\0"
286
+ else:
287
+ # empty pre-install script
288
+ cfgdata = cfgdata + b"\0"
289
+ file.write(cfgdata)
290
+
291
+ # The 'magic number' 0x1234567B is used to make sure that the
292
+ # binary layout of 'cfgdata' is what the wininst.exe binary
293
+ # expects. If the layout changes, increment that number, make
294
+ # the corresponding changes to the wininst.exe sources, and
295
+ # recompile them.
296
+ header = struct.pack("<iii",
297
+ 0x1234567B, # tag
298
+ len(cfgdata), # length
299
+ bitmaplen, # number of bytes in bitmap
300
+ )
301
+ file.write(header)
302
+ with open(arcname, "rb") as f:
303
+ file.write(f.read())
304
+
305
+ def get_installer_filename(self, fullname):
306
+ # Factored out to allow overriding in subclasses
307
+ if self.target_version:
308
+ # if we create an installer for a specific python version,
309
+ # it's better to include this in the name
310
+ installer_name = os.path.join(self.dist_dir,
311
+ "%s.%s-py%s.exe" %
312
+ (fullname, self.plat_name, self.target_version))
313
+ else:
314
+ installer_name = os.path.join(self.dist_dir,
315
+ "%s.%s.exe" % (fullname, self.plat_name))
316
+ return installer_name
317
+
318
+ def get_exe_bytes(self):
319
+ # If a target-version other than the current version has been
320
+ # specified, then using the MSVC version from *this* build is no good.
321
+ # Without actually finding and executing the target version and parsing
322
+ # its sys.version, we just hard-code our knowledge of old versions.
323
+ # NOTE: Possible alternative is to allow "--target-version" to
324
+ # specify a Python executable rather than a simple version string.
325
+ # We can then execute this program to obtain any info we need, such
326
+ # as the real sys.version string for the build.
327
+ cur_version = get_python_version()
328
+
329
+ # If the target version is *later* than us, then we assume they
330
+ # use what we use
331
+ # string compares seem wrong, but are what sysconfig.py itself uses
332
+ if self.target_version and self.target_version < cur_version:
333
+ if self.target_version < "2.4":
334
+ bv = '6.0'
335
+ elif self.target_version == "2.4":
336
+ bv = '7.1'
337
+ elif self.target_version == "2.5":
338
+ bv = '8.0'
339
+ elif self.target_version <= "3.2":
340
+ bv = '9.0'
341
+ elif self.target_version <= "3.4":
342
+ bv = '10.0'
343
+ else:
344
+ bv = '14.0'
345
+ else:
346
+ # for current version - use authoritative check.
347
+ try:
348
+ from msvcrt import CRT_ASSEMBLY_VERSION
349
+ except ImportError:
350
+ # cross-building, so assume the latest version
351
+ bv = '14.0'
352
+ else:
353
+ # as far as we know, CRT is binary compatible based on
354
+ # the first field, so assume 'x.0' until proven otherwise
355
+ major = CRT_ASSEMBLY_VERSION.partition('.')[0]
356
+ bv = major + '.0'
357
+
358
+
359
+ # wininst-x.y.exe is in the same directory as this file
360
+ directory = os.path.dirname(__file__)
361
+ # we must use a wininst-x.y.exe built with the same C compiler
362
+ # used for python. XXX What about mingw, borland, and so on?
363
+
364
+ # if plat_name starts with "win" but is not "win32"
365
+ # we want to strip "win" and leave the rest (e.g. -amd64)
366
+ # for all other cases, we don't want any suffix
367
+ if self.plat_name != 'win32' and self.plat_name[:3] == 'win':
368
+ sfix = self.plat_name[3:]
369
+ else:
370
+ sfix = ''
371
+
372
+ filename = os.path.join(directory, "wininst-%s%s.exe" % (bv, sfix))
373
+ f = open(filename, "rb")
374
+ try:
375
+ return f.read()
376
+ finally:
377
+ f.close()
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build
2
+
3
+ Implements the Distutils 'build' command."""
4
+
5
+ import sys, os
6
+ from distutils.core import Command
7
+ from distutils.errors import DistutilsOptionError
8
+ from distutils.util import get_platform
9
+
10
+
11
+ def show_compilers():
12
+ from distutils.ccompiler import show_compilers
13
+ show_compilers()
14
+
15
+
16
+ class build(Command):
17
+
18
+ description = "build everything needed to install"
19
+
20
+ user_options = [
21
+ ('build-base=', 'b',
22
+ "base directory for build library"),
23
+ ('build-purelib=', None,
24
+ "build directory for platform-neutral distributions"),
25
+ ('build-platlib=', None,
26
+ "build directory for platform-specific distributions"),
27
+ ('build-lib=', None,
28
+ "build directory for all distribution (defaults to either " +
29
+ "build-purelib or build-platlib"),
30
+ ('build-scripts=', None,
31
+ "build directory for scripts"),
32
+ ('build-temp=', 't',
33
+ "temporary build directory"),
34
+ ('plat-name=', 'p',
35
+ "platform name to build for, if supported "
36
+ "(default: %s)" % get_platform()),
37
+ ('compiler=', 'c',
38
+ "specify the compiler type"),
39
+ ('parallel=', 'j',
40
+ "number of parallel build jobs"),
41
+ ('debug', 'g',
42
+ "compile extensions and libraries with debugging information"),
43
+ ('force', 'f',
44
+ "forcibly build everything (ignore file timestamps)"),
45
+ ('executable=', 'e',
46
+ "specify final destination interpreter path (build.py)"),
47
+ ]
48
+
49
+ boolean_options = ['debug', 'force']
50
+
51
+ help_options = [
52
+ ('help-compiler', None,
53
+ "list available compilers", show_compilers),
54
+ ]
55
+
56
+ def initialize_options(self):
57
+ self.build_base = 'build'
58
+ # these are decided only after 'build_base' has its final value
59
+ # (unless overridden by the user or client)
60
+ self.build_purelib = None
61
+ self.build_platlib = None
62
+ self.build_lib = None
63
+ self.build_temp = None
64
+ self.build_scripts = None
65
+ self.compiler = None
66
+ self.plat_name = None
67
+ self.debug = None
68
+ self.force = 0
69
+ self.executable = None
70
+ self.parallel = None
71
+
72
+ def finalize_options(self):
73
+ if self.plat_name is None:
74
+ self.plat_name = get_platform()
75
+ else:
76
+ # plat-name only supported for windows (other platforms are
77
+ # supported via ./configure flags, if at all). Avoid misleading
78
+ # other platforms.
79
+ if os.name != 'nt':
80
+ raise DistutilsOptionError(
81
+ "--plat-name only supported on Windows (try "
82
+ "using './configure --help' on your platform)")
83
+
84
+ plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
85
+
86
+ # Make it so Python 2.x and Python 2.x with --with-pydebug don't
87
+ # share the same build directories. Doing so confuses the build
88
+ # process for C modules
89
+ if hasattr(sys, 'gettotalrefcount'):
90
+ plat_specifier += '-pydebug'
91
+
92
+ # 'build_purelib' and 'build_platlib' just default to 'lib' and
93
+ # 'lib.<plat>' under the base build directory. We only use one of
94
+ # them for a given distribution, though --
95
+ if self.build_purelib is None:
96
+ self.build_purelib = os.path.join(self.build_base, 'lib')
97
+ if self.build_platlib is None:
98
+ self.build_platlib = os.path.join(self.build_base,
99
+ 'lib' + plat_specifier)
100
+
101
+ # 'build_lib' is the actual directory that we will use for this
102
+ # particular module distribution -- if user didn't supply it, pick
103
+ # one of 'build_purelib' or 'build_platlib'.
104
+ if self.build_lib is None:
105
+ if self.distribution.has_ext_modules():
106
+ self.build_lib = self.build_platlib
107
+ else:
108
+ self.build_lib = self.build_purelib
109
+
110
+ # 'build_temp' -- temporary directory for compiler turds,
111
+ # "build/temp.<plat>"
112
+ if self.build_temp is None:
113
+ self.build_temp = os.path.join(self.build_base,
114
+ 'temp' + plat_specifier)
115
+ if self.build_scripts is None:
116
+ self.build_scripts = os.path.join(self.build_base,
117
+ 'scripts-%d.%d' % sys.version_info[:2])
118
+
119
+ if self.executable is None and sys.executable:
120
+ self.executable = os.path.normpath(sys.executable)
121
+
122
+ if isinstance(self.parallel, str):
123
+ try:
124
+ self.parallel = int(self.parallel)
125
+ except ValueError:
126
+ raise DistutilsOptionError("parallel should be an integer")
127
+
128
+ def run(self):
129
+ # Run all relevant sub-commands. This will be some subset of:
130
+ # - build_py - pure Python modules
131
+ # - build_clib - standalone C libraries
132
+ # - build_ext - Python extensions
133
+ # - build_scripts - (Python) scripts
134
+ for cmd_name in self.get_sub_commands():
135
+ self.run_command(cmd_name)
136
+
137
+
138
+ # -- Predicates for the sub-command list ---------------------------
139
+
140
+ def has_pure_modules(self):
141
+ return self.distribution.has_pure_modules()
142
+
143
+ def has_c_libraries(self):
144
+ return self.distribution.has_c_libraries()
145
+
146
+ def has_ext_modules(self):
147
+ return self.distribution.has_ext_modules()
148
+
149
+ def has_scripts(self):
150
+ return self.distribution.has_scripts()
151
+
152
+
153
+ sub_commands = [('build_py', has_pure_modules),
154
+ ('build_clib', has_c_libraries),
155
+ ('build_ext', has_ext_modules),
156
+ ('build_scripts', has_scripts),
157
+ ]
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_clib.py ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_clib
2
+
3
+ Implements the Distutils 'build_clib' command, to build a C/C++ library
4
+ that is included in the module distribution and needed by an extension
5
+ module."""
6
+
7
+
8
+ # XXX this module has *lots* of code ripped-off quite transparently from
9
+ # build_ext.py -- not surprisingly really, as the work required to build
10
+ # a static library from a collection of C source files is not really all
11
+ # that different from what's required to build a shared object file from
12
+ # a collection of C source files. Nevertheless, I haven't done the
13
+ # necessary refactoring to account for the overlap in code between the
14
+ # two modules, mainly because a number of subtle details changed in the
15
+ # cut 'n paste. Sigh.
16
+
17
+ import os
18
+ from distutils.core import Command
19
+ from distutils.errors import *
20
+ from distutils.sysconfig import customize_compiler
21
+ from distutils import log
22
+
23
+ def show_compilers():
24
+ from distutils.ccompiler import show_compilers
25
+ show_compilers()
26
+
27
+
28
+ class build_clib(Command):
29
+
30
+ description = "build C/C++ libraries used by Python extensions"
31
+
32
+ user_options = [
33
+ ('build-clib=', 'b',
34
+ "directory to build C/C++ libraries to"),
35
+ ('build-temp=', 't',
36
+ "directory to put temporary build by-products"),
37
+ ('debug', 'g',
38
+ "compile with debugging information"),
39
+ ('force', 'f',
40
+ "forcibly build everything (ignore file timestamps)"),
41
+ ('compiler=', 'c',
42
+ "specify the compiler type"),
43
+ ]
44
+
45
+ boolean_options = ['debug', 'force']
46
+
47
+ help_options = [
48
+ ('help-compiler', None,
49
+ "list available compilers", show_compilers),
50
+ ]
51
+
52
+ def initialize_options(self):
53
+ self.build_clib = None
54
+ self.build_temp = None
55
+
56
+ # List of libraries to build
57
+ self.libraries = None
58
+
59
+ # Compilation options for all libraries
60
+ self.include_dirs = None
61
+ self.define = None
62
+ self.undef = None
63
+ self.debug = None
64
+ self.force = 0
65
+ self.compiler = None
66
+
67
+
68
+ def finalize_options(self):
69
+ # This might be confusing: both build-clib and build-temp default
70
+ # to build-temp as defined by the "build" command. This is because
71
+ # I think that C libraries are really just temporary build
72
+ # by-products, at least from the point of view of building Python
73
+ # extensions -- but I want to keep my options open.
74
+ self.set_undefined_options('build',
75
+ ('build_temp', 'build_clib'),
76
+ ('build_temp', 'build_temp'),
77
+ ('compiler', 'compiler'),
78
+ ('debug', 'debug'),
79
+ ('force', 'force'))
80
+
81
+ self.libraries = self.distribution.libraries
82
+ if self.libraries:
83
+ self.check_library_list(self.libraries)
84
+
85
+ if self.include_dirs is None:
86
+ self.include_dirs = self.distribution.include_dirs or []
87
+ if isinstance(self.include_dirs, str):
88
+ self.include_dirs = self.include_dirs.split(os.pathsep)
89
+
90
+ # XXX same as for build_ext -- what about 'self.define' and
91
+ # 'self.undef' ?
92
+
93
+
94
+ def run(self):
95
+ if not self.libraries:
96
+ return
97
+
98
+ # Yech -- this is cut 'n pasted from build_ext.py!
99
+ from distutils.ccompiler import new_compiler
100
+ self.compiler = new_compiler(compiler=self.compiler,
101
+ dry_run=self.dry_run,
102
+ force=self.force)
103
+ customize_compiler(self.compiler)
104
+
105
+ if self.include_dirs is not None:
106
+ self.compiler.set_include_dirs(self.include_dirs)
107
+ if self.define is not None:
108
+ # 'define' option is a list of (name,value) tuples
109
+ for (name,value) in self.define:
110
+ self.compiler.define_macro(name, value)
111
+ if self.undef is not None:
112
+ for macro in self.undef:
113
+ self.compiler.undefine_macro(macro)
114
+
115
+ self.build_libraries(self.libraries)
116
+
117
+
118
+ def check_library_list(self, libraries):
119
+ """Ensure that the list of libraries is valid.
120
+
121
+ `library` is presumably provided as a command option 'libraries'.
122
+ This method checks that it is a list of 2-tuples, where the tuples
123
+ are (library_name, build_info_dict).
124
+
125
+ Raise DistutilsSetupError if the structure is invalid anywhere;
126
+ just returns otherwise.
127
+ """
128
+ if not isinstance(libraries, list):
129
+ raise DistutilsSetupError(
130
+ "'libraries' option must be a list of tuples")
131
+
132
+ for lib in libraries:
133
+ if not isinstance(lib, tuple) and len(lib) != 2:
134
+ raise DistutilsSetupError(
135
+ "each element of 'libraries' must a 2-tuple")
136
+
137
+ name, build_info = lib
138
+
139
+ if not isinstance(name, str):
140
+ raise DistutilsSetupError(
141
+ "first element of each tuple in 'libraries' "
142
+ "must be a string (the library name)")
143
+
144
+ if '/' in name or (os.sep != '/' and os.sep in name):
145
+ raise DistutilsSetupError("bad library name '%s': "
146
+ "may not contain directory separators" % lib[0])
147
+
148
+ if not isinstance(build_info, dict):
149
+ raise DistutilsSetupError(
150
+ "second element of each tuple in 'libraries' "
151
+ "must be a dictionary (build info)")
152
+
153
+
154
+ def get_library_names(self):
155
+ # Assume the library list is valid -- 'check_library_list()' is
156
+ # called from 'finalize_options()', so it should be!
157
+ if not self.libraries:
158
+ return None
159
+
160
+ lib_names = []
161
+ for (lib_name, build_info) in self.libraries:
162
+ lib_names.append(lib_name)
163
+ return lib_names
164
+
165
+
166
+ def get_source_files(self):
167
+ self.check_library_list(self.libraries)
168
+ filenames = []
169
+ for (lib_name, build_info) in self.libraries:
170
+ sources = build_info.get('sources')
171
+ if sources is None or not isinstance(sources, (list, tuple)):
172
+ raise DistutilsSetupError(
173
+ "in 'libraries' option (library '%s'), "
174
+ "'sources' must be present and must be "
175
+ "a list of source filenames" % lib_name)
176
+
177
+ filenames.extend(sources)
178
+ return filenames
179
+
180
+
181
+ def build_libraries(self, libraries):
182
+ for (lib_name, build_info) in libraries:
183
+ sources = build_info.get('sources')
184
+ if sources is None or not isinstance(sources, (list, tuple)):
185
+ raise DistutilsSetupError(
186
+ "in 'libraries' option (library '%s'), "
187
+ "'sources' must be present and must be "
188
+ "a list of source filenames" % lib_name)
189
+ sources = list(sources)
190
+
191
+ log.info("building '%s' library", lib_name)
192
+
193
+ # First, compile the source code to object files in the library
194
+ # directory. (This should probably change to putting object
195
+ # files in a temporary build directory.)
196
+ macros = build_info.get('macros')
197
+ include_dirs = build_info.get('include_dirs')
198
+ objects = self.compiler.compile(sources,
199
+ output_dir=self.build_temp,
200
+ macros=macros,
201
+ include_dirs=include_dirs,
202
+ debug=self.debug)
203
+
204
+ # Now "link" the object files together into a static library.
205
+ # (On Unix at least, this isn't really linking -- it just
206
+ # builds an archive. Whatever.)
207
+ self.compiler.create_static_lib(objects, lib_name,
208
+ output_dir=self.build_clib,
209
+ debug=self.debug)
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py ADDED
@@ -0,0 +1,755 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_ext
2
+
3
+ Implements the Distutils 'build_ext' command, for building extension
4
+ modules (currently limited to C extensions, should accommodate C++
5
+ extensions ASAP)."""
6
+
7
+ import contextlib
8
+ import os
9
+ import re
10
+ import sys
11
+ from distutils.core import Command
12
+ from distutils.errors import *
13
+ from distutils.sysconfig import customize_compiler, get_python_version
14
+ from distutils.sysconfig import get_config_h_filename
15
+ from distutils.dep_util import newer_group
16
+ from distutils.extension import Extension
17
+ from distutils.util import get_platform
18
+ from distutils import log
19
+ from . import py37compat
20
+
21
+ from site import USER_BASE
22
+
23
+ # An extension name is just a dot-separated list of Python NAMEs (ie.
24
+ # the same as a fully-qualified module name).
25
+ extension_name_re = re.compile \
26
+ (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
27
+
28
+
29
+ def show_compilers ():
30
+ from distutils.ccompiler import show_compilers
31
+ show_compilers()
32
+
33
+
34
+ class build_ext(Command):
35
+
36
+ description = "build C/C++ extensions (compile/link to build directory)"
37
+
38
+ # XXX thoughts on how to deal with complex command-line options like
39
+ # these, i.e. how to make it so fancy_getopt can suck them off the
40
+ # command line and make it look like setup.py defined the appropriate
41
+ # lists of tuples of what-have-you.
42
+ # - each command needs a callback to process its command-line options
43
+ # - Command.__init__() needs access to its share of the whole
44
+ # command line (must ultimately come from
45
+ # Distribution.parse_command_line())
46
+ # - it then calls the current command class' option-parsing
47
+ # callback to deal with weird options like -D, which have to
48
+ # parse the option text and churn out some custom data
49
+ # structure
50
+ # - that data structure (in this case, a list of 2-tuples)
51
+ # will then be present in the command object by the time
52
+ # we get to finalize_options() (i.e. the constructor
53
+ # takes care of both command-line and client options
54
+ # in between initialize_options() and finalize_options())
55
+
56
+ sep_by = " (separated by '%s')" % os.pathsep
57
+ user_options = [
58
+ ('build-lib=', 'b',
59
+ "directory for compiled extension modules"),
60
+ ('build-temp=', 't',
61
+ "directory for temporary files (build by-products)"),
62
+ ('plat-name=', 'p',
63
+ "platform name to cross-compile for, if supported "
64
+ "(default: %s)" % get_platform()),
65
+ ('inplace', 'i',
66
+ "ignore build-lib and put compiled extensions into the source " +
67
+ "directory alongside your pure Python modules"),
68
+ ('include-dirs=', 'I',
69
+ "list of directories to search for header files" + sep_by),
70
+ ('define=', 'D',
71
+ "C preprocessor macros to define"),
72
+ ('undef=', 'U',
73
+ "C preprocessor macros to undefine"),
74
+ ('libraries=', 'l',
75
+ "external C libraries to link with"),
76
+ ('library-dirs=', 'L',
77
+ "directories to search for external C libraries" + sep_by),
78
+ ('rpath=', 'R',
79
+ "directories to search for shared C libraries at runtime"),
80
+ ('link-objects=', 'O',
81
+ "extra explicit link objects to include in the link"),
82
+ ('debug', 'g',
83
+ "compile/link with debugging information"),
84
+ ('force', 'f',
85
+ "forcibly build everything (ignore file timestamps)"),
86
+ ('compiler=', 'c',
87
+ "specify the compiler type"),
88
+ ('parallel=', 'j',
89
+ "number of parallel build jobs"),
90
+ ('swig-cpp', None,
91
+ "make SWIG create C++ files (default is C)"),
92
+ ('swig-opts=', None,
93
+ "list of SWIG command line options"),
94
+ ('swig=', None,
95
+ "path to the SWIG executable"),
96
+ ('user', None,
97
+ "add user include, library and rpath")
98
+ ]
99
+
100
+ boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user']
101
+
102
+ help_options = [
103
+ ('help-compiler', None,
104
+ "list available compilers", show_compilers),
105
+ ]
106
+
107
+ def initialize_options(self):
108
+ self.extensions = None
109
+ self.build_lib = None
110
+ self.plat_name = None
111
+ self.build_temp = None
112
+ self.inplace = 0
113
+ self.package = None
114
+
115
+ self.include_dirs = None
116
+ self.define = None
117
+ self.undef = None
118
+ self.libraries = None
119
+ self.library_dirs = None
120
+ self.rpath = None
121
+ self.link_objects = None
122
+ self.debug = None
123
+ self.force = None
124
+ self.compiler = None
125
+ self.swig = None
126
+ self.swig_cpp = None
127
+ self.swig_opts = None
128
+ self.user = None
129
+ self.parallel = None
130
+
131
+ def finalize_options(self):
132
+ from distutils import sysconfig
133
+
134
+ self.set_undefined_options('build',
135
+ ('build_lib', 'build_lib'),
136
+ ('build_temp', 'build_temp'),
137
+ ('compiler', 'compiler'),
138
+ ('debug', 'debug'),
139
+ ('force', 'force'),
140
+ ('parallel', 'parallel'),
141
+ ('plat_name', 'plat_name'),
142
+ )
143
+
144
+ if self.package is None:
145
+ self.package = self.distribution.ext_package
146
+
147
+ self.extensions = self.distribution.ext_modules
148
+
149
+ # Make sure Python's include directories (for Python.h, pyconfig.h,
150
+ # etc.) are in the include search path.
151
+ py_include = sysconfig.get_python_inc()
152
+ plat_py_include = sysconfig.get_python_inc(plat_specific=1)
153
+ if self.include_dirs is None:
154
+ self.include_dirs = self.distribution.include_dirs or []
155
+ if isinstance(self.include_dirs, str):
156
+ self.include_dirs = self.include_dirs.split(os.pathsep)
157
+
158
+ # If in a virtualenv, add its include directory
159
+ # Issue 16116
160
+ if sys.exec_prefix != sys.base_exec_prefix:
161
+ self.include_dirs.append(os.path.join(sys.exec_prefix, 'include'))
162
+
163
+ # Put the Python "system" include dir at the end, so that
164
+ # any local include dirs take precedence.
165
+ self.include_dirs.extend(py_include.split(os.path.pathsep))
166
+ if plat_py_include != py_include:
167
+ self.include_dirs.extend(
168
+ plat_py_include.split(os.path.pathsep))
169
+
170
+ self.ensure_string_list('libraries')
171
+ self.ensure_string_list('link_objects')
172
+
173
+ # Life is easier if we're not forever checking for None, so
174
+ # simplify these options to empty lists if unset
175
+ if self.libraries is None:
176
+ self.libraries = []
177
+ if self.library_dirs is None:
178
+ self.library_dirs = []
179
+ elif isinstance(self.library_dirs, str):
180
+ self.library_dirs = self.library_dirs.split(os.pathsep)
181
+
182
+ if self.rpath is None:
183
+ self.rpath = []
184
+ elif isinstance(self.rpath, str):
185
+ self.rpath = self.rpath.split(os.pathsep)
186
+
187
+ # for extensions under windows use different directories
188
+ # for Release and Debug builds.
189
+ # also Python's library directory must be appended to library_dirs
190
+ if os.name == 'nt':
191
+ # the 'libs' directory is for binary installs - we assume that
192
+ # must be the *native* platform. But we don't really support
193
+ # cross-compiling via a binary install anyway, so we let it go.
194
+ self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
195
+ if sys.base_exec_prefix != sys.prefix: # Issue 16116
196
+ self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
197
+ if self.debug:
198
+ self.build_temp = os.path.join(self.build_temp, "Debug")
199
+ else:
200
+ self.build_temp = os.path.join(self.build_temp, "Release")
201
+
202
+ # Append the source distribution include and library directories,
203
+ # this allows distutils on windows to work in the source tree
204
+ self.include_dirs.append(os.path.dirname(get_config_h_filename()))
205
+ self.library_dirs.append(sys.base_exec_prefix)
206
+
207
+ # Use the .lib files for the correct architecture
208
+ if self.plat_name == 'win32':
209
+ suffix = 'win32'
210
+ else:
211
+ # win-amd64
212
+ suffix = self.plat_name[4:]
213
+ new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
214
+ if suffix:
215
+ new_lib = os.path.join(new_lib, suffix)
216
+ self.library_dirs.append(new_lib)
217
+
218
+ # For extensions under Cygwin, Python's library directory must be
219
+ # appended to library_dirs
220
+ if sys.platform[:6] == 'cygwin':
221
+ if not sysconfig.python_build:
222
+ # building third party extensions
223
+ self.library_dirs.append(os.path.join(sys.prefix, "lib",
224
+ "python" + get_python_version(),
225
+ "config"))
226
+ else:
227
+ # building python standard extensions
228
+ self.library_dirs.append('.')
229
+
230
+ # For building extensions with a shared Python library,
231
+ # Python's library directory must be appended to library_dirs
232
+ # See Issues: #1600860, #4366
233
+ if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
234
+ if not sysconfig.python_build:
235
+ # building third party extensions
236
+ self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
237
+ else:
238
+ # building python standard extensions
239
+ self.library_dirs.append('.')
240
+
241
+ # The argument parsing will result in self.define being a string, but
242
+ # it has to be a list of 2-tuples. All the preprocessor symbols
243
+ # specified by the 'define' option will be set to '1'. Multiple
244
+ # symbols can be separated with commas.
245
+
246
+ if self.define:
247
+ defines = self.define.split(',')
248
+ self.define = [(symbol, '1') for symbol in defines]
249
+
250
+ # The option for macros to undefine is also a string from the
251
+ # option parsing, but has to be a list. Multiple symbols can also
252
+ # be separated with commas here.
253
+ if self.undef:
254
+ self.undef = self.undef.split(',')
255
+
256
+ if self.swig_opts is None:
257
+ self.swig_opts = []
258
+ else:
259
+ self.swig_opts = self.swig_opts.split(' ')
260
+
261
+ # Finally add the user include and library directories if requested
262
+ if self.user:
263
+ user_include = os.path.join(USER_BASE, "include")
264
+ user_lib = os.path.join(USER_BASE, "lib")
265
+ if os.path.isdir(user_include):
266
+ self.include_dirs.append(user_include)
267
+ if os.path.isdir(user_lib):
268
+ self.library_dirs.append(user_lib)
269
+ self.rpath.append(user_lib)
270
+
271
+ if isinstance(self.parallel, str):
272
+ try:
273
+ self.parallel = int(self.parallel)
274
+ except ValueError:
275
+ raise DistutilsOptionError("parallel should be an integer")
276
+
277
+ def run(self):
278
+ from distutils.ccompiler import new_compiler
279
+
280
+ # 'self.extensions', as supplied by setup.py, is a list of
281
+ # Extension instances. See the documentation for Extension (in
282
+ # distutils.extension) for details.
283
+ #
284
+ # For backwards compatibility with Distutils 0.8.2 and earlier, we
285
+ # also allow the 'extensions' list to be a list of tuples:
286
+ # (ext_name, build_info)
287
+ # where build_info is a dictionary containing everything that
288
+ # Extension instances do except the name, with a few things being
289
+ # differently named. We convert these 2-tuples to Extension
290
+ # instances as needed.
291
+
292
+ if not self.extensions:
293
+ return
294
+
295
+ # If we were asked to build any C/C++ libraries, make sure that the
296
+ # directory where we put them is in the library search path for
297
+ # linking extensions.
298
+ if self.distribution.has_c_libraries():
299
+ build_clib = self.get_finalized_command('build_clib')
300
+ self.libraries.extend(build_clib.get_library_names() or [])
301
+ self.library_dirs.append(build_clib.build_clib)
302
+
303
+ # Setup the CCompiler object that we'll use to do all the
304
+ # compiling and linking
305
+ self.compiler = new_compiler(compiler=self.compiler,
306
+ verbose=self.verbose,
307
+ dry_run=self.dry_run,
308
+ force=self.force)
309
+ customize_compiler(self.compiler)
310
+ # If we are cross-compiling, init the compiler now (if we are not
311
+ # cross-compiling, init would not hurt, but people may rely on
312
+ # late initialization of compiler even if they shouldn't...)
313
+ if os.name == 'nt' and self.plat_name != get_platform():
314
+ self.compiler.initialize(self.plat_name)
315
+
316
+ # And make sure that any compile/link-related options (which might
317
+ # come from the command-line or from the setup script) are set in
318
+ # that CCompiler object -- that way, they automatically apply to
319
+ # all compiling and linking done here.
320
+ if self.include_dirs is not None:
321
+ self.compiler.set_include_dirs(self.include_dirs)
322
+ if self.define is not None:
323
+ # 'define' option is a list of (name,value) tuples
324
+ for (name, value) in self.define:
325
+ self.compiler.define_macro(name, value)
326
+ if self.undef is not None:
327
+ for macro in self.undef:
328
+ self.compiler.undefine_macro(macro)
329
+ if self.libraries is not None:
330
+ self.compiler.set_libraries(self.libraries)
331
+ if self.library_dirs is not None:
332
+ self.compiler.set_library_dirs(self.library_dirs)
333
+ if self.rpath is not None:
334
+ self.compiler.set_runtime_library_dirs(self.rpath)
335
+ if self.link_objects is not None:
336
+ self.compiler.set_link_objects(self.link_objects)
337
+
338
+ # Now actually compile and link everything.
339
+ self.build_extensions()
340
+
341
+ def check_extensions_list(self, extensions):
342
+ """Ensure that the list of extensions (presumably provided as a
343
+ command option 'extensions') is valid, i.e. it is a list of
344
+ Extension objects. We also support the old-style list of 2-tuples,
345
+ where the tuples are (ext_name, build_info), which are converted to
346
+ Extension instances here.
347
+
348
+ Raise DistutilsSetupError if the structure is invalid anywhere;
349
+ just returns otherwise.
350
+ """
351
+ if not isinstance(extensions, list):
352
+ raise DistutilsSetupError(
353
+ "'ext_modules' option must be a list of Extension instances")
354
+
355
+ for i, ext in enumerate(extensions):
356
+ if isinstance(ext, Extension):
357
+ continue # OK! (assume type-checking done
358
+ # by Extension constructor)
359
+
360
+ if not isinstance(ext, tuple) or len(ext) != 2:
361
+ raise DistutilsSetupError(
362
+ "each element of 'ext_modules' option must be an "
363
+ "Extension instance or 2-tuple")
364
+
365
+ ext_name, build_info = ext
366
+
367
+ log.warn("old-style (ext_name, build_info) tuple found in "
368
+ "ext_modules for extension '%s' "
369
+ "-- please convert to Extension instance", ext_name)
370
+
371
+ if not (isinstance(ext_name, str) and
372
+ extension_name_re.match(ext_name)):
373
+ raise DistutilsSetupError(
374
+ "first element of each tuple in 'ext_modules' "
375
+ "must be the extension name (a string)")
376
+
377
+ if not isinstance(build_info, dict):
378
+ raise DistutilsSetupError(
379
+ "second element of each tuple in 'ext_modules' "
380
+ "must be a dictionary (build info)")
381
+
382
+ # OK, the (ext_name, build_info) dict is type-safe: convert it
383
+ # to an Extension instance.
384
+ ext = Extension(ext_name, build_info['sources'])
385
+
386
+ # Easy stuff: one-to-one mapping from dict elements to
387
+ # instance attributes.
388
+ for key in ('include_dirs', 'library_dirs', 'libraries',
389
+ 'extra_objects', 'extra_compile_args',
390
+ 'extra_link_args'):
391
+ val = build_info.get(key)
392
+ if val is not None:
393
+ setattr(ext, key, val)
394
+
395
+ # Medium-easy stuff: same syntax/semantics, different names.
396
+ ext.runtime_library_dirs = build_info.get('rpath')
397
+ if 'def_file' in build_info:
398
+ log.warn("'def_file' element of build info dict "
399
+ "no longer supported")
400
+
401
+ # Non-trivial stuff: 'macros' split into 'define_macros'
402
+ # and 'undef_macros'.
403
+ macros = build_info.get('macros')
404
+ if macros:
405
+ ext.define_macros = []
406
+ ext.undef_macros = []
407
+ for macro in macros:
408
+ if not (isinstance(macro, tuple) and len(macro) in (1, 2)):
409
+ raise DistutilsSetupError(
410
+ "'macros' element of build info dict "
411
+ "must be 1- or 2-tuple")
412
+ if len(macro) == 1:
413
+ ext.undef_macros.append(macro[0])
414
+ elif len(macro) == 2:
415
+ ext.define_macros.append(macro)
416
+
417
+ extensions[i] = ext
418
+
419
+ def get_source_files(self):
420
+ self.check_extensions_list(self.extensions)
421
+ filenames = []
422
+
423
+ # Wouldn't it be neat if we knew the names of header files too...
424
+ for ext in self.extensions:
425
+ filenames.extend(ext.sources)
426
+ return filenames
427
+
428
+ def get_outputs(self):
429
+ # Sanity check the 'extensions' list -- can't assume this is being
430
+ # done in the same run as a 'build_extensions()' call (in fact, we
431
+ # can probably assume that it *isn't*!).
432
+ self.check_extensions_list(self.extensions)
433
+
434
+ # And build the list of output (built) filenames. Note that this
435
+ # ignores the 'inplace' flag, and assumes everything goes in the
436
+ # "build" tree.
437
+ outputs = []
438
+ for ext in self.extensions:
439
+ outputs.append(self.get_ext_fullpath(ext.name))
440
+ return outputs
441
+
442
+ def build_extensions(self):
443
+ # First, sanity-check the 'extensions' list
444
+ self.check_extensions_list(self.extensions)
445
+ if self.parallel:
446
+ self._build_extensions_parallel()
447
+ else:
448
+ self._build_extensions_serial()
449
+
450
+ def _build_extensions_parallel(self):
451
+ workers = self.parallel
452
+ if self.parallel is True:
453
+ workers = os.cpu_count() # may return None
454
+ try:
455
+ from concurrent.futures import ThreadPoolExecutor
456
+ except ImportError:
457
+ workers = None
458
+
459
+ if workers is None:
460
+ self._build_extensions_serial()
461
+ return
462
+
463
+ with ThreadPoolExecutor(max_workers=workers) as executor:
464
+ futures = [executor.submit(self.build_extension, ext)
465
+ for ext in self.extensions]
466
+ for ext, fut in zip(self.extensions, futures):
467
+ with self._filter_build_errors(ext):
468
+ fut.result()
469
+
470
+ def _build_extensions_serial(self):
471
+ for ext in self.extensions:
472
+ with self._filter_build_errors(ext):
473
+ self.build_extension(ext)
474
+
475
+ @contextlib.contextmanager
476
+ def _filter_build_errors(self, ext):
477
+ try:
478
+ yield
479
+ except (CCompilerError, DistutilsError, CompileError) as e:
480
+ if not ext.optional:
481
+ raise
482
+ self.warn('building extension "%s" failed: %s' %
483
+ (ext.name, e))
484
+
485
+ def build_extension(self, ext):
486
+ sources = ext.sources
487
+ if sources is None or not isinstance(sources, (list, tuple)):
488
+ raise DistutilsSetupError(
489
+ "in 'ext_modules' option (extension '%s'), "
490
+ "'sources' must be present and must be "
491
+ "a list of source filenames" % ext.name)
492
+ # sort to make the resulting .so file build reproducible
493
+ sources = sorted(sources)
494
+
495
+ ext_path = self.get_ext_fullpath(ext.name)
496
+ depends = sources + ext.depends
497
+ if not (self.force or newer_group(depends, ext_path, 'newer')):
498
+ log.debug("skipping '%s' extension (up-to-date)", ext.name)
499
+ return
500
+ else:
501
+ log.info("building '%s' extension", ext.name)
502
+
503
+ # First, scan the sources for SWIG definition files (.i), run
504
+ # SWIG on 'em to create .c files, and modify the sources list
505
+ # accordingly.
506
+ sources = self.swig_sources(sources, ext)
507
+
508
+ # Next, compile the source code to object files.
509
+
510
+ # XXX not honouring 'define_macros' or 'undef_macros' -- the
511
+ # CCompiler API needs to change to accommodate this, and I
512
+ # want to do one thing at a time!
513
+
514
+ # Two possible sources for extra compiler arguments:
515
+ # - 'extra_compile_args' in Extension object
516
+ # - CFLAGS environment variable (not particularly
517
+ # elegant, but people seem to expect it and I
518
+ # guess it's useful)
519
+ # The environment variable should take precedence, and
520
+ # any sensible compiler will give precedence to later
521
+ # command line args. Hence we combine them in order:
522
+ extra_args = ext.extra_compile_args or []
523
+
524
+ macros = ext.define_macros[:]
525
+ for undef in ext.undef_macros:
526
+ macros.append((undef,))
527
+
528
+ objects = self.compiler.compile(sources,
529
+ output_dir=self.build_temp,
530
+ macros=macros,
531
+ include_dirs=ext.include_dirs,
532
+ debug=self.debug,
533
+ extra_postargs=extra_args,
534
+ depends=ext.depends)
535
+
536
+ # XXX outdated variable, kept here in case third-part code
537
+ # needs it.
538
+ self._built_objects = objects[:]
539
+
540
+ # Now link the object files together into a "shared object" --
541
+ # of course, first we have to figure out all the other things
542
+ # that go into the mix.
543
+ if ext.extra_objects:
544
+ objects.extend(ext.extra_objects)
545
+ extra_args = ext.extra_link_args or []
546
+
547
+ # Detect target language, if not provided
548
+ language = ext.language or self.compiler.detect_language(sources)
549
+
550
+ self.compiler.link_shared_object(
551
+ objects, ext_path,
552
+ libraries=self.get_libraries(ext),
553
+ library_dirs=ext.library_dirs,
554
+ runtime_library_dirs=ext.runtime_library_dirs,
555
+ extra_postargs=extra_args,
556
+ export_symbols=self.get_export_symbols(ext),
557
+ debug=self.debug,
558
+ build_temp=self.build_temp,
559
+ target_lang=language)
560
+
561
+ def swig_sources(self, sources, extension):
562
+ """Walk the list of source files in 'sources', looking for SWIG
563
+ interface (.i) files. Run SWIG on all that are found, and
564
+ return a modified 'sources' list with SWIG source files replaced
565
+ by the generated C (or C++) files.
566
+ """
567
+ new_sources = []
568
+ swig_sources = []
569
+ swig_targets = {}
570
+
571
+ # XXX this drops generated C/C++ files into the source tree, which
572
+ # is fine for developers who want to distribute the generated
573
+ # source -- but there should be an option to put SWIG output in
574
+ # the temp dir.
575
+
576
+ if self.swig_cpp:
577
+ log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
578
+
579
+ if self.swig_cpp or ('-c++' in self.swig_opts) or \
580
+ ('-c++' in extension.swig_opts):
581
+ target_ext = '.cpp'
582
+ else:
583
+ target_ext = '.c'
584
+
585
+ for source in sources:
586
+ (base, ext) = os.path.splitext(source)
587
+ if ext == ".i": # SWIG interface file
588
+ new_sources.append(base + '_wrap' + target_ext)
589
+ swig_sources.append(source)
590
+ swig_targets[source] = new_sources[-1]
591
+ else:
592
+ new_sources.append(source)
593
+
594
+ if not swig_sources:
595
+ return new_sources
596
+
597
+ swig = self.swig or self.find_swig()
598
+ swig_cmd = [swig, "-python"]
599
+ swig_cmd.extend(self.swig_opts)
600
+ if self.swig_cpp:
601
+ swig_cmd.append("-c++")
602
+
603
+ # Do not override commandline arguments
604
+ if not self.swig_opts:
605
+ for o in extension.swig_opts:
606
+ swig_cmd.append(o)
607
+
608
+ for source in swig_sources:
609
+ target = swig_targets[source]
610
+ log.info("swigging %s to %s", source, target)
611
+ self.spawn(swig_cmd + ["-o", target, source])
612
+
613
+ return new_sources
614
+
615
+ def find_swig(self):
616
+ """Return the name of the SWIG executable. On Unix, this is
617
+ just "swig" -- it should be in the PATH. Tries a bit harder on
618
+ Windows.
619
+ """
620
+ if os.name == "posix":
621
+ return "swig"
622
+ elif os.name == "nt":
623
+ # Look for SWIG in its standard installation directory on
624
+ # Windows (or so I presume!). If we find it there, great;
625
+ # if not, act like Unix and assume it's in the PATH.
626
+ for vers in ("1.3", "1.2", "1.1"):
627
+ fn = os.path.join("c:\\swig%s" % vers, "swig.exe")
628
+ if os.path.isfile(fn):
629
+ return fn
630
+ else:
631
+ return "swig.exe"
632
+ else:
633
+ raise DistutilsPlatformError(
634
+ "I don't know how to find (much less run) SWIG "
635
+ "on platform '%s'" % os.name)
636
+
637
+ # -- Name generators -----------------------------------------------
638
+ # (extension names, filenames, whatever)
639
+ def get_ext_fullpath(self, ext_name):
640
+ """Returns the path of the filename for a given extension.
641
+
642
+ The file is located in `build_lib` or directly in the package
643
+ (inplace option).
644
+ """
645
+ fullname = self.get_ext_fullname(ext_name)
646
+ modpath = fullname.split('.')
647
+ filename = self.get_ext_filename(modpath[-1])
648
+
649
+ if not self.inplace:
650
+ # no further work needed
651
+ # returning :
652
+ # build_dir/package/path/filename
653
+ filename = os.path.join(*modpath[:-1]+[filename])
654
+ return os.path.join(self.build_lib, filename)
655
+
656
+ # the inplace option requires to find the package directory
657
+ # using the build_py command for that
658
+ package = '.'.join(modpath[0:-1])
659
+ build_py = self.get_finalized_command('build_py')
660
+ package_dir = os.path.abspath(build_py.get_package_dir(package))
661
+
662
+ # returning
663
+ # package_dir/filename
664
+ return os.path.join(package_dir, filename)
665
+
666
+ def get_ext_fullname(self, ext_name):
667
+ """Returns the fullname of a given extension name.
668
+
669
+ Adds the `package.` prefix"""
670
+ if self.package is None:
671
+ return ext_name
672
+ else:
673
+ return self.package + '.' + ext_name
674
+
675
+ def get_ext_filename(self, ext_name):
676
+ r"""Convert the name of an extension (eg. "foo.bar") into the name
677
+ of the file from which it will be loaded (eg. "foo/bar.so", or
678
+ "foo\bar.pyd").
679
+ """
680
+ from distutils.sysconfig import get_config_var
681
+ ext_path = ext_name.split('.')
682
+ ext_suffix = get_config_var('EXT_SUFFIX')
683
+ return os.path.join(*ext_path) + ext_suffix
684
+
685
+ def get_export_symbols(self, ext):
686
+ """Return the list of symbols that a shared extension has to
687
+ export. This either uses 'ext.export_symbols' or, if it's not
688
+ provided, "PyInit_" + module_name. Only relevant on Windows, where
689
+ the .pyd file (DLL) must export the module "PyInit_" function.
690
+ """
691
+ name = ext.name.split('.')[-1]
692
+ try:
693
+ # Unicode module name support as defined in PEP-489
694
+ # https://www.python.org/dev/peps/pep-0489/#export-hook-name
695
+ name.encode('ascii')
696
+ except UnicodeEncodeError:
697
+ suffix = 'U_' + name.encode('punycode').replace(b'-', b'_').decode('ascii')
698
+ else:
699
+ suffix = "_" + name
700
+
701
+ initfunc_name = "PyInit" + suffix
702
+ if initfunc_name not in ext.export_symbols:
703
+ ext.export_symbols.append(initfunc_name)
704
+ return ext.export_symbols
705
+
706
+ def get_libraries(self, ext):
707
+ """Return the list of libraries to link against when building a
708
+ shared extension. On most platforms, this is just 'ext.libraries';
709
+ on Windows, we add the Python library (eg. python20.dll).
710
+ """
711
+ # The python library is always needed on Windows. For MSVC, this
712
+ # is redundant, since the library is mentioned in a pragma in
713
+ # pyconfig.h that MSVC groks. The other Windows compilers all seem
714
+ # to need it mentioned explicitly, though, so that's what we do.
715
+ # Append '_d' to the python import library on debug builds.
716
+ if sys.platform == "win32":
717
+ from distutils._msvccompiler import MSVCCompiler
718
+ if not isinstance(self.compiler, MSVCCompiler):
719
+ template = "python%d%d"
720
+ if self.debug:
721
+ template = template + '_d'
722
+ pythonlib = (template %
723
+ (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
724
+ # don't extend ext.libraries, it may be shared with other
725
+ # extensions, it is a reference to the original list
726
+ return ext.libraries + [pythonlib]
727
+ else:
728
+ # On Android only the main executable and LD_PRELOADs are considered
729
+ # to be RTLD_GLOBAL, all the dependencies of the main executable
730
+ # remain RTLD_LOCAL and so the shared libraries must be linked with
731
+ # libpython when python is built with a shared python library (issue
732
+ # bpo-21536).
733
+ # On Cygwin (and if required, other POSIX-like platforms based on
734
+ # Windows like MinGW) it is simply necessary that all symbols in
735
+ # shared libraries are resolved at link time.
736
+ from distutils.sysconfig import get_config_var
737
+ link_libpython = False
738
+ if get_config_var('Py_ENABLE_SHARED'):
739
+ # A native build on an Android device or on Cygwin
740
+ if hasattr(sys, 'getandroidapilevel'):
741
+ link_libpython = True
742
+ elif sys.platform == 'cygwin':
743
+ link_libpython = True
744
+ elif '_PYTHON_HOST_PLATFORM' in os.environ:
745
+ # We are cross-compiling for one of the relevant platforms
746
+ if get_config_var('ANDROID_API_LEVEL') != 0:
747
+ link_libpython = True
748
+ elif get_config_var('MACHDEP') == 'cygwin':
749
+ link_libpython = True
750
+
751
+ if link_libpython:
752
+ ldversion = get_config_var('LDVERSION')
753
+ return ext.libraries + ['python' + ldversion]
754
+
755
+ return ext.libraries + py37compat.pythonlib()
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.py ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_py
2
+
3
+ Implements the Distutils 'build_py' command."""
4
+
5
+ import os
6
+ import importlib.util
7
+ import sys
8
+ import glob
9
+
10
+ from distutils.core import Command
11
+ from distutils.errors import *
12
+ from distutils.util import convert_path
13
+ from distutils import log
14
+
15
+ class build_py (Command):
16
+
17
+ description = "\"build\" pure Python modules (copy to build directory)"
18
+
19
+ user_options = [
20
+ ('build-lib=', 'd', "directory to \"build\" (copy) to"),
21
+ ('compile', 'c', "compile .py to .pyc"),
22
+ ('no-compile', None, "don't compile .py files [default]"),
23
+ ('optimize=', 'O',
24
+ "also compile with optimization: -O1 for \"python -O\", "
25
+ "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
26
+ ('force', 'f', "forcibly build everything (ignore file timestamps)"),
27
+ ]
28
+
29
+ boolean_options = ['compile', 'force']
30
+ negative_opt = {'no-compile' : 'compile'}
31
+
32
+ def initialize_options(self):
33
+ self.build_lib = None
34
+ self.py_modules = None
35
+ self.package = None
36
+ self.package_data = None
37
+ self.package_dir = None
38
+ self.compile = 0
39
+ self.optimize = 0
40
+ self.force = None
41
+
42
+ def finalize_options(self):
43
+ self.set_undefined_options('build',
44
+ ('build_lib', 'build_lib'),
45
+ ('force', 'force'))
46
+
47
+ # Get the distribution options that are aliases for build_py
48
+ # options -- list of packages and list of modules.
49
+ self.packages = self.distribution.packages
50
+ self.py_modules = self.distribution.py_modules
51
+ self.package_data = self.distribution.package_data
52
+ self.package_dir = {}
53
+ if self.distribution.package_dir:
54
+ for name, path in self.distribution.package_dir.items():
55
+ self.package_dir[name] = convert_path(path)
56
+ self.data_files = self.get_data_files()
57
+
58
+ # Ick, copied straight from install_lib.py (fancy_getopt needs a
59
+ # type system! Hell, *everything* needs a type system!!!)
60
+ if not isinstance(self.optimize, int):
61
+ try:
62
+ self.optimize = int(self.optimize)
63
+ assert 0 <= self.optimize <= 2
64
+ except (ValueError, AssertionError):
65
+ raise DistutilsOptionError("optimize must be 0, 1, or 2")
66
+
67
+ def run(self):
68
+ # XXX copy_file by default preserves atime and mtime. IMHO this is
69
+ # the right thing to do, but perhaps it should be an option -- in
70
+ # particular, a site administrator might want installed files to
71
+ # reflect the time of installation rather than the last
72
+ # modification time before the installed release.
73
+
74
+ # XXX copy_file by default preserves mode, which appears to be the
75
+ # wrong thing to do: if a file is read-only in the working
76
+ # directory, we want it to be installed read/write so that the next
77
+ # installation of the same module distribution can overwrite it
78
+ # without problems. (This might be a Unix-specific issue.) Thus
79
+ # we turn off 'preserve_mode' when copying to the build directory,
80
+ # since the build directory is supposed to be exactly what the
81
+ # installation will look like (ie. we preserve mode when
82
+ # installing).
83
+
84
+ # Two options control which modules will be installed: 'packages'
85
+ # and 'py_modules'. The former lets us work with whole packages, not
86
+ # specifying individual modules at all; the latter is for
87
+ # specifying modules one-at-a-time.
88
+
89
+ if self.py_modules:
90
+ self.build_modules()
91
+ if self.packages:
92
+ self.build_packages()
93
+ self.build_package_data()
94
+
95
+ self.byte_compile(self.get_outputs(include_bytecode=0))
96
+
97
+ def get_data_files(self):
98
+ """Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
99
+ data = []
100
+ if not self.packages:
101
+ return data
102
+ for package in self.packages:
103
+ # Locate package source directory
104
+ src_dir = self.get_package_dir(package)
105
+
106
+ # Compute package build directory
107
+ build_dir = os.path.join(*([self.build_lib] + package.split('.')))
108
+
109
+ # Length of path to strip from found files
110
+ plen = 0
111
+ if src_dir:
112
+ plen = len(src_dir)+1
113
+
114
+ # Strip directory from globbed filenames
115
+ filenames = [
116
+ file[plen:] for file in self.find_data_files(package, src_dir)
117
+ ]
118
+ data.append((package, src_dir, build_dir, filenames))
119
+ return data
120
+
121
+ def find_data_files(self, package, src_dir):
122
+ """Return filenames for package's data files in 'src_dir'"""
123
+ globs = (self.package_data.get('', [])
124
+ + self.package_data.get(package, []))
125
+ files = []
126
+ for pattern in globs:
127
+ # Each pattern has to be converted to a platform-specific path
128
+ filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern)))
129
+ # Files that match more than one pattern are only added once
130
+ files.extend([fn for fn in filelist if fn not in files
131
+ and os.path.isfile(fn)])
132
+ return files
133
+
134
+ def build_package_data(self):
135
+ """Copy data files into build directory"""
136
+ lastdir = None
137
+ for package, src_dir, build_dir, filenames in self.data_files:
138
+ for filename in filenames:
139
+ target = os.path.join(build_dir, filename)
140
+ self.mkpath(os.path.dirname(target))
141
+ self.copy_file(os.path.join(src_dir, filename), target,
142
+ preserve_mode=False)
143
+
144
+ def get_package_dir(self, package):
145
+ """Return the directory, relative to the top of the source
146
+ distribution, where package 'package' should be found
147
+ (at least according to the 'package_dir' option, if any)."""
148
+ path = package.split('.')
149
+
150
+ if not self.package_dir:
151
+ if path:
152
+ return os.path.join(*path)
153
+ else:
154
+ return ''
155
+ else:
156
+ tail = []
157
+ while path:
158
+ try:
159
+ pdir = self.package_dir['.'.join(path)]
160
+ except KeyError:
161
+ tail.insert(0, path[-1])
162
+ del path[-1]
163
+ else:
164
+ tail.insert(0, pdir)
165
+ return os.path.join(*tail)
166
+ else:
167
+ # Oops, got all the way through 'path' without finding a
168
+ # match in package_dir. If package_dir defines a directory
169
+ # for the root (nameless) package, then fallback on it;
170
+ # otherwise, we might as well have not consulted
171
+ # package_dir at all, as we just use the directory implied
172
+ # by 'tail' (which should be the same as the original value
173
+ # of 'path' at this point).
174
+ pdir = self.package_dir.get('')
175
+ if pdir is not None:
176
+ tail.insert(0, pdir)
177
+
178
+ if tail:
179
+ return os.path.join(*tail)
180
+ else:
181
+ return ''
182
+
183
+ def check_package(self, package, package_dir):
184
+ # Empty dir name means current directory, which we can probably
185
+ # assume exists. Also, os.path.exists and isdir don't know about
186
+ # my "empty string means current dir" convention, so we have to
187
+ # circumvent them.
188
+ if package_dir != "":
189
+ if not os.path.exists(package_dir):
190
+ raise DistutilsFileError(
191
+ "package directory '%s' does not exist" % package_dir)
192
+ if not os.path.isdir(package_dir):
193
+ raise DistutilsFileError(
194
+ "supposed package directory '%s' exists, "
195
+ "but is not a directory" % package_dir)
196
+
197
+ # Require __init__.py for all but the "root package"
198
+ if package:
199
+ init_py = os.path.join(package_dir, "__init__.py")
200
+ if os.path.isfile(init_py):
201
+ return init_py
202
+ else:
203
+ log.warn(("package init file '%s' not found " +
204
+ "(or not a regular file)"), init_py)
205
+
206
+ # Either not in a package at all (__init__.py not expected), or
207
+ # __init__.py doesn't exist -- so don't return the filename.
208
+ return None
209
+
210
+ def check_module(self, module, module_file):
211
+ if not os.path.isfile(module_file):
212
+ log.warn("file %s (for module %s) not found", module_file, module)
213
+ return False
214
+ else:
215
+ return True
216
+
217
+ def find_package_modules(self, package, package_dir):
218
+ self.check_package(package, package_dir)
219
+ module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
220
+ modules = []
221
+ setup_script = os.path.abspath(self.distribution.script_name)
222
+
223
+ for f in module_files:
224
+ abs_f = os.path.abspath(f)
225
+ if abs_f != setup_script:
226
+ module = os.path.splitext(os.path.basename(f))[0]
227
+ modules.append((package, module, f))
228
+ else:
229
+ self.debug_print("excluding %s" % setup_script)
230
+ return modules
231
+
232
+ def find_modules(self):
233
+ """Finds individually-specified Python modules, ie. those listed by
234
+ module name in 'self.py_modules'. Returns a list of tuples (package,
235
+ module_base, filename): 'package' is a tuple of the path through
236
+ package-space to the module; 'module_base' is the bare (no
237
+ packages, no dots) module name, and 'filename' is the path to the
238
+ ".py" file (relative to the distribution root) that implements the
239
+ module.
240
+ """
241
+ # Map package names to tuples of useful info about the package:
242
+ # (package_dir, checked)
243
+ # package_dir - the directory where we'll find source files for
244
+ # this package
245
+ # checked - true if we have checked that the package directory
246
+ # is valid (exists, contains __init__.py, ... ?)
247
+ packages = {}
248
+
249
+ # List of (package, module, filename) tuples to return
250
+ modules = []
251
+
252
+ # We treat modules-in-packages almost the same as toplevel modules,
253
+ # just the "package" for a toplevel is empty (either an empty
254
+ # string or empty list, depending on context). Differences:
255
+ # - don't check for __init__.py in directory for empty package
256
+ for module in self.py_modules:
257
+ path = module.split('.')
258
+ package = '.'.join(path[0:-1])
259
+ module_base = path[-1]
260
+
261
+ try:
262
+ (package_dir, checked) = packages[package]
263
+ except KeyError:
264
+ package_dir = self.get_package_dir(package)
265
+ checked = 0
266
+
267
+ if not checked:
268
+ init_py = self.check_package(package, package_dir)
269
+ packages[package] = (package_dir, 1)
270
+ if init_py:
271
+ modules.append((package, "__init__", init_py))
272
+
273
+ # XXX perhaps we should also check for just .pyc files
274
+ # (so greedy closed-source bastards can distribute Python
275
+ # modules too)
276
+ module_file = os.path.join(package_dir, module_base + ".py")
277
+ if not self.check_module(module, module_file):
278
+ continue
279
+
280
+ modules.append((package, module_base, module_file))
281
+
282
+ return modules
283
+
284
+ def find_all_modules(self):
285
+ """Compute the list of all modules that will be built, whether
286
+ they are specified one-module-at-a-time ('self.py_modules') or
287
+ by whole packages ('self.packages'). Return a list of tuples
288
+ (package, module, module_file), just like 'find_modules()' and
289
+ 'find_package_modules()' do."""
290
+ modules = []
291
+ if self.py_modules:
292
+ modules.extend(self.find_modules())
293
+ if self.packages:
294
+ for package in self.packages:
295
+ package_dir = self.get_package_dir(package)
296
+ m = self.find_package_modules(package, package_dir)
297
+ modules.extend(m)
298
+ return modules
299
+
300
+ def get_source_files(self):
301
+ return [module[-1] for module in self.find_all_modules()]
302
+
303
+ def get_module_outfile(self, build_dir, package, module):
304
+ outfile_path = [build_dir] + list(package) + [module + ".py"]
305
+ return os.path.join(*outfile_path)
306
+
307
+ def get_outputs(self, include_bytecode=1):
308
+ modules = self.find_all_modules()
309
+ outputs = []
310
+ for (package, module, module_file) in modules:
311
+ package = package.split('.')
312
+ filename = self.get_module_outfile(self.build_lib, package, module)
313
+ outputs.append(filename)
314
+ if include_bytecode:
315
+ if self.compile:
316
+ outputs.append(importlib.util.cache_from_source(
317
+ filename, optimization=''))
318
+ if self.optimize > 0:
319
+ outputs.append(importlib.util.cache_from_source(
320
+ filename, optimization=self.optimize))
321
+
322
+ outputs += [
323
+ os.path.join(build_dir, filename)
324
+ for package, src_dir, build_dir, filenames in self.data_files
325
+ for filename in filenames
326
+ ]
327
+
328
+ return outputs
329
+
330
+ def build_module(self, module, module_file, package):
331
+ if isinstance(package, str):
332
+ package = package.split('.')
333
+ elif not isinstance(package, (list, tuple)):
334
+ raise TypeError(
335
+ "'package' must be a string (dot-separated), list, or tuple")
336
+
337
+ # Now put the module source file into the "build" area -- this is
338
+ # easy, we just copy it somewhere under self.build_lib (the build
339
+ # directory for Python source).
340
+ outfile = self.get_module_outfile(self.build_lib, package, module)
341
+ dir = os.path.dirname(outfile)
342
+ self.mkpath(dir)
343
+ return self.copy_file(module_file, outfile, preserve_mode=0)
344
+
345
+ def build_modules(self):
346
+ modules = self.find_modules()
347
+ for (package, module, module_file) in modules:
348
+ # Now "build" the module -- ie. copy the source file to
349
+ # self.build_lib (the build directory for Python source).
350
+ # (Actually, it gets copied to the directory for this package
351
+ # under self.build_lib.)
352
+ self.build_module(module, module_file, package)
353
+
354
+ def build_packages(self):
355
+ for package in self.packages:
356
+ # Get list of (package, module, module_file) tuples based on
357
+ # scanning the package directory. 'package' is only included
358
+ # in the tuple so that 'find_modules()' and
359
+ # 'find_package_tuples()' have a consistent interface; it's
360
+ # ignored here (apart from a sanity check). Also, 'module' is
361
+ # the *unqualified* module name (ie. no dots, no package -- we
362
+ # already know its package!), and 'module_file' is the path to
363
+ # the .py file, relative to the current directory
364
+ # (ie. including 'package_dir').
365
+ package_dir = self.get_package_dir(package)
366
+ modules = self.find_package_modules(package, package_dir)
367
+
368
+ # Now loop over the modules we found, "building" each one (just
369
+ # copy it to self.build_lib).
370
+ for (package_, module, module_file) in modules:
371
+ assert package == package_
372
+ self.build_module(module, module_file, package)
373
+
374
+ def byte_compile(self, files):
375
+ if sys.dont_write_bytecode:
376
+ self.warn('byte-compiling is disabled, skipping.')
377
+ return
378
+
379
+ from distutils.util import byte_compile
380
+ prefix = self.build_lib
381
+ if prefix[-1] != os.sep:
382
+ prefix = prefix + os.sep
383
+
384
+ # XXX this code is essentially the same as the 'byte_compile()
385
+ # method of the "install_lib" command, except for the determination
386
+ # of the 'prefix' string. Hmmm.
387
+ if self.compile:
388
+ byte_compile(files, optimize=0,
389
+ force=self.force, prefix=prefix, dry_run=self.dry_run)
390
+ if self.optimize > 0:
391
+ byte_compile(files, optimize=self.optimize,
392
+ force=self.force, prefix=prefix, dry_run=self.dry_run)
scripts/myenv/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """distutils.command.build_scripts
2
+
3
+ Implements the Distutils 'build_scripts' command."""
4
+
5
+ import os, re
6
+ from stat import ST_MODE
7
+ from distutils import sysconfig
8
+ from distutils.core import Command
9
+ from distutils.dep_util import newer
10
+ from distutils.util import convert_path
11
+ from distutils import log
12
+ import tokenize
13
+
14
+ # check if Python is called on the first line with this expression
15
+ first_line_re = re.compile(b'^#!.*python[0-9.]*([ \t].*)?$')
16
+
17
+ class build_scripts(Command):
18
+
19
+ description = "\"build\" scripts (copy and fixup #! line)"
20
+
21
+ user_options = [
22
+ ('build-dir=', 'd', "directory to \"build\" (copy) to"),
23
+ ('force', 'f', "forcibly build everything (ignore file timestamps"),
24
+ ('executable=', 'e', "specify final destination interpreter path"),
25
+ ]
26
+
27
+ boolean_options = ['force']
28
+
29
+
30
+ def initialize_options(self):
31
+ self.build_dir = None
32
+ self.scripts = None
33
+ self.force = None
34
+ self.executable = None
35
+ self.outfiles = None
36
+
37
+ def finalize_options(self):
38
+ self.set_undefined_options('build',
39
+ ('build_scripts', 'build_dir'),
40
+ ('force', 'force'),
41
+ ('executable', 'executable'))
42
+ self.scripts = self.distribution.scripts
43
+
44
+ def get_source_files(self):
45
+ return self.scripts
46
+
47
+ def run(self):
48
+ if not self.scripts:
49
+ return
50
+ self.copy_scripts()
51
+
52
+
53
+ def copy_scripts(self):
54
+ r"""Copy each script listed in 'self.scripts'; if it's marked as a
55
+ Python script in the Unix way (first line matches 'first_line_re',
56
+ ie. starts with "\#!" and contains "python"), then adjust the first
57
+ line to refer to the current Python interpreter as we copy.
58
+ """
59
+ self.mkpath(self.build_dir)
60
+ outfiles = []
61
+ updated_files = []
62
+ for script in self.scripts:
63
+ adjust = False
64
+ script = convert_path(script)
65
+ outfile = os.path.join(self.build_dir, os.path.basename(script))
66
+ outfiles.append(outfile)
67
+
68
+ if not self.force and not newer(script, outfile):
69
+ log.debug("not copying %s (up-to-date)", script)
70
+ continue
71
+
72
+ # Always open the file, but ignore failures in dry-run mode --
73
+ # that way, we'll get accurate feedback if we can read the
74
+ # script.
75
+ try:
76
+ f = open(script, "rb")
77
+ except OSError:
78
+ if not self.dry_run:
79
+ raise
80
+ f = None
81
+ else:
82
+ encoding, lines = tokenize.detect_encoding(f.readline)
83
+ f.seek(0)
84
+ first_line = f.readline()
85
+ if not first_line:
86
+ self.warn("%s is an empty file (skipping)" % script)
87
+ continue
88
+
89
+ match = first_line_re.match(first_line)
90
+ if match:
91
+ adjust = True
92
+ post_interp = match.group(1) or b''
93
+
94
+ if adjust:
95
+ log.info("copying and adjusting %s -> %s", script,
96
+ self.build_dir)
97
+ updated_files.append(outfile)
98
+ if not self.dry_run:
99
+ if not sysconfig.python_build:
100
+ executable = self.executable
101
+ else:
102
+ executable = os.path.join(
103
+ sysconfig.get_config_var("BINDIR"),
104
+ "python%s%s" % (sysconfig.get_config_var("VERSION"),
105
+ sysconfig.get_config_var("EXE")))
106
+ executable = os.fsencode(executable)
107
+ shebang = b"#!" + executable + post_interp + b"\n"
108
+ # Python parser starts to read a script using UTF-8 until
109
+ # it gets a #coding:xxx cookie. The shebang has to be the
110
+ # first line of a file, the #coding:xxx cookie cannot be
111
+ # written before. So the shebang has to be decodable from
112
+ # UTF-8.
113
+ try:
114
+ shebang.decode('utf-8')
115
+ except UnicodeDecodeError:
116
+ raise ValueError(
117
+ "The shebang ({!r}) is not decodable "
118
+ "from utf-8".format(shebang))
119
+ # If the script is encoded to a custom encoding (use a
120
+ # #coding:xxx cookie), the shebang has to be decodable from
121
+ # the script encoding too.
122
+ try:
123
+ shebang.decode(encoding)
124
+ except UnicodeDecodeError:
125
+ raise ValueError(
126
+ "The shebang ({!r}) is not decodable "
127
+ "from the script encoding ({})"
128
+ .format(shebang, encoding))
129
+ with open(outfile, "wb") as outf:
130
+ outf.write(shebang)
131
+ outf.writelines(f.readlines())
132
+ if f:
133
+ f.close()
134
+ else:
135
+ if f:
136
+ f.close()
137
+ updated_files.append(outfile)
138
+ self.copy_file(script, outfile)
139
+
140
+ if os.name == 'posix':
141
+ for file in outfiles:
142
+ if self.dry_run:
143
+ log.info("changing mode of %s", file)
144
+ else:
145
+ oldmode = os.stat(file)[ST_MODE] & 0o7777
146
+ newmode = (oldmode | 0o555) & 0o7777
147
+ if newmode != oldmode:
148
+ log.info("changing mode of %s from %o to %o",
149
+ file, oldmode, newmode)
150
+ os.chmod(file, newmode)
151
+ # XXX should we modify self.outfiles?
152
+ return outfiles, updated_files