Chris@87: from __future__ import division, absolute_import, print_function Chris@87: Chris@87: import sys Chris@87: if 'setuptools' in sys.modules: Chris@87: import setuptools.command.install as old_install_mod Chris@87: have_setuptools = True Chris@87: else: Chris@87: import distutils.command.install as old_install_mod Chris@87: have_setuptools = False Chris@87: from distutils.file_util import write_file Chris@87: Chris@87: old_install = old_install_mod.install Chris@87: Chris@87: class install(old_install): Chris@87: Chris@87: # Always run install_clib - the command is cheap, so no need to bypass it; Chris@87: # but it's not run by setuptools -- so it's run again in install_data Chris@87: sub_commands = old_install.sub_commands + [ Chris@87: ('install_clib', lambda x: True) Chris@87: ] Chris@87: Chris@87: def finalize_options (self): Chris@87: old_install.finalize_options(self) Chris@87: self.install_lib = self.install_libbase Chris@87: Chris@87: def setuptools_run(self): Chris@87: """ The setuptools version of the .run() method. Chris@87: Chris@87: We must pull in the entire code so we can override the level used in the Chris@87: _getframe() call since we wrap this call by one more level. Chris@87: """ Chris@87: from distutils.command.install import install as distutils_install Chris@87: Chris@87: # Explicit request for old-style install? Just do it Chris@87: if self.old_and_unmanageable or self.single_version_externally_managed: Chris@87: return distutils_install.run(self) Chris@87: Chris@87: # Attempt to detect whether we were called from setup() or by another Chris@87: # command. If we were called by setup(), our caller will be the Chris@87: # 'run_command' method in 'distutils.dist', and *its* caller will be Chris@87: # the 'run_commands' method. If we were called any other way, our Chris@87: # immediate caller *might* be 'run_command', but it won't have been Chris@87: # called by 'run_commands'. This is slightly kludgy, but seems to Chris@87: # work. Chris@87: # Chris@87: caller = sys._getframe(3) Chris@87: caller_module = caller.f_globals.get('__name__', '') Chris@87: caller_name = caller.f_code.co_name Chris@87: Chris@87: if caller_module != 'distutils.dist' or caller_name!='run_commands': Chris@87: # We weren't called from the command line or setup(), so we Chris@87: # should run in backward-compatibility mode to support bdist_* Chris@87: # commands. Chris@87: distutils_install.run(self) Chris@87: else: Chris@87: self.do_egg_install() Chris@87: Chris@87: def run(self): Chris@87: if not have_setuptools: Chris@87: r = old_install.run(self) Chris@87: else: Chris@87: r = self.setuptools_run() Chris@87: if self.record: Chris@87: # bdist_rpm fails when INSTALLED_FILES contains Chris@87: # paths with spaces. Such paths must be enclosed Chris@87: # with double-quotes. Chris@87: f = open(self.record, 'r') Chris@87: lines = [] Chris@87: need_rewrite = False Chris@87: for l in f: Chris@87: l = l.rstrip() Chris@87: if ' ' in l: Chris@87: need_rewrite = True Chris@87: l = '"%s"' % (l) Chris@87: lines.append(l) Chris@87: f.close() Chris@87: if need_rewrite: Chris@87: self.execute(write_file, Chris@87: (self.record, lines), Chris@87: "re-writing list of installed files to '%s'" % Chris@87: self.record) Chris@87: return r