Fixed #6403 : package path usage for build_ext

This commit is contained in:
Tarek Ziadé 2009-07-03 08:22:56 +00:00
parent 50a2252851
commit 65ec61ed06
3 changed files with 43 additions and 10 deletions

View File

@ -644,17 +644,23 @@ class build_ext (Command):
"""
fullname = self.get_ext_fullname(ext_name)
modpath = fullname.split('.')
package = '.'.join(modpath[0:-1])
base = modpath[-1]
filename = self.get_ext_filename(base)
filename = self.get_ext_filename(modpath[-1])
if not self.inplace:
# no further work needed
# returning :
# build_dir/package/path/filename
filename = os.path.join(*modpath[:-1]+[filename])
return os.path.join(self.build_lib, filename)
# the inplace option requires to find the package directory
# using the build_py command
# using the build_py command for that
package = '.'.join(modpath[0:-1])
build_py = self.get_finalized_command('build_py')
package_dir = os.path.abspath(build_py.get_package_dir(package))
# returning
# package_dir/filename
return os.path.join(package_dir, filename)
def get_ext_fullname(self, ext_name):

View File

@ -337,7 +337,8 @@ class BuildExtTestCase(support.TempdirManager,
self.assertEquals(so_dir, cmd.build_lib)
# inplace = 0, cmd.package = 'bar'
cmd.package = 'bar'
build_py = cmd.get_finalized_command('build_py')
build_py.package_dir = {'': 'bar'}
path = cmd.get_ext_fullpath('foo')
# checking that the last directory is the build_dir
path = os.path.split(path)[0]
@ -355,12 +356,14 @@ class BuildExtTestCase(support.TempdirManager,
# checking that the last directory is bar
path = os.path.split(path)[0]
lastdir = os.path.split(path)[-1]
self.assertEquals(lastdir, cmd.package)
self.assertEquals(lastdir, 'bar')
def test_build_ext_inplace(self):
etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
etree_ext = Extension('lxml.etree', [etree_c])
dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
def test_ext_fullpath(self):
# building lxml.etree inplace
#etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
#etree_ext = Extension('lxml.etree', [etree_c])
#dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
dist = Distribution()
cmd = build_ext(dist)
cmd.inplace = 1
cmd.distribution.package_dir = {'': 'src'}
@ -370,6 +373,28 @@ class BuildExtTestCase(support.TempdirManager,
path = cmd.get_ext_fullpath('lxml.etree')
self.assertEquals(wanted, path)
# building lxml.etree not inplace
cmd.inplace = 0
cmd.build_lib = os.path.join(curdir, 'tmpdir')
wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree.so')
path = cmd.get_ext_fullpath('lxml.etree')
self.assertEquals(wanted, path)
# building twisted.runner.portmap not inplace
build_py = cmd.get_finalized_command('build_py')
build_py.package_dir = {}
cmd.distribution.packages = ['twisted', 'twisted.runner.portmap']
path = cmd.get_ext_fullpath('twisted.runner.portmap')
wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
'portmap.so')
self.assertEquals(wanted, path)
# building twisted.runner.portmap inplace
cmd.inplace = 1
path = cmd.get_ext_fullpath('twisted.runner.portmap')
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap.so')
self.assertEquals(wanted, path)
def test_suite():
src = _get_source_filename()
if not os.path.exists(src):

View File

@ -347,6 +347,8 @@ Core and Builtins
Library
-------
- Issue #6403: Fixed package path usage in build_ext.
- Issues #5155, 5313, 5331: multiprocessing.Process._bootstrap was
unconditionally calling "os.close(sys.stdin.fileno())" resulting in file
descriptor errors