From 8dff0099875bdc8e9f526c8a3ee9baf3b9fc6a5f Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 1 Feb 2022 19:55:53 +0000 Subject: Fixup DummyPopen() ( which is returned from Action._subproc() when subprocess.POpen() errors) so that it can also be used as a context manager. This is part of fixing Python 3.9(+) outputing warnings when file/other handles aren't properly closed. --- CHANGES.txt | 4 ++++ RELEASE.txt | 2 ++ SCons/Action.py | 6 ++++++ test/Variables/Variables.py | 7 +++---- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index c4245ca..005b0a4 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -22,6 +22,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER the signature of a Python Action Function. - Fix a number of Python ResourceWarnings which are issued when running SCons and/or it's tests with python 3.9 (or higher) + - Action._subproc() can now be used as a python context manager to ensure that the + POpen object is properly closed. + (Thanks to Mats Wichmann for catching that DummyPopen needed additional logic) + From Daniel Moody: - Add cache-debug messages for push failures. diff --git a/RELEASE.txt b/RELEASE.txt index c626179..6c26a34 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -28,6 +28,8 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY location for a site_scons. %AllUsersProfile%\Application Data\scons\site_scons will continue to work. There does not seem to be any convention to use an "Application Data" subdirectory here. +- Action._subproc() can now be used as a python context manager to ensure that the + POpen object is properly closed. FIXES diff --git a/SCons/Action.py b/SCons/Action.py index 67eeb1d..cf17181 100644 --- a/SCons/Action.py +++ b/SCons/Action.py @@ -800,6 +800,12 @@ def _subproc(scons_env, cmd, error='ignore', **kw): # return a dummy Popen instance that only returns error class dummyPopen: def __init__(self, e): self.exception = e + # Add the following two to enable using the return value as a context manager + # for example + # with Action._subproc(...) as po: + # logic here which uses po + def __enter__(self): return self + def __exit__(self, *args): pass def communicate(self, input=None): return ('', '') def wait(self): return -self.exception.errno stdin = None diff --git a/test/Variables/Variables.py b/test/Variables/Variables.py index 09a17d5..bb7b237 100644 --- a/test/Variables/Variables.py +++ b/test/Variables/Variables.py @@ -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 @@ -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__" import TestSCons -- cgit v0.12