diff options
author | PJ Eby <distutils-sig@python.org> | 2005-08-21 22:59:57 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-08-21 22:59:57 +0000 |
commit | e00f4a87ad767db9ff358ffc773365d5929345fa (patch) | |
tree | fe78301297b2e534a2fd46afd312ea0c2d15eb49 /setuptools/command/build_ext.py | |
parent | 46eb9e6507ed12b79ec70b55ac2ffb74543bccd1 (diff) | |
download | external_python_setuptools-e00f4a87ad767db9ff358ffc773365d5929345fa.tar.gz external_python_setuptools-e00f4a87ad767db9ff358ffc773365d5929345fa.tar.bz2 external_python_setuptools-e00f4a87ad767db9ff358ffc773365d5929345fa.zip |
Make "build_ext --inplace" work sanely w/multiple Python versions and
platforms, by ensuring that the in-place extensions are the right ones for
the currently-running Python, even if they are newer than their sources.
(This, like so many other setuptools fixes and enhancements, should
probably be backported into the distutils as well, although it would have
to be implemented a bit differently.)
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041214
Diffstat (limited to 'setuptools/command/build_ext.py')
-rw-r--r-- | setuptools/command/build_ext.py | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 35a9e63e..a2f2db09 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -1,6 +1,41 @@ # Attempt to use Pyrex for building extensions, if available try: - from Pyrex.Distutils.build_ext import build_ext + from Pyrex.Distutils.build_ext import build_ext as _build_ext except ImportError: - from distutils.command.build_ext import build_ext + from distutils.command.build_ext import build_ext as _build_ext + +import os +from distutils.file_util import copy_file + +class build_ext(_build_ext): + + def run(self): + """Build extensions in build directory, then copy if --inplace""" + old_inplace, self.inplace = self.inplace, 0 + _build_ext.run(self) + self.inplace = old_inplace + if old_inplace: + self.copy_extensions_to_source() + + def copy_extensions_to_source(self): + build_py = self.get_finalized_command('build_py') + for ext in self.extensions: + fullname = ext.name + modpath = fullname.split('.') + package = '.'.join(modpath[:-1]) + base = modpath[-1] + package_dir = build_py.get_package_dir(package) + dest_filename = os.path.join(package_dir, + self.get_ext_filename(base)) + src_filename = os.path.join(self.build_lib, + self.get_ext_filename(fullname)) + + # Always copy, even if source is older than destination, to ensure + # that the right extensions for the current Python/platform are + # used. + copy_file( + src_filename, dest_filename, verbose=self.verbose, + dry_run=self.dry_run + ) + |