更改enroll命名,添加了注释,向get_error_msg中添加了一些错误代码
This commit is contained in:
@@ -39,10 +39,9 @@ import subprocess
|
||||
import shlex
|
||||
import io
|
||||
import configparser
|
||||
import sysconfig
|
||||
|
||||
|
||||
from sysconfig import get_path
|
||||
from sysconfig import get_config_vars, get_path
|
||||
|
||||
from setuptools import SetuptoolsDeprecationWarning
|
||||
|
||||
@@ -56,21 +55,18 @@ from setuptools.package_index import (
|
||||
from setuptools.command import bdist_egg, egg_info
|
||||
from setuptools.wheel import Wheel
|
||||
from pkg_resources import (
|
||||
normalize_path, resource_string,
|
||||
yield_lines, normalize_path, resource_string, ensure_directory,
|
||||
get_distribution, find_distributions, Environment, Requirement,
|
||||
Distribution, PathMetadata, EggMetadata, WorkingSet, DistributionNotFound,
|
||||
VersionConflict, DEVELOP_DIST,
|
||||
)
|
||||
import pkg_resources
|
||||
from .._path import ensure_directory
|
||||
from ..extern.jaraco.text import yield_lines
|
||||
|
||||
|
||||
# Turn on PEP440Warnings
|
||||
warnings.filterwarnings("default", category=pkg_resources.PEP440Warning)
|
||||
|
||||
__all__ = [
|
||||
'easy_install', 'PthDistributions', 'extract_wininst_cfg',
|
||||
'samefile', 'easy_install', 'PthDistributions', 'extract_wininst_cfg',
|
||||
'get_exe_prefixes',
|
||||
]
|
||||
|
||||
@@ -79,6 +75,22 @@ def is_64bit():
|
||||
return struct.calcsize("P") == 8
|
||||
|
||||
|
||||
def samefile(p1, p2):
|
||||
"""
|
||||
Determine if two paths reference the same file.
|
||||
|
||||
Augments os.path.samefile to work on Windows and
|
||||
suppresses errors if the path doesn't exist.
|
||||
"""
|
||||
both_exist = os.path.exists(p1) and os.path.exists(p2)
|
||||
use_samefile = hasattr(os.path, 'samefile') and both_exist
|
||||
if use_samefile:
|
||||
return os.path.samefile(p1, p2)
|
||||
norm_p1 = os.path.normpath(os.path.normcase(p1))
|
||||
norm_p2 = os.path.normpath(os.path.normcase(p2))
|
||||
return norm_p1 == norm_p2
|
||||
|
||||
|
||||
def _to_bytes(s):
|
||||
return s.encode('utf8')
|
||||
|
||||
@@ -169,8 +181,12 @@ class easy_install(Command):
|
||||
self.install_data = None
|
||||
self.install_base = None
|
||||
self.install_platbase = None
|
||||
self.install_userbase = site.USER_BASE
|
||||
self.install_usersite = site.USER_SITE
|
||||
if site.ENABLE_USER_SITE:
|
||||
self.install_userbase = site.USER_BASE
|
||||
self.install_usersite = site.USER_SITE
|
||||
else:
|
||||
self.install_userbase = None
|
||||
self.install_usersite = None
|
||||
self.no_find_links = None
|
||||
|
||||
# Options not specifiable via command line
|
||||
@@ -220,22 +236,23 @@ class easy_install(Command):
|
||||
self.version and self._render_version()
|
||||
|
||||
py_version = sys.version.split()[0]
|
||||
prefix, exec_prefix = get_config_vars('prefix', 'exec_prefix')
|
||||
|
||||
self.config_vars = dict(sysconfig.get_config_vars())
|
||||
|
||||
self.config_vars.update({
|
||||
self.config_vars = {
|
||||
'dist_name': self.distribution.get_name(),
|
||||
'dist_version': self.distribution.get_version(),
|
||||
'dist_fullname': self.distribution.get_fullname(),
|
||||
'py_version': py_version,
|
||||
'py_version_short': f'{sys.version_info.major}.{sys.version_info.minor}',
|
||||
'py_version_nodot': f'{sys.version_info.major}{sys.version_info.minor}',
|
||||
'sys_prefix': self.config_vars['prefix'],
|
||||
'sys_exec_prefix': self.config_vars['exec_prefix'],
|
||||
'py_version_short': py_version[0:3],
|
||||
'py_version_nodot': py_version[0] + py_version[2],
|
||||
'sys_prefix': prefix,
|
||||
'prefix': prefix,
|
||||
'sys_exec_prefix': exec_prefix,
|
||||
'exec_prefix': exec_prefix,
|
||||
# Only python 3.2+ has abiflags
|
||||
'abiflags': getattr(sys, 'abiflags', ''),
|
||||
'platlibdir': getattr(sys, 'platlibdir', 'lib'),
|
||||
})
|
||||
}
|
||||
with contextlib.suppress(AttributeError):
|
||||
# only for distutils outside stdlib
|
||||
self.config_vars.update({
|
||||
@@ -243,15 +260,11 @@ class easy_install(Command):
|
||||
'implementation': install._get_implementation(),
|
||||
})
|
||||
|
||||
# pypa/distutils#113 Python 3.9 compat
|
||||
self.config_vars.setdefault(
|
||||
'py_version_nodot_plat',
|
||||
getattr(sys, 'windir', '').replace('.', ''),
|
||||
)
|
||||
if site.ENABLE_USER_SITE:
|
||||
self.config_vars['userbase'] = self.install_userbase
|
||||
self.config_vars['usersite'] = self.install_usersite
|
||||
|
||||
self.config_vars['userbase'] = self.install_userbase
|
||||
self.config_vars['usersite'] = self.install_usersite
|
||||
if self.user and not site.ENABLE_USER_SITE:
|
||||
elif self.user:
|
||||
log.warn("WARNING: The user site-packages directory is disabled.")
|
||||
|
||||
self._fix_install_dir_for_user_site()
|
||||
@@ -287,14 +300,27 @@ class easy_install(Command):
|
||||
self.script_dir = self.install_scripts
|
||||
# default --record from the install command
|
||||
self.set_undefined_options('install', ('record', 'record'))
|
||||
# Should this be moved to the if statement below? It's not used
|
||||
# elsewhere
|
||||
normpath = map(normalize_path, sys.path)
|
||||
self.all_site_dirs = get_site_dirs()
|
||||
self.all_site_dirs.extend(self._process_site_dirs(self.site_dirs))
|
||||
|
||||
if self.site_dirs is not None:
|
||||
site_dirs = [
|
||||
os.path.expanduser(s.strip()) for s in
|
||||
self.site_dirs.split(',')
|
||||
]
|
||||
for d in site_dirs:
|
||||
if not os.path.isdir(d):
|
||||
log.warn("%s (in --site-dirs) does not exist", d)
|
||||
elif normalize_path(d) not in normpath:
|
||||
raise DistutilsOptionError(
|
||||
d + " (in --site-dirs) is not on sys.path"
|
||||
)
|
||||
else:
|
||||
self.all_site_dirs.append(normalize_path(d))
|
||||
if not self.editable:
|
||||
self.check_site_dir()
|
||||
default_index = os.getenv("__EASYINSTALL_INDEX", "https://pypi.org/simple/")
|
||||
# ^ Private API for testing purposes only
|
||||
self.index_url = self.index_url or default_index
|
||||
self.index_url = self.index_url or "https://pypi.org/simple/"
|
||||
self.shadow_path = self.all_site_dirs[:]
|
||||
for path_item in self.install_dir, normalize_path(self.script_dir):
|
||||
if path_item not in self.shadow_path:
|
||||
@@ -320,7 +346,15 @@ class easy_install(Command):
|
||||
if not self.no_find_links:
|
||||
self.package_index.add_find_links(self.find_links)
|
||||
self.set_undefined_options('install_lib', ('optimize', 'optimize'))
|
||||
self.optimize = self._validate_optimize(self.optimize)
|
||||
if not isinstance(self.optimize, int):
|
||||
try:
|
||||
self.optimize = int(self.optimize)
|
||||
if not (0 <= self.optimize <= 2):
|
||||
raise ValueError
|
||||
except ValueError as e:
|
||||
raise DistutilsOptionError(
|
||||
"--optimize must be 0, 1, or 2"
|
||||
) from e
|
||||
|
||||
if self.editable and not self.build_directory:
|
||||
raise DistutilsArgError(
|
||||
@@ -332,44 +366,11 @@ class easy_install(Command):
|
||||
|
||||
self.outputs = []
|
||||
|
||||
@staticmethod
|
||||
def _process_site_dirs(site_dirs):
|
||||
if site_dirs is None:
|
||||
return
|
||||
|
||||
normpath = map(normalize_path, sys.path)
|
||||
site_dirs = [
|
||||
os.path.expanduser(s.strip()) for s in
|
||||
site_dirs.split(',')
|
||||
]
|
||||
for d in site_dirs:
|
||||
if not os.path.isdir(d):
|
||||
log.warn("%s (in --site-dirs) does not exist", d)
|
||||
elif normalize_path(d) not in normpath:
|
||||
raise DistutilsOptionError(
|
||||
d + " (in --site-dirs) is not on sys.path"
|
||||
)
|
||||
else:
|
||||
yield normalize_path(d)
|
||||
|
||||
@staticmethod
|
||||
def _validate_optimize(value):
|
||||
try:
|
||||
value = int(value)
|
||||
if value not in range(3):
|
||||
raise ValueError
|
||||
except ValueError as e:
|
||||
raise DistutilsOptionError(
|
||||
"--optimize must be 0, 1, or 2"
|
||||
) from e
|
||||
|
||||
return value
|
||||
|
||||
def _fix_install_dir_for_user_site(self):
|
||||
"""
|
||||
Fix the install_dir if "--user" was used.
|
||||
"""
|
||||
if not self.user:
|
||||
if not self.user or not site.ENABLE_USER_SITE:
|
||||
return
|
||||
|
||||
self.create_home_path()
|
||||
@@ -918,9 +919,7 @@ class easy_install(Command):
|
||||
ensure_directory(destination)
|
||||
|
||||
dist = self.egg_distribution(egg_path)
|
||||
if not (
|
||||
os.path.exists(destination) and os.path.samefile(egg_path, destination)
|
||||
):
|
||||
if not samefile(egg_path, destination):
|
||||
if os.path.isdir(destination) and not os.path.islink(destination):
|
||||
dir_util.remove_tree(destination, dry_run=self.dry_run)
|
||||
elif os.path.exists(destination):
|
||||
@@ -1329,7 +1328,7 @@ class easy_install(Command):
|
||||
if not self.user:
|
||||
return
|
||||
home = convert_path(os.path.expanduser("~"))
|
||||
for path in only_strs(self.config_vars.values()):
|
||||
for name, path in self.config_vars.items():
|
||||
if path.startswith(home) and not os.path.isdir(path):
|
||||
self.debug_print("os.makedirs('%s', 0o700)" % path)
|
||||
os.makedirs(path, 0o700)
|
||||
@@ -1351,7 +1350,7 @@ class easy_install(Command):
|
||||
|
||||
if self.prefix:
|
||||
# Set default install_dir/scripts from --prefix
|
||||
config_vars = dict(config_vars)
|
||||
config_vars = config_vars.copy()
|
||||
config_vars['base'] = self.prefix
|
||||
scheme = self.INSTALL_SCHEMES.get(os.name, self.DEFAULT_SCHEME)
|
||||
for attr, val in scheme.items():
|
||||
@@ -1578,7 +1577,7 @@ class PthDistributions(Environment):
|
||||
self.sitedirs = list(map(normalize_path, sitedirs))
|
||||
self.basedir = normalize_path(os.path.dirname(self.filename))
|
||||
self._load()
|
||||
super().__init__([], None, None)
|
||||
Environment.__init__(self, [], None, None)
|
||||
for path in yield_lines(self.paths):
|
||||
list(map(self.add, find_distributions(path, True)))
|
||||
|
||||
@@ -1651,14 +1650,14 @@ class PthDistributions(Environment):
|
||||
if new_path:
|
||||
self.paths.append(dist.location)
|
||||
self.dirty = True
|
||||
super().add(dist)
|
||||
Environment.add(self, dist)
|
||||
|
||||
def remove(self, dist):
|
||||
"""Remove `dist` from the distribution map"""
|
||||
while dist.location in self.paths:
|
||||
self.paths.remove(dist.location)
|
||||
self.dirty = True
|
||||
super().remove(dist)
|
||||
Environment.remove(self, dist)
|
||||
|
||||
def make_relative(self, path):
|
||||
npath, last = os.path.split(normalize_path(path))
|
||||
@@ -2299,13 +2298,6 @@ def current_umask():
|
||||
return tmp
|
||||
|
||||
|
||||
def only_strs(values):
|
||||
"""
|
||||
Exclude non-str values. Ref #3063.
|
||||
"""
|
||||
return filter(lambda val: isinstance(val, str), values)
|
||||
|
||||
|
||||
class EasyInstallDeprecationWarning(SetuptoolsDeprecationWarning):
|
||||
"""
|
||||
Warning for EasyInstall deprecations, bypassing suppression.
|
||||
|
||||
Reference in New Issue
Block a user