This commit is contained in:
lz_db
2026-10-16 22:48:30 +08:00
parent 190de72571
commit 0b36fd3383
3161 changed files with 12787 additions and 77274 deletions
@@ -1,15 +1,14 @@
import glob
import os
import setuptools
from setuptools import _normalization, _path, namespaces
from setuptools.command.easy_install import easy_install
from ..unicode_utils import _read_utf8_with_fallback
from distutils import log
from distutils.errors import DistutilsOptionError
from distutils.util import convert_path
from distutils import log
from distutils.errors import DistutilsError, DistutilsOptionError
import os
import glob
import io
import pkg_resources
from setuptools.command.easy_install import easy_install
from setuptools import namespaces
import setuptools
class develop(namespaces.DevelopInstaller, easy_install):
@@ -42,10 +41,12 @@ class develop(namespaces.DevelopInstaller, easy_install):
self.setup_path = None
self.always_copy_from = '.' # always copy eggs installed in curdir
def finalize_options(self) -> None:
import pkg_resources
def finalize_options(self):
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
raise DistutilsError(template % args)
self.args = [ei.egg_name]
easy_install.finalize_options(self)
@@ -54,16 +55,16 @@ class develop(namespaces.DevelopInstaller, easy_install):
# pick up setup-dir .egg files only: no .egg-info
self.package_index.scan(glob.glob('*.egg'))
egg_link_fn = (
_normalization.filename_component_broken(ei.egg_name) + '.egg-link'
)
egg_link_fn = ei.egg_name + '.egg-link'
self.egg_link = os.path.join(self.install_dir, egg_link_fn)
self.egg_base = ei.egg_base
if self.egg_path is None:
self.egg_path = os.path.abspath(ei.egg_base)
target = _path.normpath(self.egg_base)
egg_path = _path.normpath(os.path.join(self.install_dir, self.egg_path))
target = pkg_resources.normalize_path(self.egg_base)
egg_path = pkg_resources.normalize_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"
@@ -93,22 +94,23 @@ class develop(namespaces.DevelopInstaller, easy_install):
path_to_setup = egg_base.replace(os.sep, '/').rstrip('/')
if path_to_setup != os.curdir:
path_to_setup = '../' * (path_to_setup.count('/') + 1)
resolved = _path.normpath(os.path.join(install_dir, egg_path, path_to_setup))
curdir = _path.normpath(os.curdir)
if resolved != curdir:
resolved = pkg_resources.normalize_path(
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",
resolved,
curdir,
pkg_resources.normalize_path(os.curdir),
)
return path_to_setup
def install_for_development(self) -> None:
def install_for_development(self):
self.run_command('egg_info')
# Build extensions in-place
self.reinitialize_command('build_ext', inplace=True)
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
if setuptools.bootstrap_install_from:
@@ -120,21 +122,18 @@ class develop(namespaces.DevelopInstaller, easy_install):
# 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)
if not self.dry_run:
with open(self.egg_link, "w", encoding="utf-8") as f:
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) -> None:
def uninstall_link(self):
if os.path.exists(self.egg_link):
log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
contents = [
line.rstrip()
for line in _read_utf8_with_fallback(self.egg_link).splitlines()
]
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)
return
@@ -160,11 +159,10 @@ 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)
script_text = _read_utf8_with_fallback(script_path)
with io.open(script_path) as strm:
script_text = strm.read()
self.install_script(dist, script_name, script_text, script_path)
return None
def install_wrapper_scripts(self, dist):
dist = VersionlessRequirement(dist)
return easy_install.install_wrapper_scripts(self, dist)
@@ -185,10 +183,10 @@ class VersionlessRequirement:
'foo'
"""
def __init__(self, dist) -> None:
def __init__(self, dist):
self.__dist = dist
def __getattr__(self, name: str):
def __getattr__(self, name):
return getattr(self.__dist, name)
def as_requirement(self):