Skip to content

Commit c0f742e

Browse files
authored
Merge pull request SCons#4524 from mwichmann/maint/py-versions
Maintenance: Python version usage
2 parents 3e6a7ac + 882ccb6 commit c0f742e

File tree

10 files changed

+35
-92
lines changed

10 files changed

+35
-92
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
5858
- Clean up Variables: more consistently call them variables (finish the
5959
old change from Options) in docstrings, etc.; some typing and other
6060
tweaks. Update manpage and user guide for Variables usage.
61+
- Regularize internal usage of Python version strings and drop one
62+
old Python 2-only code block in a test.
6163

6264

6365
RELEASE 4.7.0 - Sun, 17 Mar 2024 17:22:20 -0700

SCons/Action.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,10 @@ def scons_subproc_run(scons_env, *args, **kwargs) -> subprocess.CompletedProcess
892892
kwargs['check'] = check
893893

894894
# TODO: Python version-compat stuff: remap/remove too-new args if needed
895-
if 'text' in kwargs and sys.version_info[:3] < (3, 7):
895+
if 'text' in kwargs and sys.version_info < (3, 7):
896896
kwargs['universal_newlines'] = kwargs.pop('text')
897897

898-
if 'capture_output' in kwargs and sys.version_info[:3] < (3, 7):
898+
if 'capture_output' in kwargs and sys.version_info < (3, 7):
899899
capture_output = kwargs.pop('capture_output')
900900
if capture_output:
901901
kwargs['stdout'] = kwargs['stderr'] = PIPE

scripts/scons-configure-cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# python compatibility check
5252
if sys.version_info < (3, 6, 0):
5353
msg = "scons: *** SCons version %s does not run under Python version %s.\n\
54-
Python >= 3.5 is required.\n"
54+
Python >= 3.6.0 is required.\n"
5555
sys.stderr.write(msg % (__version__, sys.version.split()[0]))
5656
sys.exit(1)
5757

scripts/scons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# Python compatibility check
4545
if sys.version_info < (3, 6, 0):
4646
msg = "scons: *** SCons version %s does not run under Python version %s.\n\
47-
Python >= 3.5 is required.\n"
47+
Python >= 3.6.0 is required.\n"
4848
sys.stderr.write(msg % (__version__, sys.version.split()[0]))
4949
sys.exit(1)
5050

scripts/sconsign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# python compatibility check
4444
if sys.version_info < (3, 6, 0):
4545
msg = "scons: *** SCons version %s does not run under Python version %s.\n\
46-
Python >= 3.5 is required.\n"
46+
Python >= 3.6.0 is required.\n"
4747
sys.stderr.write(msg % (__version__, sys.version.split()[0]))
4848
sys.exit(1)
4949

test/Execute.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
#
3-
# __COPYRIGHT__
3+
# MIT License
4+
#
5+
# Copyright The SCons Foundation
46
#
57
# Permission is hereby granted, free of charge, to any person obtaining
68
# a copy of this software and associated documentation files (the
@@ -20,15 +22,13 @@
2022
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2123
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2224
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23-
#
24-
25-
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
2625

2726
"""
2827
Test the Execute() function for executing actions directly.
2928
"""
3029
import sys
3130
import TestSCons
31+
from TestCmd import IS_WINDOWS
3232

3333
_python_ = TestSCons._python_
3434

@@ -83,7 +83,7 @@
8383
test.write('l.in', "l.in\n")
8484
test.write('m.in', "m.in\n")
8585

86-
if sys.platform == 'win32' and sys.version_info[0] == 3:
86+
if IS_WINDOWS:
8787
expect = r"""scons: \*\*\* Error 1
8888
scons: \*\*\* Error 2
8989
scons: \*\*\* nonexistent.in: (The system cannot find the path specified|Das System kann den angegebenen Pfad nicht finden)"""

test/SWIG/recursive-includes-cpp.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
#
3-
# __COPYRIGHT__
3+
# MIT License
4+
#
5+
# Copyright The SCons Foundation
46
#
57
# Permission is hereby granted, free of charge, to any person obtaining
68
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
2022
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2123
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2224
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23-
#
24-
25-
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
2625

