Skip to content

Commit 7faab38

Browse files
author
neil.schemenauer
committed
Make test_build_ext.py use sysconfig "srcdir" to find the source for
xxmodule.c. Have sysconfig make the srcdir path absolute if that seems necessary (running non-installed Python outside the build directory). git-svn-id: http://svn.python.org/projects/python/branches/py3k@69375 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 09e098c commit 7faab38

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

Lib/distutils/sysconfig.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,20 @@ def get_config_vars(*args):
504504
_config_vars['prefix'] = PREFIX
505505
_config_vars['exec_prefix'] = EXEC_PREFIX
506506

507+
# Convert srcdir into an absolute path if it appears necessary.
508+
# Normally it is relative to the build directory. However, during
509+
# testing, for example, we might be running a non-installed python
510+
# from a different directory.
511+
if python_build and os.name == "posix":
512+
base = os.path.dirname(os.path.abspath(sys.executable))
513+
if (not os.path.isabs(_config_vars['srcdir']) and
514+
base != os.getcwd()):
515+
# srcdir is relative and we are not in the same directory
516+
# as the executable. Assume executable is in the build
517+
# directory and make srcdir absolute.
518+
srcdir = os.path.join(base, _config_vars['srcdir'])
519+
_config_vars['srcdir'] = os.path.normpath(srcdir)
520+
507521
if sys.platform == 'darwin':
508522
kernel_version = os.uname()[2] # Kernel version (8.4.3)
509523
major_version = int(kernel_version.split('.')[0])

Lib/distutils/tests/test_build_ext.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
# Don't load the xx module more than once.
1616
ALREADY_TESTED = False
1717

18+
def _get_source_filename():
19+
srcdir = sysconfig.get_config_var('srcdir')
20+
return os.path.join(srcdir, 'Modules', 'xxmodule.c')
21+
1822
class BuildExtTestCase(unittest.TestCase):
1923
def setUp(self):
2024
# Create a simple test environment
2125
# Note that we're making changes to sys.path
2226
self.tmp_dir = tempfile.mkdtemp(prefix="pythontest_")
2327
self.sys_path = sys.path[:]
2428
sys.path.append(self.tmp_dir)
25-
26-
xx_c = os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c')
27-
shutil.copy(xx_c, self.tmp_dir)
29+
shutil.copy(_get_source_filename(), self.tmp_dir)
2830

2931
def test_build_ext(self):
3032
global ALREADY_TESTED
@@ -97,9 +99,11 @@ def test_solaris_enable_shared(self):
9799
self.assert_(len(cmd.library_dirs) > 0)
98100

99101
def test_suite():
100-
if not sysconfig.python_build:
102+
src = _get_source_filename()
103+
if not os.path.exists(src):
101104
if support.verbose:
102-
print('test_build_ext: The test must be run in a python build dir')
105+
print('test_build_ext: Cannot find source code (test'
106+
' must run in python build dir)')
103107
return unittest.TestSuite()
104108
else: return unittest.makeSuite(BuildExtTestCase)
105109

0 commit comments

Comments
 (0)