mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-11 05:44:16 +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,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue