更改enroll命名,添加了注释,向get_error_msg中添加了一些错误代码

This commit is contained in:
ygm1881
2022-05-05 22:59:35 +08:00
parent 51b5e374a3
commit ece69eaf57
4637 changed files with 7699 additions and 608140 deletions
+39 -102
View File
@@ -19,7 +19,6 @@ from glob import iglob
import itertools
import textwrap
from typing import List, Optional, TYPE_CHECKING
from pathlib import Path
from collections import defaultdict
from email import message_from_file
@@ -29,10 +28,7 @@ from distutils.util import rfc822_escape
from setuptools.extern import packaging
from setuptools.extern import ordered_set
from setuptools.extern.more_itertools import unique_everseen, partition
from setuptools.extern import nspektr
from ._importlib import metadata
from setuptools.extern.more_itertools import unique_everseen
from . import SetuptoolsDeprecationWarning
@@ -40,13 +36,9 @@ import setuptools
import setuptools.command
from setuptools import windows_support
from setuptools.monkey import get_unpatched
from setuptools.config import setupcfg, pyprojecttoml
from setuptools.discovery import ConfigDiscovery
from setuptools.config import parse_configuration
import pkg_resources
from setuptools.extern.packaging import version
from . import _reqs
from . import _entry_points
if TYPE_CHECKING:
from email.message import Message
@@ -121,9 +113,13 @@ def read_pkg_file(self, file):
self.author_email = _read_field_from_msg(msg, 'author-email')
self.maintainer_email = None
self.url = _read_field_from_msg(msg, 'home-page')
self.download_url = _read_field_from_msg(msg, 'download-url')
self.license = _read_field_unescaped_from_msg(msg, 'license')
if 'download-url' in msg:
self.download_url = _read_field_from_msg(msg, 'download-url')
else:
self.download_url = None
self.long_description = _read_field_unescaped_from_msg(msg, 'description')
if (
self.long_description is None and
@@ -175,10 +171,9 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
write_field('Name', self.get_name())
write_field('Version', self.get_version())
write_field('Summary', single_line(self.get_description()))
write_field('Home-page', self.get_url())
optional_fields = (
('Home-page', 'url'),
('Download-URL', 'download_url'),
('Author', 'author'),
('Author-email', 'author_email'),
('Maintainer', 'maintainer'),
@@ -192,6 +187,8 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
license = rfc822_escape(self.get_license())
write_field('License', license)
if self.download_url:
write_field('Download-URL', self.download_url)
for project_url in self.project_urls.items():
write_field('Project-URL', '%s, %s' % project_url)
@@ -230,7 +227,7 @@ sequence = tuple, list
def check_importable(dist, attr, value):
try:
ep = metadata.EntryPoint(value=value, name=None, group=None)
ep = pkg_resources.EntryPoint.parse('x=' + value)
assert not ep.extras
except (TypeError, ValueError, AttributeError, AssertionError) as e:
raise DistutilsSetupError(
@@ -288,7 +285,7 @@ def _check_extra(extra, reqs):
name, sep, marker = extra.partition(':')
if marker and pkg_resources.invalid_marker(marker):
raise DistutilsSetupError("Invalid environment marker: " + marker)
list(_reqs.parse(reqs))
list(pkg_resources.parse_requirements(reqs))
def assert_bool(dist, attr, value):
@@ -308,7 +305,7 @@ def invalid_unless_false(dist, attr, value):
def check_requirements(dist, attr, value):
"""Verify that install_requires is a valid requirements list"""
try:
list(_reqs.parse(value))
list(pkg_resources.parse_requirements(value))
if isinstance(value, (dict, set)):
raise TypeError("Unordered types are not allowed")
except (TypeError, ValueError) as error:
@@ -333,8 +330,8 @@ def check_specifier(dist, attr, value):
def check_entry_points(dist, attr, value):
"""Verify that entry_points map is parseable"""
try:
_entry_points.load(value)
except Exception as e:
pkg_resources.EntryPoint.parse_map(value)
except ValueError as e:
raise DistutilsSetupError(e) from e
@@ -457,7 +454,7 @@ class Distribution(_Distribution):
self.patch_missing_pkg_info(attrs)
self.dependency_links = attrs.pop('dependency_links', [])
self.setup_requires = attrs.pop('setup_requires', [])
for ep in metadata.entry_points(group='distutils.setup_keywords'):
for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
vars(self).setdefault(ep.name, None)
_Distribution.__init__(
self,
@@ -468,13 +465,6 @@ class Distribution(_Distribution):
},
)
# Save the original dependencies before they are processed into the egg format
self._orig_extras_require = {}
self._orig_install_requires = []
self._tmp_extras_require = defaultdict(ordered_set.OrderedSet)
self.set_defaults = ConfigDiscovery(self)
self._set_metadata_defaults(attrs)
self.metadata.version = self._normalize_version(
@@ -482,19 +472,6 @@ class Distribution(_Distribution):
)
self._finalize_requires()
def _validate_metadata(self):
required = {"name"}
provided = {
key
for key in vars(self.metadata)
if getattr(self.metadata, key, None) is not None
}
missing = required - provided
if missing:
msg = f"Required package metadata is missing: {missing}"
raise DistutilsSetupError(msg)
def _set_metadata_defaults(self, attrs):
"""
Fill-in missing metadata fields not supported by distutils.
@@ -545,8 +522,6 @@ class Distribution(_Distribution):
self.metadata.python_requires = self.python_requires
if getattr(self, 'extras_require', None):
# Save original before it is messed by _convert_extras_requirements
self._orig_extras_require = self._orig_extras_require or self.extras_require
for extra in self.extras_require.keys():
# Since this gets called multiple times at points where the
# keys have become 'converted' extras, ensure that we are only
@@ -555,10 +530,6 @@ class Distribution(_Distribution):
if extra:
self.metadata.provides_extras.add(extra)
if getattr(self, 'install_requires', None) and not self._orig_install_requires:
# Save original before it is messed by _move_install_requirements_markers
self._orig_install_requires = self.install_requires
self._convert_extras_requirements()
self._move_install_requirements_markers()
@@ -569,12 +540,11 @@ class Distribution(_Distribution):
`"extra:{marker}": ["barbazquux"]`.
"""
spec_ext_reqs = getattr(self, 'extras_require', None) or {}
tmp = defaultdict(ordered_set.OrderedSet)
self._tmp_extras_require = getattr(self, '_tmp_extras_require', tmp)
self._tmp_extras_require = defaultdict(list)
for section, v in spec_ext_reqs.items():
# Do not strip empty sections.
self._tmp_extras_require[section]
for r in _reqs.parse(v):
for r in pkg_resources.parse_requirements(v):
suffix = self._suffix_for(r)
self._tmp_extras_require[section + suffix].append(r)
@@ -600,7 +570,7 @@ class Distribution(_Distribution):
return not req.marker
spec_inst_reqs = getattr(self, 'install_requires', None) or ()
inst_reqs = list(_reqs.parse(spec_inst_reqs))
inst_reqs = list(pkg_resources.parse_requirements(spec_inst_reqs))
simple_reqs = filter(is_simple_req, inst_reqs)
complex_reqs = itertools.filterfalse(is_simple_req, inst_reqs)
self.install_requires = list(map(str, simple_reqs))
@@ -608,8 +578,7 @@ class Distribution(_Distribution):
for r in complex_reqs:
self._tmp_extras_require[':' + str(r.marker)].append(r)
self.extras_require = dict(
# list(dict.fromkeys(...)) ensures a list of unique strings
(k, list(dict.fromkeys(str(r) for r in map(self._clean_req, v))))
(k, [str(r) for r in map(self._clean_req, v)])
for k, v in self._tmp_extras_require.items()
)
@@ -742,10 +711,7 @@ class Distribution(_Distribution):
return opt
underscore_opt = opt.replace('-', '_')
commands = list(itertools.chain(
distutils.command.__all__,
self._setuptools_commands(),
))
commands = distutils.command.__all__ + self._setuptools_commands()
if (
not section.startswith('options')
and section != 'metadata'
@@ -763,8 +729,9 @@ class Distribution(_Distribution):
def _setuptools_commands(self):
try:
return metadata.distribution('setuptools').entry_points.names
except metadata.PackageNotFoundError:
dist = pkg_resources.get_distribution('setuptools')
return list(dist.get_entry_map('distutils.commands'))
except pkg_resources.DistributionNotFound:
# during bootstrapping, distribution doesn't exist
return []
@@ -827,39 +794,23 @@ class Distribution(_Distribution):
except ValueError as e:
raise DistutilsOptionError(e) from e
def _get_project_config_files(self, filenames):
"""Add default file and split between INI and TOML"""
tomlfiles = []
standard_project_metadata = Path(self.src_root or os.curdir, "pyproject.toml")
if filenames is not None:
parts = partition(lambda f: Path(f).suffix == ".toml", filenames)
filenames = list(parts[0]) # 1st element => predicate is False
tomlfiles = list(parts[1]) # 2nd element => predicate is True
elif standard_project_metadata.exists():
tomlfiles = [standard_project_metadata]
return filenames, tomlfiles
def parse_config_files(self, filenames=None, ignore_option_errors=False):
"""Parses configuration files from various levels
and loads configuration.
"""
inifiles, tomlfiles = self._get_project_config_files(filenames)
self._parse_config_files(filenames=filenames)
self._parse_config_files(filenames=inifiles)
setupcfg.parse_configuration(
parse_configuration(
self, self.command_options, ignore_option_errors=ignore_option_errors
)
for filename in tomlfiles:
pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
self._finalize_requires()
self._finalize_license_files()
def fetch_build_eggs(self, requires):
"""Resolve pre-setup requirements"""
resolved_dists = pkg_resources.working_set.resolve(
_reqs.parse(requires),
pkg_resources.parse_requirements(requires),
installer=self.fetch_build_egg,
replace_conflicting=True,
)
@@ -879,7 +830,7 @@ class Distribution(_Distribution):
def by_order(hook):
return getattr(hook, 'order', 0)
defined = metadata.entry_points(group=group)
defined = pkg_resources.iter_entry_points(group)
filtered = itertools.filterfalse(self._removed, defined)
loaded = map(lambda e: e.load(), filtered)
for ep in sorted(loaded, key=by_order):
@@ -900,21 +851,12 @@ class Distribution(_Distribution):
return ep.name in removed
def _finalize_setup_keywords(self):
for ep in metadata.entry_points(group='distutils.setup_keywords'):
for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
value = getattr(self, ep.name, None)
if value is not None:
self._install_dependencies(ep)
ep.require(installer=self.fetch_build_egg)
ep.load()(self, ep.name, value)
def _install_dependencies(self, ep):
"""
Given an entry point, ensure that any declared extras for
its distribution are installed.
"""
for req in nspektr.missing(ep):
# fetch_build_egg expects pkg_resources.Requirement
self.fetch_build_egg(pkg_resources.Requirement(str(req)))
def get_egg_cache_dir(self):
egg_cache_dir = os.path.join(os.curdir, '.eggs')
if not os.path.exists(egg_cache_dir):
@@ -945,25 +887,27 @@ class Distribution(_Distribution):
if command in self.cmdclass:
return self.cmdclass[command]
eps = metadata.entry_points(group='distutils.commands', name=command)
eps = pkg_resources.iter_entry_points('distutils.commands', command)
for ep in eps:
self._install_dependencies(ep)
ep.require(installer=self.fetch_build_egg)
self.cmdclass[command] = cmdclass = ep.load()
return cmdclass
else:
return _Distribution.get_command_class(self, command)
def print_commands(self):
for ep in metadata.entry_points(group='distutils.commands'):
for ep in pkg_resources.iter_entry_points('distutils.commands'):
if ep.name not in self.cmdclass:
cmdclass = ep.load()
# don't require extras as the commands won't be invoked
cmdclass = ep.resolve()
self.cmdclass[ep.name] = cmdclass
return _Distribution.print_commands(self)
def get_command_list(self):
for ep in metadata.entry_points(group='distutils.commands'):
for ep in pkg_resources.iter_entry_points('distutils.commands'):
if ep.name not in self.cmdclass:
cmdclass = ep.load()
# don't require extras as the commands won't be invoked
cmdclass = ep.resolve()
self.cmdclass[ep.name] = cmdclass
return _Distribution.get_command_list(self)
@@ -1206,13 +1150,6 @@ class Distribution(_Distribution):
sys.stdout.detach(), encoding, errors, newline, line_buffering
)
def run_command(self, command):
self.set_defaults()
# Postpone defaults until all explicit configuration is considered
# (setup() args, config files, command line and plugins)
super().run_command(command)
class DistDeprecationWarning(SetuptoolsDeprecationWarning):
"""Class for warning about deprecations in dist in