Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Python version usage #4524

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
- Clean up Variables: more consistently call them variables (finish the
old change from Options) in docstrings, etc.; some typing and other
tweaks. Update manpage and user guide for Variables usage.
- Regularize internal usage of Python version strings and drop one
old Python 2-only code block in a test.


RELEASE 4.7.0 - Sun, 17 Mar 2024 17:22:20 -0700
Expand Down
4 changes: 2 additions & 2 deletions SCons/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,10 @@ def scons_subproc_run(scons_env, *args, **kwargs) -> subprocess.CompletedProcess
kwargs['check'] = check

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

if 'capture_output' in kwargs and sys.version_info[:3] < (3, 7):
if 'capture_output' in kwargs and sys.version_info < (3, 7):
capture_output = kwargs.pop('capture_output')
if capture_output:
kwargs['stdout'] = kwargs['stderr'] = PIPE
Expand Down
2 changes: 1 addition & 1 deletion scripts/scons-configure-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# python compatibility check
if sys.version_info < (3, 6, 0):
msg = "scons: *** SCons version %s does not run under Python version %s.\n\
Python >= 3.5 is required.\n"
Python >= 3.6.0 is required.\n"
sys.stderr.write(msg % (__version__, sys.version.split()[0]))
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion scripts/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# Python compatibility check
if sys.version_info < (3, 6, 0):
msg = "scons: *** SCons version %s does not run under Python version %s.\n\
Python >= 3.5 is required.\n"
Python >= 3.6.0 is required.\n"
sys.stderr.write(msg % (__version__, sys.version.split()[0]))
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion scripts/sconsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# python compatibility check
if sys.version_info < (3, 6, 0):
msg = "scons: *** SCons version %s does not run under Python version %s.\n\
Python >= 3.5 is required.\n"
Python >= 3.6.0 is required.\n"
sys.stderr.write(msg % (__version__, sys.version.split()[0]))
sys.exit(1)

Expand Down
10 changes: 5 additions & 5 deletions test/Execute.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
# __COPYRIGHT__
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
Expand All @@ -20,15 +22,13 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

"""
Test the Execute() function for executing actions directly.
"""
import sys
import TestSCons
from TestCmd import IS_WINDOWS

_python_ = TestSCons._python_

Expand Down Expand Up @@ -83,7 +83,7 @@
test.write('l.in', "l.in\n")
test.write('m.in', "m.in\n")

if sys.platform == 'win32' and sys.version_info[0] == 3:
if IS_WINDOWS:
expect = r"""scons: \*\*\* Error 1
scons: \*\*\* Error 2
scons: \*\*\* nonexistent.in: (The system cannot find the path specified|Das System kann den angegebenen Pfad nicht finden)"""
Expand Down
47 changes: 18 additions & 29 deletions test/SWIG/recursive-includes-cpp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
# __COPYRIGHT__
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
Expand All @@ -20,9 +22,6 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

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

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

test.write("recursive.h", """\
/* An empty header file. */
Expand Down Expand Up @@ -79,37 +77,28 @@
TARGET_ARCH = "TARGET_ARCH = 'x86',"
else:
TARGET_ARCH = ""
test.write('SConstruct', """\
import sysconfig
import sys
test.write('SConstruct', f"""\
import os
import sys
import sysconfig

DefaultEnvironment()
env = Environment(
""" + TARGET_ARCH + """
SWIGFLAGS = [
'-python'
],
CPPPATH = [
sysconfig.get_config_var("INCLUDEPY")
],
SHLIBPREFIX = "",
tools = [ 'default', 'swig' ]
{TARGET_ARCH}
SWIGFLAGS=['-python'],
CPPPATH=[sysconfig.get_config_var("INCLUDEPY")],
SHLIBPREFIX="",
tools=['default', 'swig'],
)

if sys.platform == 'darwin':
env['LIBS']=['python%d.%d'%(sys.version_info[0],sys.version_info[1])]
env['LIBS'] = [f'python{sys.version_info.major}.{sys.version_info.minor}']
env.Append(LIBPATH=[sysconfig.get_config_var("LIBDIR")])
elif sys.platform == 'win32':
env.Append(LIBS=['python%d%d'%(sys.version_info[0],sys.version_info[1])])
env.Append(LIBS=[f'python{sys.version_info.major}{sys.version_info.minor}.lib'])
env.Append(LIBPATH=[os.path.dirname(sys.executable) + "/libs"])

env.SharedLibrary(
'mod',
[
"mod.i",
"main.c",
]
)
env.SharedLibrary('mod', ["mod.i", "main.c"])
""")

if sys.platform == 'win32':
Expand Down
44 changes: 3 additions & 41 deletions test/option/option-j.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
# __COPYRIGHT__
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
Expand All @@ -20,15 +22,12 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

"""
This tests the -j command line option, and the num_jobs
SConscript settable option.
"""

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

import os.path
import sys

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

if sys.platform != 'win32' and sys.version_info[0] == 2:
# Test breaks on win32 when using real subprocess is not the only
# package to import threading
#
# Test that we fall back and warn properly if there's no threading.py
# module (simulated), which is the case if this version of Python wasn't
# built with threading support.

test.subdir('pythonlib')

test.write(['pythonlib', 'threading.py'], "raise ImportError\n")

save_pythonpath = os.environ.get('PYTHONPATH', '')
os.environ['PYTHONPATH'] = test.workpath('pythonlib')

#start2, finish1 = RunTest('-j 2 f1, f2', "fifth")

test.write('f1.in', 'f1.in pythonlib\n')
test.write('f2.in', 'f2.in pythonlib\n')

test.run(arguments = "-j 2 f1 f2", stderr=None)

warn = """scons: warning: parallel builds are unsupported by this version of Python;
\tignoring -j or num_jobs option."""
test.must_contain_all_lines(test.stderr(), [warn])

str = test.read("f1", mode='r')
start1,finish1 = list(map(float, str.split("\n")))

str = test.read("f2", mode='r')
start2,finish2 = list(map(float, str.split("\n")))

test.fail_test(start2 < finish1)

os.environ['PYTHONPATH'] = save_pythonpath


# Test SetJobs() with no -j:
test.write('SConstruct', """
DefaultEnvironment(tools=[])
Expand Down
3 changes: 0 additions & 3 deletions testing/framework/TestRuntest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ def __init__(self, **kw) -> None:
kw['program'] = 'runtest.py'
if 'interpreter' not in kw:
kw['interpreter'] = [python,]
if sys.version_info[0] < 3:
kw['interpreter'].append('-tt')

if 'match' not in kw:
kw['match'] = match_exact
if 'workdir' not in kw:
Expand Down
11 changes: 2 additions & 9 deletions testing/framework/TestSCons.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,17 +752,10 @@ def get_sconsignname(self):
def unlink_sconsignfile(self, name: str='.sconsign.dblite') -> None:
"""Delete the sconsign file.

Note on python it seems to append .p3 to the file name so we take
care of that.

TODO the above seems to not be an issue any more.

Args:
name: expected name of sconsign file
"""
if sys.version_info[0] == 3:
name += '.p3'
self.unlink(name)
return self.unlink(name)

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

return (python, incpath, libpath, libname)
return (python, incpath, libpath, libname + _lib)

def start(self, *args, **kw):
"""
Expand Down
Loading