Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- evalkit_cambrian/lib/libtinfow.so +3 -0
- evalkit_cambrian/lib/libtinfow.so.6 +3 -0
- evalkit_cambrian/lib/python3.10/distutils/dir_util.py +210 -0
- evalkit_cambrian/lib/python3.10/distutils/extension.py +241 -0
- evalkit_cambrian/lib/python3.10/distutils/fancy_getopt.py +457 -0
- evalkit_cambrian/lib/python3.10/distutils/log.py +77 -0
- evalkit_cambrian/lib/python3.10/distutils/spawn.py +129 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/Setup.sample +67 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__init__.py +41 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_bdist.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_bdist_dumb.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_bdist_msi.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_build_ext.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_build_py.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_build_scripts.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_cmd.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_cygwinccompiler.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_dep_util.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_extension.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_file_util.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_filelist.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_install_data.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_install_scripts.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_msvc9compiler.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_msvccompiler.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_register.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_sysconfig.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_text_file.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_unixccompiler.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_upload.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_versionpredicate.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/includetest.rst +1 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/support.py +209 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_archive_util.py +396 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist.py +56 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist_dumb.py +97 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist_msi.py +27 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist_rpm.py +135 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_build.py +56 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_build_clib.py +144 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_build_ext.py +553 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_build_py.py +179 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_build_scripts.py +112 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_check.py +163 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_clean.py +49 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_cmd.py +126 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_config.py +141 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_config_cmd.py +100 -0
- evalkit_cambrian/lib/python3.10/distutils/tests/test_core.py +140 -0
.gitattributes
CHANGED
|
@@ -251,3 +251,5 @@ evalkit_cambrian/lib/libtinfow.a filter=lfs diff=lfs merge=lfs -text
|
|
| 251 |
evalkit_cambrian/bin/lzma filter=lfs diff=lfs merge=lfs -text
|
| 252 |
evalkit_cambrian/bin/xzcat filter=lfs diff=lfs merge=lfs -text
|
| 253 |
evalkit_cambrian/lib/libtinfo.so.6.4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 251 |
evalkit_cambrian/bin/lzma filter=lfs diff=lfs merge=lfs -text
|
| 252 |
evalkit_cambrian/bin/xzcat filter=lfs diff=lfs merge=lfs -text
|
| 253 |
evalkit_cambrian/lib/libtinfo.so.6.4 filter=lfs diff=lfs merge=lfs -text
|
| 254 |
+
evalkit_cambrian/lib/libtinfow.so filter=lfs diff=lfs merge=lfs -text
|
| 255 |
+
evalkit_cambrian/lib/libtinfow.so.6 filter=lfs diff=lfs merge=lfs -text
|
evalkit_cambrian/lib/libtinfow.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1b37a4e64c226f3a353c31f1f237fcba0450de33c0c513307cfabd8a82a892b7
|
| 3 |
+
size 287080
|
evalkit_cambrian/lib/libtinfow.so.6
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1b37a4e64c226f3a353c31f1f237fcba0450de33c0c513307cfabd8a82a892b7
|
| 3 |
+
size 287080
|
evalkit_cambrian/lib/python3.10/distutils/dir_util.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.dir_util
|
| 2 |
+
|
| 3 |
+
Utility functions for manipulating directories and directory trees."""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import errno
|
| 7 |
+
from distutils.errors import DistutilsFileError, DistutilsInternalError
|
| 8 |
+
from distutils import log
|
| 9 |
+
|
| 10 |
+
# cache for by mkpath() -- in addition to cheapening redundant calls,
|
| 11 |
+
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
|
| 12 |
+
_path_created = {}
|
| 13 |
+
|
| 14 |
+
# I don't use os.makedirs because a) it's new to Python 1.5.2, and
|
| 15 |
+
# b) it blows up if the directory already exists (I want to silently
|
| 16 |
+
# succeed in that case).
|
| 17 |
+
def mkpath(name, mode=0o777, verbose=1, dry_run=0):
|
| 18 |
+
"""Create a directory and any missing ancestor directories.
|
| 19 |
+
|
| 20 |
+
If the directory already exists (or if 'name' is the empty string, which
|
| 21 |
+
means the current directory, which of course exists), then do nothing.
|
| 22 |
+
Raise DistutilsFileError if unable to create some directory along the way
|
| 23 |
+
(eg. some sub-path exists, but is a file rather than a directory).
|
| 24 |
+
If 'verbose' is true, print a one-line summary of each mkdir to stdout.
|
| 25 |
+
Return the list of directories actually created.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
global _path_created
|
| 29 |
+
|
| 30 |
+
# Detect a common bug -- name is None
|
| 31 |
+
if not isinstance(name, str):
|
| 32 |
+
raise DistutilsInternalError(
|
| 33 |
+
"mkpath: 'name' must be a string (got %r)" % (name,))
|
| 34 |
+
|
| 35 |
+
# XXX what's the better way to handle verbosity? print as we create
|
| 36 |
+
# each directory in the path (the current behaviour), or only announce
|
| 37 |
+
# the creation of the whole path? (quite easy to do the latter since
|
| 38 |
+
# we're not using a recursive algorithm)
|
| 39 |
+
|
| 40 |
+
name = os.path.normpath(name)
|
| 41 |
+
created_dirs = []
|
| 42 |
+
if os.path.isdir(name) or name == '':
|
| 43 |
+
return created_dirs
|
| 44 |
+
if _path_created.get(os.path.abspath(name)):
|
| 45 |
+
return created_dirs
|
| 46 |
+
|
| 47 |
+
(head, tail) = os.path.split(name)
|
| 48 |
+
tails = [tail] # stack of lone dirs to create
|
| 49 |
+
|
| 50 |
+
while head and tail and not os.path.isdir(head):
|
| 51 |
+
(head, tail) = os.path.split(head)
|
| 52 |
+
tails.insert(0, tail) # push next higher dir onto stack
|
| 53 |
+
|
| 54 |
+
# now 'head' contains the deepest directory that already exists
|
| 55 |
+
# (that is, the child of 'head' in 'name' is the highest directory
|
| 56 |
+
# that does *not* exist)
|
| 57 |
+
for d in tails:
|
| 58 |
+
#print "head = %s, d = %s: " % (head, d),
|
| 59 |
+
head = os.path.join(head, d)
|
| 60 |
+
abs_head = os.path.abspath(head)
|
| 61 |
+
|
| 62 |
+
if _path_created.get(abs_head):
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
if verbose >= 1:
|
| 66 |
+
log.info("creating %s", head)
|
| 67 |
+
|
| 68 |
+
if not dry_run:
|
| 69 |
+
try:
|
| 70 |
+
os.mkdir(head, mode)
|
| 71 |
+
except OSError as exc:
|
| 72 |
+
if not (exc.errno == errno.EEXIST and os.path.isdir(head)):
|
| 73 |
+
raise DistutilsFileError(
|
| 74 |
+
"could not create '%s': %s" % (head, exc.args[-1]))
|
| 75 |
+
created_dirs.append(head)
|
| 76 |
+
|
| 77 |
+
_path_created[abs_head] = 1
|
| 78 |
+
return created_dirs
|
| 79 |
+
|
| 80 |
+
def create_tree(base_dir, files, mode=0o777, verbose=1, dry_run=0):
|
| 81 |
+
"""Create all the empty directories under 'base_dir' needed to put 'files'
|
| 82 |
+
there.
|
| 83 |
+
|
| 84 |
+
'base_dir' is just the name of a directory which doesn't necessarily
|
| 85 |
+
exist yet; 'files' is a list of filenames to be interpreted relative to
|
| 86 |
+
'base_dir'. 'base_dir' + the directory portion of every file in 'files'
|
| 87 |
+
will be created if it doesn't already exist. 'mode', 'verbose' and
|
| 88 |
+
'dry_run' flags are as for 'mkpath()'.
|
| 89 |
+
"""
|
| 90 |
+
# First get the list of directories to create
|
| 91 |
+
need_dir = set()
|
| 92 |
+
for file in files:
|
| 93 |
+
need_dir.add(os.path.join(base_dir, os.path.dirname(file)))
|
| 94 |
+
|
| 95 |
+
# Now create them
|
| 96 |
+
for dir in sorted(need_dir):
|
| 97 |
+
mkpath(dir, mode, verbose=verbose, dry_run=dry_run)
|
| 98 |
+
|
| 99 |
+
def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
|
| 100 |
+
preserve_symlinks=0, update=0, verbose=1, dry_run=0):
|
| 101 |
+
"""Copy an entire directory tree 'src' to a new location 'dst'.
|
| 102 |
+
|
| 103 |
+
Both 'src' and 'dst' must be directory names. If 'src' is not a
|
| 104 |
+
directory, raise DistutilsFileError. If 'dst' does not exist, it is
|
| 105 |
+
created with 'mkpath()'. The end result of the copy is that every
|
| 106 |
+
file in 'src' is copied to 'dst', and directories under 'src' are
|
| 107 |
+
recursively copied to 'dst'. Return the list of files that were
|
| 108 |
+
copied or might have been copied, using their output name. The
|
| 109 |
+
return value is unaffected by 'update' or 'dry_run': it is simply
|
| 110 |
+
the list of all files under 'src', with the names changed to be
|
| 111 |
+
under 'dst'.
|
| 112 |
+
|
| 113 |
+
'preserve_mode' and 'preserve_times' are the same as for
|
| 114 |
+
'copy_file'; note that they only apply to regular files, not to
|
| 115 |
+
directories. If 'preserve_symlinks' is true, symlinks will be
|
| 116 |
+
copied as symlinks (on platforms that support them!); otherwise
|
| 117 |
+
(the default), the destination of the symlink will be copied.
|
| 118 |
+
'update' and 'verbose' are the same as for 'copy_file'.
|
| 119 |
+
"""
|
| 120 |
+
from distutils.file_util import copy_file
|
| 121 |
+
|
| 122 |
+
if not dry_run and not os.path.isdir(src):
|
| 123 |
+
raise DistutilsFileError(
|
| 124 |
+
"cannot copy tree '%s': not a directory" % src)
|
| 125 |
+
try:
|
| 126 |
+
names = os.listdir(src)
|
| 127 |
+
except OSError as e:
|
| 128 |
+
if dry_run:
|
| 129 |
+
names = []
|
| 130 |
+
else:
|
| 131 |
+
raise DistutilsFileError(
|
| 132 |
+
"error listing files in '%s': %s" % (src, e.strerror))
|
| 133 |
+
|
| 134 |
+
if not dry_run:
|
| 135 |
+
mkpath(dst, verbose=verbose)
|
| 136 |
+
|
| 137 |
+
outputs = []
|
| 138 |
+
|
| 139 |
+
for n in names:
|
| 140 |
+
src_name = os.path.join(src, n)
|
| 141 |
+
dst_name = os.path.join(dst, n)
|
| 142 |
+
|
| 143 |
+
if n.startswith('.nfs'):
|
| 144 |
+
# skip NFS rename files
|
| 145 |
+
continue
|
| 146 |
+
|
| 147 |
+
if preserve_symlinks and os.path.islink(src_name):
|
| 148 |
+
link_dest = os.readlink(src_name)
|
| 149 |
+
if verbose >= 1:
|
| 150 |
+
log.info("linking %s -> %s", dst_name, link_dest)
|
| 151 |
+
if not dry_run:
|
| 152 |
+
os.symlink(link_dest, dst_name)
|
| 153 |
+
outputs.append(dst_name)
|
| 154 |
+
|
| 155 |
+
elif os.path.isdir(src_name):
|
| 156 |
+
outputs.extend(
|
| 157 |
+
copy_tree(src_name, dst_name, preserve_mode,
|
| 158 |
+
preserve_times, preserve_symlinks, update,
|
| 159 |
+
verbose=verbose, dry_run=dry_run))
|
| 160 |
+
else:
|
| 161 |
+
copy_file(src_name, dst_name, preserve_mode,
|
| 162 |
+
preserve_times, update, verbose=verbose,
|
| 163 |
+
dry_run=dry_run)
|
| 164 |
+
outputs.append(dst_name)
|
| 165 |
+
|
| 166 |
+
return outputs
|
| 167 |
+
|
| 168 |
+
def _build_cmdtuple(path, cmdtuples):
|
| 169 |
+
"""Helper for remove_tree()."""
|
| 170 |
+
for f in os.listdir(path):
|
| 171 |
+
real_f = os.path.join(path,f)
|
| 172 |
+
if os.path.isdir(real_f) and not os.path.islink(real_f):
|
| 173 |
+
_build_cmdtuple(real_f, cmdtuples)
|
| 174 |
+
else:
|
| 175 |
+
cmdtuples.append((os.remove, real_f))
|
| 176 |
+
cmdtuples.append((os.rmdir, path))
|
| 177 |
+
|
| 178 |
+
def remove_tree(directory, verbose=1, dry_run=0):
|
| 179 |
+
"""Recursively remove an entire directory tree.
|
| 180 |
+
|
| 181 |
+
Any errors are ignored (apart from being reported to stdout if 'verbose'
|
| 182 |
+
is true).
|
| 183 |
+
"""
|
| 184 |
+
global _path_created
|
| 185 |
+
|
| 186 |
+
if verbose >= 1:
|
| 187 |
+
log.info("removing '%s' (and everything under it)", directory)
|
| 188 |
+
if dry_run:
|
| 189 |
+
return
|
| 190 |
+
cmdtuples = []
|
| 191 |
+
_build_cmdtuple(directory, cmdtuples)
|
| 192 |
+
for cmd in cmdtuples:
|
| 193 |
+
try:
|
| 194 |
+
cmd[0](cmd[1])
|
| 195 |
+
# remove dir from cache if it's already there
|
| 196 |
+
abspath = os.path.abspath(cmd[1])
|
| 197 |
+
if abspath in _path_created:
|
| 198 |
+
del _path_created[abspath]
|
| 199 |
+
except OSError as exc:
|
| 200 |
+
log.warn("error removing %s: %s", directory, exc)
|
| 201 |
+
|
| 202 |
+
def ensure_relative(path):
|
| 203 |
+
"""Take the full path 'path', and make it a relative path.
|
| 204 |
+
|
| 205 |
+
This is useful to make 'path' the second argument to os.path.join().
|
| 206 |
+
"""
|
| 207 |
+
drive, path = os.path.splitdrive(path)
|
| 208 |
+
if path[0:1] == os.sep:
|
| 209 |
+
path = drive + path[1:]
|
| 210 |
+
return path
|
evalkit_cambrian/lib/python3.10/distutils/extension.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.extension
|
| 2 |
+
|
| 3 |
+
Provides the Extension class, used to describe C/C++ extension
|
| 4 |
+
modules in setup scripts."""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import re
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
# This class is really only used by the "build_ext" command, so it might
|
| 11 |
+
# make sense to put it in distutils.command.build_ext. However, that
|
| 12 |
+
# module is already big enough, and I want to make this class a bit more
|
| 13 |
+
# complex to simplify some common cases ("foo" module in "foo.c") and do
|
| 14 |
+
# better error-checking ("foo.c" actually exists).
|
| 15 |
+
#
|
| 16 |
+
# Also, putting this in build_ext.py means every setup script would have to
|
| 17 |
+
# import that large-ish module (indirectly, through distutils.core) in
|
| 18 |
+
# order to do anything.
|
| 19 |
+
|
| 20 |
+
class Extension:
|
| 21 |
+
"""Just a collection of attributes that describes an extension
|
| 22 |
+
module and everything needed to build it (hopefully in a portable
|
| 23 |
+
way, but there are hooks that let you be as unportable as you need).
|
| 24 |
+
|
| 25 |
+
Instance attributes:
|
| 26 |
+
name : string
|
| 27 |
+
the full name of the extension, including any packages -- ie.
|
| 28 |
+
*not* a filename or pathname, but Python dotted name
|
| 29 |
+
sources : [string]
|
| 30 |
+
list of source filenames, relative to the distribution root
|
| 31 |
+
(where the setup script lives), in Unix form (slash-separated)
|
| 32 |
+
for portability. Source files may be C, C++, SWIG (.i),
|
| 33 |
+
platform-specific resource files, or whatever else is recognized
|
| 34 |
+
by the "build_ext" command as source for a Python extension.
|
| 35 |
+
include_dirs : [string]
|
| 36 |
+
list of directories to search for C/C++ header files (in Unix
|
| 37 |
+
form for portability)
|
| 38 |
+
define_macros : [(name : string, value : string|None)]
|
| 39 |
+
list of macros to define; each macro is defined using a 2-tuple,
|
| 40 |
+
where 'value' is either the string to define it to or None to
|
| 41 |
+
define it without a particular value (equivalent of "#define
|
| 42 |
+
FOO" in source or -DFOO on Unix C compiler command line)
|
| 43 |
+
undef_macros : [string]
|
| 44 |
+
list of macros to undefine explicitly
|
| 45 |
+
library_dirs : [string]
|
| 46 |
+
list of directories to search for C/C++ libraries at link time
|
| 47 |
+
libraries : [string]
|
| 48 |
+
list of library names (not filenames or paths) to link against
|
| 49 |
+
runtime_library_dirs : [string]
|
| 50 |
+
list of directories to search for C/C++ libraries at run time
|
| 51 |
+
(for shared extensions, this is when the extension is loaded)
|
| 52 |
+
extra_objects : [string]
|
| 53 |
+
list of extra files to link with (eg. object files not implied
|
| 54 |
+
by 'sources', static library that must be explicitly specified,
|
| 55 |
+
binary resource files, etc.)
|
| 56 |
+
extra_compile_args : [string]
|
| 57 |
+
any extra platform- and compiler-specific information to use
|
| 58 |
+
when compiling the source files in 'sources'. For platforms and
|
| 59 |
+
compilers where "command line" makes sense, this is typically a
|
| 60 |
+
list of command-line arguments, but for other platforms it could
|
| 61 |
+
be anything.
|
| 62 |
+
extra_link_args : [string]
|
| 63 |
+
any extra platform- and compiler-specific information to use
|
| 64 |
+
when linking object files together to create the extension (or
|
| 65 |
+
to create a new static Python interpreter). Similar
|
| 66 |
+
interpretation as for 'extra_compile_args'.
|
| 67 |
+
export_symbols : [string]
|
| 68 |
+
list of symbols to be exported from a shared extension. Not
|
| 69 |
+
used on all platforms, and not generally necessary for Python
|
| 70 |
+
extensions, which typically export exactly one symbol: "init" +
|
| 71 |
+
extension_name.
|
| 72 |
+
swig_opts : [string]
|
| 73 |
+
any extra options to pass to SWIG if a source file has the .i
|
| 74 |
+
extension.
|
| 75 |
+
depends : [string]
|
| 76 |
+
list of files that the extension depends on
|
| 77 |
+
language : string
|
| 78 |
+
extension language (i.e. "c", "c++", "objc"). Will be detected
|
| 79 |
+
from the source extensions if not provided.
|
| 80 |
+
optional : boolean
|
| 81 |
+
specifies that a build failure in the extension should not abort the
|
| 82 |
+
build process, but simply not install the failing extension.
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
# When adding arguments to this constructor, be sure to update
|
| 86 |
+
# setup_keywords in core.py.
|
| 87 |
+
def __init__(self, name, sources,
|
| 88 |
+
include_dirs=None,
|
| 89 |
+
define_macros=None,
|
| 90 |
+
undef_macros=None,
|
| 91 |
+
library_dirs=None,
|
| 92 |
+
libraries=None,
|
| 93 |
+
runtime_library_dirs=None,
|
| 94 |
+
extra_objects=None,
|
| 95 |
+
extra_compile_args=None,
|
| 96 |
+
extra_link_args=None,
|
| 97 |
+
export_symbols=None,
|
| 98 |
+
swig_opts = None,
|
| 99 |
+
depends=None,
|
| 100 |
+
language=None,
|
| 101 |
+
optional=None,
|
| 102 |
+
**kw # To catch unknown keywords
|
| 103 |
+
):
|
| 104 |
+
if not isinstance(name, str):
|
| 105 |
+
raise AssertionError("'name' must be a string")
|
| 106 |
+
if not (isinstance(sources, list) and
|
| 107 |
+
all(isinstance(v, str) for v in sources)):
|
| 108 |
+
raise AssertionError("'sources' must be a list of strings")
|
| 109 |
+
|
| 110 |
+
self.name = name
|
| 111 |
+
self.sources = sources
|
| 112 |
+
self.include_dirs = include_dirs or []
|
| 113 |
+
self.define_macros = define_macros or []
|
| 114 |
+
self.undef_macros = undef_macros or []
|
| 115 |
+
self.library_dirs = library_dirs or []
|
| 116 |
+
self.libraries = libraries or []
|
| 117 |
+
self.runtime_library_dirs = runtime_library_dirs or []
|
| 118 |
+
self.extra_objects = extra_objects or []
|
| 119 |
+
self.extra_compile_args = extra_compile_args or []
|
| 120 |
+
self.extra_link_args = extra_link_args or []
|
| 121 |
+
self.export_symbols = export_symbols or []
|
| 122 |
+
self.swig_opts = swig_opts or []
|
| 123 |
+
self.depends = depends or []
|
| 124 |
+
self.language = language
|
| 125 |
+
self.optional = optional
|
| 126 |
+
|
| 127 |
+
# If there are unknown keyword options, warn about them
|
| 128 |
+
if len(kw) > 0:
|
| 129 |
+
options = [repr(option) for option in kw]
|
| 130 |
+
options = ', '.join(sorted(options))
|
| 131 |
+
msg = "Unknown Extension options: %s" % options
|
| 132 |
+
warnings.warn(msg)
|
| 133 |
+
|
| 134 |
+
def __repr__(self):
|
| 135 |
+
return '<%s.%s(%r) at %#x>' % (
|
| 136 |
+
self.__class__.__module__,
|
| 137 |
+
self.__class__.__qualname__,
|
| 138 |
+
self.name,
|
| 139 |
+
id(self))
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def read_setup_file(filename):
|
| 143 |
+
"""Reads a Setup file and returns Extension instances."""
|
| 144 |
+
from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
|
| 145 |
+
_variable_rx)
|
| 146 |
+
|
| 147 |
+
from distutils.text_file import TextFile
|
| 148 |
+
from distutils.util import split_quoted
|
| 149 |
+
|
| 150 |
+
# First pass over the file to gather "VAR = VALUE" assignments.
|
| 151 |
+
vars = parse_makefile(filename)
|
| 152 |
+
|
| 153 |
+
# Second pass to gobble up the real content: lines of the form
|
| 154 |
+
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
|
| 155 |
+
file = TextFile(filename,
|
| 156 |
+
strip_comments=1, skip_blanks=1, join_lines=1,
|
| 157 |
+
lstrip_ws=1, rstrip_ws=1)
|
| 158 |
+
try:
|
| 159 |
+
extensions = []
|
| 160 |
+
|
| 161 |
+
while True:
|
| 162 |
+
line = file.readline()
|
| 163 |
+
if line is None: # eof
|
| 164 |
+
break
|
| 165 |
+
if re.match(_variable_rx, line): # VAR=VALUE, handled in first pass
|
| 166 |
+
continue
|
| 167 |
+
|
| 168 |
+
if line[0] == line[-1] == "*":
|
| 169 |
+
file.warn("'%s' lines not handled yet" % line)
|
| 170 |
+
continue
|
| 171 |
+
|
| 172 |
+
line = expand_makefile_vars(line, vars)
|
| 173 |
+
words = split_quoted(line)
|
| 174 |
+
|
| 175 |
+
# NB. this parses a slightly different syntax than the old
|
| 176 |
+
# makesetup script: here, there must be exactly one extension per
|
| 177 |
+
# line, and it must be the first word of the line. I have no idea
|
| 178 |
+
# why the old syntax supported multiple extensions per line, as
|
| 179 |
+
# they all wind up being the same.
|
| 180 |
+
|
| 181 |
+
module = words[0]
|
| 182 |
+
ext = Extension(module, [])
|
| 183 |
+
append_next_word = None
|
| 184 |
+
|
| 185 |
+
for word in words[1:]:
|
| 186 |
+
if append_next_word is not None:
|
| 187 |
+
append_next_word.append(word)
|
| 188 |
+
append_next_word = None
|
| 189 |
+
continue
|
| 190 |
+
|
| 191 |
+
suffix = os.path.splitext(word)[1]
|
| 192 |
+
switch = word[0:2] ; value = word[2:]
|
| 193 |
+
|
| 194 |
+
if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"):
|
| 195 |
+
# hmm, should we do something about C vs. C++ sources?
|
| 196 |
+
# or leave it up to the CCompiler implementation to
|
| 197 |
+
# worry about?
|
| 198 |
+
ext.sources.append(word)
|
| 199 |
+
elif switch == "-I":
|
| 200 |
+
ext.include_dirs.append(value)
|
| 201 |
+
elif switch == "-D":
|
| 202 |
+
equals = value.find("=")
|
| 203 |
+
if equals == -1: # bare "-DFOO" -- no value
|
| 204 |
+
ext.define_macros.append((value, None))
|
| 205 |
+
else: # "-DFOO=blah"
|
| 206 |
+
ext.define_macros.append((value[0:equals],
|
| 207 |
+
value[equals+2:]))
|
| 208 |
+
elif switch == "-U":
|
| 209 |
+
ext.undef_macros.append(value)
|
| 210 |
+
elif switch == "-C": # only here 'cause makesetup has it!
|
| 211 |
+
ext.extra_compile_args.append(word)
|
| 212 |
+
elif switch == "-l":
|
| 213 |
+
ext.libraries.append(value)
|
| 214 |
+
elif switch == "-L":
|
| 215 |
+
ext.library_dirs.append(value)
|
| 216 |
+
elif switch == "-R":
|
| 217 |
+
ext.runtime_library_dirs.append(value)
|
| 218 |
+
elif word == "-rpath":
|
| 219 |
+
append_next_word = ext.runtime_library_dirs
|
| 220 |
+
elif word == "-Xlinker":
|
| 221 |
+
append_next_word = ext.extra_link_args
|
| 222 |
+
elif word == "-Xcompiler":
|
| 223 |
+
append_next_word = ext.extra_compile_args
|
| 224 |
+
elif switch == "-u":
|
| 225 |
+
ext.extra_link_args.append(word)
|
| 226 |
+
if not value:
|
| 227 |
+
append_next_word = ext.extra_link_args
|
| 228 |
+
elif suffix in (".a", ".so", ".sl", ".o", ".dylib"):
|
| 229 |
+
# NB. a really faithful emulation of makesetup would
|
| 230 |
+
# append a .o file to extra_objects only if it
|
| 231 |
+
# had a slash in it; otherwise, it would s/.o/.c/
|
| 232 |
+
# and append it to sources. Hmmmm.
|
| 233 |
+
ext.extra_objects.append(word)
|
| 234 |
+
else:
|
| 235 |
+
file.warn("unrecognized argument '%s'" % word)
|
| 236 |
+
|
| 237 |
+
extensions.append(ext)
|
| 238 |
+
finally:
|
| 239 |
+
file.close()
|
| 240 |
+
|
| 241 |
+
return extensions
|
evalkit_cambrian/lib/python3.10/distutils/fancy_getopt.py
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.fancy_getopt
|
| 2 |
+
|
| 3 |
+
Wrapper around the standard getopt module that provides the following
|
| 4 |
+
additional features:
|
| 5 |
+
* short and long options are tied together
|
| 6 |
+
* options have help strings, so fancy_getopt could potentially
|
| 7 |
+
create a complete usage summary
|
| 8 |
+
* options set attributes of a passed-in object
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import sys, string, re
|
| 12 |
+
import getopt
|
| 13 |
+
from distutils.errors import *
|
| 14 |
+
|
| 15 |
+
# Much like command_re in distutils.core, this is close to but not quite
|
| 16 |
+
# the same as a Python NAME -- except, in the spirit of most GNU
|
| 17 |
+
# utilities, we use '-' in place of '_'. (The spirit of LISP lives on!)
|
| 18 |
+
# The similarities to NAME are again not a coincidence...
|
| 19 |
+
longopt_pat = r'[a-zA-Z](?:[a-zA-Z0-9-]*)'
|
| 20 |
+
longopt_re = re.compile(r'^%s$' % longopt_pat)
|
| 21 |
+
|
| 22 |
+
# For recognizing "negative alias" options, eg. "quiet=!verbose"
|
| 23 |
+
neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))
|
| 24 |
+
|
| 25 |
+
# This is used to translate long options to legitimate Python identifiers
|
| 26 |
+
# (for use as attributes of some object).
|
| 27 |
+
longopt_xlate = str.maketrans('-', '_')
|
| 28 |
+
|
| 29 |
+
class FancyGetopt:
|
| 30 |
+
"""Wrapper around the standard 'getopt()' module that provides some
|
| 31 |
+
handy extra functionality:
|
| 32 |
+
* short and long options are tied together
|
| 33 |
+
* options have help strings, and help text can be assembled
|
| 34 |
+
from them
|
| 35 |
+
* options set attributes of a passed-in object
|
| 36 |
+
* boolean options can have "negative aliases" -- eg. if
|
| 37 |
+
--quiet is the "negative alias" of --verbose, then "--quiet"
|
| 38 |
+
on the command line sets 'verbose' to false
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
def __init__(self, option_table=None):
|
| 42 |
+
# The option table is (currently) a list of tuples. The
|
| 43 |
+
# tuples may have 3 or four values:
|
| 44 |
+
# (long_option, short_option, help_string [, repeatable])
|
| 45 |
+
# if an option takes an argument, its long_option should have '='
|
| 46 |
+
# appended; short_option should just be a single character, no ':'
|
| 47 |
+
# in any case. If a long_option doesn't have a corresponding
|
| 48 |
+
# short_option, short_option should be None. All option tuples
|
| 49 |
+
# must have long options.
|
| 50 |
+
self.option_table = option_table
|
| 51 |
+
|
| 52 |
+
# 'option_index' maps long option names to entries in the option
|
| 53 |
+
# table (ie. those 3-tuples).
|
| 54 |
+
self.option_index = {}
|
| 55 |
+
if self.option_table:
|
| 56 |
+
self._build_index()
|
| 57 |
+
|
| 58 |
+
# 'alias' records (duh) alias options; {'foo': 'bar'} means
|
| 59 |
+
# --foo is an alias for --bar
|
| 60 |
+
self.alias = {}
|
| 61 |
+
|
| 62 |
+
# 'negative_alias' keeps track of options that are the boolean
|
| 63 |
+
# opposite of some other option
|
| 64 |
+
self.negative_alias = {}
|
| 65 |
+
|
| 66 |
+
# These keep track of the information in the option table. We
|
| 67 |
+
# don't actually populate these structures until we're ready to
|
| 68 |
+
# parse the command-line, since the 'option_table' passed in here
|
| 69 |
+
# isn't necessarily the final word.
|
| 70 |
+
self.short_opts = []
|
| 71 |
+
self.long_opts = []
|
| 72 |
+
self.short2long = {}
|
| 73 |
+
self.attr_name = {}
|
| 74 |
+
self.takes_arg = {}
|
| 75 |
+
|
| 76 |
+
# And 'option_order' is filled up in 'getopt()'; it records the
|
| 77 |
+
# original order of options (and their values) on the command-line,
|
| 78 |
+
# but expands short options, converts aliases, etc.
|
| 79 |
+
self.option_order = []
|
| 80 |
+
|
| 81 |
+
def _build_index(self):
|
| 82 |
+
self.option_index.clear()
|
| 83 |
+
for option in self.option_table:
|
| 84 |
+
self.option_index[option[0]] = option
|
| 85 |
+
|
| 86 |
+
def set_option_table(self, option_table):
|
| 87 |
+
self.option_table = option_table
|
| 88 |
+
self._build_index()
|
| 89 |
+
|
| 90 |
+
def add_option(self, long_option, short_option=None, help_string=None):
|
| 91 |
+
if long_option in self.option_index:
|
| 92 |
+
raise DistutilsGetoptError(
|
| 93 |
+
"option conflict: already an option '%s'" % long_option)
|
| 94 |
+
else:
|
| 95 |
+
option = (long_option, short_option, help_string)
|
| 96 |
+
self.option_table.append(option)
|
| 97 |
+
self.option_index[long_option] = option
|
| 98 |
+
|
| 99 |
+
def has_option(self, long_option):
|
| 100 |
+
"""Return true if the option table for this parser has an
|
| 101 |
+
option with long name 'long_option'."""
|
| 102 |
+
return long_option in self.option_index
|
| 103 |
+
|
| 104 |
+
def get_attr_name(self, long_option):
|
| 105 |
+
"""Translate long option name 'long_option' to the form it
|
| 106 |
+
has as an attribute of some object: ie., translate hyphens
|
| 107 |
+
to underscores."""
|
| 108 |
+
return long_option.translate(longopt_xlate)
|
| 109 |
+
|
| 110 |
+
def _check_alias_dict(self, aliases, what):
|
| 111 |
+
assert isinstance(aliases, dict)
|
| 112 |
+
for (alias, opt) in aliases.items():
|
| 113 |
+
if alias not in self.option_index:
|
| 114 |
+
raise DistutilsGetoptError(("invalid %s '%s': "
|
| 115 |
+
"option '%s' not defined") % (what, alias, alias))
|
| 116 |
+
if opt not in self.option_index:
|
| 117 |
+
raise DistutilsGetoptError(("invalid %s '%s': "
|
| 118 |
+
"aliased option '%s' not defined") % (what, alias, opt))
|
| 119 |
+
|
| 120 |
+
def set_aliases(self, alias):
|
| 121 |
+
"""Set the aliases for this option parser."""
|
| 122 |
+
self._check_alias_dict(alias, "alias")
|
| 123 |
+
self.alias = alias
|
| 124 |
+
|
| 125 |
+
def set_negative_aliases(self, negative_alias):
|
| 126 |
+
"""Set the negative aliases for this option parser.
|
| 127 |
+
'negative_alias' should be a dictionary mapping option names to
|
| 128 |
+
option names, both the key and value must already be defined
|
| 129 |
+
in the option table."""
|
| 130 |
+
self._check_alias_dict(negative_alias, "negative alias")
|
| 131 |
+
self.negative_alias = negative_alias
|
| 132 |
+
|
| 133 |
+
def _grok_option_table(self):
|
| 134 |
+
"""Populate the various data structures that keep tabs on the
|
| 135 |
+
option table. Called by 'getopt()' before it can do anything
|
| 136 |
+
worthwhile.
|
| 137 |
+
"""
|
| 138 |
+
self.long_opts = []
|
| 139 |
+
self.short_opts = []
|
| 140 |
+
self.short2long.clear()
|
| 141 |
+
self.repeat = {}
|
| 142 |
+
|
| 143 |
+
for option in self.option_table:
|
| 144 |
+
if len(option) == 3:
|
| 145 |
+
long, short, help = option
|
| 146 |
+
repeat = 0
|
| 147 |
+
elif len(option) == 4:
|
| 148 |
+
long, short, help, repeat = option
|
| 149 |
+
else:
|
| 150 |
+
# the option table is part of the code, so simply
|
| 151 |
+
# assert that it is correct
|
| 152 |
+
raise ValueError("invalid option tuple: %r" % (option,))
|
| 153 |
+
|
| 154 |
+
# Type- and value-check the option names
|
| 155 |
+
if not isinstance(long, str) or len(long) < 2:
|
| 156 |
+
raise DistutilsGetoptError(("invalid long option '%s': "
|
| 157 |
+
"must be a string of length >= 2") % long)
|
| 158 |
+
|
| 159 |
+
if (not ((short is None) or
|
| 160 |
+
(isinstance(short, str) and len(short) == 1))):
|
| 161 |
+
raise DistutilsGetoptError("invalid short option '%s': "
|
| 162 |
+
"must a single character or None" % short)
|
| 163 |
+
|
| 164 |
+
self.repeat[long] = repeat
|
| 165 |
+
self.long_opts.append(long)
|
| 166 |
+
|
| 167 |
+
if long[-1] == '=': # option takes an argument?
|
| 168 |
+
if short: short = short + ':'
|
| 169 |
+
long = long[0:-1]
|
| 170 |
+
self.takes_arg[long] = 1
|
| 171 |
+
else:
|
| 172 |
+
# Is option is a "negative alias" for some other option (eg.
|
| 173 |
+
# "quiet" == "!verbose")?
|
| 174 |
+
alias_to = self.negative_alias.get(long)
|
| 175 |
+
if alias_to is not None:
|
| 176 |
+
if self.takes_arg[alias_to]:
|
| 177 |
+
raise DistutilsGetoptError(
|
| 178 |
+
"invalid negative alias '%s': "
|
| 179 |
+
"aliased option '%s' takes a value"
|
| 180 |
+
% (long, alias_to))
|
| 181 |
+
|
| 182 |
+
self.long_opts[-1] = long # XXX redundant?!
|
| 183 |
+
self.takes_arg[long] = 0
|
| 184 |
+
|
| 185 |
+
# If this is an alias option, make sure its "takes arg" flag is
|
| 186 |
+
# the same as the option it's aliased to.
|
| 187 |
+
alias_to = self.alias.get(long)
|
| 188 |
+
if alias_to is not None:
|
| 189 |
+
if self.takes_arg[long] != self.takes_arg[alias_to]:
|
| 190 |
+
raise DistutilsGetoptError(
|
| 191 |
+
"invalid alias '%s': inconsistent with "
|
| 192 |
+
"aliased option '%s' (one of them takes a value, "
|
| 193 |
+
"the other doesn't"
|
| 194 |
+
% (long, alias_to))
|
| 195 |
+
|
| 196 |
+
# Now enforce some bondage on the long option name, so we can
|
| 197 |
+
# later translate it to an attribute name on some object. Have
|
| 198 |
+
# to do this a bit late to make sure we've removed any trailing
|
| 199 |
+
# '='.
|
| 200 |
+
if not longopt_re.match(long):
|
| 201 |
+
raise DistutilsGetoptError(
|
| 202 |
+
"invalid long option name '%s' "
|
| 203 |
+
"(must be letters, numbers, hyphens only" % long)
|
| 204 |
+
|
| 205 |
+
self.attr_name[long] = self.get_attr_name(long)
|
| 206 |
+
if short:
|
| 207 |
+
self.short_opts.append(short)
|
| 208 |
+
self.short2long[short[0]] = long
|
| 209 |
+
|
| 210 |
+
def getopt(self, args=None, object=None):
|
| 211 |
+
"""Parse command-line options in args. Store as attributes on object.
|
| 212 |
+
|
| 213 |
+
If 'args' is None or not supplied, uses 'sys.argv[1:]'. If
|
| 214 |
+
'object' is None or not supplied, creates a new OptionDummy
|
| 215 |
+
object, stores option values there, and returns a tuple (args,
|
| 216 |
+
object). If 'object' is supplied, it is modified in place and
|
| 217 |
+
'getopt()' just returns 'args'; in both cases, the returned
|
| 218 |
+
'args' is a modified copy of the passed-in 'args' list, which
|
| 219 |
+
is left untouched.
|
| 220 |
+
"""
|
| 221 |
+
if args is None:
|
| 222 |
+
args = sys.argv[1:]
|
| 223 |
+
if object is None:
|
| 224 |
+
object = OptionDummy()
|
| 225 |
+
created_object = True
|
| 226 |
+
else:
|
| 227 |
+
created_object = False
|
| 228 |
+
|
| 229 |
+
self._grok_option_table()
|
| 230 |
+
|
| 231 |
+
short_opts = ' '.join(self.short_opts)
|
| 232 |
+
try:
|
| 233 |
+
opts, args = getopt.getopt(args, short_opts, self.long_opts)
|
| 234 |
+
except getopt.error as msg:
|
| 235 |
+
raise DistutilsArgError(msg)
|
| 236 |
+
|
| 237 |
+
for opt, val in opts:
|
| 238 |
+
if len(opt) == 2 and opt[0] == '-': # it's a short option
|
| 239 |
+
opt = self.short2long[opt[1]]
|
| 240 |
+
else:
|
| 241 |
+
assert len(opt) > 2 and opt[:2] == '--'
|
| 242 |
+
opt = opt[2:]
|
| 243 |
+
|
| 244 |
+
alias = self.alias.get(opt)
|
| 245 |
+
if alias:
|
| 246 |
+
opt = alias
|
| 247 |
+
|
| 248 |
+
if not self.takes_arg[opt]: # boolean option?
|
| 249 |
+
assert val == '', "boolean option can't have value"
|
| 250 |
+
alias = self.negative_alias.get(opt)
|
| 251 |
+
if alias:
|
| 252 |
+
opt = alias
|
| 253 |
+
val = 0
|
| 254 |
+
else:
|
| 255 |
+
val = 1
|
| 256 |
+
|
| 257 |
+
attr = self.attr_name[opt]
|
| 258 |
+
# The only repeating option at the moment is 'verbose'.
|
| 259 |
+
# It has a negative option -q quiet, which should set verbose = 0.
|
| 260 |
+
if val and self.repeat.get(attr) is not None:
|
| 261 |
+
val = getattr(object, attr, 0) + 1
|
| 262 |
+
setattr(object, attr, val)
|
| 263 |
+
self.option_order.append((opt, val))
|
| 264 |
+
|
| 265 |
+
# for opts
|
| 266 |
+
if created_object:
|
| 267 |
+
return args, object
|
| 268 |
+
else:
|
| 269 |
+
return args
|
| 270 |
+
|
| 271 |
+
def get_option_order(self):
|
| 272 |
+
"""Returns the list of (option, value) tuples processed by the
|
| 273 |
+
previous run of 'getopt()'. Raises RuntimeError if
|
| 274 |
+
'getopt()' hasn't been called yet.
|
| 275 |
+
"""
|
| 276 |
+
if self.option_order is None:
|
| 277 |
+
raise RuntimeError("'getopt()' hasn't been called yet")
|
| 278 |
+
else:
|
| 279 |
+
return self.option_order
|
| 280 |
+
|
| 281 |
+
def generate_help(self, header=None):
|
| 282 |
+
"""Generate help text (a list of strings, one per suggested line of
|
| 283 |
+
output) from the option table for this FancyGetopt object.
|
| 284 |
+
"""
|
| 285 |
+
# Blithely assume the option table is good: probably wouldn't call
|
| 286 |
+
# 'generate_help()' unless you've already called 'getopt()'.
|
| 287 |
+
|
| 288 |
+
# First pass: determine maximum length of long option names
|
| 289 |
+
max_opt = 0
|
| 290 |
+
for option in self.option_table:
|
| 291 |
+
long = option[0]
|
| 292 |
+
short = option[1]
|
| 293 |
+
l = len(long)
|
| 294 |
+
if long[-1] == '=':
|
| 295 |
+
l = l - 1
|
| 296 |
+
if short is not None:
|
| 297 |
+
l = l + 5 # " (-x)" where short == 'x'
|
| 298 |
+
if l > max_opt:
|
| 299 |
+
max_opt = l
|
| 300 |
+
|
| 301 |
+
opt_width = max_opt + 2 + 2 + 2 # room for indent + dashes + gutter
|
| 302 |
+
|
| 303 |
+
# Typical help block looks like this:
|
| 304 |
+
# --foo controls foonabulation
|
| 305 |
+
# Help block for longest option looks like this:
|
| 306 |
+
# --flimflam set the flim-flam level
|
| 307 |
+
# and with wrapped text:
|
| 308 |
+
# --flimflam set the flim-flam level (must be between
|
| 309 |
+
# 0 and 100, except on Tuesdays)
|
| 310 |
+
# Options with short names will have the short name shown (but
|
| 311 |
+
# it doesn't contribute to max_opt):
|
| 312 |
+
# --foo (-f) controls foonabulation
|
| 313 |
+
# If adding the short option would make the left column too wide,
|
| 314 |
+
# we push the explanation off to the next line
|
| 315 |
+
# --flimflam (-l)
|
| 316 |
+
# set the flim-flam level
|
| 317 |
+
# Important parameters:
|
| 318 |
+
# - 2 spaces before option block start lines
|
| 319 |
+
# - 2 dashes for each long option name
|
| 320 |
+
# - min. 2 spaces between option and explanation (gutter)
|
| 321 |
+
# - 5 characters (incl. space) for short option name
|
| 322 |
+
|
| 323 |
+
# Now generate lines of help text. (If 80 columns were good enough
|
| 324 |
+
# for Jesus, then 78 columns are good enough for me!)
|
| 325 |
+
line_width = 78
|
| 326 |
+
text_width = line_width - opt_width
|
| 327 |
+
big_indent = ' ' * opt_width
|
| 328 |
+
if header:
|
| 329 |
+
lines = [header]
|
| 330 |
+
else:
|
| 331 |
+
lines = ['Option summary:']
|
| 332 |
+
|
| 333 |
+
for option in self.option_table:
|
| 334 |
+
long, short, help = option[:3]
|
| 335 |
+
text = wrap_text(help, text_width)
|
| 336 |
+
if long[-1] == '=':
|
| 337 |
+
long = long[0:-1]
|
| 338 |
+
|
| 339 |
+
# Case 1: no short option at all (makes life easy)
|
| 340 |
+
if short is None:
|
| 341 |
+
if text:
|
| 342 |
+
lines.append(" --%-*s %s" % (max_opt, long, text[0]))
|
| 343 |
+
else:
|
| 344 |
+
lines.append(" --%-*s " % (max_opt, long))
|
| 345 |
+
|
| 346 |
+
# Case 2: we have a short option, so we have to include it
|
| 347 |
+
# just after the long option
|
| 348 |
+
else:
|
| 349 |
+
opt_names = "%s (-%s)" % (long, short)
|
| 350 |
+
if text:
|
| 351 |
+
lines.append(" --%-*s %s" %
|
| 352 |
+
(max_opt, opt_names, text[0]))
|
| 353 |
+
else:
|
| 354 |
+
lines.append(" --%-*s" % opt_names)
|
| 355 |
+
|
| 356 |
+
for l in text[1:]:
|
| 357 |
+
lines.append(big_indent + l)
|
| 358 |
+
return lines
|
| 359 |
+
|
| 360 |
+
def print_help(self, header=None, file=None):
|
| 361 |
+
if file is None:
|
| 362 |
+
file = sys.stdout
|
| 363 |
+
for line in self.generate_help(header):
|
| 364 |
+
file.write(line + "\n")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def fancy_getopt(options, negative_opt, object, args):
|
| 368 |
+
parser = FancyGetopt(options)
|
| 369 |
+
parser.set_negative_aliases(negative_opt)
|
| 370 |
+
return parser.getopt(args, object)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace}
|
| 374 |
+
|
| 375 |
+
def wrap_text(text, width):
|
| 376 |
+
"""wrap_text(text : string, width : int) -> [string]
|
| 377 |
+
|
| 378 |
+
Split 'text' into multiple lines of no more than 'width' characters
|
| 379 |
+
each, and return the list of strings that results.
|
| 380 |
+
"""
|
| 381 |
+
if text is None:
|
| 382 |
+
return []
|
| 383 |
+
if len(text) <= width:
|
| 384 |
+
return [text]
|
| 385 |
+
|
| 386 |
+
text = text.expandtabs()
|
| 387 |
+
text = text.translate(WS_TRANS)
|
| 388 |
+
chunks = re.split(r'( +|-+)', text)
|
| 389 |
+
chunks = [ch for ch in chunks if ch] # ' - ' results in empty strings
|
| 390 |
+
lines = []
|
| 391 |
+
|
| 392 |
+
while chunks:
|
| 393 |
+
cur_line = [] # list of chunks (to-be-joined)
|
| 394 |
+
cur_len = 0 # length of current line
|
| 395 |
+
|
| 396 |
+
while chunks:
|
| 397 |
+
l = len(chunks[0])
|
| 398 |
+
if cur_len + l <= width: # can squeeze (at least) this chunk in
|
| 399 |
+
cur_line.append(chunks[0])
|
| 400 |
+
del chunks[0]
|
| 401 |
+
cur_len = cur_len + l
|
| 402 |
+
else: # this line is full
|
| 403 |
+
# drop last chunk if all space
|
| 404 |
+
if cur_line and cur_line[-1][0] == ' ':
|
| 405 |
+
del cur_line[-1]
|
| 406 |
+
break
|
| 407 |
+
|
| 408 |
+
if chunks: # any chunks left to process?
|
| 409 |
+
# if the current line is still empty, then we had a single
|
| 410 |
+
# chunk that's too big too fit on a line -- so we break
|
| 411 |
+
# down and break it up at the line width
|
| 412 |
+
if cur_len == 0:
|
| 413 |
+
cur_line.append(chunks[0][0:width])
|
| 414 |
+
chunks[0] = chunks[0][width:]
|
| 415 |
+
|
| 416 |
+
# all-whitespace chunks at the end of a line can be discarded
|
| 417 |
+
# (and we know from the re.split above that if a chunk has
|
| 418 |
+
# *any* whitespace, it is *all* whitespace)
|
| 419 |
+
if chunks[0][0] == ' ':
|
| 420 |
+
del chunks[0]
|
| 421 |
+
|
| 422 |
+
# and store this line in the list-of-all-lines -- as a single
|
| 423 |
+
# string, of course!
|
| 424 |
+
lines.append(''.join(cur_line))
|
| 425 |
+
|
| 426 |
+
return lines
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def translate_longopt(opt):
|
| 430 |
+
"""Convert a long option name to a valid Python identifier by
|
| 431 |
+
changing "-" to "_".
|
| 432 |
+
"""
|
| 433 |
+
return opt.translate(longopt_xlate)
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
class OptionDummy:
|
| 437 |
+
"""Dummy class just used as a place to hold command-line option
|
| 438 |
+
values as instance attributes."""
|
| 439 |
+
|
| 440 |
+
def __init__(self, options=[]):
|
| 441 |
+
"""Create a new OptionDummy instance. The attributes listed in
|
| 442 |
+
'options' will be initialized to None."""
|
| 443 |
+
for opt in options:
|
| 444 |
+
setattr(self, opt, None)
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
if __name__ == "__main__":
|
| 448 |
+
text = """\
|
| 449 |
+
Tra-la-la, supercalifragilisticexpialidocious.
|
| 450 |
+
How *do* you spell that odd word, anyways?
|
| 451 |
+
(Someone ask Mary -- she'll know [or she'll
|
| 452 |
+
say, "How should I know?"].)"""
|
| 453 |
+
|
| 454 |
+
for w in (10, 20, 30, 40):
|
| 455 |
+
print("width: %d" % w)
|
| 456 |
+
print("\n".join(wrap_text(text, w)))
|
| 457 |
+
print()
|
evalkit_cambrian/lib/python3.10/distutils/log.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A simple log mechanism styled after PEP 282."""
|
| 2 |
+
|
| 3 |
+
# The class here is styled after PEP 282 so that it could later be
|
| 4 |
+
# replaced with a standard Python logging implementation.
|
| 5 |
+
|
| 6 |
+
DEBUG = 1
|
| 7 |
+
INFO = 2
|
| 8 |
+
WARN = 3
|
| 9 |
+
ERROR = 4
|
| 10 |
+
FATAL = 5
|
| 11 |
+
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
class Log:
|
| 15 |
+
|
| 16 |
+
def __init__(self, threshold=WARN):
|
| 17 |
+
self.threshold = threshold
|
| 18 |
+
|
| 19 |
+
def _log(self, level, msg, args):
|
| 20 |
+
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
|
| 21 |
+
raise ValueError('%s wrong log level' % str(level))
|
| 22 |
+
|
| 23 |
+
if level >= self.threshold:
|
| 24 |
+
if args:
|
| 25 |
+
msg = msg % args
|
| 26 |
+
if level in (WARN, ERROR, FATAL):
|
| 27 |
+
stream = sys.stderr
|
| 28 |
+
else:
|
| 29 |
+
stream = sys.stdout
|
| 30 |
+
try:
|
| 31 |
+
stream.write('%s\n' % msg)
|
| 32 |
+
except UnicodeEncodeError:
|
| 33 |
+
# emulate backslashreplace error handler
|
| 34 |
+
encoding = stream.encoding
|
| 35 |
+
msg = msg.encode(encoding, "backslashreplace").decode(encoding)
|
| 36 |
+
stream.write('%s\n' % msg)
|
| 37 |
+
stream.flush()
|
| 38 |
+
|
| 39 |
+
def log(self, level, msg, *args):
|
| 40 |
+
self._log(level, msg, args)
|
| 41 |
+
|
| 42 |
+
def debug(self, msg, *args):
|
| 43 |
+
self._log(DEBUG, msg, args)
|
| 44 |
+
|
| 45 |
+
def info(self, msg, *args):
|
| 46 |
+
self._log(INFO, msg, args)
|
| 47 |
+
|
| 48 |
+
def warn(self, msg, *args):
|
| 49 |
+
self._log(WARN, msg, args)
|
| 50 |
+
|
| 51 |
+
def error(self, msg, *args):
|
| 52 |
+
self._log(ERROR, msg, args)
|
| 53 |
+
|
| 54 |
+
def fatal(self, msg, *args):
|
| 55 |
+
self._log(FATAL, msg, args)
|
| 56 |
+
|
| 57 |
+
_global_log = Log()
|
| 58 |
+
log = _global_log.log
|
| 59 |
+
debug = _global_log.debug
|
| 60 |
+
info = _global_log.info
|
| 61 |
+
warn = _global_log.warn
|
| 62 |
+
error = _global_log.error
|
| 63 |
+
fatal = _global_log.fatal
|
| 64 |
+
|
| 65 |
+
def set_threshold(level):
|
| 66 |
+
# return the old threshold for use from tests
|
| 67 |
+
old = _global_log.threshold
|
| 68 |
+
_global_log.threshold = level
|
| 69 |
+
return old
|
| 70 |
+
|
| 71 |
+
def set_verbosity(v):
|
| 72 |
+
if v <= 0:
|
| 73 |
+
set_threshold(WARN)
|
| 74 |
+
elif v == 1:
|
| 75 |
+
set_threshold(INFO)
|
| 76 |
+
elif v >= 2:
|
| 77 |
+
set_threshold(DEBUG)
|
evalkit_cambrian/lib/python3.10/distutils/spawn.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.spawn
|
| 2 |
+
|
| 3 |
+
Provides the 'spawn()' function, a front-end to various platform-
|
| 4 |
+
specific functions for launching another program in a sub-process.
|
| 5 |
+
Also provides the 'find_executable()' to search the path for a given
|
| 6 |
+
executable name.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import sys
|
| 10 |
+
import os
|
| 11 |
+
import subprocess
|
| 12 |
+
|
| 13 |
+
from distutils.errors import DistutilsPlatformError, DistutilsExecError
|
| 14 |
+
from distutils.debug import DEBUG
|
| 15 |
+
from distutils import log
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
if sys.platform == 'darwin':
|
| 19 |
+
_cfg_target = None
|
| 20 |
+
_cfg_target_split = None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def spawn(cmd, search_path=1, verbose=0, dry_run=0):
|
| 24 |
+
"""Run another program, specified as a command list 'cmd', in a new process.
|
| 25 |
+
|
| 26 |
+
'cmd' is just the argument list for the new process, ie.
|
| 27 |
+
cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
|
| 28 |
+
There is no way to run a program with a name different from that of its
|
| 29 |
+
executable.
|
| 30 |
+
|
| 31 |
+
If 'search_path' is true (the default), the system's executable
|
| 32 |
+
search path will be used to find the program; otherwise, cmd[0]
|
| 33 |
+
must be the exact path to the executable. If 'dry_run' is true,
|
| 34 |
+
the command will not actually be run.
|
| 35 |
+
|
| 36 |
+
Raise DistutilsExecError if running the program fails in any way; just
|
| 37 |
+
return on success.
|
| 38 |
+
"""
|
| 39 |
+
# cmd is documented as a list, but just in case some code passes a tuple
|
| 40 |
+
# in, protect our %-formatting code against horrible death
|
| 41 |
+
cmd = list(cmd)
|
| 42 |
+
|
| 43 |
+
log.info(' '.join(cmd))
|
| 44 |
+
if dry_run:
|
| 45 |
+
return
|
| 46 |
+
|
| 47 |
+
if search_path:
|
| 48 |
+
executable = find_executable(cmd[0])
|
| 49 |
+
if executable is not None:
|
| 50 |
+
cmd[0] = executable
|
| 51 |
+
|
| 52 |
+
env = None
|
| 53 |
+
if sys.platform == 'darwin':
|
| 54 |
+
global _cfg_target, _cfg_target_split
|
| 55 |
+
if _cfg_target is None:
|
| 56 |
+
from distutils import sysconfig
|
| 57 |
+
_cfg_target = sysconfig.get_config_var(
|
| 58 |
+
'MACOSX_DEPLOYMENT_TARGET') or ''
|
| 59 |
+
if _cfg_target:
|
| 60 |
+
_cfg_target_split = [int(x) for x in _cfg_target.split('.')]
|
| 61 |
+
if _cfg_target:
|
| 62 |
+
# Ensure that the deployment target of the build process is not
|
| 63 |
+
# less than 10.3 if the interpreter was built for 10.3 or later.
|
| 64 |
+
# This ensures extension modules are built with correct
|
| 65 |
+
# compatibility values, specifically LDSHARED which can use
|
| 66 |
+
# '-undefined dynamic_lookup' which only works on >= 10.3.
|
| 67 |
+
cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
|
| 68 |
+
cur_target_split = [int(x) for x in cur_target.split('.')]
|
| 69 |
+
if _cfg_target_split[:2] >= [10, 3] and cur_target_split[:2] < [10, 3]:
|
| 70 |
+
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
|
| 71 |
+
'now "%s" but "%s" during configure;'
|
| 72 |
+
'must use 10.3 or later'
|
| 73 |
+
% (cur_target, _cfg_target))
|
| 74 |
+
raise DistutilsPlatformError(my_msg)
|
| 75 |
+
env = dict(os.environ,
|
| 76 |
+
MACOSX_DEPLOYMENT_TARGET=cur_target)
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
proc = subprocess.Popen(cmd, env=env)
|
| 80 |
+
proc.wait()
|
| 81 |
+
exitcode = proc.returncode
|
| 82 |
+
except OSError as exc:
|
| 83 |
+
if not DEBUG:
|
| 84 |
+
cmd = cmd[0]
|
| 85 |
+
raise DistutilsExecError(
|
| 86 |
+
"command %r failed: %s" % (cmd, exc.args[-1])) from exc
|
| 87 |
+
|
| 88 |
+
if exitcode:
|
| 89 |
+
if not DEBUG:
|
| 90 |
+
cmd = cmd[0]
|
| 91 |
+
raise DistutilsExecError(
|
| 92 |
+
"command %r failed with exit code %s" % (cmd, exitcode))
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def find_executable(executable, path=None):
|
| 96 |
+
"""Tries to find 'executable' in the directories listed in 'path'.
|
| 97 |
+
|
| 98 |
+
A string listing directories separated by 'os.pathsep'; defaults to
|
| 99 |
+
os.environ['PATH']. Returns the complete filename or None if not found.
|
| 100 |
+
"""
|
| 101 |
+
_, ext = os.path.splitext(executable)
|
| 102 |
+
if (sys.platform == 'win32') and (ext != '.exe'):
|
| 103 |
+
executable = executable + '.exe'
|
| 104 |
+
|
| 105 |
+
if os.path.isfile(executable):
|
| 106 |
+
return executable
|
| 107 |
+
|
| 108 |
+
if path is None:
|
| 109 |
+
path = os.environ.get('PATH', None)
|
| 110 |
+
if path is None:
|
| 111 |
+
try:
|
| 112 |
+
path = os.confstr("CS_PATH")
|
| 113 |
+
except (AttributeError, ValueError):
|
| 114 |
+
# os.confstr() or CS_PATH is not available
|
| 115 |
+
path = os.defpath
|
| 116 |
+
# bpo-35755: Don't use os.defpath if the PATH environment variable is
|
| 117 |
+
# set to an empty string
|
| 118 |
+
|
| 119 |
+
# PATH='' doesn't match, whereas PATH=':' looks in the current directory
|
| 120 |
+
if not path:
|
| 121 |
+
return None
|
| 122 |
+
|
| 123 |
+
paths = path.split(os.pathsep)
|
| 124 |
+
for p in paths:
|
| 125 |
+
f = os.path.join(p, executable)
|
| 126 |
+
if os.path.isfile(f):
|
| 127 |
+
# the file exists, we have a shot at spawn working
|
| 128 |
+
return f
|
| 129 |
+
return None
|
evalkit_cambrian/lib/python3.10/distutils/tests/Setup.sample
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Setup file from the pygame project
|
| 2 |
+
|
| 3 |
+
#--StartConfig
|
| 4 |
+
SDL = -I/usr/include/SDL -D_REENTRANT -lSDL
|
| 5 |
+
FONT = -lSDL_ttf
|
| 6 |
+
IMAGE = -lSDL_image
|
| 7 |
+
MIXER = -lSDL_mixer
|
| 8 |
+
SMPEG = -lsmpeg
|
| 9 |
+
PNG = -lpng
|
| 10 |
+
JPEG = -ljpeg
|
| 11 |
+
SCRAP = -lX11
|
| 12 |
+
PORTMIDI = -lportmidi
|
| 13 |
+
PORTTIME = -lporttime
|
| 14 |
+
#--EndConfig
|
| 15 |
+
|
| 16 |
+
#DEBUG = -C-W -C-Wall
|
| 17 |
+
DEBUG =
|
| 18 |
+
|
| 19 |
+
#the following modules are optional. you will want to compile
|
| 20 |
+
#everything you can, but you can ignore ones you don't have
|
| 21 |
+
#dependencies for, just comment them out
|
| 22 |
+
|
| 23 |
+
imageext src/imageext.c $(SDL) $(IMAGE) $(PNG) $(JPEG) $(DEBUG)
|
| 24 |
+
font src/font.c $(SDL) $(FONT) $(DEBUG)
|
| 25 |
+
mixer src/mixer.c $(SDL) $(MIXER) $(DEBUG)
|
| 26 |
+
mixer_music src/music.c $(SDL) $(MIXER) $(DEBUG)
|
| 27 |
+
_numericsurfarray src/_numericsurfarray.c $(SDL) $(DEBUG)
|
| 28 |
+
_numericsndarray src/_numericsndarray.c $(SDL) $(MIXER) $(DEBUG)
|
| 29 |
+
movie src/movie.c $(SDL) $(SMPEG) $(DEBUG)
|
| 30 |
+
scrap src/scrap.c $(SDL) $(SCRAP) $(DEBUG)
|
| 31 |
+
_camera src/_camera.c src/camera_v4l2.c src/camera_v4l.c $(SDL) $(DEBUG)
|
| 32 |
+
pypm src/pypm.c $(SDL) $(PORTMIDI) $(PORTTIME) $(DEBUG)
|
| 33 |
+
|
| 34 |
+
GFX = src/SDL_gfx/SDL_gfxPrimitives.c
|
| 35 |
+
#GFX = src/SDL_gfx/SDL_gfxBlitFunc.c src/SDL_gfx/SDL_gfxPrimitives.c
|
| 36 |
+
gfxdraw src/gfxdraw.c $(SDL) $(GFX) $(DEBUG)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
#these modules are required for pygame to run. they only require
|
| 41 |
+
#SDL as a dependency. these should not be altered
|
| 42 |
+
|
| 43 |
+
base src/base.c $(SDL) $(DEBUG)
|
| 44 |
+
cdrom src/cdrom.c $(SDL) $(DEBUG)
|
| 45 |
+
color src/color.c $(SDL) $(DEBUG)
|
| 46 |
+
constants src/constants.c $(SDL) $(DEBUG)
|
| 47 |
+
display src/display.c $(SDL) $(DEBUG)
|
| 48 |
+
event src/event.c $(SDL) $(DEBUG)
|
| 49 |
+
fastevent src/fastevent.c src/fastevents.c $(SDL) $(DEBUG)
|
| 50 |
+
key src/key.c $(SDL) $(DEBUG)
|
| 51 |
+
mouse src/mouse.c $(SDL) $(DEBUG)
|
| 52 |
+
rect src/rect.c $(SDL) $(DEBUG)
|
| 53 |
+
rwobject src/rwobject.c $(SDL) $(DEBUG)
|
| 54 |
+
surface src/surface.c src/alphablit.c src/surface_fill.c $(SDL) $(DEBUG)
|
| 55 |
+
surflock src/surflock.c $(SDL) $(DEBUG)
|
| 56 |
+
time src/time.c $(SDL) $(DEBUG)
|
| 57 |
+
joystick src/joystick.c $(SDL) $(DEBUG)
|
| 58 |
+
draw src/draw.c $(SDL) $(DEBUG)
|
| 59 |
+
image src/image.c $(SDL) $(DEBUG)
|
| 60 |
+
overlay src/overlay.c $(SDL) $(DEBUG)
|
| 61 |
+
transform src/transform.c src/rotozoom.c src/scale2x.c src/scale_mmx.c $(SDL) $(DEBUG)
|
| 62 |
+
mask src/mask.c src/bitmask.c $(SDL) $(DEBUG)
|
| 63 |
+
bufferproxy src/bufferproxy.c $(SDL) $(DEBUG)
|
| 64 |
+
pixelarray src/pixelarray.c $(SDL) $(DEBUG)
|
| 65 |
+
_arraysurfarray src/_arraysurfarray.c $(SDL) $(DEBUG)
|
| 66 |
+
|
| 67 |
+
|
evalkit_cambrian/lib/python3.10/distutils/tests/__init__.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test suite for distutils.
|
| 2 |
+
|
| 3 |
+
This test suite consists of a collection of test modules in the
|
| 4 |
+
distutils.tests package. Each test module has a name starting with
|
| 5 |
+
'test' and contains a function test_suite(). The function is expected
|
| 6 |
+
to return an initialized unittest.TestSuite instance.
|
| 7 |
+
|
| 8 |
+
Tests for the command classes in the distutils.command package are
|
| 9 |
+
included in distutils.tests as well, instead of using a separate
|
| 10 |
+
distutils.command.tests package, since command identification is done
|
| 11 |
+
by import rather than matching pre-defined names.
|
| 12 |
+
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
import sys
|
| 17 |
+
import unittest
|
| 18 |
+
from test.support import run_unittest
|
| 19 |
+
from test.support.warnings_helper import save_restore_warnings_filters
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
here = os.path.dirname(__file__) or os.curdir
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_suite():
|
| 26 |
+
suite = unittest.TestSuite()
|
| 27 |
+
for fn in os.listdir(here):
|
| 28 |
+
if fn.startswith("test") and fn.endswith(".py"):
|
| 29 |
+
modname = "distutils.tests." + fn[:-3]
|
| 30 |
+
# bpo-40055: Save/restore warnings filters to leave them unchanged.
|
| 31 |
+
# Importing tests imports docutils which imports pkg_resources
|
| 32 |
+
# which adds a warnings filter.
|
| 33 |
+
with save_restore_warnings_filters():
|
| 34 |
+
__import__(modname)
|
| 35 |
+
module = sys.modules[modname]
|
| 36 |
+
suite.addTest(module.test_suite())
|
| 37 |
+
return suite
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_bdist.cpython-310.pyc
ADDED
|
Binary file (2.04 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_bdist_dumb.cpython-310.pyc
ADDED
|
Binary file (3.12 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_bdist_msi.cpython-310.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_build_ext.cpython-310.pyc
ADDED
|
Binary file (14 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_build_py.cpython-310.pyc
ADDED
|
Binary file (5.02 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_build_scripts.cpython-310.pyc
ADDED
|
Binary file (3.73 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_cmd.cpython-310.pyc
ADDED
|
Binary file (4.32 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_cygwinccompiler.cpython-310.pyc
ADDED
|
Binary file (4.74 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_dep_util.cpython-310.pyc
ADDED
|
Binary file (2.55 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_extension.cpython-310.pyc
ADDED
|
Binary file (2.73 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_file_util.cpython-310.pyc
ADDED
|
Binary file (4.93 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_filelist.cpython-310.pyc
ADDED
|
Binary file (8.68 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_install_data.cpython-310.pyc
ADDED
|
Binary file (1.95 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_install_scripts.cpython-310.pyc
ADDED
|
Binary file (2.45 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_msvc9compiler.cpython-310.pyc
ADDED
|
Binary file (5.93 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_msvccompiler.cpython-310.pyc
ADDED
|
Binary file (2.81 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_register.cpython-310.pyc
ADDED
|
Binary file (8.44 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_sysconfig.cpython-310.pyc
ADDED
|
Binary file (8.84 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_text_file.cpython-310.pyc
ADDED
|
Binary file (2.65 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_unixccompiler.cpython-310.pyc
ADDED
|
Binary file (4.75 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_upload.cpython-310.pyc
ADDED
|
Binary file (7.1 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/__pycache__/test_versionpredicate.cpython-310.pyc
ADDED
|
Binary file (529 Bytes). View file
|
|
|
evalkit_cambrian/lib/python3.10/distutils/tests/includetest.rst
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
This should be included.
|
evalkit_cambrian/lib/python3.10/distutils/tests/support.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Support code for distutils test cases."""
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import shutil
|
| 5 |
+
import tempfile
|
| 6 |
+
import unittest
|
| 7 |
+
import sysconfig
|
| 8 |
+
from copy import deepcopy
|
| 9 |
+
from test.support import os_helper
|
| 10 |
+
|
| 11 |
+
from distutils import log
|
| 12 |
+
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
|
| 13 |
+
from distutils.core import Distribution
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class LoggingSilencer(object):
|
| 17 |
+
|
| 18 |
+
def setUp(self):
|
| 19 |
+
super().setUp()
|
| 20 |
+
self.threshold = log.set_threshold(log.FATAL)
|
| 21 |
+
# catching warnings
|
| 22 |
+
# when log will be replaced by logging
|
| 23 |
+
# we won't need such monkey-patch anymore
|
| 24 |
+
self._old_log = log.Log._log
|
| 25 |
+
log.Log._log = self._log
|
| 26 |
+
self.logs = []
|
| 27 |
+
|
| 28 |
+
def tearDown(self):
|
| 29 |
+
log.set_threshold(self.threshold)
|
| 30 |
+
log.Log._log = self._old_log
|
| 31 |
+
super().tearDown()
|
| 32 |
+
|
| 33 |
+
def _log(self, level, msg, args):
|
| 34 |
+
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
|
| 35 |
+
raise ValueError('%s wrong log level' % str(level))
|
| 36 |
+
if not isinstance(msg, str):
|
| 37 |
+
raise TypeError("msg should be str, not '%.200s'"
|
| 38 |
+
% (type(msg).__name__))
|
| 39 |
+
self.logs.append((level, msg, args))
|
| 40 |
+
|
| 41 |
+
def get_logs(self, *levels):
|
| 42 |
+
return [msg % args for level, msg, args
|
| 43 |
+
in self.logs if level in levels]
|
| 44 |
+
|
| 45 |
+
def clear_logs(self):
|
| 46 |
+
self.logs = []
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class TempdirManager(object):
|
| 50 |
+
"""Mix-in class that handles temporary directories for test cases.
|
| 51 |
+
|
| 52 |
+
This is intended to be used with unittest.TestCase.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def setUp(self):
|
| 56 |
+
super().setUp()
|
| 57 |
+
self.old_cwd = os.getcwd()
|
| 58 |
+
self.tempdirs = []
|
| 59 |
+
|
| 60 |
+
def tearDown(self):
|
| 61 |
+
# Restore working dir, for Solaris and derivatives, where rmdir()
|
| 62 |
+
# on the current directory fails.
|
| 63 |
+
os.chdir(self.old_cwd)
|
| 64 |
+
super().tearDown()
|
| 65 |
+
while self.tempdirs:
|
| 66 |
+
tmpdir = self.tempdirs.pop()
|
| 67 |
+
os_helper.rmtree(tmpdir)
|
| 68 |
+
|
| 69 |
+
def mkdtemp(self):
|
| 70 |
+
"""Create a temporary directory that will be cleaned up.
|
| 71 |
+
|
| 72 |
+
Returns the path of the directory.
|
| 73 |
+
"""
|
| 74 |
+
d = tempfile.mkdtemp()
|
| 75 |
+
self.tempdirs.append(d)
|
| 76 |
+
return d
|
| 77 |
+
|
| 78 |
+
def write_file(self, path, content='xxx'):
|
| 79 |
+
"""Writes a file in the given path.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
path can be a string or a sequence.
|
| 83 |
+
"""
|
| 84 |
+
if isinstance(path, (list, tuple)):
|
| 85 |
+
path = os.path.join(*path)
|
| 86 |
+
f = open(path, 'w')
|
| 87 |
+
try:
|
| 88 |
+
f.write(content)
|
| 89 |
+
finally:
|
| 90 |
+
f.close()
|
| 91 |
+
|
| 92 |
+
def create_dist(self, pkg_name='foo', **kw):
|
| 93 |
+
"""Will generate a test environment.
|
| 94 |
+
|
| 95 |
+
This function creates:
|
| 96 |
+
- a Distribution instance using keywords
|
| 97 |
+
- a temporary directory with a package structure
|
| 98 |
+
|
| 99 |
+
It returns the package directory and the distribution
|
| 100 |
+
instance.
|
| 101 |
+
"""
|
| 102 |
+
tmp_dir = self.mkdtemp()
|
| 103 |
+
pkg_dir = os.path.join(tmp_dir, pkg_name)
|
| 104 |
+
os.mkdir(pkg_dir)
|
| 105 |
+
dist = Distribution(attrs=kw)
|
| 106 |
+
|
| 107 |
+
return pkg_dir, dist
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class DummyCommand:
|
| 111 |
+
"""Class to store options for retrieval via set_undefined_options()."""
|
| 112 |
+
|
| 113 |
+
def __init__(self, **kwargs):
|
| 114 |
+
for kw, val in kwargs.items():
|
| 115 |
+
setattr(self, kw, val)
|
| 116 |
+
|
| 117 |
+
def ensure_finalized(self):
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class EnvironGuard(object):
|
| 122 |
+
|
| 123 |
+
def setUp(self):
|
| 124 |
+
super(EnvironGuard, self).setUp()
|
| 125 |
+
self.old_environ = deepcopy(os.environ)
|
| 126 |
+
|
| 127 |
+
def tearDown(self):
|
| 128 |
+
for key, value in self.old_environ.items():
|
| 129 |
+
if os.environ.get(key) != value:
|
| 130 |
+
os.environ[key] = value
|
| 131 |
+
|
| 132 |
+
for key in tuple(os.environ.keys()):
|
| 133 |
+
if key not in self.old_environ:
|
| 134 |
+
del os.environ[key]
|
| 135 |
+
|
| 136 |
+
super(EnvironGuard, self).tearDown()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def copy_xxmodule_c(directory):
|
| 140 |
+
"""Helper for tests that need the xxmodule.c source file.
|
| 141 |
+
|
| 142 |
+
Example use:
|
| 143 |
+
|
| 144 |
+
def test_compile(self):
|
| 145 |
+
copy_xxmodule_c(self.tmpdir)
|
| 146 |
+
self.assertIn('xxmodule.c', os.listdir(self.tmpdir))
|
| 147 |
+
|
| 148 |
+
If the source file can be found, it will be copied to *directory*. If not,
|
| 149 |
+
the test will be skipped. Errors during copy are not caught.
|
| 150 |
+
"""
|
| 151 |
+
filename = _get_xxmodule_path()
|
| 152 |
+
if filename is None:
|
| 153 |
+
raise unittest.SkipTest('cannot find xxmodule.c (test must run in '
|
| 154 |
+
'the python build dir)')
|
| 155 |
+
shutil.copy(filename, directory)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def _get_xxmodule_path():
|
| 159 |
+
srcdir = sysconfig.get_config_var('srcdir')
|
| 160 |
+
candidates = [
|
| 161 |
+
# use installed copy if available
|
| 162 |
+
os.path.join(os.path.dirname(__file__), 'xxmodule.c'),
|
| 163 |
+
# otherwise try using copy from build directory
|
| 164 |
+
os.path.join(srcdir, 'Modules', 'xxmodule.c'),
|
| 165 |
+
# srcdir mysteriously can be $srcdir/Lib/distutils/tests when
|
| 166 |
+
# this file is run from its parent directory, so walk up the
|
| 167 |
+
# tree to find the real srcdir
|
| 168 |
+
os.path.join(srcdir, '..', '..', '..', 'Modules', 'xxmodule.c'),
|
| 169 |
+
]
|
| 170 |
+
for path in candidates:
|
| 171 |
+
if os.path.exists(path):
|
| 172 |
+
return path
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def fixup_build_ext(cmd):
|
| 176 |
+
"""Function needed to make build_ext tests pass.
|
| 177 |
+
|
| 178 |
+
When Python was built with --enable-shared on Unix, -L. is not enough to
|
| 179 |
+
find libpython<blah>.so, because regrtest runs in a tempdir, not in the
|
| 180 |
+
source directory where the .so lives.
|
| 181 |
+
|
| 182 |
+
When Python was built with in debug mode on Windows, build_ext commands
|
| 183 |
+
need their debug attribute set, and it is not done automatically for
|
| 184 |
+
some reason.
|
| 185 |
+
|
| 186 |
+
This function handles both of these things. Example use:
|
| 187 |
+
|
| 188 |
+
cmd = build_ext(dist)
|
| 189 |
+
support.fixup_build_ext(cmd)
|
| 190 |
+
cmd.ensure_finalized()
|
| 191 |
+
|
| 192 |
+
Unlike most other Unix platforms, Mac OS X embeds absolute paths
|
| 193 |
+
to shared libraries into executables, so the fixup is not needed there.
|
| 194 |
+
"""
|
| 195 |
+
if os.name == 'nt':
|
| 196 |
+
cmd.debug = sys.executable.endswith('_d.exe')
|
| 197 |
+
elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
|
| 198 |
+
# To further add to the shared builds fun on Unix, we can't just add
|
| 199 |
+
# library_dirs to the Extension() instance because that doesn't get
|
| 200 |
+
# plumbed through to the final compiler command.
|
| 201 |
+
runshared = sysconfig.get_config_var('RUNSHARED')
|
| 202 |
+
if runshared is None:
|
| 203 |
+
cmd.library_dirs = ['.']
|
| 204 |
+
else:
|
| 205 |
+
if sys.platform == 'darwin':
|
| 206 |
+
cmd.library_dirs = []
|
| 207 |
+
else:
|
| 208 |
+
name, equals, value = runshared.partition('=')
|
| 209 |
+
cmd.library_dirs = [d for d in value.split(os.pathsep) if d]
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_archive_util.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""Tests for distutils.archive_util."""
|
| 3 |
+
import unittest
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import tarfile
|
| 7 |
+
from os.path import splitdrive
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
from distutils import archive_util
|
| 11 |
+
from distutils.archive_util import (check_archive_formats, make_tarball,
|
| 12 |
+
make_zipfile, make_archive,
|
| 13 |
+
ARCHIVE_FORMATS)
|
| 14 |
+
from distutils.spawn import find_executable, spawn
|
| 15 |
+
from distutils.tests import support
|
| 16 |
+
from test.support import run_unittest, patch
|
| 17 |
+
from test.support.os_helper import change_cwd
|
| 18 |
+
from test.support.warnings_helper import check_warnings
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
import grp
|
| 22 |
+
import pwd
|
| 23 |
+
UID_GID_SUPPORT = True
|
| 24 |
+
except ImportError:
|
| 25 |
+
UID_GID_SUPPORT = False
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
import zipfile
|
| 29 |
+
ZIP_SUPPORT = True
|
| 30 |
+
except ImportError:
|
| 31 |
+
ZIP_SUPPORT = find_executable('zip')
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
import zlib
|
| 35 |
+
ZLIB_SUPPORT = True
|
| 36 |
+
except ImportError:
|
| 37 |
+
ZLIB_SUPPORT = False
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
import bz2
|
| 41 |
+
except ImportError:
|
| 42 |
+
bz2 = None
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
import lzma
|
| 46 |
+
except ImportError:
|
| 47 |
+
lzma = None
|
| 48 |
+
|
| 49 |
+
def can_fs_encode(filename):
|
| 50 |
+
"""
|
| 51 |
+
Return True if the filename can be saved in the file system.
|
| 52 |
+
"""
|
| 53 |
+
if os.path.supports_unicode_filenames:
|
| 54 |
+
return True
|
| 55 |
+
try:
|
| 56 |
+
filename.encode(sys.getfilesystemencoding())
|
| 57 |
+
except UnicodeEncodeError:
|
| 58 |
+
return False
|
| 59 |
+
return True
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class ArchiveUtilTestCase(support.TempdirManager,
|
| 63 |
+
support.LoggingSilencer,
|
| 64 |
+
unittest.TestCase):
|
| 65 |
+
|
| 66 |
+
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
|
| 67 |
+
def test_make_tarball(self, name='archive'):
|
| 68 |
+
# creating something to tar
|
| 69 |
+
tmpdir = self._create_files()
|
| 70 |
+
self._make_tarball(tmpdir, name, '.tar.gz')
|
| 71 |
+
# trying an uncompressed one
|
| 72 |
+
self._make_tarball(tmpdir, name, '.tar', compress=None)
|
| 73 |
+
|
| 74 |
+
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
|
| 75 |
+
def test_make_tarball_gzip(self):
|
| 76 |
+
tmpdir = self._create_files()
|
| 77 |
+
self._make_tarball(tmpdir, 'archive', '.tar.gz', compress='gzip')
|
| 78 |
+
|
| 79 |
+
@unittest.skipUnless(bz2, 'Need bz2 support to run')
|
| 80 |
+
def test_make_tarball_bzip2(self):
|
| 81 |
+
tmpdir = self._create_files()
|
| 82 |
+
self._make_tarball(tmpdir, 'archive', '.tar.bz2', compress='bzip2')
|
| 83 |
+
|
| 84 |
+
@unittest.skipUnless(lzma, 'Need lzma support to run')
|
| 85 |
+
def test_make_tarball_xz(self):
|
| 86 |
+
tmpdir = self._create_files()
|
| 87 |
+
self._make_tarball(tmpdir, 'archive', '.tar.xz', compress='xz')
|
| 88 |
+
|
| 89 |
+
@unittest.skipUnless(can_fs_encode('årchiv'),
|
| 90 |
+
'File system cannot handle this filename')
|
| 91 |
+
def test_make_tarball_latin1(self):
|
| 92 |
+
"""
|
| 93 |
+
Mirror test_make_tarball, except filename contains latin characters.
|
| 94 |
+
"""
|
| 95 |
+
self.test_make_tarball('årchiv') # note this isn't a real word
|
| 96 |
+
|
| 97 |
+
@unittest.skipUnless(can_fs_encode('のアーカイブ'),
|
| 98 |
+
'File system cannot handle this filename')
|
| 99 |
+
def test_make_tarball_extended(self):
|
| 100 |
+
"""
|
| 101 |
+
Mirror test_make_tarball, except filename contains extended
|
| 102 |
+
characters outside the latin charset.
|
| 103 |
+
"""
|
| 104 |
+
self.test_make_tarball('のアーカイブ') # japanese for archive
|
| 105 |
+
|
| 106 |
+
def _make_tarball(self, tmpdir, target_name, suffix, **kwargs):
|
| 107 |
+
tmpdir2 = self.mkdtemp()
|
| 108 |
+
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
|
| 109 |
+
"source and target should be on same drive")
|
| 110 |
+
|
| 111 |
+
base_name = os.path.join(tmpdir2, target_name)
|
| 112 |
+
|
| 113 |
+
# working with relative paths to avoid tar warnings
|
| 114 |
+
with change_cwd(tmpdir):
|
| 115 |
+
make_tarball(splitdrive(base_name)[1], 'dist', **kwargs)
|
| 116 |
+
|
| 117 |
+
# check if the compressed tarball was created
|
| 118 |
+
tarball = base_name + suffix
|
| 119 |
+
self.assertTrue(os.path.exists(tarball))
|
| 120 |
+
self.assertEqual(self._tarinfo(tarball), self._created_files)
|
| 121 |
+
|
| 122 |
+
def _tarinfo(self, path):
|
| 123 |
+
tar = tarfile.open(path)
|
| 124 |
+
try:
|
| 125 |
+
names = tar.getnames()
|
| 126 |
+
names.sort()
|
| 127 |
+
return names
|
| 128 |
+
finally:
|
| 129 |
+
tar.close()
|
| 130 |
+
|
| 131 |
+
_zip_created_files = ['dist/', 'dist/file1', 'dist/file2',
|
| 132 |
+
'dist/sub/', 'dist/sub/file3', 'dist/sub2/']
|
| 133 |
+
_created_files = [p.rstrip('/') for p in _zip_created_files]
|
| 134 |
+
|
| 135 |
+
def _create_files(self):
|
| 136 |
+
# creating something to tar
|
| 137 |
+
tmpdir = self.mkdtemp()
|
| 138 |
+
dist = os.path.join(tmpdir, 'dist')
|
| 139 |
+
os.mkdir(dist)
|
| 140 |
+
self.write_file([dist, 'file1'], 'xxx')
|
| 141 |
+
self.write_file([dist, 'file2'], 'xxx')
|
| 142 |
+
os.mkdir(os.path.join(dist, 'sub'))
|
| 143 |
+
self.write_file([dist, 'sub', 'file3'], 'xxx')
|
| 144 |
+
os.mkdir(os.path.join(dist, 'sub2'))
|
| 145 |
+
return tmpdir
|
| 146 |
+
|
| 147 |
+
@unittest.skipUnless(find_executable('tar') and find_executable('gzip')
|
| 148 |
+
and ZLIB_SUPPORT,
|
| 149 |
+
'Need the tar, gzip and zlib command to run')
|
| 150 |
+
def test_tarfile_vs_tar(self):
|
| 151 |
+
tmpdir = self._create_files()
|
| 152 |
+
tmpdir2 = self.mkdtemp()
|
| 153 |
+
base_name = os.path.join(tmpdir2, 'archive')
|
| 154 |
+
old_dir = os.getcwd()
|
| 155 |
+
os.chdir(tmpdir)
|
| 156 |
+
try:
|
| 157 |
+
make_tarball(base_name, 'dist')
|
| 158 |
+
finally:
|
| 159 |
+
os.chdir(old_dir)
|
| 160 |
+
|
| 161 |
+
# check if the compressed tarball was created
|
| 162 |
+
tarball = base_name + '.tar.gz'
|
| 163 |
+
self.assertTrue(os.path.exists(tarball))
|
| 164 |
+
|
| 165 |
+
# now create another tarball using `tar`
|
| 166 |
+
tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
|
| 167 |
+
tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
|
| 168 |
+
gzip_cmd = ['gzip', '-f', '-9', 'archive2.tar']
|
| 169 |
+
old_dir = os.getcwd()
|
| 170 |
+
os.chdir(tmpdir)
|
| 171 |
+
try:
|
| 172 |
+
spawn(tar_cmd)
|
| 173 |
+
spawn(gzip_cmd)
|
| 174 |
+
finally:
|
| 175 |
+
os.chdir(old_dir)
|
| 176 |
+
|
| 177 |
+
self.assertTrue(os.path.exists(tarball2))
|
| 178 |
+
# let's compare both tarballs
|
| 179 |
+
self.assertEqual(self._tarinfo(tarball), self._created_files)
|
| 180 |
+
self.assertEqual(self._tarinfo(tarball2), self._created_files)
|
| 181 |
+
|
| 182 |
+
# trying an uncompressed one
|
| 183 |
+
base_name = os.path.join(tmpdir2, 'archive')
|
| 184 |
+
old_dir = os.getcwd()
|
| 185 |
+
os.chdir(tmpdir)
|
| 186 |
+
try:
|
| 187 |
+
make_tarball(base_name, 'dist', compress=None)
|
| 188 |
+
finally:
|
| 189 |
+
os.chdir(old_dir)
|
| 190 |
+
tarball = base_name + '.tar'
|
| 191 |
+
self.assertTrue(os.path.exists(tarball))
|
| 192 |
+
|
| 193 |
+
# now for a dry_run
|
| 194 |
+
base_name = os.path.join(tmpdir2, 'archive')
|
| 195 |
+
old_dir = os.getcwd()
|
| 196 |
+
os.chdir(tmpdir)
|
| 197 |
+
try:
|
| 198 |
+
make_tarball(base_name, 'dist', compress=None, dry_run=True)
|
| 199 |
+
finally:
|
| 200 |
+
os.chdir(old_dir)
|
| 201 |
+
tarball = base_name + '.tar'
|
| 202 |
+
self.assertTrue(os.path.exists(tarball))
|
| 203 |
+
|
| 204 |
+
@unittest.skipUnless(find_executable('compress'),
|
| 205 |
+
'The compress program is required')
|
| 206 |
+
def test_compress_deprecated(self):
|
| 207 |
+
tmpdir = self._create_files()
|
| 208 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 209 |
+
|
| 210 |
+
# using compress and testing the PendingDeprecationWarning
|
| 211 |
+
old_dir = os.getcwd()
|
| 212 |
+
os.chdir(tmpdir)
|
| 213 |
+
try:
|
| 214 |
+
with check_warnings() as w:
|
| 215 |
+
warnings.simplefilter("always")
|
| 216 |
+
make_tarball(base_name, 'dist', compress='compress')
|
| 217 |
+
finally:
|
| 218 |
+
os.chdir(old_dir)
|
| 219 |
+
tarball = base_name + '.tar.Z'
|
| 220 |
+
self.assertTrue(os.path.exists(tarball))
|
| 221 |
+
self.assertEqual(len(w.warnings), 1)
|
| 222 |
+
|
| 223 |
+
# same test with dry_run
|
| 224 |
+
os.remove(tarball)
|
| 225 |
+
old_dir = os.getcwd()
|
| 226 |
+
os.chdir(tmpdir)
|
| 227 |
+
try:
|
| 228 |
+
with check_warnings() as w:
|
| 229 |
+
warnings.simplefilter("always")
|
| 230 |
+
make_tarball(base_name, 'dist', compress='compress',
|
| 231 |
+
dry_run=True)
|
| 232 |
+
finally:
|
| 233 |
+
os.chdir(old_dir)
|
| 234 |
+
self.assertFalse(os.path.exists(tarball))
|
| 235 |
+
self.assertEqual(len(w.warnings), 1)
|
| 236 |
+
|
| 237 |
+
@unittest.skipUnless(ZIP_SUPPORT and ZLIB_SUPPORT,
|
| 238 |
+
'Need zip and zlib support to run')
|
| 239 |
+
def test_make_zipfile(self):
|
| 240 |
+
# creating something to tar
|
| 241 |
+
tmpdir = self._create_files()
|
| 242 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 243 |
+
with change_cwd(tmpdir):
|
| 244 |
+
make_zipfile(base_name, 'dist')
|
| 245 |
+
|
| 246 |
+
# check if the compressed tarball was created
|
| 247 |
+
tarball = base_name + '.zip'
|
| 248 |
+
self.assertTrue(os.path.exists(tarball))
|
| 249 |
+
with zipfile.ZipFile(tarball) as zf:
|
| 250 |
+
self.assertEqual(sorted(zf.namelist()), self._zip_created_files)
|
| 251 |
+
|
| 252 |
+
@unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
|
| 253 |
+
def test_make_zipfile_no_zlib(self):
|
| 254 |
+
patch(self, archive_util.zipfile, 'zlib', None) # force zlib ImportError
|
| 255 |
+
|
| 256 |
+
called = []
|
| 257 |
+
zipfile_class = zipfile.ZipFile
|
| 258 |
+
def fake_zipfile(*a, **kw):
|
| 259 |
+
if kw.get('compression', None) == zipfile.ZIP_STORED:
|
| 260 |
+
called.append((a, kw))
|
| 261 |
+
return zipfile_class(*a, **kw)
|
| 262 |
+
|
| 263 |
+
patch(self, archive_util.zipfile, 'ZipFile', fake_zipfile)
|
| 264 |
+
|
| 265 |
+
# create something to tar and compress
|
| 266 |
+
tmpdir = self._create_files()
|
| 267 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 268 |
+
with change_cwd(tmpdir):
|
| 269 |
+
make_zipfile(base_name, 'dist')
|
| 270 |
+
|
| 271 |
+
tarball = base_name + '.zip'
|
| 272 |
+
self.assertEqual(called,
|
| 273 |
+
[((tarball, "w"), {'compression': zipfile.ZIP_STORED})])
|
| 274 |
+
self.assertTrue(os.path.exists(tarball))
|
| 275 |
+
with zipfile.ZipFile(tarball) as zf:
|
| 276 |
+
self.assertEqual(sorted(zf.namelist()), self._zip_created_files)
|
| 277 |
+
|
| 278 |
+
def test_check_archive_formats(self):
|
| 279 |
+
self.assertEqual(check_archive_formats(['gztar', 'xxx', 'zip']),
|
| 280 |
+
'xxx')
|
| 281 |
+
self.assertIsNone(check_archive_formats(['gztar', 'bztar', 'xztar',
|
| 282 |
+
'ztar', 'tar', 'zip']))
|
| 283 |
+
|
| 284 |
+
def test_make_archive(self):
|
| 285 |
+
tmpdir = self.mkdtemp()
|
| 286 |
+
base_name = os.path.join(tmpdir, 'archive')
|
| 287 |
+
self.assertRaises(ValueError, make_archive, base_name, 'xxx')
|
| 288 |
+
|
| 289 |
+
def test_make_archive_cwd(self):
|
| 290 |
+
current_dir = os.getcwd()
|
| 291 |
+
def _breaks(*args, **kw):
|
| 292 |
+
raise RuntimeError()
|
| 293 |
+
ARCHIVE_FORMATS['xxx'] = (_breaks, [], 'xxx file')
|
| 294 |
+
try:
|
| 295 |
+
try:
|
| 296 |
+
make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
|
| 297 |
+
except:
|
| 298 |
+
pass
|
| 299 |
+
self.assertEqual(os.getcwd(), current_dir)
|
| 300 |
+
finally:
|
| 301 |
+
del ARCHIVE_FORMATS['xxx']
|
| 302 |
+
|
| 303 |
+
def test_make_archive_tar(self):
|
| 304 |
+
base_dir = self._create_files()
|
| 305 |
+
base_name = os.path.join(self.mkdtemp() , 'archive')
|
| 306 |
+
res = make_archive(base_name, 'tar', base_dir, 'dist')
|
| 307 |
+
self.assertTrue(os.path.exists(res))
|
| 308 |
+
self.assertEqual(os.path.basename(res), 'archive.tar')
|
| 309 |
+
self.assertEqual(self._tarinfo(res), self._created_files)
|
| 310 |
+
|
| 311 |
+
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
|
| 312 |
+
def test_make_archive_gztar(self):
|
| 313 |
+
base_dir = self._create_files()
|
| 314 |
+
base_name = os.path.join(self.mkdtemp() , 'archive')
|
| 315 |
+
res = make_archive(base_name, 'gztar', base_dir, 'dist')
|
| 316 |
+
self.assertTrue(os.path.exists(res))
|
| 317 |
+
self.assertEqual(os.path.basename(res), 'archive.tar.gz')
|
| 318 |
+
self.assertEqual(self._tarinfo(res), self._created_files)
|
| 319 |
+
|
| 320 |
+
@unittest.skipUnless(bz2, 'Need bz2 support to run')
|
| 321 |
+
def test_make_archive_bztar(self):
|
| 322 |
+
base_dir = self._create_files()
|
| 323 |
+
base_name = os.path.join(self.mkdtemp() , 'archive')
|
| 324 |
+
res = make_archive(base_name, 'bztar', base_dir, 'dist')
|
| 325 |
+
self.assertTrue(os.path.exists(res))
|
| 326 |
+
self.assertEqual(os.path.basename(res), 'archive.tar.bz2')
|
| 327 |
+
self.assertEqual(self._tarinfo(res), self._created_files)
|
| 328 |
+
|
| 329 |
+
@unittest.skipUnless(lzma, 'Need xz support to run')
|
| 330 |
+
def test_make_archive_xztar(self):
|
| 331 |
+
base_dir = self._create_files()
|
| 332 |
+
base_name = os.path.join(self.mkdtemp() , 'archive')
|
| 333 |
+
res = make_archive(base_name, 'xztar', base_dir, 'dist')
|
| 334 |
+
self.assertTrue(os.path.exists(res))
|
| 335 |
+
self.assertEqual(os.path.basename(res), 'archive.tar.xz')
|
| 336 |
+
self.assertEqual(self._tarinfo(res), self._created_files)
|
| 337 |
+
|
| 338 |
+
def test_make_archive_owner_group(self):
|
| 339 |
+
# testing make_archive with owner and group, with various combinations
|
| 340 |
+
# this works even if there's not gid/uid support
|
| 341 |
+
if UID_GID_SUPPORT:
|
| 342 |
+
group = grp.getgrgid(0)[0]
|
| 343 |
+
owner = pwd.getpwuid(0)[0]
|
| 344 |
+
else:
|
| 345 |
+
group = owner = 'root'
|
| 346 |
+
|
| 347 |
+
base_dir = self._create_files()
|
| 348 |
+
root_dir = self.mkdtemp()
|
| 349 |
+
base_name = os.path.join(self.mkdtemp() , 'archive')
|
| 350 |
+
res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
|
| 351 |
+
group=group)
|
| 352 |
+
self.assertTrue(os.path.exists(res))
|
| 353 |
+
|
| 354 |
+
res = make_archive(base_name, 'zip', root_dir, base_dir)
|
| 355 |
+
self.assertTrue(os.path.exists(res))
|
| 356 |
+
|
| 357 |
+
res = make_archive(base_name, 'tar', root_dir, base_dir,
|
| 358 |
+
owner=owner, group=group)
|
| 359 |
+
self.assertTrue(os.path.exists(res))
|
| 360 |
+
|
| 361 |
+
res = make_archive(base_name, 'tar', root_dir, base_dir,
|
| 362 |
+
owner='kjhkjhkjg', group='oihohoh')
|
| 363 |
+
self.assertTrue(os.path.exists(res))
|
| 364 |
+
|
| 365 |
+
@unittest.skipUnless(ZLIB_SUPPORT, "Requires zlib")
|
| 366 |
+
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
|
| 367 |
+
def test_tarfile_root_owner(self):
|
| 368 |
+
tmpdir = self._create_files()
|
| 369 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 370 |
+
old_dir = os.getcwd()
|
| 371 |
+
os.chdir(tmpdir)
|
| 372 |
+
group = grp.getgrgid(0)[0]
|
| 373 |
+
owner = pwd.getpwuid(0)[0]
|
| 374 |
+
try:
|
| 375 |
+
archive_name = make_tarball(base_name, 'dist', compress=None,
|
| 376 |
+
owner=owner, group=group)
|
| 377 |
+
finally:
|
| 378 |
+
os.chdir(old_dir)
|
| 379 |
+
|
| 380 |
+
# check if the compressed tarball was created
|
| 381 |
+
self.assertTrue(os.path.exists(archive_name))
|
| 382 |
+
|
| 383 |
+
# now checks the rights
|
| 384 |
+
archive = tarfile.open(archive_name)
|
| 385 |
+
try:
|
| 386 |
+
for member in archive.getmembers():
|
| 387 |
+
self.assertEqual(member.uid, 0)
|
| 388 |
+
self.assertEqual(member.gid, 0)
|
| 389 |
+
finally:
|
| 390 |
+
archive.close()
|
| 391 |
+
|
| 392 |
+
def test_suite():
|
| 393 |
+
return unittest.makeSuite(ArchiveUtilTestCase)
|
| 394 |
+
|
| 395 |
+
if __name__ == "__main__":
|
| 396 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist."""
|
| 2 |
+
import os
|
| 3 |
+
import unittest
|
| 4 |
+
from test.support import run_unittest
|
| 5 |
+
|
| 6 |
+
import warnings
|
| 7 |
+
with warnings.catch_warnings():
|
| 8 |
+
warnings.simplefilter('ignore', DeprecationWarning)
|
| 9 |
+
from distutils.command.bdist import bdist
|
| 10 |
+
from distutils.tests import support
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class BuildTestCase(support.TempdirManager,
|
| 14 |
+
unittest.TestCase):
|
| 15 |
+
|
| 16 |
+
def test_formats(self):
|
| 17 |
+
# let's create a command and make sure
|
| 18 |
+
# we can set the format
|
| 19 |
+
dist = self.create_dist()[1]
|
| 20 |
+
cmd = bdist(dist)
|
| 21 |
+
cmd.formats = ['msi']
|
| 22 |
+
cmd.ensure_finalized()
|
| 23 |
+
self.assertEqual(cmd.formats, ['msi'])
|
| 24 |
+
|
| 25 |
+
# what formats does bdist offer?
|
| 26 |
+
formats = ['bztar', 'gztar', 'msi', 'rpm', 'tar',
|
| 27 |
+
'xztar', 'zip', 'ztar']
|
| 28 |
+
found = sorted(cmd.format_command)
|
| 29 |
+
self.assertEqual(found, formats)
|
| 30 |
+
|
| 31 |
+
def test_skip_build(self):
|
| 32 |
+
# bug #10946: bdist --skip-build should trickle down to subcommands
|
| 33 |
+
dist = self.create_dist()[1]
|
| 34 |
+
cmd = bdist(dist)
|
| 35 |
+
cmd.skip_build = 1
|
| 36 |
+
cmd.ensure_finalized()
|
| 37 |
+
dist.command_obj['bdist'] = cmd
|
| 38 |
+
|
| 39 |
+
names = ['bdist_dumb'] # bdist_rpm does not support --skip-build
|
| 40 |
+
if os.name == 'nt':
|
| 41 |
+
names.append('bdist_msi')
|
| 42 |
+
|
| 43 |
+
for name in names:
|
| 44 |
+
subcmd = cmd.get_finalized_command(name)
|
| 45 |
+
if getattr(subcmd, '_unsupported', False):
|
| 46 |
+
# command is not supported on this build
|
| 47 |
+
continue
|
| 48 |
+
self.assertTrue(subcmd.skip_build,
|
| 49 |
+
'%s should take --skip-build from bdist' % name)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def test_suite():
|
| 53 |
+
return unittest.makeSuite(BuildTestCase)
|
| 54 |
+
|
| 55 |
+
if __name__ == '__main__':
|
| 56 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist_dumb.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist_dumb."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import zipfile
|
| 6 |
+
import unittest
|
| 7 |
+
from test.support import run_unittest
|
| 8 |
+
|
| 9 |
+
from distutils.core import Distribution
|
| 10 |
+
from distutils.command.bdist_dumb import bdist_dumb
|
| 11 |
+
from distutils.tests import support
|
| 12 |
+
|
| 13 |
+
SETUP_PY = """\
|
| 14 |
+
from distutils.core import setup
|
| 15 |
+
import foo
|
| 16 |
+
|
| 17 |
+
setup(name='foo', version='0.1', py_modules=['foo'],
|
| 18 |
+
url='xxx', author='xxx', author_email='xxx')
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
import zlib
|
| 24 |
+
ZLIB_SUPPORT = True
|
| 25 |
+
except ImportError:
|
| 26 |
+
ZLIB_SUPPORT = False
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class BuildDumbTestCase(support.TempdirManager,
|
| 30 |
+
support.LoggingSilencer,
|
| 31 |
+
support.EnvironGuard,
|
| 32 |
+
unittest.TestCase):
|
| 33 |
+
|
| 34 |
+
def setUp(self):
|
| 35 |
+
super(BuildDumbTestCase, self).setUp()
|
| 36 |
+
self.old_location = os.getcwd()
|
| 37 |
+
self.old_sys_argv = sys.argv, sys.argv[:]
|
| 38 |
+
|
| 39 |
+
def tearDown(self):
|
| 40 |
+
os.chdir(self.old_location)
|
| 41 |
+
sys.argv = self.old_sys_argv[0]
|
| 42 |
+
sys.argv[:] = self.old_sys_argv[1]
|
| 43 |
+
super(BuildDumbTestCase, self).tearDown()
|
| 44 |
+
|
| 45 |
+
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
|
| 46 |
+
def test_simple_built(self):
|
| 47 |
+
|
| 48 |
+
# let's create a simple package
|
| 49 |
+
tmp_dir = self.mkdtemp()
|
| 50 |
+
pkg_dir = os.path.join(tmp_dir, 'foo')
|
| 51 |
+
os.mkdir(pkg_dir)
|
| 52 |
+
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
|
| 53 |
+
self.write_file((pkg_dir, 'foo.py'), '#')
|
| 54 |
+
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
|
| 55 |
+
self.write_file((pkg_dir, 'README'), '')
|
| 56 |
+
|
| 57 |
+
dist = Distribution({'name': 'foo', 'version': '0.1',
|
| 58 |
+
'py_modules': ['foo'],
|
| 59 |
+
'url': 'xxx', 'author': 'xxx',
|
| 60 |
+
'author_email': 'xxx'})
|
| 61 |
+
dist.script_name = 'setup.py'
|
| 62 |
+
os.chdir(pkg_dir)
|
| 63 |
+
|
| 64 |
+
sys.argv = ['setup.py']
|
| 65 |
+
cmd = bdist_dumb(dist)
|
| 66 |
+
|
| 67 |
+
# so the output is the same no matter
|
| 68 |
+
# what is the platform
|
| 69 |
+
cmd.format = 'zip'
|
| 70 |
+
|
| 71 |
+
cmd.ensure_finalized()
|
| 72 |
+
cmd.run()
|
| 73 |
+
|
| 74 |
+
# see what we have
|
| 75 |
+
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
| 76 |
+
base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
|
| 77 |
+
|
| 78 |
+
self.assertEqual(dist_created, [base])
|
| 79 |
+
|
| 80 |
+
# now let's check what we have in the zip file
|
| 81 |
+
fp = zipfile.ZipFile(os.path.join('dist', base))
|
| 82 |
+
try:
|
| 83 |
+
contents = fp.namelist()
|
| 84 |
+
finally:
|
| 85 |
+
fp.close()
|
| 86 |
+
|
| 87 |
+
contents = sorted(filter(None, map(os.path.basename, contents)))
|
| 88 |
+
wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
|
| 89 |
+
if not sys.dont_write_bytecode:
|
| 90 |
+
wanted.append('foo.%s.pyc' % sys.implementation.cache_tag)
|
| 91 |
+
self.assertEqual(contents, sorted(wanted))
|
| 92 |
+
|
| 93 |
+
def test_suite():
|
| 94 |
+
return unittest.makeSuite(BuildDumbTestCase)
|
| 95 |
+
|
| 96 |
+
if __name__ == '__main__':
|
| 97 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist_msi.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist_msi."""
|
| 2 |
+
import sys
|
| 3 |
+
import unittest
|
| 4 |
+
from test.support import run_unittest
|
| 5 |
+
from test.support.warnings_helper import check_warnings
|
| 6 |
+
from distutils.tests import support
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows')
|
| 10 |
+
class BDistMSITestCase(support.TempdirManager,
|
| 11 |
+
support.LoggingSilencer,
|
| 12 |
+
unittest.TestCase):
|
| 13 |
+
|
| 14 |
+
def test_minimal(self):
|
| 15 |
+
# minimal test XXX need more tests
|
| 16 |
+
from distutils.command.bdist_msi import bdist_msi
|
| 17 |
+
project_dir, dist = self.create_dist()
|
| 18 |
+
with check_warnings(("", DeprecationWarning)):
|
| 19 |
+
cmd = bdist_msi(dist)
|
| 20 |
+
cmd.ensure_finalized()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_suite():
|
| 24 |
+
return unittest.makeSuite(BDistMSITestCase)
|
| 25 |
+
|
| 26 |
+
if __name__ == '__main__':
|
| 27 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_bdist_rpm.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist_rpm."""
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
from test.support import run_unittest, requires_zlib
|
| 7 |
+
|
| 8 |
+
from distutils.core import Distribution
|
| 9 |
+
from distutils.command.bdist_rpm import bdist_rpm
|
| 10 |
+
from distutils.tests import support
|
| 11 |
+
from distutils.spawn import find_executable
|
| 12 |
+
|
| 13 |
+
SETUP_PY = """\
|
| 14 |
+
from distutils.core import setup
|
| 15 |
+
import foo
|
| 16 |
+
|
| 17 |
+
setup(name='foo', version='0.1', py_modules=['foo'],
|
| 18 |
+
url='xxx', author='xxx', author_email='xxx')
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
class BuildRpmTestCase(support.TempdirManager,
|
| 23 |
+
support.EnvironGuard,
|
| 24 |
+
support.LoggingSilencer,
|
| 25 |
+
unittest.TestCase):
|
| 26 |
+
|
| 27 |
+
def setUp(self):
|
| 28 |
+
try:
|
| 29 |
+
sys.executable.encode("UTF-8")
|
| 30 |
+
except UnicodeEncodeError:
|
| 31 |
+
raise unittest.SkipTest("sys.executable is not encodable to UTF-8")
|
| 32 |
+
|
| 33 |
+
super(BuildRpmTestCase, self).setUp()
|
| 34 |
+
self.old_location = os.getcwd()
|
| 35 |
+
self.old_sys_argv = sys.argv, sys.argv[:]
|
| 36 |
+
|
| 37 |
+
def tearDown(self):
|
| 38 |
+
os.chdir(self.old_location)
|
| 39 |
+
sys.argv = self.old_sys_argv[0]
|
| 40 |
+
sys.argv[:] = self.old_sys_argv[1]
|
| 41 |
+
super(BuildRpmTestCase, self).tearDown()
|
| 42 |
+
|
| 43 |
+
# XXX I am unable yet to make this test work without
|
| 44 |
+
# spurious sdtout/stderr output under Mac OS X
|
| 45 |
+
@unittest.skipUnless(sys.platform.startswith('linux'),
|
| 46 |
+
'spurious sdtout/stderr output under Mac OS X')
|
| 47 |
+
@requires_zlib()
|
| 48 |
+
@unittest.skipIf(find_executable('rpm') is None,
|
| 49 |
+
'the rpm command is not found')
|
| 50 |
+
@unittest.skipIf(find_executable('rpmbuild') is None,
|
| 51 |
+
'the rpmbuild command is not found')
|
| 52 |
+
def test_quiet(self):
|
| 53 |
+
# let's create a package
|
| 54 |
+
tmp_dir = self.mkdtemp()
|
| 55 |
+
os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
|
| 56 |
+
pkg_dir = os.path.join(tmp_dir, 'foo')
|
| 57 |
+
os.mkdir(pkg_dir)
|
| 58 |
+
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
|
| 59 |
+
self.write_file((pkg_dir, 'foo.py'), '#')
|
| 60 |
+
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
|
| 61 |
+
self.write_file((pkg_dir, 'README'), '')
|
| 62 |
+
|
| 63 |
+
dist = Distribution({'name': 'foo', 'version': '0.1',
|
| 64 |
+
'py_modules': ['foo'],
|
| 65 |
+
'url': 'xxx', 'author': 'xxx',
|
| 66 |
+
'author_email': 'xxx'})
|
| 67 |
+
dist.script_name = 'setup.py'
|
| 68 |
+
os.chdir(pkg_dir)
|
| 69 |
+
|
| 70 |
+
sys.argv = ['setup.py']
|
| 71 |
+
cmd = bdist_rpm(dist)
|
| 72 |
+
cmd.fix_python = True
|
| 73 |
+
|
| 74 |
+
# running in quiet mode
|
| 75 |
+
cmd.quiet = 1
|
| 76 |
+
cmd.ensure_finalized()
|
| 77 |
+
cmd.run()
|
| 78 |
+
|
| 79 |
+
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
| 80 |
+
self.assertIn('foo-0.1-1.noarch.rpm', dist_created)
|
| 81 |
+
|
| 82 |
+
# bug #2945: upload ignores bdist_rpm files
|
| 83 |
+
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
|
| 84 |
+
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)
|
| 85 |
+
|
| 86 |
+
# XXX I am unable yet to make this test work without
|
| 87 |
+
# spurious sdtout/stderr output under Mac OS X
|
| 88 |
+
@unittest.skipUnless(sys.platform.startswith('linux'),
|
| 89 |
+
'spurious sdtout/stderr output under Mac OS X')
|
| 90 |
+
@requires_zlib()
|
| 91 |
+
# http://bugs.python.org/issue1533164
|
| 92 |
+
@unittest.skipIf(find_executable('rpm') is None,
|
| 93 |
+
'the rpm command is not found')
|
| 94 |
+
@unittest.skipIf(find_executable('rpmbuild') is None,
|
| 95 |
+
'the rpmbuild command is not found')
|
| 96 |
+
def test_no_optimize_flag(self):
|
| 97 |
+
# let's create a package that breaks bdist_rpm
|
| 98 |
+
tmp_dir = self.mkdtemp()
|
| 99 |
+
os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
|
| 100 |
+
pkg_dir = os.path.join(tmp_dir, 'foo')
|
| 101 |
+
os.mkdir(pkg_dir)
|
| 102 |
+
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
|
| 103 |
+
self.write_file((pkg_dir, 'foo.py'), '#')
|
| 104 |
+
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
|
| 105 |
+
self.write_file((pkg_dir, 'README'), '')
|
| 106 |
+
|
| 107 |
+
dist = Distribution({'name': 'foo', 'version': '0.1',
|
| 108 |
+
'py_modules': ['foo'],
|
| 109 |
+
'url': 'xxx', 'author': 'xxx',
|
| 110 |
+
'author_email': 'xxx'})
|
| 111 |
+
dist.script_name = 'setup.py'
|
| 112 |
+
os.chdir(pkg_dir)
|
| 113 |
+
|
| 114 |
+
sys.argv = ['setup.py']
|
| 115 |
+
cmd = bdist_rpm(dist)
|
| 116 |
+
cmd.fix_python = True
|
| 117 |
+
|
| 118 |
+
cmd.quiet = 1
|
| 119 |
+
cmd.ensure_finalized()
|
| 120 |
+
cmd.run()
|
| 121 |
+
|
| 122 |
+
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
| 123 |
+
self.assertIn('foo-0.1-1.noarch.rpm', dist_created)
|
| 124 |
+
|
| 125 |
+
# bug #2945: upload ignores bdist_rpm files
|
| 126 |
+
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
|
| 127 |
+
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)
|
| 128 |
+
|
| 129 |
+
os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
|
| 130 |
+
|
| 131 |
+
def test_suite():
|
| 132 |
+
return unittest.makeSuite(BuildRpmTestCase)
|
| 133 |
+
|
| 134 |
+
if __name__ == '__main__':
|
| 135 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_build.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build."""
|
| 2 |
+
import unittest
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from test.support import run_unittest
|
| 6 |
+
|
| 7 |
+
from distutils.command.build import build
|
| 8 |
+
from distutils.tests import support
|
| 9 |
+
from sysconfig import get_platform
|
| 10 |
+
|
| 11 |
+
class BuildTestCase(support.TempdirManager,
|
| 12 |
+
support.LoggingSilencer,
|
| 13 |
+
unittest.TestCase):
|
| 14 |
+
|
| 15 |
+
def test_finalize_options(self):
|
| 16 |
+
pkg_dir, dist = self.create_dist()
|
| 17 |
+
cmd = build(dist)
|
| 18 |
+
cmd.finalize_options()
|
| 19 |
+
|
| 20 |
+
# if not specified, plat_name gets the current platform
|
| 21 |
+
self.assertEqual(cmd.plat_name, get_platform())
|
| 22 |
+
|
| 23 |
+
# build_purelib is build + lib
|
| 24 |
+
wanted = os.path.join(cmd.build_base, 'lib')
|
| 25 |
+
self.assertEqual(cmd.build_purelib, wanted)
|
| 26 |
+
|
| 27 |
+
# build_platlib is 'build/lib.platform-x.x[-pydebug]'
|
| 28 |
+
# examples:
|
| 29 |
+
# build/lib.macosx-10.3-i386-2.7
|
| 30 |
+
plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2])
|
| 31 |
+
if hasattr(sys, 'gettotalrefcount'):
|
| 32 |
+
self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
|
| 33 |
+
plat_spec += '-pydebug'
|
| 34 |
+
wanted = os.path.join(cmd.build_base, 'lib' + plat_spec)
|
| 35 |
+
self.assertEqual(cmd.build_platlib, wanted)
|
| 36 |
+
|
| 37 |
+
# by default, build_lib = build_purelib
|
| 38 |
+
self.assertEqual(cmd.build_lib, cmd.build_purelib)
|
| 39 |
+
|
| 40 |
+
# build_temp is build/temp.<plat>
|
| 41 |
+
wanted = os.path.join(cmd.build_base, 'temp' + plat_spec)
|
| 42 |
+
self.assertEqual(cmd.build_temp, wanted)
|
| 43 |
+
|
| 44 |
+
# build_scripts is build/scripts-x.x
|
| 45 |
+
wanted = os.path.join(cmd.build_base,
|
| 46 |
+
'scripts-%d.%d' % sys.version_info[:2])
|
| 47 |
+
self.assertEqual(cmd.build_scripts, wanted)
|
| 48 |
+
|
| 49 |
+
# executable is os.path.normpath(sys.executable)
|
| 50 |
+
self.assertEqual(cmd.executable, os.path.normpath(sys.executable))
|
| 51 |
+
|
| 52 |
+
def test_suite():
|
| 53 |
+
return unittest.makeSuite(BuildTestCase)
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_build_clib.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build_clib."""
|
| 2 |
+
import unittest
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import sysconfig
|
| 6 |
+
|
| 7 |
+
from test.support import run_unittest, missing_compiler_executable
|
| 8 |
+
|
| 9 |
+
from distutils.command.build_clib import build_clib
|
| 10 |
+
from distutils.errors import DistutilsSetupError
|
| 11 |
+
from distutils.tests import support
|
| 12 |
+
|
| 13 |
+
class BuildCLibTestCase(support.TempdirManager,
|
| 14 |
+
support.LoggingSilencer,
|
| 15 |
+
unittest.TestCase):
|
| 16 |
+
|
| 17 |
+
def setUp(self):
|
| 18 |
+
super().setUp()
|
| 19 |
+
self._backup_CONFIG_VARS = dict(sysconfig._CONFIG_VARS)
|
| 20 |
+
|
| 21 |
+
def tearDown(self):
|
| 22 |
+
super().tearDown()
|
| 23 |
+
sysconfig._CONFIG_VARS.clear()
|
| 24 |
+
sysconfig._CONFIG_VARS.update(self._backup_CONFIG_VARS)
|
| 25 |
+
|
| 26 |
+
def test_check_library_dist(self):
|
| 27 |
+
pkg_dir, dist = self.create_dist()
|
| 28 |
+
cmd = build_clib(dist)
|
| 29 |
+
|
| 30 |
+
# 'libraries' option must be a list
|
| 31 |
+
self.assertRaises(DistutilsSetupError, cmd.check_library_list, 'foo')
|
| 32 |
+
|
| 33 |
+
# each element of 'libraries' must a 2-tuple
|
| 34 |
+
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
| 35 |
+
['foo1', 'foo2'])
|
| 36 |
+
|
| 37 |
+
# first element of each tuple in 'libraries'
|
| 38 |
+
# must be a string (the library name)
|
| 39 |
+
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
| 40 |
+
[(1, 'foo1'), ('name', 'foo2')])
|
| 41 |
+
|
| 42 |
+
# library name may not contain directory separators
|
| 43 |
+
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
| 44 |
+
[('name', 'foo1'),
|
| 45 |
+
('another/name', 'foo2')])
|
| 46 |
+
|
| 47 |
+
# second element of each tuple must be a dictionary (build info)
|
| 48 |
+
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
| 49 |
+
[('name', {}),
|
| 50 |
+
('another', 'foo2')])
|
| 51 |
+
|
| 52 |
+
# those work
|
| 53 |
+
libs = [('name', {}), ('name', {'ok': 'good'})]
|
| 54 |
+
cmd.check_library_list(libs)
|
| 55 |
+
|
| 56 |
+
def test_get_source_files(self):
|
| 57 |
+
pkg_dir, dist = self.create_dist()
|
| 58 |
+
cmd = build_clib(dist)
|
| 59 |
+
|
| 60 |
+
# "in 'libraries' option 'sources' must be present and must be
|
| 61 |
+
# a list of source filenames
|
| 62 |
+
cmd.libraries = [('name', {})]
|
| 63 |
+
self.assertRaises(DistutilsSetupError, cmd.get_source_files)
|
| 64 |
+
|
| 65 |
+
cmd.libraries = [('name', {'sources': 1})]
|
| 66 |
+
self.assertRaises(DistutilsSetupError, cmd.get_source_files)
|
| 67 |
+
|
| 68 |
+
cmd.libraries = [('name', {'sources': ['a', 'b']})]
|
| 69 |
+
self.assertEqual(cmd.get_source_files(), ['a', 'b'])
|
| 70 |
+
|
| 71 |
+
cmd.libraries = [('name', {'sources': ('a', 'b')})]
|
| 72 |
+
self.assertEqual(cmd.get_source_files(), ['a', 'b'])
|
| 73 |
+
|
| 74 |
+
cmd.libraries = [('name', {'sources': ('a', 'b')}),
|
| 75 |
+
('name2', {'sources': ['c', 'd']})]
|
| 76 |
+
self.assertEqual(cmd.get_source_files(), ['a', 'b', 'c', 'd'])
|
| 77 |
+
|
| 78 |
+
def test_build_libraries(self):
|
| 79 |
+
|
| 80 |
+
pkg_dir, dist = self.create_dist()
|
| 81 |
+
cmd = build_clib(dist)
|
| 82 |
+
class FakeCompiler:
|
| 83 |
+
def compile(*args, **kw):
|
| 84 |
+
pass
|
| 85 |
+
create_static_lib = compile
|
| 86 |
+
|
| 87 |
+
cmd.compiler = FakeCompiler()
|
| 88 |
+
|
| 89 |
+
# build_libraries is also doing a bit of typo checking
|
| 90 |
+
lib = [('name', {'sources': 'notvalid'})]
|
| 91 |
+
self.assertRaises(DistutilsSetupError, cmd.build_libraries, lib)
|
| 92 |
+
|
| 93 |
+
lib = [('name', {'sources': list()})]
|
| 94 |
+
cmd.build_libraries(lib)
|
| 95 |
+
|
| 96 |
+
lib = [('name', {'sources': tuple()})]
|
| 97 |
+
cmd.build_libraries(lib)
|
| 98 |
+
|
| 99 |
+
def test_finalize_options(self):
|
| 100 |
+
pkg_dir, dist = self.create_dist()
|
| 101 |
+
cmd = build_clib(dist)
|
| 102 |
+
|
| 103 |
+
cmd.include_dirs = 'one-dir'
|
| 104 |
+
cmd.finalize_options()
|
| 105 |
+
self.assertEqual(cmd.include_dirs, ['one-dir'])
|
| 106 |
+
|
| 107 |
+
cmd.include_dirs = None
|
| 108 |
+
cmd.finalize_options()
|
| 109 |
+
self.assertEqual(cmd.include_dirs, [])
|
| 110 |
+
|
| 111 |
+
cmd.distribution.libraries = 'WONTWORK'
|
| 112 |
+
self.assertRaises(DistutilsSetupError, cmd.finalize_options)
|
| 113 |
+
|
| 114 |
+
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
|
| 115 |
+
def test_run(self):
|
| 116 |
+
pkg_dir, dist = self.create_dist()
|
| 117 |
+
cmd = build_clib(dist)
|
| 118 |
+
|
| 119 |
+
foo_c = os.path.join(pkg_dir, 'foo.c')
|
| 120 |
+
self.write_file(foo_c, 'int main(void) { return 1;}\n')
|
| 121 |
+
cmd.libraries = [('foo', {'sources': [foo_c]})]
|
| 122 |
+
|
| 123 |
+
build_temp = os.path.join(pkg_dir, 'build')
|
| 124 |
+
os.mkdir(build_temp)
|
| 125 |
+
cmd.build_temp = build_temp
|
| 126 |
+
cmd.build_clib = build_temp
|
| 127 |
+
|
| 128 |
+
# Before we run the command, we want to make sure
|
| 129 |
+
# all commands are present on the system.
|
| 130 |
+
ccmd = missing_compiler_executable()
|
| 131 |
+
if ccmd is not None:
|
| 132 |
+
self.skipTest('The %r command is not found' % ccmd)
|
| 133 |
+
|
| 134 |
+
# this should work
|
| 135 |
+
cmd.run()
|
| 136 |
+
|
| 137 |
+
# let's check the result
|
| 138 |
+
self.assertIn('libfoo.a', os.listdir(build_temp))
|
| 139 |
+
|
| 140 |
+
def test_suite():
|
| 141 |
+
return unittest.makeSuite(BuildCLibTestCase)
|
| 142 |
+
|
| 143 |
+
if __name__ == "__main__":
|
| 144 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_build_ext.py
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
from io import StringIO
|
| 4 |
+
import textwrap
|
| 5 |
+
|
| 6 |
+
from distutils.core import Distribution
|
| 7 |
+
from distutils.command.build_ext import build_ext
|
| 8 |
+
from distutils import sysconfig
|
| 9 |
+
from distutils.tests.support import (TempdirManager, LoggingSilencer,
|
| 10 |
+
copy_xxmodule_c, fixup_build_ext)
|
| 11 |
+
from distutils.extension import Extension
|
| 12 |
+
from distutils.errors import (
|
| 13 |
+
CompileError, DistutilsPlatformError, DistutilsSetupError,
|
| 14 |
+
UnknownFileError)
|
| 15 |
+
|
| 16 |
+
import unittest
|
| 17 |
+
from test import support
|
| 18 |
+
from test.support import os_helper
|
| 19 |
+
from test.support.script_helper import assert_python_ok
|
| 20 |
+
|
| 21 |
+
# http://bugs.python.org/issue4373
|
| 22 |
+
# Don't load the xx module more than once.
|
| 23 |
+
ALREADY_TESTED = False
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class BuildExtTestCase(TempdirManager,
|
| 27 |
+
LoggingSilencer,
|
| 28 |
+
unittest.TestCase):
|
| 29 |
+
def setUp(self):
|
| 30 |
+
# Create a simple test environment
|
| 31 |
+
super(BuildExtTestCase, self).setUp()
|
| 32 |
+
self.tmp_dir = self.mkdtemp()
|
| 33 |
+
import site
|
| 34 |
+
self.old_user_base = site.USER_BASE
|
| 35 |
+
site.USER_BASE = self.mkdtemp()
|
| 36 |
+
from distutils.command import build_ext
|
| 37 |
+
build_ext.USER_BASE = site.USER_BASE
|
| 38 |
+
self.old_config_vars = dict(sysconfig._config_vars)
|
| 39 |
+
|
| 40 |
+
# bpo-30132: On Windows, a .pdb file may be created in the current
|
| 41 |
+
# working directory. Create a temporary working directory to cleanup
|
| 42 |
+
# everything at the end of the test.
|
| 43 |
+
change_cwd = os_helper.change_cwd(self.tmp_dir)
|
| 44 |
+
change_cwd.__enter__()
|
| 45 |
+
self.addCleanup(change_cwd.__exit__, None, None, None)
|
| 46 |
+
|
| 47 |
+
def tearDown(self):
|
| 48 |
+
import site
|
| 49 |
+
site.USER_BASE = self.old_user_base
|
| 50 |
+
from distutils.command import build_ext
|
| 51 |
+
build_ext.USER_BASE = self.old_user_base
|
| 52 |
+
sysconfig._config_vars.clear()
|
| 53 |
+
sysconfig._config_vars.update(self.old_config_vars)
|
| 54 |
+
super(BuildExtTestCase, self).tearDown()
|
| 55 |
+
|
| 56 |
+
def build_ext(self, *args, **kwargs):
|
| 57 |
+
return build_ext(*args, **kwargs)
|
| 58 |
+
|
| 59 |
+
def test_build_ext(self):
|
| 60 |
+
cmd = support.missing_compiler_executable()
|
| 61 |
+
if cmd is not None:
|
| 62 |
+
self.skipTest('The %r command is not found' % cmd)
|
| 63 |
+
global ALREADY_TESTED
|
| 64 |
+
copy_xxmodule_c(self.tmp_dir)
|
| 65 |
+
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
|
| 66 |
+
xx_ext = Extension('xx', [xx_c])
|
| 67 |
+
dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
|
| 68 |
+
dist.package_dir = self.tmp_dir
|
| 69 |
+
cmd = self.build_ext(dist)
|
| 70 |
+
fixup_build_ext(cmd)
|
| 71 |
+
cmd.build_lib = self.tmp_dir
|
| 72 |
+
cmd.build_temp = self.tmp_dir
|
| 73 |
+
|
| 74 |
+
old_stdout = sys.stdout
|
| 75 |
+
if not support.verbose:
|
| 76 |
+
# silence compiler output
|
| 77 |
+
sys.stdout = StringIO()
|
| 78 |
+
try:
|
| 79 |
+
cmd.ensure_finalized()
|
| 80 |
+
cmd.run()
|
| 81 |
+
finally:
|
| 82 |
+
sys.stdout = old_stdout
|
| 83 |
+
|
| 84 |
+
if ALREADY_TESTED:
|
| 85 |
+
self.skipTest('Already tested in %s' % ALREADY_TESTED)
|
| 86 |
+
else:
|
| 87 |
+
ALREADY_TESTED = type(self).__name__
|
| 88 |
+
|
| 89 |
+
code = textwrap.dedent(f"""
|
| 90 |
+
tmp_dir = {self.tmp_dir!r}
|
| 91 |
+
|
| 92 |
+
import sys
|
| 93 |
+
import unittest
|
| 94 |
+
from test import support
|
| 95 |
+
|
| 96 |
+
sys.path.insert(0, tmp_dir)
|
| 97 |
+
import xx
|
| 98 |
+
|
| 99 |
+
class Tests(unittest.TestCase):
|
| 100 |
+
def test_xx(self):
|
| 101 |
+
for attr in ('error', 'foo', 'new', 'roj'):
|
| 102 |
+
self.assertTrue(hasattr(xx, attr))
|
| 103 |
+
|
| 104 |
+
self.assertEqual(xx.foo(2, 5), 7)
|
| 105 |
+
self.assertEqual(xx.foo(13,15), 28)
|
| 106 |
+
self.assertEqual(xx.new().demo(), None)
|
| 107 |
+
if support.HAVE_DOCSTRINGS:
|
| 108 |
+
doc = 'This is a template module just for instruction.'
|
| 109 |
+
self.assertEqual(xx.__doc__, doc)
|
| 110 |
+
self.assertIsInstance(xx.Null(), xx.Null)
|
| 111 |
+
self.assertIsInstance(xx.Str(), xx.Str)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
unittest.main()
|
| 115 |
+
""")
|
| 116 |
+
assert_python_ok('-c', code)
|
| 117 |
+
|
| 118 |
+
def test_solaris_enable_shared(self):
|
| 119 |
+
dist = Distribution({'name': 'xx'})
|
| 120 |
+
cmd = self.build_ext(dist)
|
| 121 |
+
old = sys.platform
|
| 122 |
+
|
| 123 |
+
sys.platform = 'sunos' # fooling finalize_options
|
| 124 |
+
from distutils.sysconfig import _config_vars
|
| 125 |
+
old_var = _config_vars.get('Py_ENABLE_SHARED')
|
| 126 |
+
_config_vars['Py_ENABLE_SHARED'] = 1
|
| 127 |
+
try:
|
| 128 |
+
cmd.ensure_finalized()
|
| 129 |
+
finally:
|
| 130 |
+
sys.platform = old
|
| 131 |
+
if old_var is None:
|
| 132 |
+
del _config_vars['Py_ENABLE_SHARED']
|
| 133 |
+
else:
|
| 134 |
+
_config_vars['Py_ENABLE_SHARED'] = old_var
|
| 135 |
+
|
| 136 |
+
# make sure we get some library dirs under solaris
|
| 137 |
+
self.assertGreater(len(cmd.library_dirs), 0)
|
| 138 |
+
|
| 139 |
+
def test_user_site(self):
|
| 140 |
+
import site
|
| 141 |
+
dist = Distribution({'name': 'xx'})
|
| 142 |
+
cmd = self.build_ext(dist)
|
| 143 |
+
|
| 144 |
+
# making sure the user option is there
|
| 145 |
+
options = [name for name, short, lable in
|
| 146 |
+
cmd.user_options]
|
| 147 |
+
self.assertIn('user', options)
|
| 148 |
+
|
| 149 |
+
# setting a value
|
| 150 |
+
cmd.user = 1
|
| 151 |
+
|
| 152 |
+
# setting user based lib and include
|
| 153 |
+
lib = os.path.join(site.USER_BASE, 'lib')
|
| 154 |
+
incl = os.path.join(site.USER_BASE, 'include')
|
| 155 |
+
os.mkdir(lib)
|
| 156 |
+
os.mkdir(incl)
|
| 157 |
+
|
| 158 |
+
# let's run finalize
|
| 159 |
+
cmd.ensure_finalized()
|
| 160 |
+
|
| 161 |
+
# see if include_dirs and library_dirs
|
| 162 |
+
# were set
|
| 163 |
+
self.assertIn(lib, cmd.library_dirs)
|
| 164 |
+
self.assertIn(lib, cmd.rpath)
|
| 165 |
+
self.assertIn(incl, cmd.include_dirs)
|
| 166 |
+
|
| 167 |
+
def test_optional_extension(self):
|
| 168 |
+
|
| 169 |
+
# this extension will fail, but let's ignore this failure
|
| 170 |
+
# with the optional argument.
|
| 171 |
+
modules = [Extension('foo', ['xxx'], optional=False)]
|
| 172 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 173 |
+
cmd = self.build_ext(dist)
|
| 174 |
+
cmd.ensure_finalized()
|
| 175 |
+
self.assertRaises((UnknownFileError, CompileError),
|
| 176 |
+
cmd.run) # should raise an error
|
| 177 |
+
|
| 178 |
+
modules = [Extension('foo', ['xxx'], optional=True)]
|
| 179 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 180 |
+
cmd = self.build_ext(dist)
|
| 181 |
+
cmd.ensure_finalized()
|
| 182 |
+
cmd.run() # should pass
|
| 183 |
+
|
| 184 |
+
def test_finalize_options(self):
|
| 185 |
+
# Make sure Python's include directories (for Python.h, pyconfig.h,
|
| 186 |
+
# etc.) are in the include search path.
|
| 187 |
+
modules = [Extension('foo', ['xxx'], optional=False)]
|
| 188 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 189 |
+
cmd = self.build_ext(dist)
|
| 190 |
+
cmd.finalize_options()
|
| 191 |
+
|
| 192 |
+
py_include = sysconfig.get_python_inc()
|
| 193 |
+
for p in py_include.split(os.path.pathsep):
|
| 194 |
+
self.assertIn(p, cmd.include_dirs)
|
| 195 |
+
|
| 196 |
+
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
|
| 197 |
+
for p in plat_py_include.split(os.path.pathsep):
|
| 198 |
+
self.assertIn(p, cmd.include_dirs)
|
| 199 |
+
|
| 200 |
+
# make sure cmd.libraries is turned into a list
|
| 201 |
+
# if it's a string
|
| 202 |
+
cmd = self.build_ext(dist)
|
| 203 |
+
cmd.libraries = 'my_lib, other_lib lastlib'
|
| 204 |
+
cmd.finalize_options()
|
| 205 |
+
self.assertEqual(cmd.libraries, ['my_lib', 'other_lib', 'lastlib'])
|
| 206 |
+
|
| 207 |
+
# make sure cmd.library_dirs is turned into a list
|
| 208 |
+
# if it's a string
|
| 209 |
+
cmd = self.build_ext(dist)
|
| 210 |
+
cmd.library_dirs = 'my_lib_dir%sother_lib_dir' % os.pathsep
|
| 211 |
+
cmd.finalize_options()
|
| 212 |
+
self.assertIn('my_lib_dir', cmd.library_dirs)
|
| 213 |
+
self.assertIn('other_lib_dir', cmd.library_dirs)
|
| 214 |
+
|
| 215 |
+
# make sure rpath is turned into a list
|
| 216 |
+
# if it's a string
|
| 217 |
+
cmd = self.build_ext(dist)
|
| 218 |
+
cmd.rpath = 'one%stwo' % os.pathsep
|
| 219 |
+
cmd.finalize_options()
|
| 220 |
+
self.assertEqual(cmd.rpath, ['one', 'two'])
|
| 221 |
+
|
| 222 |
+
# make sure cmd.link_objects is turned into a list
|
| 223 |
+
# if it's a string
|
| 224 |
+
cmd = build_ext(dist)
|
| 225 |
+
cmd.link_objects = 'one two,three'
|
| 226 |
+
cmd.finalize_options()
|
| 227 |
+
self.assertEqual(cmd.link_objects, ['one', 'two', 'three'])
|
| 228 |
+
|
| 229 |
+
# XXX more tests to perform for win32
|
| 230 |
+
|
| 231 |
+
# make sure define is turned into 2-tuples
|
| 232 |
+
# strings if they are ','-separated strings
|
| 233 |
+
cmd = self.build_ext(dist)
|
| 234 |
+
cmd.define = 'one,two'
|
| 235 |
+
cmd.finalize_options()
|
| 236 |
+
self.assertEqual(cmd.define, [('one', '1'), ('two', '1')])
|
| 237 |
+
|
| 238 |
+
# make sure undef is turned into a list of
|
| 239 |
+
# strings if they are ','-separated strings
|
| 240 |
+
cmd = self.build_ext(dist)
|
| 241 |
+
cmd.undef = 'one,two'
|
| 242 |
+
cmd.finalize_options()
|
| 243 |
+
self.assertEqual(cmd.undef, ['one', 'two'])
|
| 244 |
+
|
| 245 |
+
# make sure swig_opts is turned into a list
|
| 246 |
+
cmd = self.build_ext(dist)
|
| 247 |
+
cmd.swig_opts = None
|
| 248 |
+
cmd.finalize_options()
|
| 249 |
+
self.assertEqual(cmd.swig_opts, [])
|
| 250 |
+
|
| 251 |
+
cmd = self.build_ext(dist)
|
| 252 |
+
cmd.swig_opts = '1 2'
|
| 253 |
+
cmd.finalize_options()
|
| 254 |
+
self.assertEqual(cmd.swig_opts, ['1', '2'])
|
| 255 |
+
|
| 256 |
+
def test_check_extensions_list(self):
|
| 257 |
+
dist = Distribution()
|
| 258 |
+
cmd = self.build_ext(dist)
|
| 259 |
+
cmd.finalize_options()
|
| 260 |
+
|
| 261 |
+
#'extensions' option must be a list of Extension instances
|
| 262 |
+
self.assertRaises(DistutilsSetupError,
|
| 263 |
+
cmd.check_extensions_list, 'foo')
|
| 264 |
+
|
| 265 |
+
# each element of 'ext_modules' option must be an
|
| 266 |
+
# Extension instance or 2-tuple
|
| 267 |
+
exts = [('bar', 'foo', 'bar'), 'foo']
|
| 268 |
+
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
|
| 269 |
+
|
| 270 |
+
# first element of each tuple in 'ext_modules'
|
| 271 |
+
# must be the extension name (a string) and match
|
| 272 |
+
# a python dotted-separated name
|
| 273 |
+
exts = [('foo-bar', '')]
|
| 274 |
+
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
|
| 275 |
+
|
| 276 |
+
# second element of each tuple in 'ext_modules'
|
| 277 |
+
# must be a dictionary (build info)
|
| 278 |
+
exts = [('foo.bar', '')]
|
| 279 |
+
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
|
| 280 |
+
|
| 281 |
+
# ok this one should pass
|
| 282 |
+
exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
|
| 283 |
+
'some': 'bar'})]
|
| 284 |
+
cmd.check_extensions_list(exts)
|
| 285 |
+
ext = exts[0]
|
| 286 |
+
self.assertIsInstance(ext, Extension)
|
| 287 |
+
|
| 288 |
+
# check_extensions_list adds in ext the values passed
|
| 289 |
+
# when they are in ('include_dirs', 'library_dirs', 'libraries'
|
| 290 |
+
# 'extra_objects', 'extra_compile_args', 'extra_link_args')
|
| 291 |
+
self.assertEqual(ext.libraries, 'foo')
|
| 292 |
+
self.assertFalse(hasattr(ext, 'some'))
|
| 293 |
+
|
| 294 |
+
# 'macros' element of build info dict must be 1- or 2-tuple
|
| 295 |
+
exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
|
| 296 |
+
'some': 'bar', 'macros': [('1', '2', '3'), 'foo']})]
|
| 297 |
+
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
|
| 298 |
+
|
| 299 |
+
exts[0][1]['macros'] = [('1', '2'), ('3',)]
|
| 300 |
+
cmd.check_extensions_list(exts)
|
| 301 |
+
self.assertEqual(exts[0].undef_macros, ['3'])
|
| 302 |
+
self.assertEqual(exts[0].define_macros, [('1', '2')])
|
| 303 |
+
|
| 304 |
+
def test_get_source_files(self):
|
| 305 |
+
modules = [Extension('foo', ['xxx'], optional=False)]
|
| 306 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 307 |
+
cmd = self.build_ext(dist)
|
| 308 |
+
cmd.ensure_finalized()
|
| 309 |
+
self.assertEqual(cmd.get_source_files(), ['xxx'])
|
| 310 |
+
|
| 311 |
+
def test_unicode_module_names(self):
|
| 312 |
+
modules = [
|
| 313 |
+
Extension('foo', ['aaa'], optional=False),
|
| 314 |
+
Extension('föö', ['uuu'], optional=False),
|
| 315 |
+
]
|
| 316 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 317 |
+
cmd = self.build_ext(dist)
|
| 318 |
+
cmd.ensure_finalized()
|
| 319 |
+
self.assertRegex(cmd.get_ext_filename(modules[0].name), r'foo(_d)?\..*')
|
| 320 |
+
self.assertRegex(cmd.get_ext_filename(modules[1].name), r'föö(_d)?\..*')
|
| 321 |
+
self.assertEqual(cmd.get_export_symbols(modules[0]), ['PyInit_foo'])
|
| 322 |
+
self.assertEqual(cmd.get_export_symbols(modules[1]), ['PyInitU_f_gkaa'])
|
| 323 |
+
|
| 324 |
+
def test_compiler_option(self):
|
| 325 |
+
# cmd.compiler is an option and
|
| 326 |
+
# should not be overridden by a compiler instance
|
| 327 |
+
# when the command is run
|
| 328 |
+
dist = Distribution()
|
| 329 |
+
cmd = self.build_ext(dist)
|
| 330 |
+
cmd.compiler = 'unix'
|
| 331 |
+
cmd.ensure_finalized()
|
| 332 |
+
cmd.run()
|
| 333 |
+
self.assertEqual(cmd.compiler, 'unix')
|
| 334 |
+
|
| 335 |
+
def test_get_outputs(self):
|
| 336 |
+
cmd = support.missing_compiler_executable()
|
| 337 |
+
if cmd is not None:
|
| 338 |
+
self.skipTest('The %r command is not found' % cmd)
|
| 339 |
+
tmp_dir = self.mkdtemp()
|
| 340 |
+
c_file = os.path.join(tmp_dir, 'foo.c')
|
| 341 |
+
self.write_file(c_file, 'void PyInit_foo(void) {}\n')
|
| 342 |
+
ext = Extension('foo', [c_file], optional=False)
|
| 343 |
+
dist = Distribution({'name': 'xx',
|
| 344 |
+
'ext_modules': [ext]})
|
| 345 |
+
cmd = self.build_ext(dist)
|
| 346 |
+
fixup_build_ext(cmd)
|
| 347 |
+
cmd.ensure_finalized()
|
| 348 |
+
self.assertEqual(len(cmd.get_outputs()), 1)
|
| 349 |
+
|
| 350 |
+
cmd.build_lib = os.path.join(self.tmp_dir, 'build')
|
| 351 |
+
cmd.build_temp = os.path.join(self.tmp_dir, 'tempt')
|
| 352 |
+
|
| 353 |
+
# issue #5977 : distutils build_ext.get_outputs
|
| 354 |
+
# returns wrong result with --inplace
|
| 355 |
+
other_tmp_dir = os.path.realpath(self.mkdtemp())
|
| 356 |
+
old_wd = os.getcwd()
|
| 357 |
+
os.chdir(other_tmp_dir)
|
| 358 |
+
try:
|
| 359 |
+
cmd.inplace = 1
|
| 360 |
+
cmd.run()
|
| 361 |
+
so_file = cmd.get_outputs()[0]
|
| 362 |
+
finally:
|
| 363 |
+
os.chdir(old_wd)
|
| 364 |
+
self.assertTrue(os.path.exists(so_file))
|
| 365 |
+
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
| 366 |
+
self.assertTrue(so_file.endswith(ext_suffix))
|
| 367 |
+
so_dir = os.path.dirname(so_file)
|
| 368 |
+
self.assertEqual(so_dir, other_tmp_dir)
|
| 369 |
+
|
| 370 |
+
cmd.inplace = 0
|
| 371 |
+
cmd.compiler = None
|
| 372 |
+
cmd.run()
|
| 373 |
+
so_file = cmd.get_outputs()[0]
|
| 374 |
+
self.assertTrue(os.path.exists(so_file))
|
| 375 |
+
self.assertTrue(so_file.endswith(ext_suffix))
|
| 376 |
+
so_dir = os.path.dirname(so_file)
|
| 377 |
+
self.assertEqual(so_dir, cmd.build_lib)
|
| 378 |
+
|
| 379 |
+
# inplace = 0, cmd.package = 'bar'
|
| 380 |
+
build_py = cmd.get_finalized_command('build_py')
|
| 381 |
+
build_py.package_dir = {'': 'bar'}
|
| 382 |
+
path = cmd.get_ext_fullpath('foo')
|
| 383 |
+
# checking that the last directory is the build_dir
|
| 384 |
+
path = os.path.split(path)[0]
|
| 385 |
+
self.assertEqual(path, cmd.build_lib)
|
| 386 |
+
|
| 387 |
+
# inplace = 1, cmd.package = 'bar'
|
| 388 |
+
cmd.inplace = 1
|
| 389 |
+
other_tmp_dir = os.path.realpath(self.mkdtemp())
|
| 390 |
+
old_wd = os.getcwd()
|
| 391 |
+
os.chdir(other_tmp_dir)
|
| 392 |
+
try:
|
| 393 |
+
path = cmd.get_ext_fullpath('foo')
|
| 394 |
+
finally:
|
| 395 |
+
os.chdir(old_wd)
|
| 396 |
+
# checking that the last directory is bar
|
| 397 |
+
path = os.path.split(path)[0]
|
| 398 |
+
lastdir = os.path.split(path)[-1]
|
| 399 |
+
self.assertEqual(lastdir, 'bar')
|
| 400 |
+
|
| 401 |
+
def test_ext_fullpath(self):
|
| 402 |
+
ext = sysconfig.get_config_var('EXT_SUFFIX')
|
| 403 |
+
# building lxml.etree inplace
|
| 404 |
+
#etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
|
| 405 |
+
#etree_ext = Extension('lxml.etree', [etree_c])
|
| 406 |
+
#dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
|
| 407 |
+
dist = Distribution()
|
| 408 |
+
cmd = self.build_ext(dist)
|
| 409 |
+
cmd.inplace = 1
|
| 410 |
+
cmd.distribution.package_dir = {'': 'src'}
|
| 411 |
+
cmd.distribution.packages = ['lxml', 'lxml.html']
|
| 412 |
+
curdir = os.getcwd()
|
| 413 |
+
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
|
| 414 |
+
path = cmd.get_ext_fullpath('lxml.etree')
|
| 415 |
+
self.assertEqual(wanted, path)
|
| 416 |
+
|
| 417 |
+
# building lxml.etree not inplace
|
| 418 |
+
cmd.inplace = 0
|
| 419 |
+
cmd.build_lib = os.path.join(curdir, 'tmpdir')
|
| 420 |
+
wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree' + ext)
|
| 421 |
+
path = cmd.get_ext_fullpath('lxml.etree')
|
| 422 |
+
self.assertEqual(wanted, path)
|
| 423 |
+
|
| 424 |
+
# building twisted.runner.portmap not inplace
|
| 425 |
+
build_py = cmd.get_finalized_command('build_py')
|
| 426 |
+
build_py.package_dir = {}
|
| 427 |
+
cmd.distribution.packages = ['twisted', 'twisted.runner.portmap']
|
| 428 |
+
path = cmd.get_ext_fullpath('twisted.runner.portmap')
|
| 429 |
+
wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
|
| 430 |
+
'portmap' + ext)
|
| 431 |
+
self.assertEqual(wanted, path)
|
| 432 |
+
|
| 433 |
+
# building twisted.runner.portmap inplace
|
| 434 |
+
cmd.inplace = 1
|
| 435 |
+
path = cmd.get_ext_fullpath('twisted.runner.portmap')
|
| 436 |
+
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
|
| 437 |
+
self.assertEqual(wanted, path)
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
|
| 441 |
+
def test_deployment_target_default(self):
|
| 442 |
+
# Issue 9516: Test that, in the absence of the environment variable,
|
| 443 |
+
# an extension module is compiled with the same deployment target as
|
| 444 |
+
# the interpreter.
|
| 445 |
+
self._try_compile_deployment_target('==', None)
|
| 446 |
+
|
| 447 |
+
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
|
| 448 |
+
def test_deployment_target_too_low(self):
|
| 449 |
+
# Issue 9516: Test that an extension module is not allowed to be
|
| 450 |
+
# compiled with a deployment target less than that of the interpreter.
|
| 451 |
+
self.assertRaises(DistutilsPlatformError,
|
| 452 |
+
self._try_compile_deployment_target, '>', '10.1')
|
| 453 |
+
|
| 454 |
+
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
|
| 455 |
+
def test_deployment_target_higher_ok(self):
|
| 456 |
+
# Issue 9516: Test that an extension module can be compiled with a
|
| 457 |
+
# deployment target higher than that of the interpreter: the ext
|
| 458 |
+
# module may depend on some newer OS feature.
|
| 459 |
+
deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
|
| 460 |
+
if deptarget:
|
| 461 |
+
# increment the minor version number (i.e. 10.6 -> 10.7)
|
| 462 |
+
deptarget = [int(x) for x in deptarget.split('.')]
|
| 463 |
+
deptarget[-1] += 1
|
| 464 |
+
deptarget = '.'.join(str(i) for i in deptarget)
|
| 465 |
+
self._try_compile_deployment_target('<', deptarget)
|
| 466 |
+
|
| 467 |
+
def _try_compile_deployment_target(self, operator, target):
|
| 468 |
+
orig_environ = os.environ
|
| 469 |
+
os.environ = orig_environ.copy()
|
| 470 |
+
self.addCleanup(setattr, os, 'environ', orig_environ)
|
| 471 |
+
|
| 472 |
+
if target is None:
|
| 473 |
+
if os.environ.get('MACOSX_DEPLOYMENT_TARGET'):
|
| 474 |
+
del os.environ['MACOSX_DEPLOYMENT_TARGET']
|
| 475 |
+
else:
|
| 476 |
+
os.environ['MACOSX_DEPLOYMENT_TARGET'] = target
|
| 477 |
+
|
| 478 |
+
deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c')
|
| 479 |
+
|
| 480 |
+
with open(deptarget_c, 'w') as fp:
|
| 481 |
+
fp.write(textwrap.dedent('''\
|
| 482 |
+
#include <AvailabilityMacros.h>
|
| 483 |
+
|
| 484 |
+
int dummy;
|
| 485 |
+
|
| 486 |
+
#if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED
|
| 487 |
+
#else
|
| 488 |
+
#error "Unexpected target"
|
| 489 |
+
#endif
|
| 490 |
+
|
| 491 |
+
''' % operator))
|
| 492 |
+
|
| 493 |
+
# get the deployment target that the interpreter was built with
|
| 494 |
+
target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
|
| 495 |
+
target = tuple(map(int, target.split('.')[0:2]))
|
| 496 |
+
# format the target value as defined in the Apple
|
| 497 |
+
# Availability Macros. We can't use the macro names since
|
| 498 |
+
# at least one value we test with will not exist yet.
|
| 499 |
+
if target[:2] < (10, 10):
|
| 500 |
+
# for 10.1 through 10.9.x -> "10n0"
|
| 501 |
+
target = '%02d%01d0' % target
|
| 502 |
+
else:
|
| 503 |
+
# for 10.10 and beyond -> "10nn00"
|
| 504 |
+
if len(target) >= 2:
|
| 505 |
+
target = '%02d%02d00' % target
|
| 506 |
+
else:
|
| 507 |
+
# 11 and later can have no minor version (11 instead of 11.0)
|
| 508 |
+
target = '%02d0000' % target
|
| 509 |
+
deptarget_ext = Extension(
|
| 510 |
+
'deptarget',
|
| 511 |
+
[deptarget_c],
|
| 512 |
+
extra_compile_args=['-DTARGET=%s'%(target,)],
|
| 513 |
+
)
|
| 514 |
+
dist = Distribution({
|
| 515 |
+
'name': 'deptarget',
|
| 516 |
+
'ext_modules': [deptarget_ext]
|
| 517 |
+
})
|
| 518 |
+
dist.package_dir = self.tmp_dir
|
| 519 |
+
cmd = self.build_ext(dist)
|
| 520 |
+
cmd.build_lib = self.tmp_dir
|
| 521 |
+
cmd.build_temp = self.tmp_dir
|
| 522 |
+
|
| 523 |
+
try:
|
| 524 |
+
old_stdout = sys.stdout
|
| 525 |
+
if not support.verbose:
|
| 526 |
+
# silence compiler output
|
| 527 |
+
sys.stdout = StringIO()
|
| 528 |
+
try:
|
| 529 |
+
cmd.ensure_finalized()
|
| 530 |
+
cmd.run()
|
| 531 |
+
finally:
|
| 532 |
+
sys.stdout = old_stdout
|
| 533 |
+
|
| 534 |
+
except CompileError:
|
| 535 |
+
self.fail("Wrong deployment target during compilation")
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
class ParallelBuildExtTestCase(BuildExtTestCase):
|
| 539 |
+
|
| 540 |
+
def build_ext(self, *args, **kwargs):
|
| 541 |
+
build_ext = super().build_ext(*args, **kwargs)
|
| 542 |
+
build_ext.parallel = True
|
| 543 |
+
return build_ext
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
def test_suite():
|
| 547 |
+
suite = unittest.TestSuite()
|
| 548 |
+
suite.addTest(unittest.makeSuite(BuildExtTestCase))
|
| 549 |
+
suite.addTest(unittest.makeSuite(ParallelBuildExtTestCase))
|
| 550 |
+
return suite
|
| 551 |
+
|
| 552 |
+
if __name__ == '__main__':
|
| 553 |
+
support.run_unittest(__name__)
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_build_py.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build_py."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import unittest
|
| 6 |
+
|
| 7 |
+
from distutils.command.build_py import build_py
|
| 8 |
+
from distutils.core import Distribution
|
| 9 |
+
from distutils.errors import DistutilsFileError
|
| 10 |
+
|
| 11 |
+
from distutils.tests import support
|
| 12 |
+
from test.support import run_unittest
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class BuildPyTestCase(support.TempdirManager,
|
| 16 |
+
support.LoggingSilencer,
|
| 17 |
+
unittest.TestCase):
|
| 18 |
+
|
| 19 |
+
def test_package_data(self):
|
| 20 |
+
sources = self.mkdtemp()
|
| 21 |
+
f = open(os.path.join(sources, "__init__.py"), "w")
|
| 22 |
+
try:
|
| 23 |
+
f.write("# Pretend this is a package.")
|
| 24 |
+
finally:
|
| 25 |
+
f.close()
|
| 26 |
+
f = open(os.path.join(sources, "README.txt"), "w")
|
| 27 |
+
try:
|
| 28 |
+
f.write("Info about this package")
|
| 29 |
+
finally:
|
| 30 |
+
f.close()
|
| 31 |
+
|
| 32 |
+
destination = self.mkdtemp()
|
| 33 |
+
|
| 34 |
+
dist = Distribution({"packages": ["pkg"],
|
| 35 |
+
"package_dir": {"pkg": sources}})
|
| 36 |
+
# script_name need not exist, it just need to be initialized
|
| 37 |
+
dist.script_name = os.path.join(sources, "setup.py")
|
| 38 |
+
dist.command_obj["build"] = support.DummyCommand(
|
| 39 |
+
force=0,
|
| 40 |
+
build_lib=destination)
|
| 41 |
+
dist.packages = ["pkg"]
|
| 42 |
+
dist.package_data = {"pkg": ["README.txt"]}
|
| 43 |
+
dist.package_dir = {"pkg": sources}
|
| 44 |
+
|
| 45 |
+
cmd = build_py(dist)
|
| 46 |
+
cmd.compile = 1
|
| 47 |
+
cmd.ensure_finalized()
|
| 48 |
+
self.assertEqual(cmd.package_data, dist.package_data)
|
| 49 |
+
|
| 50 |
+
cmd.run()
|
| 51 |
+
|
| 52 |
+
# This makes sure the list of outputs includes byte-compiled
|
| 53 |
+
# files for Python modules but not for package data files
|
| 54 |
+
# (there shouldn't *be* byte-code files for those!).
|
| 55 |
+
self.assertEqual(len(cmd.get_outputs()), 3)
|
| 56 |
+
pkgdest = os.path.join(destination, "pkg")
|
| 57 |
+
files = os.listdir(pkgdest)
|
| 58 |
+
pycache_dir = os.path.join(pkgdest, "__pycache__")
|
| 59 |
+
self.assertIn("__init__.py", files)
|
| 60 |
+
self.assertIn("README.txt", files)
|
| 61 |
+
if sys.dont_write_bytecode:
|
| 62 |
+
self.assertFalse(os.path.exists(pycache_dir))
|
| 63 |
+
else:
|
| 64 |
+
pyc_files = os.listdir(pycache_dir)
|
| 65 |
+
self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag,
|
| 66 |
+
pyc_files)
|
| 67 |
+
|
| 68 |
+
def test_empty_package_dir(self):
|
| 69 |
+
# See bugs #1668596/#1720897
|
| 70 |
+
sources = self.mkdtemp()
|
| 71 |
+
open(os.path.join(sources, "__init__.py"), "w").close()
|
| 72 |
+
|
| 73 |
+
testdir = os.path.join(sources, "doc")
|
| 74 |
+
os.mkdir(testdir)
|
| 75 |
+
open(os.path.join(testdir, "testfile"), "w").close()
|
| 76 |
+
|
| 77 |
+
os.chdir(sources)
|
| 78 |
+
dist = Distribution({"packages": ["pkg"],
|
| 79 |
+
"package_dir": {"pkg": ""},
|
| 80 |
+
"package_data": {"pkg": ["doc/*"]}})
|
| 81 |
+
# script_name need not exist, it just need to be initialized
|
| 82 |
+
dist.script_name = os.path.join(sources, "setup.py")
|
| 83 |
+
dist.script_args = ["build"]
|
| 84 |
+
dist.parse_command_line()
|
| 85 |
+
|
| 86 |
+
try:
|
| 87 |
+
dist.run_commands()
|
| 88 |
+
except DistutilsFileError:
|
| 89 |
+
self.fail("failed package_data test when package_dir is ''")
|
| 90 |
+
|
| 91 |
+
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
|
| 92 |
+
def test_byte_compile(self):
|
| 93 |
+
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
|
| 94 |
+
os.chdir(project_dir)
|
| 95 |
+
self.write_file('boiledeggs.py', 'import antigravity')
|
| 96 |
+
cmd = build_py(dist)
|
| 97 |
+
cmd.compile = 1
|
| 98 |
+
cmd.build_lib = 'here'
|
| 99 |
+
cmd.finalize_options()
|
| 100 |
+
cmd.run()
|
| 101 |
+
|
| 102 |
+
found = os.listdir(cmd.build_lib)
|
| 103 |
+
self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
|
| 104 |
+
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
|
| 105 |
+
self.assertEqual(found,
|
| 106 |
+
['boiledeggs.%s.pyc' % sys.implementation.cache_tag])
|
| 107 |
+
|
| 108 |
+
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
|
| 109 |
+
def test_byte_compile_optimized(self):
|
| 110 |
+
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
|
| 111 |
+
os.chdir(project_dir)
|
| 112 |
+
self.write_file('boiledeggs.py', 'import antigravity')
|
| 113 |
+
cmd = build_py(dist)
|
| 114 |
+
cmd.compile = 0
|
| 115 |
+
cmd.optimize = 1
|
| 116 |
+
cmd.build_lib = 'here'
|
| 117 |
+
cmd.finalize_options()
|
| 118 |
+
cmd.run()
|
| 119 |
+
|
| 120 |
+
found = os.listdir(cmd.build_lib)
|
| 121 |
+
self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
|
| 122 |
+
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
|
| 123 |
+
expect = 'boiledeggs.{}.opt-1.pyc'.format(sys.implementation.cache_tag)
|
| 124 |
+
self.assertEqual(sorted(found), [expect])
|
| 125 |
+
|
| 126 |
+
def test_dir_in_package_data(self):
|
| 127 |
+
"""
|
| 128 |
+
A directory in package_data should not be added to the filelist.
|
| 129 |
+
"""
|
| 130 |
+
# See bug 19286
|
| 131 |
+
sources = self.mkdtemp()
|
| 132 |
+
pkg_dir = os.path.join(sources, "pkg")
|
| 133 |
+
|
| 134 |
+
os.mkdir(pkg_dir)
|
| 135 |
+
open(os.path.join(pkg_dir, "__init__.py"), "w").close()
|
| 136 |
+
|
| 137 |
+
docdir = os.path.join(pkg_dir, "doc")
|
| 138 |
+
os.mkdir(docdir)
|
| 139 |
+
open(os.path.join(docdir, "testfile"), "w").close()
|
| 140 |
+
|
| 141 |
+
# create the directory that could be incorrectly detected as a file
|
| 142 |
+
os.mkdir(os.path.join(docdir, 'otherdir'))
|
| 143 |
+
|
| 144 |
+
os.chdir(sources)
|
| 145 |
+
dist = Distribution({"packages": ["pkg"],
|
| 146 |
+
"package_data": {"pkg": ["doc/*"]}})
|
| 147 |
+
# script_name need not exist, it just need to be initialized
|
| 148 |
+
dist.script_name = os.path.join(sources, "setup.py")
|
| 149 |
+
dist.script_args = ["build"]
|
| 150 |
+
dist.parse_command_line()
|
| 151 |
+
|
| 152 |
+
try:
|
| 153 |
+
dist.run_commands()
|
| 154 |
+
except DistutilsFileError:
|
| 155 |
+
self.fail("failed package_data when data dir includes a dir")
|
| 156 |
+
|
| 157 |
+
def test_dont_write_bytecode(self):
|
| 158 |
+
# makes sure byte_compile is not used
|
| 159 |
+
dist = self.create_dist()[1]
|
| 160 |
+
cmd = build_py(dist)
|
| 161 |
+
cmd.compile = 1
|
| 162 |
+
cmd.optimize = 1
|
| 163 |
+
|
| 164 |
+
old_dont_write_bytecode = sys.dont_write_bytecode
|
| 165 |
+
sys.dont_write_bytecode = True
|
| 166 |
+
try:
|
| 167 |
+
cmd.byte_compile([])
|
| 168 |
+
finally:
|
| 169 |
+
sys.dont_write_bytecode = old_dont_write_bytecode
|
| 170 |
+
|
| 171 |
+
self.assertIn('byte-compiling is disabled',
|
| 172 |
+
self.logs[0][1] % self.logs[0][2])
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def test_suite():
|
| 176 |
+
return unittest.makeSuite(BuildPyTestCase)
|
| 177 |
+
|
| 178 |
+
if __name__ == "__main__":
|
| 179 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_build_scripts.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build_scripts."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
from distutils.command.build_scripts import build_scripts
|
| 7 |
+
from distutils.core import Distribution
|
| 8 |
+
from distutils import sysconfig
|
| 9 |
+
|
| 10 |
+
from distutils.tests import support
|
| 11 |
+
from test.support import run_unittest
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class BuildScriptsTestCase(support.TempdirManager,
|
| 15 |
+
support.LoggingSilencer,
|
| 16 |
+
unittest.TestCase):
|
| 17 |
+
|
| 18 |
+
def test_default_settings(self):
|
| 19 |
+
cmd = self.get_build_scripts_cmd("/foo/bar", [])
|
| 20 |
+
self.assertFalse(cmd.force)
|
| 21 |
+
self.assertIsNone(cmd.build_dir)
|
| 22 |
+
|
| 23 |
+
cmd.finalize_options()
|
| 24 |
+
|
| 25 |
+
self.assertTrue(cmd.force)
|
| 26 |
+
self.assertEqual(cmd.build_dir, "/foo/bar")
|
| 27 |
+
|
| 28 |
+
def test_build(self):
|
| 29 |
+
source = self.mkdtemp()
|
| 30 |
+
target = self.mkdtemp()
|
| 31 |
+
expected = self.write_sample_scripts(source)
|
| 32 |
+
|
| 33 |
+
cmd = self.get_build_scripts_cmd(target,
|
| 34 |
+
[os.path.join(source, fn)
|
| 35 |
+
for fn in expected])
|
| 36 |
+
cmd.finalize_options()
|
| 37 |
+
cmd.run()
|
| 38 |
+
|
| 39 |
+
built = os.listdir(target)
|
| 40 |
+
for name in expected:
|
| 41 |
+
self.assertIn(name, built)
|
| 42 |
+
|
| 43 |
+
def get_build_scripts_cmd(self, target, scripts):
|
| 44 |
+
import sys
|
| 45 |
+
dist = Distribution()
|
| 46 |
+
dist.scripts = scripts
|
| 47 |
+
dist.command_obj["build"] = support.DummyCommand(
|
| 48 |
+
build_scripts=target,
|
| 49 |
+
force=1,
|
| 50 |
+
executable=sys.executable
|
| 51 |
+
)
|
| 52 |
+
return build_scripts(dist)
|
| 53 |
+
|
| 54 |
+
def write_sample_scripts(self, dir):
|
| 55 |
+
expected = []
|
| 56 |
+
expected.append("script1.py")
|
| 57 |
+
self.write_script(dir, "script1.py",
|
| 58 |
+
("#! /usr/bin/env python2.3\n"
|
| 59 |
+
"# bogus script w/ Python sh-bang\n"
|
| 60 |
+
"pass\n"))
|
| 61 |
+
expected.append("script2.py")
|
| 62 |
+
self.write_script(dir, "script2.py",
|
| 63 |
+
("#!/usr/bin/python\n"
|
| 64 |
+
"# bogus script w/ Python sh-bang\n"
|
| 65 |
+
"pass\n"))
|
| 66 |
+
expected.append("shell.sh")
|
| 67 |
+
self.write_script(dir, "shell.sh",
|
| 68 |
+
("#!/bin/sh\n"
|
| 69 |
+
"# bogus shell script w/ sh-bang\n"
|
| 70 |
+
"exit 0\n"))
|
| 71 |
+
return expected
|
| 72 |
+
|
| 73 |
+
def write_script(self, dir, name, text):
|
| 74 |
+
f = open(os.path.join(dir, name), "w")
|
| 75 |
+
try:
|
| 76 |
+
f.write(text)
|
| 77 |
+
finally:
|
| 78 |
+
f.close()
|
| 79 |
+
|
| 80 |
+
def test_version_int(self):
|
| 81 |
+
source = self.mkdtemp()
|
| 82 |
+
target = self.mkdtemp()
|
| 83 |
+
expected = self.write_sample_scripts(source)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
cmd = self.get_build_scripts_cmd(target,
|
| 87 |
+
[os.path.join(source, fn)
|
| 88 |
+
for fn in expected])
|
| 89 |
+
cmd.finalize_options()
|
| 90 |
+
|
| 91 |
+
# http://bugs.python.org/issue4524
|
| 92 |
+
#
|
| 93 |
+
# On linux-g++-32 with command line `./configure --enable-ipv6
|
| 94 |
+
# --with-suffix=3`, python is compiled okay but the build scripts
|
| 95 |
+
# failed when writing the name of the executable
|
| 96 |
+
old = sysconfig.get_config_vars().get('VERSION')
|
| 97 |
+
sysconfig._config_vars['VERSION'] = 4
|
| 98 |
+
try:
|
| 99 |
+
cmd.run()
|
| 100 |
+
finally:
|
| 101 |
+
if old is not None:
|
| 102 |
+
sysconfig._config_vars['VERSION'] = old
|
| 103 |
+
|
| 104 |
+
built = os.listdir(target)
|
| 105 |
+
for name in expected:
|
| 106 |
+
self.assertIn(name, built)
|
| 107 |
+
|
| 108 |
+
def test_suite():
|
| 109 |
+
return unittest.makeSuite(BuildScriptsTestCase)
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_check.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.check."""
|
| 2 |
+
import os
|
| 3 |
+
import textwrap
|
| 4 |
+
import unittest
|
| 5 |
+
from test.support import run_unittest
|
| 6 |
+
|
| 7 |
+
from distutils.command.check import check, HAS_DOCUTILS
|
| 8 |
+
from distutils.tests import support
|
| 9 |
+
from distutils.errors import DistutilsSetupError
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
import pygments
|
| 13 |
+
except ImportError:
|
| 14 |
+
pygments = None
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
HERE = os.path.dirname(__file__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class CheckTestCase(support.LoggingSilencer,
|
| 21 |
+
support.TempdirManager,
|
| 22 |
+
unittest.TestCase):
|
| 23 |
+
|
| 24 |
+
def _run(self, metadata=None, cwd=None, **options):
|
| 25 |
+
if metadata is None:
|
| 26 |
+
metadata = {}
|
| 27 |
+
if cwd is not None:
|
| 28 |
+
old_dir = os.getcwd()
|
| 29 |
+
os.chdir(cwd)
|
| 30 |
+
pkg_info, dist = self.create_dist(**metadata)
|
| 31 |
+
cmd = check(dist)
|
| 32 |
+
cmd.initialize_options()
|
| 33 |
+
for name, value in options.items():
|
| 34 |
+
setattr(cmd, name, value)
|
| 35 |
+
cmd.ensure_finalized()
|
| 36 |
+
cmd.run()
|
| 37 |
+
if cwd is not None:
|
| 38 |
+
os.chdir(old_dir)
|
| 39 |
+
return cmd
|
| 40 |
+
|
| 41 |
+
def test_check_metadata(self):
|
| 42 |
+
# let's run the command with no metadata at all
|
| 43 |
+
# by default, check is checking the metadata
|
| 44 |
+
# should have some warnings
|
| 45 |
+
cmd = self._run()
|
| 46 |
+
self.assertEqual(cmd._warnings, 2)
|
| 47 |
+
|
| 48 |
+
# now let's add the required fields
|
| 49 |
+
# and run it again, to make sure we don't get
|
| 50 |
+
# any warning anymore
|
| 51 |
+
metadata = {'url': 'xxx', 'author': 'xxx',
|
| 52 |
+
'author_email': 'xxx',
|
| 53 |
+
'name': 'xxx', 'version': 'xxx'}
|
| 54 |
+
cmd = self._run(metadata)
|
| 55 |
+
self.assertEqual(cmd._warnings, 0)
|
| 56 |
+
|
| 57 |
+
# now with the strict mode, we should
|
| 58 |
+
# get an error if there are missing metadata
|
| 59 |
+
self.assertRaises(DistutilsSetupError, self._run, {}, **{'strict': 1})
|
| 60 |
+
|
| 61 |
+
# and of course, no error when all metadata are present
|
| 62 |
+
cmd = self._run(metadata, strict=1)
|
| 63 |
+
self.assertEqual(cmd._warnings, 0)
|
| 64 |
+
|
| 65 |
+
# now a test with non-ASCII characters
|
| 66 |
+
metadata = {'url': 'xxx', 'author': '\u00c9ric',
|
| 67 |
+
'author_email': 'xxx', 'name': 'xxx',
|
| 68 |
+
'version': 'xxx',
|
| 69 |
+
'description': 'Something about esszet \u00df',
|
| 70 |
+
'long_description': 'More things about esszet \u00df'}
|
| 71 |
+
cmd = self._run(metadata)
|
| 72 |
+
self.assertEqual(cmd._warnings, 0)
|
| 73 |
+
|
| 74 |
+
@unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
|
| 75 |
+
def test_check_document(self):
|
| 76 |
+
pkg_info, dist = self.create_dist()
|
| 77 |
+
cmd = check(dist)
|
| 78 |
+
|
| 79 |
+
# let's see if it detects broken rest
|
| 80 |
+
broken_rest = 'title\n===\n\ntest'
|
| 81 |
+
msgs = cmd._check_rst_data(broken_rest)
|
| 82 |
+
self.assertEqual(len(msgs), 1)
|
| 83 |
+
|
| 84 |
+
# and non-broken rest
|
| 85 |
+
rest = 'title\n=====\n\ntest'
|
| 86 |
+
msgs = cmd._check_rst_data(rest)
|
| 87 |
+
self.assertEqual(len(msgs), 0)
|
| 88 |
+
|
| 89 |
+
@unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
|
| 90 |
+
def test_check_restructuredtext(self):
|
| 91 |
+
# let's see if it detects broken rest in long_description
|
| 92 |
+
broken_rest = 'title\n===\n\ntest'
|
| 93 |
+
pkg_info, dist = self.create_dist(long_description=broken_rest)
|
| 94 |
+
cmd = check(dist)
|
| 95 |
+
cmd.check_restructuredtext()
|
| 96 |
+
self.assertEqual(cmd._warnings, 1)
|
| 97 |
+
|
| 98 |
+
# let's see if we have an error with strict=1
|
| 99 |
+
metadata = {'url': 'xxx', 'author': 'xxx',
|
| 100 |
+
'author_email': 'xxx',
|
| 101 |
+
'name': 'xxx', 'version': 'xxx',
|
| 102 |
+
'long_description': broken_rest}
|
| 103 |
+
self.assertRaises(DistutilsSetupError, self._run, metadata,
|
| 104 |
+
**{'strict': 1, 'restructuredtext': 1})
|
| 105 |
+
|
| 106 |
+
# and non-broken rest, including a non-ASCII character to test #12114
|
| 107 |
+
metadata['long_description'] = 'title\n=====\n\ntest \u00df'
|
| 108 |
+
cmd = self._run(metadata, strict=1, restructuredtext=1)
|
| 109 |
+
self.assertEqual(cmd._warnings, 0)
|
| 110 |
+
|
| 111 |
+
# check that includes work to test #31292
|
| 112 |
+
metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
|
| 113 |
+
cmd = self._run(metadata, cwd=HERE, strict=1, restructuredtext=1)
|
| 114 |
+
self.assertEqual(cmd._warnings, 0)
|
| 115 |
+
|
| 116 |
+
@unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
|
| 117 |
+
def test_check_restructuredtext_with_syntax_highlight(self):
|
| 118 |
+
# Don't fail if there is a `code` or `code-block` directive
|
| 119 |
+
|
| 120 |
+
example_rst_docs = []
|
| 121 |
+
example_rst_docs.append(textwrap.dedent("""\
|
| 122 |
+
Here's some code:
|
| 123 |
+
|
| 124 |
+
.. code:: python
|
| 125 |
+
|
| 126 |
+
def foo():
|
| 127 |
+
pass
|
| 128 |
+
"""))
|
| 129 |
+
example_rst_docs.append(textwrap.dedent("""\
|
| 130 |
+
Here's some code:
|
| 131 |
+
|
| 132 |
+
.. code-block:: python
|
| 133 |
+
|
| 134 |
+
def foo():
|
| 135 |
+
pass
|
| 136 |
+
"""))
|
| 137 |
+
|
| 138 |
+
for rest_with_code in example_rst_docs:
|
| 139 |
+
pkg_info, dist = self.create_dist(long_description=rest_with_code)
|
| 140 |
+
cmd = check(dist)
|
| 141 |
+
cmd.check_restructuredtext()
|
| 142 |
+
msgs = cmd._check_rst_data(rest_with_code)
|
| 143 |
+
if pygments is not None:
|
| 144 |
+
self.assertEqual(len(msgs), 0)
|
| 145 |
+
else:
|
| 146 |
+
self.assertEqual(len(msgs), 1)
|
| 147 |
+
self.assertEqual(
|
| 148 |
+
str(msgs[0][1]),
|
| 149 |
+
'Cannot analyze code. Pygments package not found.'
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
def test_check_all(self):
|
| 153 |
+
|
| 154 |
+
metadata = {'url': 'xxx', 'author': 'xxx'}
|
| 155 |
+
self.assertRaises(DistutilsSetupError, self._run,
|
| 156 |
+
{}, **{'strict': 1,
|
| 157 |
+
'restructuredtext': 1})
|
| 158 |
+
|
| 159 |
+
def test_suite():
|
| 160 |
+
return unittest.makeSuite(CheckTestCase)
|
| 161 |
+
|
| 162 |
+
if __name__ == "__main__":
|
| 163 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_clean.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.clean."""
|
| 2 |
+
import os
|
| 3 |
+
import unittest
|
| 4 |
+
|
| 5 |
+
from distutils.command.clean import clean
|
| 6 |
+
from distutils.tests import support
|
| 7 |
+
from test.support import run_unittest
|
| 8 |
+
|
| 9 |
+
class cleanTestCase(support.TempdirManager,
|
| 10 |
+
support.LoggingSilencer,
|
| 11 |
+
unittest.TestCase):
|
| 12 |
+
|
| 13 |
+
def test_simple_run(self):
|
| 14 |
+
pkg_dir, dist = self.create_dist()
|
| 15 |
+
cmd = clean(dist)
|
| 16 |
+
|
| 17 |
+
# let's add some elements clean should remove
|
| 18 |
+
dirs = [(d, os.path.join(pkg_dir, d))
|
| 19 |
+
for d in ('build_temp', 'build_lib', 'bdist_base',
|
| 20 |
+
'build_scripts', 'build_base')]
|
| 21 |
+
|
| 22 |
+
for name, path in dirs:
|
| 23 |
+
os.mkdir(path)
|
| 24 |
+
setattr(cmd, name, path)
|
| 25 |
+
if name == 'build_base':
|
| 26 |
+
continue
|
| 27 |
+
for f in ('one', 'two', 'three'):
|
| 28 |
+
self.write_file(os.path.join(path, f))
|
| 29 |
+
|
| 30 |
+
# let's run the command
|
| 31 |
+
cmd.all = 1
|
| 32 |
+
cmd.ensure_finalized()
|
| 33 |
+
cmd.run()
|
| 34 |
+
|
| 35 |
+
# make sure the files where removed
|
| 36 |
+
for name, path in dirs:
|
| 37 |
+
self.assertFalse(os.path.exists(path),
|
| 38 |
+
'%s was not removed' % path)
|
| 39 |
+
|
| 40 |
+
# let's run the command again (should spit warnings but succeed)
|
| 41 |
+
cmd.all = 1
|
| 42 |
+
cmd.ensure_finalized()
|
| 43 |
+
cmd.run()
|
| 44 |
+
|
| 45 |
+
def test_suite():
|
| 46 |
+
return unittest.makeSuite(cleanTestCase)
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_cmd.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.cmd."""
|
| 2 |
+
import unittest
|
| 3 |
+
import os
|
| 4 |
+
from test.support import captured_stdout, run_unittest
|
| 5 |
+
|
| 6 |
+
from distutils.cmd import Command
|
| 7 |
+
from distutils.dist import Distribution
|
| 8 |
+
from distutils.errors import DistutilsOptionError
|
| 9 |
+
from distutils import debug
|
| 10 |
+
|
| 11 |
+
class MyCmd(Command):
|
| 12 |
+
def initialize_options(self):
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
class CommandTestCase(unittest.TestCase):
|
| 16 |
+
|
| 17 |
+
def setUp(self):
|
| 18 |
+
dist = Distribution()
|
| 19 |
+
self.cmd = MyCmd(dist)
|
| 20 |
+
|
| 21 |
+
def test_ensure_string_list(self):
|
| 22 |
+
|
| 23 |
+
cmd = self.cmd
|
| 24 |
+
cmd.not_string_list = ['one', 2, 'three']
|
| 25 |
+
cmd.yes_string_list = ['one', 'two', 'three']
|
| 26 |
+
cmd.not_string_list2 = object()
|
| 27 |
+
cmd.yes_string_list2 = 'ok'
|
| 28 |
+
cmd.ensure_string_list('yes_string_list')
|
| 29 |
+
cmd.ensure_string_list('yes_string_list2')
|
| 30 |
+
|
| 31 |
+
self.assertRaises(DistutilsOptionError,
|
| 32 |
+
cmd.ensure_string_list, 'not_string_list')
|
| 33 |
+
|
| 34 |
+
self.assertRaises(DistutilsOptionError,
|
| 35 |
+
cmd.ensure_string_list, 'not_string_list2')
|
| 36 |
+
|
| 37 |
+
cmd.option1 = 'ok,dok'
|
| 38 |
+
cmd.ensure_string_list('option1')
|
| 39 |
+
self.assertEqual(cmd.option1, ['ok', 'dok'])
|
| 40 |
+
|
| 41 |
+
cmd.option2 = ['xxx', 'www']
|
| 42 |
+
cmd.ensure_string_list('option2')
|
| 43 |
+
|
| 44 |
+
cmd.option3 = ['ok', 2]
|
| 45 |
+
self.assertRaises(DistutilsOptionError, cmd.ensure_string_list,
|
| 46 |
+
'option3')
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def test_make_file(self):
|
| 50 |
+
|
| 51 |
+
cmd = self.cmd
|
| 52 |
+
|
| 53 |
+
# making sure it raises when infiles is not a string or a list/tuple
|
| 54 |
+
self.assertRaises(TypeError, cmd.make_file,
|
| 55 |
+
infiles=1, outfile='', func='func', args=())
|
| 56 |
+
|
| 57 |
+
# making sure execute gets called properly
|
| 58 |
+
def _execute(func, args, exec_msg, level):
|
| 59 |
+
self.assertEqual(exec_msg, 'generating out from in')
|
| 60 |
+
cmd.force = True
|
| 61 |
+
cmd.execute = _execute
|
| 62 |
+
cmd.make_file(infiles='in', outfile='out', func='func', args=())
|
| 63 |
+
|
| 64 |
+
def test_dump_options(self):
|
| 65 |
+
|
| 66 |
+
msgs = []
|
| 67 |
+
def _announce(msg, level):
|
| 68 |
+
msgs.append(msg)
|
| 69 |
+
cmd = self.cmd
|
| 70 |
+
cmd.announce = _announce
|
| 71 |
+
cmd.option1 = 1
|
| 72 |
+
cmd.option2 = 1
|
| 73 |
+
cmd.user_options = [('option1', '', ''), ('option2', '', '')]
|
| 74 |
+
cmd.dump_options()
|
| 75 |
+
|
| 76 |
+
wanted = ["command options for 'MyCmd':", ' option1 = 1',
|
| 77 |
+
' option2 = 1']
|
| 78 |
+
self.assertEqual(msgs, wanted)
|
| 79 |
+
|
| 80 |
+
def test_ensure_string(self):
|
| 81 |
+
cmd = self.cmd
|
| 82 |
+
cmd.option1 = 'ok'
|
| 83 |
+
cmd.ensure_string('option1')
|
| 84 |
+
|
| 85 |
+
cmd.option2 = None
|
| 86 |
+
cmd.ensure_string('option2', 'xxx')
|
| 87 |
+
self.assertTrue(hasattr(cmd, 'option2'))
|
| 88 |
+
|
| 89 |
+
cmd.option3 = 1
|
| 90 |
+
self.assertRaises(DistutilsOptionError, cmd.ensure_string, 'option3')
|
| 91 |
+
|
| 92 |
+
def test_ensure_filename(self):
|
| 93 |
+
cmd = self.cmd
|
| 94 |
+
cmd.option1 = __file__
|
| 95 |
+
cmd.ensure_filename('option1')
|
| 96 |
+
cmd.option2 = 'xxx'
|
| 97 |
+
self.assertRaises(DistutilsOptionError, cmd.ensure_filename, 'option2')
|
| 98 |
+
|
| 99 |
+
def test_ensure_dirname(self):
|
| 100 |
+
cmd = self.cmd
|
| 101 |
+
cmd.option1 = os.path.dirname(__file__) or os.curdir
|
| 102 |
+
cmd.ensure_dirname('option1')
|
| 103 |
+
cmd.option2 = 'xxx'
|
| 104 |
+
self.assertRaises(DistutilsOptionError, cmd.ensure_dirname, 'option2')
|
| 105 |
+
|
| 106 |
+
def test_debug_print(self):
|
| 107 |
+
cmd = self.cmd
|
| 108 |
+
with captured_stdout() as stdout:
|
| 109 |
+
cmd.debug_print('xxx')
|
| 110 |
+
stdout.seek(0)
|
| 111 |
+
self.assertEqual(stdout.read(), '')
|
| 112 |
+
|
| 113 |
+
debug.DEBUG = True
|
| 114 |
+
try:
|
| 115 |
+
with captured_stdout() as stdout:
|
| 116 |
+
cmd.debug_print('xxx')
|
| 117 |
+
stdout.seek(0)
|
| 118 |
+
self.assertEqual(stdout.read(), 'xxx\n')
|
| 119 |
+
finally:
|
| 120 |
+
debug.DEBUG = False
|
| 121 |
+
|
| 122 |
+
def test_suite():
|
| 123 |
+
return unittest.makeSuite(CommandTestCase)
|
| 124 |
+
|
| 125 |
+
if __name__ == '__main__':
|
| 126 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_config.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.pypirc.pypirc."""
|
| 2 |
+
import os
|
| 3 |
+
import unittest
|
| 4 |
+
|
| 5 |
+
from distutils.core import PyPIRCCommand
|
| 6 |
+
from distutils.core import Distribution
|
| 7 |
+
from distutils.log import set_threshold
|
| 8 |
+
from distutils.log import WARN
|
| 9 |
+
|
| 10 |
+
from distutils.tests import support
|
| 11 |
+
from test.support import run_unittest
|
| 12 |
+
|
| 13 |
+
PYPIRC = """\
|
| 14 |
+
[distutils]
|
| 15 |
+
|
| 16 |
+
index-servers =
|
| 17 |
+
server1
|
| 18 |
+
server2
|
| 19 |
+
server3
|
| 20 |
+
|
| 21 |
+
[server1]
|
| 22 |
+
username:me
|
| 23 |
+
password:secret
|
| 24 |
+
|
| 25 |
+
[server2]
|
| 26 |
+
username:meagain
|
| 27 |
+
password: secret
|
| 28 |
+
realm:acme
|
| 29 |
+
repository:http://another.pypi/
|
| 30 |
+
|
| 31 |
+
[server3]
|
| 32 |
+
username:cbiggles
|
| 33 |
+
password:yh^%#rest-of-my-password
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
PYPIRC_OLD = """\
|
| 37 |
+
[server-login]
|
| 38 |
+
username:tarek
|
| 39 |
+
password:secret
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
WANTED = """\
|
| 43 |
+
[distutils]
|
| 44 |
+
index-servers =
|
| 45 |
+
pypi
|
| 46 |
+
|
| 47 |
+
[pypi]
|
| 48 |
+
username:tarek
|
| 49 |
+
password:xxx
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class BasePyPIRCCommandTestCase(support.TempdirManager,
|
| 54 |
+
support.LoggingSilencer,
|
| 55 |
+
support.EnvironGuard,
|
| 56 |
+
unittest.TestCase):
|
| 57 |
+
|
| 58 |
+
def setUp(self):
|
| 59 |
+
"""Patches the environment."""
|
| 60 |
+
super(BasePyPIRCCommandTestCase, self).setUp()
|
| 61 |
+
self.tmp_dir = self.mkdtemp()
|
| 62 |
+
os.environ['HOME'] = self.tmp_dir
|
| 63 |
+
os.environ['USERPROFILE'] = self.tmp_dir
|
| 64 |
+
self.rc = os.path.join(self.tmp_dir, '.pypirc')
|
| 65 |
+
self.dist = Distribution()
|
| 66 |
+
|
| 67 |
+
class command(PyPIRCCommand):
|
| 68 |
+
def __init__(self, dist):
|
| 69 |
+
PyPIRCCommand.__init__(self, dist)
|
| 70 |
+
def initialize_options(self):
|
| 71 |
+
pass
|
| 72 |
+
finalize_options = initialize_options
|
| 73 |
+
|
| 74 |
+
self._cmd = command
|
| 75 |
+
self.old_threshold = set_threshold(WARN)
|
| 76 |
+
|
| 77 |
+
def tearDown(self):
|
| 78 |
+
"""Removes the patch."""
|
| 79 |
+
set_threshold(self.old_threshold)
|
| 80 |
+
super(BasePyPIRCCommandTestCase, self).tearDown()
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class PyPIRCCommandTestCase(BasePyPIRCCommandTestCase):
|
| 84 |
+
|
| 85 |
+
def test_server_registration(self):
|
| 86 |
+
# This test makes sure PyPIRCCommand knows how to:
|
| 87 |
+
# 1. handle several sections in .pypirc
|
| 88 |
+
# 2. handle the old format
|
| 89 |
+
|
| 90 |
+
# new format
|
| 91 |
+
self.write_file(self.rc, PYPIRC)
|
| 92 |
+
cmd = self._cmd(self.dist)
|
| 93 |
+
config = cmd._read_pypirc()
|
| 94 |
+
|
| 95 |
+
config = list(sorted(config.items()))
|
| 96 |
+
waited = [('password', 'secret'), ('realm', 'pypi'),
|
| 97 |
+
('repository', 'https://upload.pypi.org/legacy/'),
|
| 98 |
+
('server', 'server1'), ('username', 'me')]
|
| 99 |
+
self.assertEqual(config, waited)
|
| 100 |
+
|
| 101 |
+
# old format
|
| 102 |
+
self.write_file(self.rc, PYPIRC_OLD)
|
| 103 |
+
config = cmd._read_pypirc()
|
| 104 |
+
config = list(sorted(config.items()))
|
| 105 |
+
waited = [('password', 'secret'), ('realm', 'pypi'),
|
| 106 |
+
('repository', 'https://upload.pypi.org/legacy/'),
|
| 107 |
+
('server', 'server-login'), ('username', 'tarek')]
|
| 108 |
+
self.assertEqual(config, waited)
|
| 109 |
+
|
| 110 |
+
def test_server_empty_registration(self):
|
| 111 |
+
cmd = self._cmd(self.dist)
|
| 112 |
+
rc = cmd._get_rc_file()
|
| 113 |
+
self.assertFalse(os.path.exists(rc))
|
| 114 |
+
cmd._store_pypirc('tarek', 'xxx')
|
| 115 |
+
self.assertTrue(os.path.exists(rc))
|
| 116 |
+
f = open(rc)
|
| 117 |
+
try:
|
| 118 |
+
content = f.read()
|
| 119 |
+
self.assertEqual(content, WANTED)
|
| 120 |
+
finally:
|
| 121 |
+
f.close()
|
| 122 |
+
|
| 123 |
+
def test_config_interpolation(self):
|
| 124 |
+
# using the % character in .pypirc should not raise an error (#20120)
|
| 125 |
+
self.write_file(self.rc, PYPIRC)
|
| 126 |
+
cmd = self._cmd(self.dist)
|
| 127 |
+
cmd.repository = 'server3'
|
| 128 |
+
config = cmd._read_pypirc()
|
| 129 |
+
|
| 130 |
+
config = list(sorted(config.items()))
|
| 131 |
+
waited = [('password', 'yh^%#rest-of-my-password'), ('realm', 'pypi'),
|
| 132 |
+
('repository', 'https://upload.pypi.org/legacy/'),
|
| 133 |
+
('server', 'server3'), ('username', 'cbiggles')]
|
| 134 |
+
self.assertEqual(config, waited)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def test_suite():
|
| 138 |
+
return unittest.makeSuite(PyPIRCCommandTestCase)
|
| 139 |
+
|
| 140 |
+
if __name__ == "__main__":
|
| 141 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_config_cmd.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.config."""
|
| 2 |
+
import unittest
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import sysconfig
|
| 6 |
+
from test.support import run_unittest, missing_compiler_executable
|
| 7 |
+
|
| 8 |
+
from distutils.command.config import dump_file, config
|
| 9 |
+
from distutils.tests import support
|
| 10 |
+
from distutils import log
|
| 11 |
+
|
| 12 |
+
class ConfigTestCase(support.LoggingSilencer,
|
| 13 |
+
support.TempdirManager,
|
| 14 |
+
unittest.TestCase):
|
| 15 |
+
|
| 16 |
+
def _info(self, msg, *args):
|
| 17 |
+
for line in msg.splitlines():
|
| 18 |
+
self._logs.append(line)
|
| 19 |
+
|
| 20 |
+
def setUp(self):
|
| 21 |
+
super(ConfigTestCase, self).setUp()
|
| 22 |
+
self._logs = []
|
| 23 |
+
self.old_log = log.info
|
| 24 |
+
log.info = self._info
|
| 25 |
+
self.old_config_vars = dict(sysconfig._CONFIG_VARS)
|
| 26 |
+
|
| 27 |
+
def tearDown(self):
|
| 28 |
+
log.info = self.old_log
|
| 29 |
+
sysconfig._CONFIG_VARS.clear()
|
| 30 |
+
sysconfig._CONFIG_VARS.update(self.old_config_vars)
|
| 31 |
+
super(ConfigTestCase, self).tearDown()
|
| 32 |
+
|
| 33 |
+
def test_dump_file(self):
|
| 34 |
+
this_file = os.path.splitext(__file__)[0] + '.py'
|
| 35 |
+
f = open(this_file)
|
| 36 |
+
try:
|
| 37 |
+
numlines = len(f.readlines())
|
| 38 |
+
finally:
|
| 39 |
+
f.close()
|
| 40 |
+
|
| 41 |
+
dump_file(this_file, 'I am the header')
|
| 42 |
+
self.assertEqual(len(self._logs), numlines+1)
|
| 43 |
+
|
| 44 |
+
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
|
| 45 |
+
def test_search_cpp(self):
|
| 46 |
+
cmd = missing_compiler_executable(['preprocessor'])
|
| 47 |
+
if cmd is not None:
|
| 48 |
+
self.skipTest('The %r command is not found' % cmd)
|
| 49 |
+
pkg_dir, dist = self.create_dist()
|
| 50 |
+
cmd = config(dist)
|
| 51 |
+
cmd._check_compiler()
|
| 52 |
+
compiler = cmd.compiler
|
| 53 |
+
if sys.platform[:3] == "aix" and "xlc" in compiler.preprocessor[0].lower():
|
| 54 |
+
self.skipTest('xlc: The -E option overrides the -P, -o, and -qsyntaxonly options')
|
| 55 |
+
|
| 56 |
+
# simple pattern searches
|
| 57 |
+
match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
|
| 58 |
+
self.assertEqual(match, 0)
|
| 59 |
+
|
| 60 |
+
match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
|
| 61 |
+
self.assertEqual(match, 1)
|
| 62 |
+
|
| 63 |
+
def test_finalize_options(self):
|
| 64 |
+
# finalize_options does a bit of transformation
|
| 65 |
+
# on options
|
| 66 |
+
pkg_dir, dist = self.create_dist()
|
| 67 |
+
cmd = config(dist)
|
| 68 |
+
cmd.include_dirs = 'one%stwo' % os.pathsep
|
| 69 |
+
cmd.libraries = 'one'
|
| 70 |
+
cmd.library_dirs = 'three%sfour' % os.pathsep
|
| 71 |
+
cmd.ensure_finalized()
|
| 72 |
+
|
| 73 |
+
self.assertEqual(cmd.include_dirs, ['one', 'two'])
|
| 74 |
+
self.assertEqual(cmd.libraries, ['one'])
|
| 75 |
+
self.assertEqual(cmd.library_dirs, ['three', 'four'])
|
| 76 |
+
|
| 77 |
+
def test_clean(self):
|
| 78 |
+
# _clean removes files
|
| 79 |
+
tmp_dir = self.mkdtemp()
|
| 80 |
+
f1 = os.path.join(tmp_dir, 'one')
|
| 81 |
+
f2 = os.path.join(tmp_dir, 'two')
|
| 82 |
+
|
| 83 |
+
self.write_file(f1, 'xxx')
|
| 84 |
+
self.write_file(f2, 'xxx')
|
| 85 |
+
|
| 86 |
+
for f in (f1, f2):
|
| 87 |
+
self.assertTrue(os.path.exists(f))
|
| 88 |
+
|
| 89 |
+
pkg_dir, dist = self.create_dist()
|
| 90 |
+
cmd = config(dist)
|
| 91 |
+
cmd._clean(f1, f2)
|
| 92 |
+
|
| 93 |
+
for f in (f1, f2):
|
| 94 |
+
self.assertFalse(os.path.exists(f))
|
| 95 |
+
|
| 96 |
+
def test_suite():
|
| 97 |
+
return unittest.makeSuite(ConfigTestCase)
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
run_unittest(test_suite())
|
evalkit_cambrian/lib/python3.10/distutils/tests/test_core.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.core."""
|
| 2 |
+
|
| 3 |
+
import io
|
| 4 |
+
import distutils.core
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
+
import sys
|
| 8 |
+
from test.support import captured_stdout, run_unittest
|
| 9 |
+
from test.support import os_helper
|
| 10 |
+
import unittest
|
| 11 |
+
from distutils.tests import support
|
| 12 |
+
from distutils import log
|
| 13 |
+
|
| 14 |
+
# setup script that uses __file__
|
| 15 |
+
setup_using___file__ = """\
|
| 16 |
+
|
| 17 |
+
__file__
|
| 18 |
+
|
| 19 |
+
from distutils.core import setup
|
| 20 |
+
setup()
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
setup_prints_cwd = """\
|
| 24 |
+
|
| 25 |
+
import os
|
| 26 |
+
print(os.getcwd())
|
| 27 |
+
|
| 28 |
+
from distutils.core import setup
|
| 29 |
+
setup()
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
setup_does_nothing = """\
|
| 33 |
+
from distutils.core import setup
|
| 34 |
+
setup()
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
setup_defines_subclass = """\
|
| 39 |
+
from distutils.core import setup
|
| 40 |
+
from distutils.command.install import install as _install
|
| 41 |
+
|
| 42 |
+
class install(_install):
|
| 43 |
+
sub_commands = _install.sub_commands + ['cmd']
|
| 44 |
+
|
| 45 |
+
setup(cmdclass={'install': install})
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
class CoreTestCase(support.EnvironGuard, unittest.TestCase):
|
| 49 |
+
|
| 50 |
+
def setUp(self):
|
| 51 |
+
super(CoreTestCase, self).setUp()
|
| 52 |
+
self.old_stdout = sys.stdout
|
| 53 |
+
self.cleanup_testfn()
|
| 54 |
+
self.old_argv = sys.argv, sys.argv[:]
|
| 55 |
+
self.addCleanup(log.set_threshold, log._global_log.threshold)
|
| 56 |
+
|
| 57 |
+
def tearDown(self):
|
| 58 |
+
sys.stdout = self.old_stdout
|
| 59 |
+
self.cleanup_testfn()
|
| 60 |
+
sys.argv = self.old_argv[0]
|
| 61 |
+
sys.argv[:] = self.old_argv[1]
|
| 62 |
+
super(CoreTestCase, self).tearDown()
|
| 63 |
+
|
| 64 |
+
def cleanup_testfn(self):
|
| 65 |
+
path = os_helper.TESTFN
|
| 66 |
+
if os.path.isfile(path):
|
| 67 |
+
os.remove(path)
|
| 68 |
+
elif os.path.isdir(path):
|
| 69 |
+
shutil.rmtree(path)
|
| 70 |
+
|
| 71 |
+
def write_setup(self, text, path=os_helper.TESTFN):
|
| 72 |
+
f = open(path, "w")
|
| 73 |
+
try:
|
| 74 |
+
f.write(text)
|
| 75 |
+
finally:
|
| 76 |
+
f.close()
|
| 77 |
+
return path
|
| 78 |
+
|
| 79 |
+
def test_run_setup_provides_file(self):
|
| 80 |
+
# Make sure the script can use __file__; if that's missing, the test
|
| 81 |
+
# setup.py script will raise NameError.
|
| 82 |
+
distutils.core.run_setup(
|
| 83 |
+
self.write_setup(setup_using___file__))
|
| 84 |
+
|
| 85 |
+
def test_run_setup_preserves_sys_argv(self):
|
| 86 |
+
# Make sure run_setup does not clobber sys.argv
|
| 87 |
+
argv_copy = sys.argv.copy()
|
| 88 |
+
distutils.core.run_setup(
|
| 89 |
+
self.write_setup(setup_does_nothing))
|
| 90 |
+
self.assertEqual(sys.argv, argv_copy)
|
| 91 |
+
|
| 92 |
+
def test_run_setup_defines_subclass(self):
|
| 93 |
+
# Make sure the script can use __file__; if that's missing, the test
|
| 94 |
+
# setup.py script will raise NameError.
|
| 95 |
+
dist = distutils.core.run_setup(
|
| 96 |
+
self.write_setup(setup_defines_subclass))
|
| 97 |
+
install = dist.get_command_obj('install')
|
| 98 |
+
self.assertIn('cmd', install.sub_commands)
|
| 99 |
+
|
| 100 |
+
def test_run_setup_uses_current_dir(self):
|
| 101 |
+
# This tests that the setup script is run with the current directory
|
| 102 |
+
# as its own current directory; this was temporarily broken by a
|
| 103 |
+
# previous patch when TESTFN did not use the current directory.
|
| 104 |
+
sys.stdout = io.StringIO()
|
| 105 |
+
cwd = os.getcwd()
|
| 106 |
+
|
| 107 |
+
# Create a directory and write the setup.py file there:
|
| 108 |
+
os.mkdir(os_helper.TESTFN)
|
| 109 |
+
setup_py = os.path.join(os_helper.TESTFN, "setup.py")
|
| 110 |
+
distutils.core.run_setup(
|
| 111 |
+
self.write_setup(setup_prints_cwd, path=setup_py))
|
| 112 |
+
|
| 113 |
+
output = sys.stdout.getvalue()
|
| 114 |
+
if output.endswith("\n"):
|
| 115 |
+
output = output[:-1]
|
| 116 |
+
self.assertEqual(cwd, output)
|
| 117 |
+
|
| 118 |
+
def test_debug_mode(self):
|
| 119 |
+
# this covers the code called when DEBUG is set
|
| 120 |
+
sys.argv = ['setup.py', '--name']
|
| 121 |
+
with captured_stdout() as stdout:
|
| 122 |
+
distutils.core.setup(name='bar')
|
| 123 |
+
stdout.seek(0)
|
| 124 |
+
self.assertEqual(stdout.read(), 'bar\n')
|
| 125 |
+
|
| 126 |
+
distutils.core.DEBUG = True
|
| 127 |
+
try:
|
| 128 |
+
with captured_stdout() as stdout:
|
| 129 |
+
distutils.core.setup(name='bar')
|
| 130 |
+
finally:
|
| 131 |
+
distutils.core.DEBUG = False
|
| 132 |
+
stdout.seek(0)
|
| 133 |
+
wanted = "options (after parsing config files):\n"
|
| 134 |
+
self.assertEqual(stdout.readlines()[0], wanted)
|
| 135 |
+
|
| 136 |
+
def test_suite():
|
| 137 |
+
return unittest.makeSuite(CoreTestCase)
|
| 138 |
+
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
run_unittest(test_suite())
|