1 from distutils
.errors
import DistutilsArgError
5 import distutils
.command
.install
as orig
8 from ..warnings
import SetuptoolsDeprecationWarning
, SetuptoolsWarning
10 # Prior to numpy 1.9, NumPy relies on the '_install' name, so provide it for
11 # now. See https://github.com/pypa/setuptools/issues/199/
12 _install
= orig
.install
15 class install(orig
.install
):
16 """Use easy_install to install the package, w/dependencies"""
18 user_options
= orig
.install
.user_options
+ [
19 ('old-and-unmanageable', None, "Try not to use this!"),
21 'single-version-externally-managed',
23 "used by system package builders to create 'flat' eggs",
26 boolean_options
= orig
.install
.boolean_options
+ [
27 'old-and-unmanageable',
28 'single-version-externally-managed',
31 ('install_egg_info', lambda self
: True),
32 ('install_scripts', lambda self
: True),
34 _nc
= dict(new_commands
)
36 def initialize_options(self
):
37 SetuptoolsDeprecationWarning
.emit(
38 "setup.py install is deprecated.",
40 Please avoid running ``setup.py`` directly.
41 Instead, use pypa/build, pypa/installer or other
42 standards-based tools.
44 see_url
="https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html",
45 # TODO: Document how to bootstrap setuptools without install
46 # (e.g. by unziping the wheel file)
47 # and then add a due_date to this warning.
50 orig
.install
.initialize_options(self
)
51 self
.old_and_unmanageable
= None
52 self
.single_version_externally_managed
= None
54 def finalize_options(self
):
55 orig
.install
.finalize_options(self
)
57 self
.single_version_externally_managed
= True
58 elif self
.single_version_externally_managed
:
59 if not self
.root
and not self
.record
:
60 raise DistutilsArgError(
61 "You must specify --record or --root when building system"
65 def handle_extra_path(self
):
66 if self
.root
or self
.single_version_externally_managed
:
67 # explicit backward-compatibility mode, allow extra_path to work
68 return orig
.install
.handle_extra_path(self
)
70 # Ignore extra_path when installing an egg (or being run by another
71 # command without --root or --single-version-externally-managed
76 # Explicit request for old-style install? Just do it
77 if self
.old_and_unmanageable
or self
.single_version_externally_managed
:
78 return orig
.install
.run(self
)
80 if not self
._called
_from
_setup
(inspect
.currentframe()):
81 # Run in backward-compatibility mode to support bdist_* commands.
82 orig
.install
.run(self
)
87 def _called_from_setup(run_frame
):
89 Attempt to detect whether run() was called from setup() or by another
90 command. If called by setup(), the parent caller will be the
91 'run_command' method in 'distutils.dist', and *its* caller will be
92 the 'run_commands' method. If called any other way, the
93 immediate caller *might* be 'run_command', but it won't have been
94 called by 'run_commands'. Return True in that case or if a call stack
95 is unavailable. Return False otherwise.
98 msg
= "Call stack not available. bdist_* commands may fail."
99 SetuptoolsWarning
.emit(msg
)
100 if platform
.python_implementation() == 'IronPython':
101 msg
= "For best results, pass -X:Frames to enable call stack."
102 SetuptoolsWarning
.emit(msg
)
105 frames
= inspect
.getouterframes(run_frame
)
106 for frame
in frames
[2:4]:
107 (caller
,) = frame
[:1]
108 info
= inspect
.getframeinfo(caller
)
109 caller_module
= caller
.f_globals
.get('__name__', '')
111 if caller_module
== "setuptools.dist" and info
.function
== "run_command":
112 # Starting from v61.0.0 setuptools overwrites dist.run_command
115 return caller_module
== 'distutils.dist' and info
.function
== 'run_commands'
117 def do_egg_install(self
):
118 easy_install
= self
.distribution
.get_command_class('easy_install')
126 cmd
.ensure_finalized() # finalize before bdist_egg munges install cmd
127 cmd
.always_copy_from
= '.' # make sure local-dir eggs get installed
129 # pick up setup-dir .egg files only: no .egg-info
130 cmd
.package_index
.scan(glob
.glob('*.egg'))
132 self
.run_command('bdist_egg')
133 args
= [self
.distribution
.get_command_obj('bdist_egg').egg_output
]
135 if setuptools
.bootstrap_install_from
:
136 # Bootstrap self-installation of setuptools
137 args
.insert(0, setuptools
.bootstrap_install_from
)
140 cmd
.run(show_deprecation
=False)
141 setuptools
.bootstrap_install_from
= None
144 # XXX Python 3.1 doesn't see _nc if this is inside the class
145 install
.sub_commands
= [
146 cmd
for cmd
in orig
.install
.sub_commands
if cmd
[0] not in install
._nc
147 ] + install
.new_commands