Phillip J. Eby | 069159b | 2006-04-18 04:05:34 +0000 | [diff] [blame] | 1 | import setuptools, sys |
| 2 | from distutils.command.install import install as _install |
| 3 | from distutils.errors import DistutilsArgError |
| 4 | |
| 5 | class 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 Peters | 584b0e0 | 2006-04-18 17:32:12 +0000 | [diff] [blame^] | 63 | |
Phillip J. Eby | 069159b | 2006-04-18 04:05:34 +0000 | [diff] [blame] | 64 | 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 Peters | 584b0e0 | 2006-04-18 17:32:12 +0000 | [diff] [blame^] | 71 | |
Phillip J. Eby | 069159b | 2006-04-18 04:05:34 +0000 | [diff] [blame] | 72 | |
| 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 |