blob: bfb9af5aee29e765b9b45788b592da65d37edca5 [file] [log] [blame]
Phillip J. Eby069159b2006-04-18 04:05:34 +00001import setuptools, sys
2from distutils.command.install import install as _install
3from distutils.errors import DistutilsArgError
4
5class install(_install):
6 """Use easy_install to install the package, w/dependencies"""
7
8 user_options = _install.user_options + [
9 ('old-and-unmanageable', None, "Try not to use this!"),
10 ('single-version-externally-managed', None,
11 "used by system package builders to create 'flat' eggs"),
12 ]
13 boolean_options = _install.boolean_options + [
14 'old-and-unmanageable', 'single-version-externally-managed',
15 ]
16 new_commands = [
17 ('install_egg_info', lambda self: True),
18 ('install_scripts', lambda self: True),
19 ]
20 _nc = dict(new_commands)
21 sub_commands = [
22 cmd for cmd in _install.sub_commands if cmd[0] not in _nc
23 ] + new_commands
24
25 def initialize_options(self):
26 _install.initialize_options(self)
27 self.old_and_unmanageable = None
28 self.single_version_externally_managed = None
29 self.no_compile = None # make DISTUTILS_DEBUG work right!
30
31 def finalize_options(self):
32 _install.finalize_options(self)
33 if self.root:
34 self.single_version_externally_managed = True
35 elif self.single_version_externally_managed:
36 if not self.root and not self.record:
37 raise DistutilsArgError(
38 "You must specify --record or --root when building system"
39 " packages"
40 )
41
42 def handle_extra_path(self):
43 # We always ignore extra_path, because we install as .egg or .egg-info
44 self.path_file = None
45 self.extra_dirs = ''
46
47 def run(self):
48 # Explicit request for old-style install? Just do it
49 if self.old_and_unmanageable or self.single_version_externally_managed:
50 return _install.run(self)
51
52 # Attempt to detect whether we were called from setup() or by another
53 # command. If we were called by setup(), our caller will be the
54 # 'run_command' method in 'distutils.dist', and *its* caller will be
55 # the 'run_commands' method. If we were called any other way, our
56 # immediate caller *might* be 'run_command', but it won't have been
57 # called by 'run_commands'. This is slightly kludgy, but seems to
58 # work.
59 #
60 caller = sys._getframe(2)
61 caller_module = caller.f_globals.get('__name__','')
62 caller_name = caller.f_code.co_name
Tim Peters584b0e02006-04-18 17:32:12 +000063
Phillip J. Eby069159b2006-04-18 04:05:34 +000064 if caller_module != 'distutils.dist' or caller_name!='run_commands':
65 # We weren't called from the command line or setup(), so we
66 # should run in backward-compatibility mode to support bdist_*
67 # commands.
68 _install.run(self)
69 else:
70 self.do_egg_install()
Tim Peters584b0e02006-04-18 17:32:12 +000071
Phillip J. Eby069159b2006-04-18 04:05:34 +000072
73
74
75
76
77
78
79
80
81
82
83 def do_egg_install(self):
84
85 from setuptools.command.easy_install import easy_install
86
87 cmd = easy_install(
88 self.distribution, args="x", root=self.root, record=self.record,
89 )
90 cmd.ensure_finalized() # finalize before bdist_egg munges install cmd
91
92 self.run_command('bdist_egg')
93 args = [self.distribution.get_command_obj('bdist_egg').egg_output]
94
95 if setuptools.bootstrap_install_from:
96 # Bootstrap self-installation of setuptools
97 args.insert(0, setuptools.bootstrap_install_from)
98
99 cmd.args = args
100 cmd.run()
101 setuptools.bootstrap_install_from = None