Sergio Pascual 48ddb7f
From f80125940eaa93ec0b2d0f579fcaaaff07698344 Mon Sep 17 00:00:00 2001
Sergio Pascual 48ddb7f
From: Michael Droettboom <mdboom@gmail.com>
Sergio Pascual 48ddb7f
Date: Mon, 24 Mar 2014 12:20:08 -0400
Sergio Pascual 48ddb7f
Subject: [PATCH] Override Install and InstallLib commands to also adjust the
Sergio Pascual 48ddb7f
 library directory to be the platform-specific one. [#2223]
Sergio Pascual 48ddb7f
Sergio Pascual 48ddb7f
---
Sergio Pascual 48ddb7f
 astropy/setup_helpers.py | 73 +++++++++++++++++++++++++++++++-----------------
Sergio Pascual 48ddb7f
 1 file changed, 47 insertions(+), 26 deletions(-)
Sergio Pascual 48ddb7f
Sergio Pascual 48ddb7f
diff --git a/astropy/setup_helpers.py b/astropy/setup_helpers.py
Sergio Pascual 48ddb7f
index 2cfadbd..536bc1e 100644
Sergio Pascual 48ddb7f
--- a/astropy/setup_helpers.py
Sergio Pascual 48ddb7f
+++ b/astropy/setup_helpers.py
Sergio Pascual 48ddb7f
@@ -28,6 +28,8 @@
Sergio Pascual 48ddb7f
 from distutils.command.sdist import sdist as DistutilsSdist
Sergio Pascual 48ddb7f
 from setuptools.command.build_ext import build_ext as SetuptoolsBuildExt
Sergio Pascual 48ddb7f
 from setuptools.command.build_py import build_py as SetuptoolsBuildPy
Sergio Pascual 48ddb7f
+from setuptools.command.install import install as SetuptoolsInstall
Sergio Pascual 48ddb7f
+from setuptools.command.install_lib import install_lib as SetuptoolsInstallLib
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
 from setuptools.command.register import register as SetuptoolsRegister
Sergio Pascual 48ddb7f
 from setuptools import find_packages
Sergio Pascual 48ddb7f
@@ -362,19 +364,25 @@ def register_commands(package, version, release):
Sergio Pascual 48ddb7f
     _registered_commands = {
Sergio Pascual 48ddb7f
         'test': generate_test_command(package),
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
-         # Use distutils' sdist because it respects package_data.
Sergio Pascual 48ddb7f
-         # setuptools/distributes sdist requires duplication of information in
Sergio Pascual 48ddb7f
-         # MANIFEST.in
Sergio Pascual 48ddb7f
-         'sdist': DistutilsSdist,
Sergio Pascual 48ddb7f
+        # Use distutils' sdist because it respects package_data.
Sergio Pascual 48ddb7f
+        # setuptools/distributes sdist requires duplication of information in
Sergio Pascual 48ddb7f
+        # MANIFEST.in
Sergio Pascual 48ddb7f
+        'sdist': DistutilsSdist,
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
-         # The exact form of the build_ext command depends on whether or not
Sergio Pascual 48ddb7f
-         # we're building a release version
Sergio Pascual 48ddb7f
-         'build_ext': generate_build_ext_command(package, release),
Sergio Pascual 48ddb7f
+        # The exact form of the build_ext command depends on whether or not
Sergio Pascual 48ddb7f
+        # we're building a release version
Sergio Pascual 48ddb7f
+        'build_ext': generate_build_ext_command(package, release),
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
-         # We have a custom build_py to generate the default configuration file
Sergio Pascual 48ddb7f
-         'build_py': AstropyBuildPy,
Sergio Pascual 48ddb7f
+        # We have a custom build_py to generate the default configuration file
Sergio Pascual 48ddb7f
+        'build_py': AstropyBuildPy,
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
-         'register': AstropyRegister
Sergio Pascual 48ddb7f
+        # Since install can (in some circumstances) be run without
Sergio Pascual 48ddb7f
+        # first building, we also need to override install and
Sergio Pascual 48ddb7f
+        # install_lib.  See #2223
Sergio Pascual 48ddb7f
+        'install': AstropyInstall,
Sergio Pascual 48ddb7f
+        'install_lib': AstropyInstallLib,
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+        'register': AstropyRegister
Sergio Pascual 48ddb7f
     }
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
     try:
Sergio Pascual 48ddb7f
@@ -542,6 +550,29 @@ def run(self):
Sergio Pascual 48ddb7f
     return type('build_ext', (basecls, object), attrs)
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
+def _get_platlib_dir(cmd):
Sergio Pascual 48ddb7f
+    plat_specifier = '.{0}-{1}'.format(cmd.plat_name, sys.version[0:3])
Sergio Pascual 48ddb7f
+    return os.path.join(cmd.build_base, 'lib' + plat_specifier)
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+class AstropyInstall(SetuptoolsInstall):
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+    def finalize_options(self):
Sergio Pascual 48ddb7f
+        build_cmd = self.get_finalized_command('build')
Sergio Pascual 48ddb7f
+        platlib_dir = _get_platlib_dir(build_cmd)
Sergio Pascual 48ddb7f
+        self.build_lib = platlib_dir
Sergio Pascual 48ddb7f
+        SetuptoolsInstall.finalize_options(self)
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+class AstropyInstallLib(SetuptoolsInstallLib):
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+    def finalize_options(self):
Sergio Pascual 48ddb7f
+        build_cmd = self.get_finalized_command('build')
Sergio Pascual 48ddb7f
+        platlib_dir = _get_platlib_dir(build_cmd)
Sergio Pascual 48ddb7f
+        self.build_dir = platlib_dir
Sergio Pascual 48ddb7f
+        SetuptoolsInstallLib.finalize_options(self)
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
 class AstropyBuildPy(SetuptoolsBuildPy):
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
     def finalize_options(self):
Sergio Pascual 48ddb7f
@@ -550,22 +581,12 @@ def finalize_options(self):
Sergio Pascual 48ddb7f
         # for projects with only pure-Python source (this is desirable
Sergio Pascual 48ddb7f
         # specifically for support of multiple Python version).
Sergio Pascual 48ddb7f
         build_cmd = self.get_finalized_command('build')
Sergio Pascual 48ddb7f
-        plat_specifier = '.{0}-{1}'.format(build_cmd.plat_name,
Sergio Pascual 48ddb7f
-                                           sys.version[0:3])
Sergio Pascual 48ddb7f
-        # Do this unconditionally
Sergio Pascual 48ddb7f
-        build_purelib = os.path.join(build_cmd.build_base,
Sergio Pascual 48ddb7f
-                                     'lib' + plat_specifier)
Sergio Pascual 48ddb7f
-        build_cmd.build_purelib = build_purelib
Sergio Pascual 48ddb7f
-        build_cmd.build_lib = build_purelib
Sergio Pascual 48ddb7f
-
Sergio Pascual 48ddb7f
-        # Ugly hack: We also need to 'fix' the build_lib option on the
Sergio Pascual 48ddb7f
-        # install command--it would be better just to override that command
Sergio Pascual 48ddb7f
-        # entirely, but we can get around that extra effort by doing it here
Sergio Pascual 48ddb7f
-        install_cmd = self.get_finalized_command('install')
Sergio Pascual 48ddb7f
-        install_cmd.build_lib = build_purelib
Sergio Pascual 48ddb7f
-        install_lib_cmd = self.get_finalized_command('install_lib')
Sergio Pascual 48ddb7f
-        install_lib_cmd.build_dir = build_purelib
Sergio Pascual 48ddb7f
-        self.build_lib = build_purelib
Sergio Pascual 48ddb7f
+        platlib_dir = _get_platlib_dir(build_cmd)
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
+        build_cmd.build_purelib = platlib_dir
Sergio Pascual 48ddb7f
+        build_cmd.build_lib = platlib_dir
Sergio Pascual 48ddb7f
+        self.build_lib = platlib_dir
Sergio Pascual 48ddb7f
+
Sergio Pascual 48ddb7f
         SetuptoolsBuildPy.finalize_options(self)
Sergio Pascual 48ddb7f
 
Sergio Pascual 48ddb7f
     def run_2to3(self, files, doctests=False):
Sergio Pascual 48ddb7f
-- 
Sergio Pascual 48ddb7f
1.8.5.5
Sergio Pascual 48ddb7f