Skip to content

Commit 17ca4e1

Browse files
authored
[3.6] Improves the ability to build in CI (GH-5730)
1 parent c1b8aed commit 17ca4e1

5 files changed

Lines changed: 21 additions & 13 deletions

File tree

Lib/test/support/script_helper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def interpreter_requires_environment():
3939
"""
4040
global __cached_interp_requires_environment
4141
if __cached_interp_requires_environment is None:
42+
# If PYTHONHOME is set, assume that we need it
43+
if 'PYTHONHOME' in os.environ:
44+
__cached_interp_requires_environment = True
45+
return True
46+
4247
# Try running an interpreter with -E to see if it works or not.
4348
try:
4449
subprocess.check_call([sys.executable, '-E',
@@ -165,7 +170,9 @@ def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
165170
kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
166171
object.
167172
"""
168-
cmd_line = [sys.executable, '-E']
173+
cmd_line = [sys.executable]
174+
if not interpreter_requires_environment():
175+
cmd_line.append('-E')
169176
cmd_line.extend(args)
170177
# Under Fedora (?), GNU readline can output junk on stderr when initialized,
171178
# depending on the TERM setting. Setting TERM=vt100 is supposed to disable

Lib/test/test_cmd_line.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import tempfile
1111
from test.support import script_helper, is_android
1212
from test.support.script_helper import (spawn_python, kill_python, assert_python_ok,
13-
assert_python_failure)
13+
assert_python_failure, interpreter_requires_environment)
1414

1515

1616
# XXX (ncoghlan): Move to script_helper and make consistent with run_python
@@ -57,6 +57,8 @@ def test_verbose(self):
5757
rc, out, err = assert_python_ok('-vv')
5858
self.assertNotIn(b'stack overflow', err)
5959

60+
@unittest.skipIf(interpreter_requires_environment(),
61+
'Cannot run -E tests when PYTHON env vars are required.')
6062
def test_xoptions(self):
6163
def get_xoptions(*args):
6264
# use subprocess module directly because test.support.script_helper adds
@@ -272,11 +274,7 @@ def test_empty_PYTHONPATH_issue16309(self):
272274

273275
def test_displayhook_unencodable(self):
274276
for encoding in ('ascii', 'latin-1', 'utf-8'):
275-
# We are testing a PYTHON environment variable here, so we can't
276-
# use -E, -I, or script_helper (which uses them). So instead we do
277-
# poor-man's isolation by deleting the PYTHON vars from env.
278-
env = {key:value for (key,value) in os.environ.copy().items()
279-
if not key.startswith('PYTHON')}
277+
env = os.environ.copy()
280278
env['PYTHONIOENCODING'] = encoding
281279
p = subprocess.Popen(
282280
[sys.executable, '-i'],
@@ -491,6 +489,7 @@ def test_isolatedmode(self):
491489
cwd=tmpdir)
492490
self.assertEqual(out.strip(), b"ok")
493491

492+
494493
def test_main():
495494
test.support.run_unittest(CmdLineTest)
496495
test.support.reap_children()

PCbuild/find_python.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
@if exist "%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe" (set PYTHON="%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe") & (set _Py_Python_Source=found in externals directory) & goto :found
3232

3333
@rem If HOST_PYTHON is recent enough, use that
34-
@if NOT "%HOST_PYTHON%"=="" @%HOST_PYTHON% -c "import sys; assert sys.version_info[:2] >= (3, 6)" >nul 2>nul && (set PYTHON="%HOST_PYTHON%") && (set _Py_Python_Source=found as HOST_PYTHON) && goto :found
34+
@if NOT "%HOST_PYTHON%"=="" @%HOST_PYTHON% -Ec "import sys; assert sys.version_info[:2] >= (3, 6)" >nul 2>nul && (set PYTHON="%HOST_PYTHON%") && (set _Py_Python_Source=found as HOST_PYTHON) && goto :found
3535

3636
@rem If py.exe finds a recent enough version, use that one
37-
@py -3.6 -V >nul 2>&1 && (set PYTHON=py -3.6) && (set _Py_Python_Source=found with py.exe) && goto :found
37+
@py -3.6 -EV >nul 2>&1 && (set PYTHON=py -3.6) && (set _Py_Python_Source=found with py.exe) && goto :found
3838

3939
@if NOT exist "%_Py_EXTERNALS_DIR%" mkdir "%_Py_EXTERNALS_DIR%"
4040
@set _Py_NUGET=%NUGET%
@@ -50,7 +50,7 @@
5050
@rem If it fails, retry with any available copy of Python
5151
@powershell.exe -Command Invoke-WebRequest %_Py_NUGET_URL% -OutFile '%_Py_NUGET%'
5252
@if errorlevel 1 (
53-
@%_Py_HOST_PYTHON% "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
53+
@%_Py_HOST_PYTHON% -E "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
5454
)
5555
)
5656
@echo Installing Python via nuget...

PCbuild/get_externals.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ for %%e in (%libraries%) do (
5656
git clone --depth 1 https://github.com/%ORG%/cpython-source-deps --branch %%e "%EXTERNALS_DIR%\%%e"
5757
) else (
5858
echo.Fetching %%e...
59-
%PYTHON% "%PCBUILD%\get_external.py" -O %ORG% %%e
59+
%PYTHON% -E "%PCBUILD%\get_external.py" -O %ORG% -e "%EXTERNALS_DIR%" %%e
6060
)
6161
)
6262

@@ -74,7 +74,7 @@ for %%b in (%binaries%) do (
7474
git clone --depth 1 https://github.com/%ORG%/cpython-bin-deps --branch %%b "%EXTERNALS_DIR%\%%b"
7575
) else (
7676
echo.Fetching %%b...
77-
%PYTHON% "%PCBUILD%\get_external.py" -b -O %ORG% %%b
77+
%PYTHON% -E "%PCBUILD%\get_external.py" -b -O %ORG% -e "%EXTERNALS_DIR%" %%b
7878
)
7979
)
8080

PCbuild/python.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
<BuildPath Condition="$(Configuration) == 'PGInstrument'">$(BuildPath)instrumented\</BuildPath>
4444

4545
<!-- Directories of external projects. tcltk is handled in tcltk.props -->
46-
<ExternalsDir>$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals\`))</ExternalsDir>
46+
<ExternalsDir>$(EXTERNALS_DIR)</ExternalsDir>
47+
<ExternalsDir Condition="$(ExternalsDir) == ''">$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals`))</ExternalsDir>
48+
<ExternalsDir Condition="!HasTrailingSlash($(ExternalsDir))">$(ExternalsDir)\</ExternalsDir>
4749
<sqlite3Dir>$(ExternalsDir)sqlite-3.21.0.0\</sqlite3Dir>
4850
<bz2Dir>$(ExternalsDir)bzip2-1.0.6\</bz2Dir>
4951
<lzmaDir>$(ExternalsDir)xz-5.2.2\</lzmaDir>

0 commit comments

Comments
 (0)