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 @@ -15,6 +15,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
From John Doe:
- Whatever John Doe did.

From Thaddeus Crews:
- Nodes are now treated as PathLike objects.

From Mats Wichmann:
- Fix typos in CCFLAGS test. Didn't affect the test itself, but
didn't correctly apply the DefaultEnvironment speedup.
Expand Down
2 changes: 2 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
- List modifications to existing features, where the previous behavior
wouldn't actually be considered a bug

- Nodes are now treated as PathLike objects.

FIXES
-----

Expand Down
10 changes: 6 additions & 4 deletions SCons/Builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
from SCons.Debug import logInstanceCreation
from SCons.Errors import InternalError, UserError
from SCons.Executor import Executor
from SCons.Node import Node

class _Null:
pass
Expand Down Expand Up @@ -487,10 +488,11 @@ def _adjustixes(self, files, pre, suf, ensure_suffix: bool=False):
# fspath() is to catch PathLike paths. We avoid the simpler
# str(f) so as not to "lose" files that are already Nodes:
# TypeError: expected str, bytes or os.PathLike object, not File
with suppress(TypeError):
f = os.fspath(f)
if SCons.Util.is_String(f):
f = SCons.Util.adjustixes(f, pre, suf, ensure_suffix)
if not isinstance(f, Node):
with suppress(TypeError):
f = os.fspath(f)
if SCons.Util.is_String(f):
f = SCons.Util.adjustixes(f, pre, suf, ensure_suffix)
result.append(f)
return result

Expand Down
6 changes: 3 additions & 3 deletions SCons/BuilderTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def test_single_source(self) -> None:
"""Test Builder with single_source flag set"""
def func(target, source, env) -> None:
"""create the file"""
with open(str(target[0]), "w"):
with open(target[0], "w"):
pass
if len(source) == 1 and len(target) == 1:
env['CNT'][0] = env['CNT'][0] + 1
Expand Down Expand Up @@ -759,7 +759,7 @@ def test_lists(self) -> None:
"""Testing handling lists of targets and source"""
def function2(target, source, env, tlist = [outfile, outfile2], **kw) -> int:
for t in target:
with open(str(t), 'w') as f:
with open(t, 'w') as f:
f.write("function2\n")
for t in tlist:
if t not in list(map(str, target)):
Expand Down Expand Up @@ -790,7 +790,7 @@ def function2(target, source, env, tlist = [outfile, outfile2], **kw) -> int:

