backup 04_physworld 2026-11-08 10:11:26 (part 5)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/__pycache__/sdist.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/__pycache__/upload.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/bdist.py +138 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/bdist_dumb.py +123 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/bdist_rpm.py +579 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build.py +157 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build_clib.py +209 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build_ext.py +754 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build_py.py +416 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build_scripts.py +160 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/check.py +154 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/clean.py +76 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/command_template +33 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/config.py +344 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install.py +679 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_data.py +79 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_egg_info.py +77 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_headers.py +47 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_lib.py +217 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_scripts.py +60 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/register.py +304 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/sdist.py +494 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/upload.py +215 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/config.py +133 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/core.py +234 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/cygwinccompiler.py +406 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/debug.py +5 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/dep_util.py +92 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/dir_util.py +210 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/dist.py +1256 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/errors.py +97 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/extension.py +241 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/fancy_getopt.py +457 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/file_util.py +238 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/filelist.py +327 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/log.py +77 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/msvc9compiler.py +788 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/msvccompiler.py +642 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/spawn.py +129 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/sysconfig.py +348 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/Setup.sample +67 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__init__.py +31 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/support.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_archive_util.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_bdist.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_bdist_dumb.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_bdist_rpm.cpython-311.pyc +0 -0
- physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_build.cpython-311.pyc +0 -0
.gitattributes
CHANGED
|
@@ -3419,3 +3419,4 @@ physworld_p1_20261018/envs/p1/lib/python3.11/__pycache__/tarfile.cpython-311.pyc
|
|
| 3419 |
physworld_p1_20261018/envs/p1/lib/python3.11/__pycache__/turtle.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 3420 |
physworld_p1_20261018/envs/p1/lib/python3.11/__pycache__/typing.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 3421 |
physworld_p1_20261018/envs/p1/lib/python3.11/__pycache__/zipfile.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 3419 |
physworld_p1_20261018/envs/p1/lib/python3.11/__pycache__/turtle.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 3420 |
physworld_p1_20261018/envs/p1/lib/python3.11/__pycache__/typing.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 3421 |
physworld_p1_20261018/envs/p1/lib/python3.11/__pycache__/zipfile.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 3422 |
+
physworld_p1_20261018/envs/p1/lib/python3.11/email/__pycache__/_header_value_parser.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/__pycache__/sdist.cpython-311.pyc
ADDED
|
Binary file (24.1 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/__pycache__/upload.cpython-311.pyc
ADDED
|
Binary file (10.6 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/bdist.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.bdist
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'bdist' command (create a built [binary]
|
| 4 |
+
distribution)."""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from distutils.core import Command
|
| 8 |
+
from distutils.errors import *
|
| 9 |
+
from distutils.util import get_platform
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def show_formats():
|
| 13 |
+
"""Print list of available formats (arguments to "--format" option).
|
| 14 |
+
"""
|
| 15 |
+
from distutils.fancy_getopt import FancyGetopt
|
| 16 |
+
formats = []
|
| 17 |
+
for format in bdist.format_commands:
|
| 18 |
+
formats.append(("formats=" + format, None,
|
| 19 |
+
bdist.format_command[format][1]))
|
| 20 |
+
pretty_printer = FancyGetopt(formats)
|
| 21 |
+
pretty_printer.print_help("List of available distribution formats:")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class bdist(Command):
|
| 25 |
+
|
| 26 |
+
description = "create a built (binary) distribution"
|
| 27 |
+
|
| 28 |
+
user_options = [('bdist-base=', 'b',
|
| 29 |
+
"temporary directory for creating built distributions"),
|
| 30 |
+
('plat-name=', 'p',
|
| 31 |
+
"platform name to embed in generated filenames "
|
| 32 |
+
"(default: %s)" % get_platform()),
|
| 33 |
+
('formats=', None,
|
| 34 |
+
"formats for distribution (comma-separated list)"),
|
| 35 |
+
('dist-dir=', 'd',
|
| 36 |
+
"directory to put final built distributions in "
|
| 37 |
+
"[default: dist]"),
|
| 38 |
+
('skip-build', None,
|
| 39 |
+
"skip rebuilding everything (for testing/debugging)"),
|
| 40 |
+
('owner=', 'u',
|
| 41 |
+
"Owner name used when creating a tar file"
|
| 42 |
+
" [default: current user]"),
|
| 43 |
+
('group=', 'g',
|
| 44 |
+
"Group name used when creating a tar file"
|
| 45 |
+
" [default: current group]"),
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
boolean_options = ['skip-build']
|
| 49 |
+
|
| 50 |
+
help_options = [
|
| 51 |
+
('help-formats', None,
|
| 52 |
+
"lists available distribution formats", show_formats),
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
# The following commands do not take a format option from bdist
|
| 56 |
+
no_format_option = ('bdist_rpm',)
|
| 57 |
+
|
| 58 |
+
# This won't do in reality: will need to distinguish RPM-ish Linux,
|
| 59 |
+
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
|
| 60 |
+
default_format = {'posix': 'gztar',
|
| 61 |
+
'nt': 'zip'}
|
| 62 |
+
|
| 63 |
+
# Establish the preferred order (for the --help-formats option).
|
| 64 |
+
format_commands = ['rpm', 'gztar', 'bztar', 'xztar', 'ztar', 'tar', 'zip']
|
| 65 |
+
|
| 66 |
+
# And the real information.
|
| 67 |
+
format_command = {'rpm': ('bdist_rpm', "RPM distribution"),
|
| 68 |
+
'gztar': ('bdist_dumb', "gzip'ed tar file"),
|
| 69 |
+
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
|
| 70 |
+
'xztar': ('bdist_dumb', "xz'ed tar file"),
|
| 71 |
+
'ztar': ('bdist_dumb', "compressed tar file"),
|
| 72 |
+
'tar': ('bdist_dumb', "tar file"),
|
| 73 |
+
'zip': ('bdist_dumb', "ZIP file"),
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
def initialize_options(self):
|
| 77 |
+
self.bdist_base = None
|
| 78 |
+
self.plat_name = None
|
| 79 |
+
self.formats = None
|
| 80 |
+
self.dist_dir = None
|
| 81 |
+
self.skip_build = 0
|
| 82 |
+
self.group = None
|
| 83 |
+
self.owner = None
|
| 84 |
+
|
| 85 |
+
def finalize_options(self):
|
| 86 |
+
# have to finalize 'plat_name' before 'bdist_base'
|
| 87 |
+
if self.plat_name is None:
|
| 88 |
+
if self.skip_build:
|
| 89 |
+
self.plat_name = get_platform()
|
| 90 |
+
else:
|
| 91 |
+
self.plat_name = self.get_finalized_command('build').plat_name
|
| 92 |
+
|
| 93 |
+
# 'bdist_base' -- parent of per-built-distribution-format
|
| 94 |
+
# temporary directories (eg. we'll probably have
|
| 95 |
+
# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
|
| 96 |
+
if self.bdist_base is None:
|
| 97 |
+
build_base = self.get_finalized_command('build').build_base
|
| 98 |
+
self.bdist_base = os.path.join(build_base,
|
| 99 |
+
'bdist.' + self.plat_name)
|
| 100 |
+
|
| 101 |
+
self.ensure_string_list('formats')
|
| 102 |
+
if self.formats is None:
|
| 103 |
+
try:
|
| 104 |
+
self.formats = [self.default_format[os.name]]
|
| 105 |
+
except KeyError:
|
| 106 |
+
raise DistutilsPlatformError(
|
| 107 |
+
"don't know how to create built distributions "
|
| 108 |
+
"on platform %s" % os.name)
|
| 109 |
+
|
| 110 |
+
if self.dist_dir is None:
|
| 111 |
+
self.dist_dir = "dist"
|
| 112 |
+
|
| 113 |
+
def run(self):
|
| 114 |
+
# Figure out which sub-commands we need to run.
|
| 115 |
+
commands = []
|
| 116 |
+
for format in self.formats:
|
| 117 |
+
try:
|
| 118 |
+
commands.append(self.format_command[format][0])
|
| 119 |
+
except KeyError:
|
| 120 |
+
raise DistutilsOptionError("invalid format '%s'" % format)
|
| 121 |
+
|
| 122 |
+
# Reinitialize and run each command.
|
| 123 |
+
for i in range(len(self.formats)):
|
| 124 |
+
cmd_name = commands[i]
|
| 125 |
+
sub_cmd = self.reinitialize_command(cmd_name)
|
| 126 |
+
if cmd_name not in self.no_format_option:
|
| 127 |
+
sub_cmd.format = self.formats[i]
|
| 128 |
+
|
| 129 |
+
# passing the owner and group names for tar archiving
|
| 130 |
+
if cmd_name == 'bdist_dumb':
|
| 131 |
+
sub_cmd.owner = self.owner
|
| 132 |
+
sub_cmd.group = self.group
|
| 133 |
+
|
| 134 |
+
# If we're going to need to run this command again, tell it to
|
| 135 |
+
# keep its temporary files around so subsequent runs go faster.
|
| 136 |
+
if cmd_name in commands[i+1:]:
|
| 137 |
+
sub_cmd.keep_temp = 1
|
| 138 |
+
self.run_command(cmd_name)
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/bdist_dumb.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.bdist_dumb
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'bdist_dumb' command (create a "dumb" built
|
| 4 |
+
distribution -- i.e., just an archive to be unpacked under $prefix or
|
| 5 |
+
$exec_prefix)."""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from distutils.core import Command
|
| 9 |
+
from distutils.util import get_platform
|
| 10 |
+
from distutils.dir_util import remove_tree, ensure_relative
|
| 11 |
+
from distutils.errors import *
|
| 12 |
+
from distutils.sysconfig import get_python_version
|
| 13 |
+
from distutils import log
|
| 14 |
+
|
| 15 |
+
class bdist_dumb(Command):
|
| 16 |
+
|
| 17 |
+
description = "create a \"dumb\" built distribution"
|
| 18 |
+
|
| 19 |
+
user_options = [('bdist-dir=', 'd',
|
| 20 |
+
"temporary directory for creating the distribution"),
|
| 21 |
+
('plat-name=', 'p',
|
| 22 |
+
"platform name to embed in generated filenames "
|
| 23 |
+
"(default: %s)" % get_platform()),
|
| 24 |
+
('format=', 'f',
|
| 25 |
+
"archive format to create (tar, gztar, bztar, xztar, "
|
| 26 |
+
"ztar, zip)"),
|
| 27 |
+
('keep-temp', 'k',
|
| 28 |
+
"keep the pseudo-installation tree around after " +
|
| 29 |
+
"creating the distribution archive"),
|
| 30 |
+
('dist-dir=', 'd',
|
| 31 |
+
"directory to put final built distributions in"),
|
| 32 |
+
('skip-build', None,
|
| 33 |
+
"skip rebuilding everything (for testing/debugging)"),
|
| 34 |
+
('relative', None,
|
| 35 |
+
"build the archive using relative paths "
|
| 36 |
+
"(default: false)"),
|
| 37 |
+
('owner=', 'u',
|
| 38 |
+
"Owner name used when creating a tar file"
|
| 39 |
+
" [default: current user]"),
|
| 40 |
+
('group=', 'g',
|
| 41 |
+
"Group name used when creating a tar file"
|
| 42 |
+
" [default: current group]"),
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
boolean_options = ['keep-temp', 'skip-build', 'relative']
|
| 46 |
+
|
| 47 |
+
default_format = { 'posix': 'gztar',
|
| 48 |
+
'nt': 'zip' }
|
| 49 |
+
|
| 50 |
+
def initialize_options(self):
|
| 51 |
+
self.bdist_dir = None
|
| 52 |
+
self.plat_name = None
|
| 53 |
+
self.format = None
|
| 54 |
+
self.keep_temp = 0
|
| 55 |
+
self.dist_dir = None
|
| 56 |
+
self.skip_build = None
|
| 57 |
+
self.relative = 0
|
| 58 |
+
self.owner = None
|
| 59 |
+
self.group = None
|
| 60 |
+
|
| 61 |
+
def finalize_options(self):
|
| 62 |
+
if self.bdist_dir is None:
|
| 63 |
+
bdist_base = self.get_finalized_command('bdist').bdist_base
|
| 64 |
+
self.bdist_dir = os.path.join(bdist_base, 'dumb')
|
| 65 |
+
|
| 66 |
+
if self.format is None:
|
| 67 |
+
try:
|
| 68 |
+
self.format = self.default_format[os.name]
|
| 69 |
+
except KeyError:
|
| 70 |
+
raise DistutilsPlatformError(
|
| 71 |
+
"don't know how to create dumb built distributions "
|
| 72 |
+
"on platform %s" % os.name)
|
| 73 |
+
|
| 74 |
+
self.set_undefined_options('bdist',
|
| 75 |
+
('dist_dir', 'dist_dir'),
|
| 76 |
+
('plat_name', 'plat_name'),
|
| 77 |
+
('skip_build', 'skip_build'))
|
| 78 |
+
|
| 79 |
+
def run(self):
|
| 80 |
+
if not self.skip_build:
|
| 81 |
+
self.run_command('build')
|
| 82 |
+
|
| 83 |
+
install = self.reinitialize_command('install', reinit_subcommands=1)
|
| 84 |
+
install.root = self.bdist_dir
|
| 85 |
+
install.skip_build = self.skip_build
|
| 86 |
+
install.warn_dir = 0
|
| 87 |
+
|
| 88 |
+
log.info("installing to %s", self.bdist_dir)
|
| 89 |
+
self.run_command('install')
|
| 90 |
+
|
| 91 |
+
# And make an archive relative to the root of the
|
| 92 |
+
# pseudo-installation tree.
|
| 93 |
+
archive_basename = "%s.%s" % (self.distribution.get_fullname(),
|
| 94 |
+
self.plat_name)
|
| 95 |
+
|
| 96 |
+
pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
|
| 97 |
+
if not self.relative:
|
| 98 |
+
archive_root = self.bdist_dir
|
| 99 |
+
else:
|
| 100 |
+
if (self.distribution.has_ext_modules() and
|
| 101 |
+
(install.install_base != install.install_platbase)):
|
| 102 |
+
raise DistutilsPlatformError(
|
| 103 |
+
"can't make a dumb built distribution where "
|
| 104 |
+
"base and platbase are different (%s, %s)"
|
| 105 |
+
% (repr(install.install_base),
|
| 106 |
+
repr(install.install_platbase)))
|
| 107 |
+
else:
|
| 108 |
+
archive_root = os.path.join(self.bdist_dir,
|
| 109 |
+
ensure_relative(install.install_base))
|
| 110 |
+
|
| 111 |
+
# Make the archive
|
| 112 |
+
filename = self.make_archive(pseudoinstall_root,
|
| 113 |
+
self.format, root_dir=archive_root,
|
| 114 |
+
owner=self.owner, group=self.group)
|
| 115 |
+
if self.distribution.has_ext_modules():
|
| 116 |
+
pyversion = get_python_version()
|
| 117 |
+
else:
|
| 118 |
+
pyversion = 'any'
|
| 119 |
+
self.distribution.dist_files.append(('bdist_dumb', pyversion,
|
| 120 |
+
filename))
|
| 121 |
+
|
| 122 |
+
if not self.keep_temp:
|
| 123 |
+
remove_tree(self.bdist_dir, dry_run=self.dry_run)
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/bdist_rpm.py
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.bdist_rpm
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'bdist_rpm' command (create RPM source and binary
|
| 4 |
+
distributions)."""
|
| 5 |
+
|
| 6 |
+
import subprocess, sys, os
|
| 7 |
+
from distutils.core import Command
|
| 8 |
+
from distutils.debug import DEBUG
|
| 9 |
+
from distutils.file_util import write_file
|
| 10 |
+
from distutils.errors import *
|
| 11 |
+
from distutils.sysconfig import get_python_version
|
| 12 |
+
from distutils import log
|
| 13 |
+
|
| 14 |
+
class bdist_rpm(Command):
|
| 15 |
+
|
| 16 |
+
description = "create an RPM distribution"
|
| 17 |
+
|
| 18 |
+
user_options = [
|
| 19 |
+
('bdist-base=', None,
|
| 20 |
+
"base directory for creating built distributions"),
|
| 21 |
+
('rpm-base=', None,
|
| 22 |
+
"base directory for creating RPMs (defaults to \"rpm\" under "
|
| 23 |
+
"--bdist-base; must be specified for RPM 2)"),
|
| 24 |
+
('dist-dir=', 'd',
|
| 25 |
+
"directory to put final RPM files in "
|
| 26 |
+
"(and .spec files if --spec-only)"),
|
| 27 |
+
('python=', None,
|
| 28 |
+
"path to Python interpreter to hard-code in the .spec file "
|
| 29 |
+
"(default: \"python\")"),
|
| 30 |
+
('fix-python', None,
|
| 31 |
+
"hard-code the exact path to the current Python interpreter in "
|
| 32 |
+
"the .spec file"),
|
| 33 |
+
('spec-only', None,
|
| 34 |
+
"only regenerate spec file"),
|
| 35 |
+
('source-only', None,
|
| 36 |
+
"only generate source RPM"),
|
| 37 |
+
('binary-only', None,
|
| 38 |
+
"only generate binary RPM"),
|
| 39 |
+
('use-bzip2', None,
|
| 40 |
+
"use bzip2 instead of gzip to create source distribution"),
|
| 41 |
+
|
| 42 |
+
# More meta-data: too RPM-specific to put in the setup script,
|
| 43 |
+
# but needs to go in the .spec file -- so we make these options
|
| 44 |
+
# to "bdist_rpm". The idea is that packagers would put this
|
| 45 |
+
# info in setup.cfg, although they are of course free to
|
| 46 |
+
# supply it on the command line.
|
| 47 |
+
('distribution-name=', None,
|
| 48 |
+
"name of the (Linux) distribution to which this "
|
| 49 |
+
"RPM applies (*not* the name of the module distribution!)"),
|
| 50 |
+
('group=', None,
|
| 51 |
+
"package classification [default: \"Development/Libraries\"]"),
|
| 52 |
+
('release=', None,
|
| 53 |
+
"RPM release number"),
|
| 54 |
+
('serial=', None,
|
| 55 |
+
"RPM serial number"),
|
| 56 |
+
('vendor=', None,
|
| 57 |
+
"RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") "
|
| 58 |
+
"[default: maintainer or author from setup script]"),
|
| 59 |
+
('packager=', None,
|
| 60 |
+
"RPM packager (eg. \"Jane Doe <jane@example.net>\") "
|
| 61 |
+
"[default: vendor]"),
|
| 62 |
+
('doc-files=', None,
|
| 63 |
+
"list of documentation files (space or comma-separated)"),
|
| 64 |
+
('changelog=', None,
|
| 65 |
+
"RPM changelog"),
|
| 66 |
+
('icon=', None,
|
| 67 |
+
"name of icon file"),
|
| 68 |
+
('provides=', None,
|
| 69 |
+
"capabilities provided by this package"),
|
| 70 |
+
('requires=', None,
|
| 71 |
+
"capabilities required by this package"),
|
| 72 |
+
('conflicts=', None,
|
| 73 |
+
"capabilities which conflict with this package"),
|
| 74 |
+
('build-requires=', None,
|
| 75 |
+
"capabilities required to build this package"),
|
| 76 |
+
('obsoletes=', None,
|
| 77 |
+
"capabilities made obsolete by this package"),
|
| 78 |
+
('no-autoreq', None,
|
| 79 |
+
"do not automatically calculate dependencies"),
|
| 80 |
+
|
| 81 |
+
# Actions to take when building RPM
|
| 82 |
+
('keep-temp', 'k',
|
| 83 |
+
"don't clean up RPM build directory"),
|
| 84 |
+
('no-keep-temp', None,
|
| 85 |
+
"clean up RPM build directory [default]"),
|
| 86 |
+
('use-rpm-opt-flags', None,
|
| 87 |
+
"compile with RPM_OPT_FLAGS when building from source RPM"),
|
| 88 |
+
('no-rpm-opt-flags', None,
|
| 89 |
+
"do not pass any RPM CFLAGS to compiler"),
|
| 90 |
+
('rpm3-mode', None,
|
| 91 |
+
"RPM 3 compatibility mode (default)"),
|
| 92 |
+
('rpm2-mode', None,
|
| 93 |
+
"RPM 2 compatibility mode"),
|
| 94 |
+
|
| 95 |
+
# Add the hooks necessary for specifying custom scripts
|
| 96 |
+
('prep-script=', None,
|
| 97 |
+
"Specify a script for the PREP phase of RPM building"),
|
| 98 |
+
('build-script=', None,
|
| 99 |
+
"Specify a script for the BUILD phase of RPM building"),
|
| 100 |
+
|
| 101 |
+
('pre-install=', None,
|
| 102 |
+
"Specify a script for the pre-INSTALL phase of RPM building"),
|
| 103 |
+
('install-script=', None,
|
| 104 |
+
"Specify a script for the INSTALL phase of RPM building"),
|
| 105 |
+
('post-install=', None,
|
| 106 |
+
"Specify a script for the post-INSTALL phase of RPM building"),
|
| 107 |
+
|
| 108 |
+
('pre-uninstall=', None,
|
| 109 |
+
"Specify a script for the pre-UNINSTALL phase of RPM building"),
|
| 110 |
+
('post-uninstall=', None,
|
| 111 |
+
"Specify a script for the post-UNINSTALL phase of RPM building"),
|
| 112 |
+
|
| 113 |
+
('clean-script=', None,
|
| 114 |
+
"Specify a script for the CLEAN phase of RPM building"),
|
| 115 |
+
|
| 116 |
+
('verify-script=', None,
|
| 117 |
+
"Specify a script for the VERIFY phase of the RPM build"),
|
| 118 |
+
|
| 119 |
+
# Allow a packager to explicitly force an architecture
|
| 120 |
+
('force-arch=', None,
|
| 121 |
+
"Force an architecture onto the RPM build process"),
|
| 122 |
+
|
| 123 |
+
('quiet', 'q',
|
| 124 |
+
"Run the INSTALL phase of RPM building in quiet mode"),
|
| 125 |
+
]
|
| 126 |
+
|
| 127 |
+
boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode',
|
| 128 |
+
'no-autoreq', 'quiet']
|
| 129 |
+
|
| 130 |
+
negative_opt = {'no-keep-temp': 'keep-temp',
|
| 131 |
+
'no-rpm-opt-flags': 'use-rpm-opt-flags',
|
| 132 |
+
'rpm2-mode': 'rpm3-mode'}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def initialize_options(self):
|
| 136 |
+
self.bdist_base = None
|
| 137 |
+
self.rpm_base = None
|
| 138 |
+
self.dist_dir = None
|
| 139 |
+
self.python = None
|
| 140 |
+
self.fix_python = None
|
| 141 |
+
self.spec_only = None
|
| 142 |
+
self.binary_only = None
|
| 143 |
+
self.source_only = None
|
| 144 |
+
self.use_bzip2 = None
|
| 145 |
+
|
| 146 |
+
self.distribution_name = None
|
| 147 |
+
self.group = None
|
| 148 |
+
self.release = None
|
| 149 |
+
self.serial = None
|
| 150 |
+
self.vendor = None
|
| 151 |
+
self.packager = None
|
| 152 |
+
self.doc_files = None
|
| 153 |
+
self.changelog = None
|
| 154 |
+
self.icon = None
|
| 155 |
+
|
| 156 |
+
self.prep_script = None
|
| 157 |
+
self.build_script = None
|
| 158 |
+
self.install_script = None
|
| 159 |
+
self.clean_script = None
|
| 160 |
+
self.verify_script = None
|
| 161 |
+
self.pre_install = None
|
| 162 |
+
self.post_install = None
|
| 163 |
+
self.pre_uninstall = None
|
| 164 |
+
self.post_uninstall = None
|
| 165 |
+
self.prep = None
|
| 166 |
+
self.provides = None
|
| 167 |
+
self.requires = None
|
| 168 |
+
self.conflicts = None
|
| 169 |
+
self.build_requires = None
|
| 170 |
+
self.obsoletes = None
|
| 171 |
+
|
| 172 |
+
self.keep_temp = 0
|
| 173 |
+
self.use_rpm_opt_flags = 1
|
| 174 |
+
self.rpm3_mode = 1
|
| 175 |
+
self.no_autoreq = 0
|
| 176 |
+
|
| 177 |
+
self.force_arch = None
|
| 178 |
+
self.quiet = 0
|
| 179 |
+
|
| 180 |
+
def finalize_options(self):
|
| 181 |
+
self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
|
| 182 |
+
if self.rpm_base is None:
|
| 183 |
+
if not self.rpm3_mode:
|
| 184 |
+
raise DistutilsOptionError(
|
| 185 |
+
"you must specify --rpm-base in RPM 2 mode")
|
| 186 |
+
self.rpm_base = os.path.join(self.bdist_base, "rpm")
|
| 187 |
+
|
| 188 |
+
if self.python is None:
|
| 189 |
+
if self.fix_python:
|
| 190 |
+
self.python = sys.executable
|
| 191 |
+
else:
|
| 192 |
+
self.python = "python3"
|
| 193 |
+
elif self.fix_python:
|
| 194 |
+
raise DistutilsOptionError(
|
| 195 |
+
"--python and --fix-python are mutually exclusive options")
|
| 196 |
+
|
| 197 |
+
if os.name != 'posix':
|
| 198 |
+
raise DistutilsPlatformError("don't know how to create RPM "
|
| 199 |
+
"distributions on platform %s" % os.name)
|
| 200 |
+
if self.binary_only and self.source_only:
|
| 201 |
+
raise DistutilsOptionError(
|
| 202 |
+
"cannot supply both '--source-only' and '--binary-only'")
|
| 203 |
+
|
| 204 |
+
# don't pass CFLAGS to pure python distributions
|
| 205 |
+
if not self.distribution.has_ext_modules():
|
| 206 |
+
self.use_rpm_opt_flags = 0
|
| 207 |
+
|
| 208 |
+
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
|
| 209 |
+
self.finalize_package_data()
|
| 210 |
+
|
| 211 |
+
def finalize_package_data(self):
|
| 212 |
+
self.ensure_string('group', "Development/Libraries")
|
| 213 |
+
self.ensure_string('vendor',
|
| 214 |
+
"%s <%s>" % (self.distribution.get_contact(),
|
| 215 |
+
self.distribution.get_contact_email()))
|
| 216 |
+
self.ensure_string('packager')
|
| 217 |
+
self.ensure_string_list('doc_files')
|
| 218 |
+
if isinstance(self.doc_files, list):
|
| 219 |
+
for readme in ('README', 'README.txt'):
|
| 220 |
+
if os.path.exists(readme) and readme not in self.doc_files:
|
| 221 |
+
self.doc_files.append(readme)
|
| 222 |
+
|
| 223 |
+
self.ensure_string('release', "1")
|
| 224 |
+
self.ensure_string('serial') # should it be an int?
|
| 225 |
+
|
| 226 |
+
self.ensure_string('distribution_name')
|
| 227 |
+
|
| 228 |
+
self.ensure_string('changelog')
|
| 229 |
+
# Format changelog correctly
|
| 230 |
+
self.changelog = self._format_changelog(self.changelog)
|
| 231 |
+
|
| 232 |
+
self.ensure_filename('icon')
|
| 233 |
+
|
| 234 |
+
self.ensure_filename('prep_script')
|
| 235 |
+
self.ensure_filename('build_script')
|
| 236 |
+
self.ensure_filename('install_script')
|
| 237 |
+
self.ensure_filename('clean_script')
|
| 238 |
+
self.ensure_filename('verify_script')
|
| 239 |
+
self.ensure_filename('pre_install')
|
| 240 |
+
self.ensure_filename('post_install')
|
| 241 |
+
self.ensure_filename('pre_uninstall')
|
| 242 |
+
self.ensure_filename('post_uninstall')
|
| 243 |
+
|
| 244 |
+
# XXX don't forget we punted on summaries and descriptions -- they
|
| 245 |
+
# should be handled here eventually!
|
| 246 |
+
|
| 247 |
+
# Now *this* is some meta-data that belongs in the setup script...
|
| 248 |
+
self.ensure_string_list('provides')
|
| 249 |
+
self.ensure_string_list('requires')
|
| 250 |
+
self.ensure_string_list('conflicts')
|
| 251 |
+
self.ensure_string_list('build_requires')
|
| 252 |
+
self.ensure_string_list('obsoletes')
|
| 253 |
+
|
| 254 |
+
self.ensure_string('force_arch')
|
| 255 |
+
|
| 256 |
+
def run(self):
|
| 257 |
+
if DEBUG:
|
| 258 |
+
print("before _get_package_data():")
|
| 259 |
+
print("vendor =", self.vendor)
|
| 260 |
+
print("packager =", self.packager)
|
| 261 |
+
print("doc_files =", self.doc_files)
|
| 262 |
+
print("changelog =", self.changelog)
|
| 263 |
+
|
| 264 |
+
# make directories
|
| 265 |
+
if self.spec_only:
|
| 266 |
+
spec_dir = self.dist_dir
|
| 267 |
+
self.mkpath(spec_dir)
|
| 268 |
+
else:
|
| 269 |
+
rpm_dir = {}
|
| 270 |
+
for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
|
| 271 |
+
rpm_dir[d] = os.path.join(self.rpm_base, d)
|
| 272 |
+
self.mkpath(rpm_dir[d])
|
| 273 |
+
spec_dir = rpm_dir['SPECS']
|
| 274 |
+
|
| 275 |
+
# Spec file goes into 'dist_dir' if '--spec-only specified',
|
| 276 |
+
# build/rpm.<plat> otherwise.
|
| 277 |
+
spec_path = os.path.join(spec_dir,
|
| 278 |
+
"%s.spec" % self.distribution.get_name())
|
| 279 |
+
self.execute(write_file,
|
| 280 |
+
(spec_path,
|
| 281 |
+
self._make_spec_file()),
|
| 282 |
+
"writing '%s'" % spec_path)
|
| 283 |
+
|
| 284 |
+
if self.spec_only: # stop if requested
|
| 285 |
+
return
|
| 286 |
+
|
| 287 |
+
# Make a source distribution and copy to SOURCES directory with
|
| 288 |
+
# optional icon.
|
| 289 |
+
saved_dist_files = self.distribution.dist_files[:]
|
| 290 |
+
sdist = self.reinitialize_command('sdist')
|
| 291 |
+
if self.use_bzip2:
|
| 292 |
+
sdist.formats = ['bztar']
|
| 293 |
+
else:
|
| 294 |
+
sdist.formats = ['gztar']
|
| 295 |
+
self.run_command('sdist')
|
| 296 |
+
self.distribution.dist_files = saved_dist_files
|
| 297 |
+
|
| 298 |
+
source = sdist.get_archive_files()[0]
|
| 299 |
+
source_dir = rpm_dir['SOURCES']
|
| 300 |
+
self.copy_file(source, source_dir)
|
| 301 |
+
|
| 302 |
+
if self.icon:
|
| 303 |
+
if os.path.exists(self.icon):
|
| 304 |
+
self.copy_file(self.icon, source_dir)
|
| 305 |
+
else:
|
| 306 |
+
raise DistutilsFileError(
|
| 307 |
+
"icon file '%s' does not exist" % self.icon)
|
| 308 |
+
|
| 309 |
+
# build package
|
| 310 |
+
log.info("building RPMs")
|
| 311 |
+
rpm_cmd = ['rpmbuild']
|
| 312 |
+
|
| 313 |
+
if self.source_only: # what kind of RPMs?
|
| 314 |
+
rpm_cmd.append('-bs')
|
| 315 |
+
elif self.binary_only:
|
| 316 |
+
rpm_cmd.append('-bb')
|
| 317 |
+
else:
|
| 318 |
+
rpm_cmd.append('-ba')
|
| 319 |
+
rpm_cmd.extend(['--define', '__python %s' % self.python])
|
| 320 |
+
if self.rpm3_mode:
|
| 321 |
+
rpm_cmd.extend(['--define',
|
| 322 |
+
'_topdir %s' % os.path.abspath(self.rpm_base)])
|
| 323 |
+
if not self.keep_temp:
|
| 324 |
+
rpm_cmd.append('--clean')
|
| 325 |
+
|
| 326 |
+
if self.quiet:
|
| 327 |
+
rpm_cmd.append('--quiet')
|
| 328 |
+
|
| 329 |
+
rpm_cmd.append(spec_path)
|
| 330 |
+
# Determine the binary rpm names that should be built out of this spec
|
| 331 |
+
# file
|
| 332 |
+
# Note that some of these may not be really built (if the file
|
| 333 |
+
# list is empty)
|
| 334 |
+
nvr_string = "%{name}-%{version}-%{release}"
|
| 335 |
+
src_rpm = nvr_string + ".src.rpm"
|
| 336 |
+
non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
|
| 337 |
+
q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
|
| 338 |
+
src_rpm, non_src_rpm, spec_path)
|
| 339 |
+
|
| 340 |
+
out = os.popen(q_cmd)
|
| 341 |
+
try:
|
| 342 |
+
binary_rpms = []
|
| 343 |
+
source_rpm = None
|
| 344 |
+
while True:
|
| 345 |
+
line = out.readline()
|
| 346 |
+
if not line:
|
| 347 |
+
break
|
| 348 |
+
l = line.strip().split()
|
| 349 |
+
assert(len(l) == 2)
|
| 350 |
+
binary_rpms.append(l[1])
|
| 351 |
+
# The source rpm is named after the first entry in the spec file
|
| 352 |
+
if source_rpm is None:
|
| 353 |
+
source_rpm = l[0]
|
| 354 |
+
|
| 355 |
+
status = out.close()
|
| 356 |
+
if status:
|
| 357 |
+
raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
|
| 358 |
+
|
| 359 |
+
finally:
|
| 360 |
+
out.close()
|
| 361 |
+
|
| 362 |
+
self.spawn(rpm_cmd)
|
| 363 |
+
|
| 364 |
+
if not self.dry_run:
|
| 365 |
+
if self.distribution.has_ext_modules():
|
| 366 |
+
pyversion = get_python_version()
|
| 367 |
+
else:
|
| 368 |
+
pyversion = 'any'
|
| 369 |
+
|
| 370 |
+
if not self.binary_only:
|
| 371 |
+
srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
|
| 372 |
+
assert(os.path.exists(srpm))
|
| 373 |
+
self.move_file(srpm, self.dist_dir)
|
| 374 |
+
filename = os.path.join(self.dist_dir, source_rpm)
|
| 375 |
+
self.distribution.dist_files.append(
|
| 376 |
+
('bdist_rpm', pyversion, filename))
|
| 377 |
+
|
| 378 |
+
if not self.source_only:
|
| 379 |
+
for rpm in binary_rpms:
|
| 380 |
+
rpm = os.path.join(rpm_dir['RPMS'], rpm)
|
| 381 |
+
if os.path.exists(rpm):
|
| 382 |
+
self.move_file(rpm, self.dist_dir)
|
| 383 |
+
filename = os.path.join(self.dist_dir,
|
| 384 |
+
os.path.basename(rpm))
|
| 385 |
+
self.distribution.dist_files.append(
|
| 386 |
+
('bdist_rpm', pyversion, filename))
|
| 387 |
+
|
| 388 |
+
def _dist_path(self, path):
|
| 389 |
+
return os.path.join(self.dist_dir, os.path.basename(path))
|
| 390 |
+
|
| 391 |
+
def _make_spec_file(self):
|
| 392 |
+
"""Generate the text of an RPM spec file and return it as a
|
| 393 |
+
list of strings (one per line).
|
| 394 |
+
"""
|
| 395 |
+
# definitions and headers
|
| 396 |
+
spec_file = [
|
| 397 |
+
'%define name ' + self.distribution.get_name(),
|
| 398 |
+
'%define version ' + self.distribution.get_version().replace('-','_'),
|
| 399 |
+
'%define unmangled_version ' + self.distribution.get_version(),
|
| 400 |
+
'%define release ' + self.release.replace('-','_'),
|
| 401 |
+
'',
|
| 402 |
+
'Summary: ' + self.distribution.get_description(),
|
| 403 |
+
]
|
| 404 |
+
|
| 405 |
+
# Workaround for #14443 which affects some RPM based systems such as
|
| 406 |
+
# RHEL6 (and probably derivatives)
|
| 407 |
+
vendor_hook = subprocess.getoutput('rpm --eval %{__os_install_post}')
|
| 408 |
+
# Generate a potential replacement value for __os_install_post (whilst
|
| 409 |
+
# normalizing the whitespace to simplify the test for whether the
|
| 410 |
+
# invocation of brp-python-bytecompile passes in __python):
|
| 411 |
+
vendor_hook = '\n'.join([' %s \\' % line.strip()
|
| 412 |
+
for line in vendor_hook.splitlines()])
|
| 413 |
+
problem = "brp-python-bytecompile \\\n"
|
| 414 |
+
fixed = "brp-python-bytecompile %{__python} \\\n"
|
| 415 |
+
fixed_hook = vendor_hook.replace(problem, fixed)
|
| 416 |
+
if fixed_hook != vendor_hook:
|
| 417 |
+
spec_file.append('# Workaround for http://bugs.python.org/issue14443')
|
| 418 |
+
spec_file.append('%define __os_install_post ' + fixed_hook + '\n')
|
| 419 |
+
|
| 420 |
+
# put locale summaries into spec file
|
| 421 |
+
# XXX not supported for now (hard to put a dictionary
|
| 422 |
+
# in a config file -- arg!)
|
| 423 |
+
#for locale in self.summaries.keys():
|
| 424 |
+
# spec_file.append('Summary(%s): %s' % (locale,
|
| 425 |
+
# self.summaries[locale]))
|
| 426 |
+
|
| 427 |
+
spec_file.extend([
|
| 428 |
+
'Name: %{name}',
|
| 429 |
+
'Version: %{version}',
|
| 430 |
+
'Release: %{release}',])
|
| 431 |
+
|
| 432 |
+
# XXX yuck! this filename is available from the "sdist" command,
|
| 433 |
+
# but only after it has run: and we create the spec file before
|
| 434 |
+
# running "sdist", in case of --spec-only.
|
| 435 |
+
if self.use_bzip2:
|
| 436 |
+
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2')
|
| 437 |
+
else:
|
| 438 |
+
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')
|
| 439 |
+
|
| 440 |
+
spec_file.extend([
|
| 441 |
+
'License: ' + self.distribution.get_license(),
|
| 442 |
+
'Group: ' + self.group,
|
| 443 |
+
'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
|
| 444 |
+
'Prefix: %{_prefix}', ])
|
| 445 |
+
|
| 446 |
+
if not self.force_arch:
|
| 447 |
+
# noarch if no extension modules
|
| 448 |
+
if not self.distribution.has_ext_modules():
|
| 449 |
+
spec_file.append('BuildArch: noarch')
|
| 450 |
+
else:
|
| 451 |
+
spec_file.append( 'BuildArch: %s' % self.force_arch )
|
| 452 |
+
|
| 453 |
+
for field in ('Vendor',
|
| 454 |
+
'Packager',
|
| 455 |
+
'Provides',
|
| 456 |
+
'Requires',
|
| 457 |
+
'Conflicts',
|
| 458 |
+
'Obsoletes',
|
| 459 |
+
):
|
| 460 |
+
val = getattr(self, field.lower())
|
| 461 |
+
if isinstance(val, list):
|
| 462 |
+
spec_file.append('%s: %s' % (field, ' '.join(val)))
|
| 463 |
+
elif val is not None:
|
| 464 |
+
spec_file.append('%s: %s' % (field, val))
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
if self.distribution.get_url() != 'UNKNOWN':
|
| 468 |
+
spec_file.append('Url: ' + self.distribution.get_url())
|
| 469 |
+
|
| 470 |
+
if self.distribution_name:
|
| 471 |
+
spec_file.append('Distribution: ' + self.distribution_name)
|
| 472 |
+
|
| 473 |
+
if self.build_requires:
|
| 474 |
+
spec_file.append('BuildRequires: ' +
|
| 475 |
+
' '.join(self.build_requires))
|
| 476 |
+
|
| 477 |
+
if self.icon:
|
| 478 |
+
spec_file.append('Icon: ' + os.path.basename(self.icon))
|
| 479 |
+
|
| 480 |
+
if self.no_autoreq:
|
| 481 |
+
spec_file.append('AutoReq: 0')
|
| 482 |
+
|
| 483 |
+
spec_file.extend([
|
| 484 |
+
'',
|
| 485 |
+
'%description',
|
| 486 |
+
self.distribution.get_long_description()
|
| 487 |
+
])
|
| 488 |
+
|
| 489 |
+
# put locale descriptions into spec file
|
| 490 |
+
# XXX again, suppressed because config file syntax doesn't
|
| 491 |
+
# easily support this ;-(
|
| 492 |
+
#for locale in self.descriptions.keys():
|
| 493 |
+
# spec_file.extend([
|
| 494 |
+
# '',
|
| 495 |
+
# '%description -l ' + locale,
|
| 496 |
+
# self.descriptions[locale],
|
| 497 |
+
# ])
|
| 498 |
+
|
| 499 |
+
# rpm scripts
|
| 500 |
+
# figure out default build script
|
| 501 |
+
def_setup_call = "%s %s" % (self.python,os.path.basename(sys.argv[0]))
|
| 502 |
+
def_build = "%s build" % def_setup_call
|
| 503 |
+
if self.use_rpm_opt_flags:
|
| 504 |
+
def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
|
| 505 |
+
|
| 506 |
+
# insert contents of files
|
| 507 |
+
|
| 508 |
+
# XXX this is kind of misleading: user-supplied options are files
|
| 509 |
+
# that we open and interpolate into the spec file, but the defaults
|
| 510 |
+
# are just text that we drop in as-is. Hmmm.
|
| 511 |
+
|
| 512 |
+
install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT '
|
| 513 |
+
'--record=INSTALLED_FILES') % def_setup_call
|
| 514 |
+
|
| 515 |
+
script_options = [
|
| 516 |
+
('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"),
|
| 517 |
+
('build', 'build_script', def_build),
|
| 518 |
+
('install', 'install_script', install_cmd),
|
| 519 |
+
('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
|
| 520 |
+
('verifyscript', 'verify_script', None),
|
| 521 |
+
('pre', 'pre_install', None),
|
| 522 |
+
('post', 'post_install', None),
|
| 523 |
+
('preun', 'pre_uninstall', None),
|
| 524 |
+
('postun', 'post_uninstall', None),
|
| 525 |
+
]
|
| 526 |
+
|
| 527 |
+
for (rpm_opt, attr, default) in script_options:
|
| 528 |
+
# Insert contents of file referred to, if no file is referred to
|
| 529 |
+
# use 'default' as contents of script
|
| 530 |
+
val = getattr(self, attr)
|
| 531 |
+
if val or default:
|
| 532 |
+
spec_file.extend([
|
| 533 |
+
'',
|
| 534 |
+
'%' + rpm_opt,])
|
| 535 |
+
if val:
|
| 536 |
+
with open(val) as f:
|
| 537 |
+
spec_file.extend(f.read().split('\n'))
|
| 538 |
+
else:
|
| 539 |
+
spec_file.append(default)
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
# files section
|
| 543 |
+
spec_file.extend([
|
| 544 |
+
'',
|
| 545 |
+
'%files -f INSTALLED_FILES',
|
| 546 |
+
'%defattr(-,root,root)',
|
| 547 |
+
])
|
| 548 |
+
|
| 549 |
+
if self.doc_files:
|
| 550 |
+
spec_file.append('%doc ' + ' '.join(self.doc_files))
|
| 551 |
+
|
| 552 |
+
if self.changelog:
|
| 553 |
+
spec_file.extend([
|
| 554 |
+
'',
|
| 555 |
+
'%changelog',])
|
| 556 |
+
spec_file.extend(self.changelog)
|
| 557 |
+
|
| 558 |
+
return spec_file
|
| 559 |
+
|
| 560 |
+
def _format_changelog(self, changelog):
|
| 561 |
+
"""Format the changelog correctly and convert it to a list of strings
|
| 562 |
+
"""
|
| 563 |
+
if not changelog:
|
| 564 |
+
return changelog
|
| 565 |
+
new_changelog = []
|
| 566 |
+
for line in changelog.strip().split('\n'):
|
| 567 |
+
line = line.strip()
|
| 568 |
+
if line[0] == '*':
|
| 569 |
+
new_changelog.extend(['', line])
|
| 570 |
+
elif line[0] == '-':
|
| 571 |
+
new_changelog.append(line)
|
| 572 |
+
else:
|
| 573 |
+
new_changelog.append(' ' + line)
|
| 574 |
+
|
| 575 |
+
# strip trailing newline inserted by first changelog entry
|
| 576 |
+
if not new_changelog[0]:
|
| 577 |
+
del new_changelog[0]
|
| 578 |
+
|
| 579 |
+
return new_changelog
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.build
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'build' command."""
|
| 4 |
+
|
| 5 |
+
import sys, os
|
| 6 |
+
from distutils.core import Command
|
| 7 |
+
from distutils.errors import DistutilsOptionError
|
| 8 |
+
from distutils.util import get_platform
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def show_compilers():
|
| 12 |
+
from distutils.ccompiler import show_compilers
|
| 13 |
+
show_compilers()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class build(Command):
|
| 17 |
+
|
| 18 |
+
description = "build everything needed to install"
|
| 19 |
+
|
| 20 |
+
user_options = [
|
| 21 |
+
('build-base=', 'b',
|
| 22 |
+
"base directory for build library"),
|
| 23 |
+
('build-purelib=', None,
|
| 24 |
+
"build directory for platform-neutral distributions"),
|
| 25 |
+
('build-platlib=', None,
|
| 26 |
+
"build directory for platform-specific distributions"),
|
| 27 |
+
('build-lib=', None,
|
| 28 |
+
"build directory for all distribution (defaults to either " +
|
| 29 |
+
"build-purelib or build-platlib"),
|
| 30 |
+
('build-scripts=', None,
|
| 31 |
+
"build directory for scripts"),
|
| 32 |
+
('build-temp=', 't',
|
| 33 |
+
"temporary build directory"),
|
| 34 |
+
('plat-name=', 'p',
|
| 35 |
+
"platform name to build for, if supported "
|
| 36 |
+
"(default: %s)" % get_platform()),
|
| 37 |
+
('compiler=', 'c',
|
| 38 |
+
"specify the compiler type"),
|
| 39 |
+
('parallel=', 'j',
|
| 40 |
+
"number of parallel build jobs"),
|
| 41 |
+
('debug', 'g',
|
| 42 |
+
"compile extensions and libraries with debugging information"),
|
| 43 |
+
('force', 'f',
|
| 44 |
+
"forcibly build everything (ignore file timestamps)"),
|
| 45 |
+
('executable=', 'e',
|
| 46 |
+
"specify final destination interpreter path (build.py)"),
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
boolean_options = ['debug', 'force']
|
| 50 |
+
|
| 51 |
+
help_options = [
|
| 52 |
+
('help-compiler', None,
|
| 53 |
+
"list available compilers", show_compilers),
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
def initialize_options(self):
|
| 57 |
+
self.build_base = 'build'
|
| 58 |
+
# these are decided only after 'build_base' has its final value
|
| 59 |
+
# (unless overridden by the user or client)
|
| 60 |
+
self.build_purelib = None
|
| 61 |
+
self.build_platlib = None
|
| 62 |
+
self.build_lib = None
|
| 63 |
+
self.build_temp = None
|
| 64 |
+
self.build_scripts = None
|
| 65 |
+
self.compiler = None
|
| 66 |
+
self.plat_name = None
|
| 67 |
+
self.debug = None
|
| 68 |
+
self.force = 0
|
| 69 |
+
self.executable = None
|
| 70 |
+
self.parallel = None
|
| 71 |
+
|
| 72 |
+
def finalize_options(self):
|
| 73 |
+
if self.plat_name is None:
|
| 74 |
+
self.plat_name = get_platform()
|
| 75 |
+
else:
|
| 76 |
+
# plat-name only supported for windows (other platforms are
|
| 77 |
+
# supported via ./configure flags, if at all). Avoid misleading
|
| 78 |
+
# other platforms.
|
| 79 |
+
if os.name != 'nt':
|
| 80 |
+
raise DistutilsOptionError(
|
| 81 |
+
"--plat-name only supported on Windows (try "
|
| 82 |
+
"using './configure --help' on your platform)")
|
| 83 |
+
|
| 84 |
+
plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
|
| 85 |
+
|
| 86 |
+
# Make it so Python 2.x and Python 2.x with --with-pydebug don't
|
| 87 |
+
# share the same build directories. Doing so confuses the build
|
| 88 |
+
# process for C modules
|
| 89 |
+
if hasattr(sys, 'gettotalrefcount'):
|
| 90 |
+
plat_specifier += '-pydebug'
|
| 91 |
+
|
| 92 |
+
# 'build_purelib' and 'build_platlib' just default to 'lib' and
|
| 93 |
+
# 'lib.<plat>' under the base build directory. We only use one of
|
| 94 |
+
# them for a given distribution, though --
|
| 95 |
+
if self.build_purelib is None:
|
| 96 |
+
self.build_purelib = os.path.join(self.build_base, 'lib')
|
| 97 |
+
if self.build_platlib is None:
|
| 98 |
+
self.build_platlib = os.path.join(self.build_base,
|
| 99 |
+
'lib' + plat_specifier)
|
| 100 |
+
|
| 101 |
+
# 'build_lib' is the actual directory that we will use for this
|
| 102 |
+
# particular module distribution -- if user didn't supply it, pick
|
| 103 |
+
# one of 'build_purelib' or 'build_platlib'.
|
| 104 |
+
if self.build_lib is None:
|
| 105 |
+
if self.distribution.ext_modules:
|
| 106 |
+
self.build_lib = self.build_platlib
|
| 107 |
+
else:
|
| 108 |
+
self.build_lib = self.build_purelib
|
| 109 |
+
|
| 110 |
+
# 'build_temp' -- temporary directory for compiler turds,
|
| 111 |
+
# "build/temp.<plat>"
|
| 112 |
+
if self.build_temp is None:
|
| 113 |
+
self.build_temp = os.path.join(self.build_base,
|
| 114 |
+
'temp' + plat_specifier)
|
| 115 |
+
if self.build_scripts is None:
|
| 116 |
+
self.build_scripts = os.path.join(self.build_base,
|
| 117 |
+
'scripts-%d.%d' % sys.version_info[:2])
|
| 118 |
+
|
| 119 |
+
if self.executable is None and sys.executable:
|
| 120 |
+
self.executable = os.path.normpath(sys.executable)
|
| 121 |
+
|
| 122 |
+
if isinstance(self.parallel, str):
|
| 123 |
+
try:
|
| 124 |
+
self.parallel = int(self.parallel)
|
| 125 |
+
except ValueError:
|
| 126 |
+
raise DistutilsOptionError("parallel should be an integer")
|
| 127 |
+
|
| 128 |
+
def run(self):
|
| 129 |
+
# Run all relevant sub-commands. This will be some subset of:
|
| 130 |
+
# - build_py - pure Python modules
|
| 131 |
+
# - build_clib - standalone C libraries
|
| 132 |
+
# - build_ext - Python extensions
|
| 133 |
+
# - build_scripts - (Python) scripts
|
| 134 |
+
for cmd_name in self.get_sub_commands():
|
| 135 |
+
self.run_command(cmd_name)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
# -- Predicates for the sub-command list ---------------------------
|
| 139 |
+
|
| 140 |
+
def has_pure_modules(self):
|
| 141 |
+
return self.distribution.has_pure_modules()
|
| 142 |
+
|
| 143 |
+
def has_c_libraries(self):
|
| 144 |
+
return self.distribution.has_c_libraries()
|
| 145 |
+
|
| 146 |
+
def has_ext_modules(self):
|
| 147 |
+
return self.distribution.has_ext_modules()
|
| 148 |
+
|
| 149 |
+
def has_scripts(self):
|
| 150 |
+
return self.distribution.has_scripts()
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
sub_commands = [('build_py', has_pure_modules),
|
| 154 |
+
('build_clib', has_c_libraries),
|
| 155 |
+
('build_ext', has_ext_modules),
|
| 156 |
+
('build_scripts', has_scripts),
|
| 157 |
+
]
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build_clib.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.build_clib
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'build_clib' command, to build a C/C++ library
|
| 4 |
+
that is included in the module distribution and needed by an extension
|
| 5 |
+
module."""
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# XXX this module has *lots* of code ripped-off quite transparently from
|
| 9 |
+
# build_ext.py -- not surprisingly really, as the work required to build
|
| 10 |
+
# a static library from a collection of C source files is not really all
|
| 11 |
+
# that different from what's required to build a shared object file from
|
| 12 |
+
# a collection of C source files. Nevertheless, I haven't done the
|
| 13 |
+
# necessary refactoring to account for the overlap in code between the
|
| 14 |
+
# two modules, mainly because a number of subtle details changed in the
|
| 15 |
+
# cut 'n paste. Sigh.
|
| 16 |
+
|
| 17 |
+
import os
|
| 18 |
+
from distutils.core import Command
|
| 19 |
+
from distutils.errors import *
|
| 20 |
+
from distutils.sysconfig import customize_compiler
|
| 21 |
+
from distutils import log
|
| 22 |
+
|
| 23 |
+
def show_compilers():
|
| 24 |
+
from distutils.ccompiler import show_compilers
|
| 25 |
+
show_compilers()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class build_clib(Command):
|
| 29 |
+
|
| 30 |
+
description = "build C/C++ libraries used by Python extensions"
|
| 31 |
+
|
| 32 |
+
user_options = [
|
| 33 |
+
('build-clib=', 'b',
|
| 34 |
+
"directory to build C/C++ libraries to"),
|
| 35 |
+
('build-temp=', 't',
|
| 36 |
+
"directory to put temporary build by-products"),
|
| 37 |
+
('debug', 'g',
|
| 38 |
+
"compile with debugging information"),
|
| 39 |
+
('force', 'f',
|
| 40 |
+
"forcibly build everything (ignore file timestamps)"),
|
| 41 |
+
('compiler=', 'c',
|
| 42 |
+
"specify the compiler type"),
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
boolean_options = ['debug', 'force']
|
| 46 |
+
|
| 47 |
+
help_options = [
|
| 48 |
+
('help-compiler', None,
|
| 49 |
+
"list available compilers", show_compilers),
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
def initialize_options(self):
|
| 53 |
+
self.build_clib = None
|
| 54 |
+
self.build_temp = None
|
| 55 |
+
|
| 56 |
+
# List of libraries to build
|
| 57 |
+
self.libraries = None
|
| 58 |
+
|
| 59 |
+
# Compilation options for all libraries
|
| 60 |
+
self.include_dirs = None
|
| 61 |
+
self.define = None
|
| 62 |
+
self.undef = None
|
| 63 |
+
self.debug = None
|
| 64 |
+
self.force = 0
|
| 65 |
+
self.compiler = None
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def finalize_options(self):
|
| 69 |
+
# This might be confusing: both build-clib and build-temp default
|
| 70 |
+
# to build-temp as defined by the "build" command. This is because
|
| 71 |
+
# I think that C libraries are really just temporary build
|
| 72 |
+
# by-products, at least from the point of view of building Python
|
| 73 |
+
# extensions -- but I want to keep my options open.
|
| 74 |
+
self.set_undefined_options('build',
|
| 75 |
+
('build_temp', 'build_clib'),
|
| 76 |
+
('build_temp', 'build_temp'),
|
| 77 |
+
('compiler', 'compiler'),
|
| 78 |
+
('debug', 'debug'),
|
| 79 |
+
('force', 'force'))
|
| 80 |
+
|
| 81 |
+
self.libraries = self.distribution.libraries
|
| 82 |
+
if self.libraries:
|
| 83 |
+
self.check_library_list(self.libraries)
|
| 84 |
+
|
| 85 |
+
if self.include_dirs is None:
|
| 86 |
+
self.include_dirs = self.distribution.include_dirs or []
|
| 87 |
+
if isinstance(self.include_dirs, str):
|
| 88 |
+
self.include_dirs = self.include_dirs.split(os.pathsep)
|
| 89 |
+
|
| 90 |
+
# XXX same as for build_ext -- what about 'self.define' and
|
| 91 |
+
# 'self.undef' ?
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def run(self):
|
| 95 |
+
if not self.libraries:
|
| 96 |
+
return
|
| 97 |
+
|
| 98 |
+
# Yech -- this is cut 'n pasted from build_ext.py!
|
| 99 |
+
from distutils.ccompiler import new_compiler
|
| 100 |
+
self.compiler = new_compiler(compiler=self.compiler,
|
| 101 |
+
dry_run=self.dry_run,
|
| 102 |
+
force=self.force)
|
| 103 |
+
customize_compiler(self.compiler)
|
| 104 |
+
|
| 105 |
+
if self.include_dirs is not None:
|
| 106 |
+
self.compiler.set_include_dirs(self.include_dirs)
|
| 107 |
+
if self.define is not None:
|
| 108 |
+
# 'define' option is a list of (name,value) tuples
|
| 109 |
+
for (name,value) in self.define:
|
| 110 |
+
self.compiler.define_macro(name, value)
|
| 111 |
+
if self.undef is not None:
|
| 112 |
+
for macro in self.undef:
|
| 113 |
+
self.compiler.undefine_macro(macro)
|
| 114 |
+
|
| 115 |
+
self.build_libraries(self.libraries)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def check_library_list(self, libraries):
|
| 119 |
+
"""Ensure that the list of libraries is valid.
|
| 120 |
+
|
| 121 |
+
`library` is presumably provided as a command option 'libraries'.
|
| 122 |
+
This method checks that it is a list of 2-tuples, where the tuples
|
| 123 |
+
are (library_name, build_info_dict).
|
| 124 |
+
|
| 125 |
+
Raise DistutilsSetupError if the structure is invalid anywhere;
|
| 126 |
+
just returns otherwise.
|
| 127 |
+
"""
|
| 128 |
+
if not isinstance(libraries, list):
|
| 129 |
+
raise DistutilsSetupError(
|
| 130 |
+
"'libraries' option must be a list of tuples")
|
| 131 |
+
|
| 132 |
+
for lib in libraries:
|
| 133 |
+
if not isinstance(lib, tuple) and len(lib) != 2:
|
| 134 |
+
raise DistutilsSetupError(
|
| 135 |
+
"each element of 'libraries' must a 2-tuple")
|
| 136 |
+
|
| 137 |
+
name, build_info = lib
|
| 138 |
+
|
| 139 |
+
if not isinstance(name, str):
|
| 140 |
+
raise DistutilsSetupError(
|
| 141 |
+
"first element of each tuple in 'libraries' "
|
| 142 |
+
"must be a string (the library name)")
|
| 143 |
+
|
| 144 |
+
if '/' in name or (os.sep != '/' and os.sep in name):
|
| 145 |
+
raise DistutilsSetupError("bad library name '%s': "
|
| 146 |
+
"may not contain directory separators" % lib[0])
|
| 147 |
+
|
| 148 |
+
if not isinstance(build_info, dict):
|
| 149 |
+
raise DistutilsSetupError(
|
| 150 |
+
"second element of each tuple in 'libraries' "
|
| 151 |
+
"must be a dictionary (build info)")
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def get_library_names(self):
|
| 155 |
+
# Assume the library list is valid -- 'check_library_list()' is
|
| 156 |
+
# called from 'finalize_options()', so it should be!
|
| 157 |
+
if not self.libraries:
|
| 158 |
+
return None
|
| 159 |
+
|
| 160 |
+
lib_names = []
|
| 161 |
+
for (lib_name, build_info) in self.libraries:
|
| 162 |
+
lib_names.append(lib_name)
|
| 163 |
+
return lib_names
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def get_source_files(self):
|
| 167 |
+
self.check_library_list(self.libraries)
|
| 168 |
+
filenames = []
|
| 169 |
+
for (lib_name, build_info) in self.libraries:
|
| 170 |
+
sources = build_info.get('sources')
|
| 171 |
+
if sources is None or not isinstance(sources, (list, tuple)):
|
| 172 |
+
raise DistutilsSetupError(
|
| 173 |
+
"in 'libraries' option (library '%s'), "
|
| 174 |
+
"'sources' must be present and must be "
|
| 175 |
+
"a list of source filenames" % lib_name)
|
| 176 |
+
|
| 177 |
+
filenames.extend(sources)
|
| 178 |
+
return filenames
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def build_libraries(self, libraries):
|
| 182 |
+
for (lib_name, build_info) in libraries:
|
| 183 |
+
sources = build_info.get('sources')
|
| 184 |
+
if sources is None or not isinstance(sources, (list, tuple)):
|
| 185 |
+
raise DistutilsSetupError(
|
| 186 |
+
"in 'libraries' option (library '%s'), "
|
| 187 |
+
"'sources' must be present and must be "
|
| 188 |
+
"a list of source filenames" % lib_name)
|
| 189 |
+
sources = list(sources)
|
| 190 |
+
|
| 191 |
+
log.info("building '%s' library", lib_name)
|
| 192 |
+
|
| 193 |
+
# First, compile the source code to object files in the library
|
| 194 |
+
# directory. (This should probably change to putting object
|
| 195 |
+
# files in a temporary build directory.)
|
| 196 |
+
macros = build_info.get('macros')
|
| 197 |
+
include_dirs = build_info.get('include_dirs')
|
| 198 |
+
objects = self.compiler.compile(sources,
|
| 199 |
+
output_dir=self.build_temp,
|
| 200 |
+
macros=macros,
|
| 201 |
+
include_dirs=include_dirs,
|
| 202 |
+
debug=self.debug)
|
| 203 |
+
|
| 204 |
+
# Now "link" the object files together into a static library.
|
| 205 |
+
# (On Unix at least, this isn't really linking -- it just
|
| 206 |
+
# builds an archive. Whatever.)
|
| 207 |
+
self.compiler.create_static_lib(objects, lib_name,
|
| 208 |
+
output_dir=self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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.build_ext
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'build_ext' command, for building extension
|
| 4 |
+
modules (currently limited to C extensions, should accommodate C++
|
| 5 |
+
extensions ASAP)."""
|
| 6 |
+
|
| 7 |
+
import contextlib
|
| 8 |
+
import os
|
| 9 |
+
import re
|
| 10 |
+
import sys
|
| 11 |
+
from distutils.core import Command
|
| 12 |
+
from distutils.errors import *
|
| 13 |
+
from distutils.sysconfig import customize_compiler, get_python_version
|
| 14 |
+
from distutils.sysconfig import get_config_h_filename
|
| 15 |
+
from distutils.dep_util import newer_group
|
| 16 |
+
from distutils.extension import Extension
|
| 17 |
+
from distutils.util import get_platform
|
| 18 |
+
from distutils import log
|
| 19 |
+
|
| 20 |
+
from site import USER_BASE
|
| 21 |
+
|
| 22 |
+
# An extension name is just a dot-separated list of Python NAMEs (ie.
|
| 23 |
+
# the same as a fully-qualified module name).
|
| 24 |
+
extension_name_re = re.compile \
|
| 25 |
+
(r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def show_compilers ():
|
| 29 |
+
from distutils.ccompiler import show_compilers
|
| 30 |
+
show_compilers()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class build_ext(Command):
|
| 34 |
+
|
| 35 |
+
description = "build C/C++ extensions (compile/link to build directory)"
|
| 36 |
+
|
| 37 |
+
# XXX thoughts on how to deal with complex command-line options like
|
| 38 |
+
# these, i.e. how to make it so fancy_getopt can suck them off the
|
| 39 |
+
# command line and make it look like setup.py defined the appropriate
|
| 40 |
+
# lists of tuples of what-have-you.
|
| 41 |
+
# - each command needs a callback to process its command-line options
|
| 42 |
+
# - Command.__init__() needs access to its share of the whole
|
| 43 |
+
# command line (must ultimately come from
|
| 44 |
+
# Distribution.parse_command_line())
|
| 45 |
+
# - it then calls the current command class' option-parsing
|
| 46 |
+
# callback to deal with weird options like -D, which have to
|
| 47 |
+
# parse the option text and churn out some custom data
|
| 48 |
+
# structure
|
| 49 |
+
# - that data structure (in this case, a list of 2-tuples)
|
| 50 |
+
# will then be present in the command object by the time
|
| 51 |
+
# we get to finalize_options() (i.e. the constructor
|
| 52 |
+
# takes care of both command-line and client options
|
| 53 |
+
# in between initialize_options() and finalize_options())
|
| 54 |
+
|
| 55 |
+
sep_by = " (separated by '%s')" % os.pathsep
|
| 56 |
+
user_options = [
|
| 57 |
+
('build-lib=', 'b',
|
| 58 |
+
"directory for compiled extension modules"),
|
| 59 |
+
('build-temp=', 't',
|
| 60 |
+
"directory for temporary files (build by-products)"),
|
| 61 |
+
('plat-name=', 'p',
|
| 62 |
+
"platform name to cross-compile for, if supported "
|
| 63 |
+
"(default: %s)" % get_platform()),
|
| 64 |
+
('inplace', 'i',
|
| 65 |
+
"ignore build-lib and put compiled extensions into the source " +
|
| 66 |
+
"directory alongside your pure Python modules"),
|
| 67 |
+
('include-dirs=', 'I',
|
| 68 |
+
"list of directories to search for header files" + sep_by),
|
| 69 |
+
('define=', 'D',
|
| 70 |
+
"C preprocessor macros to define"),
|
| 71 |
+
('undef=', 'U',
|
| 72 |
+
"C preprocessor macros to undefine"),
|
| 73 |
+
('libraries=', 'l',
|
| 74 |
+
"external C libraries to link with"),
|
| 75 |
+
('library-dirs=', 'L',
|
| 76 |
+
"directories to search for external C libraries" + sep_by),
|
| 77 |
+
('rpath=', 'R',
|
| 78 |
+
"directories to search for shared C libraries at runtime"),
|
| 79 |
+
('link-objects=', 'O',
|
| 80 |
+
"extra explicit link objects to include in the link"),
|
| 81 |
+
('debug', 'g',
|
| 82 |
+
"compile/link with debugging information"),
|
| 83 |
+
('force', 'f',
|
| 84 |
+
"forcibly build everything (ignore file timestamps)"),
|
| 85 |
+
('compiler=', 'c',
|
| 86 |
+
"specify the compiler type"),
|
| 87 |
+
('parallel=', 'j',
|
| 88 |
+
"number of parallel build jobs"),
|
| 89 |
+
('swig-cpp', None,
|
| 90 |
+
"make SWIG create C++ files (default is C)"),
|
| 91 |
+
('swig-opts=', None,
|
| 92 |
+
"list of SWIG command line options"),
|
| 93 |
+
('swig=', None,
|
| 94 |
+
"path to the SWIG executable"),
|
| 95 |
+
('user', None,
|
| 96 |
+
"add user include, library and rpath")
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user']
|
| 100 |
+
|
| 101 |
+
help_options = [
|
| 102 |
+
('help-compiler', None,
|
| 103 |
+
"list available compilers", show_compilers),
|
| 104 |
+
]
|
| 105 |
+
|
| 106 |
+
def initialize_options(self):
|
| 107 |
+
self.extensions = None
|
| 108 |
+
self.build_lib = None
|
| 109 |
+
self.plat_name = None
|
| 110 |
+
self.build_temp = None
|
| 111 |
+
self.inplace = 0
|
| 112 |
+
self.package = None
|
| 113 |
+
|
| 114 |
+
self.include_dirs = None
|
| 115 |
+
self.define = None
|
| 116 |
+
self.undef = None
|
| 117 |
+
self.libraries = None
|
| 118 |
+
self.library_dirs = None
|
| 119 |
+
self.rpath = None
|
| 120 |
+
self.link_objects = None
|
| 121 |
+
self.debug = None
|
| 122 |
+
self.force = None
|
| 123 |
+
self.compiler = None
|
| 124 |
+
self.swig = None
|
| 125 |
+
self.swig_cpp = None
|
| 126 |
+
self.swig_opts = None
|
| 127 |
+
self.user = None
|
| 128 |
+
self.parallel = None
|
| 129 |
+
|
| 130 |
+
def finalize_options(self):
|
| 131 |
+
from distutils import sysconfig
|
| 132 |
+
|
| 133 |
+
self.set_undefined_options('build',
|
| 134 |
+
('build_lib', 'build_lib'),
|
| 135 |
+
('build_temp', 'build_temp'),
|
| 136 |
+
('compiler', 'compiler'),
|
| 137 |
+
('debug', 'debug'),
|
| 138 |
+
('force', 'force'),
|
| 139 |
+
('parallel', 'parallel'),
|
| 140 |
+
('plat_name', 'plat_name'),
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
if self.package is None:
|
| 144 |
+
self.package = self.distribution.ext_package
|
| 145 |
+
|
| 146 |
+
self.extensions = self.distribution.ext_modules
|
| 147 |
+
|
| 148 |
+
# Make sure Python's include directories (for Python.h, pyconfig.h,
|
| 149 |
+
# etc.) are in the include search path.
|
| 150 |
+
py_include = sysconfig.get_python_inc()
|
| 151 |
+
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
|
| 152 |
+
if self.include_dirs is None:
|
| 153 |
+
self.include_dirs = self.distribution.include_dirs or []
|
| 154 |
+
if isinstance(self.include_dirs, str):
|
| 155 |
+
self.include_dirs = self.include_dirs.split(os.pathsep)
|
| 156 |
+
|
| 157 |
+
# If in a virtualenv, add its include directory
|
| 158 |
+
# Issue 16116
|
| 159 |
+
if sys.exec_prefix != sys.base_exec_prefix:
|
| 160 |
+
self.include_dirs.append(os.path.join(sys.exec_prefix, 'include'))
|
| 161 |
+
|
| 162 |
+
# Put the Python "system" include dir at the end, so that
|
| 163 |
+
# any local include dirs take precedence.
|
| 164 |
+
self.include_dirs.extend(py_include.split(os.path.pathsep))
|
| 165 |
+
if plat_py_include != py_include:
|
| 166 |
+
self.include_dirs.extend(
|
| 167 |
+
plat_py_include.split(os.path.pathsep))
|
| 168 |
+
|
| 169 |
+
self.ensure_string_list('libraries')
|
| 170 |
+
self.ensure_string_list('link_objects')
|
| 171 |
+
|
| 172 |
+
# Life is easier if we're not forever checking for None, so
|
| 173 |
+
# simplify these options to empty lists if unset
|
| 174 |
+
if self.libraries is None:
|
| 175 |
+
self.libraries = []
|
| 176 |
+
if self.library_dirs is None:
|
| 177 |
+
self.library_dirs = []
|
| 178 |
+
elif isinstance(self.library_dirs, str):
|
| 179 |
+
self.library_dirs = self.library_dirs.split(os.pathsep)
|
| 180 |
+
|
| 181 |
+
if self.rpath is None:
|
| 182 |
+
self.rpath = []
|
| 183 |
+
elif isinstance(self.rpath, str):
|
| 184 |
+
self.rpath = self.rpath.split(os.pathsep)
|
| 185 |
+
|
| 186 |
+
# for extensions under windows use different directories
|
| 187 |
+
# for Release and Debug builds.
|
| 188 |
+
# also Python's library directory must be appended to library_dirs
|
| 189 |
+
if os.name == 'nt':
|
| 190 |
+
# the 'libs' directory is for binary installs - we assume that
|
| 191 |
+
# must be the *native* platform. But we don't really support
|
| 192 |
+
# cross-compiling via a binary install anyway, so we let it go.
|
| 193 |
+
self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
|
| 194 |
+
if sys.base_exec_prefix != sys.prefix: # Issue 16116
|
| 195 |
+
self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
|
| 196 |
+
if self.debug:
|
| 197 |
+
self.build_temp = os.path.join(self.build_temp, "Debug")
|
| 198 |
+
else:
|
| 199 |
+
self.build_temp = os.path.join(self.build_temp, "Release")
|
| 200 |
+
|
| 201 |
+
# Append the source distribution include and library directories,
|
| 202 |
+
# this allows distutils on windows to work in the source tree
|
| 203 |
+
self.include_dirs.append(os.path.dirname(get_config_h_filename()))
|
| 204 |
+
_sys_home = getattr(sys, '_home', None)
|
| 205 |
+
if _sys_home:
|
| 206 |
+
self.library_dirs.append(_sys_home)
|
| 207 |
+
|
| 208 |
+
# Use the .lib files for the correct architecture
|
| 209 |
+
if self.plat_name == 'win32':
|
| 210 |
+
suffix = 'win32'
|
| 211 |
+
else:
|
| 212 |
+
# win-amd64
|
| 213 |
+
suffix = self.plat_name[4:]
|
| 214 |
+
new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
|
| 215 |
+
if suffix:
|
| 216 |
+
new_lib = os.path.join(new_lib, suffix)
|
| 217 |
+
self.library_dirs.append(new_lib)
|
| 218 |
+
|
| 219 |
+
# For extensions under Cygwin, Python's library directory must be
|
| 220 |
+
# appended to library_dirs
|
| 221 |
+
if sys.platform[:6] == 'cygwin':
|
| 222 |
+
if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
|
| 223 |
+
# building third party extensions
|
| 224 |
+
self.library_dirs.append(os.path.join(sys.prefix, "lib",
|
| 225 |
+
"python" + get_python_version(),
|
| 226 |
+
"config"))
|
| 227 |
+
else:
|
| 228 |
+
# building python standard extensions
|
| 229 |
+
self.library_dirs.append('.')
|
| 230 |
+
|
| 231 |
+
# For building extensions with a shared Python library,
|
| 232 |
+
# Python's library directory must be appended to library_dirs
|
| 233 |
+
# See Issues: #1600860, #4366
|
| 234 |
+
if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
|
| 235 |
+
if not sysconfig.python_build:
|
| 236 |
+
# building third party extensions
|
| 237 |
+
self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
|
| 238 |
+
else:
|
| 239 |
+
# building python standard extensions
|
| 240 |
+
self.library_dirs.append('.')
|
| 241 |
+
|
| 242 |
+
# The argument parsing will result in self.define being a string, but
|
| 243 |
+
# it has to be a list of 2-tuples. All the preprocessor symbols
|
| 244 |
+
# specified by the 'define' option will be set to '1'. Multiple
|
| 245 |
+
# symbols can be separated with commas.
|
| 246 |
+
|
| 247 |
+
if self.define:
|
| 248 |
+
defines = self.define.split(',')
|
| 249 |
+
self.define = [(symbol, '1') for symbol in defines]
|
| 250 |
+
|
| 251 |
+
# The option for macros to undefine is also a string from the
|
| 252 |
+
# option parsing, but has to be a list. Multiple symbols can also
|
| 253 |
+
# be separated with commas here.
|
| 254 |
+
if self.undef:
|
| 255 |
+
self.undef = self.undef.split(',')
|
| 256 |
+
|
| 257 |
+
if self.swig_opts is None:
|
| 258 |
+
self.swig_opts = []
|
| 259 |
+
else:
|
| 260 |
+
self.swig_opts = self.swig_opts.split(' ')
|
| 261 |
+
|
| 262 |
+
# Finally add the user include and library directories if requested
|
| 263 |
+
if self.user:
|
| 264 |
+
user_include = os.path.join(USER_BASE, "include")
|
| 265 |
+
user_lib = os.path.join(USER_BASE, "lib")
|
| 266 |
+
if os.path.isdir(user_include):
|
| 267 |
+
self.include_dirs.append(user_include)
|
| 268 |
+
if os.path.isdir(user_lib):
|
| 269 |
+
self.library_dirs.append(user_lib)
|
| 270 |
+
self.rpath.append(user_lib)
|
| 271 |
+
|
| 272 |
+
if isinstance(self.parallel, str):
|
| 273 |
+
try:
|
| 274 |
+
self.parallel = int(self.parallel)
|
| 275 |
+
except ValueError:
|
| 276 |
+
raise DistutilsOptionError("parallel should be an integer")
|
| 277 |
+
|
| 278 |
+
def run(self):
|
| 279 |
+
from distutils.ccompiler import new_compiler
|
| 280 |
+
|
| 281 |
+
# 'self.extensions', as supplied by setup.py, is a list of
|
| 282 |
+
# Extension instances. See the documentation for Extension (in
|
| 283 |
+
# distutils.extension) for details.
|
| 284 |
+
#
|
| 285 |
+
# For backwards compatibility with Distutils 0.8.2 and earlier, we
|
| 286 |
+
# also allow the 'extensions' list to be a list of tuples:
|
| 287 |
+
# (ext_name, build_info)
|
| 288 |
+
# where build_info is a dictionary containing everything that
|
| 289 |
+
# Extension instances do except the name, with a few things being
|
| 290 |
+
# differently named. We convert these 2-tuples to Extension
|
| 291 |
+
# instances as needed.
|
| 292 |
+
|
| 293 |
+
if not self.extensions:
|
| 294 |
+
return
|
| 295 |
+
|
| 296 |
+
# If we were asked to build any C/C++ libraries, make sure that the
|
| 297 |
+
# directory where we put them is in the library search path for
|
| 298 |
+
# linking extensions.
|
| 299 |
+
if self.distribution.has_c_libraries():
|
| 300 |
+
build_clib = self.get_finalized_command('build_clib')
|
| 301 |
+
self.libraries.extend(build_clib.get_library_names() or [])
|
| 302 |
+
self.library_dirs.append(build_clib.build_clib)
|
| 303 |
+
|
| 304 |
+
# Setup the CCompiler object that we'll use to do all the
|
| 305 |
+
# compiling and linking
|
| 306 |
+
self.compiler = new_compiler(compiler=self.compiler,
|
| 307 |
+
verbose=self.verbose,
|
| 308 |
+
dry_run=self.dry_run,
|
| 309 |
+
force=self.force)
|
| 310 |
+
customize_compiler(self.compiler)
|
| 311 |
+
# If we are cross-compiling, init the compiler now (if we are not
|
| 312 |
+
# cross-compiling, init would not hurt, but people may rely on
|
| 313 |
+
# late initialization of compiler even if they shouldn't...)
|
| 314 |
+
if os.name == 'nt' and self.plat_name != get_platform():
|
| 315 |
+
self.compiler.initialize(self.plat_name)
|
| 316 |
+
|
| 317 |
+
# And make sure that any compile/link-related options (which might
|
| 318 |
+
# come from the command-line or from the setup script) are set in
|
| 319 |
+
# that CCompiler object -- that way, they automatically apply to
|
| 320 |
+
# all compiling and linking done here.
|
| 321 |
+
if self.include_dirs is not None:
|
| 322 |
+
self.compiler.set_include_dirs(self.include_dirs)
|
| 323 |
+
if self.define is not None:
|
| 324 |
+
# 'define' option is a list of (name,value) tuples
|
| 325 |
+
for (name, value) in self.define:
|
| 326 |
+
self.compiler.define_macro(name, value)
|
| 327 |
+
if self.undef is not None:
|
| 328 |
+
for macro in self.undef:
|
| 329 |
+
self.compiler.undefine_macro(macro)
|
| 330 |
+
if self.libraries is not None:
|
| 331 |
+
self.compiler.set_libraries(self.libraries)
|
| 332 |
+
if self.library_dirs is not None:
|
| 333 |
+
self.compiler.set_library_dirs(self.library_dirs)
|
| 334 |
+
if self.rpath is not None:
|
| 335 |
+
self.compiler.set_runtime_library_dirs(self.rpath)
|
| 336 |
+
if self.link_objects is not None:
|
| 337 |
+
self.compiler.set_link_objects(self.link_objects)
|
| 338 |
+
|
| 339 |
+
# Now actually compile and link everything.
|
| 340 |
+
self.build_extensions()
|
| 341 |
+
|
| 342 |
+
def check_extensions_list(self, extensions):
|
| 343 |
+
"""Ensure that the list of extensions (presumably provided as a
|
| 344 |
+
command option 'extensions') is valid, i.e. it is a list of
|
| 345 |
+
Extension objects. We also support the old-style list of 2-tuples,
|
| 346 |
+
where the tuples are (ext_name, build_info), which are converted to
|
| 347 |
+
Extension instances here.
|
| 348 |
+
|
| 349 |
+
Raise DistutilsSetupError if the structure is invalid anywhere;
|
| 350 |
+
just returns otherwise.
|
| 351 |
+
"""
|
| 352 |
+
if not isinstance(extensions, list):
|
| 353 |
+
raise DistutilsSetupError(
|
| 354 |
+
"'ext_modules' option must be a list of Extension instances")
|
| 355 |
+
|
| 356 |
+
for i, ext in enumerate(extensions):
|
| 357 |
+
if isinstance(ext, Extension):
|
| 358 |
+
continue # OK! (assume type-checking done
|
| 359 |
+
# by Extension constructor)
|
| 360 |
+
|
| 361 |
+
if not isinstance(ext, tuple) or len(ext) != 2:
|
| 362 |
+
raise DistutilsSetupError(
|
| 363 |
+
"each element of 'ext_modules' option must be an "
|
| 364 |
+
"Extension instance or 2-tuple")
|
| 365 |
+
|
| 366 |
+
ext_name, build_info = ext
|
| 367 |
+
|
| 368 |
+
log.warn("old-style (ext_name, build_info) tuple found in "
|
| 369 |
+
"ext_modules for extension '%s' "
|
| 370 |
+
"-- please convert to Extension instance", ext_name)
|
| 371 |
+
|
| 372 |
+
if not (isinstance(ext_name, str) and
|
| 373 |
+
extension_name_re.match(ext_name)):
|
| 374 |
+
raise DistutilsSetupError(
|
| 375 |
+
"first element of each tuple in 'ext_modules' "
|
| 376 |
+
"must be the extension name (a string)")
|
| 377 |
+
|
| 378 |
+
if not isinstance(build_info, dict):
|
| 379 |
+
raise DistutilsSetupError(
|
| 380 |
+
"second element of each tuple in 'ext_modules' "
|
| 381 |
+
"must be a dictionary (build info)")
|
| 382 |
+
|
| 383 |
+
# OK, the (ext_name, build_info) dict is type-safe: convert it
|
| 384 |
+
# to an Extension instance.
|
| 385 |
+
ext = Extension(ext_name, build_info['sources'])
|
| 386 |
+
|
| 387 |
+
# Easy stuff: one-to-one mapping from dict elements to
|
| 388 |
+
# instance attributes.
|
| 389 |
+
for key in ('include_dirs', 'library_dirs', 'libraries',
|
| 390 |
+
'extra_objects', 'extra_compile_args',
|
| 391 |
+
'extra_link_args'):
|
| 392 |
+
val = build_info.get(key)
|
| 393 |
+
if val is not None:
|
| 394 |
+
setattr(ext, key, val)
|
| 395 |
+
|
| 396 |
+
# Medium-easy stuff: same syntax/semantics, different names.
|
| 397 |
+
ext.runtime_library_dirs = build_info.get('rpath')
|
| 398 |
+
if 'def_file' in build_info:
|
| 399 |
+
log.warn("'def_file' element of build info dict "
|
| 400 |
+
"no longer supported")
|
| 401 |
+
|
| 402 |
+
# Non-trivial stuff: 'macros' split into 'define_macros'
|
| 403 |
+
# and 'undef_macros'.
|
| 404 |
+
macros = build_info.get('macros')
|
| 405 |
+
if macros:
|
| 406 |
+
ext.define_macros = []
|
| 407 |
+
ext.undef_macros = []
|
| 408 |
+
for macro in macros:
|
| 409 |
+
if not (isinstance(macro, tuple) and len(macro) in (1, 2)):
|
| 410 |
+
raise DistutilsSetupError(
|
| 411 |
+
"'macros' element of build info dict "
|
| 412 |
+
"must be 1- or 2-tuple")
|
| 413 |
+
if len(macro) == 1:
|
| 414 |
+
ext.undef_macros.append(macro[0])
|
| 415 |
+
elif len(macro) == 2:
|
| 416 |
+
ext.define_macros.append(macro)
|
| 417 |
+
|
| 418 |
+
extensions[i] = ext
|
| 419 |
+
|
| 420 |
+
def get_source_files(self):
|
| 421 |
+
self.check_extensions_list(self.extensions)
|
| 422 |
+
filenames = []
|
| 423 |
+
|
| 424 |
+
# Wouldn't it be neat if we knew the names of header files too...
|
| 425 |
+
for ext in self.extensions:
|
| 426 |
+
filenames.extend(ext.sources)
|
| 427 |
+
return filenames
|
| 428 |
+
|
| 429 |
+
def get_outputs(self):
|
| 430 |
+
# Sanity check the 'extensions' list -- can't assume this is being
|
| 431 |
+
# done in the same run as a 'build_extensions()' call (in fact, we
|
| 432 |
+
# can probably assume that it *isn't*!).
|
| 433 |
+
self.check_extensions_list(self.extensions)
|
| 434 |
+
|
| 435 |
+
# And build the list of output (built) filenames. Note that this
|
| 436 |
+
# ignores the 'inplace' flag, and assumes everything goes in the
|
| 437 |
+
# "build" tree.
|
| 438 |
+
outputs = []
|
| 439 |
+
for ext in self.extensions:
|
| 440 |
+
outputs.append(self.get_ext_fullpath(ext.name))
|
| 441 |
+
return outputs
|
| 442 |
+
|
| 443 |
+
def build_extensions(self):
|
| 444 |
+
# First, sanity-check the 'extensions' list
|
| 445 |
+
self.check_extensions_list(self.extensions)
|
| 446 |
+
if self.parallel:
|
| 447 |
+
self._build_extensions_parallel()
|
| 448 |
+
else:
|
| 449 |
+
self._build_extensions_serial()
|
| 450 |
+
|
| 451 |
+
def _build_extensions_parallel(self):
|
| 452 |
+
workers = self.parallel
|
| 453 |
+
if self.parallel is True:
|
| 454 |
+
workers = os.cpu_count() # may return None
|
| 455 |
+
try:
|
| 456 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 457 |
+
except ImportError:
|
| 458 |
+
workers = None
|
| 459 |
+
|
| 460 |
+
if workers is None:
|
| 461 |
+
self._build_extensions_serial()
|
| 462 |
+
return
|
| 463 |
+
|
| 464 |
+
with ThreadPoolExecutor(max_workers=workers) as executor:
|
| 465 |
+
futures = [executor.submit(self.build_extension, ext)
|
| 466 |
+
for ext in self.extensions]
|
| 467 |
+
for ext, fut in zip(self.extensions, futures):
|
| 468 |
+
with self._filter_build_errors(ext):
|
| 469 |
+
fut.result()
|
| 470 |
+
|
| 471 |
+
def _build_extensions_serial(self):
|
| 472 |
+
for ext in self.extensions:
|
| 473 |
+
with self._filter_build_errors(ext):
|
| 474 |
+
self.build_extension(ext)
|
| 475 |
+
|
| 476 |
+
@contextlib.contextmanager
|
| 477 |
+
def _filter_build_errors(self, ext):
|
| 478 |
+
try:
|
| 479 |
+
yield
|
| 480 |
+
except (CCompilerError, DistutilsError, CompileError) as e:
|
| 481 |
+
if not ext.optional:
|
| 482 |
+
raise
|
| 483 |
+
self.warn('building extension "%s" failed: %s' %
|
| 484 |
+
(ext.name, e))
|
| 485 |
+
|
| 486 |
+
def build_extension(self, ext):
|
| 487 |
+
sources = ext.sources
|
| 488 |
+
if sources is None or not isinstance(sources, (list, tuple)):
|
| 489 |
+
raise DistutilsSetupError(
|
| 490 |
+
"in 'ext_modules' option (extension '%s'), "
|
| 491 |
+
"'sources' must be present and must be "
|
| 492 |
+
"a list of source filenames" % ext.name)
|
| 493 |
+
# sort to make the resulting .so file build reproducible
|
| 494 |
+
sources = sorted(sources)
|
| 495 |
+
|
| 496 |
+
ext_path = self.get_ext_fullpath(ext.name)
|
| 497 |
+
depends = sources + ext.depends
|
| 498 |
+
if not (self.force or newer_group(depends, ext_path, 'newer')):
|
| 499 |
+
log.debug("skipping '%s' extension (up-to-date)", ext.name)
|
| 500 |
+
return
|
| 501 |
+
else:
|
| 502 |
+
log.info("building '%s' extension", ext.name)
|
| 503 |
+
|
| 504 |
+
# First, scan the sources for SWIG definition files (.i), run
|
| 505 |
+
# SWIG on 'em to create .c files, and modify the sources list
|
| 506 |
+
# accordingly.
|
| 507 |
+
sources = self.swig_sources(sources, ext)
|
| 508 |
+
|
| 509 |
+
# Next, compile the source code to object files.
|
| 510 |
+
|
| 511 |
+
# XXX not honouring 'define_macros' or 'undef_macros' -- the
|
| 512 |
+
# CCompiler API needs to change to accommodate this, and I
|
| 513 |
+
# want to do one thing at a time!
|
| 514 |
+
|
| 515 |
+
# Two possible sources for extra compiler arguments:
|
| 516 |
+
# - 'extra_compile_args' in Extension object
|
| 517 |
+
# - CFLAGS environment variable (not particularly
|
| 518 |
+
# elegant, but people seem to expect it and I
|
| 519 |
+
# guess it's useful)
|
| 520 |
+
# The environment variable should take precedence, and
|
| 521 |
+
# any sensible compiler will give precedence to later
|
| 522 |
+
# command line args. Hence we combine them in order:
|
| 523 |
+
extra_args = ext.extra_compile_args or []
|
| 524 |
+
|
| 525 |
+
macros = ext.define_macros[:]
|
| 526 |
+
for undef in ext.undef_macros:
|
| 527 |
+
macros.append((undef,))
|
| 528 |
+
|
| 529 |
+
objects = self.compiler.compile(sources,
|
| 530 |
+
output_dir=self.build_temp,
|
| 531 |
+
macros=macros,
|
| 532 |
+
include_dirs=ext.include_dirs,
|
| 533 |
+
debug=self.debug,
|
| 534 |
+
extra_postargs=extra_args,
|
| 535 |
+
depends=ext.depends)
|
| 536 |
+
|
| 537 |
+
# XXX outdated variable, kept here in case third-part code
|
| 538 |
+
# needs it.
|
| 539 |
+
self._built_objects = objects[:]
|
| 540 |
+
|
| 541 |
+
# Now link the object files together into a "shared object" --
|
| 542 |
+
# of course, first we have to figure out all the other things
|
| 543 |
+
# that go into the mix.
|
| 544 |
+
if ext.extra_objects:
|
| 545 |
+
objects.extend(ext.extra_objects)
|
| 546 |
+
extra_args = ext.extra_link_args or []
|
| 547 |
+
|
| 548 |
+
# Detect target language, if not provided
|
| 549 |
+
language = ext.language or self.compiler.detect_language(sources)
|
| 550 |
+
|
| 551 |
+
self.compiler.link_shared_object(
|
| 552 |
+
objects, ext_path,
|
| 553 |
+
libraries=self.get_libraries(ext),
|
| 554 |
+
library_dirs=ext.library_dirs,
|
| 555 |
+
runtime_library_dirs=ext.runtime_library_dirs,
|
| 556 |
+
extra_postargs=extra_args,
|
| 557 |
+
export_symbols=self.get_export_symbols(ext),
|
| 558 |
+
debug=self.debug,
|
| 559 |
+
build_temp=self.build_temp,
|
| 560 |
+
target_lang=language)
|
| 561 |
+
|
| 562 |
+
def swig_sources(self, sources, extension):
|
| 563 |
+
"""Walk the list of source files in 'sources', looking for SWIG
|
| 564 |
+
interface (.i) files. Run SWIG on all that are found, and
|
| 565 |
+
return a modified 'sources' list with SWIG source files replaced
|
| 566 |
+
by the generated C (or C++) files.
|
| 567 |
+
"""
|
| 568 |
+
new_sources = []
|
| 569 |
+
swig_sources = []
|
| 570 |
+
swig_targets = {}
|
| 571 |
+
|
| 572 |
+
# XXX this drops generated C/C++ files into the source tree, which
|
| 573 |
+
# is fine for developers who want to distribute the generated
|
| 574 |
+
# source -- but there should be an option to put SWIG output in
|
| 575 |
+
# the temp dir.
|
| 576 |
+
|
| 577 |
+
if self.swig_cpp:
|
| 578 |
+
log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
|
| 579 |
+
|
| 580 |
+
if self.swig_cpp or ('-c++' in self.swig_opts) or \
|
| 581 |
+
('-c++' in extension.swig_opts):
|
| 582 |
+
target_ext = '.cpp'
|
| 583 |
+
else:
|
| 584 |
+
target_ext = '.c'
|
| 585 |
+
|
| 586 |
+
for source in sources:
|
| 587 |
+
(base, ext) = os.path.splitext(source)
|
| 588 |
+
if ext == ".i": # SWIG interface file
|
| 589 |
+
new_sources.append(base + '_wrap' + target_ext)
|
| 590 |
+
swig_sources.append(source)
|
| 591 |
+
swig_targets[source] = new_sources[-1]
|
| 592 |
+
else:
|
| 593 |
+
new_sources.append(source)
|
| 594 |
+
|
| 595 |
+
if not swig_sources:
|
| 596 |
+
return new_sources
|
| 597 |
+
|
| 598 |
+
swig = self.swig or self.find_swig()
|
| 599 |
+
swig_cmd = [swig, "-python"]
|
| 600 |
+
swig_cmd.extend(self.swig_opts)
|
| 601 |
+
if self.swig_cpp:
|
| 602 |
+
swig_cmd.append("-c++")
|
| 603 |
+
|
| 604 |
+
# Do not override commandline arguments
|
| 605 |
+
if not self.swig_opts:
|
| 606 |
+
for o in extension.swig_opts:
|
| 607 |
+
swig_cmd.append(o)
|
| 608 |
+
|
| 609 |
+
for source in swig_sources:
|
| 610 |
+
target = swig_targets[source]
|
| 611 |
+
log.info("swigging %s to %s", source, target)
|
| 612 |
+
self.spawn(swig_cmd + ["-o", target, source])
|
| 613 |
+
|
| 614 |
+
return new_sources
|
| 615 |
+
|
| 616 |
+
def find_swig(self):
|
| 617 |
+
"""Return the name of the SWIG executable. On Unix, this is
|
| 618 |
+
just "swig" -- it should be in the PATH. Tries a bit harder on
|
| 619 |
+
Windows.
|
| 620 |
+
"""
|
| 621 |
+
if os.name == "posix":
|
| 622 |
+
return "swig"
|
| 623 |
+
elif os.name == "nt":
|
| 624 |
+
# Look for SWIG in its standard installation directory on
|
| 625 |
+
# Windows (or so I presume!). If we find it there, great;
|
| 626 |
+
# if not, act like Unix and assume it's in the PATH.
|
| 627 |
+
for vers in ("1.3", "1.2", "1.1"):
|
| 628 |
+
fn = os.path.join("c:\\swig%s" % vers, "swig.exe")
|
| 629 |
+
if os.path.isfile(fn):
|
| 630 |
+
return fn
|
| 631 |
+
else:
|
| 632 |
+
return "swig.exe"
|
| 633 |
+
else:
|
| 634 |
+
raise DistutilsPlatformError(
|
| 635 |
+
"I don't know how to find (much less run) SWIG "
|
| 636 |
+
"on platform '%s'" % os.name)
|
| 637 |
+
|
| 638 |
+
# -- Name generators -----------------------------------------------
|
| 639 |
+
# (extension names, filenames, whatever)
|
| 640 |
+
def get_ext_fullpath(self, ext_name):
|
| 641 |
+
"""Returns the path of the filename for a given extension.
|
| 642 |
+
|
| 643 |
+
The file is located in `build_lib` or directly in the package
|
| 644 |
+
(inplace option).
|
| 645 |
+
"""
|
| 646 |
+
fullname = self.get_ext_fullname(ext_name)
|
| 647 |
+
modpath = fullname.split('.')
|
| 648 |
+
filename = self.get_ext_filename(modpath[-1])
|
| 649 |
+
|
| 650 |
+
if not self.inplace:
|
| 651 |
+
# no further work needed
|
| 652 |
+
# returning :
|
| 653 |
+
# build_dir/package/path/filename
|
| 654 |
+
filename = os.path.join(*modpath[:-1]+[filename])
|
| 655 |
+
return os.path.join(self.build_lib, filename)
|
| 656 |
+
|
| 657 |
+
# the inplace option requires to find the package directory
|
| 658 |
+
# using the build_py command for that
|
| 659 |
+
package = '.'.join(modpath[0:-1])
|
| 660 |
+
build_py = self.get_finalized_command('build_py')
|
| 661 |
+
package_dir = os.path.abspath(build_py.get_package_dir(package))
|
| 662 |
+
|
| 663 |
+
# returning
|
| 664 |
+
# package_dir/filename
|
| 665 |
+
return os.path.join(package_dir, filename)
|
| 666 |
+
|
| 667 |
+
def get_ext_fullname(self, ext_name):
|
| 668 |
+
"""Returns the fullname of a given extension name.
|
| 669 |
+
|
| 670 |
+
Adds the `package.` prefix"""
|
| 671 |
+
if self.package is None:
|
| 672 |
+
return ext_name
|
| 673 |
+
else:
|
| 674 |
+
return self.package + '.' + ext_name
|
| 675 |
+
|
| 676 |
+
def get_ext_filename(self, ext_name):
|
| 677 |
+
r"""Convert the name of an extension (eg. "foo.bar") into the name
|
| 678 |
+
of the file from which it will be loaded (eg. "foo/bar.so", or
|
| 679 |
+
"foo\bar.pyd").
|
| 680 |
+
"""
|
| 681 |
+
from distutils.sysconfig import get_config_var
|
| 682 |
+
ext_path = ext_name.split('.')
|
| 683 |
+
ext_suffix = get_config_var('EXT_SUFFIX')
|
| 684 |
+
return os.path.join(*ext_path) + ext_suffix
|
| 685 |
+
|
| 686 |
+
def get_export_symbols(self, ext):
|
| 687 |
+
"""Return the list of symbols that a shared extension has to
|
| 688 |
+
export. This either uses 'ext.export_symbols' or, if it's not
|
| 689 |
+
provided, "PyInit_" + module_name. Only relevant on Windows, where
|
| 690 |
+
the .pyd file (DLL) must export the module "PyInit_" function.
|
| 691 |
+
"""
|
| 692 |
+
suffix = '_' + ext.name.split('.')[-1]
|
| 693 |
+
try:
|
| 694 |
+
# Unicode module name support as defined in PEP-489
|
| 695 |
+
# https://peps.python.org/pep-0489/#export-hook-name
|
| 696 |
+
suffix.encode('ascii')
|
| 697 |
+
except UnicodeEncodeError:
|
| 698 |
+
suffix = 'U' + suffix.encode('punycode').replace(b'-', b'_').decode('ascii')
|
| 699 |
+
|
| 700 |
+
initfunc_name = "PyInit" + suffix
|
| 701 |
+
if initfunc_name not in ext.export_symbols:
|
| 702 |
+
ext.export_symbols.append(initfunc_name)
|
| 703 |
+
return ext.export_symbols
|
| 704 |
+
|
| 705 |
+
def get_libraries(self, ext):
|
| 706 |
+
"""Return the list of libraries to link against when building a
|
| 707 |
+
shared extension. On most platforms, this is just 'ext.libraries';
|
| 708 |
+
on Windows, we add the Python library (eg. python20.dll).
|
| 709 |
+
"""
|
| 710 |
+
# The python library is always needed on Windows. For MSVC, this
|
| 711 |
+
# is redundant, since the library is mentioned in a pragma in
|
| 712 |
+
# pyconfig.h that MSVC groks. The other Windows compilers all seem
|
| 713 |
+
# to need it mentioned explicitly, though, so that's what we do.
|
| 714 |
+
# Append '_d' to the python import library on debug builds.
|
| 715 |
+
if sys.platform == "win32":
|
| 716 |
+
from distutils._msvccompiler import MSVCCompiler
|
| 717 |
+
if not isinstance(self.compiler, MSVCCompiler):
|
| 718 |
+
template = "python%d%d"
|
| 719 |
+
if self.debug:
|
| 720 |
+
template = template + '_d'
|
| 721 |
+
pythonlib = (template %
|
| 722 |
+
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
|
| 723 |
+
# don't extend ext.libraries, it may be shared with other
|
| 724 |
+
# extensions, it is a reference to the original list
|
| 725 |
+
return ext.libraries + [pythonlib]
|
| 726 |
+
else:
|
| 727 |
+
# On Android only the main executable and LD_PRELOADs are considered
|
| 728 |
+
# to be RTLD_GLOBAL, all the dependencies of the main executable
|
| 729 |
+
# remain RTLD_LOCAL and so the shared libraries must be linked with
|
| 730 |
+
# libpython when python is built with a shared python library (issue
|
| 731 |
+
# bpo-21536).
|
| 732 |
+
# On Cygwin (and if required, other POSIX-like platforms based on
|
| 733 |
+
# Windows like MinGW) it is simply necessary that all symbols in
|
| 734 |
+
# shared libraries are resolved at link time.
|
| 735 |
+
from distutils.sysconfig import get_config_var
|
| 736 |
+
link_libpython = False
|
| 737 |
+
if get_config_var('Py_ENABLE_SHARED'):
|
| 738 |
+
# A native build on an Android device or on Cygwin
|
| 739 |
+
if hasattr(sys, 'getandroidapilevel'):
|
| 740 |
+
link_libpython = True
|
| 741 |
+
elif sys.platform == 'cygwin':
|
| 742 |
+
link_libpython = True
|
| 743 |
+
elif '_PYTHON_HOST_PLATFORM' in os.environ:
|
| 744 |
+
# We are cross-compiling for one of the relevant platforms
|
| 745 |
+
if get_config_var('ANDROID_API_LEVEL') != 0:
|
| 746 |
+
link_libpython = True
|
| 747 |
+
elif get_config_var('MACHDEP') == 'cygwin':
|
| 748 |
+
link_libpython = True
|
| 749 |
+
|
| 750 |
+
if link_libpython:
|
| 751 |
+
ldversion = get_config_var('LDVERSION')
|
| 752 |
+
return ext.libraries + ['python' + ldversion]
|
| 753 |
+
|
| 754 |
+
return ext.libraries
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build_py.py
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.build_py
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'build_py' command."""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import importlib.util
|
| 7 |
+
import sys
|
| 8 |
+
import glob
|
| 9 |
+
|
| 10 |
+
from distutils.core import Command
|
| 11 |
+
from distutils.errors import *
|
| 12 |
+
from distutils.util import convert_path, Mixin2to3
|
| 13 |
+
from distutils import log
|
| 14 |
+
|
| 15 |
+
class build_py (Command):
|
| 16 |
+
|
| 17 |
+
description = "\"build\" pure Python modules (copy to build directory)"
|
| 18 |
+
|
| 19 |
+
user_options = [
|
| 20 |
+
('build-lib=', 'd', "directory to \"build\" (copy) to"),
|
| 21 |
+
('compile', 'c', "compile .py to .pyc"),
|
| 22 |
+
('no-compile', None, "don't compile .py files [default]"),
|
| 23 |
+
('optimize=', 'O',
|
| 24 |
+
"also compile with optimization: -O1 for \"python -O\", "
|
| 25 |
+
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
|
| 26 |
+
('force', 'f', "forcibly build everything (ignore file timestamps)"),
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
boolean_options = ['compile', 'force']
|
| 30 |
+
negative_opt = {'no-compile' : 'compile'}
|
| 31 |
+
|
| 32 |
+
def initialize_options(self):
|
| 33 |
+
self.build_lib = None
|
| 34 |
+
self.py_modules = None
|
| 35 |
+
self.package = None
|
| 36 |
+
self.package_data = None
|
| 37 |
+
self.package_dir = None
|
| 38 |
+
self.compile = 0
|
| 39 |
+
self.optimize = 0
|
| 40 |
+
self.force = None
|
| 41 |
+
|
| 42 |
+
def finalize_options(self):
|
| 43 |
+
self.set_undefined_options('build',
|
| 44 |
+
('build_lib', 'build_lib'),
|
| 45 |
+
('force', 'force'))
|
| 46 |
+
|
| 47 |
+
# Get the distribution options that are aliases for build_py
|
| 48 |
+
# options -- list of packages and list of modules.
|
| 49 |
+
self.packages = self.distribution.packages
|
| 50 |
+
self.py_modules = self.distribution.py_modules
|
| 51 |
+
self.package_data = self.distribution.package_data
|
| 52 |
+
self.package_dir = {}
|
| 53 |
+
if self.distribution.package_dir:
|
| 54 |
+
for name, path in self.distribution.package_dir.items():
|
| 55 |
+
self.package_dir[name] = convert_path(path)
|
| 56 |
+
self.data_files = self.get_data_files()
|
| 57 |
+
|
| 58 |
+
# Ick, copied straight from install_lib.py (fancy_getopt needs a
|
| 59 |
+
# type system! Hell, *everything* needs a type system!!!)
|
| 60 |
+
if not isinstance(self.optimize, int):
|
| 61 |
+
try:
|
| 62 |
+
self.optimize = int(self.optimize)
|
| 63 |
+
assert 0 <= self.optimize <= 2
|
| 64 |
+
except (ValueError, AssertionError):
|
| 65 |
+
raise DistutilsOptionError("optimize must be 0, 1, or 2")
|
| 66 |
+
|
| 67 |
+
def run(self):
|
| 68 |
+
# XXX copy_file by default preserves atime and mtime. IMHO this is
|
| 69 |
+
# the right thing to do, but perhaps it should be an option -- in
|
| 70 |
+
# particular, a site administrator might want installed files to
|
| 71 |
+
# reflect the time of installation rather than the last
|
| 72 |
+
# modification time before the installed release.
|
| 73 |
+
|
| 74 |
+
# XXX copy_file by default preserves mode, which appears to be the
|
| 75 |
+
# wrong thing to do: if a file is read-only in the working
|
| 76 |
+
# directory, we want it to be installed read/write so that the next
|
| 77 |
+
# installation of the same module distribution can overwrite it
|
| 78 |
+
# without problems. (This might be a Unix-specific issue.) Thus
|
| 79 |
+
# we turn off 'preserve_mode' when copying to the build directory,
|
| 80 |
+
# since the build directory is supposed to be exactly what the
|
| 81 |
+
# installation will look like (ie. we preserve mode when
|
| 82 |
+
# installing).
|
| 83 |
+
|
| 84 |
+
# Two options control which modules will be installed: 'packages'
|
| 85 |
+
# and 'py_modules'. The former lets us work with whole packages, not
|
| 86 |
+
# specifying individual modules at all; the latter is for
|
| 87 |
+
# specifying modules one-at-a-time.
|
| 88 |
+
|
| 89 |
+
if self.py_modules:
|
| 90 |
+
self.build_modules()
|
| 91 |
+
if self.packages:
|
| 92 |
+
self.build_packages()
|
| 93 |
+
self.build_package_data()
|
| 94 |
+
|
| 95 |
+
self.byte_compile(self.get_outputs(include_bytecode=0))
|
| 96 |
+
|
| 97 |
+
def get_data_files(self):
|
| 98 |
+
"""Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
|
| 99 |
+
data = []
|
| 100 |
+
if not self.packages:
|
| 101 |
+
return data
|
| 102 |
+
for package in self.packages:
|
| 103 |
+
# Locate package source directory
|
| 104 |
+
src_dir = self.get_package_dir(package)
|
| 105 |
+
|
| 106 |
+
# Compute package build directory
|
| 107 |
+
build_dir = os.path.join(*([self.build_lib] + package.split('.')))
|
| 108 |
+
|
| 109 |
+
# Length of path to strip from found files
|
| 110 |
+
plen = 0
|
| 111 |
+
if src_dir:
|
| 112 |
+
plen = len(src_dir)+1
|
| 113 |
+
|
| 114 |
+
# Strip directory from globbed filenames
|
| 115 |
+
filenames = [
|
| 116 |
+
file[plen:] for file in self.find_data_files(package, src_dir)
|
| 117 |
+
]
|
| 118 |
+
data.append((package, src_dir, build_dir, filenames))
|
| 119 |
+
return data
|
| 120 |
+
|
| 121 |
+
def find_data_files(self, package, src_dir):
|
| 122 |
+
"""Return filenames for package's data files in 'src_dir'"""
|
| 123 |
+
globs = (self.package_data.get('', [])
|
| 124 |
+
+ self.package_data.get(package, []))
|
| 125 |
+
files = []
|
| 126 |
+
for pattern in globs:
|
| 127 |
+
# Each pattern has to be converted to a platform-specific path
|
| 128 |
+
filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern)))
|
| 129 |
+
# Files that match more than one pattern are only added once
|
| 130 |
+
files.extend([fn for fn in filelist if fn not in files
|
| 131 |
+
and os.path.isfile(fn)])
|
| 132 |
+
return files
|
| 133 |
+
|
| 134 |
+
def build_package_data(self):
|
| 135 |
+
"""Copy data files into build directory"""
|
| 136 |
+
lastdir = None
|
| 137 |
+
for package, src_dir, build_dir, filenames in self.data_files:
|
| 138 |
+
for filename in filenames:
|
| 139 |
+
target = os.path.join(build_dir, filename)
|
| 140 |
+
self.mkpath(os.path.dirname(target))
|
| 141 |
+
self.copy_file(os.path.join(src_dir, filename), target,
|
| 142 |
+
preserve_mode=False)
|
| 143 |
+
|
| 144 |
+
def get_package_dir(self, package):
|
| 145 |
+
"""Return the directory, relative to the top of the source
|
| 146 |
+
distribution, where package 'package' should be found
|
| 147 |
+
(at least according to the 'package_dir' option, if any)."""
|
| 148 |
+
path = package.split('.')
|
| 149 |
+
|
| 150 |
+
if not self.package_dir:
|
| 151 |
+
if path:
|
| 152 |
+
return os.path.join(*path)
|
| 153 |
+
else:
|
| 154 |
+
return ''
|
| 155 |
+
else:
|
| 156 |
+
tail = []
|
| 157 |
+
while path:
|
| 158 |
+
try:
|
| 159 |
+
pdir = self.package_dir['.'.join(path)]
|
| 160 |
+
except KeyError:
|
| 161 |
+
tail.insert(0, path[-1])
|
| 162 |
+
del path[-1]
|
| 163 |
+
else:
|
| 164 |
+
tail.insert(0, pdir)
|
| 165 |
+
return os.path.join(*tail)
|
| 166 |
+
else:
|
| 167 |
+
# Oops, got all the way through 'path' without finding a
|
| 168 |
+
# match in package_dir. If package_dir defines a directory
|
| 169 |
+
# for the root (nameless) package, then fallback on it;
|
| 170 |
+
# otherwise, we might as well have not consulted
|
| 171 |
+
# package_dir at all, as we just use the directory implied
|
| 172 |
+
# by 'tail' (which should be the same as the original value
|
| 173 |
+
# of 'path' at this point).
|
| 174 |
+
pdir = self.package_dir.get('')
|
| 175 |
+
if pdir is not None:
|
| 176 |
+
tail.insert(0, pdir)
|
| 177 |
+
|
| 178 |
+
if tail:
|
| 179 |
+
return os.path.join(*tail)
|
| 180 |
+
else:
|
| 181 |
+
return ''
|
| 182 |
+
|
| 183 |
+
def check_package(self, package, package_dir):
|
| 184 |
+
# Empty dir name means current directory, which we can probably
|
| 185 |
+
# assume exists. Also, os.path.exists and isdir don't know about
|
| 186 |
+
# my "empty string means current dir" convention, so we have to
|
| 187 |
+
# circumvent them.
|
| 188 |
+
if package_dir != "":
|
| 189 |
+
if not os.path.exists(package_dir):
|
| 190 |
+
raise DistutilsFileError(
|
| 191 |
+
"package directory '%s' does not exist" % package_dir)
|
| 192 |
+
if not os.path.isdir(package_dir):
|
| 193 |
+
raise DistutilsFileError(
|
| 194 |
+
"supposed package directory '%s' exists, "
|
| 195 |
+
"but is not a directory" % package_dir)
|
| 196 |
+
|
| 197 |
+
# Require __init__.py for all but the "root package"
|
| 198 |
+
if package:
|
| 199 |
+
init_py = os.path.join(package_dir, "__init__.py")
|
| 200 |
+
if os.path.isfile(init_py):
|
| 201 |
+
return init_py
|
| 202 |
+
else:
|
| 203 |
+
log.warn(("package init file '%s' not found " +
|
| 204 |
+
"(or not a regular file)"), init_py)
|
| 205 |
+
|
| 206 |
+
# Either not in a package at all (__init__.py not expected), or
|
| 207 |
+
# __init__.py doesn't exist -- so don't return the filename.
|
| 208 |
+
return None
|
| 209 |
+
|
| 210 |
+
def check_module(self, module, module_file):
|
| 211 |
+
if not os.path.isfile(module_file):
|
| 212 |
+
log.warn("file %s (for module %s) not found", module_file, module)
|
| 213 |
+
return False
|
| 214 |
+
else:
|
| 215 |
+
return True
|
| 216 |
+
|
| 217 |
+
def find_package_modules(self, package, package_dir):
|
| 218 |
+
self.check_package(package, package_dir)
|
| 219 |
+
module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
|
| 220 |
+
modules = []
|
| 221 |
+
setup_script = os.path.abspath(self.distribution.script_name)
|
| 222 |
+
|
| 223 |
+
for f in module_files:
|
| 224 |
+
abs_f = os.path.abspath(f)
|
| 225 |
+
if abs_f != setup_script:
|
| 226 |
+
module = os.path.splitext(os.path.basename(f))[0]
|
| 227 |
+
modules.append((package, module, f))
|
| 228 |
+
else:
|
| 229 |
+
self.debug_print("excluding %s" % setup_script)
|
| 230 |
+
return modules
|
| 231 |
+
|
| 232 |
+
def find_modules(self):
|
| 233 |
+
"""Finds individually-specified Python modules, ie. those listed by
|
| 234 |
+
module name in 'self.py_modules'. Returns a list of tuples (package,
|
| 235 |
+
module_base, filename): 'package' is a tuple of the path through
|
| 236 |
+
package-space to the module; 'module_base' is the bare (no
|
| 237 |
+
packages, no dots) module name, and 'filename' is the path to the
|
| 238 |
+
".py" file (relative to the distribution root) that implements the
|
| 239 |
+
module.
|
| 240 |
+
"""
|
| 241 |
+
# Map package names to tuples of useful info about the package:
|
| 242 |
+
# (package_dir, checked)
|
| 243 |
+
# package_dir - the directory where we'll find source files for
|
| 244 |
+
# this package
|
| 245 |
+
# checked - true if we have checked that the package directory
|
| 246 |
+
# is valid (exists, contains __init__.py, ... ?)
|
| 247 |
+
packages = {}
|
| 248 |
+
|
| 249 |
+
# List of (package, module, filename) tuples to return
|
| 250 |
+
modules = []
|
| 251 |
+
|
| 252 |
+
# We treat modules-in-packages almost the same as toplevel modules,
|
| 253 |
+
# just the "package" for a toplevel is empty (either an empty
|
| 254 |
+
# string or empty list, depending on context). Differences:
|
| 255 |
+
# - don't check for __init__.py in directory for empty package
|
| 256 |
+
for module in self.py_modules:
|
| 257 |
+
path = module.split('.')
|
| 258 |
+
package = '.'.join(path[0:-1])
|
| 259 |
+
module_base = path[-1]
|
| 260 |
+
|
| 261 |
+
try:
|
| 262 |
+
(package_dir, checked) = packages[package]
|
| 263 |
+
except KeyError:
|
| 264 |
+
package_dir = self.get_package_dir(package)
|
| 265 |
+
checked = 0
|
| 266 |
+
|
| 267 |
+
if not checked:
|
| 268 |
+
init_py = self.check_package(package, package_dir)
|
| 269 |
+
packages[package] = (package_dir, 1)
|
| 270 |
+
if init_py:
|
| 271 |
+
modules.append((package, "__init__", init_py))
|
| 272 |
+
|
| 273 |
+
# XXX perhaps we should also check for just .pyc files
|
| 274 |
+
# (so greedy closed-source bastards can distribute Python
|
| 275 |
+
# modules too)
|
| 276 |
+
module_file = os.path.join(package_dir, module_base + ".py")
|
| 277 |
+
if not self.check_module(module, module_file):
|
| 278 |
+
continue
|
| 279 |
+
|
| 280 |
+
modules.append((package, module_base, module_file))
|
| 281 |
+
|
| 282 |
+
return modules
|
| 283 |
+
|
| 284 |
+
def find_all_modules(self):
|
| 285 |
+
"""Compute the list of all modules that will be built, whether
|
| 286 |
+
they are specified one-module-at-a-time ('self.py_modules') or
|
| 287 |
+
by whole packages ('self.packages'). Return a list of tuples
|
| 288 |
+
(package, module, module_file), just like 'find_modules()' and
|
| 289 |
+
'find_package_modules()' do."""
|
| 290 |
+
modules = []
|
| 291 |
+
if self.py_modules:
|
| 292 |
+
modules.extend(self.find_modules())
|
| 293 |
+
if self.packages:
|
| 294 |
+
for package in self.packages:
|
| 295 |
+
package_dir = self.get_package_dir(package)
|
| 296 |
+
m = self.find_package_modules(package, package_dir)
|
| 297 |
+
modules.extend(m)
|
| 298 |
+
return modules
|
| 299 |
+
|
| 300 |
+
def get_source_files(self):
|
| 301 |
+
return [module[-1] for module in self.find_all_modules()]
|
| 302 |
+
|
| 303 |
+
def get_module_outfile(self, build_dir, package, module):
|
| 304 |
+
outfile_path = [build_dir] + list(package) + [module + ".py"]
|
| 305 |
+
return os.path.join(*outfile_path)
|
| 306 |
+
|
| 307 |
+
def get_outputs(self, include_bytecode=1):
|
| 308 |
+
modules = self.find_all_modules()
|
| 309 |
+
outputs = []
|
| 310 |
+
for (package, module, module_file) in modules:
|
| 311 |
+
package = package.split('.')
|
| 312 |
+
filename = self.get_module_outfile(self.build_lib, package, module)
|
| 313 |
+
outputs.append(filename)
|
| 314 |
+
if include_bytecode:
|
| 315 |
+
if self.compile:
|
| 316 |
+
outputs.append(importlib.util.cache_from_source(
|
| 317 |
+
filename, optimization=''))
|
| 318 |
+
if self.optimize > 0:
|
| 319 |
+
outputs.append(importlib.util.cache_from_source(
|
| 320 |
+
filename, optimization=self.optimize))
|
| 321 |
+
|
| 322 |
+
outputs += [
|
| 323 |
+
os.path.join(build_dir, filename)
|
| 324 |
+
for package, src_dir, build_dir, filenames in self.data_files
|
| 325 |
+
for filename in filenames
|
| 326 |
+
]
|
| 327 |
+
|
| 328 |
+
return outputs
|
| 329 |
+
|
| 330 |
+
def build_module(self, module, module_file, package):
|
| 331 |
+
if isinstance(package, str):
|
| 332 |
+
package = package.split('.')
|
| 333 |
+
elif not isinstance(package, (list, tuple)):
|
| 334 |
+
raise TypeError(
|
| 335 |
+
"'package' must be a string (dot-separated), list, or tuple")
|
| 336 |
+
|
| 337 |
+
# Now put the module source file into the "build" area -- this is
|
| 338 |
+
# easy, we just copy it somewhere under self.build_lib (the build
|
| 339 |
+
# directory for Python source).
|
| 340 |
+
outfile = self.get_module_outfile(self.build_lib, package, module)
|
| 341 |
+
dir = os.path.dirname(outfile)
|
| 342 |
+
self.mkpath(dir)
|
| 343 |
+
return self.copy_file(module_file, outfile, preserve_mode=0)
|
| 344 |
+
|
| 345 |
+
def build_modules(self):
|
| 346 |
+
modules = self.find_modules()
|
| 347 |
+
for (package, module, module_file) in modules:
|
| 348 |
+
# Now "build" the module -- ie. copy the source file to
|
| 349 |
+
# self.build_lib (the build directory for Python source).
|
| 350 |
+
# (Actually, it gets copied to the directory for this package
|
| 351 |
+
# under self.build_lib.)
|
| 352 |
+
self.build_module(module, module_file, package)
|
| 353 |
+
|
| 354 |
+
def build_packages(self):
|
| 355 |
+
for package in self.packages:
|
| 356 |
+
# Get list of (package, module, module_file) tuples based on
|
| 357 |
+
# scanning the package directory. 'package' is only included
|
| 358 |
+
# in the tuple so that 'find_modules()' and
|
| 359 |
+
# 'find_package_tuples()' have a consistent interface; it's
|
| 360 |
+
# ignored here (apart from a sanity check). Also, 'module' is
|
| 361 |
+
# the *unqualified* module name (ie. no dots, no package -- we
|
| 362 |
+
# already know its package!), and 'module_file' is the path to
|
| 363 |
+
# the .py file, relative to the current directory
|
| 364 |
+
# (ie. including 'package_dir').
|
| 365 |
+
package_dir = self.get_package_dir(package)
|
| 366 |
+
modules = self.find_package_modules(package, package_dir)
|
| 367 |
+
|
| 368 |
+
# Now loop over the modules we found, "building" each one (just
|
| 369 |
+
# copy it to self.build_lib).
|
| 370 |
+
for (package_, module, module_file) in modules:
|
| 371 |
+
assert package == package_
|
| 372 |
+
self.build_module(module, module_file, package)
|
| 373 |
+
|
| 374 |
+
def byte_compile(self, files):
|
| 375 |
+
if sys.dont_write_bytecode:
|
| 376 |
+
self.warn('byte-compiling is disabled, skipping.')
|
| 377 |
+
return
|
| 378 |
+
|
| 379 |
+
from distutils.util import byte_compile
|
| 380 |
+
prefix = self.build_lib
|
| 381 |
+
if prefix[-1] != os.sep:
|
| 382 |
+
prefix = prefix + os.sep
|
| 383 |
+
|
| 384 |
+
# XXX this code is essentially the same as the 'byte_compile()
|
| 385 |
+
# method of the "install_lib" command, except for the determination
|
| 386 |
+
# of the 'prefix' string. Hmmm.
|
| 387 |
+
if self.compile:
|
| 388 |
+
byte_compile(files, optimize=0,
|
| 389 |
+
force=self.force, prefix=prefix, dry_run=self.dry_run)
|
| 390 |
+
if self.optimize > 0:
|
| 391 |
+
byte_compile(files, optimize=self.optimize,
|
| 392 |
+
force=self.force, prefix=prefix, dry_run=self.dry_run)
|
| 393 |
+
|
| 394 |
+
class build_py_2to3(build_py, Mixin2to3):
|
| 395 |
+
def run(self):
|
| 396 |
+
self.updated_files = []
|
| 397 |
+
|
| 398 |
+
# Base class code
|
| 399 |
+
if self.py_modules:
|
| 400 |
+
self.build_modules()
|
| 401 |
+
if self.packages:
|
| 402 |
+
self.build_packages()
|
| 403 |
+
self.build_package_data()
|
| 404 |
+
|
| 405 |
+
# 2to3
|
| 406 |
+
self.run_2to3(self.updated_files)
|
| 407 |
+
|
| 408 |
+
# Remaining base class code
|
| 409 |
+
self.byte_compile(self.get_outputs(include_bytecode=0))
|
| 410 |
+
|
| 411 |
+
def build_module(self, module, module_file, package):
|
| 412 |
+
res = build_py.build_module(self, module, module_file, package)
|
| 413 |
+
if res[1]:
|
| 414 |
+
# file was copied
|
| 415 |
+
self.updated_files.append(res[0])
|
| 416 |
+
return res
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/build_scripts.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.build_scripts
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'build_scripts' command."""
|
| 4 |
+
|
| 5 |
+
import os, re
|
| 6 |
+
from stat import ST_MODE
|
| 7 |
+
from distutils import sysconfig
|
| 8 |
+
from distutils.core import Command
|
| 9 |
+
from distutils.dep_util import newer
|
| 10 |
+
from distutils.util import convert_path, Mixin2to3
|
| 11 |
+
from distutils import log
|
| 12 |
+
import tokenize
|
| 13 |
+
|
| 14 |
+
# check if Python is called on the first line with this expression
|
| 15 |
+
first_line_re = re.compile(b'^#!.*python[0-9.]*([ \t].*)?$')
|
| 16 |
+
|
| 17 |
+
class build_scripts(Command):
|
| 18 |
+
|
| 19 |
+
description = "\"build\" scripts (copy and fixup #! line)"
|
| 20 |
+
|
| 21 |
+
user_options = [
|
| 22 |
+
('build-dir=', 'd', "directory to \"build\" (copy) to"),
|
| 23 |
+
('force', 'f', "forcibly build everything (ignore file timestamps"),
|
| 24 |
+
('executable=', 'e', "specify final destination interpreter path"),
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
boolean_options = ['force']
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def initialize_options(self):
|
| 31 |
+
self.build_dir = None
|
| 32 |
+
self.scripts = None
|
| 33 |
+
self.force = None
|
| 34 |
+
self.executable = None
|
| 35 |
+
self.outfiles = None
|
| 36 |
+
|
| 37 |
+
def finalize_options(self):
|
| 38 |
+
self.set_undefined_options('build',
|
| 39 |
+
('build_scripts', 'build_dir'),
|
| 40 |
+
('force', 'force'),
|
| 41 |
+
('executable', 'executable'))
|
| 42 |
+
self.scripts = self.distribution.scripts
|
| 43 |
+
|
| 44 |
+
def get_source_files(self):
|
| 45 |
+
return self.scripts
|
| 46 |
+
|
| 47 |
+
def run(self):
|
| 48 |
+
if not self.scripts:
|
| 49 |
+
return
|
| 50 |
+
self.copy_scripts()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def copy_scripts(self):
|
| 54 |
+
r"""Copy each script listed in 'self.scripts'; if it's marked as a
|
| 55 |
+
Python script in the Unix way (first line matches 'first_line_re',
|
| 56 |
+
ie. starts with "\#!" and contains "python"), then adjust the first
|
| 57 |
+
line to refer to the current Python interpreter as we copy.
|
| 58 |
+
"""
|
| 59 |
+
self.mkpath(self.build_dir)
|
| 60 |
+
outfiles = []
|
| 61 |
+
updated_files = []
|
| 62 |
+
for script in self.scripts:
|
| 63 |
+
adjust = False
|
| 64 |
+
script = convert_path(script)
|
| 65 |
+
outfile = os.path.join(self.build_dir, os.path.basename(script))
|
| 66 |
+
outfiles.append(outfile)
|
| 67 |
+
|
| 68 |
+
if not self.force and not newer(script, outfile):
|
| 69 |
+
log.debug("not copying %s (up-to-date)", script)
|
| 70 |
+
continue
|
| 71 |
+
|
| 72 |
+
# Always open the file, but ignore failures in dry-run mode --
|
| 73 |
+
# that way, we'll get accurate feedback if we can read the
|
| 74 |
+
# script.
|
| 75 |
+
try:
|
| 76 |
+
f = open(script, "rb")
|
| 77 |
+
except OSError:
|
| 78 |
+
if not self.dry_run:
|
| 79 |
+
raise
|
| 80 |
+
f = None
|
| 81 |
+
else:
|
| 82 |
+
encoding, lines = tokenize.detect_encoding(f.readline)
|
| 83 |
+
f.seek(0)
|
| 84 |
+
first_line = f.readline()
|
| 85 |
+
if not first_line:
|
| 86 |
+
self.warn("%s is an empty file (skipping)" % script)
|
| 87 |
+
continue
|
| 88 |
+
|
| 89 |
+
match = first_line_re.match(first_line)
|
| 90 |
+
if match:
|
| 91 |
+
adjust = True
|
| 92 |
+
post_interp = match.group(1) or b''
|
| 93 |
+
|
| 94 |
+
if adjust:
|
| 95 |
+
log.info("copying and adjusting %s -> %s", script,
|
| 96 |
+
self.build_dir)
|
| 97 |
+
updated_files.append(outfile)
|
| 98 |
+
if not self.dry_run:
|
| 99 |
+
if not sysconfig.python_build:
|
| 100 |
+
executable = self.executable
|
| 101 |
+
else:
|
| 102 |
+
executable = os.path.join(
|
| 103 |
+
sysconfig.get_config_var("BINDIR"),
|
| 104 |
+
"python%s%s" % (sysconfig.get_config_var("VERSION"),
|
| 105 |
+
sysconfig.get_config_var("EXE")))
|
| 106 |
+
executable = os.fsencode(executable)
|
| 107 |
+
shebang = b"#!" + executable + post_interp + b"\n"
|
| 108 |
+
# Python parser starts to read a script using UTF-8 until
|
| 109 |
+
# it gets a #coding:xxx cookie. The shebang has to be the
|
| 110 |
+
# first line of a file, the #coding:xxx cookie cannot be
|
| 111 |
+
# written before. So the shebang has to be decodable from
|
| 112 |
+
# UTF-8.
|
| 113 |
+
try:
|
| 114 |
+
shebang.decode('utf-8')
|
| 115 |
+
except UnicodeDecodeError:
|
| 116 |
+
raise ValueError(
|
| 117 |
+
"The shebang ({!r}) is not decodable "
|
| 118 |
+
"from utf-8".format(shebang))
|
| 119 |
+
# If the script is encoded to a custom encoding (use a
|
| 120 |
+
# #coding:xxx cookie), the shebang has to be decodable from
|
| 121 |
+
# the script encoding too.
|
| 122 |
+
try:
|
| 123 |
+
shebang.decode(encoding)
|
| 124 |
+
except UnicodeDecodeError:
|
| 125 |
+
raise ValueError(
|
| 126 |
+
"The shebang ({!r}) is not decodable "
|
| 127 |
+
"from the script encoding ({})"
|
| 128 |
+
.format(shebang, encoding))
|
| 129 |
+
with open(outfile, "wb") as outf:
|
| 130 |
+
outf.write(shebang)
|
| 131 |
+
outf.writelines(f.readlines())
|
| 132 |
+
if f:
|
| 133 |
+
f.close()
|
| 134 |
+
else:
|
| 135 |
+
if f:
|
| 136 |
+
f.close()
|
| 137 |
+
updated_files.append(outfile)
|
| 138 |
+
self.copy_file(script, outfile)
|
| 139 |
+
|
| 140 |
+
if os.name == 'posix':
|
| 141 |
+
for file in outfiles:
|
| 142 |
+
if self.dry_run:
|
| 143 |
+
log.info("changing mode of %s", file)
|
| 144 |
+
else:
|
| 145 |
+
oldmode = os.stat(file)[ST_MODE] & 0o7777
|
| 146 |
+
newmode = (oldmode | 0o555) & 0o7777
|
| 147 |
+
if newmode != oldmode:
|
| 148 |
+
log.info("changing mode of %s from %o to %o",
|
| 149 |
+
file, oldmode, newmode)
|
| 150 |
+
os.chmod(file, newmode)
|
| 151 |
+
# XXX should we modify self.outfiles?
|
| 152 |
+
return outfiles, updated_files
|
| 153 |
+
|
| 154 |
+
class build_scripts_2to3(build_scripts, Mixin2to3):
|
| 155 |
+
|
| 156 |
+
def copy_scripts(self):
|
| 157 |
+
outfiles, updated_files = build_scripts.copy_scripts(self)
|
| 158 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
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.check
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'check' command.
|
| 4 |
+
"""
|
| 5 |
+
from distutils.core import Command
|
| 6 |
+
from distutils.errors import DistutilsSetupError
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
# docutils is installed
|
| 10 |
+
from docutils.utils import Reporter
|
| 11 |
+
from docutils.parsers.rst import Parser
|
| 12 |
+
from docutils import frontend
|
| 13 |
+
from docutils import nodes
|
| 14 |
+
|
| 15 |
+
class SilentReporter(Reporter):
|
| 16 |
+
|
| 17 |
+
def __init__(self, source, report_level, halt_level, stream=None,
|
| 18 |
+
debug=0, encoding='ascii', error_handler='replace'):
|
| 19 |
+
self.messages = []
|
| 20 |
+
Reporter.__init__(self, source, report_level, halt_level, stream,
|
| 21 |
+
debug, encoding, error_handler)
|
| 22 |
+
|
| 23 |
+
def system_message(self, level, message, *children, **kwargs):
|
| 24 |
+
self.messages.append((level, message, children, kwargs))
|
| 25 |
+
return nodes.system_message(message, level=level,
|
| 26 |
+
type=self.levels[level],
|
| 27 |
+
*children, **kwargs)
|
| 28 |
+
|
| 29 |
+
HAS_DOCUTILS = True
|
| 30 |
+
except Exception:
|
| 31 |
+
# Catch all exceptions because exceptions besides ImportError probably
|
| 32 |
+
# indicate that docutils is not ported to Py3k.
|
| 33 |
+
HAS_DOCUTILS = False
|
| 34 |
+
|
| 35 |
+
class check(Command):
|
| 36 |
+
"""This command checks the meta-data of the package.
|
| 37 |
+
"""
|
| 38 |
+
description = ("perform some checks on the package")
|
| 39 |
+
user_options = [('metadata', 'm', 'Verify meta-data'),
|
| 40 |
+
('restructuredtext', 'r',
|
| 41 |
+
('Checks if long string meta-data syntax '
|
| 42 |
+
'are reStructuredText-compliant')),
|
| 43 |
+
('strict', 's',
|
| 44 |
+
'Will exit with an error if a check fails')]
|
| 45 |
+
|
| 46 |
+
boolean_options = ['metadata', 'restructuredtext', 'strict']
|
| 47 |
+
|
| 48 |
+
def initialize_options(self):
|
| 49 |
+
"""Sets default values for options."""
|
| 50 |
+
self.restructuredtext = 0
|
| 51 |
+
self.metadata = 1
|
| 52 |
+
self.strict = 0
|
| 53 |
+
self._warnings = 0
|
| 54 |
+
|
| 55 |
+
def finalize_options(self):
|
| 56 |
+
pass
|
| 57 |
+
|
| 58 |
+
def warn(self, msg):
|
| 59 |
+
"""Counts the number of warnings that occurs."""
|
| 60 |
+
self._warnings += 1
|
| 61 |
+
return Command.warn(self, msg)
|
| 62 |
+
|
| 63 |
+
def run(self):
|
| 64 |
+
"""Runs the command."""
|
| 65 |
+
# perform the various tests
|
| 66 |
+
if self.metadata:
|
| 67 |
+
self.check_metadata()
|
| 68 |
+
if self.restructuredtext:
|
| 69 |
+
if HAS_DOCUTILS:
|
| 70 |
+
self.check_restructuredtext()
|
| 71 |
+
elif self.strict:
|
| 72 |
+
raise DistutilsSetupError('The docutils package is needed.')
|
| 73 |
+
|
| 74 |
+
# let's raise an error in strict mode, if we have at least
|
| 75 |
+
# one warning
|
| 76 |
+
if self.strict and self._warnings > 0:
|
| 77 |
+
raise DistutilsSetupError('Please correct your package.')
|
| 78 |
+
|
| 79 |
+
def check_metadata(self):
|
| 80 |
+
"""Ensures that all required elements of meta-data are supplied.
|
| 81 |
+
|
| 82 |
+
Required fields:
|
| 83 |
+
name, version, URL
|
| 84 |
+
|
| 85 |
+
Recommended fields:
|
| 86 |
+
(author and author_email) or (maintainer and maintainer_email)
|
| 87 |
+
|
| 88 |
+
Warns if any are missing.
|
| 89 |
+
"""
|
| 90 |
+
metadata = self.distribution.metadata
|
| 91 |
+
|
| 92 |
+
missing = []
|
| 93 |
+
for attr in ('name', 'version', 'url'):
|
| 94 |
+
if not (hasattr(metadata, attr) and getattr(metadata, attr)):
|
| 95 |
+
missing.append(attr)
|
| 96 |
+
|
| 97 |
+
if missing:
|
| 98 |
+
self.warn("missing required meta-data: %s" % ', '.join(missing))
|
| 99 |
+
if metadata.author:
|
| 100 |
+
if not metadata.author_email:
|
| 101 |
+
self.warn("missing meta-data: if 'author' supplied, " +
|
| 102 |
+
"'author_email' should be supplied too")
|
| 103 |
+
elif metadata.maintainer:
|
| 104 |
+
if not metadata.maintainer_email:
|
| 105 |
+
self.warn("missing meta-data: if 'maintainer' supplied, " +
|
| 106 |
+
"'maintainer_email' should be supplied too")
|
| 107 |
+
else:
|
| 108 |
+
self.warn("missing meta-data: either (author and author_email) " +
|
| 109 |
+
"or (maintainer and maintainer_email) " +
|
| 110 |
+
"should be supplied")
|
| 111 |
+
|
| 112 |
+
def check_restructuredtext(self):
|
| 113 |
+
"""Checks if the long string fields are reST-compliant."""
|
| 114 |
+
data = self.distribution.get_long_description()
|
| 115 |
+
for warning in self._check_rst_data(data):
|
| 116 |
+
line = warning[-1].get('line')
|
| 117 |
+
if line is None:
|
| 118 |
+
warning = warning[1]
|
| 119 |
+
else:
|
| 120 |
+
warning = '%s (line %s)' % (warning[1], line)
|
| 121 |
+
self.warn(warning)
|
| 122 |
+
|
| 123 |
+
def _check_rst_data(self, data):
|
| 124 |
+
"""Returns warnings when the provided data doesn't compile."""
|
| 125 |
+
# the include and csv_table directives need this to be a path
|
| 126 |
+
source_path = self.distribution.script_name or 'setup.py'
|
| 127 |
+
parser = Parser()
|
| 128 |
+
try:
|
| 129 |
+
get_default_settings = frontend.get_default_settings
|
| 130 |
+
except AttributeError:
|
| 131 |
+
# Deprecated in Docutils 0.19, may be broken in Docutils 0.21.
|
| 132 |
+
settings = frontend.OptionParser(components=(Parser,)).get_default_values()
|
| 133 |
+
else:
|
| 134 |
+
settings = get_default_settings(Parser)
|
| 135 |
+
settings.tab_width = 4
|
| 136 |
+
settings.pep_references = None
|
| 137 |
+
settings.rfc_references = None
|
| 138 |
+
reporter = SilentReporter(source_path,
|
| 139 |
+
settings.report_level,
|
| 140 |
+
settings.halt_level,
|
| 141 |
+
stream=settings.warning_stream,
|
| 142 |
+
debug=settings.debug,
|
| 143 |
+
encoding=settings.error_encoding,
|
| 144 |
+
error_handler=settings.error_encoding_error_handler)
|
| 145 |
+
|
| 146 |
+
document = nodes.document(settings, reporter, source=source_path)
|
| 147 |
+
document.note_source(source_path, -1)
|
| 148 |
+
try:
|
| 149 |
+
parser.parse(data, document)
|
| 150 |
+
except AttributeError as e:
|
| 151 |
+
reporter.messages.append(
|
| 152 |
+
(-1, 'Could not finish the parsing: %s.' % e, '', {}))
|
| 153 |
+
|
| 154 |
+
return reporter.messages
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/clean.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.clean
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'clean' command."""
|
| 4 |
+
|
| 5 |
+
# contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from distutils.core import Command
|
| 9 |
+
from distutils.dir_util import remove_tree
|
| 10 |
+
from distutils import log
|
| 11 |
+
|
| 12 |
+
class clean(Command):
|
| 13 |
+
|
| 14 |
+
description = "clean up temporary files from 'build' command"
|
| 15 |
+
user_options = [
|
| 16 |
+
('build-base=', 'b',
|
| 17 |
+
"base build directory (default: 'build.build-base')"),
|
| 18 |
+
('build-lib=', None,
|
| 19 |
+
"build directory for all modules (default: 'build.build-lib')"),
|
| 20 |
+
('build-temp=', 't',
|
| 21 |
+
"temporary build directory (default: 'build.build-temp')"),
|
| 22 |
+
('build-scripts=', None,
|
| 23 |
+
"build directory for scripts (default: 'build.build-scripts')"),
|
| 24 |
+
('bdist-base=', None,
|
| 25 |
+
"temporary directory for built distributions"),
|
| 26 |
+
('all', 'a',
|
| 27 |
+
"remove all build output, not just temporary by-products")
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
boolean_options = ['all']
|
| 31 |
+
|
| 32 |
+
def initialize_options(self):
|
| 33 |
+
self.build_base = None
|
| 34 |
+
self.build_lib = None
|
| 35 |
+
self.build_temp = None
|
| 36 |
+
self.build_scripts = None
|
| 37 |
+
self.bdist_base = None
|
| 38 |
+
self.all = None
|
| 39 |
+
|
| 40 |
+
def finalize_options(self):
|
| 41 |
+
self.set_undefined_options('build',
|
| 42 |
+
('build_base', 'build_base'),
|
| 43 |
+
('build_lib', 'build_lib'),
|
| 44 |
+
('build_scripts', 'build_scripts'),
|
| 45 |
+
('build_temp', 'build_temp'))
|
| 46 |
+
self.set_undefined_options('bdist',
|
| 47 |
+
('bdist_base', 'bdist_base'))
|
| 48 |
+
|
| 49 |
+
def run(self):
|
| 50 |
+
# remove the build/temp.<plat> directory (unless it's already
|
| 51 |
+
# gone)
|
| 52 |
+
if os.path.exists(self.build_temp):
|
| 53 |
+
remove_tree(self.build_temp, dry_run=self.dry_run)
|
| 54 |
+
else:
|
| 55 |
+
log.debug("'%s' does not exist -- can't clean it",
|
| 56 |
+
self.build_temp)
|
| 57 |
+
|
| 58 |
+
if self.all:
|
| 59 |
+
# remove build directories
|
| 60 |
+
for directory in (self.build_lib,
|
| 61 |
+
self.bdist_base,
|
| 62 |
+
self.build_scripts):
|
| 63 |
+
if os.path.exists(directory):
|
| 64 |
+
remove_tree(directory, dry_run=self.dry_run)
|
| 65 |
+
else:
|
| 66 |
+
log.warn("'%s' does not exist -- can't clean it",
|
| 67 |
+
directory)
|
| 68 |
+
|
| 69 |
+
# just for the heck of it, try to remove the base build directory:
|
| 70 |
+
# we might have emptied it right now, but if not we don't care
|
| 71 |
+
if not self.dry_run:
|
| 72 |
+
try:
|
| 73 |
+
os.rmdir(self.build_base)
|
| 74 |
+
log.info("removing '%s'", self.build_base)
|
| 75 |
+
except OSError:
|
| 76 |
+
pass
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/command_template
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.x
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'x' command.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
# created 2000/mm/dd, John Doe
|
| 7 |
+
|
| 8 |
+
__revision__ = "$Id$"
|
| 9 |
+
|
| 10 |
+
from distutils.core import Command
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class x(Command):
|
| 14 |
+
|
| 15 |
+
# Brief (40-50 characters) description of the command
|
| 16 |
+
description = ""
|
| 17 |
+
|
| 18 |
+
# List of option tuples: long name, short name (None if no short
|
| 19 |
+
# name), and help string.
|
| 20 |
+
user_options = [('', '',
|
| 21 |
+
""),
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
def initialize_options(self):
|
| 25 |
+
self. = None
|
| 26 |
+
self. = None
|
| 27 |
+
self. = None
|
| 28 |
+
|
| 29 |
+
def finalize_options(self):
|
| 30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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.config
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'config' command, a (mostly) empty command class
|
| 4 |
+
that exists mainly to be sub-classed by specific module distributions and
|
| 5 |
+
applications. The idea is that while every "config" command is different,
|
| 6 |
+
at least they're all named the same, and users always see "config" in the
|
| 7 |
+
list of standard commands. Also, this is a good place to put common
|
| 8 |
+
configure-like tasks: "try to compile this C code", or "figure out where
|
| 9 |
+
this header file lives".
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import os, re
|
| 13 |
+
|
| 14 |
+
from distutils.core import Command
|
| 15 |
+
from distutils.errors import DistutilsExecError
|
| 16 |
+
from distutils.sysconfig import customize_compiler
|
| 17 |
+
from distutils import log
|
| 18 |
+
|
| 19 |
+
LANG_EXT = {"c": ".c", "c++": ".cxx"}
|
| 20 |
+
|
| 21 |
+
class config(Command):
|
| 22 |
+
|
| 23 |
+
description = "prepare to build"
|
| 24 |
+
|
| 25 |
+
user_options = [
|
| 26 |
+
('compiler=', None,
|
| 27 |
+
"specify the compiler type"),
|
| 28 |
+
('cc=', None,
|
| 29 |
+
"specify the compiler executable"),
|
| 30 |
+
('include-dirs=', 'I',
|
| 31 |
+
"list of directories to search for header files"),
|
| 32 |
+
('define=', 'D',
|
| 33 |
+
"C preprocessor macros to define"),
|
| 34 |
+
('undef=', 'U',
|
| 35 |
+
"C preprocessor macros to undefine"),
|
| 36 |
+
('libraries=', 'l',
|
| 37 |
+
"external C libraries to link with"),
|
| 38 |
+
('library-dirs=', 'L',
|
| 39 |
+
"directories to search for external C libraries"),
|
| 40 |
+
|
| 41 |
+
('noisy', None,
|
| 42 |
+
"show every action (compile, link, run, ...) taken"),
|
| 43 |
+
('dump-source', None,
|
| 44 |
+
"dump generated source files before attempting to compile them"),
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# The three standard command methods: since the "config" command
|
| 49 |
+
# does nothing by default, these are empty.
|
| 50 |
+
|
| 51 |
+
def initialize_options(self):
|
| 52 |
+
self.compiler = None
|
| 53 |
+
self.cc = None
|
| 54 |
+
self.include_dirs = None
|
| 55 |
+
self.libraries = None
|
| 56 |
+
self.library_dirs = None
|
| 57 |
+
|
| 58 |
+
# maximal output for now
|
| 59 |
+
self.noisy = 1
|
| 60 |
+
self.dump_source = 1
|
| 61 |
+
|
| 62 |
+
# list of temporary files generated along-the-way that we have
|
| 63 |
+
# to clean at some point
|
| 64 |
+
self.temp_files = []
|
| 65 |
+
|
| 66 |
+
def finalize_options(self):
|
| 67 |
+
if self.include_dirs is None:
|
| 68 |
+
self.include_dirs = self.distribution.include_dirs or []
|
| 69 |
+
elif isinstance(self.include_dirs, str):
|
| 70 |
+
self.include_dirs = self.include_dirs.split(os.pathsep)
|
| 71 |
+
|
| 72 |
+
if self.libraries is None:
|
| 73 |
+
self.libraries = []
|
| 74 |
+
elif isinstance(self.libraries, str):
|
| 75 |
+
self.libraries = [self.libraries]
|
| 76 |
+
|
| 77 |
+
if self.library_dirs is None:
|
| 78 |
+
self.library_dirs = []
|
| 79 |
+
elif isinstance(self.library_dirs, str):
|
| 80 |
+
self.library_dirs = self.library_dirs.split(os.pathsep)
|
| 81 |
+
|
| 82 |
+
def run(self):
|
| 83 |
+
pass
|
| 84 |
+
|
| 85 |
+
# Utility methods for actual "config" commands. The interfaces are
|
| 86 |
+
# loosely based on Autoconf macros of similar names. Sub-classes
|
| 87 |
+
# may use these freely.
|
| 88 |
+
|
| 89 |
+
def _check_compiler(self):
|
| 90 |
+
"""Check that 'self.compiler' really is a CCompiler object;
|
| 91 |
+
if not, make it one.
|
| 92 |
+
"""
|
| 93 |
+
# We do this late, and only on-demand, because this is an expensive
|
| 94 |
+
# import.
|
| 95 |
+
from distutils.ccompiler import CCompiler, new_compiler
|
| 96 |
+
if not isinstance(self.compiler, CCompiler):
|
| 97 |
+
self.compiler = new_compiler(compiler=self.compiler,
|
| 98 |
+
dry_run=self.dry_run, force=1)
|
| 99 |
+
customize_compiler(self.compiler)
|
| 100 |
+
if self.include_dirs:
|
| 101 |
+
self.compiler.set_include_dirs(self.include_dirs)
|
| 102 |
+
if self.libraries:
|
| 103 |
+
self.compiler.set_libraries(self.libraries)
|
| 104 |
+
if self.library_dirs:
|
| 105 |
+
self.compiler.set_library_dirs(self.library_dirs)
|
| 106 |
+
|
| 107 |
+
def _gen_temp_sourcefile(self, body, headers, lang):
|
| 108 |
+
filename = "_configtest" + LANG_EXT[lang]
|
| 109 |
+
with open(filename, "w") as file:
|
| 110 |
+
if headers:
|
| 111 |
+
for header in headers:
|
| 112 |
+
file.write("#include <%s>\n" % header)
|
| 113 |
+
file.write("\n")
|
| 114 |
+
file.write(body)
|
| 115 |
+
if body[-1] != "\n":
|
| 116 |
+
file.write("\n")
|
| 117 |
+
return filename
|
| 118 |
+
|
| 119 |
+
def _preprocess(self, body, headers, include_dirs, lang):
|
| 120 |
+
src = self._gen_temp_sourcefile(body, headers, lang)
|
| 121 |
+
out = "_configtest.i"
|
| 122 |
+
self.temp_files.extend([src, out])
|
| 123 |
+
self.compiler.preprocess(src, out, include_dirs=include_dirs)
|
| 124 |
+
return (src, out)
|
| 125 |
+
|
| 126 |
+
def _compile(self, body, headers, include_dirs, lang):
|
| 127 |
+
src = self._gen_temp_sourcefile(body, headers, lang)
|
| 128 |
+
if self.dump_source:
|
| 129 |
+
dump_file(src, "compiling '%s':" % src)
|
| 130 |
+
(obj,) = self.compiler.object_filenames([src])
|
| 131 |
+
self.temp_files.extend([src, obj])
|
| 132 |
+
self.compiler.compile([src], include_dirs=include_dirs)
|
| 133 |
+
return (src, obj)
|
| 134 |
+
|
| 135 |
+
def _link(self, body, headers, include_dirs, libraries, library_dirs,
|
| 136 |
+
lang):
|
| 137 |
+
(src, obj) = self._compile(body, headers, include_dirs, lang)
|
| 138 |
+
prog = os.path.splitext(os.path.basename(src))[0]
|
| 139 |
+
self.compiler.link_executable([obj], prog,
|
| 140 |
+
libraries=libraries,
|
| 141 |
+
library_dirs=library_dirs,
|
| 142 |
+
target_lang=lang)
|
| 143 |
+
|
| 144 |
+
if self.compiler.exe_extension is not None:
|
| 145 |
+
prog = prog + self.compiler.exe_extension
|
| 146 |
+
self.temp_files.append(prog)
|
| 147 |
+
|
| 148 |
+
return (src, obj, prog)
|
| 149 |
+
|
| 150 |
+
def _clean(self, *filenames):
|
| 151 |
+
if not filenames:
|
| 152 |
+
filenames = self.temp_files
|
| 153 |
+
self.temp_files = []
|
| 154 |
+
log.info("removing: %s", ' '.join(filenames))
|
| 155 |
+
for filename in filenames:
|
| 156 |
+
try:
|
| 157 |
+
os.remove(filename)
|
| 158 |
+
except OSError:
|
| 159 |
+
pass
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
# XXX these ignore the dry-run flag: what to do, what to do? even if
|
| 163 |
+
# you want a dry-run build, you still need some sort of configuration
|
| 164 |
+
# info. My inclination is to make it up to the real config command to
|
| 165 |
+
# consult 'dry_run', and assume a default (minimal) configuration if
|
| 166 |
+
# true. The problem with trying to do it here is that you'd have to
|
| 167 |
+
# return either true or false from all the 'try' methods, neither of
|
| 168 |
+
# which is correct.
|
| 169 |
+
|
| 170 |
+
# XXX need access to the header search path and maybe default macros.
|
| 171 |
+
|
| 172 |
+
def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"):
|
| 173 |
+
"""Construct a source file from 'body' (a string containing lines
|
| 174 |
+
of C/C++ code) and 'headers' (a list of header files to include)
|
| 175 |
+
and run it through the preprocessor. Return true if the
|
| 176 |
+
preprocessor succeeded, false if there were any errors.
|
| 177 |
+
('body' probably isn't of much use, but what the heck.)
|
| 178 |
+
"""
|
| 179 |
+
from distutils.ccompiler import CompileError
|
| 180 |
+
self._check_compiler()
|
| 181 |
+
ok = True
|
| 182 |
+
try:
|
| 183 |
+
self._preprocess(body, headers, include_dirs, lang)
|
| 184 |
+
except CompileError:
|
| 185 |
+
ok = False
|
| 186 |
+
|
| 187 |
+
self._clean()
|
| 188 |
+
return ok
|
| 189 |
+
|
| 190 |
+
def search_cpp(self, pattern, body=None, headers=None, include_dirs=None,
|
| 191 |
+
lang="c"):
|
| 192 |
+
"""Construct a source file (just like 'try_cpp()'), run it through
|
| 193 |
+
the preprocessor, and return true if any line of the output matches
|
| 194 |
+
'pattern'. 'pattern' should either be a compiled regex object or a
|
| 195 |
+
string containing a regex. If both 'body' and 'headers' are None,
|
| 196 |
+
preprocesses an empty file -- which can be useful to determine the
|
| 197 |
+
symbols the preprocessor and compiler set by default.
|
| 198 |
+
"""
|
| 199 |
+
self._check_compiler()
|
| 200 |
+
src, out = self._preprocess(body, headers, include_dirs, lang)
|
| 201 |
+
|
| 202 |
+
if isinstance(pattern, str):
|
| 203 |
+
pattern = re.compile(pattern)
|
| 204 |
+
|
| 205 |
+
with open(out) as file:
|
| 206 |
+
match = False
|
| 207 |
+
while True:
|
| 208 |
+
line = file.readline()
|
| 209 |
+
if line == '':
|
| 210 |
+
break
|
| 211 |
+
if pattern.search(line):
|
| 212 |
+
match = True
|
| 213 |
+
break
|
| 214 |
+
|
| 215 |
+
self._clean()
|
| 216 |
+
return match
|
| 217 |
+
|
| 218 |
+
def try_compile(self, body, headers=None, include_dirs=None, lang="c"):
|
| 219 |
+
"""Try to compile a source file built from 'body' and 'headers'.
|
| 220 |
+
Return true on success, false otherwise.
|
| 221 |
+
"""
|
| 222 |
+
from distutils.ccompiler import CompileError
|
| 223 |
+
self._check_compiler()
|
| 224 |
+
try:
|
| 225 |
+
self._compile(body, headers, include_dirs, lang)
|
| 226 |
+
ok = True
|
| 227 |
+
except CompileError:
|
| 228 |
+
ok = False
|
| 229 |
+
|
| 230 |
+
log.info(ok and "success!" or "failure.")
|
| 231 |
+
self._clean()
|
| 232 |
+
return ok
|
| 233 |
+
|
| 234 |
+
def try_link(self, body, headers=None, include_dirs=None, libraries=None,
|
| 235 |
+
library_dirs=None, lang="c"):
|
| 236 |
+
"""Try to compile and link a source file, built from 'body' and
|
| 237 |
+
'headers', to executable form. Return true on success, false
|
| 238 |
+
otherwise.
|
| 239 |
+
"""
|
| 240 |
+
from distutils.ccompiler import CompileError, LinkError
|
| 241 |
+
self._check_compiler()
|
| 242 |
+
try:
|
| 243 |
+
self._link(body, headers, include_dirs,
|
| 244 |
+
libraries, library_dirs, lang)
|
| 245 |
+
ok = True
|
| 246 |
+
except (CompileError, LinkError):
|
| 247 |
+
ok = False
|
| 248 |
+
|
| 249 |
+
log.info(ok and "success!" or "failure.")
|
| 250 |
+
self._clean()
|
| 251 |
+
return ok
|
| 252 |
+
|
| 253 |
+
def try_run(self, body, headers=None, include_dirs=None, libraries=None,
|
| 254 |
+
library_dirs=None, lang="c"):
|
| 255 |
+
"""Try to compile, link to an executable, and run a program
|
| 256 |
+
built from 'body' and 'headers'. Return true on success, false
|
| 257 |
+
otherwise.
|
| 258 |
+
"""
|
| 259 |
+
from distutils.ccompiler import CompileError, LinkError
|
| 260 |
+
self._check_compiler()
|
| 261 |
+
try:
|
| 262 |
+
src, obj, exe = self._link(body, headers, include_dirs,
|
| 263 |
+
libraries, library_dirs, lang)
|
| 264 |
+
self.spawn([exe])
|
| 265 |
+
ok = True
|
| 266 |
+
except (CompileError, LinkError, DistutilsExecError):
|
| 267 |
+
ok = False
|
| 268 |
+
|
| 269 |
+
log.info(ok and "success!" or "failure.")
|
| 270 |
+
self._clean()
|
| 271 |
+
return ok
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
# -- High-level methods --------------------------------------------
|
| 275 |
+
# (these are the ones that are actually likely to be useful
|
| 276 |
+
# when implementing a real-world config command!)
|
| 277 |
+
|
| 278 |
+
def check_func(self, func, headers=None, include_dirs=None,
|
| 279 |
+
libraries=None, library_dirs=None, decl=0, call=0):
|
| 280 |
+
"""Determine if function 'func' is available by constructing a
|
| 281 |
+
source file that refers to 'func', and compiles and links it.
|
| 282 |
+
If everything succeeds, returns true; otherwise returns false.
|
| 283 |
+
|
| 284 |
+
The constructed source file starts out by including the header
|
| 285 |
+
files listed in 'headers'. If 'decl' is true, it then declares
|
| 286 |
+
'func' (as "int func()"); you probably shouldn't supply 'headers'
|
| 287 |
+
and set 'decl' true in the same call, or you might get errors about
|
| 288 |
+
a conflicting declarations for 'func'. Finally, the constructed
|
| 289 |
+
'main()' function either references 'func' or (if 'call' is true)
|
| 290 |
+
calls it. 'libraries' and 'library_dirs' are used when
|
| 291 |
+
linking.
|
| 292 |
+
"""
|
| 293 |
+
self._check_compiler()
|
| 294 |
+
body = []
|
| 295 |
+
if decl:
|
| 296 |
+
body.append("int %s ();" % func)
|
| 297 |
+
body.append("int main () {")
|
| 298 |
+
if call:
|
| 299 |
+
body.append(" %s();" % func)
|
| 300 |
+
else:
|
| 301 |
+
body.append(" %s;" % func)
|
| 302 |
+
body.append("}")
|
| 303 |
+
body = "\n".join(body) + "\n"
|
| 304 |
+
|
| 305 |
+
return self.try_link(body, headers, include_dirs,
|
| 306 |
+
libraries, library_dirs)
|
| 307 |
+
|
| 308 |
+
def check_lib(self, library, library_dirs=None, headers=None,
|
| 309 |
+
include_dirs=None, other_libraries=[]):
|
| 310 |
+
"""Determine if 'library' is available to be linked against,
|
| 311 |
+
without actually checking that any particular symbols are provided
|
| 312 |
+
by it. 'headers' will be used in constructing the source file to
|
| 313 |
+
be compiled, but the only effect of this is to check if all the
|
| 314 |
+
header files listed are available. Any libraries listed in
|
| 315 |
+
'other_libraries' will be included in the link, in case 'library'
|
| 316 |
+
has symbols that depend on other libraries.
|
| 317 |
+
"""
|
| 318 |
+
self._check_compiler()
|
| 319 |
+
return self.try_link("int main (void) { }", headers, include_dirs,
|
| 320 |
+
[library] + other_libraries, library_dirs)
|
| 321 |
+
|
| 322 |
+
def check_header(self, header, include_dirs=None, library_dirs=None,
|
| 323 |
+
lang="c"):
|
| 324 |
+
"""Determine if the system header file named by 'header_file'
|
| 325 |
+
exists and can be found by the preprocessor; return true if so,
|
| 326 |
+
false otherwise.
|
| 327 |
+
"""
|
| 328 |
+
return self.try_cpp(body="/* No body */", headers=[header],
|
| 329 |
+
include_dirs=include_dirs)
|
| 330 |
+
|
| 331 |
+
def dump_file(filename, head=None):
|
| 332 |
+
"""Dumps a file content into log.info.
|
| 333 |
+
|
| 334 |
+
If head is not None, will be dumped before the file content.
|
| 335 |
+
"""
|
| 336 |
+
if head is None:
|
| 337 |
+
log.info('%s', filename)
|
| 338 |
+
else:
|
| 339 |
+
log.info(head)
|
| 340 |
+
file = open(filename)
|
| 341 |
+
try:
|
| 342 |
+
log.info(file.read())
|
| 343 |
+
finally:
|
| 344 |
+
file.close()
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install.py
ADDED
|
@@ -0,0 +1,679 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install' command."""
|
| 4 |
+
|
| 5 |
+
import sys
|
| 6 |
+
import sysconfig
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
|
| 10 |
+
from distutils import log
|
| 11 |
+
from distutils.core import Command
|
| 12 |
+
from distutils.debug import DEBUG
|
| 13 |
+
from distutils.sysconfig import get_config_vars
|
| 14 |
+
from distutils.errors import DistutilsPlatformError
|
| 15 |
+
from distutils.file_util import write_file
|
| 16 |
+
from distutils.util import convert_path, subst_vars, change_root
|
| 17 |
+
from distutils.util import get_platform
|
| 18 |
+
from distutils.errors import DistutilsOptionError
|
| 19 |
+
|
| 20 |
+
from site import USER_BASE
|
| 21 |
+
from site import USER_SITE
|
| 22 |
+
|
| 23 |
+
HAS_USER_SITE = (USER_SITE is not None)
|
| 24 |
+
|
| 25 |
+
# The keys to an installation scheme; if any new types of files are to be
|
| 26 |
+
# installed, be sure to add an entry to every scheme in
|
| 27 |
+
# sysconfig._INSTALL_SCHEMES, and to SCHEME_KEYS here.
|
| 28 |
+
SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
|
| 29 |
+
|
| 30 |
+
# The following code provides backward-compatible INSTALL_SCHEMES
|
| 31 |
+
# while making the sysconfig module the single point of truth.
|
| 32 |
+
# This makes it easier for OS distributions where they need to
|
| 33 |
+
# alter locations for packages installations in a single place.
|
| 34 |
+
# Note that this module is deprecated (PEP 632); all consumers
|
| 35 |
+
# of this information should switch to using sysconfig directly.
|
| 36 |
+
INSTALL_SCHEMES = {"unix_prefix": {}, "unix_home": {}, "nt": {}}
|
| 37 |
+
|
| 38 |
+
# Copy from sysconfig._INSTALL_SCHEMES
|
| 39 |
+
for key in SCHEME_KEYS:
|
| 40 |
+
for distutils_scheme_name, sys_scheme_name in (
|
| 41 |
+
("unix_prefix", "posix_prefix"), ("unix_home", "posix_home"),
|
| 42 |
+
("nt", "nt")):
|
| 43 |
+
sys_key = key
|
| 44 |
+
sys_scheme = sysconfig._INSTALL_SCHEMES[sys_scheme_name]
|
| 45 |
+
if key == "headers" and key not in sys_scheme:
|
| 46 |
+
# On POSIX-y platforms, Python will:
|
| 47 |
+
# - Build from .h files in 'headers' (only there when
|
| 48 |
+
# building CPython)
|
| 49 |
+
# - Install .h files to 'include'
|
| 50 |
+
# When 'headers' is missing, fall back to 'include'
|
| 51 |
+
sys_key = 'include'
|
| 52 |
+
INSTALL_SCHEMES[distutils_scheme_name][key] = sys_scheme[sys_key]
|
| 53 |
+
|
| 54 |
+
# Transformation to different template format
|
| 55 |
+
for main_key in INSTALL_SCHEMES:
|
| 56 |
+
for key, value in INSTALL_SCHEMES[main_key].items():
|
| 57 |
+
# Change all ocurences of {variable} to $variable
|
| 58 |
+
value = re.sub(r"\{(.+?)\}", r"$\g<1>", value)
|
| 59 |
+
value = value.replace("$installed_base", "$base")
|
| 60 |
+
value = value.replace("$py_version_nodot_plat", "$py_version_nodot")
|
| 61 |
+
if key == "headers":
|
| 62 |
+
value += "/$dist_name"
|
| 63 |
+
if sys.version_info >= (3, 9) and key == "platlib":
|
| 64 |
+
# platlibdir is available since 3.9: bpo-1294959
|
| 65 |
+
value = value.replace("/lib/", "/$platlibdir/")
|
| 66 |
+
INSTALL_SCHEMES[main_key][key] = value
|
| 67 |
+
|
| 68 |
+
# The following part of INSTALL_SCHEMES has a different definition
|
| 69 |
+
# than the one in sysconfig, but because both depend on the site module,
|
| 70 |
+
# the outcomes should be the same.
|
| 71 |
+
if HAS_USER_SITE:
|
| 72 |
+
INSTALL_SCHEMES['nt_user'] = {
|
| 73 |
+
'purelib': '$usersite',
|
| 74 |
+
'platlib': '$usersite',
|
| 75 |
+
'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
|
| 76 |
+
'scripts': '$userbase/Python$py_version_nodot/Scripts',
|
| 77 |
+
'data' : '$userbase',
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
INSTALL_SCHEMES['unix_user'] = {
|
| 81 |
+
'purelib': '$usersite',
|
| 82 |
+
'platlib': '$usersite',
|
| 83 |
+
'headers':
|
| 84 |
+
'$userbase/include/python$py_version_short$abiflags/$dist_name',
|
| 85 |
+
'scripts': '$userbase/bin',
|
| 86 |
+
'data' : '$userbase',
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class install(Command):
|
| 91 |
+
|
| 92 |
+
description = "install everything from build directory"
|
| 93 |
+
|
| 94 |
+
user_options = [
|
| 95 |
+
# Select installation scheme and set base director(y|ies)
|
| 96 |
+
('prefix=', None,
|
| 97 |
+
"installation prefix"),
|
| 98 |
+
('exec-prefix=', None,
|
| 99 |
+
"(Unix only) prefix for platform-specific files"),
|
| 100 |
+
('home=', None,
|
| 101 |
+
"(Unix only) home directory to install under"),
|
| 102 |
+
|
| 103 |
+
# Or, just set the base director(y|ies)
|
| 104 |
+
('install-base=', None,
|
| 105 |
+
"base installation directory (instead of --prefix or --home)"),
|
| 106 |
+
('install-platbase=', None,
|
| 107 |
+
"base installation directory for platform-specific files " +
|
| 108 |
+
"(instead of --exec-prefix or --home)"),
|
| 109 |
+
('root=', None,
|
| 110 |
+
"install everything relative to this alternate root directory"),
|
| 111 |
+
|
| 112 |
+
# Or, explicitly set the installation scheme
|
| 113 |
+
('install-purelib=', None,
|
| 114 |
+
"installation directory for pure Python module distributions"),
|
| 115 |
+
('install-platlib=', None,
|
| 116 |
+
"installation directory for non-pure module distributions"),
|
| 117 |
+
('install-lib=', None,
|
| 118 |
+
"installation directory for all module distributions " +
|
| 119 |
+
"(overrides --install-purelib and --install-platlib)"),
|
| 120 |
+
|
| 121 |
+
('install-headers=', None,
|
| 122 |
+
"installation directory for C/C++ headers"),
|
| 123 |
+
('install-scripts=', None,
|
| 124 |
+
"installation directory for Python scripts"),
|
| 125 |
+
('install-data=', None,
|
| 126 |
+
"installation directory for data files"),
|
| 127 |
+
|
| 128 |
+
# Byte-compilation options -- see install_lib.py for details, as
|
| 129 |
+
# these are duplicated from there (but only install_lib does
|
| 130 |
+
# anything with them).
|
| 131 |
+
('compile', 'c', "compile .py to .pyc [default]"),
|
| 132 |
+
('no-compile', None, "don't compile .py files"),
|
| 133 |
+
('optimize=', 'O',
|
| 134 |
+
"also compile with optimization: -O1 for \"python -O\", "
|
| 135 |
+
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
|
| 136 |
+
|
| 137 |
+
# Miscellaneous control options
|
| 138 |
+
('force', 'f',
|
| 139 |
+
"force installation (overwrite any existing files)"),
|
| 140 |
+
('skip-build', None,
|
| 141 |
+
"skip rebuilding everything (for testing/debugging)"),
|
| 142 |
+
|
| 143 |
+
# Where to install documentation (eventually!)
|
| 144 |
+
#('doc-format=', None, "format of documentation to generate"),
|
| 145 |
+
#('install-man=', None, "directory for Unix man pages"),
|
| 146 |
+
#('install-html=', None, "directory for HTML documentation"),
|
| 147 |
+
#('install-info=', None, "directory for GNU info files"),
|
| 148 |
+
|
| 149 |
+
('record=', None,
|
| 150 |
+
"filename in which to record list of installed files"),
|
| 151 |
+
]
|
| 152 |
+
|
| 153 |
+
boolean_options = ['compile', 'force', 'skip-build']
|
| 154 |
+
|
| 155 |
+
if HAS_USER_SITE:
|
| 156 |
+
user_options.append(('user', None,
|
| 157 |
+
"install in user site-package '%s'" % USER_SITE))
|
| 158 |
+
boolean_options.append('user')
|
| 159 |
+
|
| 160 |
+
negative_opt = {'no-compile' : 'compile'}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def initialize_options(self):
|
| 164 |
+
"""Initializes options."""
|
| 165 |
+
# High-level options: these select both an installation base
|
| 166 |
+
# and scheme.
|
| 167 |
+
self.prefix = None
|
| 168 |
+
self.exec_prefix = None
|
| 169 |
+
self.home = None
|
| 170 |
+
self.user = 0
|
| 171 |
+
|
| 172 |
+
# These select only the installation base; it's up to the user to
|
| 173 |
+
# specify the installation scheme (currently, that means supplying
|
| 174 |
+
# the --install-{platlib,purelib,scripts,data} options).
|
| 175 |
+
self.install_base = None
|
| 176 |
+
self.install_platbase = None
|
| 177 |
+
self.root = None
|
| 178 |
+
|
| 179 |
+
# These options are the actual installation directories; if not
|
| 180 |
+
# supplied by the user, they are filled in using the installation
|
| 181 |
+
# scheme implied by prefix/exec-prefix/home and the contents of
|
| 182 |
+
# that installation scheme.
|
| 183 |
+
self.install_purelib = None # for pure module distributions
|
| 184 |
+
self.install_platlib = None # non-pure (dists w/ extensions)
|
| 185 |
+
self.install_headers = None # for C/C++ headers
|
| 186 |
+
self.install_lib = None # set to either purelib or platlib
|
| 187 |
+
self.install_scripts = None
|
| 188 |
+
self.install_data = None
|
| 189 |
+
if HAS_USER_SITE:
|
| 190 |
+
self.install_userbase = USER_BASE
|
| 191 |
+
self.install_usersite = USER_SITE
|
| 192 |
+
|
| 193 |
+
self.compile = None
|
| 194 |
+
self.optimize = None
|
| 195 |
+
|
| 196 |
+
# Deprecated
|
| 197 |
+
# These two are for putting non-packagized distributions into their
|
| 198 |
+
# own directory and creating a .pth file if it makes sense.
|
| 199 |
+
# 'extra_path' comes from the setup file; 'install_path_file' can
|
| 200 |
+
# be turned off if it makes no sense to install a .pth file. (But
|
| 201 |
+
# better to install it uselessly than to guess wrong and not
|
| 202 |
+
# install it when it's necessary and would be used!) Currently,
|
| 203 |
+
# 'install_path_file' is always true unless some outsider meddles
|
| 204 |
+
# with it.
|
| 205 |
+
self.extra_path = None
|
| 206 |
+
self.install_path_file = 1
|
| 207 |
+
|
| 208 |
+
# 'force' forces installation, even if target files are not
|
| 209 |
+
# out-of-date. 'skip_build' skips running the "build" command,
|
| 210 |
+
# handy if you know it's not necessary. 'warn_dir' (which is *not*
|
| 211 |
+
# a user option, it's just there so the bdist_* commands can turn
|
| 212 |
+
# it off) determines whether we warn about installing to a
|
| 213 |
+
# directory not in sys.path.
|
| 214 |
+
self.force = 0
|
| 215 |
+
self.skip_build = 0
|
| 216 |
+
self.warn_dir = 1
|
| 217 |
+
|
| 218 |
+
# These are only here as a conduit from the 'build' command to the
|
| 219 |
+
# 'install_*' commands that do the real work. ('build_base' isn't
|
| 220 |
+
# actually used anywhere, but it might be useful in future.) They
|
| 221 |
+
# are not user options, because if the user told the install
|
| 222 |
+
# command where the build directory is, that wouldn't affect the
|
| 223 |
+
# build command.
|
| 224 |
+
self.build_base = None
|
| 225 |
+
self.build_lib = None
|
| 226 |
+
|
| 227 |
+
# Not defined yet because we don't know anything about
|
| 228 |
+
# documentation yet.
|
| 229 |
+
#self.install_man = None
|
| 230 |
+
#self.install_html = None
|
| 231 |
+
#self.install_info = None
|
| 232 |
+
|
| 233 |
+
self.record = None
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
# -- Option finalizing methods -------------------------------------
|
| 237 |
+
# (This is rather more involved than for most commands,
|
| 238 |
+
# because this is where the policy for installing third-
|
| 239 |
+
# party Python modules on various platforms given a wide
|
| 240 |
+
# array of user input is decided. Yes, it's quite complex!)
|
| 241 |
+
|
| 242 |
+
def finalize_options(self):
|
| 243 |
+
"""Finalizes options."""
|
| 244 |
+
# This method (and its helpers, like 'finalize_unix()',
|
| 245 |
+
# 'finalize_other()', and 'select_scheme()') is where the default
|
| 246 |
+
# installation directories for modules, extension modules, and
|
| 247 |
+
# anything else we care to install from a Python module
|
| 248 |
+
# distribution. Thus, this code makes a pretty important policy
|
| 249 |
+
# statement about how third-party stuff is added to a Python
|
| 250 |
+
# installation! Note that the actual work of installation is done
|
| 251 |
+
# by the relatively simple 'install_*' commands; they just take
|
| 252 |
+
# their orders from the installation directory options determined
|
| 253 |
+
# here.
|
| 254 |
+
|
| 255 |
+
# Check for errors/inconsistencies in the options; first, stuff
|
| 256 |
+
# that's wrong on any platform.
|
| 257 |
+
|
| 258 |
+
if ((self.prefix or self.exec_prefix or self.home) and
|
| 259 |
+
(self.install_base or self.install_platbase)):
|
| 260 |
+
raise DistutilsOptionError(
|
| 261 |
+
"must supply either prefix/exec-prefix/home or " +
|
| 262 |
+
"install-base/install-platbase -- not both")
|
| 263 |
+
|
| 264 |
+
if self.home and (self.prefix or self.exec_prefix):
|
| 265 |
+
raise DistutilsOptionError(
|
| 266 |
+
"must supply either home or prefix/exec-prefix -- not both")
|
| 267 |
+
|
| 268 |
+
if self.user and (self.prefix or self.exec_prefix or self.home or
|
| 269 |
+
self.install_base or self.install_platbase):
|
| 270 |
+
raise DistutilsOptionError("can't combine user with prefix, "
|
| 271 |
+
"exec_prefix/home, or install_(plat)base")
|
| 272 |
+
|
| 273 |
+
# Next, stuff that's wrong (or dubious) only on certain platforms.
|
| 274 |
+
if os.name != "posix":
|
| 275 |
+
if self.exec_prefix:
|
| 276 |
+
self.warn("exec-prefix option ignored on this platform")
|
| 277 |
+
self.exec_prefix = None
|
| 278 |
+
|
| 279 |
+
# Now the interesting logic -- so interesting that we farm it out
|
| 280 |
+
# to other methods. The goal of these methods is to set the final
|
| 281 |
+
# values for the install_{lib,scripts,data,...} options, using as
|
| 282 |
+
# input a heady brew of prefix, exec_prefix, home, install_base,
|
| 283 |
+
# install_platbase, user-supplied versions of
|
| 284 |
+
# install_{purelib,platlib,lib,scripts,data,...}, and the
|
| 285 |
+
# INSTALL_SCHEME dictionary above. Phew!
|
| 286 |
+
|
| 287 |
+
self.dump_dirs("pre-finalize_{unix,other}")
|
| 288 |
+
|
| 289 |
+
if os.name == 'posix':
|
| 290 |
+
self.finalize_unix()
|
| 291 |
+
else:
|
| 292 |
+
self.finalize_other()
|
| 293 |
+
|
| 294 |
+
self.dump_dirs("post-finalize_{unix,other}()")
|
| 295 |
+
|
| 296 |
+
# Expand configuration variables, tilde, etc. in self.install_base
|
| 297 |
+
# and self.install_platbase -- that way, we can use $base or
|
| 298 |
+
# $platbase in the other installation directories and not worry
|
| 299 |
+
# about needing recursive variable expansion (shudder).
|
| 300 |
+
|
| 301 |
+
py_version = sys.version.split()[0]
|
| 302 |
+
(prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
|
| 303 |
+
try:
|
| 304 |
+
abiflags = sys.abiflags
|
| 305 |
+
except AttributeError:
|
| 306 |
+
# sys.abiflags may not be defined on all platforms.
|
| 307 |
+
abiflags = ''
|
| 308 |
+
self.config_vars = {'dist_name': self.distribution.get_name(),
|
| 309 |
+
'dist_version': self.distribution.get_version(),
|
| 310 |
+
'dist_fullname': self.distribution.get_fullname(),
|
| 311 |
+
'py_version': py_version,
|
| 312 |
+
'py_version_short': '%d.%d' % sys.version_info[:2],
|
| 313 |
+
'py_version_nodot': '%d%d' % sys.version_info[:2],
|
| 314 |
+
'sys_prefix': prefix,
|
| 315 |
+
'prefix': prefix,
|
| 316 |
+
'sys_exec_prefix': exec_prefix,
|
| 317 |
+
'exec_prefix': exec_prefix,
|
| 318 |
+
'abiflags': abiflags,
|
| 319 |
+
'platlibdir': sys.platlibdir,
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
if HAS_USER_SITE:
|
| 323 |
+
self.config_vars['userbase'] = self.install_userbase
|
| 324 |
+
self.config_vars['usersite'] = self.install_usersite
|
| 325 |
+
|
| 326 |
+
if sysconfig.is_python_build(True):
|
| 327 |
+
self.config_vars['srcdir'] = sysconfig.get_config_var('srcdir')
|
| 328 |
+
|
| 329 |
+
self.expand_basedirs()
|
| 330 |
+
|
| 331 |
+
self.dump_dirs("post-expand_basedirs()")
|
| 332 |
+
|
| 333 |
+
# Now define config vars for the base directories so we can expand
|
| 334 |
+
# everything else.
|
| 335 |
+
self.config_vars['base'] = self.install_base
|
| 336 |
+
self.config_vars['platbase'] = self.install_platbase
|
| 337 |
+
|
| 338 |
+
if DEBUG:
|
| 339 |
+
from pprint import pprint
|
| 340 |
+
print("config vars:")
|
| 341 |
+
pprint(self.config_vars)
|
| 342 |
+
|
| 343 |
+
# Expand "~" and configuration variables in the installation
|
| 344 |
+
# directories.
|
| 345 |
+
self.expand_dirs()
|
| 346 |
+
|
| 347 |
+
self.dump_dirs("post-expand_dirs()")
|
| 348 |
+
|
| 349 |
+
# Create directories in the home dir:
|
| 350 |
+
if self.user:
|
| 351 |
+
self.create_home_path()
|
| 352 |
+
|
| 353 |
+
# Pick the actual directory to install all modules to: either
|
| 354 |
+
# install_purelib or install_platlib, depending on whether this
|
| 355 |
+
# module distribution is pure or not. Of course, if the user
|
| 356 |
+
# already specified install_lib, use their selection.
|
| 357 |
+
if self.install_lib is None:
|
| 358 |
+
if self.distribution.ext_modules: # has extensions: non-pure
|
| 359 |
+
self.install_lib = self.install_platlib
|
| 360 |
+
else:
|
| 361 |
+
self.install_lib = self.install_purelib
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
# Convert directories from Unix /-separated syntax to the local
|
| 365 |
+
# convention.
|
| 366 |
+
self.convert_paths('lib', 'purelib', 'platlib',
|
| 367 |
+
'scripts', 'data', 'headers')
|
| 368 |
+
if HAS_USER_SITE:
|
| 369 |
+
self.convert_paths('userbase', 'usersite')
|
| 370 |
+
|
| 371 |
+
# Deprecated
|
| 372 |
+
# Well, we're not actually fully completely finalized yet: we still
|
| 373 |
+
# have to deal with 'extra_path', which is the hack for allowing
|
| 374 |
+
# non-packagized module distributions (hello, Numerical Python!) to
|
| 375 |
+
# get their own directories.
|
| 376 |
+
self.handle_extra_path()
|
| 377 |
+
self.install_libbase = self.install_lib # needed for .pth file
|
| 378 |
+
self.install_lib = os.path.join(self.install_lib, self.extra_dirs)
|
| 379 |
+
|
| 380 |
+
# If a new root directory was supplied, make all the installation
|
| 381 |
+
# dirs relative to it.
|
| 382 |
+
if self.root is not None:
|
| 383 |
+
self.change_roots('libbase', 'lib', 'purelib', 'platlib',
|
| 384 |
+
'scripts', 'data', 'headers')
|
| 385 |
+
|
| 386 |
+
self.dump_dirs("after prepending root")
|
| 387 |
+
|
| 388 |
+
# Find out the build directories, ie. where to install from.
|
| 389 |
+
self.set_undefined_options('build',
|
| 390 |
+
('build_base', 'build_base'),
|
| 391 |
+
('build_lib', 'build_lib'))
|
| 392 |
+
|
| 393 |
+
# Punt on doc directories for now -- after all, we're punting on
|
| 394 |
+
# documentation completely!
|
| 395 |
+
|
| 396 |
+
def dump_dirs(self, msg):
|
| 397 |
+
"""Dumps the list of user options."""
|
| 398 |
+
if not DEBUG:
|
| 399 |
+
return
|
| 400 |
+
from distutils.fancy_getopt import longopt_xlate
|
| 401 |
+
log.debug(msg + ":")
|
| 402 |
+
for opt in self.user_options:
|
| 403 |
+
opt_name = opt[0]
|
| 404 |
+
if opt_name[-1] == "=":
|
| 405 |
+
opt_name = opt_name[0:-1]
|
| 406 |
+
if opt_name in self.negative_opt:
|
| 407 |
+
opt_name = self.negative_opt[opt_name]
|
| 408 |
+
opt_name = opt_name.translate(longopt_xlate)
|
| 409 |
+
val = not getattr(self, opt_name)
|
| 410 |
+
else:
|
| 411 |
+
opt_name = opt_name.translate(longopt_xlate)
|
| 412 |
+
val = getattr(self, opt_name)
|
| 413 |
+
log.debug(" %s: %s", opt_name, val)
|
| 414 |
+
|
| 415 |
+
def finalize_unix(self):
|
| 416 |
+
"""Finalizes options for posix platforms."""
|
| 417 |
+
if self.install_base is not None or self.install_platbase is not None:
|
| 418 |
+
if ((self.install_lib is None and
|
| 419 |
+
self.install_purelib is None and
|
| 420 |
+
self.install_platlib is None) or
|
| 421 |
+
self.install_headers is None or
|
| 422 |
+
self.install_scripts is None or
|
| 423 |
+
self.install_data is None):
|
| 424 |
+
raise DistutilsOptionError(
|
| 425 |
+
"install-base or install-platbase supplied, but "
|
| 426 |
+
"installation scheme is incomplete")
|
| 427 |
+
return
|
| 428 |
+
|
| 429 |
+
if self.user:
|
| 430 |
+
if self.install_userbase is None:
|
| 431 |
+
raise DistutilsPlatformError(
|
| 432 |
+
"User base directory is not specified")
|
| 433 |
+
self.install_base = self.install_platbase = self.install_userbase
|
| 434 |
+
self.select_scheme("unix_user")
|
| 435 |
+
elif self.home is not None:
|
| 436 |
+
self.install_base = self.install_platbase = self.home
|
| 437 |
+
self.select_scheme("unix_home")
|
| 438 |
+
else:
|
| 439 |
+
if self.prefix is None:
|
| 440 |
+
if self.exec_prefix is not None:
|
| 441 |
+
raise DistutilsOptionError(
|
| 442 |
+
"must not supply exec-prefix without prefix")
|
| 443 |
+
|
| 444 |
+
self.prefix = os.path.normpath(sys.prefix)
|
| 445 |
+
self.exec_prefix = os.path.normpath(sys.exec_prefix)
|
| 446 |
+
|
| 447 |
+
else:
|
| 448 |
+
if self.exec_prefix is None:
|
| 449 |
+
self.exec_prefix = self.prefix
|
| 450 |
+
|
| 451 |
+
self.install_base = self.prefix
|
| 452 |
+
self.install_platbase = self.exec_prefix
|
| 453 |
+
self.select_scheme("unix_prefix")
|
| 454 |
+
|
| 455 |
+
def finalize_other(self):
|
| 456 |
+
"""Finalizes options for non-posix platforms"""
|
| 457 |
+
if self.user:
|
| 458 |
+
if self.install_userbase is None:
|
| 459 |
+
raise DistutilsPlatformError(
|
| 460 |
+
"User base directory is not specified")
|
| 461 |
+
self.install_base = self.install_platbase = self.install_userbase
|
| 462 |
+
self.select_scheme(os.name + "_user")
|
| 463 |
+
elif self.home is not None:
|
| 464 |
+
self.install_base = self.install_platbase = self.home
|
| 465 |
+
self.select_scheme("unix_home")
|
| 466 |
+
else:
|
| 467 |
+
if self.prefix is None:
|
| 468 |
+
self.prefix = os.path.normpath(sys.prefix)
|
| 469 |
+
|
| 470 |
+
self.install_base = self.install_platbase = self.prefix
|
| 471 |
+
try:
|
| 472 |
+
self.select_scheme(os.name)
|
| 473 |
+
except KeyError:
|
| 474 |
+
raise DistutilsPlatformError(
|
| 475 |
+
"I don't know how to install stuff on '%s'" % os.name)
|
| 476 |
+
|
| 477 |
+
def select_scheme(self, name):
|
| 478 |
+
"""Sets the install directories by applying the install schemes."""
|
| 479 |
+
# it's the caller's problem if they supply a bad name!
|
| 480 |
+
scheme = INSTALL_SCHEMES[name]
|
| 481 |
+
for key in SCHEME_KEYS:
|
| 482 |
+
attrname = 'install_' + key
|
| 483 |
+
if getattr(self, attrname) is None:
|
| 484 |
+
setattr(self, attrname, scheme[key])
|
| 485 |
+
|
| 486 |
+
def _expand_attrs(self, attrs):
|
| 487 |
+
for attr in attrs:
|
| 488 |
+
val = getattr(self, attr)
|
| 489 |
+
if val is not None:
|
| 490 |
+
if os.name == 'posix' or os.name == 'nt':
|
| 491 |
+
val = os.path.expanduser(val)
|
| 492 |
+
val = subst_vars(val, self.config_vars)
|
| 493 |
+
setattr(self, attr, val)
|
| 494 |
+
|
| 495 |
+
def expand_basedirs(self):
|
| 496 |
+
"""Calls `os.path.expanduser` on install_base, install_platbase and
|
| 497 |
+
root."""
|
| 498 |
+
self._expand_attrs(['install_base', 'install_platbase', 'root'])
|
| 499 |
+
|
| 500 |
+
def expand_dirs(self):
|
| 501 |
+
"""Calls `os.path.expanduser` on install dirs."""
|
| 502 |
+
self._expand_attrs(['install_purelib', 'install_platlib',
|
| 503 |
+
'install_lib', 'install_headers',
|
| 504 |
+
'install_scripts', 'install_data',])
|
| 505 |
+
|
| 506 |
+
def convert_paths(self, *names):
|
| 507 |
+
"""Call `convert_path` over `names`."""
|
| 508 |
+
for name in names:
|
| 509 |
+
attr = "install_" + name
|
| 510 |
+
setattr(self, attr, convert_path(getattr(self, attr)))
|
| 511 |
+
|
| 512 |
+
def handle_extra_path(self):
|
| 513 |
+
"""Set `path_file` and `extra_dirs` using `extra_path`."""
|
| 514 |
+
if self.extra_path is None:
|
| 515 |
+
self.extra_path = self.distribution.extra_path
|
| 516 |
+
|
| 517 |
+
if self.extra_path is not None:
|
| 518 |
+
log.warn(
|
| 519 |
+
"Distribution option extra_path is deprecated. "
|
| 520 |
+
"See issue27919 for details."
|
| 521 |
+
)
|
| 522 |
+
if isinstance(self.extra_path, str):
|
| 523 |
+
self.extra_path = self.extra_path.split(',')
|
| 524 |
+
|
| 525 |
+
if len(self.extra_path) == 1:
|
| 526 |
+
path_file = extra_dirs = self.extra_path[0]
|
| 527 |
+
elif len(self.extra_path) == 2:
|
| 528 |
+
path_file, extra_dirs = self.extra_path
|
| 529 |
+
else:
|
| 530 |
+
raise DistutilsOptionError(
|
| 531 |
+
"'extra_path' option must be a list, tuple, or "
|
| 532 |
+
"comma-separated string with 1 or 2 elements")
|
| 533 |
+
|
| 534 |
+
# convert to local form in case Unix notation used (as it
|
| 535 |
+
# should be in setup scripts)
|
| 536 |
+
extra_dirs = convert_path(extra_dirs)
|
| 537 |
+
else:
|
| 538 |
+
path_file = None
|
| 539 |
+
extra_dirs = ''
|
| 540 |
+
|
| 541 |
+
# XXX should we warn if path_file and not extra_dirs? (in which
|
| 542 |
+
# case the path file would be harmless but pointless)
|
| 543 |
+
self.path_file = path_file
|
| 544 |
+
self.extra_dirs = extra_dirs
|
| 545 |
+
|
| 546 |
+
def change_roots(self, *names):
|
| 547 |
+
"""Change the install directories pointed by name using root."""
|
| 548 |
+
for name in names:
|
| 549 |
+
attr = "install_" + name
|
| 550 |
+
setattr(self, attr, change_root(self.root, getattr(self, attr)))
|
| 551 |
+
|
| 552 |
+
def create_home_path(self):
|
| 553 |
+
"""Create directories under ~."""
|
| 554 |
+
if not self.user:
|
| 555 |
+
return
|
| 556 |
+
home = convert_path(os.path.expanduser("~"))
|
| 557 |
+
for name, path in self.config_vars.items():
|
| 558 |
+
if path.startswith(home) and not os.path.isdir(path):
|
| 559 |
+
self.debug_print("os.makedirs('%s', 0o700)" % path)
|
| 560 |
+
os.makedirs(path, 0o700)
|
| 561 |
+
|
| 562 |
+
# -- Command execution methods -------------------------------------
|
| 563 |
+
|
| 564 |
+
def run(self):
|
| 565 |
+
"""Runs the command."""
|
| 566 |
+
# Obviously have to build before we can install
|
| 567 |
+
if not self.skip_build:
|
| 568 |
+
self.run_command('build')
|
| 569 |
+
# If we built for any other platform, we can't install.
|
| 570 |
+
build_plat = self.distribution.get_command_obj('build').plat_name
|
| 571 |
+
# check warn_dir - it is a clue that the 'install' is happening
|
| 572 |
+
# internally, and not to sys.path, so we don't check the platform
|
| 573 |
+
# matches what we are running.
|
| 574 |
+
if self.warn_dir and build_plat != get_platform():
|
| 575 |
+
raise DistutilsPlatformError("Can't install when "
|
| 576 |
+
"cross-compiling")
|
| 577 |
+
|
| 578 |
+
# Run all sub-commands (at least those that need to be run)
|
| 579 |
+
for cmd_name in self.get_sub_commands():
|
| 580 |
+
self.run_command(cmd_name)
|
| 581 |
+
|
| 582 |
+
if self.path_file:
|
| 583 |
+
self.create_path_file()
|
| 584 |
+
|
| 585 |
+
# write list of installed files, if requested.
|
| 586 |
+
if self.record:
|
| 587 |
+
outputs = self.get_outputs()
|
| 588 |
+
if self.root: # strip any package prefix
|
| 589 |
+
root_len = len(self.root)
|
| 590 |
+
for counter in range(len(outputs)):
|
| 591 |
+
outputs[counter] = outputs[counter][root_len:]
|
| 592 |
+
self.execute(write_file,
|
| 593 |
+
(self.record, outputs),
|
| 594 |
+
"writing list of installed files to '%s'" %
|
| 595 |
+
self.record)
|
| 596 |
+
|
| 597 |
+
sys_path = map(os.path.normpath, sys.path)
|
| 598 |
+
sys_path = map(os.path.normcase, sys_path)
|
| 599 |
+
install_lib = os.path.normcase(os.path.normpath(self.install_lib))
|
| 600 |
+
if (self.warn_dir and
|
| 601 |
+
not (self.path_file and self.install_path_file) and
|
| 602 |
+
install_lib not in sys_path):
|
| 603 |
+
log.debug(("modules installed to '%s', which is not in "
|
| 604 |
+
"Python's module search path (sys.path) -- "
|
| 605 |
+
"you'll have to change the search path yourself"),
|
| 606 |
+
self.install_lib)
|
| 607 |
+
|
| 608 |
+
def create_path_file(self):
|
| 609 |
+
"""Creates the .pth file"""
|
| 610 |
+
filename = os.path.join(self.install_libbase,
|
| 611 |
+
self.path_file + ".pth")
|
| 612 |
+
if self.install_path_file:
|
| 613 |
+
self.execute(write_file,
|
| 614 |
+
(filename, [self.extra_dirs]),
|
| 615 |
+
"creating %s" % filename)
|
| 616 |
+
else:
|
| 617 |
+
self.warn("path file '%s' not created" % filename)
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
# -- Reporting methods ---------------------------------------------
|
| 621 |
+
|
| 622 |
+
def get_outputs(self):
|
| 623 |
+
"""Assembles the outputs of all the sub-commands."""
|
| 624 |
+
outputs = []
|
| 625 |
+
for cmd_name in self.get_sub_commands():
|
| 626 |
+
cmd = self.get_finalized_command(cmd_name)
|
| 627 |
+
# Add the contents of cmd.get_outputs(), ensuring
|
| 628 |
+
# that outputs doesn't contain duplicate entries
|
| 629 |
+
for filename in cmd.get_outputs():
|
| 630 |
+
if filename not in outputs:
|
| 631 |
+
outputs.append(filename)
|
| 632 |
+
|
| 633 |
+
if self.path_file and self.install_path_file:
|
| 634 |
+
outputs.append(os.path.join(self.install_libbase,
|
| 635 |
+
self.path_file + ".pth"))
|
| 636 |
+
|
| 637 |
+
return outputs
|
| 638 |
+
|
| 639 |
+
def get_inputs(self):
|
| 640 |
+
"""Returns the inputs of all the sub-commands"""
|
| 641 |
+
# XXX gee, this looks familiar ;-(
|
| 642 |
+
inputs = []
|
| 643 |
+
for cmd_name in self.get_sub_commands():
|
| 644 |
+
cmd = self.get_finalized_command(cmd_name)
|
| 645 |
+
inputs.extend(cmd.get_inputs())
|
| 646 |
+
|
| 647 |
+
return inputs
|
| 648 |
+
|
| 649 |
+
# -- Predicates for sub-command list -------------------------------
|
| 650 |
+
|
| 651 |
+
def has_lib(self):
|
| 652 |
+
"""Returns true if the current distribution has any Python
|
| 653 |
+
modules to install."""
|
| 654 |
+
return (self.distribution.has_pure_modules() or
|
| 655 |
+
self.distribution.has_ext_modules())
|
| 656 |
+
|
| 657 |
+
def has_headers(self):
|
| 658 |
+
"""Returns true if the current distribution has any headers to
|
| 659 |
+
install."""
|
| 660 |
+
return self.distribution.has_headers()
|
| 661 |
+
|
| 662 |
+
def has_scripts(self):
|
| 663 |
+
"""Returns true if the current distribution has any scripts to.
|
| 664 |
+
install."""
|
| 665 |
+
return self.distribution.has_scripts()
|
| 666 |
+
|
| 667 |
+
def has_data(self):
|
| 668 |
+
"""Returns true if the current distribution has any data to.
|
| 669 |
+
install."""
|
| 670 |
+
return self.distribution.has_data_files()
|
| 671 |
+
|
| 672 |
+
# 'sub_commands': a list of commands this command might have to run to
|
| 673 |
+
# get its work done. See cmd.py for more info.
|
| 674 |
+
sub_commands = [('install_lib', has_lib),
|
| 675 |
+
('install_headers', has_headers),
|
| 676 |
+
('install_scripts', has_scripts),
|
| 677 |
+
('install_data', has_data),
|
| 678 |
+
('install_egg_info', lambda self:True),
|
| 679 |
+
]
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_data.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install_data
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install_data' command, for installing
|
| 4 |
+
platform-independent data files."""
|
| 5 |
+
|
| 6 |
+
# contributed by Bastian Kleineidam
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
from distutils.core import Command
|
| 10 |
+
from distutils.util import change_root, convert_path
|
| 11 |
+
|
| 12 |
+
class install_data(Command):
|
| 13 |
+
|
| 14 |
+
description = "install data files"
|
| 15 |
+
|
| 16 |
+
user_options = [
|
| 17 |
+
('install-dir=', 'd',
|
| 18 |
+
"base directory for installing data files "
|
| 19 |
+
"(default: installation base dir)"),
|
| 20 |
+
('root=', None,
|
| 21 |
+
"install everything relative to this alternate root directory"),
|
| 22 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
boolean_options = ['force']
|
| 26 |
+
|
| 27 |
+
def initialize_options(self):
|
| 28 |
+
self.install_dir = None
|
| 29 |
+
self.outfiles = []
|
| 30 |
+
self.root = None
|
| 31 |
+
self.force = 0
|
| 32 |
+
self.data_files = self.distribution.data_files
|
| 33 |
+
self.warn_dir = 1
|
| 34 |
+
|
| 35 |
+
def finalize_options(self):
|
| 36 |
+
self.set_undefined_options('install',
|
| 37 |
+
('install_data', 'install_dir'),
|
| 38 |
+
('root', 'root'),
|
| 39 |
+
('force', 'force'),
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
def run(self):
|
| 43 |
+
self.mkpath(self.install_dir)
|
| 44 |
+
for f in self.data_files:
|
| 45 |
+
if isinstance(f, str):
|
| 46 |
+
# it's a simple file, so copy it
|
| 47 |
+
f = convert_path(f)
|
| 48 |
+
if self.warn_dir:
|
| 49 |
+
self.warn("setup script did not provide a directory for "
|
| 50 |
+
"'%s' -- installing right in '%s'" %
|
| 51 |
+
(f, self.install_dir))
|
| 52 |
+
(out, _) = self.copy_file(f, self.install_dir)
|
| 53 |
+
self.outfiles.append(out)
|
| 54 |
+
else:
|
| 55 |
+
# it's a tuple with path to install to and a list of files
|
| 56 |
+
dir = convert_path(f[0])
|
| 57 |
+
if not os.path.isabs(dir):
|
| 58 |
+
dir = os.path.join(self.install_dir, dir)
|
| 59 |
+
elif self.root:
|
| 60 |
+
dir = change_root(self.root, dir)
|
| 61 |
+
self.mkpath(dir)
|
| 62 |
+
|
| 63 |
+
if f[1] == []:
|
| 64 |
+
# If there are no files listed, the user must be
|
| 65 |
+
# trying to create an empty directory, so add the
|
| 66 |
+
# directory to the list of output files.
|
| 67 |
+
self.outfiles.append(dir)
|
| 68 |
+
else:
|
| 69 |
+
# Copy files, adding them to the list of output files.
|
| 70 |
+
for data in f[1]:
|
| 71 |
+
data = convert_path(data)
|
| 72 |
+
(out, _) = self.copy_file(data, dir)
|
| 73 |
+
self.outfiles.append(out)
|
| 74 |
+
|
| 75 |
+
def get_inputs(self):
|
| 76 |
+
return self.data_files or []
|
| 77 |
+
|
| 78 |
+
def get_outputs(self):
|
| 79 |
+
return self.outfiles
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_egg_info.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install_egg_info
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install_egg_info' command, for installing
|
| 4 |
+
a package's PKG-INFO metadata."""
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
from distutils.cmd import Command
|
| 8 |
+
from distutils import log, dir_util
|
| 9 |
+
import os, sys, re
|
| 10 |
+
|
| 11 |
+
class install_egg_info(Command):
|
| 12 |
+
"""Install an .egg-info file for the package"""
|
| 13 |
+
|
| 14 |
+
description = "Install package's PKG-INFO metadata as an .egg-info file"
|
| 15 |
+
user_options = [
|
| 16 |
+
('install-dir=', 'd', "directory to install to"),
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
def initialize_options(self):
|
| 20 |
+
self.install_dir = None
|
| 21 |
+
|
| 22 |
+
def finalize_options(self):
|
| 23 |
+
self.set_undefined_options('install_lib',('install_dir','install_dir'))
|
| 24 |
+
basename = "%s-%s-py%d.%d.egg-info" % (
|
| 25 |
+
to_filename(safe_name(self.distribution.get_name())),
|
| 26 |
+
to_filename(safe_version(self.distribution.get_version())),
|
| 27 |
+
*sys.version_info[:2]
|
| 28 |
+
)
|
| 29 |
+
self.target = os.path.join(self.install_dir, basename)
|
| 30 |
+
self.outputs = [self.target]
|
| 31 |
+
|
| 32 |
+
def run(self):
|
| 33 |
+
target = self.target
|
| 34 |
+
if os.path.isdir(target) and not os.path.islink(target):
|
| 35 |
+
dir_util.remove_tree(target, dry_run=self.dry_run)
|
| 36 |
+
elif os.path.exists(target):
|
| 37 |
+
self.execute(os.unlink,(self.target,),"Removing "+target)
|
| 38 |
+
elif not os.path.isdir(self.install_dir):
|
| 39 |
+
self.execute(os.makedirs, (self.install_dir,),
|
| 40 |
+
"Creating "+self.install_dir)
|
| 41 |
+
log.info("Writing %s", target)
|
| 42 |
+
if not self.dry_run:
|
| 43 |
+
with open(target, 'w', encoding='UTF-8') as f:
|
| 44 |
+
self.distribution.metadata.write_pkg_file(f)
|
| 45 |
+
|
| 46 |
+
def get_outputs(self):
|
| 47 |
+
return self.outputs
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# The following routines are taken from setuptools' pkg_resources module and
|
| 51 |
+
# can be replaced by importing them from pkg_resources once it is included
|
| 52 |
+
# in the stdlib.
|
| 53 |
+
|
| 54 |
+
def safe_name(name):
|
| 55 |
+
"""Convert an arbitrary string to a standard distribution name
|
| 56 |
+
|
| 57 |
+
Any runs of non-alphanumeric/. characters are replaced with a single '-'.
|
| 58 |
+
"""
|
| 59 |
+
return re.sub('[^A-Za-z0-9.]+', '-', name)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def safe_version(version):
|
| 63 |
+
"""Convert an arbitrary string to a standard version string
|
| 64 |
+
|
| 65 |
+
Spaces become dots, and all other non-alphanumeric characters become
|
| 66 |
+
dashes, with runs of multiple dashes condensed to a single dash.
|
| 67 |
+
"""
|
| 68 |
+
version = version.replace(' ','.')
|
| 69 |
+
return re.sub('[^A-Za-z0-9.]+', '-', version)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def to_filename(name):
|
| 73 |
+
"""Convert a project or version name to its filename-escaped form
|
| 74 |
+
|
| 75 |
+
Any '-' characters are currently replaced with '_'.
|
| 76 |
+
"""
|
| 77 |
+
return name.replace('-','_')
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_headers.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install_headers
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install_headers' command, to install C/C++ header
|
| 4 |
+
files to the Python include directory."""
|
| 5 |
+
|
| 6 |
+
from distutils.core import Command
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# XXX force is never used
|
| 10 |
+
class install_headers(Command):
|
| 11 |
+
|
| 12 |
+
description = "install C/C++ header files"
|
| 13 |
+
|
| 14 |
+
user_options = [('install-dir=', 'd',
|
| 15 |
+
"directory to install header files to"),
|
| 16 |
+
('force', 'f',
|
| 17 |
+
"force installation (overwrite existing files)"),
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
boolean_options = ['force']
|
| 21 |
+
|
| 22 |
+
def initialize_options(self):
|
| 23 |
+
self.install_dir = None
|
| 24 |
+
self.force = 0
|
| 25 |
+
self.outfiles = []
|
| 26 |
+
|
| 27 |
+
def finalize_options(self):
|
| 28 |
+
self.set_undefined_options('install',
|
| 29 |
+
('install_headers', 'install_dir'),
|
| 30 |
+
('force', 'force'))
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def run(self):
|
| 34 |
+
headers = self.distribution.headers
|
| 35 |
+
if not headers:
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
self.mkpath(self.install_dir)
|
| 39 |
+
for header in headers:
|
| 40 |
+
(out, _) = self.copy_file(header, self.install_dir)
|
| 41 |
+
self.outfiles.append(out)
|
| 42 |
+
|
| 43 |
+
def get_inputs(self):
|
| 44 |
+
return self.distribution.headers or []
|
| 45 |
+
|
| 46 |
+
def get_outputs(self):
|
| 47 |
+
return self.outfiles
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_lib.py
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install_lib
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install_lib' command
|
| 4 |
+
(install all Python modules)."""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import importlib.util
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
from distutils.core import Command
|
| 11 |
+
from distutils.errors import DistutilsOptionError
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# Extension for Python source files.
|
| 15 |
+
PYTHON_SOURCE_EXTENSION = ".py"
|
| 16 |
+
|
| 17 |
+
class install_lib(Command):
|
| 18 |
+
|
| 19 |
+
description = "install all Python modules (extensions and pure Python)"
|
| 20 |
+
|
| 21 |
+
# The byte-compilation options are a tad confusing. Here are the
|
| 22 |
+
# possible scenarios:
|
| 23 |
+
# 1) no compilation at all (--no-compile --no-optimize)
|
| 24 |
+
# 2) compile .pyc only (--compile --no-optimize; default)
|
| 25 |
+
# 3) compile .pyc and "opt-1" .pyc (--compile --optimize)
|
| 26 |
+
# 4) compile "opt-1" .pyc only (--no-compile --optimize)
|
| 27 |
+
# 5) compile .pyc and "opt-2" .pyc (--compile --optimize-more)
|
| 28 |
+
# 6) compile "opt-2" .pyc only (--no-compile --optimize-more)
|
| 29 |
+
#
|
| 30 |
+
# The UI for this is two options, 'compile' and 'optimize'.
|
| 31 |
+
# 'compile' is strictly boolean, and only decides whether to
|
| 32 |
+
# generate .pyc files. 'optimize' is three-way (0, 1, or 2), and
|
| 33 |
+
# decides both whether to generate .pyc files and what level of
|
| 34 |
+
# optimization to use.
|
| 35 |
+
|
| 36 |
+
user_options = [
|
| 37 |
+
('install-dir=', 'd', "directory to install to"),
|
| 38 |
+
('build-dir=','b', "build directory (where to install from)"),
|
| 39 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
| 40 |
+
('compile', 'c', "compile .py to .pyc [default]"),
|
| 41 |
+
('no-compile', None, "don't compile .py files"),
|
| 42 |
+
('optimize=', 'O',
|
| 43 |
+
"also compile with optimization: -O1 for \"python -O\", "
|
| 44 |
+
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
|
| 45 |
+
('skip-build', None, "skip the build steps"),
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
boolean_options = ['force', 'compile', 'skip-build']
|
| 49 |
+
negative_opt = {'no-compile' : 'compile'}
|
| 50 |
+
|
| 51 |
+
def initialize_options(self):
|
| 52 |
+
# let the 'install' command dictate our installation directory
|
| 53 |
+
self.install_dir = None
|
| 54 |
+
self.build_dir = None
|
| 55 |
+
self.force = 0
|
| 56 |
+
self.compile = None
|
| 57 |
+
self.optimize = None
|
| 58 |
+
self.skip_build = None
|
| 59 |
+
|
| 60 |
+
def finalize_options(self):
|
| 61 |
+
# Get all the information we need to install pure Python modules
|
| 62 |
+
# from the umbrella 'install' command -- build (source) directory,
|
| 63 |
+
# install (target) directory, and whether to compile .py files.
|
| 64 |
+
self.set_undefined_options('install',
|
| 65 |
+
('build_lib', 'build_dir'),
|
| 66 |
+
('install_lib', 'install_dir'),
|
| 67 |
+
('force', 'force'),
|
| 68 |
+
('compile', 'compile'),
|
| 69 |
+
('optimize', 'optimize'),
|
| 70 |
+
('skip_build', 'skip_build'),
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
if self.compile is None:
|
| 74 |
+
self.compile = True
|
| 75 |
+
if self.optimize is None:
|
| 76 |
+
self.optimize = False
|
| 77 |
+
|
| 78 |
+
if not isinstance(self.optimize, int):
|
| 79 |
+
try:
|
| 80 |
+
self.optimize = int(self.optimize)
|
| 81 |
+
if self.optimize not in (0, 1, 2):
|
| 82 |
+
raise AssertionError
|
| 83 |
+
except (ValueError, AssertionError):
|
| 84 |
+
raise DistutilsOptionError("optimize must be 0, 1, or 2")
|
| 85 |
+
|
| 86 |
+
def run(self):
|
| 87 |
+
# Make sure we have built everything we need first
|
| 88 |
+
self.build()
|
| 89 |
+
|
| 90 |
+
# Install everything: simply dump the entire contents of the build
|
| 91 |
+
# directory to the installation directory (that's the beauty of
|
| 92 |
+
# having a build directory!)
|
| 93 |
+
outfiles = self.install()
|
| 94 |
+
|
| 95 |
+
# (Optionally) compile .py to .pyc
|
| 96 |
+
if outfiles is not None and self.distribution.has_pure_modules():
|
| 97 |
+
self.byte_compile(outfiles)
|
| 98 |
+
|
| 99 |
+
# -- Top-level worker functions ------------------------------------
|
| 100 |
+
# (called from 'run()')
|
| 101 |
+
|
| 102 |
+
def build(self):
|
| 103 |
+
if not self.skip_build:
|
| 104 |
+
if self.distribution.has_pure_modules():
|
| 105 |
+
self.run_command('build_py')
|
| 106 |
+
if self.distribution.has_ext_modules():
|
| 107 |
+
self.run_command('build_ext')
|
| 108 |
+
|
| 109 |
+
def install(self):
|
| 110 |
+
if os.path.isdir(self.build_dir):
|
| 111 |
+
outfiles = self.copy_tree(self.build_dir, self.install_dir)
|
| 112 |
+
else:
|
| 113 |
+
self.warn("'%s' does not exist -- no Python modules to install" %
|
| 114 |
+
self.build_dir)
|
| 115 |
+
return
|
| 116 |
+
return outfiles
|
| 117 |
+
|
| 118 |
+
def byte_compile(self, files):
|
| 119 |
+
if sys.dont_write_bytecode:
|
| 120 |
+
self.warn('byte-compiling is disabled, skipping.')
|
| 121 |
+
return
|
| 122 |
+
|
| 123 |
+
from distutils.util import byte_compile
|
| 124 |
+
|
| 125 |
+
# Get the "--root" directory supplied to the "install" command,
|
| 126 |
+
# and use it as a prefix to strip off the purported filename
|
| 127 |
+
# encoded in bytecode files. This is far from complete, but it
|
| 128 |
+
# should at least generate usable bytecode in RPM distributions.
|
| 129 |
+
install_root = self.get_finalized_command('install').root
|
| 130 |
+
|
| 131 |
+
if self.compile:
|
| 132 |
+
byte_compile(files, optimize=0,
|
| 133 |
+
force=self.force, prefix=install_root,
|
| 134 |
+
dry_run=self.dry_run)
|
| 135 |
+
if self.optimize > 0:
|
| 136 |
+
byte_compile(files, optimize=self.optimize,
|
| 137 |
+
force=self.force, prefix=install_root,
|
| 138 |
+
verbose=self.verbose, dry_run=self.dry_run)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
# -- Utility methods -----------------------------------------------
|
| 142 |
+
|
| 143 |
+
def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir):
|
| 144 |
+
if not has_any:
|
| 145 |
+
return []
|
| 146 |
+
|
| 147 |
+
build_cmd = self.get_finalized_command(build_cmd)
|
| 148 |
+
build_files = build_cmd.get_outputs()
|
| 149 |
+
build_dir = getattr(build_cmd, cmd_option)
|
| 150 |
+
|
| 151 |
+
prefix_len = len(build_dir) + len(os.sep)
|
| 152 |
+
outputs = []
|
| 153 |
+
for file in build_files:
|
| 154 |
+
outputs.append(os.path.join(output_dir, file[prefix_len:]))
|
| 155 |
+
|
| 156 |
+
return outputs
|
| 157 |
+
|
| 158 |
+
def _bytecode_filenames(self, py_filenames):
|
| 159 |
+
bytecode_files = []
|
| 160 |
+
for py_file in py_filenames:
|
| 161 |
+
# Since build_py handles package data installation, the
|
| 162 |
+
# list of outputs can contain more than just .py files.
|
| 163 |
+
# Make sure we only report bytecode for the .py files.
|
| 164 |
+
ext = os.path.splitext(os.path.normcase(py_file))[1]
|
| 165 |
+
if ext != PYTHON_SOURCE_EXTENSION:
|
| 166 |
+
continue
|
| 167 |
+
if self.compile:
|
| 168 |
+
bytecode_files.append(importlib.util.cache_from_source(
|
| 169 |
+
py_file, optimization=''))
|
| 170 |
+
if self.optimize > 0:
|
| 171 |
+
bytecode_files.append(importlib.util.cache_from_source(
|
| 172 |
+
py_file, optimization=self.optimize))
|
| 173 |
+
|
| 174 |
+
return bytecode_files
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
# -- External interface --------------------------------------------
|
| 178 |
+
# (called by outsiders)
|
| 179 |
+
|
| 180 |
+
def get_outputs(self):
|
| 181 |
+
"""Return the list of files that would be installed if this command
|
| 182 |
+
were actually run. Not affected by the "dry-run" flag or whether
|
| 183 |
+
modules have actually been built yet.
|
| 184 |
+
"""
|
| 185 |
+
pure_outputs = \
|
| 186 |
+
self._mutate_outputs(self.distribution.has_pure_modules(),
|
| 187 |
+
'build_py', 'build_lib',
|
| 188 |
+
self.install_dir)
|
| 189 |
+
if self.compile:
|
| 190 |
+
bytecode_outputs = self._bytecode_filenames(pure_outputs)
|
| 191 |
+
else:
|
| 192 |
+
bytecode_outputs = []
|
| 193 |
+
|
| 194 |
+
ext_outputs = \
|
| 195 |
+
self._mutate_outputs(self.distribution.has_ext_modules(),
|
| 196 |
+
'build_ext', 'build_lib',
|
| 197 |
+
self.install_dir)
|
| 198 |
+
|
| 199 |
+
return pure_outputs + bytecode_outputs + ext_outputs
|
| 200 |
+
|
| 201 |
+
def get_inputs(self):
|
| 202 |
+
"""Get the list of files that are input to this command, ie. the
|
| 203 |
+
files that get installed as they are named in the build tree.
|
| 204 |
+
The files in this list correspond one-to-one to the output
|
| 205 |
+
filenames returned by 'get_outputs()'.
|
| 206 |
+
"""
|
| 207 |
+
inputs = []
|
| 208 |
+
|
| 209 |
+
if self.distribution.has_pure_modules():
|
| 210 |
+
build_py = self.get_finalized_command('build_py')
|
| 211 |
+
inputs.extend(build_py.get_outputs())
|
| 212 |
+
|
| 213 |
+
if self.distribution.has_ext_modules():
|
| 214 |
+
build_ext = self.get_finalized_command('build_ext')
|
| 215 |
+
inputs.extend(build_ext.get_outputs())
|
| 216 |
+
|
| 217 |
+
return inputs
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/install_scripts.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install_scripts
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install_scripts' command, for installing
|
| 4 |
+
Python scripts."""
|
| 5 |
+
|
| 6 |
+
# contributed by Bastian Kleineidam
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
from distutils.core import Command
|
| 10 |
+
from distutils import log
|
| 11 |
+
from stat import ST_MODE
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class install_scripts(Command):
|
| 15 |
+
|
| 16 |
+
description = "install scripts (Python or otherwise)"
|
| 17 |
+
|
| 18 |
+
user_options = [
|
| 19 |
+
('install-dir=', 'd', "directory to install scripts to"),
|
| 20 |
+
('build-dir=','b', "build directory (where to install from)"),
|
| 21 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
| 22 |
+
('skip-build', None, "skip the build steps"),
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
boolean_options = ['force', 'skip-build']
|
| 26 |
+
|
| 27 |
+
def initialize_options(self):
|
| 28 |
+
self.install_dir = None
|
| 29 |
+
self.force = 0
|
| 30 |
+
self.build_dir = None
|
| 31 |
+
self.skip_build = None
|
| 32 |
+
|
| 33 |
+
def finalize_options(self):
|
| 34 |
+
self.set_undefined_options('build', ('build_scripts', 'build_dir'))
|
| 35 |
+
self.set_undefined_options('install',
|
| 36 |
+
('install_scripts', 'install_dir'),
|
| 37 |
+
('force', 'force'),
|
| 38 |
+
('skip_build', 'skip_build'),
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
def run(self):
|
| 42 |
+
if not self.skip_build:
|
| 43 |
+
self.run_command('build_scripts')
|
| 44 |
+
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
|
| 45 |
+
if os.name == 'posix':
|
| 46 |
+
# Set the executable bits (owner, group, and world) on
|
| 47 |
+
# all the scripts we just installed.
|
| 48 |
+
for file in self.get_outputs():
|
| 49 |
+
if self.dry_run:
|
| 50 |
+
log.info("changing mode of %s", file)
|
| 51 |
+
else:
|
| 52 |
+
mode = ((os.stat(file)[ST_MODE]) | 0o555) & 0o7777
|
| 53 |
+
log.info("changing mode of %s to %o", file, mode)
|
| 54 |
+
os.chmod(file, mode)
|
| 55 |
+
|
| 56 |
+
def get_inputs(self):
|
| 57 |
+
return self.distribution.scripts or []
|
| 58 |
+
|
| 59 |
+
def get_outputs(self):
|
| 60 |
+
return self.outfiles or []
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/register.py
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.register
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'register' command (register with the repository).
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
# created 2002/10/21, Richard Jones
|
| 7 |
+
|
| 8 |
+
import getpass
|
| 9 |
+
import io
|
| 10 |
+
import urllib.parse, urllib.request
|
| 11 |
+
from warnings import warn
|
| 12 |
+
|
| 13 |
+
from distutils.core import PyPIRCCommand
|
| 14 |
+
from distutils.errors import *
|
| 15 |
+
from distutils import log
|
| 16 |
+
|
| 17 |
+
class register(PyPIRCCommand):
|
| 18 |
+
|
| 19 |
+
description = ("register the distribution with the Python package index")
|
| 20 |
+
user_options = PyPIRCCommand.user_options + [
|
| 21 |
+
('list-classifiers', None,
|
| 22 |
+
'list the valid Trove classifiers'),
|
| 23 |
+
('strict', None ,
|
| 24 |
+
'Will stop the registering if the meta-data are not fully compliant')
|
| 25 |
+
]
|
| 26 |
+
boolean_options = PyPIRCCommand.boolean_options + [
|
| 27 |
+
'verify', 'list-classifiers', 'strict']
|
| 28 |
+
|
| 29 |
+
sub_commands = [('check', lambda self: True)]
|
| 30 |
+
|
| 31 |
+
def initialize_options(self):
|
| 32 |
+
PyPIRCCommand.initialize_options(self)
|
| 33 |
+
self.list_classifiers = 0
|
| 34 |
+
self.strict = 0
|
| 35 |
+
|
| 36 |
+
def finalize_options(self):
|
| 37 |
+
PyPIRCCommand.finalize_options(self)
|
| 38 |
+
# setting options for the `check` subcommand
|
| 39 |
+
check_options = {'strict': ('register', self.strict),
|
| 40 |
+
'restructuredtext': ('register', 1)}
|
| 41 |
+
self.distribution.command_options['check'] = check_options
|
| 42 |
+
|
| 43 |
+
def run(self):
|
| 44 |
+
self.finalize_options()
|
| 45 |
+
self._set_config()
|
| 46 |
+
|
| 47 |
+
# Run sub commands
|
| 48 |
+
for cmd_name in self.get_sub_commands():
|
| 49 |
+
self.run_command(cmd_name)
|
| 50 |
+
|
| 51 |
+
if self.dry_run:
|
| 52 |
+
self.verify_metadata()
|
| 53 |
+
elif self.list_classifiers:
|
| 54 |
+
self.classifiers()
|
| 55 |
+
else:
|
| 56 |
+
self.send_metadata()
|
| 57 |
+
|
| 58 |
+
def check_metadata(self):
|
| 59 |
+
"""Deprecated API."""
|
| 60 |
+
warn("distutils.command.register.check_metadata is deprecated, \
|
| 61 |
+
use the check command instead", PendingDeprecationWarning)
|
| 62 |
+
check = self.distribution.get_command_obj('check')
|
| 63 |
+
check.ensure_finalized()
|
| 64 |
+
check.strict = self.strict
|
| 65 |
+
check.restructuredtext = 1
|
| 66 |
+
check.run()
|
| 67 |
+
|
| 68 |
+
def _set_config(self):
|
| 69 |
+
''' Reads the configuration file and set attributes.
|
| 70 |
+
'''
|
| 71 |
+
config = self._read_pypirc()
|
| 72 |
+
if config != {}:
|
| 73 |
+
self.username = config['username']
|
| 74 |
+
self.password = config['password']
|
| 75 |
+
self.repository = config['repository']
|
| 76 |
+
self.realm = config['realm']
|
| 77 |
+
self.has_config = True
|
| 78 |
+
else:
|
| 79 |
+
if self.repository not in ('pypi', self.DEFAULT_REPOSITORY):
|
| 80 |
+
raise ValueError('%s not found in .pypirc' % self.repository)
|
| 81 |
+
if self.repository == 'pypi':
|
| 82 |
+
self.repository = self.DEFAULT_REPOSITORY
|
| 83 |
+
self.has_config = False
|
| 84 |
+
|
| 85 |
+
def classifiers(self):
|
| 86 |
+
''' Fetch the list of classifiers from the server.
|
| 87 |
+
'''
|
| 88 |
+
url = self.repository+'?:action=list_classifiers'
|
| 89 |
+
response = urllib.request.urlopen(url)
|
| 90 |
+
log.info(self._read_pypi_response(response))
|
| 91 |
+
|
| 92 |
+
def verify_metadata(self):
|
| 93 |
+
''' Send the metadata to the package index server to be checked.
|
| 94 |
+
'''
|
| 95 |
+
# send the info to the server and report the result
|
| 96 |
+
(code, result) = self.post_to_server(self.build_post_data('verify'))
|
| 97 |
+
log.info('Server response (%s): %s', code, result)
|
| 98 |
+
|
| 99 |
+
def send_metadata(self):
|
| 100 |
+
''' Send the metadata to the package index server.
|
| 101 |
+
|
| 102 |
+
Well, do the following:
|
| 103 |
+
1. figure who the user is, and then
|
| 104 |
+
2. send the data as a Basic auth'ed POST.
|
| 105 |
+
|
| 106 |
+
First we try to read the username/password from $HOME/.pypirc,
|
| 107 |
+
which is a ConfigParser-formatted file with a section
|
| 108 |
+
[distutils] containing username and password entries (both
|
| 109 |
+
in clear text). Eg:
|
| 110 |
+
|
| 111 |
+
[distutils]
|
| 112 |
+
index-servers =
|
| 113 |
+
pypi
|
| 114 |
+
|
| 115 |
+
[pypi]
|
| 116 |
+
username: fred
|
| 117 |
+
password: sekrit
|
| 118 |
+
|
| 119 |
+
Otherwise, to figure who the user is, we offer the user three
|
| 120 |
+
choices:
|
| 121 |
+
|
| 122 |
+
1. use existing login,
|
| 123 |
+
2. register as a new user, or
|
| 124 |
+
3. set the password to a random string and email the user.
|
| 125 |
+
|
| 126 |
+
'''
|
| 127 |
+
# see if we can short-cut and get the username/password from the
|
| 128 |
+
# config
|
| 129 |
+
if self.has_config:
|
| 130 |
+
choice = '1'
|
| 131 |
+
username = self.username
|
| 132 |
+
password = self.password
|
| 133 |
+
else:
|
| 134 |
+
choice = 'x'
|
| 135 |
+
username = password = ''
|
| 136 |
+
|
| 137 |
+
# get the user's login info
|
| 138 |
+
choices = '1 2 3 4'.split()
|
| 139 |
+
while choice not in choices:
|
| 140 |
+
self.announce('''\
|
| 141 |
+
We need to know who you are, so please choose either:
|
| 142 |
+
1. use your existing login,
|
| 143 |
+
2. register as a new user,
|
| 144 |
+
3. have the server generate a new password for you (and email it to you), or
|
| 145 |
+
4. quit
|
| 146 |
+
Your selection [default 1]: ''', log.INFO)
|
| 147 |
+
choice = input()
|
| 148 |
+
if not choice:
|
| 149 |
+
choice = '1'
|
| 150 |
+
elif choice not in choices:
|
| 151 |
+
print('Please choose one of the four options!')
|
| 152 |
+
|
| 153 |
+
if choice == '1':
|
| 154 |
+
# get the username and password
|
| 155 |
+
while not username:
|
| 156 |
+
username = input('Username: ')
|
| 157 |
+
while not password:
|
| 158 |
+
password = getpass.getpass('Password: ')
|
| 159 |
+
|
| 160 |
+
# set up the authentication
|
| 161 |
+
auth = urllib.request.HTTPPasswordMgr()
|
| 162 |
+
host = urllib.parse.urlparse(self.repository)[1]
|
| 163 |
+
auth.add_password(self.realm, host, username, password)
|
| 164 |
+
# send the info to the server and report the result
|
| 165 |
+
code, result = self.post_to_server(self.build_post_data('submit'),
|
| 166 |
+
auth)
|
| 167 |
+
self.announce('Server response (%s): %s' % (code, result),
|
| 168 |
+
log.INFO)
|
| 169 |
+
|
| 170 |
+
# possibly save the login
|
| 171 |
+
if code == 200:
|
| 172 |
+
if self.has_config:
|
| 173 |
+
# sharing the password in the distribution instance
|
| 174 |
+
# so the upload command can reuse it
|
| 175 |
+
self.distribution.password = password
|
| 176 |
+
else:
|
| 177 |
+
self.announce(('I can store your PyPI login so future '
|
| 178 |
+
'submissions will be faster.'), log.INFO)
|
| 179 |
+
self.announce('(the login will be stored in %s)' % \
|
| 180 |
+
self._get_rc_file(), log.INFO)
|
| 181 |
+
choice = 'X'
|
| 182 |
+
while choice.lower() not in 'yn':
|
| 183 |
+
choice = input('Save your login (y/N)?')
|
| 184 |
+
if not choice:
|
| 185 |
+
choice = 'n'
|
| 186 |
+
if choice.lower() == 'y':
|
| 187 |
+
self._store_pypirc(username, password)
|
| 188 |
+
|
| 189 |
+
elif choice == '2':
|
| 190 |
+
data = {':action': 'user'}
|
| 191 |
+
data['name'] = data['password'] = data['email'] = ''
|
| 192 |
+
data['confirm'] = None
|
| 193 |
+
while not data['name']:
|
| 194 |
+
data['name'] = input('Username: ')
|
| 195 |
+
while data['password'] != data['confirm']:
|
| 196 |
+
while not data['password']:
|
| 197 |
+
data['password'] = getpass.getpass('Password: ')
|
| 198 |
+
while not data['confirm']:
|
| 199 |
+
data['confirm'] = getpass.getpass(' Confirm: ')
|
| 200 |
+
if data['password'] != data['confirm']:
|
| 201 |
+
data['password'] = ''
|
| 202 |
+
data['confirm'] = None
|
| 203 |
+
print("Password and confirm don't match!")
|
| 204 |
+
while not data['email']:
|
| 205 |
+
data['email'] = input(' EMail: ')
|
| 206 |
+
code, result = self.post_to_server(data)
|
| 207 |
+
if code != 200:
|
| 208 |
+
log.info('Server response (%s): %s', code, result)
|
| 209 |
+
else:
|
| 210 |
+
log.info('You will receive an email shortly.')
|
| 211 |
+
log.info(('Follow the instructions in it to '
|
| 212 |
+
'complete registration.'))
|
| 213 |
+
elif choice == '3':
|
| 214 |
+
data = {':action': 'password_reset'}
|
| 215 |
+
data['email'] = ''
|
| 216 |
+
while not data['email']:
|
| 217 |
+
data['email'] = input('Your email address: ')
|
| 218 |
+
code, result = self.post_to_server(data)
|
| 219 |
+
log.info('Server response (%s): %s', code, result)
|
| 220 |
+
|
| 221 |
+
def build_post_data(self, action):
|
| 222 |
+
# figure the data to send - the metadata plus some additional
|
| 223 |
+
# information used by the package server
|
| 224 |
+
meta = self.distribution.metadata
|
| 225 |
+
data = {
|
| 226 |
+
':action': action,
|
| 227 |
+
'metadata_version' : '1.0',
|
| 228 |
+
'name': meta.get_name(),
|
| 229 |
+
'version': meta.get_version(),
|
| 230 |
+
'summary': meta.get_description(),
|
| 231 |
+
'home_page': meta.get_url(),
|
| 232 |
+
'author': meta.get_contact(),
|
| 233 |
+
'author_email': meta.get_contact_email(),
|
| 234 |
+
'license': meta.get_licence(),
|
| 235 |
+
'description': meta.get_long_description(),
|
| 236 |
+
'keywords': meta.get_keywords(),
|
| 237 |
+
'platform': meta.get_platforms(),
|
| 238 |
+
'classifiers': meta.get_classifiers(),
|
| 239 |
+
'download_url': meta.get_download_url(),
|
| 240 |
+
# PEP 314
|
| 241 |
+
'provides': meta.get_provides(),
|
| 242 |
+
'requires': meta.get_requires(),
|
| 243 |
+
'obsoletes': meta.get_obsoletes(),
|
| 244 |
+
}
|
| 245 |
+
if data['provides'] or data['requires'] or data['obsoletes']:
|
| 246 |
+
data['metadata_version'] = '1.1'
|
| 247 |
+
return data
|
| 248 |
+
|
| 249 |
+
def post_to_server(self, data, auth=None):
|
| 250 |
+
''' Post a query to the server, and return a string response.
|
| 251 |
+
'''
|
| 252 |
+
if 'name' in data:
|
| 253 |
+
self.announce('Registering %s to %s' % (data['name'],
|
| 254 |
+
self.repository),
|
| 255 |
+
log.INFO)
|
| 256 |
+
# Build up the MIME payload for the urllib2 POST data
|
| 257 |
+
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
|
| 258 |
+
sep_boundary = '\n--' + boundary
|
| 259 |
+
end_boundary = sep_boundary + '--'
|
| 260 |
+
body = io.StringIO()
|
| 261 |
+
for key, value in data.items():
|
| 262 |
+
# handle multiple entries for the same name
|
| 263 |
+
if type(value) not in (type([]), type( () )):
|
| 264 |
+
value = [value]
|
| 265 |
+
for value in value:
|
| 266 |
+
value = str(value)
|
| 267 |
+
body.write(sep_boundary)
|
| 268 |
+
body.write('\nContent-Disposition: form-data; name="%s"'%key)
|
| 269 |
+
body.write("\n\n")
|
| 270 |
+
body.write(value)
|
| 271 |
+
if value and value[-1] == '\r':
|
| 272 |
+
body.write('\n') # write an extra newline (lurve Macs)
|
| 273 |
+
body.write(end_boundary)
|
| 274 |
+
body.write("\n")
|
| 275 |
+
body = body.getvalue().encode("utf-8")
|
| 276 |
+
|
| 277 |
+
# build the Request
|
| 278 |
+
headers = {
|
| 279 |
+
'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%boundary,
|
| 280 |
+
'Content-length': str(len(body))
|
| 281 |
+
}
|
| 282 |
+
req = urllib.request.Request(self.repository, body, headers)
|
| 283 |
+
|
| 284 |
+
# handle HTTP and include the Basic Auth handler
|
| 285 |
+
opener = urllib.request.build_opener(
|
| 286 |
+
urllib.request.HTTPBasicAuthHandler(password_mgr=auth)
|
| 287 |
+
)
|
| 288 |
+
data = ''
|
| 289 |
+
try:
|
| 290 |
+
result = opener.open(req)
|
| 291 |
+
except urllib.error.HTTPError as e:
|
| 292 |
+
if self.show_response:
|
| 293 |
+
data = e.fp.read()
|
| 294 |
+
result = e.code, e.msg
|
| 295 |
+
except urllib.error.URLError as e:
|
| 296 |
+
result = 500, str(e)
|
| 297 |
+
else:
|
| 298 |
+
if self.show_response:
|
| 299 |
+
data = self._read_pypi_response(result)
|
| 300 |
+
result = 200, 'OK'
|
| 301 |
+
if self.show_response:
|
| 302 |
+
msg = '\n'.join(('-' * 75, data, '-' * 75))
|
| 303 |
+
self.announce(msg, log.INFO)
|
| 304 |
+
return result
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/command/sdist.py
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.sdist
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'sdist' command (create a source distribution)."""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from glob import glob
|
| 8 |
+
from warnings import warn
|
| 9 |
+
|
| 10 |
+
from distutils.core import Command
|
| 11 |
+
from distutils import dir_util
|
| 12 |
+
from distutils import file_util
|
| 13 |
+
from distutils import archive_util
|
| 14 |
+
from distutils.text_file import TextFile
|
| 15 |
+
from distutils.filelist import FileList
|
| 16 |
+
from distutils import log
|
| 17 |
+
from distutils.util import convert_path
|
| 18 |
+
from distutils.errors import DistutilsTemplateError, DistutilsOptionError
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def show_formats():
|
| 22 |
+
"""Print all possible values for the 'formats' option (used by
|
| 23 |
+
the "--help-formats" command-line option).
|
| 24 |
+
"""
|
| 25 |
+
from distutils.fancy_getopt import FancyGetopt
|
| 26 |
+
from distutils.archive_util import ARCHIVE_FORMATS
|
| 27 |
+
formats = []
|
| 28 |
+
for format in ARCHIVE_FORMATS.keys():
|
| 29 |
+
formats.append(("formats=" + format, None,
|
| 30 |
+
ARCHIVE_FORMATS[format][2]))
|
| 31 |
+
formats.sort()
|
| 32 |
+
FancyGetopt(formats).print_help(
|
| 33 |
+
"List of available source distribution formats:")
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class sdist(Command):
|
| 37 |
+
|
| 38 |
+
description = "create a source distribution (tarball, zip file, etc.)"
|
| 39 |
+
|
| 40 |
+
def checking_metadata(self):
|
| 41 |
+
"""Callable used for the check sub-command.
|
| 42 |
+
|
| 43 |
+
Placed here so user_options can view it"""
|
| 44 |
+
return self.metadata_check
|
| 45 |
+
|
| 46 |
+
user_options = [
|
| 47 |
+
('template=', 't',
|
| 48 |
+
"name of manifest template file [default: MANIFEST.in]"),
|
| 49 |
+
('manifest=', 'm',
|
| 50 |
+
"name of manifest file [default: MANIFEST]"),
|
| 51 |
+
('use-defaults', None,
|
| 52 |
+
"include the default file set in the manifest "
|
| 53 |
+
"[default; disable with --no-defaults]"),
|
| 54 |
+
('no-defaults', None,
|
| 55 |
+
"don't include the default file set"),
|
| 56 |
+
('prune', None,
|
| 57 |
+
"specifically exclude files/directories that should not be "
|
| 58 |
+
"distributed (build tree, RCS/CVS dirs, etc.) "
|
| 59 |
+
"[default; disable with --no-prune]"),
|
| 60 |
+
('no-prune', None,
|
| 61 |
+
"don't automatically exclude anything"),
|
| 62 |
+
('manifest-only', 'o',
|
| 63 |
+
"just regenerate the manifest and then stop "
|
| 64 |
+
"(implies --force-manifest)"),
|
| 65 |
+
('force-manifest', 'f',
|
| 66 |
+
"forcibly regenerate the manifest and carry on as usual. "
|
| 67 |
+
"Deprecated: now the manifest is always regenerated."),
|
| 68 |
+
('formats=', None,
|
| 69 |
+
"formats for source distribution (comma-separated list)"),
|
| 70 |
+
('keep-temp', 'k',
|
| 71 |
+
"keep the distribution tree around after creating " +
|
| 72 |
+
"archive file(s)"),
|
| 73 |
+
('dist-dir=', 'd',
|
| 74 |
+
"directory to put the source distribution archive(s) in "
|
| 75 |
+
"[default: dist]"),
|
| 76 |
+
('metadata-check', None,
|
| 77 |
+
"Ensure that all required elements of meta-data "
|
| 78 |
+
"are supplied. Warn if any missing. [default]"),
|
| 79 |
+
('owner=', 'u',
|
| 80 |
+
"Owner name used when creating a tar file [default: current user]"),
|
| 81 |
+
('group=', 'g',
|
| 82 |
+
"Group name used when creating a tar file [default: current group]"),
|
| 83 |
+
]
|
| 84 |
+
|
| 85 |
+
boolean_options = ['use-defaults', 'prune',
|
| 86 |
+
'manifest-only', 'force-manifest',
|
| 87 |
+
'keep-temp', 'metadata-check']
|
| 88 |
+
|
| 89 |
+
help_options = [
|
| 90 |
+
('help-formats', None,
|
| 91 |
+
"list available distribution formats", show_formats),
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
negative_opt = {'no-defaults': 'use-defaults',
|
| 95 |
+
'no-prune': 'prune' }
|
| 96 |
+
|
| 97 |
+
sub_commands = [('check', checking_metadata)]
|
| 98 |
+
|
| 99 |
+
READMES = ('README', 'README.txt', 'README.rst')
|
| 100 |
+
|
| 101 |
+
def initialize_options(self):
|
| 102 |
+
# 'template' and 'manifest' are, respectively, the names of
|
| 103 |
+
# the manifest template and manifest file.
|
| 104 |
+
self.template = None
|
| 105 |
+
self.manifest = None
|
| 106 |
+
|
| 107 |
+
# 'use_defaults': if true, we will include the default file set
|
| 108 |
+
# in the manifest
|
| 109 |
+
self.use_defaults = 1
|
| 110 |
+
self.prune = 1
|
| 111 |
+
|
| 112 |
+
self.manifest_only = 0
|
| 113 |
+
self.force_manifest = 0
|
| 114 |
+
|
| 115 |
+
self.formats = ['gztar']
|
| 116 |
+
self.keep_temp = 0
|
| 117 |
+
self.dist_dir = None
|
| 118 |
+
|
| 119 |
+
self.archive_files = None
|
| 120 |
+
self.metadata_check = 1
|
| 121 |
+
self.owner = None
|
| 122 |
+
self.group = None
|
| 123 |
+
|
| 124 |
+
def finalize_options(self):
|
| 125 |
+
if self.manifest is None:
|
| 126 |
+
self.manifest = "MANIFEST"
|
| 127 |
+
if self.template is None:
|
| 128 |
+
self.template = "MANIFEST.in"
|
| 129 |
+
|
| 130 |
+
self.ensure_string_list('formats')
|
| 131 |
+
|
| 132 |
+
bad_format = archive_util.check_archive_formats(self.formats)
|
| 133 |
+
if bad_format:
|
| 134 |
+
raise DistutilsOptionError(
|
| 135 |
+
"unknown archive format '%s'" % bad_format)
|
| 136 |
+
|
| 137 |
+
if self.dist_dir is None:
|
| 138 |
+
self.dist_dir = "dist"
|
| 139 |
+
|
| 140 |
+
def run(self):
|
| 141 |
+
# 'filelist' contains the list of files that will make up the
|
| 142 |
+
# manifest
|
| 143 |
+
self.filelist = FileList()
|
| 144 |
+
|
| 145 |
+
# Run sub commands
|
| 146 |
+
for cmd_name in self.get_sub_commands():
|
| 147 |
+
self.run_command(cmd_name)
|
| 148 |
+
|
| 149 |
+
# Do whatever it takes to get the list of files to process
|
| 150 |
+
# (process the manifest template, read an existing manifest,
|
| 151 |
+
# whatever). File list is accumulated in 'self.filelist'.
|
| 152 |
+
self.get_file_list()
|
| 153 |
+
|
| 154 |
+
# If user just wanted us to regenerate the manifest, stop now.
|
| 155 |
+
if self.manifest_only:
|
| 156 |
+
return
|
| 157 |
+
|
| 158 |
+
# Otherwise, go ahead and create the source distribution tarball,
|
| 159 |
+
# or zipfile, or whatever.
|
| 160 |
+
self.make_distribution()
|
| 161 |
+
|
| 162 |
+
def check_metadata(self):
|
| 163 |
+
"""Deprecated API."""
|
| 164 |
+
warn("distutils.command.sdist.check_metadata is deprecated, \
|
| 165 |
+
use the check command instead", PendingDeprecationWarning)
|
| 166 |
+
check = self.distribution.get_command_obj('check')
|
| 167 |
+
check.ensure_finalized()
|
| 168 |
+
check.run()
|
| 169 |
+
|
| 170 |
+
def get_file_list(self):
|
| 171 |
+
"""Figure out the list of files to include in the source
|
| 172 |
+
distribution, and put it in 'self.filelist'. This might involve
|
| 173 |
+
reading the manifest template (and writing the manifest), or just
|
| 174 |
+
reading the manifest, or just using the default file set -- it all
|
| 175 |
+
depends on the user's options.
|
| 176 |
+
"""
|
| 177 |
+
# new behavior when using a template:
|
| 178 |
+
# the file list is recalculated every time because
|
| 179 |
+
# even if MANIFEST.in or setup.py are not changed
|
| 180 |
+
# the user might have added some files in the tree that
|
| 181 |
+
# need to be included.
|
| 182 |
+
#
|
| 183 |
+
# This makes --force the default and only behavior with templates.
|
| 184 |
+
template_exists = os.path.isfile(self.template)
|
| 185 |
+
if not template_exists and self._manifest_is_not_generated():
|
| 186 |
+
self.read_manifest()
|
| 187 |
+
self.filelist.sort()
|
| 188 |
+
self.filelist.remove_duplicates()
|
| 189 |
+
return
|
| 190 |
+
|
| 191 |
+
if not template_exists:
|
| 192 |
+
self.warn(("manifest template '%s' does not exist " +
|
| 193 |
+
"(using default file list)") %
|
| 194 |
+
self.template)
|
| 195 |
+
self.filelist.findall()
|
| 196 |
+
|
| 197 |
+
if self.use_defaults:
|
| 198 |
+
self.add_defaults()
|
| 199 |
+
|
| 200 |
+
if template_exists:
|
| 201 |
+
self.read_template()
|
| 202 |
+
|
| 203 |
+
if self.prune:
|
| 204 |
+
self.prune_file_list()
|
| 205 |
+
|
| 206 |
+
self.filelist.sort()
|
| 207 |
+
self.filelist.remove_duplicates()
|
| 208 |
+
self.write_manifest()
|
| 209 |
+
|
| 210 |
+
def add_defaults(self):
|
| 211 |
+
"""Add all the default files to self.filelist:
|
| 212 |
+
- README or README.txt
|
| 213 |
+
- setup.py
|
| 214 |
+
- test/test*.py
|
| 215 |
+
- all pure Python modules mentioned in setup script
|
| 216 |
+
- all files pointed by package_data (build_py)
|
| 217 |
+
- all files defined in data_files.
|
| 218 |
+
- all files defined as scripts.
|
| 219 |
+
- all C sources listed as part of extensions or C libraries
|
| 220 |
+
in the setup script (doesn't catch C headers!)
|
| 221 |
+
Warns if (README or README.txt) or setup.py are missing; everything
|
| 222 |
+
else is optional.
|
| 223 |
+
"""
|
| 224 |
+
self._add_defaults_standards()
|
| 225 |
+
self._add_defaults_optional()
|
| 226 |
+
self._add_defaults_python()
|
| 227 |
+
self._add_defaults_data_files()
|
| 228 |
+
self._add_defaults_ext()
|
| 229 |
+
self._add_defaults_c_libs()
|
| 230 |
+
self._add_defaults_scripts()
|
| 231 |
+
|
| 232 |
+
@staticmethod
|
| 233 |
+
def _cs_path_exists(fspath):
|
| 234 |
+
"""
|
| 235 |
+
Case-sensitive path existence check
|
| 236 |
+
|
| 237 |
+
>>> sdist._cs_path_exists(__file__)
|
| 238 |
+
True
|
| 239 |
+
>>> sdist._cs_path_exists(__file__.upper())
|
| 240 |
+
False
|
| 241 |
+
"""
|
| 242 |
+
if not os.path.exists(fspath):
|
| 243 |
+
return False
|
| 244 |
+
# make absolute so we always have a directory
|
| 245 |
+
abspath = os.path.abspath(fspath)
|
| 246 |
+
directory, filename = os.path.split(abspath)
|
| 247 |
+
return filename in os.listdir(directory)
|
| 248 |
+
|
| 249 |
+
def _add_defaults_standards(self):
|
| 250 |
+
standards = [self.READMES, self.distribution.script_name]
|
| 251 |
+
for fn in standards:
|
| 252 |
+
if isinstance(fn, tuple):
|
| 253 |
+
alts = fn
|
| 254 |
+
got_it = False
|
| 255 |
+
for fn in alts:
|
| 256 |
+
if self._cs_path_exists(fn):
|
| 257 |
+
got_it = True
|
| 258 |
+
self.filelist.append(fn)
|
| 259 |
+
break
|
| 260 |
+
|
| 261 |
+
if not got_it:
|
| 262 |
+
self.warn("standard file not found: should have one of " +
|
| 263 |
+
', '.join(alts))
|
| 264 |
+
else:
|
| 265 |
+
if self._cs_path_exists(fn):
|
| 266 |
+
self.filelist.append(fn)
|
| 267 |
+
else:
|
| 268 |
+
self.warn("standard file '%s' not found" % fn)
|
| 269 |
+
|
| 270 |
+
def _add_defaults_optional(self):
|
| 271 |
+
optional = ['test/test*.py', 'setup.cfg']
|
| 272 |
+
for pattern in optional:
|
| 273 |
+
files = filter(os.path.isfile, glob(pattern))
|
| 274 |
+
self.filelist.extend(files)
|
| 275 |
+
|
| 276 |
+
def _add_defaults_python(self):
|
| 277 |
+
# build_py is used to get:
|
| 278 |
+
# - python modules
|
| 279 |
+
# - files defined in package_data
|
| 280 |
+
build_py = self.get_finalized_command('build_py')
|
| 281 |
+
|
| 282 |
+
# getting python files
|
| 283 |
+
if self.distribution.has_pure_modules():
|
| 284 |
+
self.filelist.extend(build_py.get_source_files())
|
| 285 |
+
|
| 286 |
+
# getting package_data files
|
| 287 |
+
# (computed in build_py.data_files by build_py.finalize_options)
|
| 288 |
+
for pkg, src_dir, build_dir, filenames in build_py.data_files:
|
| 289 |
+
for filename in filenames:
|
| 290 |
+
self.filelist.append(os.path.join(src_dir, filename))
|
| 291 |
+
|
| 292 |
+
def _add_defaults_data_files(self):
|
| 293 |
+
# getting distribution.data_files
|
| 294 |
+
if self.distribution.has_data_files():
|
| 295 |
+
for item in self.distribution.data_files:
|
| 296 |
+
if isinstance(item, str):
|
| 297 |
+
# plain file
|
| 298 |
+
item = convert_path(item)
|
| 299 |
+
if os.path.isfile(item):
|
| 300 |
+
self.filelist.append(item)
|
| 301 |
+
else:
|
| 302 |
+
# a (dirname, filenames) tuple
|
| 303 |
+
dirname, filenames = item
|
| 304 |
+
for f in filenames:
|
| 305 |
+
f = convert_path(f)
|
| 306 |
+
if os.path.isfile(f):
|
| 307 |
+
self.filelist.append(f)
|
| 308 |
+
|
| 309 |
+
def _add_defaults_ext(self):
|
| 310 |
+
if self.distribution.has_ext_modules():
|
| 311 |
+
build_ext = self.get_finalized_command('build_ext')
|
| 312 |
+
self.filelist.extend(build_ext.get_source_files())
|
| 313 |
+
|
| 314 |
+
def _add_defaults_c_libs(self):
|
| 315 |
+
if self.distribution.has_c_libraries():
|
| 316 |
+
build_clib = self.get_finalized_command('build_clib')
|
| 317 |
+
self.filelist.extend(build_clib.get_source_files())
|
| 318 |
+
|
| 319 |
+
def _add_defaults_scripts(self):
|
| 320 |
+
if self.distribution.has_scripts():
|
| 321 |
+
build_scripts = self.get_finalized_command('build_scripts')
|
| 322 |
+
self.filelist.extend(build_scripts.get_source_files())
|
| 323 |
+
|
| 324 |
+
def read_template(self):
|
| 325 |
+
"""Read and parse manifest template file named by self.template.
|
| 326 |
+
|
| 327 |
+
(usually "MANIFEST.in") The parsing and processing is done by
|
| 328 |
+
'self.filelist', which updates itself accordingly.
|
| 329 |
+
"""
|
| 330 |
+
log.info("reading manifest template '%s'", self.template)
|
| 331 |
+
template = TextFile(self.template, strip_comments=1, skip_blanks=1,
|
| 332 |
+
join_lines=1, lstrip_ws=1, rstrip_ws=1,
|
| 333 |
+
collapse_join=1)
|
| 334 |
+
|
| 335 |
+
try:
|
| 336 |
+
while True:
|
| 337 |
+
line = template.readline()
|
| 338 |
+
if line is None: # end of file
|
| 339 |
+
break
|
| 340 |
+
|
| 341 |
+
try:
|
| 342 |
+
self.filelist.process_template_line(line)
|
| 343 |
+
# the call above can raise a DistutilsTemplateError for
|
| 344 |
+
# malformed lines, or a ValueError from the lower-level
|
| 345 |
+
# convert_path function
|
| 346 |
+
except (DistutilsTemplateError, ValueError) as msg:
|
| 347 |
+
self.warn("%s, line %d: %s" % (template.filename,
|
| 348 |
+
template.current_line,
|
| 349 |
+
msg))
|
| 350 |
+
finally:
|
| 351 |
+
template.close()
|
| 352 |
+
|
| 353 |
+
def prune_file_list(self):
|
| 354 |
+
"""Prune off branches that might slip into the file list as created
|
| 355 |
+
by 'read_template()', but really don't belong there:
|
| 356 |
+
* the build tree (typically "build")
|
| 357 |
+
* the release tree itself (only an issue if we ran "sdist"
|
| 358 |
+
previously with --keep-temp, or it aborted)
|
| 359 |
+
* any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
|
| 360 |
+
"""
|
| 361 |
+
build = self.get_finalized_command('build')
|
| 362 |
+
base_dir = self.distribution.get_fullname()
|
| 363 |
+
|
| 364 |
+
self.filelist.exclude_pattern(None, prefix=build.build_base)
|
| 365 |
+
self.filelist.exclude_pattern(None, prefix=base_dir)
|
| 366 |
+
|
| 367 |
+
if sys.platform == 'win32':
|
| 368 |
+
seps = r'/|\\'
|
| 369 |
+
else:
|
| 370 |
+
seps = '/'
|
| 371 |
+
|
| 372 |
+
vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
|
| 373 |
+
'_darcs']
|
| 374 |
+
vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
|
| 375 |
+
self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)
|
| 376 |
+
|
| 377 |
+
def write_manifest(self):
|
| 378 |
+
"""Write the file list in 'self.filelist' (presumably as filled in
|
| 379 |
+
by 'add_defaults()' and 'read_template()') to the manifest file
|
| 380 |
+
named by 'self.manifest'.
|
| 381 |
+
"""
|
| 382 |
+
if self._manifest_is_not_generated():
|
| 383 |
+
log.info("not writing to manually maintained "
|
| 384 |
+
"manifest file '%s'" % self.manifest)
|
| 385 |
+
return
|
| 386 |
+
|
| 387 |
+
content = self.filelist.files[:]
|
| 388 |
+
content.insert(0, '# file GENERATED by distutils, do NOT edit')
|
| 389 |
+
self.execute(file_util.write_file, (self.manifest, content),
|
| 390 |
+
"writing manifest file '%s'" % self.manifest)
|
| 391 |
+
|
| 392 |
+
def _manifest_is_not_generated(self):
|
| 393 |
+
# check for special comment used in 3.1.3 and higher
|
| 394 |
+
if not os.path.isfile(self.manifest):
|
| 395 |
+
return False
|
| 396 |
+
|
| 397 |
+
fp = open(self.manifest)
|
| 398 |
+
try:
|
| 399 |
+
first_line = fp.readline()
|
| 400 |
+
finally:
|
| 401 |
+
fp.close()
|
| 402 |
+
return first_line != '# file GENERATED by distutils, do NOT edit\n'
|
| 403 |
+
|
| 404 |
+
def read_manifest(self):
|
| 405 |
+
"""Read the manifest file (named by 'self.manifest') and use it to
|
| 406 |
+
fill in 'self.filelist', the list of files to include in the source
|
| 407 |
+
distribution.
|
| 408 |
+
"""
|
| 409 |
+
log.info("reading manifest file '%s'", self.manifest)
|
| 410 |
+
with open(self.manifest) as manifest:
|
| 411 |
+
for line in manifest:
|
| 412 |
+
# ignore comments and blank lines
|
| 413 |
+
line = line.strip()
|
| 414 |
+
if line.startswith('#') or not line:
|
| 415 |
+
continue
|
| 416 |
+
self.filelist.append(line)
|
| 417 |
+
|
| 418 |
+
def make_release_tree(self, base_dir, files):
|
| 419 |
+
"""Create the directory tree that will become the source
|
| 420 |
+
distribution archive. All directories implied by the filenames in
|
| 421 |
+
'files' are created under 'base_dir', and then we hard link or copy
|
| 422 |
+
(if hard linking is unavailable) those files into place.
|
| 423 |
+
Essentially, this duplicates the developer's source tree, but in a
|
| 424 |
+
directory named after the distribution, containing only the files
|
| 425 |
+
to be distributed.
|
| 426 |
+
"""
|
| 427 |
+
# Create all the directories under 'base_dir' necessary to
|
| 428 |
+
# put 'files' there; the 'mkpath()' is just so we don't die
|
| 429 |
+
# if the manifest happens to be empty.
|
| 430 |
+
self.mkpath(base_dir)
|
| 431 |
+
dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
|
| 432 |
+
|
| 433 |
+
# And walk over the list of files, either making a hard link (if
|
| 434 |
+
# os.link exists) to each one that doesn't already exist in its
|
| 435 |
+
# corresponding location under 'base_dir', or copying each file
|
| 436 |
+
# that's out-of-date in 'base_dir'. (Usually, all files will be
|
| 437 |
+
# out-of-date, because by default we blow away 'base_dir' when
|
| 438 |
+
# we're done making the distribution archives.)
|
| 439 |
+
|
| 440 |
+
if hasattr(os, 'link'): # can make hard links on this system
|
| 441 |
+
link = 'hard'
|
| 442 |
+
msg = "making hard links in %s..." % base_dir
|
| 443 |
+
else: # nope, have to copy
|
| 444 |
+
link = None
|
| 445 |
+
msg = "copying files to %s..." % base_dir
|
| 446 |
+
|
| 447 |
+
if not files:
|
| 448 |
+
log.warn("no files to distribute -- empty manifest?")
|
| 449 |
+
else:
|
| 450 |
+
log.info(msg)
|
| 451 |
+
for file in files:
|
| 452 |
+
if not os.path.isfile(file):
|
| 453 |
+
log.warn("'%s' not a regular file -- skipping", file)
|
| 454 |
+
else:
|
| 455 |
+
dest = os.path.join(base_dir, file)
|
| 456 |
+
self.copy_file(file, dest, link=link)
|
| 457 |
+
|
| 458 |
+
self.distribution.metadata.write_pkg_info(base_dir)
|
| 459 |
+
|
| 460 |
+
def make_distribution(self):
|
| 461 |
+
"""Create the source distribution(s). First, we create the release
|
| 462 |
+
tree with 'make_release_tree()'; then, we create all required
|
| 463 |
+
archive files (according to 'self.formats') from the release tree.
|
| 464 |
+
Finally, we clean up by blowing away the release tree (unless
|
| 465 |
+
'self.keep_temp' is true). The list of archive files created is
|
| 466 |
+
stored so it can be retrieved later by 'get_archive_files()'.
|
| 467 |
+
"""
|
| 468 |
+
# Don't warn about missing meta-data here -- should be (and is!)
|
| 469 |
+
# done elsewhere.
|
| 470 |
+
base_dir = self.distribution.get_fullname()
|
| 471 |
+
base_name = os.path.join(self.dist_dir, base_dir)
|
| 472 |
+
|
| 473 |
+
self.make_release_tree(base_dir, self.filelist.files)
|
| 474 |
+
archive_files = [] # remember names of files we create
|
| 475 |
+
# tar archive must be created last to avoid overwrite and remove
|
| 476 |
+
if 'tar' in self.formats:
|
| 477 |
+
self.formats.append(self.formats.pop(self.formats.index('tar')))
|
| 478 |
+
|
| 479 |
+
for fmt in self.formats:
|
| 480 |
+
file = self.make_archive(base_name, fmt, base_dir=base_dir,
|
| 481 |
+
owner=self.owner, group=self.group)
|
| 482 |
+
archive_files.append(file)
|
| 483 |
+
self.distribution.dist_files.append(('sdist', '', file))
|
| 484 |
+
|
| 485 |
+
self.archive_files = archive_files
|
| 486 |
+
|
| 487 |
+
if not self.keep_temp:
|
| 488 |
+
dir_util.remove_tree(base_dir, dry_run=self.dry_run)
|
| 489 |
+
|
| 490 |
+
def get_archive_files(self):
|
| 491 |
+
"""Return the list of archive files created when the command
|
| 492 |
+
was run, or None if the command hasn't run y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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
distutils.command.upload
|
| 3 |
+
|
| 4 |
+
Implements the Distutils 'upload' subcommand (upload package to a package
|
| 5 |
+
index).
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
import io
|
| 10 |
+
import hashlib
|
| 11 |
+
from base64 import standard_b64encode
|
| 12 |
+
from urllib.error import HTTPError
|
| 13 |
+
from urllib.request import urlopen, Request
|
| 14 |
+
from urllib.parse import urlparse
|
| 15 |
+
from distutils.errors import DistutilsError, DistutilsOptionError
|
| 16 |
+
from distutils.core import PyPIRCCommand
|
| 17 |
+
from distutils.spawn import spawn
|
| 18 |
+
from distutils import log
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# PyPI Warehouse supports MD5, SHA256, and Blake2 (blake2-256)
|
| 22 |
+
# https://bugs.python.org/issue40698
|
| 23 |
+
_FILE_CONTENT_DIGESTS = {
|
| 24 |
+
"md5_digest": getattr(hashlib, "md5", None),
|
| 25 |
+
"sha256_digest": getattr(hashlib, "sha256", None),
|
| 26 |
+
"blake2_256_digest": getattr(hashlib, "blake2b", None),
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class upload(PyPIRCCommand):
|
| 31 |
+
|
| 32 |
+
description = "upload binary package to PyPI"
|
| 33 |
+
|
| 34 |
+
user_options = PyPIRCCommand.user_options + [
|
| 35 |
+
('sign', 's',
|
| 36 |
+
'sign files to upload using gpg'),
|
| 37 |
+
('identity=', 'i', 'GPG identity used to sign files'),
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
boolean_options = PyPIRCCommand.boolean_options + ['sign']
|
| 41 |
+
|
| 42 |
+
def initialize_options(self):
|
| 43 |
+
PyPIRCCommand.initialize_options(self)
|
| 44 |
+
self.username = ''
|
| 45 |
+
self.password = ''
|
| 46 |
+
self.show_response = 0
|
| 47 |
+
self.sign = False
|
| 48 |
+
self.identity = None
|
| 49 |
+
|
| 50 |
+
def finalize_options(self):
|
| 51 |
+
PyPIRCCommand.finalize_options(self)
|
| 52 |
+
if self.identity and not self.sign:
|
| 53 |
+
raise DistutilsOptionError(
|
| 54 |
+
"Must use --sign for --identity to have meaning"
|
| 55 |
+
)
|
| 56 |
+
config = self._read_pypirc()
|
| 57 |
+
if config != {}:
|
| 58 |
+
self.username = config['username']
|
| 59 |
+
self.password = config['password']
|
| 60 |
+
self.repository = config['repository']
|
| 61 |
+
self.realm = config['realm']
|
| 62 |
+
|
| 63 |
+
# getting the password from the distribution
|
| 64 |
+
# if previously set by the register command
|
| 65 |
+
if not self.password and self.distribution.password:
|
| 66 |
+
self.password = self.distribution.password
|
| 67 |
+
|
| 68 |
+
def run(self):
|
| 69 |
+
if not self.distribution.dist_files:
|
| 70 |
+
msg = ("Must create and upload files in one command "
|
| 71 |
+
"(e.g. setup.py sdist upload)")
|
| 72 |
+
raise DistutilsOptionError(msg)
|
| 73 |
+
for command, pyversion, filename in self.distribution.dist_files:
|
| 74 |
+
self.upload_file(command, pyversion, filename)
|
| 75 |
+
|
| 76 |
+
def upload_file(self, command, pyversion, filename):
|
| 77 |
+
# Makes sure the repository URL is compliant
|
| 78 |
+
schema, netloc, url, params, query, fragments = \
|
| 79 |
+
urlparse(self.repository)
|
| 80 |
+
if params or query or fragments:
|
| 81 |
+
raise AssertionError("Incompatible url %s" % self.repository)
|
| 82 |
+
|
| 83 |
+
if schema not in ('http', 'https'):
|
| 84 |
+
raise AssertionError("unsupported schema " + schema)
|
| 85 |
+
|
| 86 |
+
# Sign if requested
|
| 87 |
+
if self.sign:
|
| 88 |
+
gpg_args = ["gpg", "--detach-sign", "-a", filename]
|
| 89 |
+
if self.identity:
|
| 90 |
+
gpg_args[2:2] = ["--local-user", self.identity]
|
| 91 |
+
spawn(gpg_args,
|
| 92 |
+
dry_run=self.dry_run)
|
| 93 |
+
|
| 94 |
+
# Fill in the data - send all the meta-data in case we need to
|
| 95 |
+
# register a new release
|
| 96 |
+
f = open(filename,'rb')
|
| 97 |
+
try:
|
| 98 |
+
content = f.read()
|
| 99 |
+
finally:
|
| 100 |
+
f.close()
|
| 101 |
+
|
| 102 |
+
meta = self.distribution.metadata
|
| 103 |
+
data = {
|
| 104 |
+
# action
|
| 105 |
+
':action': 'file_upload',
|
| 106 |
+
'protocol_version': '1',
|
| 107 |
+
|
| 108 |
+
# identify release
|
| 109 |
+
'name': meta.get_name(),
|
| 110 |
+
'version': meta.get_version(),
|
| 111 |
+
|
| 112 |
+
# file content
|
| 113 |
+
'content': (os.path.basename(filename),content),
|
| 114 |
+
'filetype': command,
|
| 115 |
+
'pyversion': pyversion,
|
| 116 |
+
|
| 117 |
+
# additional meta-data
|
| 118 |
+
'metadata_version': '1.0',
|
| 119 |
+
'summary': meta.get_description(),
|
| 120 |
+
'home_page': meta.get_url(),
|
| 121 |
+
'author': meta.get_contact(),
|
| 122 |
+
'author_email': meta.get_contact_email(),
|
| 123 |
+
'license': meta.get_licence(),
|
| 124 |
+
'description': meta.get_long_description(),
|
| 125 |
+
'keywords': meta.get_keywords(),
|
| 126 |
+
'platform': meta.get_platforms(),
|
| 127 |
+
'classifiers': meta.get_classifiers(),
|
| 128 |
+
'download_url': meta.get_download_url(),
|
| 129 |
+
# PEP 314
|
| 130 |
+
'provides': meta.get_provides(),
|
| 131 |
+
'requires': meta.get_requires(),
|
| 132 |
+
'obsoletes': meta.get_obsoletes(),
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
data['comment'] = ''
|
| 136 |
+
|
| 137 |
+
# file content digests
|
| 138 |
+
for digest_name, digest_cons in _FILE_CONTENT_DIGESTS.items():
|
| 139 |
+
if digest_cons is None:
|
| 140 |
+
continue
|
| 141 |
+
try:
|
| 142 |
+
data[digest_name] = digest_cons(content).hexdigest()
|
| 143 |
+
except ValueError:
|
| 144 |
+
# hash digest not available or blocked by security policy
|
| 145 |
+
pass
|
| 146 |
+
|
| 147 |
+
if self.sign:
|
| 148 |
+
with open(filename + ".asc", "rb") as f:
|
| 149 |
+
data['gpg_signature'] = (os.path.basename(filename) + ".asc",
|
| 150 |
+
f.read())
|
| 151 |
+
|
| 152 |
+
# set up the authentication
|
| 153 |
+
user_pass = (self.username + ":" + self.password).encode('ascii')
|
| 154 |
+
# The exact encoding of the authentication string is debated.
|
| 155 |
+
# Anyway PyPI only accepts ascii for both username or password.
|
| 156 |
+
auth = "Basic " + standard_b64encode(user_pass).decode('ascii')
|
| 157 |
+
|
| 158 |
+
# Build up the MIME payload for the POST data
|
| 159 |
+
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
|
| 160 |
+
sep_boundary = b'\r\n--' + boundary.encode('ascii')
|
| 161 |
+
end_boundary = sep_boundary + b'--\r\n'
|
| 162 |
+
body = io.BytesIO()
|
| 163 |
+
for key, value in data.items():
|
| 164 |
+
title = '\r\nContent-Disposition: form-data; name="%s"' % key
|
| 165 |
+
# handle multiple entries for the same name
|
| 166 |
+
if not isinstance(value, list):
|
| 167 |
+
value = [value]
|
| 168 |
+
for value in value:
|
| 169 |
+
if type(value) is tuple:
|
| 170 |
+
title += '; filename="%s"' % value[0]
|
| 171 |
+
value = value[1]
|
| 172 |
+
else:
|
| 173 |
+
value = str(value).encode('utf-8')
|
| 174 |
+
body.write(sep_boundary)
|
| 175 |
+
body.write(title.encode('utf-8'))
|
| 176 |
+
body.write(b"\r\n\r\n")
|
| 177 |
+
body.write(value)
|
| 178 |
+
body.write(end_boundary)
|
| 179 |
+
body = body.getvalue()
|
| 180 |
+
|
| 181 |
+
msg = "Submitting %s to %s" % (filename, self.repository)
|
| 182 |
+
self.announce(msg, log.INFO)
|
| 183 |
+
|
| 184 |
+
# build the Request
|
| 185 |
+
headers = {
|
| 186 |
+
'Content-type': 'multipart/form-data; boundary=%s' % boundary,
|
| 187 |
+
'Content-length': str(len(body)),
|
| 188 |
+
'Authorization': auth,
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
request = Request(self.repository, data=body,
|
| 192 |
+
headers=headers)
|
| 193 |
+
# send the data
|
| 194 |
+
try:
|
| 195 |
+
result = urlopen(request)
|
| 196 |
+
status = result.getcode()
|
| 197 |
+
reason = result.msg
|
| 198 |
+
except HTTPError as e:
|
| 199 |
+
status = e.code
|
| 200 |
+
reason = e.msg
|
| 201 |
+
except OSError as e:
|
| 202 |
+
self.announce(str(e), log.ERROR)
|
| 203 |
+
raise
|
| 204 |
+
|
| 205 |
+
if status == 200:
|
| 206 |
+
self.announce('Server response (%s): %s' % (status, reason),
|
| 207 |
+
log.INFO)
|
| 208 |
+
if self.show_response:
|
| 209 |
+
text = self._read_pypi_response(result)
|
| 210 |
+
msg = '\n'.join(('-' * 75, text, '-' * 75))
|
| 211 |
+
self.announce(msg, log.INFO)
|
| 212 |
+
else:
|
| 213 |
+
msg = 'Upload failed (%s): %s' % (status, reason)
|
| 214 |
+
self.announce(msg, log.ERROR)
|
| 215 |
+
raise DistutilsError(msg)
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/config.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.pypirc
|
| 2 |
+
|
| 3 |
+
Provides the PyPIRCCommand class, the base class for the command classes
|
| 4 |
+
that uses .pypirc in the distutils.command package.
|
| 5 |
+
"""
|
| 6 |
+
import os
|
| 7 |
+
from configparser import RawConfigParser
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
from distutils.cmd import Command
|
| 11 |
+
|
| 12 |
+
DEFAULT_PYPIRC = """\
|
| 13 |
+
[distutils]
|
| 14 |
+
index-servers =
|
| 15 |
+
pypi
|
| 16 |
+
|
| 17 |
+
[pypi]
|
| 18 |
+
username:%s
|
| 19 |
+
password:%s
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
class PyPIRCCommand(Command):
|
| 23 |
+
"""Base command that knows how to handle the .pypirc file
|
| 24 |
+
"""
|
| 25 |
+
DEFAULT_REPOSITORY = 'https://upload.pypi.org/legacy/'
|
| 26 |
+
DEFAULT_REALM = 'pypi'
|
| 27 |
+
repository = None
|
| 28 |
+
realm = None
|
| 29 |
+
|
| 30 |
+
user_options = [
|
| 31 |
+
('repository=', 'r',
|
| 32 |
+
"url of repository [default: %s]" % \
|
| 33 |
+
DEFAULT_REPOSITORY),
|
| 34 |
+
('show-response', None,
|
| 35 |
+
'display full response text from server')]
|
| 36 |
+
|
| 37 |
+
boolean_options = ['show-response']
|
| 38 |
+
|
| 39 |
+
def _get_rc_file(self):
|
| 40 |
+
"""Returns rc file path."""
|
| 41 |
+
return os.path.join(os.path.expanduser('~'), '.pypirc')
|
| 42 |
+
|
| 43 |
+
def _store_pypirc(self, username, password):
|
| 44 |
+
"""Creates a default .pypirc file."""
|
| 45 |
+
rc = self._get_rc_file()
|
| 46 |
+
with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
|
| 47 |
+
f.write(DEFAULT_PYPIRC % (username, password))
|
| 48 |
+
|
| 49 |
+
def _read_pypirc(self):
|
| 50 |
+
"""Reads the .pypirc file."""
|
| 51 |
+
rc = self._get_rc_file()
|
| 52 |
+
if os.path.exists(rc):
|
| 53 |
+
self.announce('Using PyPI login from %s' % rc)
|
| 54 |
+
repository = self.repository or self.DEFAULT_REPOSITORY
|
| 55 |
+
|
| 56 |
+
config = RawConfigParser()
|
| 57 |
+
config.read(rc)
|
| 58 |
+
sections = config.sections()
|
| 59 |
+
if 'distutils' in sections:
|
| 60 |
+
# let's get the list of servers
|
| 61 |
+
index_servers = config.get('distutils', 'index-servers')
|
| 62 |
+
_servers = [server.strip() for server in
|
| 63 |
+
index_servers.split('\n')
|
| 64 |
+
if server.strip() != '']
|
| 65 |
+
if _servers == []:
|
| 66 |
+
# nothing set, let's try to get the default pypi
|
| 67 |
+
if 'pypi' in sections:
|
| 68 |
+
_servers = ['pypi']
|
| 69 |
+
else:
|
| 70 |
+
# the file is not properly defined, returning
|
| 71 |
+
# an empty dict
|
| 72 |
+
return {}
|
| 73 |
+
for server in _servers:
|
| 74 |
+
current = {'server': server}
|
| 75 |
+
current['username'] = config.get(server, 'username')
|
| 76 |
+
|
| 77 |
+
# optional params
|
| 78 |
+
for key, default in (('repository',
|
| 79 |
+
self.DEFAULT_REPOSITORY),
|
| 80 |
+
('realm', self.DEFAULT_REALM),
|
| 81 |
+
('password', None)):
|
| 82 |
+
if config.has_option(server, key):
|
| 83 |
+
current[key] = config.get(server, key)
|
| 84 |
+
else:
|
| 85 |
+
current[key] = default
|
| 86 |
+
|
| 87 |
+
# work around people having "repository" for the "pypi"
|
| 88 |
+
# section of their config set to the HTTP (rather than
|
| 89 |
+
# HTTPS) URL
|
| 90 |
+
if (server == 'pypi' and
|
| 91 |
+
repository in (self.DEFAULT_REPOSITORY, 'pypi')):
|
| 92 |
+
current['repository'] = self.DEFAULT_REPOSITORY
|
| 93 |
+
return current
|
| 94 |
+
|
| 95 |
+
if (current['server'] == repository or
|
| 96 |
+
current['repository'] == repository):
|
| 97 |
+
return current
|
| 98 |
+
elif 'server-login' in sections:
|
| 99 |
+
# old format
|
| 100 |
+
server = 'server-login'
|
| 101 |
+
if config.has_option(server, 'repository'):
|
| 102 |
+
repository = config.get(server, 'repository')
|
| 103 |
+
else:
|
| 104 |
+
repository = self.DEFAULT_REPOSITORY
|
| 105 |
+
return {'username': config.get(server, 'username'),
|
| 106 |
+
'password': config.get(server, 'password'),
|
| 107 |
+
'repository': repository,
|
| 108 |
+
'server': server,
|
| 109 |
+
'realm': self.DEFAULT_REALM}
|
| 110 |
+
|
| 111 |
+
return {}
|
| 112 |
+
|
| 113 |
+
def _read_pypi_response(self, response):
|
| 114 |
+
"""Read and decode a PyPI HTTP response."""
|
| 115 |
+
with warnings.catch_warnings():
|
| 116 |
+
warnings.simplefilter("ignore", DeprecationWarning)
|
| 117 |
+
import cgi
|
| 118 |
+
content_type = response.getheader('content-type', 'text/plain')
|
| 119 |
+
encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
|
| 120 |
+
return response.read().decode(encoding)
|
| 121 |
+
|
| 122 |
+
def initialize_options(self):
|
| 123 |
+
"""Initialize options."""
|
| 124 |
+
self.repository = None
|
| 125 |
+
self.realm = None
|
| 126 |
+
self.show_response = 0
|
| 127 |
+
|
| 128 |
+
def finalize_options(self):
|
| 129 |
+
"""Finalizes options."""
|
| 130 |
+
if self.repository is None:
|
| 131 |
+
self.repository = self.DEFAULT_REPOSITORY
|
| 132 |
+
if self.realm is None:
|
| 133 |
+
self.realm = self.DEFAULT_REALM
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/core.py
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.core
|
| 2 |
+
|
| 3 |
+
The only module that needs to be imported to use the Distutils; provides
|
| 4 |
+
the 'setup' function (which is to be called from the setup script). Also
|
| 5 |
+
indirectly provides the Distribution and Command classes, although they are
|
| 6 |
+
really defined in distutils.dist and distutils.cmd.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
from distutils.debug import DEBUG
|
| 13 |
+
from distutils.errors import *
|
| 14 |
+
|
| 15 |
+
# Mainly import these so setup scripts can "from distutils.core import" them.
|
| 16 |
+
from distutils.dist import Distribution
|
| 17 |
+
from distutils.cmd import Command
|
| 18 |
+
from distutils.config import PyPIRCCommand
|
| 19 |
+
from distutils.extension import Extension
|
| 20 |
+
|
| 21 |
+
# This is a barebones help message generated displayed when the user
|
| 22 |
+
# runs the setup script with no arguments at all. More useful help
|
| 23 |
+
# is generated with various --help options: global help, list commands,
|
| 24 |
+
# and per-command help.
|
| 25 |
+
USAGE = """\
|
| 26 |
+
usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
|
| 27 |
+
or: %(script)s --help [cmd1 cmd2 ...]
|
| 28 |
+
or: %(script)s --help-commands
|
| 29 |
+
or: %(script)s cmd --help
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def gen_usage (script_name):
|
| 33 |
+
script = os.path.basename(script_name)
|
| 34 |
+
return USAGE % vars()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
|
| 38 |
+
_setup_stop_after = None
|
| 39 |
+
_setup_distribution = None
|
| 40 |
+
|
| 41 |
+
# Legal keyword arguments for the setup() function
|
| 42 |
+
setup_keywords = ('distclass', 'script_name', 'script_args', 'options',
|
| 43 |
+
'name', 'version', 'author', 'author_email',
|
| 44 |
+
'maintainer', 'maintainer_email', 'url', 'license',
|
| 45 |
+
'description', 'long_description', 'keywords',
|
| 46 |
+
'platforms', 'classifiers', 'download_url',
|
| 47 |
+
'requires', 'provides', 'obsoletes',
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Legal keyword arguments for the Extension constructor
|
| 51 |
+
extension_keywords = ('name', 'sources', 'include_dirs',
|
| 52 |
+
'define_macros', 'undef_macros',
|
| 53 |
+
'library_dirs', 'libraries', 'runtime_library_dirs',
|
| 54 |
+
'extra_objects', 'extra_compile_args', 'extra_link_args',
|
| 55 |
+
'swig_opts', 'export_symbols', 'depends', 'language')
|
| 56 |
+
|
| 57 |
+
def setup (**attrs):
|
| 58 |
+
"""The gateway to the Distutils: do everything your setup script needs
|
| 59 |
+
to do, in a highly flexible and user-driven way. Briefly: create a
|
| 60 |
+
Distribution instance; find and parse config files; parse the command
|
| 61 |
+
line; run each Distutils command found there, customized by the options
|
| 62 |
+
supplied to 'setup()' (as keyword arguments), in config files, and on
|
| 63 |
+
the command line.
|
| 64 |
+
|
| 65 |
+
The Distribution instance might be an instance of a class supplied via
|
| 66 |
+
the 'distclass' keyword argument to 'setup'; if no such class is
|
| 67 |
+
supplied, then the Distribution class (in dist.py) is instantiated.
|
| 68 |
+
All other arguments to 'setup' (except for 'cmdclass') are used to set
|
| 69 |
+
attributes of the Distribution instance.
|
| 70 |
+
|
| 71 |
+
The 'cmdclass' argument, if supplied, is a dictionary mapping command
|
| 72 |
+
names to command classes. Each command encountered on the command line
|
| 73 |
+
will be turned into a command class, which is in turn instantiated; any
|
| 74 |
+
class found in 'cmdclass' is used in place of the default, which is
|
| 75 |
+
(for command 'foo_bar') class 'foo_bar' in module
|
| 76 |
+
'distutils.command.foo_bar'. The command class must provide a
|
| 77 |
+
'user_options' attribute which is a list of option specifiers for
|
| 78 |
+
'distutils.fancy_getopt'. Any command-line options between the current
|
| 79 |
+
and the next command are used to set attributes of the current command
|
| 80 |
+
object.
|
| 81 |
+
|
| 82 |
+
When the entire command-line has been successfully parsed, calls the
|
| 83 |
+
'run()' method on each command object in turn. This method will be
|
| 84 |
+
driven entirely by the Distribution object (which each command object
|
| 85 |
+
has a reference to, thanks to its constructor), and the
|
| 86 |
+
command-specific options that became attributes of each command
|
| 87 |
+
object.
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
global _setup_stop_after, _setup_distribution
|
| 91 |
+
|
| 92 |
+
# Determine the distribution class -- either caller-supplied or
|
| 93 |
+
# our Distribution (see below).
|
| 94 |
+
klass = attrs.get('distclass')
|
| 95 |
+
if klass:
|
| 96 |
+
del attrs['distclass']
|
| 97 |
+
else:
|
| 98 |
+
klass = Distribution
|
| 99 |
+
|
| 100 |
+
if 'script_name' not in attrs:
|
| 101 |
+
attrs['script_name'] = os.path.basename(sys.argv[0])
|
| 102 |
+
if 'script_args' not in attrs:
|
| 103 |
+
attrs['script_args'] = sys.argv[1:]
|
| 104 |
+
|
| 105 |
+
# Create the Distribution instance, using the remaining arguments
|
| 106 |
+
# (ie. everything except distclass) to initialize it
|
| 107 |
+
try:
|
| 108 |
+
_setup_distribution = dist = klass(attrs)
|
| 109 |
+
except DistutilsSetupError as msg:
|
| 110 |
+
if 'name' not in attrs:
|
| 111 |
+
raise SystemExit("error in setup command: %s" % msg)
|
| 112 |
+
else:
|
| 113 |
+
raise SystemExit("error in %s setup command: %s" % \
|
| 114 |
+
(attrs['name'], msg))
|
| 115 |
+
|
| 116 |
+
if _setup_stop_after == "init":
|
| 117 |
+
return dist
|
| 118 |
+
|
| 119 |
+
# Find and parse the config file(s): they will override options from
|
| 120 |
+
# the setup script, but be overridden by the command line.
|
| 121 |
+
dist.parse_config_files()
|
| 122 |
+
|
| 123 |
+
if DEBUG:
|
| 124 |
+
print("options (after parsing config files):")
|
| 125 |
+
dist.dump_option_dicts()
|
| 126 |
+
|
| 127 |
+
if _setup_stop_after == "config":
|
| 128 |
+
return dist
|
| 129 |
+
|
| 130 |
+
# Parse the command line and override config files; any
|
| 131 |
+
# command-line errors are the end user's fault, so turn them into
|
| 132 |
+
# SystemExit to suppress tracebacks.
|
| 133 |
+
try:
|
| 134 |
+
ok = dist.parse_command_line()
|
| 135 |
+
except DistutilsArgError as msg:
|
| 136 |
+
raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg)
|
| 137 |
+
|
| 138 |
+
if DEBUG:
|
| 139 |
+
print("options (after parsing command line):")
|
| 140 |
+
dist.dump_option_dicts()
|
| 141 |
+
|
| 142 |
+
if _setup_stop_after == "commandline":
|
| 143 |
+
return dist
|
| 144 |
+
|
| 145 |
+
# And finally, run all the commands found on the command line.
|
| 146 |
+
if ok:
|
| 147 |
+
try:
|
| 148 |
+
dist.run_commands()
|
| 149 |
+
except KeyboardInterrupt:
|
| 150 |
+
raise SystemExit("interrupted")
|
| 151 |
+
except OSError as exc:
|
| 152 |
+
if DEBUG:
|
| 153 |
+
sys.stderr.write("error: %s\n" % (exc,))
|
| 154 |
+
raise
|
| 155 |
+
else:
|
| 156 |
+
raise SystemExit("error: %s" % (exc,))
|
| 157 |
+
|
| 158 |
+
except (DistutilsError,
|
| 159 |
+
CCompilerError) as msg:
|
| 160 |
+
if DEBUG:
|
| 161 |
+
raise
|
| 162 |
+
else:
|
| 163 |
+
raise SystemExit("error: " + str(msg))
|
| 164 |
+
|
| 165 |
+
return dist
|
| 166 |
+
|
| 167 |
+
# setup ()
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def run_setup (script_name, script_args=None, stop_after="run"):
|
| 171 |
+
"""Run a setup script in a somewhat controlled environment, and
|
| 172 |
+
return the Distribution instance that drives things. This is useful
|
| 173 |
+
if you need to find out the distribution meta-data (passed as
|
| 174 |
+
keyword args from 'script' to 'setup()', or the contents of the
|
| 175 |
+
config files or command-line.
|
| 176 |
+
|
| 177 |
+
'script_name' is a file that will be read and run with 'exec()';
|
| 178 |
+
'sys.argv[0]' will be replaced with 'script' for the duration of the
|
| 179 |
+
call. 'script_args' is a list of strings; if supplied,
|
| 180 |
+
'sys.argv[1:]' will be replaced by 'script_args' for the duration of
|
| 181 |
+
the call.
|
| 182 |
+
|
| 183 |
+
'stop_after' tells 'setup()' when to stop processing; possible
|
| 184 |
+
values:
|
| 185 |
+
init
|
| 186 |
+
stop after the Distribution instance has been created and
|
| 187 |
+
populated with the keyword arguments to 'setup()'
|
| 188 |
+
config
|
| 189 |
+
stop after config files have been parsed (and their data
|
| 190 |
+
stored in the Distribution instance)
|
| 191 |
+
commandline
|
| 192 |
+
stop after the command-line ('sys.argv[1:]' or 'script_args')
|
| 193 |
+
have been parsed (and the data stored in the Distribution)
|
| 194 |
+
run [default]
|
| 195 |
+
stop after all commands have been run (the same as if 'setup()'
|
| 196 |
+
had been called in the usual way
|
| 197 |
+
|
| 198 |
+
Returns the Distribution instance, which provides all information
|
| 199 |
+
used to drive the Distutils.
|
| 200 |
+
"""
|
| 201 |
+
if stop_after not in ('init', 'config', 'commandline', 'run'):
|
| 202 |
+
raise ValueError("invalid value for 'stop_after': %r" % (stop_after,))
|
| 203 |
+
|
| 204 |
+
global _setup_stop_after, _setup_distribution
|
| 205 |
+
_setup_stop_after = stop_after
|
| 206 |
+
|
| 207 |
+
save_argv = sys.argv.copy()
|
| 208 |
+
g = {'__file__': script_name}
|
| 209 |
+
try:
|
| 210 |
+
try:
|
| 211 |
+
sys.argv[0] = script_name
|
| 212 |
+
if script_args is not None:
|
| 213 |
+
sys.argv[1:] = script_args
|
| 214 |
+
with open(script_name, 'rb') as f:
|
| 215 |
+
exec(f.read(), g)
|
| 216 |
+
finally:
|
| 217 |
+
sys.argv = save_argv
|
| 218 |
+
_setup_stop_after = None
|
| 219 |
+
except SystemExit:
|
| 220 |
+
# Hmm, should we do something if exiting with a non-zero code
|
| 221 |
+
# (ie. error)?
|
| 222 |
+
pass
|
| 223 |
+
|
| 224 |
+
if _setup_distribution is None:
|
| 225 |
+
raise RuntimeError(("'distutils.core.setup()' was never called -- "
|
| 226 |
+
"perhaps '%s' is not a Distutils setup script?") % \
|
| 227 |
+
script_name)
|
| 228 |
+
|
| 229 |
+
# I wonder if the setup script's namespace -- g and l -- would be of
|
| 230 |
+
# any interest to callers?
|
| 231 |
+
#print "_setup_distribution:", _setup_distribution
|
| 232 |
+
return _setup_distribution
|
| 233 |
+
|
| 234 |
+
# run_setup ()
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/cygwinccompiler.py
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.cygwinccompiler
|
| 2 |
+
|
| 3 |
+
Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
|
| 4 |
+
handles the Cygwin port of the GNU C compiler to Windows. It also contains
|
| 5 |
+
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
|
| 6 |
+
cygwin in no-cygwin mode).
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
# problems:
|
| 10 |
+
#
|
| 11 |
+
# * if you use a msvc compiled python version (1.5.2)
|
| 12 |
+
# 1. you have to insert a __GNUC__ section in its config.h
|
| 13 |
+
# 2. you have to generate an import library for its dll
|
| 14 |
+
# - create a def-file for python??.dll
|
| 15 |
+
# - create an import library using
|
| 16 |
+
# dlltool --dllname python15.dll --def python15.def \
|
| 17 |
+
# --output-lib libpython15.a
|
| 18 |
+
#
|
| 19 |
+
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
| 20 |
+
#
|
| 21 |
+
# * We put export_symbols in a def-file, and don't use
|
| 22 |
+
# --export-all-symbols because it doesn't worked reliable in some
|
| 23 |
+
# tested configurations. And because other windows compilers also
|
| 24 |
+
# need their symbols specified this no serious problem.
|
| 25 |
+
#
|
| 26 |
+
# tested configurations:
|
| 27 |
+
#
|
| 28 |
+
# * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works
|
| 29 |
+
# (after patching python's config.h and for C++ some other include files)
|
| 30 |
+
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
| 31 |
+
# * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works
|
| 32 |
+
# (ld doesn't support -shared, so we use dllwrap)
|
| 33 |
+
# * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now
|
| 34 |
+
# - its dllwrap doesn't work, there is a bug in binutils 2.10.90
|
| 35 |
+
# see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html
|
| 36 |
+
# - using gcc -mdll instead dllwrap doesn't work without -static because
|
| 37 |
+
# it tries to link against dlls instead their import libraries. (If
|
| 38 |
+
# it finds the dll first.)
|
| 39 |
+
# By specifying -static we force ld to link against the import libraries,
|
| 40 |
+
# this is windows standard and there are normally not the necessary symbols
|
| 41 |
+
# in the dlls.
|
| 42 |
+
# *** only the version of June 2000 shows these problems
|
| 43 |
+
# * cygwin gcc 3.2/ld 2.13.90 works
|
| 44 |
+
# (ld supports -shared)
|
| 45 |
+
# * mingw gcc 3.2/ld 2.13 works
|
| 46 |
+
# (ld supports -shared)
|
| 47 |
+
|
| 48 |
+
import os
|
| 49 |
+
import sys
|
| 50 |
+
import copy
|
| 51 |
+
from subprocess import Popen, PIPE, check_output
|
| 52 |
+
import re
|
| 53 |
+
|
| 54 |
+
from distutils.unixccompiler import UnixCCompiler
|
| 55 |
+
from distutils.file_util import write_file
|
| 56 |
+
from distutils.errors import (DistutilsExecError, CCompilerError,
|
| 57 |
+
CompileError, UnknownFileError)
|
| 58 |
+
from distutils.version import LooseVersion
|
| 59 |
+
from distutils.spawn import find_executable
|
| 60 |
+
|
| 61 |
+
def get_msvcr():
|
| 62 |
+
"""Include the appropriate MSVC runtime library if Python was built
|
| 63 |
+
with MSVC 7.0 or later.
|
| 64 |
+
"""
|
| 65 |
+
msc_pos = sys.version.find('MSC v.')
|
| 66 |
+
if msc_pos != -1:
|
| 67 |
+
msc_ver = sys.version[msc_pos+6:msc_pos+10]
|
| 68 |
+
if msc_ver == '1300':
|
| 69 |
+
# MSVC 7.0
|
| 70 |
+
return ['msvcr70']
|
| 71 |
+
elif msc_ver == '1310':
|
| 72 |
+
# MSVC 7.1
|
| 73 |
+
return ['msvcr71']
|
| 74 |
+
elif msc_ver == '1400':
|
| 75 |
+
# VS2005 / MSVC 8.0
|
| 76 |
+
return ['msvcr80']
|
| 77 |
+
elif msc_ver == '1500':
|
| 78 |
+
# VS2008 / MSVC 9.0
|
| 79 |
+
return ['msvcr90']
|
| 80 |
+
elif msc_ver == '1600':
|
| 81 |
+
# VS2010 / MSVC 10.0
|
| 82 |
+
return ['msvcr100']
|
| 83 |
+
elif int(msc_ver) >= 1900:
|
| 84 |
+
# VS2015 / MSVC 14.0
|
| 85 |
+
return ['msvcr140']
|
| 86 |
+
else:
|
| 87 |
+
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class CygwinCCompiler(UnixCCompiler):
|
| 91 |
+
""" Handles the Cygwin port of the GNU C compiler to Windows.
|
| 92 |
+
"""
|
| 93 |
+
compiler_type = 'cygwin'
|
| 94 |
+
obj_extension = ".o"
|
| 95 |
+
static_lib_extension = ".a"
|
| 96 |
+
shared_lib_extension = ".dll"
|
| 97 |
+
static_lib_format = "lib%s%s"
|
| 98 |
+
shared_lib_format = "%s%s"
|
| 99 |
+
exe_extension = ".exe"
|
| 100 |
+
|
| 101 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 102 |
+
|
| 103 |
+
UnixCCompiler.__init__(self, verbose, dry_run, force)
|
| 104 |
+
|
| 105 |
+
status, details = check_config_h()
|
| 106 |
+
self.debug_print("Python's GCC status: %s (details: %s)" %
|
| 107 |
+
(status, details))
|
| 108 |
+
if status is not CONFIG_H_OK:
|
| 109 |
+
self.warn(
|
| 110 |
+
"Python's pyconfig.h doesn't seem to support your compiler. "
|
| 111 |
+
"Reason: %s. "
|
| 112 |
+
"Compiling may fail because of undefined preprocessor macros."
|
| 113 |
+
% details)
|
| 114 |
+
|
| 115 |
+
self.gcc_version, self.ld_version, self.dllwrap_version = \
|
| 116 |
+
get_versions()
|
| 117 |
+
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
|
| 118 |
+
(self.gcc_version,
|
| 119 |
+
self.ld_version,
|
| 120 |
+
self.dllwrap_version) )
|
| 121 |
+
|
| 122 |
+
# ld_version >= "2.10.90" and < "2.13" should also be able to use
|
| 123 |
+
# gcc -mdll instead of dllwrap
|
| 124 |
+
# Older dllwraps had own version numbers, newer ones use the
|
| 125 |
+
# same as the rest of binutils ( also ld )
|
| 126 |
+
# dllwrap 2.10.90 is buggy
|
| 127 |
+
if self.ld_version >= "2.10.90":
|
| 128 |
+
self.linker_dll = "gcc"
|
| 129 |
+
else:
|
| 130 |
+
self.linker_dll = "dllwrap"
|
| 131 |
+
|
| 132 |
+
# ld_version >= "2.13" support -shared so use it instead of
|
| 133 |
+
# -mdll -static
|
| 134 |
+
if self.ld_version >= "2.13":
|
| 135 |
+
shared_option = "-shared"
|
| 136 |
+
else:
|
| 137 |
+
shared_option = "-mdll -static"
|
| 138 |
+
|
| 139 |
+
# Hard-code GCC because that's what this is all about.
|
| 140 |
+
# XXX optimization, warnings etc. should be customizable.
|
| 141 |
+
self.set_executables(compiler='gcc -mcygwin -O -Wall',
|
| 142 |
+
compiler_so='gcc -mcygwin -mdll -O -Wall',
|
| 143 |
+
compiler_cxx='g++ -mcygwin -O -Wall',
|
| 144 |
+
linker_exe='gcc -mcygwin',
|
| 145 |
+
linker_so=('%s -mcygwin %s' %
|
| 146 |
+
(self.linker_dll, shared_option)))
|
| 147 |
+
|
| 148 |
+
# cygwin and mingw32 need different sets of libraries
|
| 149 |
+
if self.gcc_version == "2.91.57":
|
| 150 |
+
# cygwin shouldn't need msvcrt, but without the dlls will crash
|
| 151 |
+
# (gcc version 2.91.57) -- perhaps something about initialization
|
| 152 |
+
self.dll_libraries=["msvcrt"]
|
| 153 |
+
self.warn(
|
| 154 |
+
"Consider upgrading to a newer version of gcc")
|
| 155 |
+
else:
|
| 156 |
+
# Include the appropriate MSVC runtime library if Python was built
|
| 157 |
+
# with MSVC 7.0 or later.
|
| 158 |
+
self.dll_libraries = get_msvcr()
|
| 159 |
+
|
| 160 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 161 |
+
"""Compiles the source by spawning GCC and windres if needed."""
|
| 162 |
+
if ext == '.rc' or ext == '.res':
|
| 163 |
+
# gcc needs '.res' and '.rc' compiled to object files !!!
|
| 164 |
+
try:
|
| 165 |
+
self.spawn(["windres", "-i", src, "-o", obj])
|
| 166 |
+
except DistutilsExecError as msg:
|
| 167 |
+
raise CompileError(msg)
|
| 168 |
+
else: # for other files use the C-compiler
|
| 169 |
+
try:
|
| 170 |
+
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
|
| 171 |
+
extra_postargs)
|
| 172 |
+
except DistutilsExecError as msg:
|
| 173 |
+
raise CompileError(msg)
|
| 174 |
+
|
| 175 |
+
def link(self, target_desc, objects, output_filename, output_dir=None,
|
| 176 |
+
libraries=None, library_dirs=None, runtime_library_dirs=None,
|
| 177 |
+
export_symbols=None, debug=0, extra_preargs=None,
|
| 178 |
+
extra_postargs=None, build_temp=None, target_lang=None):
|
| 179 |
+
"""Link the objects."""
|
| 180 |
+
# use separate copies, so we can modify the lists
|
| 181 |
+
extra_preargs = copy.copy(extra_preargs or [])
|
| 182 |
+
libraries = copy.copy(libraries or [])
|
| 183 |
+
objects = copy.copy(objects or [])
|
| 184 |
+
|
| 185 |
+
# Additional libraries
|
| 186 |
+
libraries.extend(self.dll_libraries)
|
| 187 |
+
|
| 188 |
+
# handle export symbols by creating a def-file
|
| 189 |
+
# with executables this only works with gcc/ld as linker
|
| 190 |
+
if ((export_symbols is not None) and
|
| 191 |
+
(target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
| 192 |
+
# (The linker doesn't do anything if output is up-to-date.
|
| 193 |
+
# So it would probably better to check if we really need this,
|
| 194 |
+
# but for this we had to insert some unchanged parts of
|
| 195 |
+
# UnixCCompiler, and this is not what we want.)
|
| 196 |
+
|
| 197 |
+
# we want to put some files in the same directory as the
|
| 198 |
+
# object files are, build_temp doesn't help much
|
| 199 |
+
# where are the object files
|
| 200 |
+
temp_dir = os.path.dirname(objects[0])
|
| 201 |
+
# name of dll to give the helper files the same base name
|
| 202 |
+
(dll_name, dll_extension) = os.path.splitext(
|
| 203 |
+
os.path.basename(output_filename))
|
| 204 |
+
|
| 205 |
+
# generate the filenames for these files
|
| 206 |
+
def_file = os.path.join(temp_dir, dll_name + ".def")
|
| 207 |
+
lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
|
| 208 |
+
|
| 209 |
+
# Generate .def file
|
| 210 |
+
contents = [
|
| 211 |
+
"LIBRARY %s" % os.path.basename(output_filename),
|
| 212 |
+
"EXPORTS"]
|
| 213 |
+
for sym in export_symbols:
|
| 214 |
+
contents.append(sym)
|
| 215 |
+
self.execute(write_file, (def_file, contents),
|
| 216 |
+
"writing %s" % def_file)
|
| 217 |
+
|
| 218 |
+
# next add options for def-file and to creating import libraries
|
| 219 |
+
|
| 220 |
+
# dllwrap uses different options than gcc/ld
|
| 221 |
+
if self.linker_dll == "dllwrap":
|
| 222 |
+
extra_preargs.extend(["--output-lib", lib_file])
|
| 223 |
+
# for dllwrap we have to use a special option
|
| 224 |
+
extra_preargs.extend(["--def", def_file])
|
| 225 |
+
# we use gcc/ld here and can be sure ld is >= 2.9.10
|
| 226 |
+
else:
|
| 227 |
+
# doesn't work: bfd_close build\...\libfoo.a: Invalid operation
|
| 228 |
+
#extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
|
| 229 |
+
# for gcc/ld the def-file is specified as any object files
|
| 230 |
+
objects.append(def_file)
|
| 231 |
+
|
| 232 |
+
#end: if ((export_symbols is not None) and
|
| 233 |
+
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
| 234 |
+
|
| 235 |
+
# who wants symbols and a many times larger output file
|
| 236 |
+
# should explicitly switch the debug mode on
|
| 237 |
+
# otherwise we let dllwrap/ld strip the output file
|
| 238 |
+
# (On my machine: 10KiB < stripped_file < ??100KiB
|
| 239 |
+
# unstripped_file = stripped_file + XXX KiB
|
| 240 |
+
# ( XXX=254 for a typical python extension))
|
| 241 |
+
if not debug:
|
| 242 |
+
extra_preargs.append("-s")
|
| 243 |
+
|
| 244 |
+
UnixCCompiler.link(self, target_desc, objects, output_filename,
|
| 245 |
+
output_dir, libraries, library_dirs,
|
| 246 |
+
runtime_library_dirs,
|
| 247 |
+
None, # export_symbols, we do this in our def-file
|
| 248 |
+
debug, extra_preargs, extra_postargs, build_temp,
|
| 249 |
+
target_lang)
|
| 250 |
+
|
| 251 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 252 |
+
|
| 253 |
+
def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
| 254 |
+
"""Adds supports for rc and res files."""
|
| 255 |
+
if output_dir is None:
|
| 256 |
+
output_dir = ''
|
| 257 |
+
obj_names = []
|
| 258 |
+
for src_name in source_filenames:
|
| 259 |
+
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
| 260 |
+
base, ext = os.path.splitext(os.path.normcase(src_name))
|
| 261 |
+
if ext not in (self.src_extensions + ['.rc','.res']):
|
| 262 |
+
raise UnknownFileError("unknown file type '%s' (from '%s')" % \
|
| 263 |
+
(ext, src_name))
|
| 264 |
+
if strip_dir:
|
| 265 |
+
base = os.path.basename (base)
|
| 266 |
+
if ext in ('.res', '.rc'):
|
| 267 |
+
# these need to be compiled to object files
|
| 268 |
+
obj_names.append (os.path.join(output_dir,
|
| 269 |
+
base + ext + self.obj_extension))
|
| 270 |
+
else:
|
| 271 |
+
obj_names.append (os.path.join(output_dir,
|
| 272 |
+
base + self.obj_extension))
|
| 273 |
+
return obj_names
|
| 274 |
+
|
| 275 |
+
# the same as cygwin plus some additional parameters
|
| 276 |
+
class Mingw32CCompiler(CygwinCCompiler):
|
| 277 |
+
""" Handles the Mingw32 port of the GNU C compiler to Windows.
|
| 278 |
+
"""
|
| 279 |
+
compiler_type = 'mingw32'
|
| 280 |
+
|
| 281 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 282 |
+
|
| 283 |
+
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
|
| 284 |
+
|
| 285 |
+
# ld_version >= "2.13" support -shared so use it instead of
|
| 286 |
+
# -mdll -static
|
| 287 |
+
if self.ld_version >= "2.13":
|
| 288 |
+
shared_option = "-shared"
|
| 289 |
+
else:
|
| 290 |
+
shared_option = "-mdll -static"
|
| 291 |
+
|
| 292 |
+
# A real mingw32 doesn't need to specify a different entry point,
|
| 293 |
+
# but cygwin 2.91.57 in no-cygwin-mode needs it.
|
| 294 |
+
if self.gcc_version <= "2.91.57":
|
| 295 |
+
entry_point = '--entry _DllMain@12'
|
| 296 |
+
else:
|
| 297 |
+
entry_point = ''
|
| 298 |
+
|
| 299 |
+
if is_cygwingcc():
|
| 300 |
+
raise CCompilerError(
|
| 301 |
+
'Cygwin gcc cannot be used with --compiler=mingw32')
|
| 302 |
+
|
| 303 |
+
self.set_executables(compiler='gcc -O -Wall',
|
| 304 |
+
compiler_so='gcc -mdll -O -Wall',
|
| 305 |
+
compiler_cxx='g++ -O -Wall',
|
| 306 |
+
linker_exe='gcc',
|
| 307 |
+
linker_so='%s %s %s'
|
| 308 |
+
% (self.linker_dll, shared_option,
|
| 309 |
+
entry_point))
|
| 310 |
+
# Maybe we should also append -mthreads, but then the finished
|
| 311 |
+
# dlls need another dll (mingwm10.dll see Mingw32 docs)
|
| 312 |
+
# (-mthreads: Support thread-safe exception handling on `Mingw32')
|
| 313 |
+
|
| 314 |
+
# no additional libraries needed
|
| 315 |
+
self.dll_libraries=[]
|
| 316 |
+
|
| 317 |
+
# Include the appropriate MSVC runtime library if Python was built
|
| 318 |
+
# with MSVC 7.0 or later.
|
| 319 |
+
self.dll_libraries = get_msvcr()
|
| 320 |
+
|
| 321 |
+
# Because these compilers aren't configured in Python's pyconfig.h file by
|
| 322 |
+
# default, we should at least warn the user if he is using an unmodified
|
| 323 |
+
# version.
|
| 324 |
+
|
| 325 |
+
CONFIG_H_OK = "ok"
|
| 326 |
+
CONFIG_H_NOTOK = "not ok"
|
| 327 |
+
CONFIG_H_UNCERTAIN = "uncertain"
|
| 328 |
+
|
| 329 |
+
def check_config_h():
|
| 330 |
+
"""Check if the current Python installation appears amenable to building
|
| 331 |
+
extensions with GCC.
|
| 332 |
+
|
| 333 |
+
Returns a tuple (status, details), where 'status' is one of the following
|
| 334 |
+
constants:
|
| 335 |
+
|
| 336 |
+
- CONFIG_H_OK: all is well, go ahead and compile
|
| 337 |
+
- CONFIG_H_NOTOK: doesn't look good
|
| 338 |
+
- CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
|
| 339 |
+
|
| 340 |
+
'details' is a human-readable string explaining the situation.
|
| 341 |
+
|
| 342 |
+
Note there are two ways to conclude "OK": either 'sys.version' contains
|
| 343 |
+
the string "GCC" (implying that this Python was built with GCC), or the
|
| 344 |
+
installed "pyconfig.h" contains the string "__GNUC__".
|
| 345 |
+
"""
|
| 346 |
+
|
| 347 |
+
# XXX since this function also checks sys.version, it's not strictly a
|
| 348 |
+
# "pyconfig.h" check -- should probably be renamed...
|
| 349 |
+
|
| 350 |
+
from distutils import sysconfig
|
| 351 |
+
|
| 352 |
+
# if sys.version contains GCC then python was compiled with GCC, and the
|
| 353 |
+
# pyconfig.h file should be OK
|
| 354 |
+
if "GCC" in sys.version:
|
| 355 |
+
return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
| 356 |
+
|
| 357 |
+
# let's see if __GNUC__ is mentioned in python.h
|
| 358 |
+
fn = sysconfig.get_config_h_filename()
|
| 359 |
+
try:
|
| 360 |
+
config_h = open(fn)
|
| 361 |
+
try:
|
| 362 |
+
if "__GNUC__" in config_h.read():
|
| 363 |
+
return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn
|
| 364 |
+
else:
|
| 365 |
+
return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
|
| 366 |
+
finally:
|
| 367 |
+
config_h.close()
|
| 368 |
+
except OSError as exc:
|
| 369 |
+
return (CONFIG_H_UNCERTAIN,
|
| 370 |
+
"couldn't read '%s': %s" % (fn, exc.strerror))
|
| 371 |
+
|
| 372 |
+
RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
|
| 373 |
+
|
| 374 |
+
def _find_exe_version(cmd):
|
| 375 |
+
"""Find the version of an executable by running `cmd` in the shell.
|
| 376 |
+
|
| 377 |
+
If the command is not found, or the output does not match
|
| 378 |
+
`RE_VERSION`, returns None.
|
| 379 |
+
"""
|
| 380 |
+
executable = cmd.split()[0]
|
| 381 |
+
if find_executable(executable) is None:
|
| 382 |
+
return None
|
| 383 |
+
out = Popen(cmd, shell=True, stdout=PIPE).stdout
|
| 384 |
+
try:
|
| 385 |
+
out_string = out.read()
|
| 386 |
+
finally:
|
| 387 |
+
out.close()
|
| 388 |
+
result = RE_VERSION.search(out_string)
|
| 389 |
+
if result is None:
|
| 390 |
+
return None
|
| 391 |
+
# LooseVersion works with strings
|
| 392 |
+
# so we need to decode our bytes
|
| 393 |
+
return LooseVersion(result.group(1).decode())
|
| 394 |
+
|
| 395 |
+
def get_versions():
|
| 396 |
+
""" Try to find out the versions of gcc, ld and dllwrap.
|
| 397 |
+
|
| 398 |
+
If not possible it returns None for it.
|
| 399 |
+
"""
|
| 400 |
+
commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
|
| 401 |
+
return tuple([_find_exe_version(cmd) for cmd in commands])
|
| 402 |
+
|
| 403 |
+
def is_cygwingcc():
|
| 404 |
+
'''Try to determine if the gcc that would be used is from cygwin.'''
|
| 405 |
+
out_string = check_output(['gcc', '-dumpmachine'])
|
| 406 |
+
return out_string.strip().endswith(b'cygwin')
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/debug.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# If DISTUTILS_DEBUG is anything other than the empty string, we run in
|
| 4 |
+
# debug mode.
|
| 5 |
+
DEBUG = os.environ.get('DISTUTILS_DEBUG')
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/dep_util.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.dep_util
|
| 2 |
+
|
| 3 |
+
Utility functions for simple, timestamp-based dependency of files
|
| 4 |
+
and groups of files; also, function based entirely on such
|
| 5 |
+
timestamp dependency analysis."""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from distutils.errors import DistutilsFileError
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def newer (source, target):
|
| 12 |
+
"""Return true if 'source' exists and is more recently modified than
|
| 13 |
+
'target', or if 'source' exists and 'target' doesn't. Return false if
|
| 14 |
+
both exist and 'target' is the same age or younger than 'source'.
|
| 15 |
+
Raise DistutilsFileError if 'source' does not exist.
|
| 16 |
+
"""
|
| 17 |
+
if not os.path.exists(source):
|
| 18 |
+
raise DistutilsFileError("file '%s' does not exist" %
|
| 19 |
+
os.path.abspath(source))
|
| 20 |
+
if not os.path.exists(target):
|
| 21 |
+
return 1
|
| 22 |
+
|
| 23 |
+
from stat import ST_MTIME
|
| 24 |
+
mtime1 = os.stat(source)[ST_MTIME]
|
| 25 |
+
mtime2 = os.stat(target)[ST_MTIME]
|
| 26 |
+
|
| 27 |
+
return mtime1 > mtime2
|
| 28 |
+
|
| 29 |
+
# newer ()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def newer_pairwise (sources, targets):
|
| 33 |
+
"""Walk two filename lists in parallel, testing if each source is newer
|
| 34 |
+
than its corresponding target. Return a pair of lists (sources,
|
| 35 |
+
targets) where source is newer than target, according to the semantics
|
| 36 |
+
of 'newer()'.
|
| 37 |
+
"""
|
| 38 |
+
if len(sources) != len(targets):
|
| 39 |
+
raise ValueError("'sources' and 'targets' must be same length")
|
| 40 |
+
|
| 41 |
+
# build a pair of lists (sources, targets) where source is newer
|
| 42 |
+
n_sources = []
|
| 43 |
+
n_targets = []
|
| 44 |
+
for i in range(len(sources)):
|
| 45 |
+
if newer(sources[i], targets[i]):
|
| 46 |
+
n_sources.append(sources[i])
|
| 47 |
+
n_targets.append(targets[i])
|
| 48 |
+
|
| 49 |
+
return (n_sources, n_targets)
|
| 50 |
+
|
| 51 |
+
# newer_pairwise ()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def newer_group (sources, target, missing='error'):
|
| 55 |
+
"""Return true if 'target' is out-of-date with respect to any file
|
| 56 |
+
listed in 'sources'. In other words, if 'target' exists and is newer
|
| 57 |
+
than every file in 'sources', return false; otherwise return true.
|
| 58 |
+
'missing' controls what we do when a source file is missing; the
|
| 59 |
+
default ("error") is to blow up with an OSError from inside 'stat()';
|
| 60 |
+
if it is "ignore", we silently drop any missing source files; if it is
|
| 61 |
+
"newer", any missing source files make us assume that 'target' is
|
| 62 |
+
out-of-date (this is handy in "dry-run" mode: it'll make you pretend to
|
| 63 |
+
carry out commands that wouldn't work because inputs are missing, but
|
| 64 |
+
that doesn't matter because you're not actually going to run the
|
| 65 |
+
commands).
|
| 66 |
+
"""
|
| 67 |
+
# If the target doesn't even exist, then it's definitely out-of-date.
|
| 68 |
+
if not os.path.exists(target):
|
| 69 |
+
return 1
|
| 70 |
+
|
| 71 |
+
# Otherwise we have to find out the hard way: if *any* source file
|
| 72 |
+
# is more recent than 'target', then 'target' is out-of-date and
|
| 73 |
+
# we can immediately return true. If we fall through to the end
|
| 74 |
+
# of the loop, then 'target' is up-to-date and we return false.
|
| 75 |
+
from stat import ST_MTIME
|
| 76 |
+
target_mtime = os.stat(target)[ST_MTIME]
|
| 77 |
+
for source in sources:
|
| 78 |
+
if not os.path.exists(source):
|
| 79 |
+
if missing == 'error': # blow up when we stat() the file
|
| 80 |
+
pass
|
| 81 |
+
elif missing == 'ignore': # missing source dropped from
|
| 82 |
+
continue # target's dependency list
|
| 83 |
+
elif missing == 'newer': # missing source means target is
|
| 84 |
+
return 1 # out-of-date
|
| 85 |
+
|
| 86 |
+
source_mtime = os.stat(source)[ST_MTIME]
|
| 87 |
+
if source_mtime > target_mtime:
|
| 88 |
+
return 1
|
| 89 |
+
else:
|
| 90 |
+
return 0
|
| 91 |
+
|
| 92 |
+
# newer_group ()
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/dir_util.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/dist.py
ADDED
|
@@ -0,0 +1,1256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.dist
|
| 2 |
+
|
| 3 |
+
Provides the Distribution class, which represents the module distribution
|
| 4 |
+
being built/installed/distributed.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import re
|
| 10 |
+
from email import message_from_file
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
import warnings
|
| 14 |
+
except ImportError:
|
| 15 |
+
warnings = None
|
| 16 |
+
|
| 17 |
+
from distutils.errors import *
|
| 18 |
+
from distutils.fancy_getopt import FancyGetopt, translate_longopt
|
| 19 |
+
from distutils.util import check_environ, strtobool, rfc822_escape
|
| 20 |
+
from distutils import log
|
| 21 |
+
from distutils.debug import DEBUG
|
| 22 |
+
|
| 23 |
+
# Regex to define acceptable Distutils command names. This is not *quite*
|
| 24 |
+
# the same as a Python NAME -- I don't allow leading underscores. The fact
|
| 25 |
+
# that they're very similar is no coincidence; the default naming scheme is
|
| 26 |
+
# to look for a Python module named after the command.
|
| 27 |
+
command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _ensure_list(value, fieldname):
|
| 31 |
+
if isinstance(value, str):
|
| 32 |
+
# a string containing comma separated values is okay. It will
|
| 33 |
+
# be converted to a list by Distribution.finalize_options().
|
| 34 |
+
pass
|
| 35 |
+
elif not isinstance(value, list):
|
| 36 |
+
# passing a tuple or an iterator perhaps, warn and convert
|
| 37 |
+
typename = type(value).__name__
|
| 38 |
+
msg = f"Warning: '{fieldname}' should be a list, got type '{typename}'"
|
| 39 |
+
log.log(log.WARN, msg)
|
| 40 |
+
value = list(value)
|
| 41 |
+
return value
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class Distribution:
|
| 45 |
+
"""The core of the Distutils. Most of the work hiding behind 'setup'
|
| 46 |
+
is really done within a Distribution instance, which farms the work out
|
| 47 |
+
to the Distutils commands specified on the command line.
|
| 48 |
+
|
| 49 |
+
Setup scripts will almost never instantiate Distribution directly,
|
| 50 |
+
unless the 'setup()' function is totally inadequate to their needs.
|
| 51 |
+
However, it is conceivable that a setup script might wish to subclass
|
| 52 |
+
Distribution for some specialized purpose, and then pass the subclass
|
| 53 |
+
to 'setup()' as the 'distclass' keyword argument. If so, it is
|
| 54 |
+
necessary to respect the expectations that 'setup' has of Distribution.
|
| 55 |
+
See the code for 'setup()', in core.py, for details.
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
# 'global_options' describes the command-line options that may be
|
| 59 |
+
# supplied to the setup script prior to any actual commands.
|
| 60 |
+
# Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
|
| 61 |
+
# these global options. This list should be kept to a bare minimum,
|
| 62 |
+
# since every global option is also valid as a command option -- and we
|
| 63 |
+
# don't want to pollute the commands with too many options that they
|
| 64 |
+
# have minimal control over.
|
| 65 |
+
# The fourth entry for verbose means that it can be repeated.
|
| 66 |
+
global_options = [
|
| 67 |
+
('verbose', 'v', "run verbosely (default)", 1),
|
| 68 |
+
('quiet', 'q', "run quietly (turns verbosity off)"),
|
| 69 |
+
('dry-run', 'n', "don't actually do anything"),
|
| 70 |
+
('help', 'h', "show detailed help message"),
|
| 71 |
+
('no-user-cfg', None,
|
| 72 |
+
'ignore pydistutils.cfg in your home directory'),
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
# 'common_usage' is a short (2-3 line) string describing the common
|
| 76 |
+
# usage of the setup script.
|
| 77 |
+
common_usage = """\
|
| 78 |
+
Common commands: (see '--help-commands' for more)
|
| 79 |
+
|
| 80 |
+
setup.py build will build the package underneath 'build/'
|
| 81 |
+
setup.py install will install the package
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
# options that are not propagated to the commands
|
| 85 |
+
display_options = [
|
| 86 |
+
('help-commands', None,
|
| 87 |
+
"list all available commands"),
|
| 88 |
+
('name', None,
|
| 89 |
+
"print package name"),
|
| 90 |
+
('version', 'V',
|
| 91 |
+
"print package version"),
|
| 92 |
+
('fullname', None,
|
| 93 |
+
"print <package name>-<version>"),
|
| 94 |
+
('author', None,
|
| 95 |
+
"print the author's name"),
|
| 96 |
+
('author-email', None,
|
| 97 |
+
"print the author's email address"),
|
| 98 |
+
('maintainer', None,
|
| 99 |
+
"print the maintainer's name"),
|
| 100 |
+
('maintainer-email', None,
|
| 101 |
+
"print the maintainer's email address"),
|
| 102 |
+
('contact', None,
|
| 103 |
+
"print the maintainer's name if known, else the author's"),
|
| 104 |
+
('contact-email', None,
|
| 105 |
+
"print the maintainer's email address if known, else the author's"),
|
| 106 |
+
('url', None,
|
| 107 |
+
"print the URL for this package"),
|
| 108 |
+
('license', None,
|
| 109 |
+
"print the license of the package"),
|
| 110 |
+
('licence', None,
|
| 111 |
+
"alias for --license"),
|
| 112 |
+
('description', None,
|
| 113 |
+
"print the package description"),
|
| 114 |
+
('long-description', None,
|
| 115 |
+
"print the long package description"),
|
| 116 |
+
('platforms', None,
|
| 117 |
+
"print the list of platforms"),
|
| 118 |
+
('classifiers', None,
|
| 119 |
+
"print the list of classifiers"),
|
| 120 |
+
('keywords', None,
|
| 121 |
+
"print the list of keywords"),
|
| 122 |
+
('provides', None,
|
| 123 |
+
"print the list of packages/modules provided"),
|
| 124 |
+
('requires', None,
|
| 125 |
+
"print the list of packages/modules required"),
|
| 126 |
+
('obsoletes', None,
|
| 127 |
+
"print the list of packages/modules made obsolete")
|
| 128 |
+
]
|
| 129 |
+
display_option_names = [translate_longopt(x[0]) for x in display_options]
|
| 130 |
+
|
| 131 |
+
# negative options are options that exclude other options
|
| 132 |
+
negative_opt = {'quiet': 'verbose'}
|
| 133 |
+
|
| 134 |
+
# -- Creation/initialization methods -------------------------------
|
| 135 |
+
|
| 136 |
+
def __init__(self, attrs=None):
|
| 137 |
+
"""Construct a new Distribution instance: initialize all the
|
| 138 |
+
attributes of a Distribution, and then use 'attrs' (a dictionary
|
| 139 |
+
mapping attribute names to values) to assign some of those
|
| 140 |
+
attributes their "real" values. (Any attributes not mentioned in
|
| 141 |
+
'attrs' will be assigned to some null value: 0, None, an empty list
|
| 142 |
+
or dictionary, etc.) Most importantly, initialize the
|
| 143 |
+
'command_obj' attribute to the empty dictionary; this will be
|
| 144 |
+
filled in with real command objects by 'parse_command_line()'.
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
# Default values for our command-line options
|
| 148 |
+
self.verbose = 1
|
| 149 |
+
self.dry_run = 0
|
| 150 |
+
self.help = 0
|
| 151 |
+
for attr in self.display_option_names:
|
| 152 |
+
setattr(self, attr, 0)
|
| 153 |
+
|
| 154 |
+
# Store the distribution meta-data (name, version, author, and so
|
| 155 |
+
# forth) in a separate object -- we're getting to have enough
|
| 156 |
+
# information here (and enough command-line options) that it's
|
| 157 |
+
# worth it. Also delegate 'get_XXX()' methods to the 'metadata'
|
| 158 |
+
# object in a sneaky and underhanded (but efficient!) way.
|
| 159 |
+
self.metadata = DistributionMetadata()
|
| 160 |
+
for basename in self.metadata._METHOD_BASENAMES:
|
| 161 |
+
method_name = "get_" + basename
|
| 162 |
+
setattr(self, method_name, getattr(self.metadata, method_name))
|
| 163 |
+
|
| 164 |
+
# 'cmdclass' maps command names to class objects, so we
|
| 165 |
+
# can 1) quickly figure out which class to instantiate when
|
| 166 |
+
# we need to create a new command object, and 2) have a way
|
| 167 |
+
# for the setup script to override command classes
|
| 168 |
+
self.cmdclass = {}
|
| 169 |
+
|
| 170 |
+
# 'command_packages' is a list of packages in which commands
|
| 171 |
+
# are searched for. The factory for command 'foo' is expected
|
| 172 |
+
# to be named 'foo' in the module 'foo' in one of the packages
|
| 173 |
+
# named here. This list is searched from the left; an error
|
| 174 |
+
# is raised if no named package provides the command being
|
| 175 |
+
# searched for. (Always access using get_command_packages().)
|
| 176 |
+
self.command_packages = None
|
| 177 |
+
|
| 178 |
+
# 'script_name' and 'script_args' are usually set to sys.argv[0]
|
| 179 |
+
# and sys.argv[1:], but they can be overridden when the caller is
|
| 180 |
+
# not necessarily a setup script run from the command-line.
|
| 181 |
+
self.script_name = None
|
| 182 |
+
self.script_args = None
|
| 183 |
+
|
| 184 |
+
# 'command_options' is where we store command options between
|
| 185 |
+
# parsing them (from config files, the command-line, etc.) and when
|
| 186 |
+
# they are actually needed -- ie. when the command in question is
|
| 187 |
+
# instantiated. It is a dictionary of dictionaries of 2-tuples:
|
| 188 |
+
# command_options = { command_name : { option : (source, value) } }
|
| 189 |
+
self.command_options = {}
|
| 190 |
+
|
| 191 |
+
# 'dist_files' is the list of (command, pyversion, file) that
|
| 192 |
+
# have been created by any dist commands run so far. This is
|
| 193 |
+
# filled regardless of whether the run is dry or not. pyversion
|
| 194 |
+
# gives sysconfig.get_python_version() if the dist file is
|
| 195 |
+
# specific to a Python version, 'any' if it is good for all
|
| 196 |
+
# Python versions on the target platform, and '' for a source
|
| 197 |
+
# file. pyversion should not be used to specify minimum or
|
| 198 |
+
# maximum required Python versions; use the metainfo for that
|
| 199 |
+
# instead.
|
| 200 |
+
self.dist_files = []
|
| 201 |
+
|
| 202 |
+
# These options are really the business of various commands, rather
|
| 203 |
+
# than of the Distribution itself. We provide aliases for them in
|
| 204 |
+
# Distribution as a convenience to the developer.
|
| 205 |
+
self.packages = None
|
| 206 |
+
self.package_data = {}
|
| 207 |
+
self.package_dir = None
|
| 208 |
+
self.py_modules = None
|
| 209 |
+
self.libraries = None
|
| 210 |
+
self.headers = None
|
| 211 |
+
self.ext_modules = None
|
| 212 |
+
self.ext_package = None
|
| 213 |
+
self.include_dirs = None
|
| 214 |
+
self.extra_path = None
|
| 215 |
+
self.scripts = None
|
| 216 |
+
self.data_files = None
|
| 217 |
+
self.password = ''
|
| 218 |
+
|
| 219 |
+
# And now initialize bookkeeping stuff that can't be supplied by
|
| 220 |
+
# the caller at all. 'command_obj' maps command names to
|
| 221 |
+
# Command instances -- that's how we enforce that every command
|
| 222 |
+
# class is a singleton.
|
| 223 |
+
self.command_obj = {}
|
| 224 |
+
|
| 225 |
+
# 'have_run' maps command names to boolean values; it keeps track
|
| 226 |
+
# of whether we have actually run a particular command, to make it
|
| 227 |
+
# cheap to "run" a command whenever we think we might need to -- if
|
| 228 |
+
# it's already been done, no need for expensive filesystem
|
| 229 |
+
# operations, we just check the 'have_run' dictionary and carry on.
|
| 230 |
+
# It's only safe to query 'have_run' for a command class that has
|
| 231 |
+
# been instantiated -- a false value will be inserted when the
|
| 232 |
+
# command object is created, and replaced with a true value when
|
| 233 |
+
# the command is successfully run. Thus it's probably best to use
|
| 234 |
+
# '.get()' rather than a straight lookup.
|
| 235 |
+
self.have_run = {}
|
| 236 |
+
|
| 237 |
+
# Now we'll use the attrs dictionary (ultimately, keyword args from
|
| 238 |
+
# the setup script) to possibly override any or all of these
|
| 239 |
+
# distribution options.
|
| 240 |
+
|
| 241 |
+
if attrs:
|
| 242 |
+
# Pull out the set of command options and work on them
|
| 243 |
+
# specifically. Note that this order guarantees that aliased
|
| 244 |
+
# command options will override any supplied redundantly
|
| 245 |
+
# through the general options dictionary.
|
| 246 |
+
options = attrs.get('options')
|
| 247 |
+
if options is not None:
|
| 248 |
+
del attrs['options']
|
| 249 |
+
for (command, cmd_options) in options.items():
|
| 250 |
+
opt_dict = self.get_option_dict(command)
|
| 251 |
+
for (opt, val) in cmd_options.items():
|
| 252 |
+
opt_dict[opt] = ("setup script", val)
|
| 253 |
+
|
| 254 |
+
if 'licence' in attrs:
|
| 255 |
+
attrs['license'] = attrs['licence']
|
| 256 |
+
del attrs['licence']
|
| 257 |
+
msg = "'licence' distribution option is deprecated; use 'license'"
|
| 258 |
+
if warnings is not None:
|
| 259 |
+
warnings.warn(msg)
|
| 260 |
+
else:
|
| 261 |
+
sys.stderr.write(msg + "\n")
|
| 262 |
+
|
| 263 |
+
# Now work on the rest of the attributes. Any attribute that's
|
| 264 |
+
# not already defined is invalid!
|
| 265 |
+
for (key, val) in attrs.items():
|
| 266 |
+
if hasattr(self.metadata, "set_" + key):
|
| 267 |
+
getattr(self.metadata, "set_" + key)(val)
|
| 268 |
+
elif hasattr(self.metadata, key):
|
| 269 |
+
setattr(self.metadata, key, val)
|
| 270 |
+
elif hasattr(self, key):
|
| 271 |
+
setattr(self, key, val)
|
| 272 |
+
else:
|
| 273 |
+
msg = "Unknown distribution option: %s" % repr(key)
|
| 274 |
+
warnings.warn(msg)
|
| 275 |
+
|
| 276 |
+
# no-user-cfg is handled before other command line args
|
| 277 |
+
# because other args override the config files, and this
|
| 278 |
+
# one is needed before we can load the config files.
|
| 279 |
+
# If attrs['script_args'] wasn't passed, assume false.
|
| 280 |
+
#
|
| 281 |
+
# This also make sure we just look at the global options
|
| 282 |
+
self.want_user_cfg = True
|
| 283 |
+
|
| 284 |
+
if self.script_args is not None:
|
| 285 |
+
for arg in self.script_args:
|
| 286 |
+
if not arg.startswith('-'):
|
| 287 |
+
break
|
| 288 |
+
if arg == '--no-user-cfg':
|
| 289 |
+
self.want_user_cfg = False
|
| 290 |
+
break
|
| 291 |
+
|
| 292 |
+
self.finalize_options()
|
| 293 |
+
|
| 294 |
+
def get_option_dict(self, command):
|
| 295 |
+
"""Get the option dictionary for a given command. If that
|
| 296 |
+
command's option dictionary hasn't been created yet, then create it
|
| 297 |
+
and return the new dictionary; otherwise, return the existing
|
| 298 |
+
option dictionary.
|
| 299 |
+
"""
|
| 300 |
+
dict = self.command_options.get(command)
|
| 301 |
+
if dict is None:
|
| 302 |
+
dict = self.command_options[command] = {}
|
| 303 |
+
return dict
|
| 304 |
+
|
| 305 |
+
def dump_option_dicts(self, header=None, commands=None, indent=""):
|
| 306 |
+
from pprint import pformat
|
| 307 |
+
|
| 308 |
+
if commands is None: # dump all command option dicts
|
| 309 |
+
commands = sorted(self.command_options.keys())
|
| 310 |
+
|
| 311 |
+
if header is not None:
|
| 312 |
+
self.announce(indent + header)
|
| 313 |
+
indent = indent + " "
|
| 314 |
+
|
| 315 |
+
if not commands:
|
| 316 |
+
self.announce(indent + "no commands known yet")
|
| 317 |
+
return
|
| 318 |
+
|
| 319 |
+
for cmd_name in commands:
|
| 320 |
+
opt_dict = self.command_options.get(cmd_name)
|
| 321 |
+
if opt_dict is None:
|
| 322 |
+
self.announce(indent +
|
| 323 |
+
"no option dict for '%s' command" % cmd_name)
|
| 324 |
+
else:
|
| 325 |
+
self.announce(indent +
|
| 326 |
+
"option dict for '%s' command:" % cmd_name)
|
| 327 |
+
out = pformat(opt_dict)
|
| 328 |
+
for line in out.split('\n'):
|
| 329 |
+
self.announce(indent + " " + line)
|
| 330 |
+
|
| 331 |
+
# -- Config file finding/parsing methods ---------------------------
|
| 332 |
+
|
| 333 |
+
def find_config_files(self):
|
| 334 |
+
"""Find as many configuration files as should be processed for this
|
| 335 |
+
platform, and return a list of filenames in the order in which they
|
| 336 |
+
should be parsed. The filenames returned are guaranteed to exist
|
| 337 |
+
(modulo nasty race conditions).
|
| 338 |
+
|
| 339 |
+
There are three possible config files: distutils.cfg in the
|
| 340 |
+
Distutils installation directory (ie. where the top-level
|
| 341 |
+
Distutils __inst__.py file lives), a file in the user's home
|
| 342 |
+
directory named .pydistutils.cfg on Unix and pydistutils.cfg
|
| 343 |
+
on Windows/Mac; and setup.cfg in the current directory.
|
| 344 |
+
|
| 345 |
+
The file in the user's home directory can be disabled with the
|
| 346 |
+
--no-user-cfg option.
|
| 347 |
+
"""
|
| 348 |
+
files = []
|
| 349 |
+
check_environ()
|
| 350 |
+
|
| 351 |
+
# Where to look for the system-wide Distutils config file
|
| 352 |
+
sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
|
| 353 |
+
|
| 354 |
+
# Look for the system config file
|
| 355 |
+
sys_file = os.path.join(sys_dir, "distutils.cfg")
|
| 356 |
+
if os.path.isfile(sys_file):
|
| 357 |
+
files.append(sys_file)
|
| 358 |
+
|
| 359 |
+
# What to call the per-user config file
|
| 360 |
+
if os.name == 'posix':
|
| 361 |
+
user_filename = ".pydistutils.cfg"
|
| 362 |
+
else:
|
| 363 |
+
user_filename = "pydistutils.cfg"
|
| 364 |
+
|
| 365 |
+
# And look for the user config file
|
| 366 |
+
if self.want_user_cfg:
|
| 367 |
+
user_file = os.path.join(os.path.expanduser('~'), user_filename)
|
| 368 |
+
if os.path.isfile(user_file):
|
| 369 |
+
files.append(user_file)
|
| 370 |
+
|
| 371 |
+
# All platforms support local setup.cfg
|
| 372 |
+
local_file = "setup.cfg"
|
| 373 |
+
if os.path.isfile(local_file):
|
| 374 |
+
files.append(local_file)
|
| 375 |
+
|
| 376 |
+
if DEBUG:
|
| 377 |
+
self.announce("using config files: %s" % ', '.join(files))
|
| 378 |
+
|
| 379 |
+
return files
|
| 380 |
+
|
| 381 |
+
def parse_config_files(self, filenames=None):
|
| 382 |
+
from configparser import ConfigParser
|
| 383 |
+
|
| 384 |
+
# Ignore install directory options if we have a venv
|
| 385 |
+
if sys.prefix != sys.base_prefix:
|
| 386 |
+
ignore_options = [
|
| 387 |
+
'install-base', 'install-platbase', 'install-lib',
|
| 388 |
+
'install-platlib', 'install-purelib', 'install-headers',
|
| 389 |
+
'install-scripts', 'install-data', 'prefix', 'exec-prefix',
|
| 390 |
+
'home', 'user', 'root']
|
| 391 |
+
else:
|
| 392 |
+
ignore_options = []
|
| 393 |
+
|
| 394 |
+
ignore_options = frozenset(ignore_options)
|
| 395 |
+
|
| 396 |
+
if filenames is None:
|
| 397 |
+
filenames = self.find_config_files()
|
| 398 |
+
|
| 399 |
+
if DEBUG:
|
| 400 |
+
self.announce("Distribution.parse_config_files():")
|
| 401 |
+
|
| 402 |
+
parser = ConfigParser()
|
| 403 |
+
for filename in filenames:
|
| 404 |
+
if DEBUG:
|
| 405 |
+
self.announce(" reading %s" % filename)
|
| 406 |
+
parser.read(filename)
|
| 407 |
+
for section in parser.sections():
|
| 408 |
+
options = parser.options(section)
|
| 409 |
+
opt_dict = self.get_option_dict(section)
|
| 410 |
+
|
| 411 |
+
for opt in options:
|
| 412 |
+
if opt != '__name__' and opt not in ignore_options:
|
| 413 |
+
val = parser.get(section,opt)
|
| 414 |
+
opt = opt.replace('-', '_')
|
| 415 |
+
opt_dict[opt] = (filename, val)
|
| 416 |
+
|
| 417 |
+
# Make the ConfigParser forget everything (so we retain
|
| 418 |
+
# the original filenames that options come from)
|
| 419 |
+
parser.__init__()
|
| 420 |
+
|
| 421 |
+
# If there was a "global" section in the config file, use it
|
| 422 |
+
# to set Distribution options.
|
| 423 |
+
|
| 424 |
+
if 'global' in self.command_options:
|
| 425 |
+
for (opt, (src, val)) in self.command_options['global'].items():
|
| 426 |
+
alias = self.negative_opt.get(opt)
|
| 427 |
+
try:
|
| 428 |
+
if alias:
|
| 429 |
+
setattr(self, alias, not strtobool(val))
|
| 430 |
+
elif opt in ('verbose', 'dry_run'): # ugh!
|
| 431 |
+
setattr(self, opt, strtobool(val))
|
| 432 |
+
else:
|
| 433 |
+
setattr(self, opt, val)
|
| 434 |
+
except ValueError as msg:
|
| 435 |
+
raise DistutilsOptionError(msg)
|
| 436 |
+
|
| 437 |
+
# -- Command-line parsing methods ----------------------------------
|
| 438 |
+
|
| 439 |
+
def parse_command_line(self):
|
| 440 |
+
"""Parse the setup script's command line, taken from the
|
| 441 |
+
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
|
| 442 |
+
-- see 'setup()' in core.py). This list is first processed for
|
| 443 |
+
"global options" -- options that set attributes of the Distribution
|
| 444 |
+
instance. Then, it is alternately scanned for Distutils commands
|
| 445 |
+
and options for that command. Each new command terminates the
|
| 446 |
+
options for the previous command. The allowed options for a
|
| 447 |
+
command are determined by the 'user_options' attribute of the
|
| 448 |
+
command class -- thus, we have to be able to load command classes
|
| 449 |
+
in order to parse the command line. Any error in that 'options'
|
| 450 |
+
attribute raises DistutilsGetoptError; any error on the
|
| 451 |
+
command-line raises DistutilsArgError. If no Distutils commands
|
| 452 |
+
were found on the command line, raises DistutilsArgError. Return
|
| 453 |
+
true if command-line was successfully parsed and we should carry
|
| 454 |
+
on with executing commands; false if no errors but we shouldn't
|
| 455 |
+
execute commands (currently, this only happens if user asks for
|
| 456 |
+
help).
|
| 457 |
+
"""
|
| 458 |
+
#
|
| 459 |
+
# We now have enough information to show the Macintosh dialog
|
| 460 |
+
# that allows the user to interactively specify the "command line".
|
| 461 |
+
#
|
| 462 |
+
toplevel_options = self._get_toplevel_options()
|
| 463 |
+
|
| 464 |
+
# We have to parse the command line a bit at a time -- global
|
| 465 |
+
# options, then the first command, then its options, and so on --
|
| 466 |
+
# because each command will be handled by a different class, and
|
| 467 |
+
# the options that are valid for a particular class aren't known
|
| 468 |
+
# until we have loaded the command class, which doesn't happen
|
| 469 |
+
# until we know what the command is.
|
| 470 |
+
|
| 471 |
+
self.commands = []
|
| 472 |
+
parser = FancyGetopt(toplevel_options + self.display_options)
|
| 473 |
+
parser.set_negative_aliases(self.negative_opt)
|
| 474 |
+
parser.set_aliases({'licence': 'license'})
|
| 475 |
+
args = parser.getopt(args=self.script_args, object=self)
|
| 476 |
+
option_order = parser.get_option_order()
|
| 477 |
+
log.set_verbosity(self.verbose)
|
| 478 |
+
|
| 479 |
+
# for display options we return immediately
|
| 480 |
+
if self.handle_display_options(option_order):
|
| 481 |
+
return
|
| 482 |
+
while args:
|
| 483 |
+
args = self._parse_command_opts(parser, args)
|
| 484 |
+
if args is None: # user asked for help (and got it)
|
| 485 |
+
return
|
| 486 |
+
|
| 487 |
+
# Handle the cases of --help as a "global" option, ie.
|
| 488 |
+
# "setup.py --help" and "setup.py --help command ...". For the
|
| 489 |
+
# former, we show global options (--verbose, --dry-run, etc.)
|
| 490 |
+
# and display-only options (--name, --version, etc.); for the
|
| 491 |
+
# latter, we omit the display-only options and show help for
|
| 492 |
+
# each command listed on the command line.
|
| 493 |
+
if self.help:
|
| 494 |
+
self._show_help(parser,
|
| 495 |
+
display_options=len(self.commands) == 0,
|
| 496 |
+
commands=self.commands)
|
| 497 |
+
return
|
| 498 |
+
|
| 499 |
+
# Oops, no commands found -- an end-user error
|
| 500 |
+
if not self.commands:
|
| 501 |
+
raise DistutilsArgError("no commands supplied")
|
| 502 |
+
|
| 503 |
+
# All is well: return true
|
| 504 |
+
return True
|
| 505 |
+
|
| 506 |
+
def _get_toplevel_options(self):
|
| 507 |
+
"""Return the non-display options recognized at the top level.
|
| 508 |
+
|
| 509 |
+
This includes options that are recognized *only* at the top
|
| 510 |
+
level as well as options recognized for commands.
|
| 511 |
+
"""
|
| 512 |
+
return self.global_options + [
|
| 513 |
+
("command-packages=", None,
|
| 514 |
+
"list of packages that provide distutils commands"),
|
| 515 |
+
]
|
| 516 |
+
|
| 517 |
+
def _parse_command_opts(self, parser, args):
|
| 518 |
+
"""Parse the command-line options for a single command.
|
| 519 |
+
'parser' must be a FancyGetopt instance; 'args' must be the list
|
| 520 |
+
of arguments, starting with the current command (whose options
|
| 521 |
+
we are about to parse). Returns a new version of 'args' with
|
| 522 |
+
the next command at the front of the list; will be the empty
|
| 523 |
+
list if there are no more commands on the command line. Returns
|
| 524 |
+
None if the user asked for help on this command.
|
| 525 |
+
"""
|
| 526 |
+
# late import because of mutual dependence between these modules
|
| 527 |
+
from distutils.cmd import Command
|
| 528 |
+
|
| 529 |
+
# Pull the current command from the head of the command line
|
| 530 |
+
command = args[0]
|
| 531 |
+
if not command_re.match(command):
|
| 532 |
+
raise SystemExit("invalid command name '%s'" % command)
|
| 533 |
+
self.commands.append(command)
|
| 534 |
+
|
| 535 |
+
# Dig up the command class that implements this command, so we
|
| 536 |
+
# 1) know that it's a valid command, and 2) know which options
|
| 537 |
+
# it takes.
|
| 538 |
+
try:
|
| 539 |
+
cmd_class = self.get_command_class(command)
|
| 540 |
+
except DistutilsModuleError as msg:
|
| 541 |
+
raise DistutilsArgError(msg)
|
| 542 |
+
|
| 543 |
+
# Require that the command class be derived from Command -- want
|
| 544 |
+
# to be sure that the basic "command" interface is implemented.
|
| 545 |
+
if not issubclass(cmd_class, Command):
|
| 546 |
+
raise DistutilsClassError(
|
| 547 |
+
"command class %s must subclass Command" % cmd_class)
|
| 548 |
+
|
| 549 |
+
# Also make sure that the command object provides a list of its
|
| 550 |
+
# known options.
|
| 551 |
+
if not (hasattr(cmd_class, 'user_options') and
|
| 552 |
+
isinstance(cmd_class.user_options, list)):
|
| 553 |
+
msg = ("command class %s must provide "
|
| 554 |
+
"'user_options' attribute (a list of tuples)")
|
| 555 |
+
raise DistutilsClassError(msg % cmd_class)
|
| 556 |
+
|
| 557 |
+
# If the command class has a list of negative alias options,
|
| 558 |
+
# merge it in with the global negative aliases.
|
| 559 |
+
negative_opt = self.negative_opt
|
| 560 |
+
if hasattr(cmd_class, 'negative_opt'):
|
| 561 |
+
negative_opt = negative_opt.copy()
|
| 562 |
+
negative_opt.update(cmd_class.negative_opt)
|
| 563 |
+
|
| 564 |
+
# Check for help_options in command class. They have a different
|
| 565 |
+
# format (tuple of four) so we need to preprocess them here.
|
| 566 |
+
if (hasattr(cmd_class, 'help_options') and
|
| 567 |
+
isinstance(cmd_class.help_options, list)):
|
| 568 |
+
help_options = fix_help_options(cmd_class.help_options)
|
| 569 |
+
else:
|
| 570 |
+
help_options = []
|
| 571 |
+
|
| 572 |
+
# All commands support the global options too, just by adding
|
| 573 |
+
# in 'global_options'.
|
| 574 |
+
parser.set_option_table(self.global_options +
|
| 575 |
+
cmd_class.user_options +
|
| 576 |
+
help_options)
|
| 577 |
+
parser.set_negative_aliases(negative_opt)
|
| 578 |
+
(args, opts) = parser.getopt(args[1:])
|
| 579 |
+
if hasattr(opts, 'help') and opts.help:
|
| 580 |
+
self._show_help(parser, display_options=0, commands=[cmd_class])
|
| 581 |
+
return
|
| 582 |
+
|
| 583 |
+
if (hasattr(cmd_class, 'help_options') and
|
| 584 |
+
isinstance(cmd_class.help_options, list)):
|
| 585 |
+
help_option_found=0
|
| 586 |
+
for (help_option, short, desc, func) in cmd_class.help_options:
|
| 587 |
+
if hasattr(opts, parser.get_attr_name(help_option)):
|
| 588 |
+
help_option_found=1
|
| 589 |
+
if callable(func):
|
| 590 |
+
func()
|
| 591 |
+
else:
|
| 592 |
+
raise DistutilsClassError(
|
| 593 |
+
"invalid help function %r for help option '%s': "
|
| 594 |
+
"must be a callable object (function, etc.)"
|
| 595 |
+
% (func, help_option))
|
| 596 |
+
|
| 597 |
+
if help_option_found:
|
| 598 |
+
return
|
| 599 |
+
|
| 600 |
+
# Put the options from the command-line into their official
|
| 601 |
+
# holding pen, the 'command_options' dictionary.
|
| 602 |
+
opt_dict = self.get_option_dict(command)
|
| 603 |
+
for (name, value) in vars(opts).items():
|
| 604 |
+
opt_dict[name] = ("command line", value)
|
| 605 |
+
|
| 606 |
+
return args
|
| 607 |
+
|
| 608 |
+
def finalize_options(self):
|
| 609 |
+
"""Set final values for all the options on the Distribution
|
| 610 |
+
instance, analogous to the .finalize_options() method of Command
|
| 611 |
+
objects.
|
| 612 |
+
"""
|
| 613 |
+
for attr in ('keywords', 'platforms'):
|
| 614 |
+
value = getattr(self.metadata, attr)
|
| 615 |
+
if value is None:
|
| 616 |
+
continue
|
| 617 |
+
if isinstance(value, str):
|
| 618 |
+
value = [elm.strip() for elm in value.split(',')]
|
| 619 |
+
setattr(self.metadata, attr, value)
|
| 620 |
+
|
| 621 |
+
def _show_help(self, parser, global_options=1, display_options=1,
|
| 622 |
+
commands=[]):
|
| 623 |
+
"""Show help for the setup script command-line in the form of
|
| 624 |
+
several lists of command-line options. 'parser' should be a
|
| 625 |
+
FancyGetopt instance; do not expect it to be returned in the
|
| 626 |
+
same state, as its option table will be reset to make it
|
| 627 |
+
generate the correct help text.
|
| 628 |
+
|
| 629 |
+
If 'global_options' is true, lists the global options:
|
| 630 |
+
--verbose, --dry-run, etc. If 'display_options' is true, lists
|
| 631 |
+
the "display-only" options: --name, --version, etc. Finally,
|
| 632 |
+
lists per-command help for every command name or command class
|
| 633 |
+
in 'commands'.
|
| 634 |
+
"""
|
| 635 |
+
# late import because of mutual dependence between these modules
|
| 636 |
+
from distutils.core import gen_usage
|
| 637 |
+
from distutils.cmd import Command
|
| 638 |
+
|
| 639 |
+
if global_options:
|
| 640 |
+
if display_options:
|
| 641 |
+
options = self._get_toplevel_options()
|
| 642 |
+
else:
|
| 643 |
+
options = self.global_options
|
| 644 |
+
parser.set_option_table(options)
|
| 645 |
+
parser.print_help(self.common_usage + "\nGlobal options:")
|
| 646 |
+
print('')
|
| 647 |
+
|
| 648 |
+
if display_options:
|
| 649 |
+
parser.set_option_table(self.display_options)
|
| 650 |
+
parser.print_help(
|
| 651 |
+
"Information display options (just display " +
|
| 652 |
+
"information, ignore any commands)")
|
| 653 |
+
print('')
|
| 654 |
+
|
| 655 |
+
for command in self.commands:
|
| 656 |
+
if isinstance(command, type) and issubclass(command, Command):
|
| 657 |
+
klass = command
|
| 658 |
+
else:
|
| 659 |
+
klass = self.get_command_class(command)
|
| 660 |
+
if (hasattr(klass, 'help_options') and
|
| 661 |
+
isinstance(klass.help_options, list)):
|
| 662 |
+
parser.set_option_table(klass.user_options +
|
| 663 |
+
fix_help_options(klass.help_options))
|
| 664 |
+
else:
|
| 665 |
+
parser.set_option_table(klass.user_options)
|
| 666 |
+
parser.print_help("Options for '%s' command:" % klass.__name__)
|
| 667 |
+
print('')
|
| 668 |
+
|
| 669 |
+
print(gen_usage(self.script_name))
|
| 670 |
+
|
| 671 |
+
def handle_display_options(self, option_order):
|
| 672 |
+
"""If there were any non-global "display-only" options
|
| 673 |
+
(--help-commands or the metadata display options) on the command
|
| 674 |
+
line, display the requested info and return true; else return
|
| 675 |
+
false.
|
| 676 |
+
"""
|
| 677 |
+
from distutils.core import gen_usage
|
| 678 |
+
|
| 679 |
+
# User just wants a list of commands -- we'll print it out and stop
|
| 680 |
+
# processing now (ie. if they ran "setup --help-commands foo bar",
|
| 681 |
+
# we ignore "foo bar").
|
| 682 |
+
if self.help_commands:
|
| 683 |
+
self.print_commands()
|
| 684 |
+
print('')
|
| 685 |
+
print(gen_usage(self.script_name))
|
| 686 |
+
return 1
|
| 687 |
+
|
| 688 |
+
# If user supplied any of the "display metadata" options, then
|
| 689 |
+
# display that metadata in the order in which the user supplied the
|
| 690 |
+
# metadata options.
|
| 691 |
+
any_display_options = 0
|
| 692 |
+
is_display_option = {}
|
| 693 |
+
for option in self.display_options:
|
| 694 |
+
is_display_option[option[0]] = 1
|
| 695 |
+
|
| 696 |
+
for (opt, val) in option_order:
|
| 697 |
+
if val and is_display_option.get(opt):
|
| 698 |
+
opt = translate_longopt(opt)
|
| 699 |
+
value = getattr(self.metadata, "get_"+opt)()
|
| 700 |
+
if opt in ['keywords', 'platforms']:
|
| 701 |
+
print(','.join(value))
|
| 702 |
+
elif opt in ('classifiers', 'provides', 'requires',
|
| 703 |
+
'obsoletes'):
|
| 704 |
+
print('\n'.join(value))
|
| 705 |
+
else:
|
| 706 |
+
print(value)
|
| 707 |
+
any_display_options = 1
|
| 708 |
+
|
| 709 |
+
return any_display_options
|
| 710 |
+
|
| 711 |
+
def print_command_list(self, commands, header, max_length):
|
| 712 |
+
"""Print a subset of the list of all commands -- used by
|
| 713 |
+
'print_commands()'.
|
| 714 |
+
"""
|
| 715 |
+
print(header + ":")
|
| 716 |
+
|
| 717 |
+
for cmd in commands:
|
| 718 |
+
klass = self.cmdclass.get(cmd)
|
| 719 |
+
if not klass:
|
| 720 |
+
klass = self.get_command_class(cmd)
|
| 721 |
+
try:
|
| 722 |
+
description = klass.description
|
| 723 |
+
except AttributeError:
|
| 724 |
+
description = "(no description available)"
|
| 725 |
+
|
| 726 |
+
print(" %-*s %s" % (max_length, cmd, description))
|
| 727 |
+
|
| 728 |
+
def print_commands(self):
|
| 729 |
+
"""Print out a help message listing all available commands with a
|
| 730 |
+
description of each. The list is divided into "standard commands"
|
| 731 |
+
(listed in distutils.command.__all__) and "extra commands"
|
| 732 |
+
(mentioned in self.cmdclass, but not a standard command). The
|
| 733 |
+
descriptions come from the command class attribute
|
| 734 |
+
'description'.
|
| 735 |
+
"""
|
| 736 |
+
import distutils.command
|
| 737 |
+
std_commands = distutils.command.__all__
|
| 738 |
+
is_std = {}
|
| 739 |
+
for cmd in std_commands:
|
| 740 |
+
is_std[cmd] = 1
|
| 741 |
+
|
| 742 |
+
extra_commands = []
|
| 743 |
+
for cmd in self.cmdclass.keys():
|
| 744 |
+
if not is_std.get(cmd):
|
| 745 |
+
extra_commands.append(cmd)
|
| 746 |
+
|
| 747 |
+
max_length = 0
|
| 748 |
+
for cmd in (std_commands + extra_commands):
|
| 749 |
+
if len(cmd) > max_length:
|
| 750 |
+
max_length = len(cmd)
|
| 751 |
+
|
| 752 |
+
self.print_command_list(std_commands,
|
| 753 |
+
"Standard commands",
|
| 754 |
+
max_length)
|
| 755 |
+
if extra_commands:
|
| 756 |
+
print()
|
| 757 |
+
self.print_command_list(extra_commands,
|
| 758 |
+
"Extra commands",
|
| 759 |
+
max_length)
|
| 760 |
+
|
| 761 |
+
def get_command_list(self):
|
| 762 |
+
"""Get a list of (command, description) tuples.
|
| 763 |
+
The list is divided into "standard commands" (listed in
|
| 764 |
+
distutils.command.__all__) and "extra commands" (mentioned in
|
| 765 |
+
self.cmdclass, but not a standard command). The descriptions come
|
| 766 |
+
from the command class attribute 'description'.
|
| 767 |
+
"""
|
| 768 |
+
# Currently this is only used on Mac OS, for the Mac-only GUI
|
| 769 |
+
# Distutils interface (by Jack Jansen)
|
| 770 |
+
import distutils.command
|
| 771 |
+
std_commands = distutils.command.__all__
|
| 772 |
+
is_std = {}
|
| 773 |
+
for cmd in std_commands:
|
| 774 |
+
is_std[cmd] = 1
|
| 775 |
+
|
| 776 |
+
extra_commands = []
|
| 777 |
+
for cmd in self.cmdclass.keys():
|
| 778 |
+
if not is_std.get(cmd):
|
| 779 |
+
extra_commands.append(cmd)
|
| 780 |
+
|
| 781 |
+
rv = []
|
| 782 |
+
for cmd in (std_commands + extra_commands):
|
| 783 |
+
klass = self.cmdclass.get(cmd)
|
| 784 |
+
if not klass:
|
| 785 |
+
klass = self.get_command_class(cmd)
|
| 786 |
+
try:
|
| 787 |
+
description = klass.description
|
| 788 |
+
except AttributeError:
|
| 789 |
+
description = "(no description available)"
|
| 790 |
+
rv.append((cmd, description))
|
| 791 |
+
return rv
|
| 792 |
+
|
| 793 |
+
# -- Command class/object methods ----------------------------------
|
| 794 |
+
|
| 795 |
+
def get_command_packages(self):
|
| 796 |
+
"""Return a list of packages from which commands are loaded."""
|
| 797 |
+
pkgs = self.command_packages
|
| 798 |
+
if not isinstance(pkgs, list):
|
| 799 |
+
if pkgs is None:
|
| 800 |
+
pkgs = ''
|
| 801 |
+
pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
|
| 802 |
+
if "distutils.command" not in pkgs:
|
| 803 |
+
pkgs.insert(0, "distutils.command")
|
| 804 |
+
self.command_packages = pkgs
|
| 805 |
+
return pkgs
|
| 806 |
+
|
| 807 |
+
def get_command_class(self, command):
|
| 808 |
+
"""Return the class that implements the Distutils command named by
|
| 809 |
+
'command'. First we check the 'cmdclass' dictionary; if the
|
| 810 |
+
command is mentioned there, we fetch the class object from the
|
| 811 |
+
dictionary and return it. Otherwise we load the command module
|
| 812 |
+
("distutils.command." + command) and fetch the command class from
|
| 813 |
+
the module. The loaded class is also stored in 'cmdclass'
|
| 814 |
+
to speed future calls to 'get_command_class()'.
|
| 815 |
+
|
| 816 |
+
Raises DistutilsModuleError if the expected module could not be
|
| 817 |
+
found, or if that module does not define the expected class.
|
| 818 |
+
"""
|
| 819 |
+
klass = self.cmdclass.get(command)
|
| 820 |
+
if klass:
|
| 821 |
+
return klass
|
| 822 |
+
|
| 823 |
+
for pkgname in self.get_command_packages():
|
| 824 |
+
module_name = "%s.%s" % (pkgname, command)
|
| 825 |
+
klass_name = command
|
| 826 |
+
|
| 827 |
+
try:
|
| 828 |
+
__import__(module_name)
|
| 829 |
+
module = sys.modules[module_name]
|
| 830 |
+
except ImportError:
|
| 831 |
+
continue
|
| 832 |
+
|
| 833 |
+
try:
|
| 834 |
+
klass = getattr(module, klass_name)
|
| 835 |
+
except AttributeError:
|
| 836 |
+
raise DistutilsModuleError(
|
| 837 |
+
"invalid command '%s' (no class '%s' in module '%s')"
|
| 838 |
+
% (command, klass_name, module_name))
|
| 839 |
+
|
| 840 |
+
self.cmdclass[command] = klass
|
| 841 |
+
return klass
|
| 842 |
+
|
| 843 |
+
raise DistutilsModuleError("invalid command '%s'" % command)
|
| 844 |
+
|
| 845 |
+
def get_command_obj(self, command, create=1):
|
| 846 |
+
"""Return the command object for 'command'. Normally this object
|
| 847 |
+
is cached on a previous call to 'get_command_obj()'; if no command
|
| 848 |
+
object for 'command' is in the cache, then we either create and
|
| 849 |
+
return it (if 'create' is true) or return None.
|
| 850 |
+
"""
|
| 851 |
+
cmd_obj = self.command_obj.get(command)
|
| 852 |
+
if not cmd_obj and create:
|
| 853 |
+
if DEBUG:
|
| 854 |
+
self.announce("Distribution.get_command_obj(): "
|
| 855 |
+
"creating '%s' command object" % command)
|
| 856 |
+
|
| 857 |
+
klass = self.get_command_class(command)
|
| 858 |
+
cmd_obj = self.command_obj[command] = klass(self)
|
| 859 |
+
self.have_run[command] = 0
|
| 860 |
+
|
| 861 |
+
# Set any options that were supplied in config files
|
| 862 |
+
# or on the command line. (NB. support for error
|
| 863 |
+
# reporting is lame here: any errors aren't reported
|
| 864 |
+
# until 'finalize_options()' is called, which means
|
| 865 |
+
# we won't report the source of the error.)
|
| 866 |
+
options = self.command_options.get(command)
|
| 867 |
+
if options:
|
| 868 |
+
self._set_command_options(cmd_obj, options)
|
| 869 |
+
|
| 870 |
+
return cmd_obj
|
| 871 |
+
|
| 872 |
+
def _set_command_options(self, command_obj, option_dict=None):
|
| 873 |
+
"""Set the options for 'command_obj' from 'option_dict'. Basically
|
| 874 |
+
this means copying elements of a dictionary ('option_dict') to
|
| 875 |
+
attributes of an instance ('command').
|
| 876 |
+
|
| 877 |
+
'command_obj' must be a Command instance. If 'option_dict' is not
|
| 878 |
+
supplied, uses the standard option dictionary for this command
|
| 879 |
+
(from 'self.command_options').
|
| 880 |
+
"""
|
| 881 |
+
command_name = command_obj.get_command_name()
|
| 882 |
+
if option_dict is None:
|
| 883 |
+
option_dict = self.get_option_dict(command_name)
|
| 884 |
+
|
| 885 |
+
if DEBUG:
|
| 886 |
+
self.announce(" setting options for '%s' command:" % command_name)
|
| 887 |
+
for (option, (source, value)) in option_dict.items():
|
| 888 |
+
if DEBUG:
|
| 889 |
+
self.announce(" %s = %s (from %s)" % (option, value,
|
| 890 |
+
source))
|
| 891 |
+
try:
|
| 892 |
+
bool_opts = [translate_longopt(o)
|
| 893 |
+
for o in command_obj.boolean_options]
|
| 894 |
+
except AttributeError:
|
| 895 |
+
bool_opts = []
|
| 896 |
+
try:
|
| 897 |
+
neg_opt = command_obj.negative_opt
|
| 898 |
+
except AttributeError:
|
| 899 |
+
neg_opt = {}
|
| 900 |
+
|
| 901 |
+
try:
|
| 902 |
+
is_string = isinstance(value, str)
|
| 903 |
+
if option in neg_opt and is_string:
|
| 904 |
+
setattr(command_obj, neg_opt[option], not strtobool(value))
|
| 905 |
+
elif option in bool_opts and is_string:
|
| 906 |
+
setattr(command_obj, option, strtobool(value))
|
| 907 |
+
elif hasattr(command_obj, option):
|
| 908 |
+
setattr(command_obj, option, value)
|
| 909 |
+
else:
|
| 910 |
+
raise DistutilsOptionError(
|
| 911 |
+
"error in %s: command '%s' has no such option '%s'"
|
| 912 |
+
% (source, command_name, option))
|
| 913 |
+
except ValueError as msg:
|
| 914 |
+
raise DistutilsOptionError(msg)
|
| 915 |
+
|
| 916 |
+
def reinitialize_command(self, command, reinit_subcommands=0):
|
| 917 |
+
"""Reinitializes a command to the state it was in when first
|
| 918 |
+
returned by 'get_command_obj()': ie., initialized but not yet
|
| 919 |
+
finalized. This provides the opportunity to sneak option
|
| 920 |
+
values in programmatically, overriding or supplementing
|
| 921 |
+
user-supplied values from the config files and command line.
|
| 922 |
+
You'll have to re-finalize the command object (by calling
|
| 923 |
+
'finalize_options()' or 'ensure_finalized()') before using it for
|
| 924 |
+
real.
|
| 925 |
+
|
| 926 |
+
'command' should be a command name (string) or command object. If
|
| 927 |
+
'reinit_subcommands' is true, also reinitializes the command's
|
| 928 |
+
sub-commands, as declared by the 'sub_commands' class attribute (if
|
| 929 |
+
it has one). See the "install" command for an example. Only
|
| 930 |
+
reinitializes the sub-commands that actually matter, ie. those
|
| 931 |
+
whose test predicates return true.
|
| 932 |
+
|
| 933 |
+
Returns the reinitialized command object.
|
| 934 |
+
"""
|
| 935 |
+
from distutils.cmd import Command
|
| 936 |
+
if not isinstance(command, Command):
|
| 937 |
+
command_name = command
|
| 938 |
+
command = self.get_command_obj(command_name)
|
| 939 |
+
else:
|
| 940 |
+
command_name = command.get_command_name()
|
| 941 |
+
|
| 942 |
+
if not command.finalized:
|
| 943 |
+
return command
|
| 944 |
+
command.initialize_options()
|
| 945 |
+
command.finalized = 0
|
| 946 |
+
self.have_run[command_name] = 0
|
| 947 |
+
self._set_command_options(command)
|
| 948 |
+
|
| 949 |
+
if reinit_subcommands:
|
| 950 |
+
for sub in command.get_sub_commands():
|
| 951 |
+
self.reinitialize_command(sub, reinit_subcommands)
|
| 952 |
+
|
| 953 |
+
return command
|
| 954 |
+
|
| 955 |
+
# -- Methods that operate on the Distribution ----------------------
|
| 956 |
+
|
| 957 |
+
def announce(self, msg, level=log.INFO):
|
| 958 |
+
log.log(level, msg)
|
| 959 |
+
|
| 960 |
+
def run_commands(self):
|
| 961 |
+
"""Run each command that was seen on the setup script command line.
|
| 962 |
+
Uses the list of commands found and cache of command objects
|
| 963 |
+
created by 'get_command_obj()'.
|
| 964 |
+
"""
|
| 965 |
+
for cmd in self.commands:
|
| 966 |
+
self.run_command(cmd)
|
| 967 |
+
|
| 968 |
+
# -- Methods that operate on its Commands --------------------------
|
| 969 |
+
|
| 970 |
+
def run_command(self, command):
|
| 971 |
+
"""Do whatever it takes to run a command (including nothing at all,
|
| 972 |
+
if the command has already been run). Specifically: if we have
|
| 973 |
+
already created and run the command named by 'command', return
|
| 974 |
+
silently without doing anything. If the command named by 'command'
|
| 975 |
+
doesn't even have a command object yet, create one. Then invoke
|
| 976 |
+
'run()' on that command object (or an existing one).
|
| 977 |
+
"""
|
| 978 |
+
# Already been here, done that? then return silently.
|
| 979 |
+
if self.have_run.get(command):
|
| 980 |
+
return
|
| 981 |
+
|
| 982 |
+
log.info("running %s", command)
|
| 983 |
+
cmd_obj = self.get_command_obj(command)
|
| 984 |
+
cmd_obj.ensure_finalized()
|
| 985 |
+
cmd_obj.run()
|
| 986 |
+
self.have_run[command] = 1
|
| 987 |
+
|
| 988 |
+
# -- Distribution query methods ------------------------------------
|
| 989 |
+
|
| 990 |
+
def has_pure_modules(self):
|
| 991 |
+
return len(self.packages or self.py_modules or []) > 0
|
| 992 |
+
|
| 993 |
+
def has_ext_modules(self):
|
| 994 |
+
return self.ext_modules and len(self.ext_modules) > 0
|
| 995 |
+
|
| 996 |
+
def has_c_libraries(self):
|
| 997 |
+
return self.libraries and len(self.libraries) > 0
|
| 998 |
+
|
| 999 |
+
def has_modules(self):
|
| 1000 |
+
return self.has_pure_modules() or self.has_ext_modules()
|
| 1001 |
+
|
| 1002 |
+
def has_headers(self):
|
| 1003 |
+
return self.headers and len(self.headers) > 0
|
| 1004 |
+
|
| 1005 |
+
def has_scripts(self):
|
| 1006 |
+
return self.scripts and len(self.scripts) > 0
|
| 1007 |
+
|
| 1008 |
+
def has_data_files(self):
|
| 1009 |
+
return self.data_files and len(self.data_files) > 0
|
| 1010 |
+
|
| 1011 |
+
def is_pure(self):
|
| 1012 |
+
return (self.has_pure_modules() and
|
| 1013 |
+
not self.has_ext_modules() and
|
| 1014 |
+
not self.has_c_libraries())
|
| 1015 |
+
|
| 1016 |
+
# -- Metadata query methods ----------------------------------------
|
| 1017 |
+
|
| 1018 |
+
# If you're looking for 'get_name()', 'get_version()', and so forth,
|
| 1019 |
+
# they are defined in a sneaky way: the constructor binds self.get_XXX
|
| 1020 |
+
# to self.metadata.get_XXX. The actual code is in the
|
| 1021 |
+
# DistributionMetadata class, below.
|
| 1022 |
+
|
| 1023 |
+
class DistributionMetadata:
|
| 1024 |
+
"""Dummy class to hold the distribution meta-data: name, version,
|
| 1025 |
+
author, and so forth.
|
| 1026 |
+
"""
|
| 1027 |
+
|
| 1028 |
+
_METHOD_BASENAMES = ("name", "version", "author", "author_email",
|
| 1029 |
+
"maintainer", "maintainer_email", "url",
|
| 1030 |
+
"license", "description", "long_description",
|
| 1031 |
+
"keywords", "platforms", "fullname", "contact",
|
| 1032 |
+
"contact_email", "classifiers", "download_url",
|
| 1033 |
+
# PEP 314
|
| 1034 |
+
"provides", "requires", "obsoletes",
|
| 1035 |
+
)
|
| 1036 |
+
|
| 1037 |
+
def __init__(self, path=None):
|
| 1038 |
+
if path is not None:
|
| 1039 |
+
self.read_pkg_file(open(path))
|
| 1040 |
+
else:
|
| 1041 |
+
self.name = None
|
| 1042 |
+
self.version = None
|
| 1043 |
+
self.author = None
|
| 1044 |
+
self.author_email = None
|
| 1045 |
+
self.maintainer = None
|
| 1046 |
+
self.maintainer_email = None
|
| 1047 |
+
self.url = None
|
| 1048 |
+
self.license = None
|
| 1049 |
+
self.description = None
|
| 1050 |
+
self.long_description = None
|
| 1051 |
+
self.keywords = None
|
| 1052 |
+
self.platforms = None
|
| 1053 |
+
self.classifiers = None
|
| 1054 |
+
self.download_url = None
|
| 1055 |
+
# PEP 314
|
| 1056 |
+
self.provides = None
|
| 1057 |
+
self.requires = None
|
| 1058 |
+
self.obsoletes = None
|
| 1059 |
+
|
| 1060 |
+
def read_pkg_file(self, file):
|
| 1061 |
+
"""Reads the metadata values from a file object."""
|
| 1062 |
+
msg = message_from_file(file)
|
| 1063 |
+
|
| 1064 |
+
def _read_field(name):
|
| 1065 |
+
value = msg[name]
|
| 1066 |
+
if value == 'UNKNOWN':
|
| 1067 |
+
return None
|
| 1068 |
+
return value
|
| 1069 |
+
|
| 1070 |
+
def _read_list(name):
|
| 1071 |
+
values = msg.get_all(name, None)
|
| 1072 |
+
if values == []:
|
| 1073 |
+
return None
|
| 1074 |
+
return values
|
| 1075 |
+
|
| 1076 |
+
metadata_version = msg['metadata-version']
|
| 1077 |
+
self.name = _read_field('name')
|
| 1078 |
+
self.version = _read_field('version')
|
| 1079 |
+
self.description = _read_field('summary')
|
| 1080 |
+
# we are filling author only.
|
| 1081 |
+
self.author = _read_field('author')
|
| 1082 |
+
self.maintainer = None
|
| 1083 |
+
self.author_email = _read_field('author-email')
|
| 1084 |
+
self.maintainer_email = None
|
| 1085 |
+
self.url = _read_field('home-page')
|
| 1086 |
+
self.license = _read_field('license')
|
| 1087 |
+
|
| 1088 |
+
if 'download-url' in msg:
|
| 1089 |
+
self.download_url = _read_field('download-url')
|
| 1090 |
+
else:
|
| 1091 |
+
self.download_url = None
|
| 1092 |
+
|
| 1093 |
+
self.long_description = _read_field('description')
|
| 1094 |
+
self.description = _read_field('summary')
|
| 1095 |
+
|
| 1096 |
+
if 'keywords' in msg:
|
| 1097 |
+
self.keywords = _read_field('keywords').split(',')
|
| 1098 |
+
|
| 1099 |
+
self.platforms = _read_list('platform')
|
| 1100 |
+
self.classifiers = _read_list('classifier')
|
| 1101 |
+
|
| 1102 |
+
# PEP 314 - these fields only exist in 1.1
|
| 1103 |
+
if metadata_version == '1.1':
|
| 1104 |
+
self.requires = _read_list('requires')
|
| 1105 |
+
self.provides = _read_list('provides')
|
| 1106 |
+
self.obsoletes = _read_list('obsoletes')
|
| 1107 |
+
else:
|
| 1108 |
+
self.requires = None
|
| 1109 |
+
self.provides = None
|
| 1110 |
+
self.obsoletes = None
|
| 1111 |
+
|
| 1112 |
+
def write_pkg_info(self, base_dir):
|
| 1113 |
+
"""Write the PKG-INFO file into the release tree.
|
| 1114 |
+
"""
|
| 1115 |
+
with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
|
| 1116 |
+
encoding='UTF-8') as pkg_info:
|
| 1117 |
+
self.write_pkg_file(pkg_info)
|
| 1118 |
+
|
| 1119 |
+
def write_pkg_file(self, file):
|
| 1120 |
+
"""Write the PKG-INFO format data to a file object.
|
| 1121 |
+
"""
|
| 1122 |
+
version = '1.0'
|
| 1123 |
+
if (self.provides or self.requires or self.obsoletes or
|
| 1124 |
+
self.classifiers or self.download_url):
|
| 1125 |
+
version = '1.1'
|
| 1126 |
+
|
| 1127 |
+
file.write('Metadata-Version: %s\n' % version)
|
| 1128 |
+
file.write('Name: %s\n' % self.get_name())
|
| 1129 |
+
file.write('Version: %s\n' % self.get_version())
|
| 1130 |
+
file.write('Summary: %s\n' % self.get_description())
|
| 1131 |
+
file.write('Home-page: %s\n' % self.get_url())
|
| 1132 |
+
file.write('Author: %s\n' % self.get_contact())
|
| 1133 |
+
file.write('Author-email: %s\n' % self.get_contact_email())
|
| 1134 |
+
file.write('License: %s\n' % self.get_license())
|
| 1135 |
+
if self.download_url:
|
| 1136 |
+
file.write('Download-URL: %s\n' % self.download_url)
|
| 1137 |
+
|
| 1138 |
+
long_desc = rfc822_escape(self.get_long_description())
|
| 1139 |
+
file.write('Description: %s\n' % long_desc)
|
| 1140 |
+
|
| 1141 |
+
keywords = ','.join(self.get_keywords())
|
| 1142 |
+
if keywords:
|
| 1143 |
+
file.write('Keywords: %s\n' % keywords)
|
| 1144 |
+
|
| 1145 |
+
self._write_list(file, 'Platform', self.get_platforms())
|
| 1146 |
+
self._write_list(file, 'Classifier', self.get_classifiers())
|
| 1147 |
+
|
| 1148 |
+
# PEP 314
|
| 1149 |
+
self._write_list(file, 'Requires', self.get_requires())
|
| 1150 |
+
self._write_list(file, 'Provides', self.get_provides())
|
| 1151 |
+
self._write_list(file, 'Obsoletes', self.get_obsoletes())
|
| 1152 |
+
|
| 1153 |
+
def _write_list(self, file, name, values):
|
| 1154 |
+
for value in values:
|
| 1155 |
+
file.write('%s: %s\n' % (name, value))
|
| 1156 |
+
|
| 1157 |
+
# -- Metadata query methods ----------------------------------------
|
| 1158 |
+
|
| 1159 |
+
def get_name(self):
|
| 1160 |
+
return self.name or "UNKNOWN"
|
| 1161 |
+
|
| 1162 |
+
def get_version(self):
|
| 1163 |
+
return self.version or "0.0.0"
|
| 1164 |
+
|
| 1165 |
+
def get_fullname(self):
|
| 1166 |
+
return "%s-%s" % (self.get_name(), self.get_version())
|
| 1167 |
+
|
| 1168 |
+
def get_author(self):
|
| 1169 |
+
return self.author or "UNKNOWN"
|
| 1170 |
+
|
| 1171 |
+
def get_author_email(self):
|
| 1172 |
+
return self.author_email or "UNKNOWN"
|
| 1173 |
+
|
| 1174 |
+
def get_maintainer(self):
|
| 1175 |
+
return self.maintainer or "UNKNOWN"
|
| 1176 |
+
|
| 1177 |
+
def get_maintainer_email(self):
|
| 1178 |
+
return self.maintainer_email or "UNKNOWN"
|
| 1179 |
+
|
| 1180 |
+
def get_contact(self):
|
| 1181 |
+
return self.maintainer or self.author or "UNKNOWN"
|
| 1182 |
+
|
| 1183 |
+
def get_contact_email(self):
|
| 1184 |
+
return self.maintainer_email or self.author_email or "UNKNOWN"
|
| 1185 |
+
|
| 1186 |
+
def get_url(self):
|
| 1187 |
+
return self.url or "UNKNOWN"
|
| 1188 |
+
|
| 1189 |
+
def get_license(self):
|
| 1190 |
+
return self.license or "UNKNOWN"
|
| 1191 |
+
get_licence = get_license
|
| 1192 |
+
|
| 1193 |
+
def get_description(self):
|
| 1194 |
+
return self.description or "UNKNOWN"
|
| 1195 |
+
|
| 1196 |
+
def get_long_description(self):
|
| 1197 |
+
return self.long_description or "UNKNOWN"
|
| 1198 |
+
|
| 1199 |
+
def get_keywords(self):
|
| 1200 |
+
return self.keywords or []
|
| 1201 |
+
|
| 1202 |
+
def set_keywords(self, value):
|
| 1203 |
+
self.keywords = _ensure_list(value, 'keywords')
|
| 1204 |
+
|
| 1205 |
+
def get_platforms(self):
|
| 1206 |
+
return self.platforms or ["UNKNOWN"]
|
| 1207 |
+
|
| 1208 |
+
def set_platforms(self, value):
|
| 1209 |
+
self.platforms = _ensure_list(value, 'platforms')
|
| 1210 |
+
|
| 1211 |
+
def get_classifiers(self):
|
| 1212 |
+
return self.classifiers or []
|
| 1213 |
+
|
| 1214 |
+
def set_classifiers(self, value):
|
| 1215 |
+
self.classifiers = _ensure_list(value, 'classifiers')
|
| 1216 |
+
|
| 1217 |
+
def get_download_url(self):
|
| 1218 |
+
return self.download_url or "UNKNOWN"
|
| 1219 |
+
|
| 1220 |
+
# PEP 314
|
| 1221 |
+
def get_requires(self):
|
| 1222 |
+
return self.requires or []
|
| 1223 |
+
|
| 1224 |
+
def set_requires(self, value):
|
| 1225 |
+
import distutils.versionpredicate
|
| 1226 |
+
for v in value:
|
| 1227 |
+
distutils.versionpredicate.VersionPredicate(v)
|
| 1228 |
+
self.requires = list(value)
|
| 1229 |
+
|
| 1230 |
+
def get_provides(self):
|
| 1231 |
+
return self.provides or []
|
| 1232 |
+
|
| 1233 |
+
def set_provides(self, value):
|
| 1234 |
+
value = [v.strip() for v in value]
|
| 1235 |
+
for v in value:
|
| 1236 |
+
import distutils.versionpredicate
|
| 1237 |
+
distutils.versionpredicate.split_provision(v)
|
| 1238 |
+
self.provides = value
|
| 1239 |
+
|
| 1240 |
+
def get_obsoletes(self):
|
| 1241 |
+
return self.obsoletes or []
|
| 1242 |
+
|
| 1243 |
+
def set_obsoletes(self, value):
|
| 1244 |
+
import distutils.versionpredicate
|
| 1245 |
+
for v in value:
|
| 1246 |
+
distutils.versionpredicate.VersionPredicate(v)
|
| 1247 |
+
self.obsoletes = list(value)
|
| 1248 |
+
|
| 1249 |
+
def fix_help_options(options):
|
| 1250 |
+
"""Convert a 4-tuple 'help_options' list as found in various command
|
| 1251 |
+
classes to the 3-tuple form required by FancyGetopt.
|
| 1252 |
+
"""
|
| 1253 |
+
new_options = []
|
| 1254 |
+
for help_tuple in options:
|
| 1255 |
+
new_options.append(help_tuple[0:3])
|
| 1256 |
+
return new_options
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/errors.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.errors
|
| 2 |
+
|
| 3 |
+
Provides exceptions used by the Distutils modules. Note that Distutils
|
| 4 |
+
modules may raise standard exceptions; in particular, SystemExit is
|
| 5 |
+
usually raised for errors that are obviously the end-user's fault
|
| 6 |
+
(eg. bad command-line arguments).
|
| 7 |
+
|
| 8 |
+
This module is safe to use in "from ... import *" mode; it only exports
|
| 9 |
+
symbols whose names start with "Distutils" and end with "Error"."""
|
| 10 |
+
|
| 11 |
+
class DistutilsError (Exception):
|
| 12 |
+
"""The root of all Distutils evil."""
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
class DistutilsModuleError (DistutilsError):
|
| 16 |
+
"""Unable to load an expected module, or to find an expected class
|
| 17 |
+
within some module (in particular, command modules and classes)."""
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
class DistutilsClassError (DistutilsError):
|
| 21 |
+
"""Some command class (or possibly distribution class, if anyone
|
| 22 |
+
feels a need to subclass Distribution) is found not to be holding
|
| 23 |
+
up its end of the bargain, ie. implementing some part of the
|
| 24 |
+
"command "interface."""
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
class DistutilsGetoptError (DistutilsError):
|
| 28 |
+
"""The option table provided to 'fancy_getopt()' is bogus."""
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
class DistutilsArgError (DistutilsError):
|
| 32 |
+
"""Raised by fancy_getopt in response to getopt.error -- ie. an
|
| 33 |
+
error in the command line usage."""
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
class DistutilsFileError (DistutilsError):
|
| 37 |
+
"""Any problems in the filesystem: expected file not found, etc.
|
| 38 |
+
Typically this is for problems that we detect before OSError
|
| 39 |
+
could be raised."""
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
class DistutilsOptionError (DistutilsError):
|
| 43 |
+
"""Syntactic/semantic errors in command options, such as use of
|
| 44 |
+
mutually conflicting options, or inconsistent options,
|
| 45 |
+
badly-spelled values, etc. No distinction is made between option
|
| 46 |
+
values originating in the setup script, the command line, config
|
| 47 |
+
files, or what-have-you -- but if we *know* something originated in
|
| 48 |
+
the setup script, we'll raise DistutilsSetupError instead."""
|
| 49 |
+
pass
|
| 50 |
+
|
| 51 |
+
class DistutilsSetupError (DistutilsError):
|
| 52 |
+
"""For errors that can be definitely blamed on the setup script,
|
| 53 |
+
such as invalid keyword arguments to 'setup()'."""
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
class DistutilsPlatformError (DistutilsError):
|
| 57 |
+
"""We don't know how to do something on the current platform (but
|
| 58 |
+
we do know how to do it on some platform) -- eg. trying to compile
|
| 59 |
+
C files on a platform not supported by a CCompiler subclass."""
|
| 60 |
+
pass
|
| 61 |
+
|
| 62 |
+
class DistutilsExecError (DistutilsError):
|
| 63 |
+
"""Any problems executing an external program (such as the C
|
| 64 |
+
compiler, when compiling C files)."""
|
| 65 |
+
pass
|
| 66 |
+
|
| 67 |
+
class DistutilsInternalError (DistutilsError):
|
| 68 |
+
"""Internal inconsistencies or impossibilities (obviously, this
|
| 69 |
+
should never be seen if the code is working!)."""
|
| 70 |
+
pass
|
| 71 |
+
|
| 72 |
+
class DistutilsTemplateError (DistutilsError):
|
| 73 |
+
"""Syntax error in a file list template."""
|
| 74 |
+
|
| 75 |
+
class DistutilsByteCompileError(DistutilsError):
|
| 76 |
+
"""Byte compile error."""
|
| 77 |
+
|
| 78 |
+
# Exception classes used by the CCompiler implementation classes
|
| 79 |
+
class CCompilerError (Exception):
|
| 80 |
+
"""Some compile/link operation failed."""
|
| 81 |
+
|
| 82 |
+
class PreprocessError (CCompilerError):
|
| 83 |
+
"""Failure to preprocess one or more C/C++ files."""
|
| 84 |
+
|
| 85 |
+
class CompileError (CCompilerError):
|
| 86 |
+
"""Failure to compile one or more C/C++ source files."""
|
| 87 |
+
|
| 88 |
+
class LibError (CCompilerError):
|
| 89 |
+
"""Failure to create a static library from one or more C/C++ object
|
| 90 |
+
files."""
|
| 91 |
+
|
| 92 |
+
class LinkError (CCompilerError):
|
| 93 |
+
"""Failure to link one or more C/C++ object files into an executable
|
| 94 |
+
or shared library file."""
|
| 95 |
+
|
| 96 |
+
class UnknownFileError (CCompilerError):
|
| 97 |
+
"""Attempt to process an unknown file type."""
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/extension.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/fancy_getopt.py
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
physworld_p1_20261018/envs/p1/lib/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.file_util
|
| 2 |
+
|
| 3 |
+
Utility functions for operating on single files.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from distutils.errors import DistutilsFileError
|
| 8 |
+
from distutils import log
|
| 9 |
+
|
| 10 |
+
# for generating verbose output in 'copy_file()'
|
| 11 |
+
_copy_action = { None: 'copying',
|
| 12 |
+
'hard': 'hard linking',
|
| 13 |
+
'sym': 'symbolically linking' }
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _copy_file_contents(src, dst, buffer_size=16*1024):
|
| 17 |
+
"""Copy the file 'src' to 'dst'; both must be filenames. Any error
|
| 18 |
+
opening either file, reading from 'src', or writing to 'dst', raises
|
| 19 |
+
DistutilsFileError. Data is read/written in chunks of 'buffer_size'
|
| 20 |
+
bytes (default 16k). No attempt is made to handle anything apart from
|
| 21 |
+
regular files.
|
| 22 |
+
"""
|
| 23 |
+
# Stolen from shutil module in the standard library, but with
|
| 24 |
+
# custom error-handling added.
|
| 25 |
+
fsrc = None
|
| 26 |
+
fdst = None
|
| 27 |
+
try:
|
| 28 |
+
try:
|
| 29 |
+
fsrc = open(src, 'rb')
|
| 30 |
+
except OSError as e:
|
| 31 |
+
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
|
| 32 |
+
|
| 33 |
+
if os.path.exists(dst):
|
| 34 |
+
try:
|
| 35 |
+
os.unlink(dst)
|
| 36 |
+
except OSError as e:
|
| 37 |
+
raise DistutilsFileError(
|
| 38 |
+
"could not delete '%s': %s" % (dst, e.strerror))
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
fdst = open(dst, 'wb')
|
| 42 |
+
except OSError as e:
|
| 43 |
+
raise DistutilsFileError(
|
| 44 |
+
"could not create '%s': %s" % (dst, e.strerror))
|
| 45 |
+
|
| 46 |
+
while True:
|
| 47 |
+
try:
|
| 48 |
+
buf = fsrc.read(buffer_size)
|
| 49 |
+
except OSError as e:
|
| 50 |
+
raise DistutilsFileError(
|
| 51 |
+
"could not read from '%s': %s" % (src, e.strerror))
|
| 52 |
+
|
| 53 |
+
if not buf:
|
| 54 |
+
break
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
fdst.write(buf)
|
| 58 |
+
except OSError as e:
|
| 59 |
+
raise DistutilsFileError(
|
| 60 |
+
"could not write to '%s': %s" % (dst, e.strerror))
|
| 61 |
+
finally:
|
| 62 |
+
if fdst:
|
| 63 |
+
fdst.close()
|
| 64 |
+
if fsrc:
|
| 65 |
+
fsrc.close()
|
| 66 |
+
|
| 67 |
+
def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
|
| 68 |
+
link=None, verbose=1, dry_run=0):
|
| 69 |
+
"""Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is
|
| 70 |
+
copied there with the same name; otherwise, it must be a filename. (If
|
| 71 |
+
the file exists, it will be ruthlessly clobbered.) If 'preserve_mode'
|
| 72 |
+
is true (the default), the file's mode (type and permission bits, or
|
| 73 |
+
whatever is analogous on the current platform) is copied. If
|
| 74 |
+
'preserve_times' is true (the default), the last-modified and
|
| 75 |
+
last-access times are copied as well. If 'update' is true, 'src' will
|
| 76 |
+
only be copied if 'dst' does not exist, or if 'dst' does exist but is
|
| 77 |
+
older than 'src'.
|
| 78 |
+
|
| 79 |
+
'link' allows you to make hard links (os.link) or symbolic links
|
| 80 |
+
(os.symlink) instead of copying: set it to "hard" or "sym"; if it is
|
| 81 |
+
None (the default), files are copied. Don't set 'link' on systems that
|
| 82 |
+
don't support it: 'copy_file()' doesn't check if hard or symbolic
|
| 83 |
+
linking is available. If hardlink fails, falls back to
|
| 84 |
+
_copy_file_contents().
|
| 85 |
+
|
| 86 |
+
Under Mac OS, uses the native file copy function in macostools; on
|
| 87 |
+
other systems, uses '_copy_file_contents()' to copy file contents.
|
| 88 |
+
|
| 89 |
+
Return a tuple (dest_name, copied): 'dest_name' is the actual name of
|
| 90 |
+
the output file, and 'copied' is true if the file was copied (or would
|
| 91 |
+
have been copied, if 'dry_run' true).
|
| 92 |
+
"""
|
| 93 |
+
# XXX if the destination file already exists, we clobber it if
|
| 94 |
+
# copying, but blow up if linking. Hmmm. And I don't know what
|
| 95 |
+
# macostools.copyfile() does. Should definitely be consistent, and
|
| 96 |
+
# should probably blow up if destination exists and we would be
|
| 97 |
+
# changing it (ie. it's not already a hard/soft link to src OR
|
| 98 |
+
# (not update) and (src newer than dst).
|
| 99 |
+
|
| 100 |
+
from distutils.dep_util import newer
|
| 101 |
+
from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE
|
| 102 |
+
|
| 103 |
+
if not os.path.isfile(src):
|
| 104 |
+
raise DistutilsFileError(
|
| 105 |
+
"can't copy '%s': doesn't exist or not a regular file" % src)
|
| 106 |
+
|
| 107 |
+
if os.path.isdir(dst):
|
| 108 |
+
dir = dst
|
| 109 |
+
dst = os.path.join(dst, os.path.basename(src))
|
| 110 |
+
else:
|
| 111 |
+
dir = os.path.dirname(dst)
|
| 112 |
+
|
| 113 |
+
if update and not newer(src, dst):
|
| 114 |
+
if verbose >= 1:
|
| 115 |
+
log.debug("not copying %s (output up-to-date)", src)
|
| 116 |
+
return (dst, 0)
|
| 117 |
+
|
| 118 |
+
try:
|
| 119 |
+
action = _copy_action[link]
|
| 120 |
+
except KeyError:
|
| 121 |
+
raise ValueError("invalid value '%s' for 'link' argument" % link)
|
| 122 |
+
|
| 123 |
+
if verbose >= 1:
|
| 124 |
+
if os.path.basename(dst) == os.path.basename(src):
|
| 125 |
+
log.info("%s %s -> %s", action, src, dir)
|
| 126 |
+
else:
|
| 127 |
+
log.info("%s %s -> %s", action, src, dst)
|
| 128 |
+
|
| 129 |
+
if dry_run:
|
| 130 |
+
return (dst, 1)
|
| 131 |
+
|
| 132 |
+
# If linking (hard or symbolic), use the appropriate system call
|
| 133 |
+
# (Unix only, of course, but that's the caller's responsibility)
|
| 134 |
+
elif link == 'hard':
|
| 135 |
+
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
|
| 136 |
+
try:
|
| 137 |
+
os.link(src, dst)
|
| 138 |
+
return (dst, 1)
|
| 139 |
+
except OSError:
|
| 140 |
+
# If hard linking fails, fall back on copying file
|
| 141 |
+
# (some special filesystems don't support hard linking
|
| 142 |
+
# even under Unix, see issue #8876).
|
| 143 |
+
pass
|
| 144 |
+
elif link == 'sym':
|
| 145 |
+
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
|
| 146 |
+
os.symlink(src, dst)
|
| 147 |
+
return (dst, 1)
|
| 148 |
+
|
| 149 |
+
# Otherwise (non-Mac, not linking), copy the file contents and
|
| 150 |
+
# (optionally) copy the times and mode.
|
| 151 |
+
_copy_file_contents(src, dst)
|
| 152 |
+
if preserve_mode or preserve_times:
|
| 153 |
+
st = os.stat(src)
|
| 154 |
+
|
| 155 |
+
# According to David Ascher <da@ski.org>, utime() should be done
|
| 156 |
+
# before chmod() (at least under NT).
|
| 157 |
+
if preserve_times:
|
| 158 |
+
os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
|
| 159 |
+
if preserve_mode:
|
| 160 |
+
os.chmod(dst, S_IMODE(st[ST_MODE]))
|
| 161 |
+
|
| 162 |
+
return (dst, 1)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# XXX I suspect this is Unix-specific -- need porting help!
|
| 166 |
+
def move_file (src, dst,
|
| 167 |
+
verbose=1,
|
| 168 |
+
dry_run=0):
|
| 169 |
+
|
| 170 |
+
"""Move a file 'src' to 'dst'. If 'dst' is a directory, the file will
|
| 171 |
+
be moved into it with the same name; otherwise, 'src' is just renamed
|
| 172 |
+
to 'dst'. Return the new full name of the file.
|
| 173 |
+
|
| 174 |
+
Handles cross-device moves on Unix using 'copy_file()'. What about
|
| 175 |
+
other systems???
|
| 176 |
+
"""
|
| 177 |
+
from os.path import exists, isfile, isdir, basename, dirname
|
| 178 |
+
import errno
|
| 179 |
+
|
| 180 |
+
if verbose >= 1:
|
| 181 |
+
log.info("moving %s -> %s", src, dst)
|
| 182 |
+
|
| 183 |
+
if dry_run:
|
| 184 |
+
return dst
|
| 185 |
+
|
| 186 |
+
if not isfile(src):
|
| 187 |
+
raise DistutilsFileError("can't move '%s': not a regular file" % src)
|
| 188 |
+
|
| 189 |
+
if isdir(dst):
|
| 190 |
+
dst = os.path.join(dst, basename(src))
|
| 191 |
+
elif exists(dst):
|
| 192 |
+
raise DistutilsFileError(
|
| 193 |
+
"can't move '%s': destination '%s' already exists" %
|
| 194 |
+
(src, dst))
|
| 195 |
+
|
| 196 |
+
if not isdir(dirname(dst)):
|
| 197 |
+
raise DistutilsFileError(
|
| 198 |
+
"can't move '%s': destination '%s' not a valid path" %
|
| 199 |
+
(src, dst))
|
| 200 |
+
|
| 201 |
+
copy_it = False
|
| 202 |
+
try:
|
| 203 |
+
os.rename(src, dst)
|
| 204 |
+
except OSError as e:
|
| 205 |
+
(num, msg) = e.args
|
| 206 |
+
if num == errno.EXDEV:
|
| 207 |
+
copy_it = True
|
| 208 |
+
else:
|
| 209 |
+
raise DistutilsFileError(
|
| 210 |
+
"couldn't move '%s' to '%s': %s" % (src, dst, msg))
|
| 211 |
+
|
| 212 |
+
if copy_it:
|
| 213 |
+
copy_file(src, dst, verbose=verbose)
|
| 214 |
+
try:
|
| 215 |
+
os.unlink(src)
|
| 216 |
+
except OSError as e:
|
| 217 |
+
(num, msg) = e.args
|
| 218 |
+
try:
|
| 219 |
+
os.unlink(dst)
|
| 220 |
+
except OSError:
|
| 221 |
+
pass
|
| 222 |
+
raise DistutilsFileError(
|
| 223 |
+
"couldn't move '%s' to '%s' by copy/delete: "
|
| 224 |
+
"delete '%s' failed: %s"
|
| 225 |
+
% (src, dst, src, msg))
|
| 226 |
+
return dst
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def write_file (filename, contents):
|
| 230 |
+
"""Create a file with the specified name and write 'contents' (a
|
| 231 |
+
sequence of strings without line terminators) to it.
|
| 232 |
+
"""
|
| 233 |
+
f = open(filename, "w")
|
| 234 |
+
try:
|
| 235 |
+
for line in contents:
|
| 236 |
+
f.write(line + "\n")
|
| 237 |
+
finally:
|
| 238 |
+
f.close()
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/filelist.py
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.filelist
|
| 2 |
+
|
| 3 |
+
Provides the FileList class, used for poking about the filesystem
|
| 4 |
+
and building lists of files.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os, re
|
| 8 |
+
import fnmatch
|
| 9 |
+
import functools
|
| 10 |
+
from distutils.util import convert_path
|
| 11 |
+
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
|
| 12 |
+
from distutils import log
|
| 13 |
+
|
| 14 |
+
class FileList:
|
| 15 |
+
"""A list of files built by on exploring the filesystem and filtered by
|
| 16 |
+
applying various patterns to what we find there.
|
| 17 |
+
|
| 18 |
+
Instance attributes:
|
| 19 |
+
dir
|
| 20 |
+
directory from which files will be taken -- only used if
|
| 21 |
+
'allfiles' not supplied to constructor
|
| 22 |
+
files
|
| 23 |
+
list of filenames currently being built/filtered/manipulated
|
| 24 |
+
allfiles
|
| 25 |
+
complete list of files under consideration (ie. without any
|
| 26 |
+
filtering applied)
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
def __init__(self, warn=None, debug_print=None):
|
| 30 |
+
# ignore argument to FileList, but keep them for backwards
|
| 31 |
+
# compatibility
|
| 32 |
+
self.allfiles = None
|
| 33 |
+
self.files = []
|
| 34 |
+
|
| 35 |
+
def set_allfiles(self, allfiles):
|
| 36 |
+
self.allfiles = allfiles
|
| 37 |
+
|
| 38 |
+
def findall(self, dir=os.curdir):
|
| 39 |
+
self.allfiles = findall(dir)
|
| 40 |
+
|
| 41 |
+
def debug_print(self, msg):
|
| 42 |
+
"""Print 'msg' to stdout if the global DEBUG (taken from the
|
| 43 |
+
DISTUTILS_DEBUG environment variable) flag is true.
|
| 44 |
+
"""
|
| 45 |
+
from distutils.debug import DEBUG
|
| 46 |
+
if DEBUG:
|
| 47 |
+
print(msg)
|
| 48 |
+
|
| 49 |
+
# -- List-like methods ---------------------------------------------
|
| 50 |
+
|
| 51 |
+
def append(self, item):
|
| 52 |
+
self.files.append(item)
|
| 53 |
+
|
| 54 |
+
def extend(self, items):
|
| 55 |
+
self.files.extend(items)
|
| 56 |
+
|
| 57 |
+
def sort(self):
|
| 58 |
+
# Not a strict lexical sort!
|
| 59 |
+
sortable_files = sorted(map(os.path.split, self.files))
|
| 60 |
+
self.files = []
|
| 61 |
+
for sort_tuple in sortable_files:
|
| 62 |
+
self.files.append(os.path.join(*sort_tuple))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# -- Other miscellaneous utility methods ---------------------------
|
| 66 |
+
|
| 67 |
+
def remove_duplicates(self):
|
| 68 |
+
# Assumes list has been sorted!
|
| 69 |
+
for i in range(len(self.files) - 1, 0, -1):
|
| 70 |
+
if self.files[i] == self.files[i - 1]:
|
| 71 |
+
del self.files[i]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# -- "File template" methods ---------------------------------------
|
| 75 |
+
|
| 76 |
+
def _parse_template_line(self, line):
|
| 77 |
+
words = line.split()
|
| 78 |
+
action = words[0]
|
| 79 |
+
|
| 80 |
+
patterns = dir = dir_pattern = None
|
| 81 |
+
|
| 82 |
+
if action in ('include', 'exclude',
|
| 83 |
+
'global-include', 'global-exclude'):
|
| 84 |
+
if len(words) < 2:
|
| 85 |
+
raise DistutilsTemplateError(
|
| 86 |
+
"'%s' expects <pattern1> <pattern2> ..." % action)
|
| 87 |
+
patterns = [convert_path(w) for w in words[1:]]
|
| 88 |
+
elif action in ('recursive-include', 'recursive-exclude'):
|
| 89 |
+
if len(words) < 3:
|
| 90 |
+
raise DistutilsTemplateError(
|
| 91 |
+
"'%s' expects <dir> <pattern1> <pattern2> ..." % action)
|
| 92 |
+
dir = convert_path(words[1])
|
| 93 |
+
patterns = [convert_path(w) for w in words[2:]]
|
| 94 |
+
elif action in ('graft', 'prune'):
|
| 95 |
+
if len(words) != 2:
|
| 96 |
+
raise DistutilsTemplateError(
|
| 97 |
+
"'%s' expects a single <dir_pattern>" % action)
|
| 98 |
+
dir_pattern = convert_path(words[1])
|
| 99 |
+
else:
|
| 100 |
+
raise DistutilsTemplateError("unknown action '%s'" % action)
|
| 101 |
+
|
| 102 |
+
return (action, patterns, dir, dir_pattern)
|
| 103 |
+
|
| 104 |
+
def process_template_line(self, line):
|
| 105 |
+
# Parse the line: split it up, make sure the right number of words
|
| 106 |
+
# is there, and return the relevant words. 'action' is always
|
| 107 |
+
# defined: it's the first word of the line. Which of the other
|
| 108 |
+
# three are defined depends on the action; it'll be either
|
| 109 |
+
# patterns, (dir and patterns), or (dir_pattern).
|
| 110 |
+
(action, patterns, dir, dir_pattern) = self._parse_template_line(line)
|
| 111 |
+
|
| 112 |
+
# OK, now we know that the action is valid and we have the
|
| 113 |
+
# right number of words on the line for that action -- so we
|
| 114 |
+
# can proceed with minimal error-checking.
|
| 115 |
+
if action == 'include':
|
| 116 |
+
self.debug_print("include " + ' '.join(patterns))
|
| 117 |
+
for pattern in patterns:
|
| 118 |
+
if not self.include_pattern(pattern, anchor=1):
|
| 119 |
+
log.warn("warning: no files found matching '%s'",
|
| 120 |
+
pattern)
|
| 121 |
+
|
| 122 |
+
elif action == 'exclude':
|
| 123 |
+
self.debug_print("exclude " + ' '.join(patterns))
|
| 124 |
+
for pattern in patterns:
|
| 125 |
+
if not self.exclude_pattern(pattern, anchor=1):
|
| 126 |
+
log.warn(("warning: no previously-included files "
|
| 127 |
+
"found matching '%s'"), pattern)
|
| 128 |
+
|
| 129 |
+
elif action == 'global-include':
|
| 130 |
+
self.debug_print("global-include " + ' '.join(patterns))
|
| 131 |
+
for pattern in patterns:
|
| 132 |
+
if not self.include_pattern(pattern, anchor=0):
|
| 133 |
+
log.warn(("warning: no files found matching '%s' "
|
| 134 |
+
"anywhere in distribution"), pattern)
|
| 135 |
+
|
| 136 |
+
elif action == 'global-exclude':
|
| 137 |
+
self.debug_print("global-exclude " + ' '.join(patterns))
|
| 138 |
+
for pattern in patterns:
|
| 139 |
+
if not self.exclude_pattern(pattern, anchor=0):
|
| 140 |
+
log.warn(("warning: no previously-included files matching "
|
| 141 |
+
"'%s' found anywhere in distribution"),
|
| 142 |
+
pattern)
|
| 143 |
+
|
| 144 |
+
elif action == 'recursive-include':
|
| 145 |
+
self.debug_print("recursive-include %s %s" %
|
| 146 |
+
(dir, ' '.join(patterns)))
|
| 147 |
+
for pattern in patterns:
|
| 148 |
+
if not self.include_pattern(pattern, prefix=dir):
|
| 149 |
+
log.warn(("warning: no files found matching '%s' "
|
| 150 |
+
"under directory '%s'"),
|
| 151 |
+
pattern, dir)
|
| 152 |
+
|
| 153 |
+
elif action == 'recursive-exclude':
|
| 154 |
+
self.debug_print("recursive-exclude %s %s" %
|
| 155 |
+
(dir, ' '.join(patterns)))
|
| 156 |
+
for pattern in patterns:
|
| 157 |
+
if not self.exclude_pattern(pattern, prefix=dir):
|
| 158 |
+
log.warn(("warning: no previously-included files matching "
|
| 159 |
+
"'%s' found under directory '%s'"),
|
| 160 |
+
pattern, dir)
|
| 161 |
+
|
| 162 |
+
elif action == 'graft':
|
| 163 |
+
self.debug_print("graft " + dir_pattern)
|
| 164 |
+
if not self.include_pattern(None, prefix=dir_pattern):
|
| 165 |
+
log.warn("warning: no directories found matching '%s'",
|
| 166 |
+
dir_pattern)
|
| 167 |
+
|
| 168 |
+
elif action == 'prune':
|
| 169 |
+
self.debug_print("prune " + dir_pattern)
|
| 170 |
+
if not self.exclude_pattern(None, prefix=dir_pattern):
|
| 171 |
+
log.warn(("no previously-included directories found "
|
| 172 |
+
"matching '%s'"), dir_pattern)
|
| 173 |
+
else:
|
| 174 |
+
raise DistutilsInternalError(
|
| 175 |
+
"this cannot happen: invalid action '%s'" % action)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
# -- Filtering/selection methods -----------------------------------
|
| 179 |
+
|
| 180 |
+
def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
|
| 181 |
+
"""Select strings (presumably filenames) from 'self.files' that
|
| 182 |
+
match 'pattern', a Unix-style wildcard (glob) pattern. Patterns
|
| 183 |
+
are not quite the same as implemented by the 'fnmatch' module: '*'
|
| 184 |
+
and '?' match non-special characters, where "special" is platform-
|
| 185 |
+
dependent: slash on Unix; colon, slash, and backslash on
|
| 186 |
+
DOS/Windows; and colon on Mac OS.
|
| 187 |
+
|
| 188 |
+
If 'anchor' is true (the default), then the pattern match is more
|
| 189 |
+
stringent: "*.py" will match "foo.py" but not "foo/bar.py". If
|
| 190 |
+
'anchor' is false, both of these will match.
|
| 191 |
+
|
| 192 |
+
If 'prefix' is supplied, then only filenames starting with 'prefix'
|
| 193 |
+
(itself a pattern) and ending with 'pattern', with anything in between
|
| 194 |
+
them, will match. 'anchor' is ignored in this case.
|
| 195 |
+
|
| 196 |
+
If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
|
| 197 |
+
'pattern' is assumed to be either a string containing a regex or a
|
| 198 |
+
regex object -- no translation is done, the regex is just compiled
|
| 199 |
+
and used as-is.
|
| 200 |
+
|
| 201 |
+
Selected strings will be added to self.files.
|
| 202 |
+
|
| 203 |
+
Return True if files are found, False otherwise.
|
| 204 |
+
"""
|
| 205 |
+
# XXX docstring lying about what the special chars are?
|
| 206 |
+
files_found = False
|
| 207 |
+
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
|
| 208 |
+
self.debug_print("include_pattern: applying regex r'%s'" %
|
| 209 |
+
pattern_re.pattern)
|
| 210 |
+
|
| 211 |
+
# delayed loading of allfiles list
|
| 212 |
+
if self.allfiles is None:
|
| 213 |
+
self.findall()
|
| 214 |
+
|
| 215 |
+
for name in self.allfiles:
|
| 216 |
+
if pattern_re.search(name):
|
| 217 |
+
self.debug_print(" adding " + name)
|
| 218 |
+
self.files.append(name)
|
| 219 |
+
files_found = True
|
| 220 |
+
return files_found
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def exclude_pattern (self, pattern,
|
| 224 |
+
anchor=1, prefix=None, is_regex=0):
|
| 225 |
+
"""Remove strings (presumably filenames) from 'files' that match
|
| 226 |
+
'pattern'. Other parameters are the same as for
|
| 227 |
+
'include_pattern()', above.
|
| 228 |
+
The list 'self.files' is modified in place.
|
| 229 |
+
Return True if files are found, False otherwise.
|
| 230 |
+
"""
|
| 231 |
+
files_found = False
|
| 232 |
+
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
|
| 233 |
+
self.debug_print("exclude_pattern: applying regex r'%s'" %
|
| 234 |
+
pattern_re.pattern)
|
| 235 |
+
for i in range(len(self.files)-1, -1, -1):
|
| 236 |
+
if pattern_re.search(self.files[i]):
|
| 237 |
+
self.debug_print(" removing " + self.files[i])
|
| 238 |
+
del self.files[i]
|
| 239 |
+
files_found = True
|
| 240 |
+
return files_found
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
# ----------------------------------------------------------------------
|
| 244 |
+
# Utility functions
|
| 245 |
+
|
| 246 |
+
def _find_all_simple(path):
|
| 247 |
+
"""
|
| 248 |
+
Find all files under 'path'
|
| 249 |
+
"""
|
| 250 |
+
results = (
|
| 251 |
+
os.path.join(base, file)
|
| 252 |
+
for base, dirs, files in os.walk(path, followlinks=True)
|
| 253 |
+
for file in files
|
| 254 |
+
)
|
| 255 |
+
return filter(os.path.isfile, results)
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def findall(dir=os.curdir):
|
| 259 |
+
"""
|
| 260 |
+
Find all files under 'dir' and return the list of full filenames.
|
| 261 |
+
Unless dir is '.', return full filenames with dir prepended.
|
| 262 |
+
"""
|
| 263 |
+
files = _find_all_simple(dir)
|
| 264 |
+
if dir == os.curdir:
|
| 265 |
+
make_rel = functools.partial(os.path.relpath, start=dir)
|
| 266 |
+
files = map(make_rel, files)
|
| 267 |
+
return list(files)
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def glob_to_re(pattern):
|
| 271 |
+
"""Translate a shell-like glob pattern to a regular expression; return
|
| 272 |
+
a string containing the regex. Differs from 'fnmatch.translate()' in
|
| 273 |
+
that '*' does not match "special characters" (which are
|
| 274 |
+
platform-specific).
|
| 275 |
+
"""
|
| 276 |
+
pattern_re = fnmatch.translate(pattern)
|
| 277 |
+
|
| 278 |
+
# '?' and '*' in the glob pattern become '.' and '.*' in the RE, which
|
| 279 |
+
# IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix,
|
| 280 |
+
# and by extension they shouldn't match such "special characters" under
|
| 281 |
+
# any OS. So change all non-escaped dots in the RE to match any
|
| 282 |
+
# character except the special characters (currently: just os.sep).
|
| 283 |
+
sep = os.sep
|
| 284 |
+
if os.sep == '\\':
|
| 285 |
+
# we're using a regex to manipulate a regex, so we need
|
| 286 |
+
# to escape the backslash twice
|
| 287 |
+
sep = r'\\\\'
|
| 288 |
+
escaped = r'\1[^%s]' % sep
|
| 289 |
+
pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', escaped, pattern_re)
|
| 290 |
+
return pattern_re
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
|
| 294 |
+
"""Translate a shell-like wildcard pattern to a compiled regular
|
| 295 |
+
expression. Return the compiled regex. If 'is_regex' true,
|
| 296 |
+
then 'pattern' is directly compiled to a regex (if it's a string)
|
| 297 |
+
or just returned as-is (assumes it's a regex object).
|
| 298 |
+
"""
|
| 299 |
+
if is_regex:
|
| 300 |
+
if isinstance(pattern, str):
|
| 301 |
+
return re.compile(pattern)
|
| 302 |
+
else:
|
| 303 |
+
return pattern
|
| 304 |
+
|
| 305 |
+
# ditch start and end characters
|
| 306 |
+
start, _, end = glob_to_re('_').partition('_')
|
| 307 |
+
|
| 308 |
+
if pattern:
|
| 309 |
+
pattern_re = glob_to_re(pattern)
|
| 310 |
+
assert pattern_re.startswith(start) and pattern_re.endswith(end)
|
| 311 |
+
else:
|
| 312 |
+
pattern_re = ''
|
| 313 |
+
|
| 314 |
+
if prefix is not None:
|
| 315 |
+
prefix_re = glob_to_re(prefix)
|
| 316 |
+
assert prefix_re.startswith(start) and prefix_re.endswith(end)
|
| 317 |
+
prefix_re = prefix_re[len(start): len(prefix_re) - len(end)]
|
| 318 |
+
sep = os.sep
|
| 319 |
+
if os.sep == '\\':
|
| 320 |
+
sep = r'\\'
|
| 321 |
+
pattern_re = pattern_re[len(start): len(pattern_re) - len(end)]
|
| 322 |
+
pattern_re = r'%s\A%s%s.*%s%s' % (start, prefix_re, sep, pattern_re, end)
|
| 323 |
+
else: # no prefix -- respect anchor flag
|
| 324 |
+
if anchor:
|
| 325 |
+
pattern_re = r'%s\A%s' % (start, pattern_re[len(start):])
|
| 326 |
+
|
| 327 |
+
return re.compile(pattern_re)
|
physworld_p1_20261018/envs/p1/lib/python3.11/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)
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/msvc9compiler.py
ADDED
|
@@ -0,0 +1,788 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.msvc9compiler
|
| 2 |
+
|
| 3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
| 4 |
+
for the Microsoft Visual Studio 2008.
|
| 5 |
+
|
| 6 |
+
The module is compatible with VS 2005 and VS 2008. You can find legacy support
|
| 7 |
+
for older versions of VS in distutils.msvccompiler.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
# Written by Perry Stoll
|
| 11 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
| 12 |
+
# finding DevStudio (through the registry)
|
| 13 |
+
# ported to VS2005 and VS 2008 by Christian Heimes
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import re
|
| 19 |
+
|
| 20 |
+
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
|
| 21 |
+
CompileError, LibError, LinkError
|
| 22 |
+
from distutils.ccompiler import CCompiler, gen_lib_options
|
| 23 |
+
from distutils import log
|
| 24 |
+
from distutils.util import get_platform
|
| 25 |
+
|
| 26 |
+
import winreg
|
| 27 |
+
|
| 28 |
+
RegOpenKeyEx = winreg.OpenKeyEx
|
| 29 |
+
RegEnumKey = winreg.EnumKey
|
| 30 |
+
RegEnumValue = winreg.EnumValue
|
| 31 |
+
RegError = winreg.error
|
| 32 |
+
|
| 33 |
+
HKEYS = (winreg.HKEY_USERS,
|
| 34 |
+
winreg.HKEY_CURRENT_USER,
|
| 35 |
+
winreg.HKEY_LOCAL_MACHINE,
|
| 36 |
+
winreg.HKEY_CLASSES_ROOT)
|
| 37 |
+
|
| 38 |
+
NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32)
|
| 39 |
+
if NATIVE_WIN64:
|
| 40 |
+
# Visual C++ is a 32-bit application, so we need to look in
|
| 41 |
+
# the corresponding registry branch, if we're running a
|
| 42 |
+
# 64-bit Python on Win64
|
| 43 |
+
VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
|
| 44 |
+
WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"
|
| 45 |
+
NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"
|
| 46 |
+
else:
|
| 47 |
+
VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f"
|
| 48 |
+
WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows"
|
| 49 |
+
NET_BASE = r"Software\Microsoft\.NETFramework"
|
| 50 |
+
|
| 51 |
+
# A map keyed by get_platform() return values to values accepted by
|
| 52 |
+
# 'vcvarsall.bat'. Note a cross-compile may combine these (eg, 'x86_amd64' is
|
| 53 |
+
# the param to cross-compile on x86 targeting amd64.)
|
| 54 |
+
PLAT_TO_VCVARS = {
|
| 55 |
+
'win32' : 'x86',
|
| 56 |
+
'win-amd64' : 'amd64',
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
class Reg:
|
| 60 |
+
"""Helper class to read values from the registry
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
def get_value(cls, path, key):
|
| 64 |
+
for base in HKEYS:
|
| 65 |
+
d = cls.read_values(base, path)
|
| 66 |
+
if d and key in d:
|
| 67 |
+
return d[key]
|
| 68 |
+
raise KeyError(key)
|
| 69 |
+
get_value = classmethod(get_value)
|
| 70 |
+
|
| 71 |
+
def read_keys(cls, base, key):
|
| 72 |
+
"""Return list of registry keys."""
|
| 73 |
+
try:
|
| 74 |
+
handle = RegOpenKeyEx(base, key)
|
| 75 |
+
except RegError:
|
| 76 |
+
return None
|
| 77 |
+
L = []
|
| 78 |
+
i = 0
|
| 79 |
+
while True:
|
| 80 |
+
try:
|
| 81 |
+
k = RegEnumKey(handle, i)
|
| 82 |
+
except RegError:
|
| 83 |
+
break
|
| 84 |
+
L.append(k)
|
| 85 |
+
i += 1
|
| 86 |
+
return L
|
| 87 |
+
read_keys = classmethod(read_keys)
|
| 88 |
+
|
| 89 |
+
def read_values(cls, base, key):
|
| 90 |
+
"""Return dict of registry keys and values.
|
| 91 |
+
|
| 92 |
+
All names are converted to lowercase.
|
| 93 |
+
"""
|
| 94 |
+
try:
|
| 95 |
+
handle = RegOpenKeyEx(base, key)
|
| 96 |
+
except RegError:
|
| 97 |
+
return None
|
| 98 |
+
d = {}
|
| 99 |
+
i = 0
|
| 100 |
+
while True:
|
| 101 |
+
try:
|
| 102 |
+
name, value, type = RegEnumValue(handle, i)
|
| 103 |
+
except RegError:
|
| 104 |
+
break
|
| 105 |
+
name = name.lower()
|
| 106 |
+
d[cls.convert_mbcs(name)] = cls.convert_mbcs(value)
|
| 107 |
+
i += 1
|
| 108 |
+
return d
|
| 109 |
+
read_values = classmethod(read_values)
|
| 110 |
+
|
| 111 |
+
def convert_mbcs(s):
|
| 112 |
+
dec = getattr(s, "decode", None)
|
| 113 |
+
if dec is not None:
|
| 114 |
+
try:
|
| 115 |
+
s = dec("mbcs")
|
| 116 |
+
except UnicodeError:
|
| 117 |
+
pass
|
| 118 |
+
return s
|
| 119 |
+
convert_mbcs = staticmethod(convert_mbcs)
|
| 120 |
+
|
| 121 |
+
class MacroExpander:
|
| 122 |
+
|
| 123 |
+
def __init__(self, version):
|
| 124 |
+
self.macros = {}
|
| 125 |
+
self.vsbase = VS_BASE % version
|
| 126 |
+
self.load_macros(version)
|
| 127 |
+
|
| 128 |
+
def set_macro(self, macro, path, key):
|
| 129 |
+
self.macros["$(%s)" % macro] = Reg.get_value(path, key)
|
| 130 |
+
|
| 131 |
+
def load_macros(self, version):
|
| 132 |
+
self.set_macro("VCInstallDir", self.vsbase + r"\Setup\VC", "productdir")
|
| 133 |
+
self.set_macro("VSInstallDir", self.vsbase + r"\Setup\VS", "productdir")
|
| 134 |
+
self.set_macro("FrameworkDir", NET_BASE, "installroot")
|
| 135 |
+
try:
|
| 136 |
+
if version >= 8.0:
|
| 137 |
+
self.set_macro("FrameworkSDKDir", NET_BASE,
|
| 138 |
+
"sdkinstallrootv2.0")
|
| 139 |
+
else:
|
| 140 |
+
raise KeyError("sdkinstallrootv2.0")
|
| 141 |
+
except KeyError:
|
| 142 |
+
raise DistutilsPlatformError(
|
| 143 |
+
"""Python was built with Visual Studio 2008;
|
| 144 |
+
extensions must be built with a compiler than can generate compatible binaries.
|
| 145 |
+
Visual Studio 2008 was not found on this system. If you have Cygwin installed,
|
| 146 |
+
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
|
| 147 |
+
|
| 148 |
+
if version >= 9.0:
|
| 149 |
+
self.set_macro("FrameworkVersion", self.vsbase, "clr version")
|
| 150 |
+
self.set_macro("WindowsSdkDir", WINSDK_BASE, "currentinstallfolder")
|
| 151 |
+
else:
|
| 152 |
+
p = r"Software\Microsoft\NET Framework Setup\Product"
|
| 153 |
+
for base in HKEYS:
|
| 154 |
+
try:
|
| 155 |
+
h = RegOpenKeyEx(base, p)
|
| 156 |
+
except RegError:
|
| 157 |
+
continue
|
| 158 |
+
key = RegEnumKey(h, 0)
|
| 159 |
+
d = Reg.get_value(base, r"%s\%s" % (p, key))
|
| 160 |
+
self.macros["$(FrameworkVersion)"] = d["version"]
|
| 161 |
+
|
| 162 |
+
def sub(self, s):
|
| 163 |
+
for k, v in self.macros.items():
|
| 164 |
+
s = s.replace(k, v)
|
| 165 |
+
return s
|
| 166 |
+
|
| 167 |
+
def get_build_version():
|
| 168 |
+
"""Return the version of MSVC that was used to build Python.
|
| 169 |
+
|
| 170 |
+
For Python 2.3 and up, the version number is included in
|
| 171 |
+
sys.version. For earlier versions, assume the compiler is MSVC 6.
|
| 172 |
+
"""
|
| 173 |
+
prefix = "MSC v."
|
| 174 |
+
i = sys.version.find(prefix)
|
| 175 |
+
if i == -1:
|
| 176 |
+
return 6
|
| 177 |
+
i = i + len(prefix)
|
| 178 |
+
s, rest = sys.version[i:].split(" ", 1)
|
| 179 |
+
majorVersion = int(s[:-2]) - 6
|
| 180 |
+
if majorVersion >= 13:
|
| 181 |
+
# v13 was skipped and should be v14
|
| 182 |
+
majorVersion += 1
|
| 183 |
+
minorVersion = int(s[2:3]) / 10.0
|
| 184 |
+
# I don't think paths are affected by minor version in version 6
|
| 185 |
+
if majorVersion == 6:
|
| 186 |
+
minorVersion = 0
|
| 187 |
+
if majorVersion >= 6:
|
| 188 |
+
return majorVersion + minorVersion
|
| 189 |
+
# else we don't know what version of the compiler this is
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
def normalize_and_reduce_paths(paths):
|
| 193 |
+
"""Return a list of normalized paths with duplicates removed.
|
| 194 |
+
|
| 195 |
+
The current order of paths is maintained.
|
| 196 |
+
"""
|
| 197 |
+
# Paths are normalized so things like: /a and /a/ aren't both preserved.
|
| 198 |
+
reduced_paths = []
|
| 199 |
+
for p in paths:
|
| 200 |
+
np = os.path.normpath(p)
|
| 201 |
+
# XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
|
| 202 |
+
if np not in reduced_paths:
|
| 203 |
+
reduced_paths.append(np)
|
| 204 |
+
return reduced_paths
|
| 205 |
+
|
| 206 |
+
def removeDuplicates(variable):
|
| 207 |
+
"""Remove duplicate values of an environment variable.
|
| 208 |
+
"""
|
| 209 |
+
oldList = variable.split(os.pathsep)
|
| 210 |
+
newList = []
|
| 211 |
+
for i in oldList:
|
| 212 |
+
if i not in newList:
|
| 213 |
+
newList.append(i)
|
| 214 |
+
newVariable = os.pathsep.join(newList)
|
| 215 |
+
return newVariable
|
| 216 |
+
|
| 217 |
+
def find_vcvarsall(version):
|
| 218 |
+
"""Find the vcvarsall.bat file
|
| 219 |
+
|
| 220 |
+
At first it tries to find the productdir of VS 2008 in the registry. If
|
| 221 |
+
that fails it falls back to the VS90COMNTOOLS env var.
|
| 222 |
+
"""
|
| 223 |
+
vsbase = VS_BASE % version
|
| 224 |
+
try:
|
| 225 |
+
productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
|
| 226 |
+
"productdir")
|
| 227 |
+
except KeyError:
|
| 228 |
+
log.debug("Unable to find productdir in registry")
|
| 229 |
+
productdir = None
|
| 230 |
+
|
| 231 |
+
if not productdir or not os.path.isdir(productdir):
|
| 232 |
+
toolskey = "VS%0.f0COMNTOOLS" % version
|
| 233 |
+
toolsdir = os.environ.get(toolskey, None)
|
| 234 |
+
|
| 235 |
+
if toolsdir and os.path.isdir(toolsdir):
|
| 236 |
+
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
|
| 237 |
+
productdir = os.path.abspath(productdir)
|
| 238 |
+
if not os.path.isdir(productdir):
|
| 239 |
+
log.debug("%s is not a valid directory" % productdir)
|
| 240 |
+
return None
|
| 241 |
+
else:
|
| 242 |
+
log.debug("Env var %s is not set or invalid" % toolskey)
|
| 243 |
+
if not productdir:
|
| 244 |
+
log.debug("No productdir found")
|
| 245 |
+
return None
|
| 246 |
+
vcvarsall = os.path.join(productdir, "vcvarsall.bat")
|
| 247 |
+
if os.path.isfile(vcvarsall):
|
| 248 |
+
return vcvarsall
|
| 249 |
+
log.debug("Unable to find vcvarsall.bat")
|
| 250 |
+
return None
|
| 251 |
+
|
| 252 |
+
def query_vcvarsall(version, arch="x86"):
|
| 253 |
+
"""Launch vcvarsall.bat and read the settings from its environment
|
| 254 |
+
"""
|
| 255 |
+
vcvarsall = find_vcvarsall(version)
|
| 256 |
+
interesting = {"include", "lib", "libpath", "path"}
|
| 257 |
+
result = {}
|
| 258 |
+
|
| 259 |
+
if vcvarsall is None:
|
| 260 |
+
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
|
| 261 |
+
log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
|
| 262 |
+
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
|
| 263 |
+
stdout=subprocess.PIPE,
|
| 264 |
+
stderr=subprocess.PIPE)
|
| 265 |
+
try:
|
| 266 |
+
stdout, stderr = popen.communicate()
|
| 267 |
+
if popen.wait() != 0:
|
| 268 |
+
raise DistutilsPlatformError(stderr.decode("mbcs"))
|
| 269 |
+
|
| 270 |
+
stdout = stdout.decode("mbcs")
|
| 271 |
+
for line in stdout.split("\n"):
|
| 272 |
+
line = Reg.convert_mbcs(line)
|
| 273 |
+
if '=' not in line:
|
| 274 |
+
continue
|
| 275 |
+
line = line.strip()
|
| 276 |
+
key, value = line.split('=', 1)
|
| 277 |
+
key = key.lower()
|
| 278 |
+
if key in interesting:
|
| 279 |
+
if value.endswith(os.pathsep):
|
| 280 |
+
value = value[:-1]
|
| 281 |
+
result[key] = removeDuplicates(value)
|
| 282 |
+
|
| 283 |
+
finally:
|
| 284 |
+
popen.stdout.close()
|
| 285 |
+
popen.stderr.close()
|
| 286 |
+
|
| 287 |
+
if len(result) != len(interesting):
|
| 288 |
+
raise ValueError(str(list(result.keys())))
|
| 289 |
+
|
| 290 |
+
return result
|
| 291 |
+
|
| 292 |
+
# More globals
|
| 293 |
+
VERSION = get_build_version()
|
| 294 |
+
if VERSION < 8.0:
|
| 295 |
+
raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
|
| 296 |
+
# MACROS = MacroExpander(VERSION)
|
| 297 |
+
|
| 298 |
+
class MSVCCompiler(CCompiler) :
|
| 299 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
| 300 |
+
as defined by the CCompiler abstract class."""
|
| 301 |
+
|
| 302 |
+
compiler_type = 'msvc'
|
| 303 |
+
|
| 304 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 305 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 306 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 307 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 308 |
+
# though, so it's worth thinking about.
|
| 309 |
+
executables = {}
|
| 310 |
+
|
| 311 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 312 |
+
_c_extensions = ['.c']
|
| 313 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 314 |
+
_rc_extensions = ['.rc']
|
| 315 |
+
_mc_extensions = ['.mc']
|
| 316 |
+
|
| 317 |
+
# Needed for the filename generation methods provided by the
|
| 318 |
+
# base class, CCompiler.
|
| 319 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
| 320 |
+
_rc_extensions + _mc_extensions)
|
| 321 |
+
res_extension = '.res'
|
| 322 |
+
obj_extension = '.obj'
|
| 323 |
+
static_lib_extension = '.lib'
|
| 324 |
+
shared_lib_extension = '.dll'
|
| 325 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 326 |
+
exe_extension = '.exe'
|
| 327 |
+
|
| 328 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 329 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
| 330 |
+
self.__version = VERSION
|
| 331 |
+
self.__root = r"Software\Microsoft\VisualStudio"
|
| 332 |
+
# self.__macros = MACROS
|
| 333 |
+
self.__paths = []
|
| 334 |
+
# target platform (.plat_name is consistent with 'bdist')
|
| 335 |
+
self.plat_name = None
|
| 336 |
+
self.__arch = None # deprecated name
|
| 337 |
+
self.initialized = False
|
| 338 |
+
|
| 339 |
+
def initialize(self, plat_name=None):
|
| 340 |
+
# multi-init means we would need to check platform same each time...
|
| 341 |
+
assert not self.initialized, "don't init multiple times"
|
| 342 |
+
if plat_name is None:
|
| 343 |
+
plat_name = get_platform()
|
| 344 |
+
# sanity check for platforms to prevent obscure errors later.
|
| 345 |
+
ok_plats = 'win32', 'win-amd64'
|
| 346 |
+
if plat_name not in ok_plats:
|
| 347 |
+
raise DistutilsPlatformError("--plat-name must be one of %s" %
|
| 348 |
+
(ok_plats,))
|
| 349 |
+
|
| 350 |
+
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
|
| 351 |
+
# Assume that the SDK set up everything alright; don't try to be
|
| 352 |
+
# smarter
|
| 353 |
+
self.cc = "cl.exe"
|
| 354 |
+
self.linker = "link.exe"
|
| 355 |
+
self.lib = "lib.exe"
|
| 356 |
+
self.rc = "rc.exe"
|
| 357 |
+
self.mc = "mc.exe"
|
| 358 |
+
else:
|
| 359 |
+
# On x86, 'vcvars32.bat amd64' creates an env that doesn't work;
|
| 360 |
+
# to cross compile, you use 'x86_amd64'.
|
| 361 |
+
# On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
|
| 362 |
+
# compile use 'x86' (ie, it runs the x86 compiler directly)
|
| 363 |
+
if plat_name == get_platform() or plat_name == 'win32':
|
| 364 |
+
# native build or cross-compile to win32
|
| 365 |
+
plat_spec = PLAT_TO_VCVARS[plat_name]
|
| 366 |
+
else:
|
| 367 |
+
# cross compile from win32 -> some 64bit
|
| 368 |
+
plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \
|
| 369 |
+
PLAT_TO_VCVARS[plat_name]
|
| 370 |
+
|
| 371 |
+
vc_env = query_vcvarsall(VERSION, plat_spec)
|
| 372 |
+
|
| 373 |
+
self.__paths = vc_env['path'].split(os.pathsep)
|
| 374 |
+
os.environ['lib'] = vc_env['lib']
|
| 375 |
+
os.environ['include'] = vc_env['include']
|
| 376 |
+
|
| 377 |
+
if len(self.__paths) == 0:
|
| 378 |
+
raise DistutilsPlatformError("Python was built with %s, "
|
| 379 |
+
"and extensions need to be built with the same "
|
| 380 |
+
"version of the compiler, but it isn't installed."
|
| 381 |
+
% self.__product)
|
| 382 |
+
|
| 383 |
+
self.cc = self.find_exe("cl.exe")
|
| 384 |
+
self.linker = self.find_exe("link.exe")
|
| 385 |
+
self.lib = self.find_exe("lib.exe")
|
| 386 |
+
self.rc = self.find_exe("rc.exe") # resource compiler
|
| 387 |
+
self.mc = self.find_exe("mc.exe") # message compiler
|
| 388 |
+
#self.set_path_env_var('lib')
|
| 389 |
+
#self.set_path_env_var('include')
|
| 390 |
+
|
| 391 |
+
# extend the MSVC path with the current path
|
| 392 |
+
try:
|
| 393 |
+
for p in os.environ['path'].split(';'):
|
| 394 |
+
self.__paths.append(p)
|
| 395 |
+
except KeyError:
|
| 396 |
+
pass
|
| 397 |
+
self.__paths = normalize_and_reduce_paths(self.__paths)
|
| 398 |
+
os.environ['path'] = ";".join(self.__paths)
|
| 399 |
+
|
| 400 |
+
self.preprocess_options = None
|
| 401 |
+
if self.__arch == "x86":
|
| 402 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3',
|
| 403 |
+
'/DNDEBUG']
|
| 404 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3',
|
| 405 |
+
'/Z7', '/D_DEBUG']
|
| 406 |
+
else:
|
| 407 |
+
# Win64
|
| 408 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
|
| 409 |
+
'/DNDEBUG']
|
| 410 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
| 411 |
+
'/Z7', '/D_DEBUG']
|
| 412 |
+
|
| 413 |
+
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
| 414 |
+
if self.__version >= 7:
|
| 415 |
+
self.ldflags_shared_debug = [
|
| 416 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
|
| 417 |
+
]
|
| 418 |
+
self.ldflags_static = [ '/nologo']
|
| 419 |
+
|
| 420 |
+
self.initialized = True
|
| 421 |
+
|
| 422 |
+
# -- Worker methods ------------------------------------------------
|
| 423 |
+
|
| 424 |
+
def object_filenames(self,
|
| 425 |
+
source_filenames,
|
| 426 |
+
strip_dir=0,
|
| 427 |
+
output_dir=''):
|
| 428 |
+
# Copied from ccompiler.py, extended to return .res as 'object'-file
|
| 429 |
+
# for .rc input file
|
| 430 |
+
if output_dir is None: output_dir = ''
|
| 431 |
+
obj_names = []
|
| 432 |
+
for src_name in source_filenames:
|
| 433 |
+
(base, ext) = os.path.splitext (src_name)
|
| 434 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
| 435 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
| 436 |
+
if ext not in self.src_extensions:
|
| 437 |
+
# Better to raise an exception instead of silently continuing
|
| 438 |
+
# and later complain about sources and targets having
|
| 439 |
+
# different lengths
|
| 440 |
+
raise CompileError ("Don't know how to compile %s" % src_name)
|
| 441 |
+
if strip_dir:
|
| 442 |
+
base = os.path.basename (base)
|
| 443 |
+
if ext in self._rc_extensions:
|
| 444 |
+
obj_names.append (os.path.join (output_dir,
|
| 445 |
+
base + self.res_extension))
|
| 446 |
+
elif ext in self._mc_extensions:
|
| 447 |
+
obj_names.append (os.path.join (output_dir,
|
| 448 |
+
base + self.res_extension))
|
| 449 |
+
else:
|
| 450 |
+
obj_names.append (os.path.join (output_dir,
|
| 451 |
+
base + self.obj_extension))
|
| 452 |
+
return obj_names
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
def compile(self, sources,
|
| 456 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
| 457 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
| 458 |
+
|
| 459 |
+
if not self.initialized:
|
| 460 |
+
self.initialize()
|
| 461 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
| 462 |
+
sources, depends, extra_postargs)
|
| 463 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
| 464 |
+
|
| 465 |
+
compile_opts = extra_preargs or []
|
| 466 |
+
compile_opts.append ('/c')
|
| 467 |
+
if debug:
|
| 468 |
+
compile_opts.extend(self.compile_options_debug)
|
| 469 |
+
else:
|
| 470 |
+
compile_opts.extend(self.compile_options)
|
| 471 |
+
|
| 472 |
+
for obj in objects:
|
| 473 |
+
try:
|
| 474 |
+
src, ext = build[obj]
|
| 475 |
+
except KeyError:
|
| 476 |
+
continue
|
| 477 |
+
if debug:
|
| 478 |
+
# pass the full pathname to MSVC in debug mode,
|
| 479 |
+
# this allows the debugger to find the source file
|
| 480 |
+
# without asking the user to browse for it
|
| 481 |
+
src = os.path.abspath(src)
|
| 482 |
+
|
| 483 |
+
if ext in self._c_extensions:
|
| 484 |
+
input_opt = "/Tc" + src
|
| 485 |
+
elif ext in self._cpp_extensions:
|
| 486 |
+
input_opt = "/Tp" + src
|
| 487 |
+
elif ext in self._rc_extensions:
|
| 488 |
+
# compile .RC to .RES file
|
| 489 |
+
input_opt = src
|
| 490 |
+
output_opt = "/fo" + obj
|
| 491 |
+
try:
|
| 492 |
+
self.spawn([self.rc] + pp_opts +
|
| 493 |
+
[output_opt] + [input_opt])
|
| 494 |
+
except DistutilsExecError as msg:
|
| 495 |
+
raise CompileError(msg)
|
| 496 |
+
continue
|
| 497 |
+
elif ext in self._mc_extensions:
|
| 498 |
+
# Compile .MC to .RC file to .RES file.
|
| 499 |
+
# * '-h dir' specifies the directory for the
|
| 500 |
+
# generated include file
|
| 501 |
+
# * '-r dir' specifies the target directory of the
|
| 502 |
+
# generated RC file and the binary message resource
|
| 503 |
+
# it includes
|
| 504 |
+
#
|
| 505 |
+
# For now (since there are no options to change this),
|
| 506 |
+
# we use the source-directory for the include file and
|
| 507 |
+
# the build directory for the RC file and message
|
| 508 |
+
# resources. This works at least for win32all.
|
| 509 |
+
h_dir = os.path.dirname(src)
|
| 510 |
+
rc_dir = os.path.dirname(obj)
|
| 511 |
+
try:
|
| 512 |
+
# first compile .MC to .RC and .H file
|
| 513 |
+
self.spawn([self.mc] +
|
| 514 |
+
['-h', h_dir, '-r', rc_dir] + [src])
|
| 515 |
+
base, _ = os.path.splitext (os.path.basename (src))
|
| 516 |
+
rc_file = os.path.join (rc_dir, base + '.rc')
|
| 517 |
+
# then compile .RC to .RES file
|
| 518 |
+
self.spawn([self.rc] +
|
| 519 |
+
["/fo" + obj] + [rc_file])
|
| 520 |
+
|
| 521 |
+
except DistutilsExecError as msg:
|
| 522 |
+
raise CompileError(msg)
|
| 523 |
+
continue
|
| 524 |
+
else:
|
| 525 |
+
# how to handle this file?
|
| 526 |
+
raise CompileError("Don't know how to compile %s to %s"
|
| 527 |
+
% (src, obj))
|
| 528 |
+
|
| 529 |
+
output_opt = "/Fo" + obj
|
| 530 |
+
try:
|
| 531 |
+
self.spawn([self.cc] + compile_opts + pp_opts +
|
| 532 |
+
[input_opt, output_opt] +
|
| 533 |
+
extra_postargs)
|
| 534 |
+
except DistutilsExecError as msg:
|
| 535 |
+
raise CompileError(msg)
|
| 536 |
+
|
| 537 |
+
return objects
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
def create_static_lib(self,
|
| 541 |
+
objects,
|
| 542 |
+
output_libname,
|
| 543 |
+
output_dir=None,
|
| 544 |
+
debug=0,
|
| 545 |
+
target_lang=None):
|
| 546 |
+
|
| 547 |
+
if not self.initialized:
|
| 548 |
+
self.initialize()
|
| 549 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 550 |
+
output_filename = self.library_filename(output_libname,
|
| 551 |
+
output_dir=output_dir)
|
| 552 |
+
|
| 553 |
+
if self._need_link(objects, output_filename):
|
| 554 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
| 555 |
+
if debug:
|
| 556 |
+
pass # XXX what goes here?
|
| 557 |
+
try:
|
| 558 |
+
self.spawn([self.lib] + lib_args)
|
| 559 |
+
except DistutilsExecError as msg:
|
| 560 |
+
raise LibError(msg)
|
| 561 |
+
else:
|
| 562 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def link(self,
|
| 566 |
+
target_desc,
|
| 567 |
+
objects,
|
| 568 |
+
output_filename,
|
| 569 |
+
output_dir=None,
|
| 570 |
+
libraries=None,
|
| 571 |
+
library_dirs=None,
|
| 572 |
+
runtime_library_dirs=None,
|
| 573 |
+
export_symbols=None,
|
| 574 |
+
debug=0,
|
| 575 |
+
extra_preargs=None,
|
| 576 |
+
extra_postargs=None,
|
| 577 |
+
build_temp=None,
|
| 578 |
+
target_lang=None):
|
| 579 |
+
|
| 580 |
+
if not self.initialized:
|
| 581 |
+
self.initialize()
|
| 582 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 583 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
| 584 |
+
runtime_library_dirs)
|
| 585 |
+
(libraries, library_dirs, runtime_library_dirs) = fixed_args
|
| 586 |
+
|
| 587 |
+
if runtime_library_dirs:
|
| 588 |
+
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
| 589 |
+
+ str (runtime_library_dirs))
|
| 590 |
+
|
| 591 |
+
lib_opts = gen_lib_options(self,
|
| 592 |
+
library_dirs, runtime_library_dirs,
|
| 593 |
+
libraries)
|
| 594 |
+
if output_dir is not None:
|
| 595 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 596 |
+
|
| 597 |
+
if self._need_link(objects, output_filename):
|
| 598 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 599 |
+
if debug:
|
| 600 |
+
ldflags = self.ldflags_shared_debug[1:]
|
| 601 |
+
else:
|
| 602 |
+
ldflags = self.ldflags_shared[1:]
|
| 603 |
+
else:
|
| 604 |
+
if debug:
|
| 605 |
+
ldflags = self.ldflags_shared_debug
|
| 606 |
+
else:
|
| 607 |
+
ldflags = self.ldflags_shared
|
| 608 |
+
|
| 609 |
+
export_opts = []
|
| 610 |
+
for sym in (export_symbols or []):
|
| 611 |
+
export_opts.append("/EXPORT:" + sym)
|
| 612 |
+
|
| 613 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
| 614 |
+
objects + ['/OUT:' + output_filename])
|
| 615 |
+
|
| 616 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
| 617 |
+
# suppressed by any linker switches. The .lib files may even be
|
| 618 |
+
# needed! Make sure they are generated in the temporary build
|
| 619 |
+
# directory. Since they have different names for debug and release
|
| 620 |
+
# builds, they can go into the same directory.
|
| 621 |
+
build_temp = os.path.dirname(objects[0])
|
| 622 |
+
if export_symbols is not None:
|
| 623 |
+
(dll_name, dll_ext) = os.path.splitext(
|
| 624 |
+
os.path.basename(output_filename))
|
| 625 |
+
implib_file = os.path.join(
|
| 626 |
+
build_temp,
|
| 627 |
+
self.library_filename(dll_name))
|
| 628 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
| 629 |
+
|
| 630 |
+
self.manifest_setup_ldargs(output_filename, build_temp, ld_args)
|
| 631 |
+
|
| 632 |
+
if extra_preargs:
|
| 633 |
+
ld_args[:0] = extra_preargs
|
| 634 |
+
if extra_postargs:
|
| 635 |
+
ld_args.extend(extra_postargs)
|
| 636 |
+
|
| 637 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 638 |
+
try:
|
| 639 |
+
self.spawn([self.linker] + ld_args)
|
| 640 |
+
except DistutilsExecError as msg:
|
| 641 |
+
raise LinkError(msg)
|
| 642 |
+
|
| 643 |
+
# embed the manifest
|
| 644 |
+
# XXX - this is somewhat fragile - if mt.exe fails, distutils
|
| 645 |
+
# will still consider the DLL up-to-date, but it will not have a
|
| 646 |
+
# manifest. Maybe we should link to a temp file? OTOH, that
|
| 647 |
+
# implies a build environment error that shouldn't go undetected.
|
| 648 |
+
mfinfo = self.manifest_get_embed_info(target_desc, ld_args)
|
| 649 |
+
if mfinfo is not None:
|
| 650 |
+
mffilename, mfid = mfinfo
|
| 651 |
+
out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
|
| 652 |
+
try:
|
| 653 |
+
self.spawn(['mt.exe', '-nologo', '-manifest',
|
| 654 |
+
mffilename, out_arg])
|
| 655 |
+
except DistutilsExecError as msg:
|
| 656 |
+
raise LinkError(msg)
|
| 657 |
+
else:
|
| 658 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 659 |
+
|
| 660 |
+
def manifest_setup_ldargs(self, output_filename, build_temp, ld_args):
|
| 661 |
+
# If we need a manifest at all, an embedded manifest is recommended.
|
| 662 |
+
# See MSDN article titled
|
| 663 |
+
# "How to: Embed a Manifest Inside a C/C++ Application"
|
| 664 |
+
# (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
|
| 665 |
+
# Ask the linker to generate the manifest in the temp dir, so
|
| 666 |
+
# we can check it, and possibly embed it, later.
|
| 667 |
+
temp_manifest = os.path.join(
|
| 668 |
+
build_temp,
|
| 669 |
+
os.path.basename(output_filename) + ".manifest")
|
| 670 |
+
ld_args.append('/MANIFESTFILE:' + temp_manifest)
|
| 671 |
+
|
| 672 |
+
def manifest_get_embed_info(self, target_desc, ld_args):
|
| 673 |
+
# If a manifest should be embedded, return a tuple of
|
| 674 |
+
# (manifest_filename, resource_id). Returns None if no manifest
|
| 675 |
+
# should be embedded. See http://bugs.python.org/issue7833 for why
|
| 676 |
+
# we want to avoid any manifest for extension modules if we can.
|
| 677 |
+
for arg in ld_args:
|
| 678 |
+
if arg.startswith("/MANIFESTFILE:"):
|
| 679 |
+
temp_manifest = arg.split(":", 1)[1]
|
| 680 |
+
break
|
| 681 |
+
else:
|
| 682 |
+
# no /MANIFESTFILE so nothing to do.
|
| 683 |
+
return None
|
| 684 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 685 |
+
# by default, executables always get the manifest with the
|
| 686 |
+
# CRT referenced.
|
| 687 |
+
mfid = 1
|
| 688 |
+
else:
|
| 689 |
+
# Extension modules try and avoid any manifest if possible.
|
| 690 |
+
mfid = 2
|
| 691 |
+
temp_manifest = self._remove_visual_c_ref(temp_manifest)
|
| 692 |
+
if temp_manifest is None:
|
| 693 |
+
return None
|
| 694 |
+
return temp_manifest, mfid
|
| 695 |
+
|
| 696 |
+
def _remove_visual_c_ref(self, manifest_file):
|
| 697 |
+
try:
|
| 698 |
+
# Remove references to the Visual C runtime, so they will
|
| 699 |
+
# fall through to the Visual C dependency of Python.exe.
|
| 700 |
+
# This way, when installed for a restricted user (e.g.
|
| 701 |
+
# runtimes are not in WinSxS folder, but in Python's own
|
| 702 |
+
# folder), the runtimes do not need to be in every folder
|
| 703 |
+
# with .pyd's.
|
| 704 |
+
# Returns either the filename of the modified manifest or
|
| 705 |
+
# None if no manifest should be embedded.
|
| 706 |
+
manifest_f = open(manifest_file)
|
| 707 |
+
try:
|
| 708 |
+
manifest_buf = manifest_f.read()
|
| 709 |
+
finally:
|
| 710 |
+
manifest_f.close()
|
| 711 |
+
pattern = re.compile(
|
| 712 |
+
r"""<assemblyIdentity.*?name=("|')Microsoft\."""\
|
| 713 |
+
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
|
| 714 |
+
re.DOTALL)
|
| 715 |
+
manifest_buf = re.sub(pattern, "", manifest_buf)
|
| 716 |
+
pattern = r"<dependentAssembly>\s*</dependentAssembly>"
|
| 717 |
+
manifest_buf = re.sub(pattern, "", manifest_buf)
|
| 718 |
+
# Now see if any other assemblies are referenced - if not, we
|
| 719 |
+
# don't want a manifest embedded.
|
| 720 |
+
pattern = re.compile(
|
| 721 |
+
r"""<assemblyIdentity.*?name=(?:"|')(.+?)(?:"|')"""
|
| 722 |
+
r""".*?(?:/>|</assemblyIdentity>)""", re.DOTALL)
|
| 723 |
+
if re.search(pattern, manifest_buf) is None:
|
| 724 |
+
return None
|
| 725 |
+
|
| 726 |
+
manifest_f = open(manifest_file, 'w')
|
| 727 |
+
try:
|
| 728 |
+
manifest_f.write(manifest_buf)
|
| 729 |
+
return manifest_file
|
| 730 |
+
finally:
|
| 731 |
+
manifest_f.close()
|
| 732 |
+
except OSError:
|
| 733 |
+
pass
|
| 734 |
+
|
| 735 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 736 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 737 |
+
# ccompiler.py.
|
| 738 |
+
|
| 739 |
+
def library_dir_option(self, dir):
|
| 740 |
+
return "/LIBPATH:" + dir
|
| 741 |
+
|
| 742 |
+
def runtime_library_dir_option(self, dir):
|
| 743 |
+
raise DistutilsPlatformError(
|
| 744 |
+
"don't know how to set runtime library search path for MSVC++")
|
| 745 |
+
|
| 746 |
+
def library_option(self, lib):
|
| 747 |
+
return self.library_filename(lib)
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
def find_library_file(self, dirs, lib, debug=0):
|
| 751 |
+
# Prefer a debugging library if found (and requested), but deal
|
| 752 |
+
# with it if we don't have one.
|
| 753 |
+
if debug:
|
| 754 |
+
try_names = [lib + "_d", lib]
|
| 755 |
+
else:
|
| 756 |
+
try_names = [lib]
|
| 757 |
+
for dir in dirs:
|
| 758 |
+
for name in try_names:
|
| 759 |
+
libfile = os.path.join(dir, self.library_filename (name))
|
| 760 |
+
if os.path.exists(libfile):
|
| 761 |
+
return libfile
|
| 762 |
+
else:
|
| 763 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 764 |
+
return None
|
| 765 |
+
|
| 766 |
+
# Helper methods for using the MSVC registry settings
|
| 767 |
+
|
| 768 |
+
def find_exe(self, exe):
|
| 769 |
+
"""Return path to an MSVC executable program.
|
| 770 |
+
|
| 771 |
+
Tries to find the program in several places: first, one of the
|
| 772 |
+
MSVC program search paths from the registry; next, the directories
|
| 773 |
+
in the PATH environment variable. If any of those work, return an
|
| 774 |
+
absolute path that is known to exist. If none of them work, just
|
| 775 |
+
return the original program name, 'exe'.
|
| 776 |
+
"""
|
| 777 |
+
for p in self.__paths:
|
| 778 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
| 779 |
+
if os.path.isfile(fn):
|
| 780 |
+
return fn
|
| 781 |
+
|
| 782 |
+
# didn't find it; try existing path
|
| 783 |
+
for p in os.environ['Path'].split(';'):
|
| 784 |
+
fn = os.path.join(os.path.abspath(p),exe)
|
| 785 |
+
if os.path.isfile(fn):
|
| 786 |
+
return fn
|
| 787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Robin Becker and Thomas Heller to do a better job of
|
| 9 |
+
# finding DevStudio (through the registry)
|
| 10 |
+
|
| 11 |
+
import sys, os
|
| 12 |
+
from distutils.errors import \
|
| 13 |
+
DistutilsExecError, DistutilsPlatformError, \
|
| 14 |
+
CompileError, LibError, LinkError
|
| 15 |
+
from distutils.ccompiler import \
|
| 16 |
+
CCompiler, gen_lib_options
|
| 17 |
+
from distutils import log
|
| 18 |
+
|
| 19 |
+
_can_read_reg = False
|
| 20 |
+
try:
|
| 21 |
+
import winreg
|
| 22 |
+
|
| 23 |
+
_can_read_reg = True
|
| 24 |
+
hkey_mod = winreg
|
| 25 |
+
|
| 26 |
+
RegOpenKeyEx = winreg.OpenKeyEx
|
| 27 |
+
RegEnumKey = winreg.EnumKey
|
| 28 |
+
RegEnumValue = winreg.EnumValue
|
| 29 |
+
RegError = winreg.error
|
| 30 |
+
|
| 31 |
+
except ImportError:
|
| 32 |
+
try:
|
| 33 |
+
import win32api
|
| 34 |
+
import win32con
|
| 35 |
+
_can_read_reg = True
|
| 36 |
+
hkey_mod = win32con
|
| 37 |
+
|
| 38 |
+
RegOpenKeyEx = win32api.RegOpenKeyEx
|
| 39 |
+
RegEnumKey = win32api.RegEnumKey
|
| 40 |
+
RegEnumValue = win32api.RegEnumValue
|
| 41 |
+
RegError = win32api.error
|
| 42 |
+
except ImportError:
|
| 43 |
+
log.info("Warning: Can't read registry to find the "
|
| 44 |
+
"necessary compiler setting\n"
|
| 45 |
+
"Make sure that Python modules winreg, "
|
| 46 |
+
"win32api or win32con are installed.")
|
| 47 |
+
|
| 48 |
+
if _can_read_reg:
|
| 49 |
+
HKEYS = (hkey_mod.HKEY_USERS,
|
| 50 |
+
hkey_mod.HKEY_CURRENT_USER,
|
| 51 |
+
hkey_mod.HKEY_LOCAL_MACHINE,
|
| 52 |
+
hkey_mod.HKEY_CLASSES_ROOT)
|
| 53 |
+
|
| 54 |
+
def read_keys(base, key):
|
| 55 |
+
"""Return list of registry keys."""
|
| 56 |
+
try:
|
| 57 |
+
handle = RegOpenKeyEx(base, key)
|
| 58 |
+
except RegError:
|
| 59 |
+
return None
|
| 60 |
+
L = []
|
| 61 |
+
i = 0
|
| 62 |
+
while True:
|
| 63 |
+
try:
|
| 64 |
+
k = RegEnumKey(handle, i)
|
| 65 |
+
except RegError:
|
| 66 |
+
break
|
| 67 |
+
L.append(k)
|
| 68 |
+
i += 1
|
| 69 |
+
return L
|
| 70 |
+
|
| 71 |
+
def read_values(base, key):
|
| 72 |
+
"""Return dict of registry keys and values.
|
| 73 |
+
|
| 74 |
+
All names are converted to lowercase.
|
| 75 |
+
"""
|
| 76 |
+
try:
|
| 77 |
+
handle = RegOpenKeyEx(base, key)
|
| 78 |
+
except RegError:
|
| 79 |
+
return None
|
| 80 |
+
d = {}
|
| 81 |
+
i = 0
|
| 82 |
+
while True:
|
| 83 |
+
try:
|
| 84 |
+
name, value, type = RegEnumValue(handle, i)
|
| 85 |
+
except RegError:
|
| 86 |
+
break
|
| 87 |
+
name = name.lower()
|
| 88 |
+
d[convert_mbcs(name)] = convert_mbcs(value)
|
| 89 |
+
i += 1
|
| 90 |
+
return d
|
| 91 |
+
|
| 92 |
+
def convert_mbcs(s):
|
| 93 |
+
dec = getattr(s, "decode", None)
|
| 94 |
+
if dec is not None:
|
| 95 |
+
try:
|
| 96 |
+
s = dec("mbcs")
|
| 97 |
+
except UnicodeError:
|
| 98 |
+
pass
|
| 99 |
+
return s
|
| 100 |
+
|
| 101 |
+
class MacroExpander:
|
| 102 |
+
def __init__(self, version):
|
| 103 |
+
self.macros = {}
|
| 104 |
+
self.load_macros(version)
|
| 105 |
+
|
| 106 |
+
def set_macro(self, macro, path, key):
|
| 107 |
+
for base in HKEYS:
|
| 108 |
+
d = read_values(base, path)
|
| 109 |
+
if d:
|
| 110 |
+
self.macros["$(%s)" % macro] = d[key]
|
| 111 |
+
break
|
| 112 |
+
|
| 113 |
+
def load_macros(self, version):
|
| 114 |
+
vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version
|
| 115 |
+
self.set_macro("VCInstallDir", vsbase + r"\Setup\VC", "productdir")
|
| 116 |
+
self.set_macro("VSInstallDir", vsbase + r"\Setup\VS", "productdir")
|
| 117 |
+
net = r"Software\Microsoft\.NETFramework"
|
| 118 |
+
self.set_macro("FrameworkDir", net, "installroot")
|
| 119 |
+
try:
|
| 120 |
+
if version > 7.0:
|
| 121 |
+
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
|
| 122 |
+
else:
|
| 123 |
+
self.set_macro("FrameworkSDKDir", net, "sdkinstallroot")
|
| 124 |
+
except KeyError as exc: #
|
| 125 |
+
raise DistutilsPlatformError(
|
| 126 |
+
"""Python was built with Visual Studio 2003;
|
| 127 |
+
extensions must be built with a compiler than can generate compatible binaries.
|
| 128 |
+
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
|
| 129 |
+
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
|
| 130 |
+
|
| 131 |
+
p = r"Software\Microsoft\NET Framework Setup\Product"
|
| 132 |
+
for base in HKEYS:
|
| 133 |
+
try:
|
| 134 |
+
h = RegOpenKeyEx(base, p)
|
| 135 |
+
except RegError:
|
| 136 |
+
continue
|
| 137 |
+
key = RegEnumKey(h, 0)
|
| 138 |
+
d = read_values(base, r"%s\%s" % (p, key))
|
| 139 |
+
self.macros["$(FrameworkVersion)"] = d["version"]
|
| 140 |
+
|
| 141 |
+
def sub(self, s):
|
| 142 |
+
for k, v in self.macros.items():
|
| 143 |
+
s = s.replace(k, v)
|
| 144 |
+
return s
|
| 145 |
+
|
| 146 |
+
def get_build_version():
|
| 147 |
+
"""Return the version of MSVC that was used to build Python.
|
| 148 |
+
|
| 149 |
+
For Python 2.3 and up, the version number is included in
|
| 150 |
+
sys.version. For earlier versions, assume the compiler is MSVC 6.
|
| 151 |
+
"""
|
| 152 |
+
prefix = "MSC v."
|
| 153 |
+
i = sys.version.find(prefix)
|
| 154 |
+
if i == -1:
|
| 155 |
+
return 6
|
| 156 |
+
i = i + len(prefix)
|
| 157 |
+
s, rest = sys.version[i:].split(" ", 1)
|
| 158 |
+
majorVersion = int(s[:-2]) - 6
|
| 159 |
+
if majorVersion >= 13:
|
| 160 |
+
# v13 was skipped and should be v14
|
| 161 |
+
majorVersion += 1
|
| 162 |
+
minorVersion = int(s[2:3]) / 10.0
|
| 163 |
+
# I don't think paths are affected by minor version in version 6
|
| 164 |
+
if majorVersion == 6:
|
| 165 |
+
minorVersion = 0
|
| 166 |
+
if majorVersion >= 6:
|
| 167 |
+
return majorVersion + minorVersion
|
| 168 |
+
# else we don't know what version of the compiler this is
|
| 169 |
+
return None
|
| 170 |
+
|
| 171 |
+
def get_build_architecture():
|
| 172 |
+
"""Return the processor architecture.
|
| 173 |
+
|
| 174 |
+
Possible results are "Intel" or "AMD64".
|
| 175 |
+
"""
|
| 176 |
+
|
| 177 |
+
prefix = " bit ("
|
| 178 |
+
i = sys.version.find(prefix)
|
| 179 |
+
if i == -1:
|
| 180 |
+
return "Intel"
|
| 181 |
+
j = sys.version.find(")", i)
|
| 182 |
+
return sys.version[i+len(prefix):j]
|
| 183 |
+
|
| 184 |
+
def normalize_and_reduce_paths(paths):
|
| 185 |
+
"""Return a list of normalized paths with duplicates removed.
|
| 186 |
+
|
| 187 |
+
The current order of paths is maintained.
|
| 188 |
+
"""
|
| 189 |
+
# Paths are normalized so things like: /a and /a/ aren't both preserved.
|
| 190 |
+
reduced_paths = []
|
| 191 |
+
for p in paths:
|
| 192 |
+
np = os.path.normpath(p)
|
| 193 |
+
# XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
|
| 194 |
+
if np not in reduced_paths:
|
| 195 |
+
reduced_paths.append(np)
|
| 196 |
+
return reduced_paths
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
class MSVCCompiler(CCompiler) :
|
| 200 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
| 201 |
+
as defined by the CCompiler abstract class."""
|
| 202 |
+
|
| 203 |
+
compiler_type = 'msvc'
|
| 204 |
+
|
| 205 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 206 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 207 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 208 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 209 |
+
# though, so it's worth thinking about.
|
| 210 |
+
executables = {}
|
| 211 |
+
|
| 212 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 213 |
+
_c_extensions = ['.c']
|
| 214 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 215 |
+
_rc_extensions = ['.rc']
|
| 216 |
+
_mc_extensions = ['.mc']
|
| 217 |
+
|
| 218 |
+
# Needed for the filename generation methods provided by the
|
| 219 |
+
# base class, CCompiler.
|
| 220 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
| 221 |
+
_rc_extensions + _mc_extensions)
|
| 222 |
+
res_extension = '.res'
|
| 223 |
+
obj_extension = '.obj'
|
| 224 |
+
static_lib_extension = '.lib'
|
| 225 |
+
shared_lib_extension = '.dll'
|
| 226 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 227 |
+
exe_extension = '.exe'
|
| 228 |
+
|
| 229 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 230 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
| 231 |
+
self.__version = get_build_version()
|
| 232 |
+
self.__arch = get_build_architecture()
|
| 233 |
+
if self.__arch == "Intel":
|
| 234 |
+
# x86
|
| 235 |
+
if self.__version >= 7:
|
| 236 |
+
self.__root = r"Software\Microsoft\VisualStudio"
|
| 237 |
+
self.__macros = MacroExpander(self.__version)
|
| 238 |
+
else:
|
| 239 |
+
self.__root = r"Software\Microsoft\Devstudio"
|
| 240 |
+
self.__product = "Visual Studio version %s" % self.__version
|
| 241 |
+
else:
|
| 242 |
+
# Win64. Assume this was built with the platform SDK
|
| 243 |
+
self.__product = "Microsoft SDK compiler %s" % (self.__version + 6)
|
| 244 |
+
|
| 245 |
+
self.initialized = False
|
| 246 |
+
|
| 247 |
+
def initialize(self):
|
| 248 |
+
self.__paths = []
|
| 249 |
+
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
|
| 250 |
+
# Assume that the SDK set up everything alright; don't try to be
|
| 251 |
+
# smarter
|
| 252 |
+
self.cc = "cl.exe"
|
| 253 |
+
self.linker = "link.exe"
|
| 254 |
+
self.lib = "lib.exe"
|
| 255 |
+
self.rc = "rc.exe"
|
| 256 |
+
self.mc = "mc.exe"
|
| 257 |
+
else:
|
| 258 |
+
self.__paths = self.get_msvc_paths("path")
|
| 259 |
+
|
| 260 |
+
if len(self.__paths) == 0:
|
| 261 |
+
raise DistutilsPlatformError("Python was built with %s, "
|
| 262 |
+
"and extensions need to be built with the same "
|
| 263 |
+
"version of the compiler, but it isn't installed."
|
| 264 |
+
% self.__product)
|
| 265 |
+
|
| 266 |
+
self.cc = self.find_exe("cl.exe")
|
| 267 |
+
self.linker = self.find_exe("link.exe")
|
| 268 |
+
self.lib = self.find_exe("lib.exe")
|
| 269 |
+
self.rc = self.find_exe("rc.exe") # resource compiler
|
| 270 |
+
self.mc = self.find_exe("mc.exe") # message compiler
|
| 271 |
+
self.set_path_env_var('lib')
|
| 272 |
+
self.set_path_env_var('include')
|
| 273 |
+
|
| 274 |
+
# extend the MSVC path with the current path
|
| 275 |
+
try:
|
| 276 |
+
for p in os.environ['path'].split(';'):
|
| 277 |
+
self.__paths.append(p)
|
| 278 |
+
except KeyError:
|
| 279 |
+
pass
|
| 280 |
+
self.__paths = normalize_and_reduce_paths(self.__paths)
|
| 281 |
+
os.environ['path'] = ";".join(self.__paths)
|
| 282 |
+
|
| 283 |
+
self.preprocess_options = None
|
| 284 |
+
if self.__arch == "Intel":
|
| 285 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GX' ,
|
| 286 |
+
'/DNDEBUG']
|
| 287 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GX',
|
| 288 |
+
'/Z7', '/D_DEBUG']
|
| 289 |
+
else:
|
| 290 |
+
# Win64
|
| 291 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
|
| 292 |
+
'/DNDEBUG']
|
| 293 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
| 294 |
+
'/Z7', '/D_DEBUG']
|
| 295 |
+
|
| 296 |
+
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
| 297 |
+
if self.__version >= 7:
|
| 298 |
+
self.ldflags_shared_debug = [
|
| 299 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
|
| 300 |
+
]
|
| 301 |
+
else:
|
| 302 |
+
self.ldflags_shared_debug = [
|
| 303 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG'
|
| 304 |
+
]
|
| 305 |
+
self.ldflags_static = [ '/nologo']
|
| 306 |
+
|
| 307 |
+
self.initialized = True
|
| 308 |
+
|
| 309 |
+
# -- Worker methods ------------------------------------------------
|
| 310 |
+
|
| 311 |
+
def object_filenames(self,
|
| 312 |
+
source_filenames,
|
| 313 |
+
strip_dir=0,
|
| 314 |
+
output_dir=''):
|
| 315 |
+
# Copied from ccompiler.py, extended to return .res as 'object'-file
|
| 316 |
+
# for .rc input file
|
| 317 |
+
if output_dir is None: output_dir = ''
|
| 318 |
+
obj_names = []
|
| 319 |
+
for src_name in source_filenames:
|
| 320 |
+
(base, ext) = os.path.splitext (src_name)
|
| 321 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
| 322 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
| 323 |
+
if ext not in self.src_extensions:
|
| 324 |
+
# Better to raise an exception instead of silently continuing
|
| 325 |
+
# and later complain about sources and targets having
|
| 326 |
+
# different lengths
|
| 327 |
+
raise CompileError ("Don't know how to compile %s" % src_name)
|
| 328 |
+
if strip_dir:
|
| 329 |
+
base = os.path.basename (base)
|
| 330 |
+
if ext in self._rc_extensions:
|
| 331 |
+
obj_names.append (os.path.join (output_dir,
|
| 332 |
+
base + self.res_extension))
|
| 333 |
+
elif ext in self._mc_extensions:
|
| 334 |
+
obj_names.append (os.path.join (output_dir,
|
| 335 |
+
base + self.res_extension))
|
| 336 |
+
else:
|
| 337 |
+
obj_names.append (os.path.join (output_dir,
|
| 338 |
+
base + self.obj_extension))
|
| 339 |
+
return obj_names
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def compile(self, sources,
|
| 343 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
| 344 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
| 345 |
+
|
| 346 |
+
if not self.initialized:
|
| 347 |
+
self.initialize()
|
| 348 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
| 349 |
+
sources, depends, extra_postargs)
|
| 350 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
| 351 |
+
|
| 352 |
+
compile_opts = extra_preargs or []
|
| 353 |
+
compile_opts.append ('/c')
|
| 354 |
+
if debug:
|
| 355 |
+
compile_opts.extend(self.compile_options_debug)
|
| 356 |
+
else:
|
| 357 |
+
compile_opts.extend(self.compile_options)
|
| 358 |
+
|
| 359 |
+
for obj in objects:
|
| 360 |
+
try:
|
| 361 |
+
src, ext = build[obj]
|
| 362 |
+
except KeyError:
|
| 363 |
+
continue
|
| 364 |
+
if debug:
|
| 365 |
+
# pass the full pathname to MSVC in debug mode,
|
| 366 |
+
# this allows the debugger to find the source file
|
| 367 |
+
# without asking the user to browse for it
|
| 368 |
+
src = os.path.abspath(src)
|
| 369 |
+
|
| 370 |
+
if ext in self._c_extensions:
|
| 371 |
+
input_opt = "/Tc" + src
|
| 372 |
+
elif ext in self._cpp_extensions:
|
| 373 |
+
input_opt = "/Tp" + src
|
| 374 |
+
elif ext in self._rc_extensions:
|
| 375 |
+
# compile .RC to .RES file
|
| 376 |
+
input_opt = src
|
| 377 |
+
output_opt = "/fo" + obj
|
| 378 |
+
try:
|
| 379 |
+
self.spawn([self.rc] + pp_opts +
|
| 380 |
+
[output_opt] + [input_opt])
|
| 381 |
+
except DistutilsExecError as msg:
|
| 382 |
+
raise CompileError(msg)
|
| 383 |
+
continue
|
| 384 |
+
elif ext in self._mc_extensions:
|
| 385 |
+
# Compile .MC to .RC file to .RES file.
|
| 386 |
+
# * '-h dir' specifies the directory for the
|
| 387 |
+
# generated include file
|
| 388 |
+
# * '-r dir' specifies the target directory of the
|
| 389 |
+
# generated RC file and the binary message resource
|
| 390 |
+
# it includes
|
| 391 |
+
#
|
| 392 |
+
# For now (since there are no options to change this),
|
| 393 |
+
# we use the source-directory for the include file and
|
| 394 |
+
# the build directory for the RC file and message
|
| 395 |
+
# resources. This works at least for win32all.
|
| 396 |
+
h_dir = os.path.dirname(src)
|
| 397 |
+
rc_dir = os.path.dirname(obj)
|
| 398 |
+
try:
|
| 399 |
+
# first compile .MC to .RC and .H file
|
| 400 |
+
self.spawn([self.mc] +
|
| 401 |
+
['-h', h_dir, '-r', rc_dir] + [src])
|
| 402 |
+
base, _ = os.path.splitext (os.path.basename (src))
|
| 403 |
+
rc_file = os.path.join (rc_dir, base + '.rc')
|
| 404 |
+
# then compile .RC to .RES file
|
| 405 |
+
self.spawn([self.rc] +
|
| 406 |
+
["/fo" + obj] + [rc_file])
|
| 407 |
+
|
| 408 |
+
except DistutilsExecError as msg:
|
| 409 |
+
raise CompileError(msg)
|
| 410 |
+
continue
|
| 411 |
+
else:
|
| 412 |
+
# how to handle this file?
|
| 413 |
+
raise CompileError("Don't know how to compile %s to %s"
|
| 414 |
+
% (src, obj))
|
| 415 |
+
|
| 416 |
+
output_opt = "/Fo" + obj
|
| 417 |
+
try:
|
| 418 |
+
self.spawn([self.cc] + compile_opts + pp_opts +
|
| 419 |
+
[input_opt, output_opt] +
|
| 420 |
+
extra_postargs)
|
| 421 |
+
except DistutilsExecError as msg:
|
| 422 |
+
raise CompileError(msg)
|
| 423 |
+
|
| 424 |
+
return objects
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
def create_static_lib(self,
|
| 428 |
+
objects,
|
| 429 |
+
output_libname,
|
| 430 |
+
output_dir=None,
|
| 431 |
+
debug=0,
|
| 432 |
+
target_lang=None):
|
| 433 |
+
|
| 434 |
+
if not self.initialized:
|
| 435 |
+
self.initialize()
|
| 436 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 437 |
+
output_filename = self.library_filename(output_libname,
|
| 438 |
+
output_dir=output_dir)
|
| 439 |
+
|
| 440 |
+
if self._need_link(objects, output_filename):
|
| 441 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
| 442 |
+
if debug:
|
| 443 |
+
pass # XXX what goes here?
|
| 444 |
+
try:
|
| 445 |
+
self.spawn([self.lib] + lib_args)
|
| 446 |
+
except DistutilsExecError as msg:
|
| 447 |
+
raise LibError(msg)
|
| 448 |
+
else:
|
| 449 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def link(self,
|
| 453 |
+
target_desc,
|
| 454 |
+
objects,
|
| 455 |
+
output_filename,
|
| 456 |
+
output_dir=None,
|
| 457 |
+
libraries=None,
|
| 458 |
+
library_dirs=None,
|
| 459 |
+
runtime_library_dirs=None,
|
| 460 |
+
export_symbols=None,
|
| 461 |
+
debug=0,
|
| 462 |
+
extra_preargs=None,
|
| 463 |
+
extra_postargs=None,
|
| 464 |
+
build_temp=None,
|
| 465 |
+
target_lang=None):
|
| 466 |
+
|
| 467 |
+
if not self.initialized:
|
| 468 |
+
self.initialize()
|
| 469 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 470 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
| 471 |
+
runtime_library_dirs)
|
| 472 |
+
(libraries, library_dirs, runtime_library_dirs) = fixed_args
|
| 473 |
+
|
| 474 |
+
if runtime_library_dirs:
|
| 475 |
+
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
| 476 |
+
+ str (runtime_library_dirs))
|
| 477 |
+
|
| 478 |
+
lib_opts = gen_lib_options(self,
|
| 479 |
+
library_dirs, runtime_library_dirs,
|
| 480 |
+
libraries)
|
| 481 |
+
if output_dir is not None:
|
| 482 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 483 |
+
|
| 484 |
+
if self._need_link(objects, output_filename):
|
| 485 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 486 |
+
if debug:
|
| 487 |
+
ldflags = self.ldflags_shared_debug[1:]
|
| 488 |
+
else:
|
| 489 |
+
ldflags = self.ldflags_shared[1:]
|
| 490 |
+
else:
|
| 491 |
+
if debug:
|
| 492 |
+
ldflags = self.ldflags_shared_debug
|
| 493 |
+
else:
|
| 494 |
+
ldflags = self.ldflags_shared
|
| 495 |
+
|
| 496 |
+
export_opts = []
|
| 497 |
+
for sym in (export_symbols or []):
|
| 498 |
+
export_opts.append("/EXPORT:" + sym)
|
| 499 |
+
|
| 500 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
| 501 |
+
objects + ['/OUT:' + output_filename])
|
| 502 |
+
|
| 503 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
| 504 |
+
# suppressed by any linker switches. The .lib files may even be
|
| 505 |
+
# needed! Make sure they are generated in the temporary build
|
| 506 |
+
# directory. Since they have different names for debug and release
|
| 507 |
+
# builds, they can go into the same directory.
|
| 508 |
+
if export_symbols is not None:
|
| 509 |
+
(dll_name, dll_ext) = os.path.splitext(
|
| 510 |
+
os.path.basename(output_filename))
|
| 511 |
+
implib_file = os.path.join(
|
| 512 |
+
os.path.dirname(objects[0]),
|
| 513 |
+
self.library_filename(dll_name))
|
| 514 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
| 515 |
+
|
| 516 |
+
if extra_preargs:
|
| 517 |
+
ld_args[:0] = extra_preargs
|
| 518 |
+
if extra_postargs:
|
| 519 |
+
ld_args.extend(extra_postargs)
|
| 520 |
+
|
| 521 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 522 |
+
try:
|
| 523 |
+
self.spawn([self.linker] + ld_args)
|
| 524 |
+
except DistutilsExecError as msg:
|
| 525 |
+
raise LinkError(msg)
|
| 526 |
+
|
| 527 |
+
else:
|
| 528 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 532 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 533 |
+
# ccompiler.py.
|
| 534 |
+
|
| 535 |
+
def library_dir_option(self, dir):
|
| 536 |
+
return "/LIBPATH:" + dir
|
| 537 |
+
|
| 538 |
+
def runtime_library_dir_option(self, dir):
|
| 539 |
+
raise DistutilsPlatformError(
|
| 540 |
+
"don't know how to set runtime library search path for MSVC++")
|
| 541 |
+
|
| 542 |
+
def library_option(self, lib):
|
| 543 |
+
return self.library_filename(lib)
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
def find_library_file(self, dirs, lib, debug=0):
|
| 547 |
+
# Prefer a debugging library if found (and requested), but deal
|
| 548 |
+
# with it if we don't have one.
|
| 549 |
+
if debug:
|
| 550 |
+
try_names = [lib + "_d", lib]
|
| 551 |
+
else:
|
| 552 |
+
try_names = [lib]
|
| 553 |
+
for dir in dirs:
|
| 554 |
+
for name in try_names:
|
| 555 |
+
libfile = os.path.join(dir, self.library_filename (name))
|
| 556 |
+
if os.path.exists(libfile):
|
| 557 |
+
return libfile
|
| 558 |
+
else:
|
| 559 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 560 |
+
return None
|
| 561 |
+
|
| 562 |
+
# Helper methods for using the MSVC registry settings
|
| 563 |
+
|
| 564 |
+
def find_exe(self, exe):
|
| 565 |
+
"""Return path to an MSVC executable program.
|
| 566 |
+
|
| 567 |
+
Tries to find the program in several places: first, one of the
|
| 568 |
+
MSVC program search paths from the registry; next, the directories
|
| 569 |
+
in the PATH environment variable. If any of those work, return an
|
| 570 |
+
absolute path that is known to exist. If none of them work, just
|
| 571 |
+
return the original program name, 'exe'.
|
| 572 |
+
"""
|
| 573 |
+
for p in self.__paths:
|
| 574 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
| 575 |
+
if os.path.isfile(fn):
|
| 576 |
+
return fn
|
| 577 |
+
|
| 578 |
+
# didn't find it; try existing path
|
| 579 |
+
for p in os.environ['Path'].split(';'):
|
| 580 |
+
fn = os.path.join(os.path.abspath(p),exe)
|
| 581 |
+
if os.path.isfile(fn):
|
| 582 |
+
return fn
|
| 583 |
+
|
| 584 |
+
return exe
|
| 585 |
+
|
| 586 |
+
def get_msvc_paths(self, path, platform='x86'):
|
| 587 |
+
"""Get a list of devstudio directories (include, lib or path).
|
| 588 |
+
|
| 589 |
+
Return a list of strings. The list will be empty if unable to
|
| 590 |
+
access the registry or appropriate registry keys not found.
|
| 591 |
+
"""
|
| 592 |
+
if not _can_read_reg:
|
| 593 |
+
return []
|
| 594 |
+
|
| 595 |
+
path = path + " dirs"
|
| 596 |
+
if self.__version >= 7:
|
| 597 |
+
key = (r"%s\%0.1f\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directories"
|
| 598 |
+
% (self.__root, self.__version))
|
| 599 |
+
else:
|
| 600 |
+
key = (r"%s\6.0\Build System\Components\Platforms"
|
| 601 |
+
r"\Win32 (%s)\Directories" % (self.__root, platform))
|
| 602 |
+
|
| 603 |
+
for base in HKEYS:
|
| 604 |
+
d = read_values(base, key)
|
| 605 |
+
if d:
|
| 606 |
+
if self.__version >= 7:
|
| 607 |
+
return self.__macros.sub(d[path]).split(";")
|
| 608 |
+
else:
|
| 609 |
+
return d[path].split(";")
|
| 610 |
+
# MSVC 6 seems to create the registry entries we need only when
|
| 611 |
+
# the GUI is run.
|
| 612 |
+
if self.__version == 6:
|
| 613 |
+
for base in HKEYS:
|
| 614 |
+
if read_values(base, r"%s\6.0" % self.__root) is not None:
|
| 615 |
+
self.warn("It seems you have Visual Studio 6 installed, "
|
| 616 |
+
"but the expected registry settings are not present.\n"
|
| 617 |
+
"You must at least run the Visual Studio GUI once "
|
| 618 |
+
"so that these entries are created.")
|
| 619 |
+
break
|
| 620 |
+
return []
|
| 621 |
+
|
| 622 |
+
def set_path_env_var(self, name):
|
| 623 |
+
"""Set environment variable 'name' to an MSVC path type value.
|
| 624 |
+
|
| 625 |
+
This is equivalent to a SET command prior to execution of spawned
|
| 626 |
+
commands.
|
| 627 |
+
"""
|
| 628 |
+
|
| 629 |
+
if name == "lib":
|
| 630 |
+
p = self.get_msvc_paths("library")
|
| 631 |
+
else:
|
| 632 |
+
p = self.get_msvc_paths(name)
|
| 633 |
+
if p:
|
| 634 |
+
os.environ[name] = ';'.join(p)
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
if get_build_version() >= 8.0:
|
| 638 |
+
log.debug("Importing new compiler from distutils.msvc9compiler")
|
| 639 |
+
OldMSVCCompiler = MSVCCompiler
|
| 640 |
+
from distutils.msvc9compiler import MSVCCompiler
|
| 641 |
+
# get_build_architecture not really relevant now we support cross-compile
|
| 642 |
+
from distutils.msvc9compiler import MacroExpander
|
physworld_p1_20261018/envs/p1/lib/python3.11/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
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/sysconfig.py
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Provide access to Python's configuration information. The specific
|
| 2 |
+
configuration variables available depend heavily on the platform and
|
| 3 |
+
configuration. The values may be retrieved using
|
| 4 |
+
get_config_var(name), and the list of variables is available via
|
| 5 |
+
get_config_vars().keys(). Additional convenience functions are also
|
| 6 |
+
available.
|
| 7 |
+
|
| 8 |
+
Written by: Fred L. Drake, Jr.
|
| 9 |
+
Email: <fdrake@acm.org>
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import _imp
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import sys
|
| 16 |
+
import warnings
|
| 17 |
+
|
| 18 |
+
from functools import partial
|
| 19 |
+
|
| 20 |
+
from .errors import DistutilsPlatformError
|
| 21 |
+
|
| 22 |
+
from sysconfig import (
|
| 23 |
+
_PREFIX as PREFIX,
|
| 24 |
+
_BASE_PREFIX as BASE_PREFIX,
|
| 25 |
+
_EXEC_PREFIX as EXEC_PREFIX,
|
| 26 |
+
_BASE_EXEC_PREFIX as BASE_EXEC_PREFIX,
|
| 27 |
+
_PROJECT_BASE as project_base,
|
| 28 |
+
_PYTHON_BUILD as python_build,
|
| 29 |
+
_init_posix as sysconfig_init_posix,
|
| 30 |
+
parse_config_h as sysconfig_parse_config_h,
|
| 31 |
+
|
| 32 |
+
_init_non_posix,
|
| 33 |
+
|
| 34 |
+
_variable_rx,
|
| 35 |
+
_findvar1_rx,
|
| 36 |
+
_findvar2_rx,
|
| 37 |
+
|
| 38 |
+
expand_makefile_vars,
|
| 39 |
+
is_python_build,
|
| 40 |
+
get_config_h_filename,
|
| 41 |
+
get_config_var,
|
| 42 |
+
get_config_vars,
|
| 43 |
+
get_makefile_filename,
|
| 44 |
+
get_python_version,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# This is better than
|
| 48 |
+
# from sysconfig import _CONFIG_VARS as _config_vars
|
| 49 |
+
# because it makes sure that the global dictionary is initialized
|
| 50 |
+
# which might not be true in the time of import.
|
| 51 |
+
_config_vars = get_config_vars()
|
| 52 |
+
|
| 53 |
+
warnings.warn(
|
| 54 |
+
'The distutils.sysconfig module is deprecated, use sysconfig instead',
|
| 55 |
+
DeprecationWarning,
|
| 56 |
+
stacklevel=2
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# Following functions are the same as in sysconfig but with different API
|
| 61 |
+
def parse_config_h(fp, g=None):
|
| 62 |
+
return sysconfig_parse_config_h(fp, vars=g)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
_python_build = partial(is_python_build, check_home=True)
|
| 66 |
+
_init_posix = partial(sysconfig_init_posix, _config_vars)
|
| 67 |
+
_init_nt = partial(_init_non_posix, _config_vars)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Similar function is also implemented in sysconfig as _parse_makefile
|
| 71 |
+
# but without the parsing capabilities of distutils.text_file.TextFile.
|
| 72 |
+
def parse_makefile(fn, g=None):
|
| 73 |
+
"""Parse a Makefile-style file.
|
| 74 |
+
A dictionary containing name/value pairs is returned. If an
|
| 75 |
+
optional dictionary is passed in as the second argument, it is
|
| 76 |
+
used instead of a new dictionary.
|
| 77 |
+
"""
|
| 78 |
+
from distutils.text_file import TextFile
|
| 79 |
+
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
|
| 80 |
+
|
| 81 |
+
if g is None:
|
| 82 |
+
g = {}
|
| 83 |
+
done = {}
|
| 84 |
+
notdone = {}
|
| 85 |
+
|
| 86 |
+
while True:
|
| 87 |
+
line = fp.readline()
|
| 88 |
+
if line is None: # eof
|
| 89 |
+
break
|
| 90 |
+
m = re.match(_variable_rx, line)
|
| 91 |
+
if m:
|
| 92 |
+
n, v = m.group(1, 2)
|
| 93 |
+
v = v.strip()
|
| 94 |
+
# `$$' is a literal `$' in make
|
| 95 |
+
tmpv = v.replace('$$', '')
|
| 96 |
+
|
| 97 |
+
if "$" in tmpv:
|
| 98 |
+
notdone[n] = v
|
| 99 |
+
else:
|
| 100 |
+
try:
|
| 101 |
+
v = int(v)
|
| 102 |
+
except ValueError:
|
| 103 |
+
# insert literal `$'
|
| 104 |
+
done[n] = v.replace('$$', '$')
|
| 105 |
+
else:
|
| 106 |
+
done[n] = v
|
| 107 |
+
|
| 108 |
+
# Variables with a 'PY_' prefix in the makefile. These need to
|
| 109 |
+
# be made available without that prefix through sysconfig.
|
| 110 |
+
# Special care is needed to ensure that variable expansion works, even
|
| 111 |
+
# if the expansion uses the name without a prefix.
|
| 112 |
+
renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
|
| 113 |
+
|
| 114 |
+
# do variable interpolation here
|
| 115 |
+
while notdone:
|
| 116 |
+
for name in list(notdone):
|
| 117 |
+
value = notdone[name]
|
| 118 |
+
m = re.search(_findvar1_rx, value) or re.search(_findvar2_rx, value)
|
| 119 |
+
if m:
|
| 120 |
+
n = m.group(1)
|
| 121 |
+
found = True
|
| 122 |
+
if n in done:
|
| 123 |
+
item = str(done[n])
|
| 124 |
+
elif n in notdone:
|
| 125 |
+
# get it on a subsequent round
|
| 126 |
+
found = False
|
| 127 |
+
elif n in os.environ:
|
| 128 |
+
# do it like make: fall back to environment
|
| 129 |
+
item = os.environ[n]
|
| 130 |
+
|
| 131 |
+
elif n in renamed_variables:
|
| 132 |
+
if name.startswith('PY_') and name[3:] in renamed_variables:
|
| 133 |
+
item = ""
|
| 134 |
+
|
| 135 |
+
elif 'PY_' + n in notdone:
|
| 136 |
+
found = False
|
| 137 |
+
|
| 138 |
+
else:
|
| 139 |
+
item = str(done['PY_' + n])
|
| 140 |
+
else:
|
| 141 |
+
done[n] = item = ""
|
| 142 |
+
if found:
|
| 143 |
+
after = value[m.end():]
|
| 144 |
+
value = value[:m.start()] + item + after
|
| 145 |
+
if "$" in after:
|
| 146 |
+
notdone[name] = value
|
| 147 |
+
else:
|
| 148 |
+
try: value = int(value)
|
| 149 |
+
except ValueError:
|
| 150 |
+
done[name] = value.strip()
|
| 151 |
+
else:
|
| 152 |
+
done[name] = value
|
| 153 |
+
del notdone[name]
|
| 154 |
+
|
| 155 |
+
if name.startswith('PY_') \
|
| 156 |
+
and name[3:] in renamed_variables:
|
| 157 |
+
|
| 158 |
+
name = name[3:]
|
| 159 |
+
if name not in done:
|
| 160 |
+
done[name] = value
|
| 161 |
+
else:
|
| 162 |
+
# bogus variable reference; just drop it since we can't deal
|
| 163 |
+
del notdone[name]
|
| 164 |
+
|
| 165 |
+
fp.close()
|
| 166 |
+
|
| 167 |
+
# strip spurious spaces
|
| 168 |
+
for k, v in done.items():
|
| 169 |
+
if isinstance(v, str):
|
| 170 |
+
done[k] = v.strip()
|
| 171 |
+
|
| 172 |
+
# save the results in the global dictionary
|
| 173 |
+
g.update(done)
|
| 174 |
+
return g
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
# Following functions are deprecated together with this module and they
|
| 178 |
+
# have no direct replacement
|
| 179 |
+
|
| 180 |
+
# Calculate the build qualifier flags if they are defined. Adding the flags
|
| 181 |
+
# to the include and lib directories only makes sense for an installation, not
|
| 182 |
+
# an in-source build.
|
| 183 |
+
build_flags = ''
|
| 184 |
+
try:
|
| 185 |
+
if not python_build:
|
| 186 |
+
build_flags = sys.abiflags
|
| 187 |
+
except AttributeError:
|
| 188 |
+
# It's not a configure-based build, so the sys module doesn't have
|
| 189 |
+
# this attribute, which is fine.
|
| 190 |
+
pass
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def customize_compiler(compiler):
|
| 194 |
+
"""Do any platform-specific customization of a CCompiler instance.
|
| 195 |
+
|
| 196 |
+
Mainly needed on Unix, so we can plug in the information that
|
| 197 |
+
varies across Unices and is stored in Python's Makefile.
|
| 198 |
+
"""
|
| 199 |
+
if compiler.compiler_type == "unix":
|
| 200 |
+
if sys.platform == "darwin":
|
| 201 |
+
# Perform first-time customization of compiler-related
|
| 202 |
+
# config vars on OS X now that we know we need a compiler.
|
| 203 |
+
# This is primarily to support Pythons from binary
|
| 204 |
+
# installers. The kind and paths to build tools on
|
| 205 |
+
# the user system may vary significantly from the system
|
| 206 |
+
# that Python itself was built on. Also the user OS
|
| 207 |
+
# version and build tools may not support the same set
|
| 208 |
+
# of CPU architectures for universal builds.
|
| 209 |
+
if not _config_vars.get('CUSTOMIZED_OSX_COMPILER'):
|
| 210 |
+
import _osx_support
|
| 211 |
+
_osx_support.customize_compiler(_config_vars)
|
| 212 |
+
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
|
| 213 |
+
|
| 214 |
+
(cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
|
| 215 |
+
get_config_vars('CC', 'CXX', 'CFLAGS',
|
| 216 |
+
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
|
| 217 |
+
|
| 218 |
+
if 'CC' in os.environ:
|
| 219 |
+
newcc = os.environ['CC']
|
| 220 |
+
if ('LDSHARED' not in os.environ
|
| 221 |
+
and ldshared.startswith(cc)):
|
| 222 |
+
# If CC is overridden, use that as the default
|
| 223 |
+
# command for LDSHARED as well
|
| 224 |
+
ldshared = newcc + ldshared[len(cc):]
|
| 225 |
+
cc = newcc
|
| 226 |
+
if 'CXX' in os.environ:
|
| 227 |
+
cxx = os.environ['CXX']
|
| 228 |
+
if 'LDSHARED' in os.environ:
|
| 229 |
+
ldshared = os.environ['LDSHARED']
|
| 230 |
+
if 'CPP' in os.environ:
|
| 231 |
+
cpp = os.environ['CPP']
|
| 232 |
+
else:
|
| 233 |
+
cpp = cc + " -E" # not always
|
| 234 |
+
if 'LDFLAGS' in os.environ:
|
| 235 |
+
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
|
| 236 |
+
if 'CFLAGS' in os.environ:
|
| 237 |
+
cflags = cflags + ' ' + os.environ['CFLAGS']
|
| 238 |
+
ldshared = ldshared + ' ' + os.environ['CFLAGS']
|
| 239 |
+
if 'CPPFLAGS' in os.environ:
|
| 240 |
+
cpp = cpp + ' ' + os.environ['CPPFLAGS']
|
| 241 |
+
cflags = cflags + ' ' + os.environ['CPPFLAGS']
|
| 242 |
+
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
|
| 243 |
+
if 'AR' in os.environ:
|
| 244 |
+
ar = os.environ['AR']
|
| 245 |
+
if 'ARFLAGS' in os.environ:
|
| 246 |
+
archiver = ar + ' ' + os.environ['ARFLAGS']
|
| 247 |
+
else:
|
| 248 |
+
archiver = ar + ' ' + ar_flags
|
| 249 |
+
|
| 250 |
+
cc_cmd = cc + ' ' + cflags
|
| 251 |
+
compiler.set_executables(
|
| 252 |
+
preprocessor=cpp,
|
| 253 |
+
compiler=cc_cmd,
|
| 254 |
+
compiler_so=cc_cmd + ' ' + ccshared,
|
| 255 |
+
compiler_cxx=cxx,
|
| 256 |
+
linker_so=ldshared,
|
| 257 |
+
linker_exe=cc,
|
| 258 |
+
archiver=archiver)
|
| 259 |
+
|
| 260 |
+
if 'RANLIB' in os.environ and 'ranlib' in compiler.executables:
|
| 261 |
+
compiler.set_executables(ranlib=os.environ['RANLIB'])
|
| 262 |
+
|
| 263 |
+
compiler.shared_lib_extension = shlib_suffix
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def get_python_inc(plat_specific=0, prefix=None):
|
| 267 |
+
"""Return the directory containing installed Python header files.
|
| 268 |
+
|
| 269 |
+
If 'plat_specific' is false (the default), this is the path to the
|
| 270 |
+
non-platform-specific header files, i.e. Python.h and so on;
|
| 271 |
+
otherwise, this is the path to platform-specific header files
|
| 272 |
+
(namely pyconfig.h).
|
| 273 |
+
|
| 274 |
+
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
| 275 |
+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
| 276 |
+
"""
|
| 277 |
+
if prefix is None:
|
| 278 |
+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
| 279 |
+
if os.name == "posix":
|
| 280 |
+
if python_build:
|
| 281 |
+
# Assume the executable is in the build directory. The
|
| 282 |
+
# pyconfig.h file should be in the same directory. Since
|
| 283 |
+
# the build directory may not be the source directory, we
|
| 284 |
+
# must use "srcdir" from the makefile to find the "Include"
|
| 285 |
+
# directory.
|
| 286 |
+
if plat_specific:
|
| 287 |
+
return project_base
|
| 288 |
+
else:
|
| 289 |
+
incdir = os.path.join(get_config_var('srcdir'), 'Include')
|
| 290 |
+
return os.path.normpath(incdir)
|
| 291 |
+
python_dir = 'python' + get_python_version() + build_flags
|
| 292 |
+
return os.path.join(prefix, "include", python_dir)
|
| 293 |
+
elif os.name == "nt":
|
| 294 |
+
if python_build:
|
| 295 |
+
# Include both the include and PC dir to ensure we can find
|
| 296 |
+
# pyconfig.h
|
| 297 |
+
return (os.path.join(prefix, "include") + os.path.pathsep +
|
| 298 |
+
os.path.join(prefix, "PC"))
|
| 299 |
+
return os.path.join(prefix, "include")
|
| 300 |
+
else:
|
| 301 |
+
raise DistutilsPlatformError(
|
| 302 |
+
"I don't know where Python installs its C header files "
|
| 303 |
+
"on platform '%s'" % os.name)
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
| 307 |
+
"""Return the directory containing the Python library (standard or
|
| 308 |
+
site additions).
|
| 309 |
+
|
| 310 |
+
If 'plat_specific' is true, return the directory containing
|
| 311 |
+
platform-specific modules, i.e. any module from a non-pure-Python
|
| 312 |
+
module distribution; otherwise, return the platform-shared library
|
| 313 |
+
directory. If 'standard_lib' is true, return the directory
|
| 314 |
+
containing standard Python library modules; otherwise, return the
|
| 315 |
+
directory for site-specific modules.
|
| 316 |
+
|
| 317 |
+
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
| 318 |
+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
| 319 |
+
"""
|
| 320 |
+
if prefix is None:
|
| 321 |
+
if standard_lib:
|
| 322 |
+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
| 323 |
+
else:
|
| 324 |
+
prefix = plat_specific and EXEC_PREFIX or PREFIX
|
| 325 |
+
|
| 326 |
+
if os.name == "posix":
|
| 327 |
+
if plat_specific or standard_lib:
|
| 328 |
+
# Platform-specific modules (any module from a non-pure-Python
|
| 329 |
+
# module distribution) or standard Python library modules.
|
| 330 |
+
libdir = sys.platlibdir
|
| 331 |
+
else:
|
| 332 |
+
# Pure Python
|
| 333 |
+
libdir = "lib"
|
| 334 |
+
libpython = os.path.join(prefix, libdir,
|
| 335 |
+
"python" + get_python_version())
|
| 336 |
+
if standard_lib:
|
| 337 |
+
return libpython
|
| 338 |
+
else:
|
| 339 |
+
return os.path.join(libpython, "site-packages")
|
| 340 |
+
elif os.name == "nt":
|
| 341 |
+
if standard_lib:
|
| 342 |
+
return os.path.join(prefix, "Lib")
|
| 343 |
+
else:
|
| 344 |
+
return os.path.join(prefix, "Lib", "site-packages")
|
| 345 |
+
else:
|
| 346 |
+
raise DistutilsPlatformError(
|
| 347 |
+
"I don't know where Python installs its library "
|
| 348 |
+
"on platform '%s'" % os.name)
|
physworld_p1_20261018/envs/p1/lib/python3.11/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 |
+
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test suite for distutils.
|
| 2 |
+
|
| 3 |
+
This test suite consists of a collection of test modules in the
|
| 4 |
+
distutils.tests package.
|
| 5 |
+
|
| 6 |
+
Tests for the command classes in the distutils.command package are
|
| 7 |
+
included in distutils.tests as well, instead of using a separate
|
| 8 |
+
distutils.command.tests package, since command identification is done
|
| 9 |
+
by import rather than matching pre-defined names.
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import os
|
| 14 |
+
import unittest
|
| 15 |
+
from test.support.warnings_helper import save_restore_warnings_filters
|
| 16 |
+
from test.support import warnings_helper
|
| 17 |
+
from test.support import load_package_tests
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def load_tests(*args):
|
| 21 |
+
# bpo-40055: Save/restore warnings filters to leave them unchanged.
|
| 22 |
+
# Importing tests imports docutils which imports pkg_resources
|
| 23 |
+
# which adds a warnings filter.
|
| 24 |
+
with (save_restore_warnings_filters(),
|
| 25 |
+
warnings_helper.check_warnings(
|
| 26 |
+
("The distutils.sysconfig module is deprecated", DeprecationWarning),
|
| 27 |
+
quiet=True)):
|
| 28 |
+
return load_package_tests(os.path.dirname(__file__), *args)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
unittest.main()
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (2.15 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/support.cpython-311.pyc
ADDED
|
Binary file (12.3 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_archive_util.cpython-311.pyc
ADDED
|
Binary file (27.2 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_bdist.cpython-311.pyc
ADDED
|
Binary file (2.95 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_bdist_dumb.cpython-311.pyc
ADDED
|
Binary file (5.46 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_bdist_rpm.cpython-311.pyc
ADDED
|
Binary file (7.88 kB). View file
|
|
|
physworld_p1_20261018/envs/p1/lib/python3.11/distutils/tests/__pycache__/test_build.cpython-311.pyc
ADDED
|
Binary file (3.47 kB). View file
|
|
|