Skip to content

Commit b24ecb7

Browse files
committed
pythongh-109615: Fix support test_copy_python_src_ignore() (python#109958)
Fix the test when run on an installed Python: use "abs_srcdir" of sysconfig, and skip the test if the Python source code cannot be found. * Tools/patchcheck/patchcheck.py, Tools/freeze/test/freeze.py and Lib/test/libregrtest/utils.py now first try to get "abs_srcdir" from sysconfig, before getting "srcdir" from sysconfig. * test.pythoninfo logs sysconfig "abs_srcdir". (cherry picked from commit b89ed9d)
1 parent 35feda5 commit b24ecb7

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

Lib/test/libregrtest/main.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,13 @@ def set_temp_dir(self):
747747
if sysconfig.is_python_build():
748748
self.tmp_dir = sysconfig.get_config_var('abs_builddir')
749749
if self.tmp_dir is None:
750-
# gh-74470: On Windows, only srcdir is available. Using
751-
# abs_builddir mostly matters on UNIX when building Python
752-
# out of the source tree, especially when the source tree
753-
# is read only.
754-
self.tmp_dir = sysconfig.get_config_var('srcdir')
750+
self.tmp_dir = sysconfig.get_config_var('abs_srcdir')
751+
if not self.tmp_dir:
752+
# gh-74470: On Windows, only srcdir is available. Using
753+
# abs_builddir mostly matters on UNIX when building
754+
# Python out of the source tree, especially when the
755+
# source tree is read only.
756+
self.tmp_dir = sysconfig.get_config_var('srcdir')
755757
self.tmp_dir = os.path.join(self.tmp_dir, 'build')
756758
else:
757759
self.tmp_dir = tempfile.gettempdir()

Lib/test/pythoninfo.py

+2
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ def collect_sysconfig(info_add):
516516
'Py_ENABLE_SHARED',
517517
'SHELL',
518518
'SOABI',
519+
'abs_builddir',
520+
'abs_srcdir',
519521
'prefix',
520522
):
521523
value = sysconfig.get_config_var(name)

Lib/test/test_support.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,13 @@ def recursive_function(depth):
767767
#self.assertEqual(available, 2)
768768

769769
def test_copy_python_src_ignore(self):
770-
src_dir = sysconfig.get_config_var('srcdir')
770+
src_dir = sysconfig.get_config_var('abs_srcdir')
771+
if not src_dir:
772+
src_dir = sysconfig.get_config_var('srcdir')
771773
src_dir = os.path.abspath(src_dir)
774+
if not os.path.exists(src_dir):
775+
self.skipTest(f"cannot access Python source code directory:"
776+
f" {src_dir!r}")
772777

773778
ignored = {'.git', '__pycache__'}
774779

Tools/freeze/test/freeze.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
from test import support
88

99

10+
def get_python_source_dir():
11+
src_dir = sysconfig.get_config_var('abs_srcdir')
12+
if not src_dir:
13+
src_dir = sysconfig.get_config_var('srcdir')
14+
return os.path.abspath(src_dir)
15+
16+
1017
TESTS_DIR = os.path.dirname(__file__)
1118
TOOL_ROOT = os.path.dirname(TESTS_DIR)
12-
SRCDIR = os.path.abspath(sysconfig.get_config_var('srcdir'))
19+
SRCDIR = get_python_source_dir()
1320

1421
MAKE = shutil.which('make')
1522
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')

Tools/patchcheck/patchcheck.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111
import untabify
1212

1313

14+
def get_python_source_dir():
15+
src_dir = sysconfig.get_config_var('abs_srcdir')
16+
if not src_dir:
17+
src_dir = sysconfig.get_config_var('srcdir')
18+
return os.path.abspath(src_dir)
19+
20+
1421
# Excluded directories which are copies of external libraries:
1522
# don't check their coding style
1623
EXCLUDE_DIRS = [
1724
os.path.join('Modules', '_decimal', 'libmpdec'),
1825
os.path.join('Modules', 'expat'),
1926
os.path.join('Modules', 'zlib'),
2027
]
21-
SRCDIR = sysconfig.get_config_var('srcdir')
28+
SRCDIR = get_python_source_dir()
2229

2330

2431
def n_files_str(count):

0 commit comments

Comments
 (0)