def function3(target, source, env, tlist = [sub1_out, sub2_out]) -> int:
for t in target:
with open(str(t), 'w') as f:
with open(t, 'w') as f:
f.write("function3\n")
for t in tlist:
if t not in list(map(str, target)):
Expand Down
4 changes: 2 additions & 2 deletions SCons/Environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ env.Command(

import os
def rename(env, target, source):
os.rename('.tmp', str(target[0]))
os.rename('.tmp', target[0])


env.Command(
Expand Down Expand Up @@ -3626,7 +3626,7 @@ def create(target, source, env):

Writes 'prefix=$SOURCE' into the file name given as $TARGET.
"""
with open(str(target[0]), 'wb') as f:
with open(target[0], 'wb') as f:
f.write(b'prefix=' + source[0].get_contents() + b'\n')

# Fetch the prefix= argument, if any, from the command line.
Expand Down
3 changes: 3 additions & 0 deletions SCons/Node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ def __init__(self) -> None:
# what line in what file created the node, for example).
Annotate(self)

def __fspath__(self) -> str:
return str(self)

def disambiguate(self, must_exist: bool = False):
return self

Expand Down
2 changes: 1 addition & 1 deletion SCons/SConfTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_TryAction(self) -> None:
"""Test SConf.TryAction
"""
def actionOK(target, source, env):
with open(str(target[0]), "w") as f:
with open(target[0], "w") as f:
f.write("RUN OK\n")
return None
def actionFAIL(target, source, env) -> int:
Expand Down
2 changes: 1 addition & 1 deletion bin/SConsExamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def process(source_file, ofp):
elif line[:11] != "STRIP CCCOM":
ofp.write(line)

with open(str(target[0]), "w") as fp:
with open(target[0], "w") as fp:
for src in map(str, source):
process(src, fp)
fp.write('debug = ' + ARGUMENTS.get('debug', '0') + '\\n')
Expand Down
4 changes: 2 additions & 2 deletions test/Actions/append.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
env=Environment()

def before(env, target, source):
with open(str(target[0]), "wb") as f:
with open(target[0], "wb") as f:
f.write(b"Foo\\n")
with open("before.txt", "wb") as f:
f.write(b"Bar\\n")

def after(env, target, source):
with open(str(target[0]), "rb") as fin, open("after%s", "wb") as fout:
with open(target[0], "rb") as fin, open("after%s", "wb") as fout:
fout.write(fin.read())

env.Prepend(LINKCOM=Action(before))
Expand Down
2 changes: 1 addition & 1 deletion test/Actions/exitstatfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def always_succeed(s):
return 0

def copy_fail(target, source, env):
with open(str(source[0]), 'rb') as infp, open(str(target[0]), 'wb') as f:
with open(source[0], 'rb') as infp, open(target[0], 'wb') as f:
f.write(infp.read())
return 2

Expand Down
2 changes: 1 addition & 1 deletion test/Actions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def writeDeps(target, source, env, b=%(b)s, r=r %(extraarg)s , header=header, tr
def foo(b=b):
return %(nestedfuncexp)s

with open(str(target[0]), 'wb') as f:
with open(target[0], 'wb') as f:
f.write(bytearray(header, 'utf-8'))
for d in env['ENVDEPS']:
f.write(bytearray(d+'%(separator)s', 'utf-8'))
Expand Down
2 changes: 1 addition & 1 deletion test/Actions/pre-post-fixture/work2/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright The SCons Foundation

def b(target, source, env):
with open(str(target[0]), 'wb') as f:
with open(target[0], 'wb') as f:
f.write((env['X'] + '\n').encode())

DefaultEnvironment(tools=[])
Expand Down
2 changes: 1 addition & 1 deletion test/Actions/pre-post-fixture/work3/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def post(target, source, env):
pass

def build(target, source, env):
with open(str(target[0]), 'wb') as f:
with open(target[0], 'wb') as f:
f.write(b'build()\n')

DefaultEnvironment(tools=[])
Expand Down
6 changes: 3 additions & 3 deletions test/Actions/pre-post.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def before(env, target, source):
f.write(b"Foo\\n")
os.chmod(a, os.stat(a).st_mode | stat.S_IXUSR)
with open("before.txt", "ab") as f:
f.write((os.path.splitext(str(target[0]))[0] + "\\n").encode())
f.write((os.path.splitext(target[0])[0] + "\\n").encode())

def after(env, target, source):
t = str(target[0])
Expand Down Expand Up @@ -104,11 +104,11 @@ def after(env, target, source):
DefaultEnvironment(tools=[])

def pre_action(target, source, env):
with open(str(target[0]), 'ab') as f:
with open(target[0], 'ab') as f:
f.write(('pre %%s\\n' %% source[0]).encode())

def post_action(target, source, env):
with open(str(target[0]), 'ab') as f:
with open(target[0], 'ab') as f:
f.write(('post %%s\\n' %% source[0]).encode())

env = Environment(tools=[])
Expand Down
2 changes: 1 addition & 1 deletion test/Actions/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

test.write('SConstruct', """\
def my_copy(target, source, env):
with open(str(target[0]), 'w') as f, open(str(source[0]), 'r') as infp:
with open(target[0], 'w') as f, open(source[0], 'r') as infp:
f.write(infp.read())
env = Environment()
env.Decider('timestamp-match')
Expand Down
2 changes: 1 addition & 1 deletion test/Actions/unicode-signature-fixture/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fnode = File(u'foo.txt')

def funcact(target, source, env):
with open(str(target[0]), 'wb') as f:
with open(target[0], 'wb') as f:
f.write(b"funcact\n")
for i in range(300):
pass
Expand Down
5 changes: 2 additions & 3 deletions test/Alias/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@

test.write('SConstruct', """
def cat(target, source, env):
target = str(target[0])
with open(target, "wb") as f:
with open(target[0], "wb") as f:
for src in source:
with open(str(src), "rb") as ifp:
with open(src, "rb") as ifp:
f.write(ifp.read())

def foo(target, source, env):
Expand Down
5 changes: 2 additions & 3 deletions test/Alias/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(env, source, target):
target = str(target[0])
with open(target, "wb") as f:
with open(target[0], "wb") as f:
for src in source:
with open(str(src), "rb") as ifp:
with open(src, "rb") as ifp:
f.write(ifp.read())

XBuilder = Builder(action = cat, src_suffix = '.x', suffix = '.c')
Expand Down
2 changes: 1 addition & 1 deletion test/Batch/Boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

def batch_build(target, source, env):
for t, s in zip(target, source):
with open(str(t), 'wb') as f, open(str(s), 'rb') as infp:
with open(t, 'wb') as f, open(s, 'rb') as infp:
f.write(infp.read())
env = Environment(tools=[])
bb = Action(batch_build, batch_key=True)
Expand Down
2 changes: 1 addition & 1 deletion test/Batch/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
DefaultEnvironment(tools=[])
def batch_build(target, source, env):
for t, s in zip(target, source):
with open(str(t), 'wb') as f, open(str(s), 'rb') as infp:
with open(t, 'wb') as f, open(s, 'rb') as infp:
f.write(infp.read())
if ARGUMENTS.get('BATCH_CALLABLE'):
def batch_key(action, env, target, source):
Expand Down
4 changes: 2 additions & 2 deletions test/Batch/generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@

def batch_build(target, source, env):
for t, s in zip(target, source):
with open(str(t), 'wb') as fp:
with open(t, 'wb') as fp:
if str(t) == 'f3.out':
with open('f3.include', 'rb') as f:
fp.write(f.read())
with open(str(s), 'rb') as f:
with open(s, 'rb') as f:
fp.write(f.read())
env = Environment(tools=[])
bb = Action(batch_build, batch_key=True)
Expand Down
2 changes: 1 addition & 1 deletion test/Builder-factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def mkdir(env, source, target):
f.write(b"MakeDirectory\\n")
MakeDirectory = Builder(action=mkdir, target_factory=Dir)
def collect(env, source, target):
with open(str(target[0]), 'wb') as out:
with open(target[0], 'wb') as out:
dir = str(source[0])
for f in sorted(os.listdir(dir)):
f = os.path.join(dir, f)
Expand Down
2 changes: 1 addition & 1 deletion test/Builder/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
DefaultEnvironment(tools=[])

def buildop(env, source, target):
with open(str(target[0]), 'wb') as outf, open(str(source[0]), 'r') as infp:
with open(target[0], 'wb') as outf, open(source[0], 'r') as infp:
for line in inpf.readlines():
if line.find(str(target[0])) == -1:
outf.write(line)
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/different-actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
with open(str(target[0]), 'wb') as f:
for s in source:
with open(str(s), 'rb') as infp:
with open(target[0], 'wb') as f:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())

B = Builder(action=Action(build, varlist=['XXX']), multi=1)
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/different-environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
test.write('build.py', r"""\
import sys
def build(num, target, source):
with open(str(target), 'wb') as f:
with open(target[0], 'wb') as f:
f.write('%s\n' % num)
for s in source:
with open(str(s), 'rb') as infp:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())
build(sys.argv[1],sys.argv[2],sys.argv[3:])
""")
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/different-multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
DefaultEnvironment(tools=[])

def build(env, target, source):
with open(str(target[0]), 'wb') as f:
for s in source:
with open(str(s), 'rb') as infp:
with open(target[0], 'wb') as f:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())

def build2(env, target, source):
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/different-order.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
DefaultEnvironment(tools=[])
def build(env, target, source):
for t in target:
with open(str(target[0]), 'wb') as f:
for s in source:
with open(str(s), 'rb') as infp:
with open(target[0], 'wb') as f:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())

B = Builder(action=build, multi=1)
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/different-overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
test.write('SConstruct', """\
DefaultEnvironment(tools=[])
def build(env, target, source):
with open(str(target[0]), 'wb') as f:
for s in source:
with open(str(s), 'rb') as infp:
with open(target[0], 'wb') as f:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())

B = Builder(action=build, multi=1)
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/different-target-lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
DefaultEnvironment(tools=[])
def build(env, target, source):
for t in target:
with open(str(target[0]), 'wb') as f:
for s in source:
with open(str(s), 'rb') as infp:
with open(target[0], 'wb') as f:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())

B = Builder(action=build, multi=1)
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
DefaultEnvironment(tools=[])

def build(env, target, source):
with open(str(target[0]), 'wb') as f:
for s in source:
with open(str(s), 'rb') as infp:
with open(target[0], 'wb') as f:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())

B = Builder(action=build, multi=0)
Expand Down
6 changes: 3 additions & 3 deletions test/Builder/multi/lone-target-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

def build(env, target, source):
for t in target:
with open(str(target[0]), 'wb') as f:
for s in source:
with open(str(s), 'rb') as infp:
with open(t, 'wb') as f:
for src in source:
with open(src, 'rb') as infp:
f.write(infp.read())

B = Builder(action=build, multi=1)
Expand Down
Loading
Loading