diff --git a/CHANGES.txt b/CHANGES.txt index e938a74adb..ee2657ba1c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,10 @@ NOTE: 4.3.0 now requires Python 3.6.0 and above. Python 3.5.x is no longer suppo RELEASE VERSION/DATE TO BE FILLED IN LATER + From Thaddeus Crews: + - GetSConsVersion() to grab the latest SCons version without needing to + dig into private functions. + From Raymond Li: - Fix issue #3935: OSErrors are now no longer hidden during execution of Actions. All exceptions during the execution of an Action are now diff --git a/RELEASE.txt b/RELEASE.txt index 12d4b07940..650288043f 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -16,7 +16,7 @@ Here is a summary of the changes since 4.7.0: NEW FUNCTIONALITY ----------------- -- List new features (presumably why a checkpoint is being released) +- GetSConsVersion() to grab the current SCons version from an exposed api. DEPRECATED FUNCTIONALITY ------------------------ diff --git a/SCons/Script/SConscript.py b/SCons/Script/SConscript.py index 85070ab053..a2ef3b9d57 100644 --- a/SCons/Script/SConscript.py +++ b/SCons/Script/SConscript.py @@ -45,6 +45,7 @@ import sys import traceback import time +from typing import Tuple class SConscriptReturn(Exception): pass @@ -385,7 +386,7 @@ class SConsEnvironment(SCons.Environment.Base): # Private methods of an SConsEnvironment. # @staticmethod - def _get_major_minor_revision(version_string): + def _get_major_minor_revision(version_string: str) -> Tuple[int, int, int]: """Split a version string into major, minor and (optionally) revision parts. @@ -484,15 +485,22 @@ def Default(self, *targets) -> None: SCons.Script._Set_Default_Targets(self, targets) @staticmethod - def EnsureSConsVersion(major, minor, revision: int=0) -> None: + def GetSConsVersion() -> Tuple[int, int, int]: + """Return the current SCons version. + + .. versionadded:: 4.8.0 + """ + return SConsEnvironment._get_major_minor_revision(SCons.__version__) + + @staticmethod + def EnsureSConsVersion(major: int, minor: int, revision: int = 0) -> None: """Exit abnormally if the SCons version is not late enough.""" # split string to avoid replacement during build process if SCons.__version__ == '__' + 'VERSION__': SCons.Warnings.warn(SCons.Warnings.DevelopmentVersionWarning, "EnsureSConsVersion is ignored for development version") return - scons_ver = SConsEnvironment._get_major_minor_revision(SCons.__version__) - if scons_ver < (major, minor, revision): + if SConsEnvironment.GetSConsVersion() < (major, minor, revision): if revision: scons_ver_string = '%d.%d.%d' % (major, minor, revision) else: diff --git a/SCons/Script/__init__.py b/SCons/Script/__init__.py index a62650f7f6..ce0105573c 100644 --- a/SCons/Script/__init__.py +++ b/SCons/Script/__init__.py @@ -297,6 +297,7 @@ def Variables(files=None, args=ARGUMENTS): # # Static functions that do not trigger initialization of # DefaultEnvironment() and don't use its state. +GetSConsVersion = _SConscript.SConsEnvironment.GetSConsVersion EnsureSConsVersion = _SConscript.SConsEnvironment.EnsureSConsVersion EnsurePythonVersion = _SConscript.SConsEnvironment.EnsurePythonVersion Exit = _SConscript.SConsEnvironment.Exit diff --git a/test/EnsureSConsVersion.py b/test/EnsureSConsVersion.py index 7eae2ad9cd..9da88d8b30 100644 --- a/test/EnsureSConsVersion.py +++ b/test/EnsureSConsVersion.py @@ -63,6 +63,14 @@ test.run(status=2) + test.write('SConstruct', """\ +env = Environment() +env.EnsureSConsVersion(env.GetSConsVersion()) +Exit(0) +""") + + test.run() + test.write('SConstruct', """\ @@ -121,6 +129,12 @@ test.run(status=2) +test.write('SConstruct', """\ +import SCons +EnsureSConsVersion(GetSConsVersion()) +""") + +test.run() test.pass_test()