2726
"""
2827
Verify that SWIG include directives produce the correct dependencies
@@ -46,10 +45,9 @@
4645
python, python_include, python_libpath, python_lib = \
4746
test.get_platform_python_info(python_h_required=True)
4847

49-
if sys.platform == 'win32':
50-
python_lib = os.path.dirname(sys.executable) + "/libs/" + ('python%d%d'%(sys.version_info[0],sys.version_info[1])) + '.lib'
51-
if not os.path.isfile(python_lib):
52-
test.skip_test('Can not find python lib at "' + python_lib + '", skipping test.%s' % os.linesep)
48+
if TestCmd.IS_WINDOWS:
49+
if not os.path.isfile(os.path.join(python_libpath, python_lib)):
50+
test.skip_test(f"Can not find python lib {python_libh!r}, skipping test.\n")
5351

5452
test.write("recursive.h", """\
5553
/* An empty header file. */
@@ -79,37 +77,28 @@
7977
TARGET_ARCH = "TARGET_ARCH = 'x86',"
8078
else:
8179
TARGET_ARCH = ""
82-
test.write('SConstruct', """\
83-
import sysconfig
84-
import sys
80+
test.write('SConstruct', f"""\
8581
import os
82+
import sys
83+
import sysconfig
8684
85+
DefaultEnvironment()
8786
env = Environment(
88-
""" + TARGET_ARCH + """
89-
SWIGFLAGS = [
90-
'-python'
91-
],
92-
CPPPATH = [
93-
sysconfig.get_config_var("INCLUDEPY")
94-
],
95-
SHLIBPREFIX = "",
96-
tools = [ 'default', 'swig' ]
87+
{TARGET_ARCH}
88+
SWIGFLAGS=['-python'],
89+
CPPPATH=[sysconfig.get_config_var("INCLUDEPY")],
90+
SHLIBPREFIX="",
91+
tools=['default', 'swig'],
9792
)
9893
9994
if sys.platform == 'darwin':
100-
env['LIBS']=['python%d.%d'%(sys.version_info[0],sys.version_info[1])]
95+
env['LIBS'] = [f'python{sys.version_info.major}.{sys.version_info.minor}']
10196
env.Append(LIBPATH=[sysconfig.get_config_var("LIBDIR")])
10297
elif sys.platform == 'win32':
103-
env.Append(LIBS=['python%d%d'%(sys.version_info[0],sys.version_info[1])])
98+
env.Append(LIBS=[f'python{sys.version_info.major}{sys.version_info.minor}.lib'])
10499
env.Append(LIBPATH=[os.path.dirname(sys.executable) + "/libs"])
105100
106-
env.SharedLibrary(
107-
'mod',
108-
[
109-
"mod.i",
110-
"main.c",
111-
]
112-
)
101+
env.SharedLibrary('mod', ["mod.i", "main.c"])
113102
""")
114103

115104
if sys.platform == 'win32':

test/option/option-j.py

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
#
3-
# __COPYRIGHT__
3+
# MIT License
4+
#
5+
# Copyright The SCons Foundation
46
#
57
# Permission is hereby granted, free of charge, to any person obtaining
68
# a copy of this software and associated documentation files (the
@@ -20,15 +22,12 @@
2022
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2123
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2224
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23-
#
2425

2526
"""
2627
This tests the -j command line option, and the num_jobs
2728
SConscript settable option.
2829
"""
2930

30-
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
31-
3231
import os.path
3332
import sys
3433

@@ -122,43 +121,6 @@ def RunTest(args, extra):
122121
# succeeds.
123122
test.run(arguments='-j 2 out')
124123

125-
if sys.platform != 'win32' and sys.version_info[0] == 2:
126-
# Test breaks on win32 when using real subprocess is not the only
127-
# package to import threading
128-
#
129-
# Test that we fall back and warn properly if there's no threading.py
130-
# module (simulated), which is the case if this version of Python wasn't
131-
# built with threading support.
132-
133-
test.subdir('pythonlib')
134-
135-
test.write(['pythonlib', 'threading.py'], "raise ImportError\n")
136-
137-
save_pythonpath = os.environ.get('PYTHONPATH', '')
138-
os.environ['PYTHONPATH'] = test.workpath('pythonlib')
139-
140-
#start2, finish1 = RunTest('-j 2 f1, f2', "fifth")
141-
142-
test.write('f1.in', 'f1.in pythonlib\n')
143-
test.write('f2.in', 'f2.in pythonlib\n')
144-
145-
test.run(arguments = "-j 2 f1 f2", stderr=None)
146-
147-
warn = """scons: warning: parallel builds are unsupported by this version of Python;
148-
\tignoring -j or num_jobs option."""
149-
test.must_contain_all_lines(test.stderr(), [warn])
150-
151-
str = test.read("f1", mode='r')
152-
start1,finish1 = list(map(float, str.split("\n")))
153-
154-
str = test.read("f2", mode='r')
155-
start2,finish2 = list(map(float, str.split("\n")))
156-
157-
test.fail_test(start2 < finish1)
158-
159-
os.environ['PYTHONPATH'] = save_pythonpath
160-
161-
162124
# Test SetJobs() with no -j:
163125
test.write('SConstruct', """
164126
DefaultEnvironment(tools=[])

testing/framework/TestRuntest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ def __init__(self, **kw) -> None:
123123
kw['program'] = 'runtest.py'
124124
if 'interpreter' not in kw:
125125
kw['interpreter'] = [python,]
126-
if sys.version_info[0] < 3:
127-
kw['interpreter'].append('-tt')
128-
129126
if 'match' not in kw:
130127
kw['match'] = match_exact
131128
if 'workdir' not in kw:

testing/framework/TestSCons.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -752,17 +752,10 @@ def get_sconsignname(self):
752752
def unlink_sconsignfile(self, name: str='.sconsign.dblite') -> None:
753753
"""Delete the sconsign file.
754754
755-
Note on python it seems to append .p3 to the file name so we take
756-
care of that.
757-
758-
TODO the above seems to not be an issue any more.
759-
760755
Args:
761756
name: expected name of sconsign file
762757
"""
763-
if sys.version_info[0] == 3:
764-
name += '.p3'
765-
self.unlink(name)
758+
return self.unlink(name)
766759

767760
def java_ENV(self, version=None):
768761
""" Initialize JAVA SDK environment.
@@ -1621,7 +1614,7 @@ def venv_path():
16211614
if python_h == "False" and python_h_required:
16221615
self.skip_test('Can not find required "Python.h", skipping test.\n', from_fw=True)
16231616

1624-
return (python, incpath, libpath, libname)
1617+
return (python, incpath, libpath, libname + _lib)
16251618

16261619
def start(self, *args, **kw):
16271620
"""

0 commit comments

Comments
 (0)