Path: blob/main/test/lib/python3.9/site-packages/setuptools/command/install.py
4799 views
from distutils.errors import DistutilsArgError1import inspect2import glob3import warnings4import platform5import distutils.command.install as orig67import setuptools89# Prior to numpy 1.9, NumPy relies on the '_install' name, so provide it for10# now. See https://github.com/pypa/setuptools/issues/199/11_install = orig.install121314class install(orig.install):15"""Use easy_install to install the package, w/dependencies"""1617user_options = orig.install.user_options + [18('old-and-unmanageable', None, "Try not to use this!"),19('single-version-externally-managed', None,20"used by system package builders to create 'flat' eggs"),21]22boolean_options = orig.install.boolean_options + [23'old-and-unmanageable', 'single-version-externally-managed',24]25new_commands = [26('install_egg_info', lambda self: True),27('install_scripts', lambda self: True),28]29_nc = dict(new_commands)3031def initialize_options(self):3233warnings.warn(34"setup.py install is deprecated. "35"Use build and pip and other standards-based tools.",36setuptools.SetuptoolsDeprecationWarning,37)3839orig.install.initialize_options(self)40self.old_and_unmanageable = None41self.single_version_externally_managed = None4243def finalize_options(self):44orig.install.finalize_options(self)45if self.root:46self.single_version_externally_managed = True47elif self.single_version_externally_managed:48if not self.root and not self.record:49raise DistutilsArgError(50"You must specify --record or --root when building system"51" packages"52)5354def handle_extra_path(self):55if self.root or self.single_version_externally_managed:56# explicit backward-compatibility mode, allow extra_path to work57return orig.install.handle_extra_path(self)5859# Ignore extra_path when installing an egg (or being run by another60# command without --root or --single-version-externally-managed61self.path_file = None62self.extra_dirs = ''6364def run(self):65# Explicit request for old-style install? Just do it66if self.old_and_unmanageable or self.single_version_externally_managed:67return orig.install.run(self)6869if not self._called_from_setup(inspect.currentframe()):70# Run in backward-compatibility mode to support bdist_* commands.71orig.install.run(self)72else:73self.do_egg_install()7475@staticmethod76def _called_from_setup(run_frame):77"""78Attempt to detect whether run() was called from setup() or by another79command. If called by setup(), the parent caller will be the80'run_command' method in 'distutils.dist', and *its* caller will be81the 'run_commands' method. If called any other way, the82immediate caller *might* be 'run_command', but it won't have been83called by 'run_commands'. Return True in that case or if a call stack84is unavailable. Return False otherwise.85"""86if run_frame is None:87msg = "Call stack not available. bdist_* commands may fail."88warnings.warn(msg)89if platform.python_implementation() == 'IronPython':90msg = "For best results, pass -X:Frames to enable call stack."91warnings.warn(msg)92return True9394frames = inspect.getouterframes(run_frame)95for frame in frames[2:4]:96caller, = frame[:1]97info = inspect.getframeinfo(caller)98caller_module = caller.f_globals.get('__name__', '')99100if caller_module == "setuptools.dist" and info.function == "run_command":101# Starting from v61.0.0 setuptools overwrites dist.run_command102continue103104return (105caller_module == 'distutils.dist'106and info.function == 'run_commands'107)108109def do_egg_install(self):110111easy_install = self.distribution.get_command_class('easy_install')112113cmd = easy_install(114self.distribution, args="x", root=self.root, record=self.record,115)116cmd.ensure_finalized() # finalize before bdist_egg munges install cmd117cmd.always_copy_from = '.' # make sure local-dir eggs get installed118119# pick up setup-dir .egg files only: no .egg-info120cmd.package_index.scan(glob.glob('*.egg'))121122self.run_command('bdist_egg')123args = [self.distribution.get_command_obj('bdist_egg').egg_output]124125if setuptools.bootstrap_install_from:126# Bootstrap self-installation of setuptools127args.insert(0, setuptools.bootstrap_install_from)128129cmd.args = args130cmd.run(show_deprecation=False)131setuptools.bootstrap_install_from = None132133134# XXX Python 3.1 doesn't see _nc if this is inside the class135install.sub_commands = (136[cmd for cmd in orig.install.sub_commands if cmd[0] not in install._nc] +137install.new_commands138)139140141