Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/setuptools/command/develop.py
7738 views
from distutils.util import convert_path1from distutils import log2from distutils.errors import DistutilsError, DistutilsOptionError3import os4import glob5import io67from setuptools.extern import six89import pkg_resources10from setuptools.command.easy_install import easy_install11from setuptools import namespaces12import setuptools1314__metaclass__ = type151617class develop(namespaces.DevelopInstaller, easy_install):18"""Set up package for development"""1920description = "install package in 'development mode'"2122user_options = easy_install.user_options + [23("uninstall", "u", "Uninstall this source package"),24("egg-path=", None, "Set the path to be used in the .egg-link file"),25]2627boolean_options = easy_install.boolean_options + ['uninstall']2829command_consumes_arguments = False # override base3031def run(self):32if self.uninstall:33self.multi_version = True34self.uninstall_link()35self.uninstall_namespaces()36else:37self.install_for_development()38self.warn_deprecated_options()3940def initialize_options(self):41self.uninstall = None42self.egg_path = None43easy_install.initialize_options(self)44self.setup_path = None45self.always_copy_from = '.' # always copy eggs installed in curdir4647def finalize_options(self):48ei = self.get_finalized_command("egg_info")49if ei.broken_egg_info:50template = "Please rename %r to %r before using 'develop'"51args = ei.egg_info, ei.broken_egg_info52raise DistutilsError(template % args)53self.args = [ei.egg_name]5455easy_install.finalize_options(self)56self.expand_basedirs()57self.expand_dirs()58# pick up setup-dir .egg files only: no .egg-info59self.package_index.scan(glob.glob('*.egg'))6061egg_link_fn = ei.egg_name + '.egg-link'62self.egg_link = os.path.join(self.install_dir, egg_link_fn)63self.egg_base = ei.egg_base64if self.egg_path is None:65self.egg_path = os.path.abspath(ei.egg_base)6667target = pkg_resources.normalize_path(self.egg_base)68egg_path = pkg_resources.normalize_path(69os.path.join(self.install_dir, self.egg_path))70if egg_path != target:71raise DistutilsOptionError(72"--egg-path must be a relative path from the install"73" directory to " + target74)7576# Make a distribution for the package's source77self.dist = pkg_resources.Distribution(78target,79pkg_resources.PathMetadata(target, os.path.abspath(ei.egg_info)),80project_name=ei.egg_name81)8283self.setup_path = self._resolve_setup_path(84self.egg_base,85self.install_dir,86self.egg_path,87)8889@staticmethod90def _resolve_setup_path(egg_base, install_dir, egg_path):91"""92Generate a path from egg_base back to '.' where the93setup script resides and ensure that path points to the94setup path from $install_dir/$egg_path.95"""96path_to_setup = egg_base.replace(os.sep, '/').rstrip('/')97if path_to_setup != os.curdir:98path_to_setup = '../' * (path_to_setup.count('/') + 1)99resolved = pkg_resources.normalize_path(100os.path.join(install_dir, egg_path, path_to_setup)101)102if resolved != pkg_resources.normalize_path(os.curdir):103raise DistutilsOptionError(104"Can't get a consistent path to setup script from"105" installation directory", resolved,106pkg_resources.normalize_path(os.curdir))107return path_to_setup108109def install_for_development(self):110if not six.PY2 and getattr(self.distribution, 'use_2to3', False):111# If we run 2to3 we can not do this inplace:112113# Ensure metadata is up-to-date114self.reinitialize_command('build_py', inplace=0)115self.run_command('build_py')116bpy_cmd = self.get_finalized_command("build_py")117build_path = pkg_resources.normalize_path(bpy_cmd.build_lib)118119# Build extensions120self.reinitialize_command('egg_info', egg_base=build_path)121self.run_command('egg_info')122123self.reinitialize_command('build_ext', inplace=0)124self.run_command('build_ext')125126# Fixup egg-link and easy-install.pth127ei_cmd = self.get_finalized_command("egg_info")128self.egg_path = build_path129self.dist.location = build_path130# XXX131self.dist._provider = pkg_resources.PathMetadata(132build_path, ei_cmd.egg_info)133else:134# Without 2to3 inplace works fine:135self.run_command('egg_info')136137# Build extensions in-place138self.reinitialize_command('build_ext', inplace=1)139self.run_command('build_ext')140141if setuptools.bootstrap_install_from:142self.easy_install(setuptools.bootstrap_install_from)143setuptools.bootstrap_install_from = None144145self.install_namespaces()146147# create an .egg-link in the installation dir, pointing to our egg148log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)149if not self.dry_run:150with open(self.egg_link, "w") as f:151f.write(self.egg_path + "\n" + self.setup_path)152# postprocess the installed distro, fixing up .pth, installing scripts,153# and handling requirements154self.process_distribution(None, self.dist, not self.no_deps)155156def uninstall_link(self):157if os.path.exists(self.egg_link):158log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)159egg_link_file = open(self.egg_link)160contents = [line.rstrip() for line in egg_link_file]161egg_link_file.close()162if contents not in ([self.egg_path],163[self.egg_path, self.setup_path]):164log.warn("Link points to %s: uninstall aborted", contents)165return166if not self.dry_run:167os.unlink(self.egg_link)168if not self.dry_run:169self.update_pth(self.dist) # remove any .pth link to us170if self.distribution.scripts:171# XXX should also check for entry point scripts!172log.warn("Note: you must uninstall or replace scripts manually!")173174def install_egg_scripts(self, dist):175if dist is not self.dist:176# Installing a dependency, so fall back to normal behavior177return easy_install.install_egg_scripts(self, dist)178179# create wrapper scripts in the script dir, pointing to dist.scripts180181# new-style...182self.install_wrapper_scripts(dist)183184# ...and old-style185for script_name in self.distribution.scripts or []:186script_path = os.path.abspath(convert_path(script_name))187script_name = os.path.basename(script_path)188with io.open(script_path) as strm:189script_text = strm.read()190self.install_script(dist, script_name, script_text, script_path)191192def install_wrapper_scripts(self, dist):193dist = VersionlessRequirement(dist)194return easy_install.install_wrapper_scripts(self, dist)195196197class VersionlessRequirement:198"""199Adapt a pkg_resources.Distribution to simply return the project200name as the 'requirement' so that scripts will work across201multiple versions.202203>>> from pkg_resources import Distribution204>>> dist = Distribution(project_name='foo', version='1.0')205>>> str(dist.as_requirement())206'foo==1.0'207>>> adapted_dist = VersionlessRequirement(dist)208>>> str(adapted_dist.as_requirement())209'foo'210"""211212def __init__(self, dist):213self.__dist = dist214215def __getattr__(self, name):216return getattr(self.__dist, name)217218def as_requirement(self):219return self.project_name220221222