Skip to content
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
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
- runtest.py once again finds "external" tests, such as the tests for
tools in scons-contrib. An earlier rework had broken this. Fixes #4699.
- Clarify how pre/post actions on an alias work.
- Replace use of old conditional expression idioms with the official
one from PEP 308 introduced in Python 2.5 (2006). The idiom being
replaced (using and/or) is regarded as error prone.


RELEASE 4.9.1 - Thu, 27 Mar 2025 11:40:20 -0700
Expand Down
4 changes: 4 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY

- Nodes are now treated as PathLike objects.

- Replace use of old conditional expression idioms with the official
one from PEP 308 introduced in Python 2.5 (2006). The idiom being
replaced (using and/or) is regarded as error prone.

FIXES
-----

Expand Down
2 changes: 1 addition & 1 deletion SCons/Builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def set_src_suffix(self, src_suffix) -> None:
src_suffix = []
elif not SCons.Util.is_List(src_suffix):
src_suffix = [ src_suffix ]
self.src_suffix = [callable(suf) and suf or self.adjust_suffix(suf) for suf in src_suffix]
self.src_suffix = [suf if callable(suf) else self.adjust_suffix(suf) for suf in src_suffix]

def get_src_suffix(self, env):
"""Get the first src_suffix in the list of src_suffixes."""
Expand Down
15 changes: 12 additions & 3 deletions SCons/Script/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,28 @@ def __init__(self, derived: bool=False, prune: bool=False, status: bool=False, s
self.prune = prune
self.status = status
self.sLineDraw = sLineDraw

def get_all_children(self, node):
return node.all_children()

def get_derived_children(self, node):
children = node.all_children(None)
return [x for x in children if x.has_builder()]

def display(self, t) -> None:
if self.derived:
func = self.get_derived_children
else:
func = self.get_all_children
s = self.status and 2 or 0
SCons.Util.print_tree(t, func, prune=self.prune, showtags=s, lastChild=True, singleLineDraw=self.sLineDraw)

s = 2 if self.status else 0
SCons.Util.print_tree(
t,
func,
prune=self.prune,
showtags=s,
lastChild=True,
singleLineDraw=self.sLineDraw,
)

def python_version_string():
return sys.version.split()[0]
Expand Down
2 changes: 1 addition & 1 deletion SCons/Tool/linkCommon/SharedLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def setup_shared_lib_logic(env) -> None:

# Note this is gnu style
env["SHLIBSONAMEFLAGS"] = "-Wl,-soname=$_SHLIBSONAME"
env["_SHLIBVERSION"] = "${SHLIBVERSION and '.'+SHLIBVERSION or ''}"
env["_SHLIBVERSION"] = "${'.' + SHLIBVERSION if SHLIBVERSION else ''}"
env["_SHLIBVERSIONFLAGS"] = "$SHLIBVERSIONFLAGS -Wl,-soname=$_SHLIBSONAME"

env["SHLIBEMITTER"] = [lib_emitter, shlib_symlink_emitter]
Expand Down
8 changes: 4 additions & 4 deletions SCons/Tool/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def msvc_set_PCHPDBFLAGS(env) -> None:
if env.get('MSVC_VERSION',False):
maj, min = msvc_version_to_maj_min(env['MSVC_VERSION'])
if maj < 8:
env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Yd") or ""}'])
env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${"/Yd" if PDB else ""}'])
else:
env['PCHPDBFLAGS'] = ''
else:
# Default if we can't determine which version of MSVC we're using
env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Yd") or ""}'])
env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${"/Yd" if PDB else ""}'])


def pch_emitter(target, source, env):
Expand Down Expand Up @@ -143,7 +143,7 @@ def gen_ccpchflags(env, target, source, for_signature):
pch_node = get_pch_node(env, target, source)
if not pch_node:
return ''

return SCons.Util.CLVar(["/Yu$PCHSTOP", "/Fp%s" % pch_node])

pch_action = SCons.Action.Action('$PCHCOM', '$PCHCOMSTR')
Expand Down Expand Up @@ -256,7 +256,7 @@ def generate(env) -> None:
static_obj.add_emitter(suffix, static_object_emitter)
shared_obj.add_emitter(suffix, shared_object_emitter)

env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}'])
env['CCPDBFLAGS'] = SCons.Util.CLVar(['${"/Z7" if PDB else ""}'])
env['CCPCHFLAGS'] = gen_ccpchflags
env['_MSVC_OUTPUT_FLAG'] = msvc_output_flag
env['_CCCOMCOM'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $CCPCHFLAGS $CCPDBFLAGS'
Expand Down
4 changes: 3 additions & 1 deletion bin/scons-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ def simple_diff(a, b, fromfile='', tofile='',
output like the simple, unadorned 'diff" command.
"""
sm = difflib.SequenceMatcher(None, a, b)

def comma(x1, x2):
return x1+1 == x2 and str(x2) or '%s,%s' % (x1+1, x2)
return x1 + 1 == str(x2) if x2 else '%s,%s' % (x1 + 1, x2)

result = []
for op, a1, a2, b1, b2 in sm.get_opcodes():
if op == 'delete':
Expand Down
2 changes: 1 addition & 1 deletion bin/update-release-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def set_new_date(self):
Mon, 05 Jun 2010 21:17:15 -0700
NEW DATE WILL BE INSERTED HERE
"""
min = (time.daylight and time.altzone or time.timezone) // 60
min = (time.altzone if time.daylight else time.timezone) // 60
hr = min // 60
min = -(min % 60 + hr * 100)
self.new_date = (time.strftime('%a, %d %b %Y %X', self.release_date + (0, 0, 0))
Expand Down
2 changes: 1 addition & 1 deletion site_scons/BuildCommandLine.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def set_date(self):
NEW DATE WILL BE INSERTED HERE
"""

min = (time.daylight and time.altzone or time.timezone) // 60
min = (time.altzone if time.daylight else time.timezone) // 60
hr = min // 60
min = -(min % 60 + hr * 100)
# TODO: is it better to take the date of last rev? Externally:
Expand Down
2 changes: 1 addition & 1 deletion test/Actions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def foo(b=b):
def runtest(arguments, expectedOutFile, expectedRebuild=True, stderr=""):
test.run(
arguments=arguments,
stdout=expectedRebuild and rebuildstr or nobuildstr,
stdout=rebuildstr if expectedRebuild else nobuildstr,
stderr="",
)

Expand Down
17 changes: 10 additions & 7 deletions test/SPAWN.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
ofp.write(ifp.read())
""")

test.write('SConstruct', """
test.write('SConstruct', """\
import subprocess
import sys

Expand All @@ -56,16 +56,19 @@ def my_spawn2(sh, escape, cmd, args, env):
cp = subprocess.run(s, shell=True)
return cp.returncode

env = Environment(MY_SPAWN1 = my_spawn1,
MY_SPAWN2 = my_spawn2,
COMMAND = r'%(_python_)s cat.py $TARGET $SOURCES')
env1 = env.Clone(SPAWN = my_spawn1)
DefaultEnvironment()
env = Environment(
MY_SPAWN1=my_spawn1,
MY_SPAWN2=my_spawn2,
COMMAND=r'%(_python_)s cat.py $TARGET $SOURCES',
)
env1 = env.Clone(SPAWN=my_spawn1)
env1.Command('file1.out', 'file1.in', '$COMMAND')

env2 = env.Clone(SPAWN = '$MY_SPAWN2')
env2 = env.Clone(SPAWN='$MY_SPAWN2')
env2.Command('file2.out', 'file2.in', '$COMMAND')

env3 = env.Clone(SPAWN = '${USE_TWO and MY_SPAWN2 or MY_SPAWN1}')
env3 = env.Clone(SPAWN='${MY_SPAWN2 if USE_TWO else MY_SPAWN1}')
env3.Command('file3.out', 'file3.in', '$COMMAND', USE_TWO=0)
env3.Command('file4.out', 'file4.in', '$COMMAND', USE_TWO=1)
""" % locals())
Expand Down
6 changes: 3 additions & 3 deletions test/option/help-options.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
lines = stdout.split('\n')
lines = [x for x in lines if x[:3] == ' -']
lines = [x[3:] for x in lines]
lines = [x[0] == '-' and x[1:] or x for x in lines]
lines = [x[1:] if x.startswith('-') else x for x in lines]
options = [x.split()[0] for x in lines]
options = [x[-1] == ',' and x[:-1] or x for x in options]
options = [x[:-1] if x.endswith(',') else x for x in options]
lowered = [x.lower() for x in options]
ordered = sorted(lowered)
if lowered != ordered:
Expand All @@ -65,7 +65,7 @@
test.fail_test()

test.pass_test()


# Local Variables:
# tab-width:4
Expand Down
2 changes: 1 addition & 1 deletion testing/framework/TestCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def simple_diff(
sm = difflib.SequenceMatcher(None, a, b)

def comma(x1, x2):
return x1 + 1 == x2 and str(x2) or f'{x1 + 1},{x2}'
return str(x2) if x1 + 1 == x2 else f'{x1 + 1},{x2}'

for op, a1, a2, b1, b2 in sm.get_opcodes():
if op == 'delete':
Expand Down
12 changes: 6 additions & 6 deletions testing/framework/TestCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def must_be_writable(self, *files) -> None:
them. Exits FAILED if any of the files does not exist or is
not writable.
"""
flist = [is_List(x) and os.path.join(*x) or x for x in files]
flist = [os.path.join(*x) if is_List(x) else x for x in files]
existing, missing = separate_files(flist)
unwritable = [x for x in existing if not is_writable(x)]
if missing:
Expand Down Expand Up @@ -531,7 +531,7 @@ def must_exist(self, *files, message: str = "") -> None:
pathname will be constructed by concatenating them. Exits FAILED
if any of the files does not exist.
"""
flist = [is_List(x) and os.path.join(*x) or x for x in files]
flist = [os.path.join(*x) if is_List(x) else x for x in files]
missing = [x for x in flist if not os.path.exists(x) and not os.path.islink(x)]
if missing:
print("Missing files: `%s'" % "', `".join(missing))
Expand All @@ -550,7 +550,7 @@ def must_exist_one_of(self, files, message: str = "") -> None:
if is_List(x) or is_Tuple(x):
xpath = os.path.join(*x)
else:
xpath = is_Sequence(x) and os.path.join(x) or x
xpath = os.path.join(x) if is_Sequence(x) else x
if glob.glob(xpath):
return
missing.append(xpath)
Expand Down Expand Up @@ -669,7 +669,7 @@ def must_not_exist(self, *files) -> None:
which case the pathname will be constructed by concatenating them.
Exits FAILED if any of the files exists.
"""
flist = [is_List(x) and os.path.join(*x) or x for x in files]
flist = [os.path.join(*x) if is_List(x) else x for x in files]
existing = [x for x in flist if os.path.exists(x) or os.path.islink(x)]
if existing:
print("Unexpected files exist: `%s'" % "', `".join(existing))
Expand All @@ -688,7 +688,7 @@ def must_not_exist_any_of(self, files) -> None:
if is_List(x) or is_Tuple(x):
xpath = os.path.join(*x)
else:
xpath = is_Sequence(x) and os.path.join(x) or x
xpath = os.path.join(x) if is_Sequence(x) else x
if glob.glob(xpath):
existing.append(xpath)
if existing:
Expand Down Expand Up @@ -719,7 +719,7 @@ def must_not_be_writable(self, *files) -> None:
them. Exits FAILED if any of the files does not exist or is
writable.
"""
flist = [is_List(x) and os.path.join(*x) or x for x in files]
flist = [os.path.join(*x) if is_List(x) else x for x in files]
existing, missing = separate_files(flist)
writable = [file for file in existing if is_writable(file)]
if missing:
Expand Down
Loading