mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 12:06:53 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,8 +1,11 @@
|
|||
from distutils.command.bdist import bdist
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from distutils.command.bdist import bdist
|
||||
|
||||
if 'egg' not in bdist.format_commands:
|
||||
bdist.format_command['egg'] = ('bdist_egg', "Python .egg file")
|
||||
bdist.format_command['egg'] = ('bdist_egg', 'Python .egg file')
|
||||
bdist.format_commands.append('egg')
|
||||
|
||||
del bdist, sys
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
from distutils.errors import DistutilsOptionError
|
||||
from __future__ import annotations
|
||||
|
||||
from setuptools.command.setopt import edit_config, option_base, config_file
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from setuptools.command.setopt import config_file
|
||||
from setuptools.command.setopt import edit_config
|
||||
from setuptools.command.setopt import option_base
|
||||
|
||||
|
||||
def shquote(arg):
|
||||
"""Quote an argument for later parsing by shlex.split()"""
|
||||
for c in '"', "'", "\\", "#":
|
||||
for c in '"', "'", '\\', '#':
|
||||
if c in arg:
|
||||
return repr(arg)
|
||||
if arg.split() != [arg]:
|
||||
|
|
@ -16,7 +19,7 @@ def shquote(arg):
|
|||
class alias(option_base):
|
||||
"""Define a shortcut that invokes one or more commands"""
|
||||
|
||||
description = "define a shortcut to invoke one or more commands"
|
||||
description = 'define a shortcut to invoke one or more commands'
|
||||
command_consumes_arguments = True
|
||||
|
||||
user_options = [
|
||||
|
|
@ -34,18 +37,18 @@ class alias(option_base):
|
|||
option_base.finalize_options(self)
|
||||
if self.remove and len(self.args) != 1:
|
||||
raise DistutilsOptionError(
|
||||
"Must specify exactly one argument (the alias name) when "
|
||||
"using --remove"
|
||||
'Must specify exactly one argument (the alias name) when '
|
||||
'using --remove',
|
||||
)
|
||||
|
||||
def run(self):
|
||||
aliases = self.distribution.get_option_dict('aliases')
|
||||
|
||||
if not self.args:
|
||||
print("Command Aliases")
|
||||
print("---------------")
|
||||
print('Command Aliases')
|
||||
print('---------------')
|
||||
for alias in aliases:
|
||||
print("setup.py alias", format_alias(alias, aliases))
|
||||
print('setup.py alias', format_alias(alias, aliases))
|
||||
return
|
||||
|
||||
elif len(self.args) == 1:
|
||||
|
|
@ -53,10 +56,10 @@ class alias(option_base):
|
|||
if self.remove:
|
||||
command = None
|
||||
elif alias in aliases:
|
||||
print("setup.py alias", format_alias(alias, aliases))
|
||||
print('setup.py alias', format_alias(alias, aliases))
|
||||
return
|
||||
else:
|
||||
print("No alias definition found for %r" % alias)
|
||||
print('No alias definition found for %r' % alias)
|
||||
return
|
||||
else:
|
||||
alias = self.args[0]
|
||||
|
|
|
|||
|
|
@ -1,25 +1,29 @@
|
|||
"""setuptools.command.bdist_egg
|
||||
|
||||
Build .egg distributions"""
|
||||
from __future__ import annotations
|
||||
|
||||
from distutils.dir_util import remove_tree, mkpath
|
||||
from distutils import log
|
||||
from types import CodeType
|
||||
import sys
|
||||
import marshal
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
import marshal
|
||||
from sysconfig import get_path
|
||||
from sysconfig import get_python_version
|
||||
from types import CodeType
|
||||
|
||||
from pkg_resources import get_build_platform, Distribution, ensure_directory
|
||||
from setuptools.extension import Library
|
||||
from distutils import log
|
||||
from distutils.dir_util import mkpath
|
||||
from distutils.dir_util import remove_tree
|
||||
from pkg_resources import Distribution
|
||||
from pkg_resources import ensure_directory
|
||||
from pkg_resources import get_build_platform
|
||||
from setuptools import Command
|
||||
|
||||
from sysconfig import get_path, get_python_version
|
||||
from setuptools.extension import Library
|
||||
|
||||
|
||||
def _get_purelib():
|
||||
return get_path("purelib")
|
||||
return get_path('purelib')
|
||||
|
||||
|
||||
def strip_module(filename):
|
||||
|
|
@ -60,23 +64,35 @@ class bdist_egg(Command):
|
|||
description = "create an \"egg\" distribution"
|
||||
|
||||
user_options = [
|
||||
('bdist-dir=', 'b',
|
||||
"temporary directory for creating the distribution"),
|
||||
('plat-name=', 'p', "platform name to embed in generated filenames "
|
||||
"(default: %s)" % get_build_platform()),
|
||||
('exclude-source-files', None,
|
||||
"remove all .py files from the generated egg"),
|
||||
('keep-temp', 'k',
|
||||
"keep the pseudo-installation tree around after " +
|
||||
"creating the distribution archive"),
|
||||
('dist-dir=', 'd',
|
||||
"directory to put final built distributions in"),
|
||||
('skip-build', None,
|
||||
"skip rebuilding everything (for testing/debugging)"),
|
||||
(
|
||||
'bdist-dir=', 'b',
|
||||
'temporary directory for creating the distribution',
|
||||
),
|
||||
(
|
||||
'plat-name=', 'p', 'platform name to embed in generated filenames '
|
||||
'(default: %s)' % get_build_platform(),
|
||||
),
|
||||
(
|
||||
'exclude-source-files', None,
|
||||
'remove all .py files from the generated egg',
|
||||
),
|
||||
(
|
||||
'keep-temp', 'k',
|
||||
'keep the pseudo-installation tree around after ' +
|
||||
'creating the distribution archive',
|
||||
),
|
||||
(
|
||||
'dist-dir=', 'd',
|
||||
'directory to put final built distributions in',
|
||||
),
|
||||
(
|
||||
'skip-build', None,
|
||||
'skip rebuilding everything (for testing/debugging)',
|
||||
),
|
||||
]
|
||||
|
||||
boolean_options = [
|
||||
'keep-temp', 'skip-build', 'exclude-source-files'
|
||||
'keep-temp', 'skip-build', 'exclude-source-files',
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
|
|
@ -89,7 +105,7 @@ class bdist_egg(Command):
|
|||
self.exclude_source_files = None
|
||||
|
||||
def finalize_options(self):
|
||||
ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
|
||||
ei_cmd = self.ei_cmd = self.get_finalized_command('egg_info')
|
||||
self.egg_info = ei_cmd.egg_info
|
||||
|
||||
if self.bdist_dir is None:
|
||||
|
|
@ -107,7 +123,7 @@ class bdist_egg(Command):
|
|||
basename = Distribution(
|
||||
None, None, ei_cmd.egg_name, ei_cmd.egg_version,
|
||||
get_python_version(),
|
||||
self.distribution.has_ext_modules() and self.plat_name
|
||||
self.distribution.has_ext_modules() and self.plat_name,
|
||||
).egg_name()
|
||||
|
||||
self.egg_output = os.path.join(self.dist_dir, basename + '.egg')
|
||||
|
|
@ -125,14 +141,14 @@ class bdist_egg(Command):
|
|||
realpath = os.path.realpath(item[0])
|
||||
normalized = os.path.normcase(realpath)
|
||||
if normalized == site_packages or normalized.startswith(
|
||||
site_packages + os.sep
|
||||
site_packages + os.sep,
|
||||
):
|
||||
item = realpath[len(site_packages) + 1:], item[1]
|
||||
# XXX else: raise ???
|
||||
self.distribution.data_files.append(item)
|
||||
|
||||
try:
|
||||
log.info("installing package data to %s", self.bdist_dir)
|
||||
log.info('installing package data to %s', self.bdist_dir)
|
||||
self.call_command('install_data', force=0, root=None)
|
||||
finally:
|
||||
self.distribution.data_files = old
|
||||
|
|
@ -152,10 +168,10 @@ class bdist_egg(Command):
|
|||
|
||||
def run(self): # noqa: C901 # is too complex (14) # FIXME
|
||||
# Generate metadata first
|
||||
self.run_command("egg_info")
|
||||
self.run_command('egg_info')
|
||||
# We run install_lib before install_data, because some data hacks
|
||||
# pull their data path from the install_lib command.
|
||||
log.info("installing library code to %s", self.bdist_dir)
|
||||
log.info('installing library code to %s', self.bdist_dir)
|
||||
instcmd = self.get_finalized_command('install')
|
||||
old_root = instcmd.root
|
||||
instcmd.root = None
|
||||
|
|
@ -169,10 +185,12 @@ class bdist_egg(Command):
|
|||
to_compile = []
|
||||
for (p, ext_name) in enumerate(ext_outputs):
|
||||
filename, ext = os.path.splitext(ext_name)
|
||||
pyfile = os.path.join(self.bdist_dir, strip_module(filename) +
|
||||
'.py')
|
||||
pyfile = os.path.join(
|
||||
self.bdist_dir, strip_module(filename) +
|
||||
'.py',
|
||||
)
|
||||
self.stubs.append(pyfile)
|
||||
log.info("creating stub loader for %s", ext_name)
|
||||
log.info('creating stub loader for %s', ext_name)
|
||||
if not self.dry_run:
|
||||
write_stub(os.path.basename(ext_name), pyfile)
|
||||
to_compile.append(pyfile)
|
||||
|
|
@ -189,56 +207,61 @@ class bdist_egg(Command):
|
|||
self.mkpath(egg_info)
|
||||
if self.distribution.scripts:
|
||||
script_dir = os.path.join(egg_info, 'scripts')
|
||||
log.info("installing scripts to %s", script_dir)
|
||||
self.call_command('install_scripts', install_dir=script_dir,
|
||||
no_ep=1)
|
||||
log.info('installing scripts to %s', script_dir)
|
||||
self.call_command(
|
||||
'install_scripts', install_dir=script_dir,
|
||||
no_ep=1,
|
||||
)
|
||||
|
||||
self.copy_metadata_to(egg_info)
|
||||
native_libs = os.path.join(egg_info, "native_libs.txt")
|
||||
native_libs = os.path.join(egg_info, 'native_libs.txt')
|
||||
if all_outputs:
|
||||
log.info("writing %s", native_libs)
|
||||
log.info('writing %s', native_libs)
|
||||
if not self.dry_run:
|
||||
ensure_directory(native_libs)
|
||||
libs_file = open(native_libs, 'wt')
|
||||
libs_file = open(native_libs, 'w')
|
||||
libs_file.write('\n'.join(all_outputs))
|
||||
libs_file.write('\n')
|
||||
libs_file.close()
|
||||
elif os.path.isfile(native_libs):
|
||||
log.info("removing %s", native_libs)
|
||||
log.info('removing %s', native_libs)
|
||||
if not self.dry_run:
|
||||
os.unlink(native_libs)
|
||||
|
||||
write_safety_flag(
|
||||
os.path.join(archive_root, 'EGG-INFO'), self.zip_safe()
|
||||
os.path.join(archive_root, 'EGG-INFO'), self.zip_safe(),
|
||||
)
|
||||
|
||||
if os.path.exists(os.path.join(self.egg_info, 'depends.txt')):
|
||||
log.warn(
|
||||
"WARNING: 'depends.txt' will not be used by setuptools 0.6!\n"
|
||||
"Use the install_requires/extras_require setup() args instead."
|
||||
'Use the install_requires/extras_require setup() args instead.',
|
||||
)
|
||||
|
||||
if self.exclude_source_files:
|
||||
self.zap_pyfiles()
|
||||
|
||||
# Make the archive
|
||||
make_zipfile(self.egg_output, archive_root, verbose=self.verbose,
|
||||
dry_run=self.dry_run, mode=self.gen_header())
|
||||
make_zipfile(
|
||||
self.egg_output, archive_root, verbose=self.verbose,
|
||||
dry_run=self.dry_run, mode=self.gen_header(),
|
||||
)
|
||||
if not self.keep_temp:
|
||||
remove_tree(self.bdist_dir, dry_run=self.dry_run)
|
||||
|
||||
# Add to 'Distribution.dist_files' so that the "upload" command works
|
||||
getattr(self.distribution, 'dist_files', []).append(
|
||||
('bdist_egg', get_python_version(), self.egg_output))
|
||||
('bdist_egg', get_python_version(), self.egg_output),
|
||||
)
|
||||
|
||||
def zap_pyfiles(self):
|
||||
log.info("Removing .py files from temporary directory")
|
||||
log.info('Removing .py files from temporary directory')
|
||||
for base, dirs, files in walk_egg(self.bdist_dir):
|
||||
for name in files:
|
||||
path = os.path.join(base, name)
|
||||
|
||||
if name.endswith('.py'):
|
||||
log.debug("Deleting %s", path)
|
||||
log.debug('Deleting %s', path)
|
||||
os.unlink(path)
|
||||
|
||||
if base.endswith('__pycache__'):
|
||||
|
|
@ -247,10 +270,12 @@ class bdist_egg(Command):
|
|||
pattern = r'(?P<name>.+)\.(?P<magic>[^.]+)\.pyc'
|
||||
m = re.match(pattern, name)
|
||||
path_new = os.path.join(
|
||||
base, os.pardir, m.group('name') + '.pyc')
|
||||
base, os.pardir, m.group('name') + '.pyc',
|
||||
)
|
||||
log.info(
|
||||
"Renaming file from [%s] to [%s]"
|
||||
% (path_old, path_new))
|
||||
'Renaming file from [%s] to [%s]'
|
||||
% (path_old, path_new),
|
||||
)
|
||||
try:
|
||||
os.remove(path_new)
|
||||
except OSError:
|
||||
|
|
@ -261,14 +286,14 @@ class bdist_egg(Command):
|
|||
safe = getattr(self.distribution, 'zip_safe', None)
|
||||
if safe is not None:
|
||||
return safe
|
||||
log.warn("zip_safe flag not set; analyzing archive contents...")
|
||||
log.warn('zip_safe flag not set; analyzing archive contents...')
|
||||
return analyze_egg(self.bdist_dir, self.stubs)
|
||||
|
||||
def gen_header(self):
|
||||
return 'w'
|
||||
|
||||
def copy_metadata_to(self, target_dir):
|
||||
"Copy metadata (egg info) to the target_dir"
|
||||
'Copy metadata (egg info) to the target_dir'
|
||||
# normalize the path (so that a forward-slash in egg_info will
|
||||
# match using startswith below)
|
||||
norm_egg_info = os.path.normpath(self.egg_info)
|
||||
|
|
@ -291,8 +316,10 @@ class bdist_egg(Command):
|
|||
if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS:
|
||||
all_outputs.append(paths[base] + filename)
|
||||
for filename in dirs:
|
||||
paths[os.path.join(base, filename)] = (paths[base] +
|
||||
filename + '/')
|
||||
paths[os.path.join(base, filename)] = (
|
||||
paths[base] +
|
||||
filename + '/'
|
||||
)
|
||||
|
||||
if self.distribution.has_ext_modules():
|
||||
build_cmd = self.get_finalized_command('build_ext')
|
||||
|
|
@ -318,8 +345,7 @@ def walk_egg(egg_dir):
|
|||
if 'EGG-INFO' in dirs:
|
||||
dirs.remove('EGG-INFO')
|
||||
yield base, dirs, files
|
||||
for bdf in walker:
|
||||
yield bdf
|
||||
yield from walker
|
||||
|
||||
|
||||
def analyze_egg(egg_dir, stubs):
|
||||
|
|
@ -348,7 +374,7 @@ def write_safety_flag(egg_dir, safe):
|
|||
if safe is None or bool(safe) != flag:
|
||||
os.unlink(fn)
|
||||
elif safe is not None and bool(safe) == flag:
|
||||
f = open(fn, 'wt')
|
||||
f = open(fn, 'w')
|
||||
f.write('\n')
|
||||
f.close()
|
||||
|
||||
|
|
@ -367,10 +393,7 @@ def scan_module(egg_dir, base, name, stubs):
|
|||
return True # Extension module
|
||||
pkg = base[len(egg_dir) + 1:].replace(os.sep, '.')
|
||||
module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0]
|
||||
if sys.version_info < (3, 7):
|
||||
skip = 12 # skip magic & date & file size
|
||||
else:
|
||||
skip = 16 # skip magic & reserved? & date & file size
|
||||
skip = 16 # skip magic & reserved? & date & file size
|
||||
f = open(filename, 'rb')
|
||||
f.read(skip)
|
||||
code = marshal.load(f)
|
||||
|
|
@ -379,51 +402,53 @@ def scan_module(egg_dir, base, name, stubs):
|
|||
symbols = dict.fromkeys(iter_symbols(code))
|
||||
for bad in ['__file__', '__path__']:
|
||||
if bad in symbols:
|
||||
log.warn("%s: module references %s", module, bad)
|
||||
log.warn('%s: module references %s', module, bad)
|
||||
safe = False
|
||||
if 'inspect' in symbols:
|
||||
for bad in [
|
||||
'getsource', 'getabsfile', 'getsourcefile', 'getfile'
|
||||
'getsourcelines', 'findsource', 'getcomments', 'getframeinfo',
|
||||
'getinnerframes', 'getouterframes', 'stack', 'trace'
|
||||
'getinnerframes', 'getouterframes', 'stack', 'trace',
|
||||
]:
|
||||
if bad in symbols:
|
||||
log.warn("%s: module MAY be using inspect.%s", module, bad)
|
||||
log.warn('%s: module MAY be using inspect.%s', module, bad)
|
||||
safe = False
|
||||
return safe
|
||||
|
||||
|
||||
def iter_symbols(code):
|
||||
"""Yield names and strings used by `code` and its nested code objects"""
|
||||
for name in code.co_names:
|
||||
yield name
|
||||
yield from code.co_names
|
||||
for const in code.co_consts:
|
||||
if isinstance(const, str):
|
||||
yield const
|
||||
elif isinstance(const, CodeType):
|
||||
for name in iter_symbols(const):
|
||||
yield name
|
||||
yield from iter_symbols(const)
|
||||
|
||||
|
||||
def can_scan():
|
||||
if not sys.platform.startswith('java') and sys.platform != 'cli':
|
||||
# CPython, PyPy, etc.
|
||||
return True
|
||||
log.warn("Unable to analyze compiled code on this platform.")
|
||||
log.warn("Please ask the author to include a 'zip_safe'"
|
||||
" setting (either True or False) in the package's setup.py")
|
||||
log.warn('Unable to analyze compiled code on this platform.')
|
||||
log.warn(
|
||||
"Please ask the author to include a 'zip_safe'"
|
||||
" setting (either True or False) in the package's setup.py",
|
||||
)
|
||||
|
||||
|
||||
# Attribute names of options for commands that might need to be convinced to
|
||||
# install to the egg build directory
|
||||
|
||||
INSTALL_DIRECTORY_ATTRS = [
|
||||
'install_lib', 'install_dir', 'install_data', 'install_base'
|
||||
'install_lib', 'install_dir', 'install_data', 'install_base',
|
||||
]
|
||||
|
||||
|
||||
def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=True,
|
||||
mode='w'):
|
||||
def make_zipfile(
|
||||
zip_filename, base_dir, verbose=0, dry_run=0, compress=True,
|
||||
mode='w',
|
||||
):
|
||||
"""Create a zip file from all the files under 'base_dir'. The output
|
||||
zip file will be named 'base_dir' + ".zip". Uses either the "zipfile"
|
||||
Python module (if available) or the InfoZIP "zip" utility (if installed
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import distutils.command.bdist_rpm as orig
|
||||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
|
||||
import distutils.command.bdist_rpm as orig
|
||||
from setuptools import SetuptoolsDeprecationWarning
|
||||
|
||||
|
||||
|
|
@ -15,8 +17,8 @@ class bdist_rpm(orig.bdist_rpm):
|
|||
|
||||
def run(self):
|
||||
warnings.warn(
|
||||
"bdist_rpm is deprecated and will be removed in a future "
|
||||
"version. Use bdist_wheel (wheel packages) instead.",
|
||||
'bdist_rpm is deprecated and will be removed in a future '
|
||||
'version. Use bdist_wheel (wheel packages) instead.',
|
||||
SetuptoolsDeprecationWarning,
|
||||
)
|
||||
|
||||
|
|
@ -29,11 +31,11 @@ class bdist_rpm(orig.bdist_rpm):
|
|||
spec = orig.bdist_rpm._make_spec_file(self)
|
||||
spec = [
|
||||
line.replace(
|
||||
"setup.py install ",
|
||||
"setup.py install --single-version-externally-managed "
|
||||
'setup.py install ',
|
||||
'setup.py install --single-version-externally-managed ',
|
||||
).replace(
|
||||
"%setup",
|
||||
"%setup -n %{name}-%{unmangled_version}"
|
||||
'%setup',
|
||||
'%setup -n %{name}-%{unmangled_version}',
|
||||
)
|
||||
for line in spec
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import distutils.command.build_clib as orig
|
||||
from distutils.errors import DistutilsSetupError
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsSetupError
|
||||
from setuptools.dep_util import newer_pairwise_group
|
||||
|
||||
|
||||
|
|
@ -27,7 +29,8 @@ class build_clib(orig.build_clib):
|
|||
raise DistutilsSetupError(
|
||||
"in 'libraries' option (library '%s'), "
|
||||
"'sources' must be present and must be "
|
||||
"a list of source filenames" % lib_name)
|
||||
'a list of source filenames' % lib_name,
|
||||
)
|
||||
sources = list(sources)
|
||||
|
||||
log.info("building '%s' library", lib_name)
|
||||
|
|
@ -40,7 +43,8 @@ class build_clib(orig.build_clib):
|
|||
raise DistutilsSetupError(
|
||||
"in 'libraries' option (library '%s'), "
|
||||
"'obj_deps' must be a dictionary of "
|
||||
"type 'source: list'" % lib_name)
|
||||
"type 'source: list'" % lib_name,
|
||||
)
|
||||
dependencies = []
|
||||
|
||||
# Get the global dependencies that are specified by the '' key.
|
||||
|
|
@ -50,7 +54,8 @@ class build_clib(orig.build_clib):
|
|||
raise DistutilsSetupError(
|
||||
"in 'libraries' option (library '%s'), "
|
||||
"'obj_deps' must be a dictionary of "
|
||||
"type 'source: list'" % lib_name)
|
||||
"type 'source: list'" % lib_name,
|
||||
)
|
||||
|
||||
# Build the list to be used by newer_pairwise_group
|
||||
# each source will be auto-added to its dependencies.
|
||||
|
|
@ -62,7 +67,8 @@ class build_clib(orig.build_clib):
|
|||
raise DistutilsSetupError(
|
||||
"in 'libraries' option (library '%s'), "
|
||||
"'obj_deps' must be a dictionary of "
|
||||
"type 'source: list'" % lib_name)
|
||||
"type 'source: list'" % lib_name,
|
||||
)
|
||||
src_deps.extend(extra_deps)
|
||||
dependencies.append(src_deps)
|
||||
|
||||
|
|
@ -72,8 +78,8 @@ class build_clib(orig.build_clib):
|
|||
)
|
||||
|
||||
if (
|
||||
newer_pairwise_group(dependencies, expected_objects)
|
||||
!= ([], [])
|
||||
newer_pairwise_group(dependencies, expected_objects) !=
|
||||
([], [])
|
||||
):
|
||||
# First, compile the source code to object files in the library
|
||||
# directory. (This should probably change to putting object
|
||||
|
|
@ -87,7 +93,7 @@ class build_clib(orig.build_clib):
|
|||
macros=macros,
|
||||
include_dirs=include_dirs,
|
||||
extra_postargs=cflags,
|
||||
debug=self.debug
|
||||
debug=self.debug,
|
||||
)
|
||||
|
||||
# Now "link" the object files together into a static library.
|
||||
|
|
@ -97,5 +103,5 @@ class build_clib(orig.build_clib):
|
|||
expected_objects,
|
||||
lib_name,
|
||||
output_dir=self.build_clib,
|
||||
debug=self.debug
|
||||
debug=self.debug,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import itertools
|
||||
import os
|
||||
import sys
|
||||
import itertools
|
||||
from importlib.machinery import EXTENSION_SUFFIXES
|
||||
from distutils.command.build_ext import build_ext as _du_build_ext
|
||||
from distutils.file_util import copy_file
|
||||
from distutils.ccompiler import new_compiler
|
||||
from distutils.sysconfig import customize_compiler, get_config_var
|
||||
from distutils.errors import DistutilsError
|
||||
from distutils import log
|
||||
|
||||
from distutils import log
|
||||
from distutils.ccompiler import new_compiler
|
||||
from distutils.command.build_ext import build_ext as _du_build_ext
|
||||
from distutils.errors import DistutilsError
|
||||
from distutils.file_util import copy_file
|
||||
from distutils.sysconfig import customize_compiler
|
||||
from distutils.sysconfig import get_config_var
|
||||
from setuptools.extension import Library
|
||||
|
||||
try:
|
||||
|
|
@ -21,12 +24,12 @@ except ImportError:
|
|||
_build_ext = _du_build_ext
|
||||
|
||||
# make sure _config_vars is initialized
|
||||
get_config_var("LDSHARED")
|
||||
get_config_var('LDSHARED')
|
||||
from distutils.sysconfig import _config_vars as _CONFIG_VARS # noqa
|
||||
|
||||
|
||||
def _customize_compiler_for_shlib(compiler):
|
||||
if sys.platform == "darwin":
|
||||
if sys.platform == 'darwin':
|
||||
# building .dylib requires additional compiler flags on OSX; here we
|
||||
# temporarily substitute the pyconfig.h variables so that distutils'
|
||||
# 'customize_compiler' uses them before we build the shared libraries.
|
||||
|
|
@ -34,9 +37,10 @@ def _customize_compiler_for_shlib(compiler):
|
|||
try:
|
||||
# XXX Help! I don't have any idea whether these are right...
|
||||
_CONFIG_VARS['LDSHARED'] = (
|
||||
"gcc -Wl,-x -dynamiclib -undefined dynamic_lookup")
|
||||
_CONFIG_VARS['CCSHARED'] = " -dynamiclib"
|
||||
_CONFIG_VARS['SO'] = ".dylib"
|
||||
'gcc -Wl,-x -dynamiclib -undefined dynamic_lookup'
|
||||
)
|
||||
_CONFIG_VARS['CCSHARED'] = ' -dynamiclib'
|
||||
_CONFIG_VARS['SO'] = '.dylib'
|
||||
customize_compiler(compiler)
|
||||
finally:
|
||||
_CONFIG_VARS.clear()
|
||||
|
|
@ -49,7 +53,7 @@ have_rtld = False
|
|||
use_stubs = False
|
||||
libtype = 'shared'
|
||||
|
||||
if sys.platform == "darwin":
|
||||
if sys.platform == 'darwin':
|
||||
use_stubs = True
|
||||
elif os.name != 'nt':
|
||||
try:
|
||||
|
|
@ -89,8 +93,10 @@ class build_ext(_build_ext):
|
|||
modpath = fullname.split('.')
|
||||
package = '.'.join(modpath[:-1])
|
||||
package_dir = build_py.get_package_dir(package)
|
||||
dest_filename = os.path.join(package_dir,
|
||||
os.path.basename(filename))
|
||||
dest_filename = os.path.join(
|
||||
package_dir,
|
||||
os.path.basename(filename),
|
||||
)
|
||||
src_filename = os.path.join(self.build_lib, filename)
|
||||
|
||||
# Always copy, even if source is older than destination, to ensure
|
||||
|
|
@ -98,7 +104,7 @@ class build_ext(_build_ext):
|
|||
# used.
|
||||
copy_file(
|
||||
src_filename, dest_filename, verbose=self.verbose,
|
||||
dry_run=self.dry_run
|
||||
dry_run=self.dry_run,
|
||||
)
|
||||
if ext._needs_stub:
|
||||
self.write_stub(package_dir or os.curdir, ext, True)
|
||||
|
|
@ -136,8 +142,10 @@ class build_ext(_build_ext):
|
|||
_build_ext.finalize_options(self)
|
||||
self.extensions = self.extensions or []
|
||||
self.check_extensions_list(self.extensions)
|
||||
self.shlibs = [ext for ext in self.extensions
|
||||
if isinstance(ext, Library)]
|
||||
self.shlibs = [
|
||||
ext for ext in self.extensions
|
||||
if isinstance(ext, Library)
|
||||
]
|
||||
if self.shlibs:
|
||||
self.setup_shlib_compiler()
|
||||
for ext in self.extensions:
|
||||
|
|
@ -163,7 +171,7 @@ class build_ext(_build_ext):
|
|||
|
||||
def setup_shlib_compiler(self):
|
||||
compiler = self.shlib_compiler = new_compiler(
|
||||
compiler=self.compiler, dry_run=self.dry_run, force=self.force
|
||||
compiler=self.compiler, dry_run=self.dry_run, force=self.force,
|
||||
)
|
||||
_customize_compiler_for_shlib(compiler)
|
||||
|
||||
|
|
@ -236,52 +244,60 @@ class build_ext(_build_ext):
|
|||
yield '.pyo'
|
||||
|
||||
def write_stub(self, output_dir, ext, compile=False):
|
||||
log.info("writing stub loader for %s to %s", ext._full_name,
|
||||
output_dir)
|
||||
stub_file = (os.path.join(output_dir, *ext._full_name.split('.')) +
|
||||
'.py')
|
||||
log.info(
|
||||
'writing stub loader for %s to %s', ext._full_name,
|
||||
output_dir,
|
||||
)
|
||||
stub_file = (
|
||||
os.path.join(output_dir, *ext._full_name.split('.')) +
|
||||
'.py'
|
||||
)
|
||||
if compile and os.path.exists(stub_file):
|
||||
raise DistutilsError(stub_file + " already exists! Please delete.")
|
||||
raise DistutilsError(stub_file + ' already exists! Please delete.')
|
||||
if not self.dry_run:
|
||||
f = open(stub_file, 'w')
|
||||
f.write(
|
||||
'\n'.join([
|
||||
"def __bootstrap__():",
|
||||
" global __bootstrap__, __file__, __loader__",
|
||||
" import sys, os, pkg_resources, importlib.util" +
|
||||
if_dl(", dl"),
|
||||
" __file__ = pkg_resources.resource_filename"
|
||||
"(__name__,%r)"
|
||||
'def __bootstrap__():',
|
||||
' global __bootstrap__, __file__, __loader__',
|
||||
' import sys, os, pkg_resources, importlib.util' +
|
||||
if_dl(', dl'),
|
||||
' __file__ = pkg_resources.resource_filename'
|
||||
'(__name__,%r)'
|
||||
% os.path.basename(ext._file_name),
|
||||
" del __bootstrap__",
|
||||
' del __bootstrap__',
|
||||
" if '__loader__' in globals():",
|
||||
" del __loader__",
|
||||
if_dl(" old_flags = sys.getdlopenflags()"),
|
||||
" old_dir = os.getcwd()",
|
||||
" try:",
|
||||
" os.chdir(os.path.dirname(__file__))",
|
||||
if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"),
|
||||
" spec = importlib.util.spec_from_file_location(",
|
||||
" __name__, __file__)",
|
||||
" mod = importlib.util.module_from_spec(spec)",
|
||||
" spec.loader.exec_module(mod)",
|
||||
" finally:",
|
||||
if_dl(" sys.setdlopenflags(old_flags)"),
|
||||
" os.chdir(old_dir)",
|
||||
"__bootstrap__()",
|
||||
"" # terminal \n
|
||||
])
|
||||
' del __loader__',
|
||||
if_dl(' old_flags = sys.getdlopenflags()'),
|
||||
' old_dir = os.getcwd()',
|
||||
' try:',
|
||||
' os.chdir(os.path.dirname(__file__))',
|
||||
if_dl(' sys.setdlopenflags(dl.RTLD_NOW)'),
|
||||
' spec = importlib.util.spec_from_file_location(',
|
||||
' __name__, __file__)',
|
||||
' mod = importlib.util.module_from_spec(spec)',
|
||||
' spec.loader.exec_module(mod)',
|
||||
' finally:',
|
||||
if_dl(' sys.setdlopenflags(old_flags)'),
|
||||
' os.chdir(old_dir)',
|
||||
'__bootstrap__()',
|
||||
'', # terminal \n
|
||||
]),
|
||||
)
|
||||
f.close()
|
||||
if compile:
|
||||
from distutils.util import byte_compile
|
||||
|
||||
byte_compile([stub_file], optimize=0,
|
||||
force=True, dry_run=self.dry_run)
|
||||
byte_compile(
|
||||
[stub_file], optimize=0,
|
||||
force=True, dry_run=self.dry_run,
|
||||
)
|
||||
optimize = self.get_finalized_command('install_lib').optimize
|
||||
if optimize > 0:
|
||||
byte_compile([stub_file], optimize=optimize,
|
||||
force=True, dry_run=self.dry_run)
|
||||
byte_compile(
|
||||
[stub_file], optimize=optimize,
|
||||
force=True, dry_run=self.dry_run,
|
||||
)
|
||||
if os.path.exists(stub_file) and not self.dry_run:
|
||||
os.unlink(stub_file)
|
||||
|
||||
|
|
@ -293,12 +309,13 @@ if use_stubs or os.name == 'nt':
|
|||
self, objects, output_libname, output_dir=None, libraries=None,
|
||||
library_dirs=None, runtime_library_dirs=None, export_symbols=None,
|
||||
debug=0, extra_preargs=None, extra_postargs=None, build_temp=None,
|
||||
target_lang=None):
|
||||
target_lang=None,
|
||||
):
|
||||
self.link(
|
||||
self.SHARED_LIBRARY, objects, output_libname,
|
||||
output_dir, libraries, library_dirs, runtime_library_dirs,
|
||||
export_symbols, debug, extra_preargs, extra_postargs,
|
||||
build_temp, target_lang
|
||||
build_temp, target_lang,
|
||||
)
|
||||
else:
|
||||
# Build static libraries everywhere else
|
||||
|
|
@ -308,7 +325,8 @@ else:
|
|||
self, objects, output_libname, output_dir=None, libraries=None,
|
||||
library_dirs=None, runtime_library_dirs=None, export_symbols=None,
|
||||
debug=0, extra_preargs=None, extra_postargs=None, build_temp=None,
|
||||
target_lang=None):
|
||||
target_lang=None,
|
||||
):
|
||||
# XXX we need to either disallow these attrs on Library instances,
|
||||
# or warn/abort here if set, or something...
|
||||
# libraries=None, library_dirs=None, runtime_library_dirs=None,
|
||||
|
|
@ -318,11 +336,11 @@ else:
|
|||
assert output_dir is None # distutils build_ext doesn't pass this
|
||||
output_dir, filename = os.path.split(output_libname)
|
||||
basename, ext = os.path.splitext(filename)
|
||||
if self.library_filename("x").startswith('lib'):
|
||||
if self.library_filename('x').startswith('lib'):
|
||||
# strip 'lib' prefix; this is kludgy if some platform uses
|
||||
# a different prefix
|
||||
basename = basename[3:]
|
||||
|
||||
self.create_static_lib(
|
||||
objects, basename, output_dir, debug, target_lang
|
||||
objects, basename, output_dir, debug, target_lang,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
from glob import glob
|
||||
from distutils.util import convert_path
|
||||
import distutils.command.build_py as orig
|
||||
import os
|
||||
from __future__ import annotations
|
||||
|
||||
import fnmatch
|
||||
import textwrap
|
||||
import io
|
||||
import distutils.errors
|
||||
import itertools
|
||||
import os
|
||||
import stat
|
||||
import textwrap
|
||||
from glob import glob
|
||||
|
||||
import distutils.command.build_py as orig
|
||||
import distutils.errors
|
||||
from distutils.util import convert_path
|
||||
from setuptools.extern.more_itertools import unique_everseen
|
||||
|
||||
|
||||
|
|
@ -50,7 +53,7 @@ class build_py(orig.build_py):
|
|||
self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0))
|
||||
|
||||
def __getattr__(self, attr):
|
||||
"lazily compute data files"
|
||||
'lazily compute data files'
|
||||
if attr == 'data_files':
|
||||
self.data_files = self._get_data_files()
|
||||
return self.data_files
|
||||
|
|
@ -155,14 +158,14 @@ class build_py(orig.build_py):
|
|||
else:
|
||||
return init_py
|
||||
|
||||
with io.open(init_py, 'rb') as f:
|
||||
with open(init_py, 'rb') as f:
|
||||
contents = f.read()
|
||||
if b'declare_namespace' not in contents:
|
||||
raise distutils.errors.DistutilsError(
|
||||
"Namespace package problem: %s is a namespace package, but "
|
||||
"its\n__init__.py does not call declare_namespace()! Please "
|
||||
'Namespace package problem: %s is a namespace package, but '
|
||||
'its\n__init__.py does not call declare_namespace()! Please '
|
||||
'fix it.\n(See the setuptools manual under '
|
||||
'"Namespace Packages" for details.)\n"' % (package,)
|
||||
'"Namespace Packages" for details.)\n"' % (package,),
|
||||
)
|
||||
return init_py
|
||||
|
||||
|
|
@ -225,7 +228,7 @@ def assert_relative(path):
|
|||
|
||||
setup() arguments must *always* be /-separated paths relative to the
|
||||
setup.py directory, *never* absolute paths.
|
||||
"""
|
||||
""",
|
||||
).lstrip()
|
||||
% path
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
from distutils.util import convert_path
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsError, DistutilsOptionError
|
||||
import os
|
||||
from __future__ import annotations
|
||||
|
||||
import glob
|
||||
import io
|
||||
import os
|
||||
|
||||
import pkg_resources
|
||||
from setuptools.command.easy_install import easy_install
|
||||
from setuptools import namespaces
|
||||
import setuptools
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsError
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from distutils.util import convert_path
|
||||
from setuptools import namespaces
|
||||
from setuptools.command.easy_install import easy_install
|
||||
|
||||
|
||||
class develop(namespaces.DevelopInstaller, easy_install):
|
||||
|
|
@ -17,8 +20,8 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
description = "install package in 'development mode'"
|
||||
|
||||
user_options = easy_install.user_options + [
|
||||
("uninstall", "u", "Uninstall this source package"),
|
||||
("egg-path=", None, "Set the path to be used in the .egg-link file"),
|
||||
('uninstall', 'u', 'Uninstall this source package'),
|
||||
('egg-path=', None, 'Set the path to be used in the .egg-link file'),
|
||||
]
|
||||
|
||||
boolean_options = easy_install.boolean_options + ['uninstall']
|
||||
|
|
@ -42,7 +45,7 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
self.always_copy_from = '.' # always copy eggs installed in curdir
|
||||
|
||||
def finalize_options(self):
|
||||
ei = self.get_finalized_command("egg_info")
|
||||
ei = self.get_finalized_command('egg_info')
|
||||
if ei.broken_egg_info:
|
||||
template = "Please rename %r to %r before using 'develop'"
|
||||
args = ei.egg_info, ei.broken_egg_info
|
||||
|
|
@ -63,12 +66,12 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
|
||||
target = pkg_resources.normalize_path(self.egg_base)
|
||||
egg_path = pkg_resources.normalize_path(
|
||||
os.path.join(self.install_dir, self.egg_path)
|
||||
os.path.join(self.install_dir, self.egg_path),
|
||||
)
|
||||
if egg_path != target:
|
||||
raise DistutilsOptionError(
|
||||
"--egg-path must be a relative path from the install"
|
||||
" directory to " + target
|
||||
'--egg-path must be a relative path from the install'
|
||||
' directory to ' + target,
|
||||
)
|
||||
|
||||
# Make a distribution for the package's source
|
||||
|
|
@ -95,12 +98,12 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
if path_to_setup != os.curdir:
|
||||
path_to_setup = '../' * (path_to_setup.count('/') + 1)
|
||||
resolved = pkg_resources.normalize_path(
|
||||
os.path.join(install_dir, egg_path, path_to_setup)
|
||||
os.path.join(install_dir, egg_path, path_to_setup),
|
||||
)
|
||||
if resolved != pkg_resources.normalize_path(os.curdir):
|
||||
raise DistutilsOptionError(
|
||||
"Can't get a consistent path to setup script from"
|
||||
" installation directory",
|
||||
' installation directory',
|
||||
resolved,
|
||||
pkg_resources.normalize_path(os.curdir),
|
||||
)
|
||||
|
|
@ -120,22 +123,22 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
self.install_namespaces()
|
||||
|
||||
# create an .egg-link in the installation dir, pointing to our egg
|
||||
log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
|
||||
log.info('Creating %s (link to %s)', self.egg_link, self.egg_base)
|
||||
if not self.dry_run:
|
||||
with open(self.egg_link, "w") as f:
|
||||
f.write(self.egg_path + "\n" + self.setup_path)
|
||||
with open(self.egg_link, 'w') as f:
|
||||
f.write(self.egg_path + '\n' + self.setup_path)
|
||||
# postprocess the installed distro, fixing up .pth, installing scripts,
|
||||
# and handling requirements
|
||||
self.process_distribution(None, self.dist, not self.no_deps)
|
||||
|
||||
def uninstall_link(self):
|
||||
if os.path.exists(self.egg_link):
|
||||
log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
|
||||
log.info('Removing %s (link to %s)', self.egg_link, self.egg_base)
|
||||
egg_link_file = open(self.egg_link)
|
||||
contents = [line.rstrip() for line in egg_link_file]
|
||||
egg_link_file.close()
|
||||
if contents not in ([self.egg_path], [self.egg_path, self.setup_path]):
|
||||
log.warn("Link points to %s: uninstall aborted", contents)
|
||||
log.warn('Link points to %s: uninstall aborted', contents)
|
||||
return
|
||||
if not self.dry_run:
|
||||
os.unlink(self.egg_link)
|
||||
|
|
@ -143,7 +146,7 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
self.update_pth(self.dist) # remove any .pth link to us
|
||||
if self.distribution.scripts:
|
||||
# XXX should also check for entry point scripts!
|
||||
log.warn("Note: you must uninstall or replace scripts manually!")
|
||||
log.warn('Note: you must uninstall or replace scripts manually!')
|
||||
|
||||
def install_egg_scripts(self, dist):
|
||||
if dist is not self.dist:
|
||||
|
|
@ -159,7 +162,7 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
for script_name in self.distribution.scripts or []:
|
||||
script_path = os.path.abspath(convert_path(script_name))
|
||||
script_name = os.path.basename(script_path)
|
||||
with io.open(script_path) as strm:
|
||||
with open(script_path) as strm:
|
||||
script_text = strm.read()
|
||||
self.install_script(dist, script_name, script_text, script_path)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
Create a dist_info directory
|
||||
As defined in the wheel specification
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from distutils.core import Command
|
||||
from distutils import log
|
||||
from distutils.core import Command
|
||||
|
||||
|
||||
class dist_info(Command):
|
||||
|
|
@ -14,8 +15,10 @@ class dist_info(Command):
|
|||
description = 'create a .dist-info directory'
|
||||
|
||||
user_options = [
|
||||
('egg-base=', 'e', "directory containing .egg-info directories"
|
||||
" (default: top of the source tree)"),
|
||||
(
|
||||
'egg-base=', 'e', 'directory containing .egg-info directories'
|
||||
' (default: top of the source tree)',
|
||||
),
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
|
|
@ -30,7 +33,7 @@ class dist_info(Command):
|
|||
egg_info.finalize_options()
|
||||
egg_info.run()
|
||||
dist_info_dir = egg_info.egg_info[:-len('.egg-info')] + '.dist-info'
|
||||
log.info("creating '{}'".format(os.path.abspath(dist_info_dir)))
|
||||
log.info(f"creating '{os.path.abspath(dist_info_dir)}'")
|
||||
|
||||
bdist_wheel = self.get_finalized_command('bdist_wheel')
|
||||
bdist_wheel.egg2dist(egg_info.egg_info, dist_info_dir)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,35 +1,40 @@
|
|||
"""setuptools.command.egg_info
|
||||
|
||||
Create a distribution's .egg-info directory and contents"""
|
||||
from __future__ import annotations
|
||||
|
||||
from distutils.filelist import FileList as _FileList
|
||||
from distutils.errors import DistutilsInternalError
|
||||
from distutils.util import convert_path
|
||||
from distutils import log
|
||||
import distutils.errors
|
||||
import distutils.filelist
|
||||
import collections
|
||||
import functools
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import io
|
||||
import warnings
|
||||
import time
|
||||
import collections
|
||||
import warnings
|
||||
|
||||
import distutils.errors
|
||||
import distutils.filelist
|
||||
import setuptools.unicode_utils as unicode_utils
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsInternalError
|
||||
from distutils.filelist import FileList as _FileList
|
||||
from distutils.util import convert_path
|
||||
from pkg_resources import EntryPoint
|
||||
from pkg_resources import iter_entry_points
|
||||
from pkg_resources import parse_requirements
|
||||
from pkg_resources import parse_version
|
||||
from pkg_resources import safe_name
|
||||
from pkg_resources import safe_version
|
||||
from pkg_resources import to_filename
|
||||
from pkg_resources import yield_lines
|
||||
from setuptools import Command
|
||||
from setuptools import SetuptoolsDeprecationWarning
|
||||
from setuptools.command import bdist_egg
|
||||
from setuptools.command.sdist import sdist
|
||||
from setuptools.command.sdist import walk_revctrl
|
||||
from setuptools.command.setopt import edit_config
|
||||
from setuptools.command import bdist_egg
|
||||
from pkg_resources import (
|
||||
parse_requirements, safe_name, parse_version,
|
||||
safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename)
|
||||
import setuptools.unicode_utils as unicode_utils
|
||||
from setuptools.glob import glob
|
||||
|
||||
from setuptools.extern import packaging
|
||||
from setuptools import SetuptoolsDeprecationWarning
|
||||
from setuptools.glob import glob
|
||||
|
||||
|
||||
def translate_pattern(glob): # noqa: C901 # is too complex (14) # FIXME
|
||||
|
|
@ -45,7 +50,7 @@ def translate_pattern(glob): # noqa: C901 # is too complex (14) # FIXME
|
|||
chunks = glob.split(os.path.sep)
|
||||
|
||||
sep = re.escape(os.sep)
|
||||
valid_char = '[^%s]' % (sep,)
|
||||
valid_char = '[^{}]'.format(sep)
|
||||
|
||||
for c, chunk in enumerate(chunks):
|
||||
last_chunk = c == len(chunks) - 1
|
||||
|
|
@ -57,7 +62,7 @@ def translate_pattern(glob): # noqa: C901 # is too complex (14) # FIXME
|
|||
pat += '.*'
|
||||
else:
|
||||
# Match '(name/)*'
|
||||
pat += '(?:%s+%s)*' % (valid_char, sep)
|
||||
pat += '(?:{}+{})*'.format(valid_char, sep)
|
||||
continue # Break here as the whole path component has been handled
|
||||
|
||||
# Find any special characters in the remainder
|
||||
|
|
@ -99,7 +104,7 @@ def translate_pattern(glob): # noqa: C901 # is too complex (14) # FIXME
|
|||
inner = inner[1:]
|
||||
|
||||
char_class += re.escape(inner)
|
||||
pat += '[%s]' % (char_class,)
|
||||
pat += '[{}]'.format(char_class)
|
||||
|
||||
# Skip to the end ]
|
||||
i = inner_i
|
||||
|
|
@ -141,7 +146,7 @@ class InfoCommon:
|
|||
if self.tag_build:
|
||||
version += self.tag_build
|
||||
if self.tag_date:
|
||||
version += time.strftime("-%Y%m%d")
|
||||
version += time.strftime('-%Y%m%d')
|
||||
return version
|
||||
vtags = property(tags)
|
||||
|
||||
|
|
@ -150,10 +155,12 @@ class egg_info(InfoCommon, Command):
|
|||
description = "create a distribution's .egg-info directory"
|
||||
|
||||
user_options = [
|
||||
('egg-base=', 'e', "directory containing .egg-info directories"
|
||||
" (default: top of the source tree)"),
|
||||
('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"),
|
||||
('tag-build=', 'b', "Specify explicit tag to add to version number"),
|
||||
(
|
||||
'egg-base=', 'e', 'directory containing .egg-info directories'
|
||||
' (default: top of the source tree)',
|
||||
),
|
||||
('tag-date', 'd', 'Add date stamp (e.g. 20050528) to version number'),
|
||||
('tag-build=', 'b', 'Specify explicit tag to add to version number'),
|
||||
('no-date', 'D', "Don't include date stamp [default]"),
|
||||
]
|
||||
|
||||
|
|
@ -206,15 +213,15 @@ class egg_info(InfoCommon, Command):
|
|||
try:
|
||||
is_version = isinstance(parsed_version, packaging.version.Version)
|
||||
spec = (
|
||||
"%s==%s" if is_version else "%s===%s"
|
||||
'%s==%s' if is_version else '%s===%s'
|
||||
)
|
||||
list(
|
||||
parse_requirements(spec % (self.egg_name, self.egg_version))
|
||||
parse_requirements(spec % (self.egg_name, self.egg_version)),
|
||||
)
|
||||
except ValueError as e:
|
||||
raise distutils.errors.DistutilsOptionError(
|
||||
"Invalid distribution name or version syntax: %s-%s" %
|
||||
(self.egg_name, self.egg_version)
|
||||
'Invalid distribution name or version syntax: %s-%s' %
|
||||
(self.egg_name, self.egg_version),
|
||||
) from e
|
||||
|
||||
if self.egg_base is None:
|
||||
|
|
@ -257,7 +264,7 @@ class egg_info(InfoCommon, Command):
|
|||
elif os.path.exists(filename):
|
||||
if data is None and not force:
|
||||
log.warn(
|
||||
"%s not set in setup(), but %s exists", what, filename
|
||||
'%s not set in setup(), but %s exists', what, filename,
|
||||
)
|
||||
return
|
||||
else:
|
||||
|
|
@ -269,8 +276,8 @@ class egg_info(InfoCommon, Command):
|
|||
`what` is used in a log message to identify what is being written
|
||||
to the file.
|
||||
"""
|
||||
log.info("writing %s to %s", what, filename)
|
||||
data = data.encode("utf-8")
|
||||
log.info('writing %s to %s', what, filename)
|
||||
data = data.encode('utf-8')
|
||||
if not self.dry_run:
|
||||
f = open(filename, 'wb')
|
||||
f.write(data)
|
||||
|
|
@ -278,7 +285,7 @@ class egg_info(InfoCommon, Command):
|
|||
|
||||
def delete_file(self, filename):
|
||||
"""Delete `filename` (if not a dry run) after announcing it"""
|
||||
log.info("deleting %s", filename)
|
||||
log.info('deleting %s', filename)
|
||||
if not self.dry_run:
|
||||
os.unlink(filename)
|
||||
|
||||
|
|
@ -292,7 +299,7 @@ class egg_info(InfoCommon, Command):
|
|||
writer(self, ep.name, os.path.join(self.egg_info, ep.name))
|
||||
|
||||
# Get rid of native_libs.txt if it was put there by older bdist_egg
|
||||
nl = os.path.join(self.egg_info, "native_libs.txt")
|
||||
nl = os.path.join(self.egg_info, 'native_libs.txt')
|
||||
if os.path.exists(nl):
|
||||
self.delete_file(nl)
|
||||
|
||||
|
|
@ -300,7 +307,7 @@ class egg_info(InfoCommon, Command):
|
|||
|
||||
def find_sources(self):
|
||||
"""Generate SOURCES.txt manifest file"""
|
||||
manifest_filename = os.path.join(self.egg_info, "SOURCES.txt")
|
||||
manifest_filename = os.path.join(self.egg_info, 'SOURCES.txt')
|
||||
mm = manifest_maker(self.distribution)
|
||||
mm.manifest = manifest_filename
|
||||
mm.run()
|
||||
|
|
@ -312,11 +319,11 @@ class egg_info(InfoCommon, Command):
|
|||
bei = os.path.join(self.egg_base, bei)
|
||||
if os.path.exists(bei):
|
||||
log.warn(
|
||||
"-" * 78 + '\n'
|
||||
'-' * 78 + '\n'
|
||||
"Note: Your current .egg-info directory has a '-' in its name;"
|
||||
'\nthis will not work correctly with "setup.py develop".\n\n'
|
||||
'Please rename %s to %s to correct this problem.\n' + '-' * 78,
|
||||
bei, self.egg_info
|
||||
bei, self.egg_info,
|
||||
)
|
||||
self.broken_egg_info = self.egg_info
|
||||
self.egg_info = bei # make it work for now
|
||||
|
|
@ -350,15 +357,15 @@ class FileList(_FileList):
|
|||
log_map = {
|
||||
'include': "warning: no files found matching '%s'",
|
||||
'exclude': (
|
||||
"warning: no previously-included files found "
|
||||
'warning: no previously-included files found '
|
||||
"matching '%s'"
|
||||
),
|
||||
'global-include': (
|
||||
"warning: no files found matching '%s' "
|
||||
"anywhere in distribution"
|
||||
'anywhere in distribution'
|
||||
),
|
||||
'global-exclude': (
|
||||
"warning: no previously-included files matching "
|
||||
'warning: no previously-included files matching '
|
||||
"'%s' found anywhere in distribution"
|
||||
),
|
||||
'recursive-include': (
|
||||
|
|
@ -366,7 +373,7 @@ class FileList(_FileList):
|
|||
"under directory '%s'"
|
||||
),
|
||||
'recursive-exclude': (
|
||||
"warning: no previously-included files matching "
|
||||
'warning: no previously-included files matching '
|
||||
"'%s' found under directory '%s'"
|
||||
),
|
||||
'graft': "warning: no directories found matching '%s'",
|
||||
|
|
@ -388,7 +395,7 @@ class FileList(_FileList):
|
|||
action_is_recursive = action.startswith('recursive-')
|
||||
if action in {'graft', 'prune'}:
|
||||
patterns = [dir_pattern]
|
||||
extra_log_args = (dir, ) if action_is_recursive else ()
|
||||
extra_log_args = (dir,) if action_is_recursive else ()
|
||||
log_tmpl = log_map[action]
|
||||
|
||||
self.debug_print(
|
||||
|
|
@ -396,7 +403,7 @@ class FileList(_FileList):
|
|||
[action] +
|
||||
([dir] if action_is_recursive else []) +
|
||||
patterns,
|
||||
)
|
||||
),
|
||||
)
|
||||
for pattern in patterns:
|
||||
if not process_action(pattern):
|
||||
|
|
@ -410,7 +417,7 @@ class FileList(_FileList):
|
|||
found = False
|
||||
for i in range(len(self.files) - 1, -1, -1):
|
||||
if predicate(self.files[i]):
|
||||
self.debug_print(" removing " + self.files[i])
|
||||
self.debug_print(' removing ' + self.files[i])
|
||||
del self.files[i]
|
||||
found = True
|
||||
return found
|
||||
|
|
@ -431,8 +438,10 @@ class FileList(_FileList):
|
|||
Include all files anywhere in 'dir/' that match the pattern.
|
||||
"""
|
||||
full_pattern = os.path.join(dir, '**', pattern)
|
||||
found = [f for f in glob(full_pattern, recursive=True)
|
||||
if not os.path.isdir(f)]
|
||||
found = [
|
||||
f for f in glob(full_pattern, recursive=True)
|
||||
if not os.path.isdir(f)
|
||||
]
|
||||
self.extend(found)
|
||||
return bool(found)
|
||||
|
||||
|
|
@ -508,7 +517,7 @@ class FileList(_FileList):
|
|||
return False
|
||||
|
||||
# Must ensure utf-8 encodability
|
||||
utf8_path = unicode_utils.try_encode(u_path, "utf-8")
|
||||
utf8_path = unicode_utils.try_encode(u_path, 'utf-8')
|
||||
if utf8_path is None:
|
||||
log.warn(enc_warn, path, 'utf-8')
|
||||
return False
|
||||
|
|
@ -523,7 +532,7 @@ class FileList(_FileList):
|
|||
|
||||
|
||||
class manifest_maker(sdist):
|
||||
template = "MANIFEST.in"
|
||||
template = 'MANIFEST.in'
|
||||
|
||||
def initialize_options(self):
|
||||
self.use_defaults = 1
|
||||
|
|
@ -572,7 +581,7 @@ class manifest_maker(sdist):
|
|||
"""
|
||||
suppress missing-file warnings from sdist
|
||||
"""
|
||||
return re.match(r"standard file .*not found", msg)
|
||||
return re.match(r'standard file .*not found', msg)
|
||||
|
||||
def add_defaults(self):
|
||||
sdist.add_defaults(self)
|
||||
|
|
@ -584,10 +593,10 @@ class manifest_maker(sdist):
|
|||
elif os.path.exists(self.manifest):
|
||||
self.read_manifest()
|
||||
|
||||
if os.path.exists("setup.py"):
|
||||
if os.path.exists('setup.py'):
|
||||
# setup.py should be included by default, even if it's not
|
||||
# the script called to create the sdist
|
||||
self.filelist.append("setup.py")
|
||||
self.filelist.append('setup.py')
|
||||
|
||||
ei_cmd = self.get_finalized_command('egg_info')
|
||||
self.filelist.graft(ei_cmd.egg_info)
|
||||
|
|
@ -605,25 +614,27 @@ class manifest_maker(sdist):
|
|||
self.filelist.prune(build.build_base)
|
||||
self.filelist.prune(base_dir)
|
||||
sep = re.escape(os.sep)
|
||||
self.filelist.exclude_pattern(r'(^|' + sep + r')(RCS|CVS|\.svn)' + sep,
|
||||
is_regex=1)
|
||||
self.filelist.exclude_pattern(
|
||||
r'(^|' + sep + r')(RCS|CVS|\.svn)' + sep,
|
||||
is_regex=1,
|
||||
)
|
||||
|
||||
|
||||
def write_file(filename, contents):
|
||||
"""Create a file with the specified name and write 'contents' (a
|
||||
sequence of strings without line terminators) to it.
|
||||
"""
|
||||
contents = "\n".join(contents)
|
||||
contents = '\n'.join(contents)
|
||||
|
||||
# assuming the contents has been vetted for utf-8 encoding
|
||||
contents = contents.encode("utf-8")
|
||||
contents = contents.encode('utf-8')
|
||||
|
||||
with open(filename, "wb") as f: # always write POSIX-style manifest
|
||||
with open(filename, 'wb') as f: # always write POSIX-style manifest
|
||||
f.write(contents)
|
||||
|
||||
|
||||
def write_pkg_info(cmd, basename, filename):
|
||||
log.info("writing %s", filename)
|
||||
log.info('writing %s', filename)
|
||||
if not cmd.dry_run:
|
||||
metadata = cmd.distribution.metadata
|
||||
metadata.version, oldver = cmd.egg_version, metadata.version
|
||||
|
|
@ -645,7 +656,7 @@ def warn_depends_obsolete(cmd, basename, filename):
|
|||
if os.path.exists(filename):
|
||||
log.warn(
|
||||
"WARNING: 'depends.txt' is not used by setuptools 0.6!\n"
|
||||
"Use the install_requires/extras_require setup() args instead."
|
||||
'Use the install_requires/extras_require setup() args instead.',
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -666,13 +677,13 @@ def write_requirements(cmd, basename, filename):
|
|||
for extra in sorted(extras_require):
|
||||
data.write('\n[{extra}]\n'.format(**vars()))
|
||||
_write_requirements(data, extras_require[extra])
|
||||
cmd.write_or_delete_file("requirements", filename, data.getvalue())
|
||||
cmd.write_or_delete_file('requirements', filename, data.getvalue())
|
||||
|
||||
|
||||
def write_setup_requirements(cmd, basename, filename):
|
||||
data = io.StringIO()
|
||||
_write_requirements(data, cmd.distribution.setup_requires)
|
||||
cmd.write_or_delete_file("setup-requirements", filename, data.getvalue())
|
||||
cmd.write_or_delete_file('setup-requirements', filename, data.getvalue())
|
||||
|
||||
|
||||
def write_toplevel_names(cmd, basename, filename):
|
||||
|
|
@ -680,9 +691,9 @@ def write_toplevel_names(cmd, basename, filename):
|
|||
[
|
||||
k.split('.', 1)[0]
|
||||
for k in cmd.distribution.iter_distribution_names()
|
||||
]
|
||||
],
|
||||
)
|
||||
cmd.write_file("top-level names", filename, '\n'.join(sorted(pkgs)) + '\n')
|
||||
cmd.write_file('top-level names', filename, '\n'.join(sorted(pkgs)) + '\n')
|
||||
|
||||
|
||||
def overwrite_arg(cmd, basename, filename):
|
||||
|
|
@ -708,7 +719,7 @@ def write_entries(cmd, basename, filename):
|
|||
if not isinstance(contents, str):
|
||||
contents = EntryPoint.parse_group(section, contents)
|
||||
contents = '\n'.join(sorted(map(str, contents.values())))
|
||||
data.append('[%s]\n%s\n\n' % (section, contents))
|
||||
data.append('[{}]\n{}\n\n'.format(section, contents))
|
||||
data = ''.join(data)
|
||||
|
||||
cmd.write_or_delete_file('entry points', filename, data, True)
|
||||
|
|
@ -720,11 +731,12 @@ def get_pkg_info_revision():
|
|||
a subversion revision.
|
||||
"""
|
||||
warnings.warn(
|
||||
"get_pkg_info_revision is deprecated.", EggInfoDeprecationWarning)
|
||||
'get_pkg_info_revision is deprecated.', EggInfoDeprecationWarning,
|
||||
)
|
||||
if os.path.exists('PKG-INFO'):
|
||||
with io.open('PKG-INFO') as f:
|
||||
with open('PKG-INFO') as f:
|
||||
for line in f:
|
||||
match = re.match(r"Version:.*-r(\d+)\s*$", line)
|
||||
match = re.match(r'Version:.*-r(\d+)\s*$', line)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
from distutils.errors import DistutilsArgError
|
||||
import inspect
|
||||
import glob
|
||||
import warnings
|
||||
import platform
|
||||
import distutils.command.install as orig
|
||||
from __future__ import annotations
|
||||
|
||||
import glob
|
||||
import inspect
|
||||
import platform
|
||||
import warnings
|
||||
|
||||
import distutils.command.install as orig
|
||||
import setuptools
|
||||
from distutils.errors import DistutilsArgError
|
||||
|
||||
# Prior to numpy 1.9, NumPy relies on the '_install' name, so provide it for
|
||||
# now. See https://github.com/pypa/setuptools/issues/199/
|
||||
|
|
@ -16,9 +18,11 @@ class install(orig.install):
|
|||
"""Use easy_install to install the package, w/dependencies"""
|
||||
|
||||
user_options = orig.install.user_options + [
|
||||
('old-and-unmanageable', None, "Try not to use this!"),
|
||||
('single-version-externally-managed', None,
|
||||
"used by system package builders to create 'flat' eggs"),
|
||||
('old-and-unmanageable', None, 'Try not to use this!'),
|
||||
(
|
||||
'single-version-externally-managed', None,
|
||||
"used by system package builders to create 'flat' eggs",
|
||||
),
|
||||
]
|
||||
boolean_options = orig.install.boolean_options + [
|
||||
'old-and-unmanageable', 'single-version-externally-managed',
|
||||
|
|
@ -41,8 +45,8 @@ class install(orig.install):
|
|||
elif self.single_version_externally_managed:
|
||||
if not self.root and not self.record:
|
||||
raise DistutilsArgError(
|
||||
"You must specify --record or --root when building system"
|
||||
" packages"
|
||||
'You must specify --record or --root when building system'
|
||||
' packages',
|
||||
)
|
||||
|
||||
def handle_extra_path(self):
|
||||
|
|
@ -78,10 +82,10 @@ class install(orig.install):
|
|||
is unavailable. Return False otherwise.
|
||||
"""
|
||||
if run_frame is None:
|
||||
msg = "Call stack not available. bdist_* commands may fail."
|
||||
msg = 'Call stack not available. bdist_* commands may fail.'
|
||||
warnings.warn(msg)
|
||||
if platform.python_implementation() == 'IronPython':
|
||||
msg = "For best results, pass -X:Frames to enable call stack."
|
||||
msg = 'For best results, pass -X:Frames to enable call stack.'
|
||||
warnings.warn(msg)
|
||||
return True
|
||||
res = inspect.getouterframes(run_frame)[2]
|
||||
|
|
@ -89,8 +93,8 @@ class install(orig.install):
|
|||
info = inspect.getframeinfo(caller)
|
||||
caller_module = caller.f_globals.get('__name__', '')
|
||||
return (
|
||||
caller_module == 'distutils.dist'
|
||||
and info.function == 'run_commands'
|
||||
caller_module == 'distutils.dist' and
|
||||
info.function == 'run_commands'
|
||||
)
|
||||
|
||||
def do_egg_install(self):
|
||||
|
|
@ -98,7 +102,7 @@ class install(orig.install):
|
|||
easy_install = self.distribution.get_command_class('easy_install')
|
||||
|
||||
cmd = easy_install(
|
||||
self.distribution, args="x", root=self.root, record=self.record,
|
||||
self.distribution, args='x', root=self.root, record=self.record,
|
||||
)
|
||||
cmd.ensure_finalized() # finalize before bdist_egg munges install cmd
|
||||
cmd.always_copy_from = '.' # make sure local-dir eggs get installed
|
||||
|
|
|
|||
|
|
@ -1,30 +1,35 @@
|
|||
from distutils import log, dir_util
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
import pkg_resources
|
||||
from distutils import dir_util
|
||||
from distutils import log
|
||||
from setuptools import Command
|
||||
from setuptools import namespaces
|
||||
from setuptools.archive_util import unpack_archive
|
||||
import pkg_resources
|
||||
|
||||
|
||||
class install_egg_info(namespaces.Installer, Command):
|
||||
"""Install an .egg-info directory for the package"""
|
||||
|
||||
description = "Install an .egg-info directory for the package"
|
||||
description = 'Install an .egg-info directory for the package'
|
||||
|
||||
user_options = [
|
||||
('install-dir=', 'd', "directory to install to"),
|
||||
('install-dir=', 'd', 'directory to install to'),
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
self.install_dir = None
|
||||
|
||||
def finalize_options(self):
|
||||
self.set_undefined_options('install_lib',
|
||||
('install_dir', 'install_dir'))
|
||||
ei_cmd = self.get_finalized_command("egg_info")
|
||||
self.set_undefined_options(
|
||||
'install_lib',
|
||||
('install_dir', 'install_dir'),
|
||||
)
|
||||
ei_cmd = self.get_finalized_command('egg_info')
|
||||
basename = pkg_resources.Distribution(
|
||||
None, None, ei_cmd.egg_name, ei_cmd.egg_version
|
||||
None, None, ei_cmd.egg_name, ei_cmd.egg_version,
|
||||
).egg_name() + '.egg-info'
|
||||
self.source = ei_cmd.egg_info
|
||||
self.target = os.path.join(self.install_dir, basename)
|
||||
|
|
@ -35,11 +40,11 @@ class install_egg_info(namespaces.Installer, Command):
|
|||
if os.path.isdir(self.target) and not os.path.islink(self.target):
|
||||
dir_util.remove_tree(self.target, dry_run=self.dry_run)
|
||||
elif os.path.exists(self.target):
|
||||
self.execute(os.unlink, (self.target,), "Removing " + self.target)
|
||||
self.execute(os.unlink, (self.target,), 'Removing ' + self.target)
|
||||
if not self.dry_run:
|
||||
pkg_resources.ensure_directory(self.target)
|
||||
self.execute(
|
||||
self.copytree, (), "Copying %s to %s" % (self.source, self.target)
|
||||
self.copytree, (), 'Copying {} to {}'.format(self.source, self.target),
|
||||
)
|
||||
self.install_namespaces()
|
||||
|
||||
|
|
@ -56,7 +61,7 @@ class install_egg_info(namespaces.Installer, Command):
|
|||
if src.startswith(skip) or '/' + skip in src:
|
||||
return None
|
||||
self.outputs.append(dst)
|
||||
log.debug("Copying %s to %s", src, dst)
|
||||
log.debug('Copying %s to %s', src, dst)
|
||||
return dst
|
||||
|
||||
unpack_archive(self.source, self.target, skimmer)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from itertools import product, starmap
|
||||
from itertools import product
|
||||
from itertools import starmap
|
||||
|
||||
import distutils.command.install_lib as orig
|
||||
|
||||
|
||||
|
|
@ -78,7 +82,8 @@ class install_lib(orig.install_lib):
|
|||
return
|
||||
|
||||
base = os.path.join(
|
||||
'__pycache__', '__init__.' + sys.implementation.cache_tag)
|
||||
'__pycache__', '__init__.' + sys.implementation.cache_tag,
|
||||
)
|
||||
yield base + '.pyc'
|
||||
yield base + '.pyo'
|
||||
yield base + '.opt-1.pyc'
|
||||
|
|
@ -86,7 +91,7 @@ class install_lib(orig.install_lib):
|
|||
|
||||
def copy_tree(
|
||||
self, infile, outfile,
|
||||
preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1
|
||||
preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1,
|
||||
):
|
||||
assert preserve_mode and preserve_times and not preserve_symlinks
|
||||
exclude = self.get_exclusions()
|
||||
|
|
@ -103,11 +108,13 @@ class install_lib(orig.install_lib):
|
|||
|
||||
def pf(src, dst):
|
||||
if dst in exclude:
|
||||
log.warn("Skipping installation of %s (namespace package)",
|
||||
dst)
|
||||
log.warn(
|
||||
'Skipping installation of %s (namespace package)',
|
||||
dst,
|
||||
)
|
||||
return False
|
||||
|
||||
log.info("copying %s -> %s", src, os.path.dirname(dst))
|
||||
log.info('copying %s -> %s', src, os.path.dirname(dst))
|
||||
outfiles.append(dst)
|
||||
return dst
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
from distutils import log
|
||||
import distutils.command.install_scripts as orig
|
||||
from distutils.errors import DistutilsModuleError
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pkg_resources import Distribution, PathMetadata, ensure_directory
|
||||
import distutils.command.install_scripts as orig
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsModuleError
|
||||
from pkg_resources import Distribution
|
||||
from pkg_resources import ensure_directory
|
||||
from pkg_resources import PathMetadata
|
||||
|
||||
|
||||
class install_scripts(orig.install_scripts):
|
||||
|
|
@ -17,7 +21,7 @@ class install_scripts(orig.install_scripts):
|
|||
def run(self):
|
||||
import setuptools.command.easy_install as ei
|
||||
|
||||
self.run_command("egg_info")
|
||||
self.run_command('egg_info')
|
||||
if self.distribution.scripts:
|
||||
orig.install_scripts.run(self) # run first to set up self.outfiles
|
||||
else:
|
||||
|
|
@ -26,7 +30,7 @@ class install_scripts(orig.install_scripts):
|
|||
# don't install entry point scripts into .egg file!
|
||||
return
|
||||
|
||||
ei_cmd = self.get_finalized_command("egg_info")
|
||||
ei_cmd = self.get_finalized_command('egg_info')
|
||||
dist = Distribution(
|
||||
ei_cmd.egg_base, PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),
|
||||
ei_cmd.egg_name, ei_cmd.egg_version,
|
||||
|
|
@ -34,13 +38,13 @@ class install_scripts(orig.install_scripts):
|
|||
bs_cmd = self.get_finalized_command('build_scripts')
|
||||
exec_param = getattr(bs_cmd, 'executable', None)
|
||||
try:
|
||||
bw_cmd = self.get_finalized_command("bdist_wininst")
|
||||
bw_cmd = self.get_finalized_command('bdist_wininst')
|
||||
is_wininst = getattr(bw_cmd, '_is_running', False)
|
||||
except (ImportError, DistutilsModuleError):
|
||||
is_wininst = False
|
||||
writer = ei.ScriptWriter
|
||||
if is_wininst:
|
||||
exec_param = "python.exe"
|
||||
exec_param = 'python.exe'
|
||||
writer = ei.WindowsScriptWriter
|
||||
if exec_param == sys.executable:
|
||||
# In case the path to the Python executable contains a space, wrap
|
||||
|
|
@ -52,18 +56,18 @@ class install_scripts(orig.install_scripts):
|
|||
for args in writer.get_args(dist, cmd.as_header()):
|
||||
self.write_script(*args)
|
||||
|
||||
def write_script(self, script_name, contents, mode="t", *ignored):
|
||||
def write_script(self, script_name, contents, mode='t', *ignored):
|
||||
"""Write an executable file to the scripts directory"""
|
||||
from setuptools.command.easy_install import chmod, current_umask
|
||||
|
||||
log.info("Installing %s script to %s", script_name, self.install_dir)
|
||||
log.info('Installing %s script to %s', script_name, self.install_dir)
|
||||
target = os.path.join(self.install_dir, script_name)
|
||||
self.outfiles.append(target)
|
||||
|
||||
mask = current_umask()
|
||||
if not self.dry_run:
|
||||
ensure_directory(target)
|
||||
f = open(target, "w" + mode)
|
||||
f = open(target, 'w' + mode)
|
||||
f.write(contents)
|
||||
f.close()
|
||||
chmod(target, 0o777 - mask)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from glob import glob
|
||||
from distutils.util import convert_path
|
||||
|
||||
from distutils.command import sdist
|
||||
from distutils.util import convert_path
|
||||
|
||||
|
||||
class sdist_add_defaults:
|
||||
|
|
@ -65,8 +68,10 @@ class sdist_add_defaults:
|
|||
break
|
||||
|
||||
if not got_it:
|
||||
self.warn("standard file not found: should have one of " +
|
||||
', '.join(alts))
|
||||
self.warn(
|
||||
'standard file not found: should have one of ' +
|
||||
', '.join(alts),
|
||||
)
|
||||
else:
|
||||
if self._cs_path_exists(fn):
|
||||
self.filelist.append(fn)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from distutils import log
|
||||
import distutils.command.register as orig
|
||||
from __future__ import annotations
|
||||
|
||||
import distutils.command.register as orig
|
||||
from distutils import log
|
||||
from setuptools.errors import RemovedCommandError
|
||||
|
||||
|
||||
|
|
@ -9,10 +10,10 @@ class register(orig.register):
|
|||
|
||||
def run(self):
|
||||
msg = (
|
||||
"The register command has been removed, use twine to upload "
|
||||
+ "instead (https://pypi.org/p/twine)"
|
||||
'The register command has been removed, use twine to upload ' +
|
||||
'instead (https://pypi.org/p/twine)'
|
||||
)
|
||||
|
||||
self.announce("ERROR: " + msg, log.ERROR)
|
||||
self.announce('ERROR: ' + msg, log.ERROR)
|
||||
|
||||
raise RemovedCommandError(msg)
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
from distutils.util import convert_path
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from distutils.util import convert_path
|
||||
from setuptools import Command
|
||||
|
||||
|
||||
class rotate(Command):
|
||||
"""Delete older distributions"""
|
||||
|
||||
description = "delete older distributions, keeping N newest files"
|
||||
description = 'delete older distributions, keeping N newest files'
|
||||
user_options = [
|
||||
('match=', 'm', "patterns to match (required)"),
|
||||
('dist-dir=', 'd', "directory where the distributions are"),
|
||||
('keep=', 'k', "number of matching distributions to keep"),
|
||||
('match=', 'm', 'patterns to match (required)'),
|
||||
('dist-dir=', 'd', 'directory where the distributions are'),
|
||||
('keep=', 'k', 'number of matching distributions to keep'),
|
||||
]
|
||||
|
||||
boolean_options = []
|
||||
|
|
@ -27,15 +29,15 @@ class rotate(Command):
|
|||
def finalize_options(self):
|
||||
if self.match is None:
|
||||
raise DistutilsOptionError(
|
||||
"Must specify one or more (comma-separated) match patterns "
|
||||
"(e.g. '.zip' or '.egg')"
|
||||
'Must specify one or more (comma-separated) match patterns '
|
||||
"(e.g. '.zip' or '.egg')",
|
||||
)
|
||||
if self.keep is None:
|
||||
raise DistutilsOptionError("Must specify number of files to keep")
|
||||
raise DistutilsOptionError('Must specify number of files to keep')
|
||||
try:
|
||||
self.keep = int(self.keep)
|
||||
except ValueError as e:
|
||||
raise DistutilsOptionError("--keep must be an integer") from e
|
||||
raise DistutilsOptionError('--keep must be an integer') from e
|
||||
if isinstance(self.match, str):
|
||||
self.match = [
|
||||
convert_path(p.strip()) for p in self.match.split(',')
|
||||
|
|
@ -43,7 +45,7 @@ class rotate(Command):
|
|||
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
|
||||
|
||||
def run(self):
|
||||
self.run_command("egg_info")
|
||||
self.run_command('egg_info')
|
||||
from glob import glob
|
||||
|
||||
for pattern in self.match:
|
||||
|
|
@ -53,10 +55,10 @@ class rotate(Command):
|
|||
files.sort()
|
||||
files.reverse()
|
||||
|
||||
log.info("%d file(s) matching %s", len(files), pattern)
|
||||
log.info('%d file(s) matching %s', len(files), pattern)
|
||||
files = files[self.keep:]
|
||||
for (t, f) in files:
|
||||
log.info("Deleting %s", f)
|
||||
log.info('Deleting %s', f)
|
||||
if not self.dry_run:
|
||||
if os.path.isdir(f):
|
||||
shutil.rmtree(f)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
from setuptools.command.setopt import edit_config, option_base
|
||||
from __future__ import annotations
|
||||
|
||||
from setuptools.command.setopt import edit_config
|
||||
from setuptools.command.setopt import option_base
|
||||
|
||||
|
||||
class saveopts(option_base):
|
||||
"""Save command-line options to a file"""
|
||||
|
||||
description = "save supplied options to setup.cfg or other config file"
|
||||
description = 'save supplied options to setup.cfg or other config file'
|
||||
|
||||
def run(self):
|
||||
dist = self.distribution
|
||||
|
|
@ -16,7 +19,7 @@ class saveopts(option_base):
|
|||
continue # don't save our own options!
|
||||
|
||||
for opt, (src, val) in dist.get_option_dict(cmd).items():
|
||||
if src == "command line":
|
||||
if src == 'command line':
|
||||
settings.setdefault(cmd, {})[opt] = val
|
||||
|
||||
edit_config(self.filename, settings, self.dry_run)
|
||||
|
|
|
|||
|
|
@ -1,42 +1,49 @@
|
|||
from distutils import log
|
||||
import distutils.command.sdist as orig
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import io
|
||||
import contextlib
|
||||
|
||||
import distutils.command.sdist as orig
|
||||
import pkg_resources
|
||||
from distutils import log
|
||||
|
||||
from .py36compat import sdist_add_defaults
|
||||
|
||||
import pkg_resources
|
||||
|
||||
_default_revctrl = list
|
||||
|
||||
|
||||
def walk_revctrl(dirname=''):
|
||||
"""Find all files under revision control"""
|
||||
for ep in pkg_resources.iter_entry_points('setuptools.file_finders'):
|
||||
for item in ep.load()(dirname):
|
||||
yield item
|
||||
yield from ep.load()(dirname)
|
||||
|
||||
|
||||
class sdist(sdist_add_defaults, orig.sdist):
|
||||
"""Smart sdist that finds anything supported by revision control"""
|
||||
|
||||
user_options = [
|
||||
('formats=', None,
|
||||
"formats for source distribution (comma-separated list)"),
|
||||
('keep-temp', 'k',
|
||||
"keep the distribution tree around after creating " +
|
||||
"archive file(s)"),
|
||||
('dist-dir=', 'd',
|
||||
"directory to put the source distribution archive(s) in "
|
||||
"[default: dist]"),
|
||||
(
|
||||
'formats=', None,
|
||||
'formats for source distribution (comma-separated list)',
|
||||
),
|
||||
(
|
||||
'keep-temp', 'k',
|
||||
'keep the distribution tree around after creating ' +
|
||||
'archive file(s)',
|
||||
),
|
||||
(
|
||||
'dist-dir=', 'd',
|
||||
'directory to put the source distribution archive(s) in '
|
||||
'[default: dist]',
|
||||
),
|
||||
]
|
||||
|
||||
negative_opt = {}
|
||||
|
||||
README_EXTENSIONS = ['', '.rst', '.txt', '.md']
|
||||
READMES = tuple('README{0}'.format(ext) for ext in README_EXTENSIONS)
|
||||
READMES = tuple(f'README{ext}' for ext in README_EXTENSIONS)
|
||||
|
||||
def run(self):
|
||||
self.run_command('egg_info')
|
||||
|
|
@ -132,7 +139,7 @@ class sdist(sdist_add_defaults, orig.sdist):
|
|||
try:
|
||||
super()._add_defaults_data_files()
|
||||
except TypeError:
|
||||
log.warn("data_files contains unexpected objects")
|
||||
log.warn('data_files contains unexpected objects')
|
||||
|
||||
def check_readme(self):
|
||||
for f in self.READMES:
|
||||
|
|
@ -140,8 +147,8 @@ class sdist(sdist_add_defaults, orig.sdist):
|
|||
return
|
||||
else:
|
||||
self.warn(
|
||||
"standard file not found: should have one of " +
|
||||
', '.join(self.READMES)
|
||||
'standard file not found: should have one of ' +
|
||||
', '.join(self.READMES),
|
||||
)
|
||||
|
||||
def make_release_tree(self, base_dir, files):
|
||||
|
|
@ -162,10 +169,12 @@ class sdist(sdist_add_defaults, orig.sdist):
|
|||
if not os.path.isfile(self.manifest):
|
||||
return False
|
||||
|
||||
with io.open(self.manifest, 'rb') as fp:
|
||||
with open(self.manifest, 'rb') as fp:
|
||||
first_line = fp.readline()
|
||||
return (first_line !=
|
||||
'# file GENERATED by distutils, do NOT edit\n'.encode())
|
||||
return (
|
||||
first_line !=
|
||||
b'# file GENERATED by distutils, do NOT edit\n'
|
||||
)
|
||||
|
||||
def read_manifest(self):
|
||||
"""Read the manifest file (named by 'self.manifest') and use it to
|
||||
|
|
@ -179,7 +188,7 @@ class sdist(sdist_add_defaults, orig.sdist):
|
|||
try:
|
||||
line = line.decode('UTF-8')
|
||||
except UnicodeDecodeError:
|
||||
log.warn("%r not UTF-8 decodable -- skipping" % line)
|
||||
log.warn('%r not UTF-8 decodable -- skipping' % line)
|
||||
continue
|
||||
# ignore comments and blank lines
|
||||
line = line.strip()
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
from distutils.util import convert_path
|
||||
from __future__ import annotations
|
||||
|
||||
import configparser
|
||||
import os
|
||||
|
||||
import distutils
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsOptionError
|
||||
import distutils
|
||||
import os
|
||||
import configparser
|
||||
|
||||
from distutils.util import convert_path
|
||||
from setuptools import Command
|
||||
|
||||
__all__ = ['config_file', 'edit_config', 'option_base', 'setopt']
|
||||
|
||||
|
||||
def config_file(kind="local"):
|
||||
def config_file(kind='local'):
|
||||
"""Get the filename of the distutils, local, global, or per-user config
|
||||
|
||||
`kind` must be one of "local", "global", or "user"
|
||||
|
|
@ -19,13 +21,13 @@ def config_file(kind="local"):
|
|||
return 'setup.cfg'
|
||||
if kind == 'global':
|
||||
return os.path.join(
|
||||
os.path.dirname(distutils.__file__), 'distutils.cfg'
|
||||
os.path.dirname(distutils.__file__), 'distutils.cfg',
|
||||
)
|
||||
if kind == 'user':
|
||||
dot = os.name == 'posix' and '.' or ''
|
||||
return os.path.expanduser(convert_path("~/%spydistutils.cfg" % dot))
|
||||
return os.path.expanduser(convert_path('~/%spydistutils.cfg' % dot))
|
||||
raise ValueError(
|
||||
"config_file() type must be 'local', 'global', or 'user'", kind
|
||||
"config_file() type must be 'local', 'global', or 'user'", kind,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -37,37 +39,39 @@ def edit_config(filename, settings, dry_run=False):
|
|||
while a dictionary lists settings to be changed or deleted in that section.
|
||||
A setting of ``None`` means to delete that setting.
|
||||
"""
|
||||
log.debug("Reading configuration from %s", filename)
|
||||
log.debug('Reading configuration from %s', filename)
|
||||
opts = configparser.RawConfigParser()
|
||||
opts.optionxform = lambda x: x
|
||||
opts.read([filename])
|
||||
for section, options in settings.items():
|
||||
if options is None:
|
||||
log.info("Deleting section [%s] from %s", section, filename)
|
||||
log.info('Deleting section [%s] from %s', section, filename)
|
||||
opts.remove_section(section)
|
||||
else:
|
||||
if not opts.has_section(section):
|
||||
log.debug("Adding new section [%s] to %s", section, filename)
|
||||
log.debug('Adding new section [%s] to %s', section, filename)
|
||||
opts.add_section(section)
|
||||
for option, value in options.items():
|
||||
if value is None:
|
||||
log.debug(
|
||||
"Deleting %s.%s from %s",
|
||||
section, option, filename
|
||||
'Deleting %s.%s from %s',
|
||||
section, option, filename,
|
||||
)
|
||||
opts.remove_option(section, option)
|
||||
if not opts.options(section):
|
||||
log.info("Deleting empty [%s] section from %s",
|
||||
section, filename)
|
||||
log.info(
|
||||
'Deleting empty [%s] section from %s',
|
||||
section, filename,
|
||||
)
|
||||
opts.remove_section(section)
|
||||
else:
|
||||
log.debug(
|
||||
"Setting %s.%s to %r in %s",
|
||||
section, option, value, filename
|
||||
'Setting %s.%s to %r in %s',
|
||||
section, option, value, filename,
|
||||
)
|
||||
opts.set(section, option, value)
|
||||
|
||||
log.info("Writing %s", filename)
|
||||
log.info('Writing %s', filename)
|
||||
if not dry_run:
|
||||
with open(filename, 'w') as f:
|
||||
opts.write(f)
|
||||
|
|
@ -77,12 +81,18 @@ class option_base(Command):
|
|||
"""Abstract base class for commands that mess with config files"""
|
||||
|
||||
user_options = [
|
||||
('global-config', 'g',
|
||||
"save options to the site-wide distutils.cfg file"),
|
||||
('user-config', 'u',
|
||||
"save options to the current user's pydistutils.cfg file"),
|
||||
('filename=', 'f',
|
||||
"configuration file to use (default=setup.cfg)"),
|
||||
(
|
||||
'global-config', 'g',
|
||||
'save options to the site-wide distutils.cfg file',
|
||||
),
|
||||
(
|
||||
'user-config', 'u',
|
||||
"save options to the current user's pydistutils.cfg file",
|
||||
),
|
||||
(
|
||||
'filename=', 'f',
|
||||
'configuration file to use (default=setup.cfg)',
|
||||
),
|
||||
]
|
||||
|
||||
boolean_options = [
|
||||
|
|
@ -106,8 +116,8 @@ class option_base(Command):
|
|||
filenames.append(config_file('local'))
|
||||
if len(filenames) > 1:
|
||||
raise DistutilsOptionError(
|
||||
"Must specify only one configuration file option",
|
||||
filenames
|
||||
'Must specify only one configuration file option',
|
||||
filenames,
|
||||
)
|
||||
self.filename, = filenames
|
||||
|
||||
|
|
@ -115,7 +125,7 @@ class option_base(Command):
|
|||
class setopt(option_base):
|
||||
"""Save command-line options to a file"""
|
||||
|
||||
description = "set an option in setup.cfg or another config file"
|
||||
description = 'set an option in setup.cfg or another config file'
|
||||
|
||||
user_options = [
|
||||
('command=', 'c', 'command to set an option for'),
|
||||
|
|
@ -136,14 +146,14 @@ class setopt(option_base):
|
|||
def finalize_options(self):
|
||||
option_base.finalize_options(self)
|
||||
if self.command is None or self.option is None:
|
||||
raise DistutilsOptionError("Must specify --command *and* --option")
|
||||
raise DistutilsOptionError('Must specify --command *and* --option')
|
||||
if self.set_value is None and not self.remove:
|
||||
raise DistutilsOptionError("Must specify --set-value or --remove")
|
||||
raise DistutilsOptionError('Must specify --set-value or --remove')
|
||||
|
||||
def run(self):
|
||||
edit_config(
|
||||
self.filename, {
|
||||
self.command: {self.option.replace('-', '_'): self.set_value}
|
||||
self.command: {self.option.replace('-', '_'): self.set_value},
|
||||
},
|
||||
self.dry_run
|
||||
self.dry_run,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,24 @@
|
|||
import os
|
||||
import operator
|
||||
import sys
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import itertools
|
||||
import operator
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from distutils.errors import DistutilsError, DistutilsOptionError
|
||||
from distutils import log
|
||||
from unittest import TestLoader
|
||||
|
||||
from pkg_resources import (
|
||||
resource_listdir,
|
||||
resource_exists,
|
||||
normalize_path,
|
||||
working_set,
|
||||
evaluate_marker,
|
||||
add_activation_listener,
|
||||
require,
|
||||
EntryPoint,
|
||||
)
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsError
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from pkg_resources import add_activation_listener
|
||||
from pkg_resources import EntryPoint
|
||||
from pkg_resources import evaluate_marker
|
||||
from pkg_resources import normalize_path
|
||||
from pkg_resources import require
|
||||
from pkg_resources import resource_exists
|
||||
from pkg_resources import resource_listdir
|
||||
from pkg_resources import working_set
|
||||
from setuptools import Command
|
||||
from setuptools.extern.more_itertools import unique_everseen
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ class ScanningLoader(TestLoader):
|
|||
tests = []
|
||||
tests.append(TestLoader.loadTestsFromModule(self, module))
|
||||
|
||||
if hasattr(module, "additional_tests"):
|
||||
if hasattr(module, 'additional_tests'):
|
||||
tests.append(module.additional_tests())
|
||||
|
||||
if hasattr(module, '__path__'):
|
||||
|
|
@ -75,7 +76,7 @@ class NonDataProperty:
|
|||
class test(Command):
|
||||
"""Command to run unit tests after in-place build"""
|
||||
|
||||
description = "run unit tests after in-place build (deprecated)"
|
||||
description = 'run unit tests after in-place build (deprecated)'
|
||||
|
||||
user_options = [
|
||||
('test-module=', 'm', "Run 'test_suite' in specified module"),
|
||||
|
|
@ -84,7 +85,7 @@ class test(Command):
|
|||
's',
|
||||
"Run single test, case or suite (e.g. 'module.test_suite')",
|
||||
),
|
||||
('test-runner=', 'r', "Test runner to use"),
|
||||
('test-runner=', 'r', 'Test runner to use'),
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
|
|
@ -96,19 +97,19 @@ class test(Command):
|
|||
def finalize_options(self):
|
||||
|
||||
if self.test_suite and self.test_module:
|
||||
msg = "You may specify a module or a suite, but not both"
|
||||
msg = 'You may specify a module or a suite, but not both'
|
||||
raise DistutilsOptionError(msg)
|
||||
|
||||
if self.test_suite is None:
|
||||
if self.test_module is None:
|
||||
self.test_suite = self.distribution.test_suite
|
||||
else:
|
||||
self.test_suite = self.test_module + ".test_suite"
|
||||
self.test_suite = self.test_module + '.test_suite'
|
||||
|
||||
if self.test_loader is None:
|
||||
self.test_loader = getattr(self.distribution, 'test_loader', None)
|
||||
if self.test_loader is None:
|
||||
self.test_loader = "setuptools.command.test:ScanningLoader"
|
||||
self.test_loader = 'setuptools.command.test:ScanningLoader'
|
||||
if self.test_runner is None:
|
||||
self.test_runner = getattr(self.distribution, 'test_runner', None)
|
||||
|
||||
|
|
@ -139,7 +140,7 @@ class test(Command):
|
|||
self.reinitialize_command('build_ext', inplace=1)
|
||||
self.run_command('build_ext')
|
||||
|
||||
ei_cmd = self.get_finalized_command("egg_info")
|
||||
ei_cmd = self.get_finalized_command('egg_info')
|
||||
|
||||
old_path = sys.path[:]
|
||||
old_modules = sys.modules.copy()
|
||||
|
|
@ -149,7 +150,7 @@ class test(Command):
|
|||
sys.path.insert(0, project_path)
|
||||
working_set.__init__()
|
||||
add_activation_listener(lambda dist: dist.activate())
|
||||
require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
|
||||
require('{}=={}'.format(ei_cmd.egg_name, ei_cmd.egg_version))
|
||||
with self.paths_on_pythonpath([project_path]):
|
||||
yield
|
||||
finally:
|
||||
|
|
@ -201,10 +202,10 @@ class test(Command):
|
|||
|
||||
def run(self):
|
||||
self.announce(
|
||||
"WARNING: Testing via this command is deprecated and will be "
|
||||
"removed in a future version. Users looking for a generic test "
|
||||
"entry point independent of test runner are encouraged to use "
|
||||
"tox.",
|
||||
'WARNING: Testing via this command is deprecated and will be '
|
||||
'removed in a future version. Users looking for a generic test '
|
||||
'entry point independent of test runner are encouraged to use '
|
||||
'tox.',
|
||||
log.WARN,
|
||||
)
|
||||
|
||||
|
|
@ -248,5 +249,5 @@ class test(Command):
|
|||
"""
|
||||
if val is None:
|
||||
return
|
||||
parsed = EntryPoint.parse("x=" + val)
|
||||
parsed = EntryPoint.parse('x=' + val)
|
||||
return parsed.resolve()()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from distutils import log
|
||||
from distutils.command import upload as orig
|
||||
|
||||
from setuptools.errors import RemovedCommandError
|
||||
|
||||
|
||||
|
|
@ -9,9 +10,9 @@ class upload(orig.upload):
|
|||
|
||||
def run(self):
|
||||
msg = (
|
||||
"The upload command has been removed, use twine to upload "
|
||||
+ "instead (https://pypi.org/p/twine)"
|
||||
'The upload command has been removed, use twine to upload ' +
|
||||
'instead (https://pypi.org/p/twine)'
|
||||
)
|
||||
|
||||
self.announce("ERROR: " + msg, log.ERROR)
|
||||
self.announce('ERROR: ' + msg, log.ERROR)
|
||||
raise RemovedCommandError(msg)
|
||||
|
|
|
|||
|
|
@ -1,24 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""upload_docs
|
||||
|
||||
Implements a Distutils 'upload_docs' subcommand (upload documentation to
|
||||
sites other than PyPi such as devpi).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from base64 import standard_b64encode
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsOptionError
|
||||
import os
|
||||
import socket
|
||||
import zipfile
|
||||
import tempfile
|
||||
import shutil
|
||||
import itertools
|
||||
import functools
|
||||
import http.client
|
||||
import itertools
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import tempfile
|
||||
import urllib.parse
|
||||
import zipfile
|
||||
from base64 import standard_b64encode
|
||||
|
||||
from distutils import log
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from pkg_resources import iter_entry_points
|
||||
|
||||
from .upload import upload
|
||||
|
||||
|
||||
|
|
@ -34,10 +35,14 @@ class upload_docs(upload):
|
|||
description = 'Upload documentation to sites other than PyPi such as devpi'
|
||||
|
||||
user_options = [
|
||||
('repository=', 'r',
|
||||
"url of repository [default: %s]" % upload.DEFAULT_REPOSITORY),
|
||||
('show-response', None,
|
||||
'display full response text from server'),
|
||||
(
|
||||
'repository=', 'r',
|
||||
'url of repository [default: %s]' % upload.DEFAULT_REPOSITORY,
|
||||
),
|
||||
(
|
||||
'show-response', None,
|
||||
'display full response text from server',
|
||||
),
|
||||
('upload-dir=', None, 'directory to upload'),
|
||||
]
|
||||
boolean_options = upload.boolean_options
|
||||
|
|
@ -67,11 +72,11 @@ class upload_docs(upload):
|
|||
self.ensure_dirname('upload_dir')
|
||||
self.target_dir = self.upload_dir
|
||||
if 'pypi.python.org' in self.repository:
|
||||
log.warn("Upload_docs command is deprecated for PyPi. Use RTD instead.")
|
||||
log.warn('Upload_docs command is deprecated for PyPi. Use RTD instead.')
|
||||
self.announce('Using upload directory %s' % self.target_dir)
|
||||
|
||||
def create_zipfile(self, filename):
|
||||
zip_file = zipfile.ZipFile(filename, "w")
|
||||
zip_file = zipfile.ZipFile(filename, 'w')
|
||||
try:
|
||||
self.mkpath(self.target_dir) # just in case
|
||||
for root, dirs, files in os.walk(self.target_dir):
|
||||
|
|
@ -93,7 +98,7 @@ class upload_docs(upload):
|
|||
|
||||
tmp_dir = tempfile.mkdtemp()
|
||||
name = self.distribution.metadata.get_name()
|
||||
zip_file = os.path.join(tmp_dir, "%s.zip" % name)
|
||||
zip_file = os.path.join(tmp_dir, '%s.zip' % name)
|
||||
try:
|
||||
self.create_zipfile(zip_file)
|
||||
self.upload_file(zip_file)
|
||||
|
|
@ -115,7 +120,7 @@ class upload_docs(upload):
|
|||
value = _encode(value)
|
||||
yield sep_boundary
|
||||
yield _encode(title)
|
||||
yield b"\n\n"
|
||||
yield b'\n\n'
|
||||
yield value
|
||||
if value and value[-1:] == b'\r':
|
||||
yield b'\n' # write an extra newline (lurve Macs)
|
||||
|
|
@ -128,7 +133,7 @@ class upload_docs(upload):
|
|||
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
|
||||
sep_boundary = b'\n--' + boundary.encode('ascii')
|
||||
end_boundary = sep_boundary + b'--'
|
||||
end_items = end_boundary, b"\n",
|
||||
end_items = end_boundary, b'\n',
|
||||
builder = functools.partial(
|
||||
cls._build_part,
|
||||
sep_boundary=sep_boundary,
|
||||
|
|
@ -151,11 +156,11 @@ class upload_docs(upload):
|
|||
# set up the authentication
|
||||
credentials = _encode(self.username + ':' + self.password)
|
||||
credentials = standard_b64encode(credentials).decode('ascii')
|
||||
auth = "Basic " + credentials
|
||||
auth = 'Basic ' + credentials
|
||||
|
||||
body, ct = self._build_multipart(data)
|
||||
|
||||
msg = "Submitting documentation to %s" % (self.repository)
|
||||
msg = 'Submitting documentation to %s' % (self.repository)
|
||||
self.announce(msg, log.INFO)
|
||||
|
||||
# build the Request
|
||||
|
|
@ -169,25 +174,25 @@ class upload_docs(upload):
|
|||
elif schema == 'https':
|
||||
conn = http.client.HTTPSConnection(netloc)
|
||||
else:
|
||||
raise AssertionError("unsupported schema " + schema)
|
||||
raise AssertionError('unsupported schema ' + schema)
|
||||
|
||||
data = ''
|
||||
try:
|
||||
conn.connect()
|
||||
conn.putrequest("POST", url)
|
||||
conn.putrequest('POST', url)
|
||||
content_type = ct
|
||||
conn.putheader('Content-type', content_type)
|
||||
conn.putheader('Content-length', str(len(body)))
|
||||
conn.putheader('Authorization', auth)
|
||||
conn.endheaders()
|
||||
conn.send(body)
|
||||
except socket.error as e:
|
||||
except OSError as e:
|
||||
self.announce(str(e), log.ERROR)
|
||||
return
|
||||
|
||||
r = conn.getresponse()
|
||||
if r.status == 200:
|
||||
msg = 'Server response (%s): %s' % (r.status, r.reason)
|
||||
msg = 'Server response ({}): {}'.format(r.status, r.reason)
|
||||
self.announce(msg, log.INFO)
|
||||
elif r.status == 301:
|
||||
location = r.getheader('Location')
|
||||
|
|
@ -196,7 +201,7 @@ class upload_docs(upload):
|
|||
msg = 'Upload successful. Visit %s' % location
|
||||
self.announce(msg, log.INFO)
|
||||
else:
|
||||
msg = 'Upload failed (%s): %s' % (r.status, r.reason)
|
||||
msg = 'Upload failed ({}): {}'.format(r.status, r.reason)
|
||||
self.announce(msg, log.ERROR)
|
||||
if self.show_response:
|
||||
print('-' * 75, r.read(), '-' * 75)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue