Skip to content

Commit 7418439

Browse files
committed
Replace some more %-formatting with f-strings
1 parent 66c23ea commit 7418439

File tree

15 files changed

+92
-100
lines changed

15 files changed

+92
-100
lines changed

bin.src/makeLinkFarm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def linkFiles(dstDir, srcDir, verbose=0, force=False):
2929
if force:
3030
os.unlink(fullDst)
3131
else:
32-
print("%s already exists; use --force to overwrite" % fullDst, file=sys.stderr)
32+
print(f"{fullDst} already exists; use --force to overwrite", file=sys.stderr)
3333
sys.exit(1)
3434

3535
os.symlink(fullSrc, fullDst)
@@ -58,7 +58,7 @@ creates a link farm for your current selection of products.
5858
linkFarmDir = os.path.abspath(args.linkFarmDir)
5959

6060
if not args.force and os.path.exists(linkFarmDir):
61-
print("Path %s already exists; use --force to overwrite" % args.linkFarmDir, file=sys.stderr)
61+
print(f"Path {args.linkFarmDir} already exists; use --force to overwrite", file=sys.stderr)
6262
sys.exit(1)
6363

6464
#
@@ -88,7 +88,7 @@ creates a link farm for your current selection of products.
8888

8989
if args.verbose:
9090
if args.verbose > 1 or os.path.exists(binDir) or os.path.exists(incDir) or os.path.exists(libDir):
91-
print("%-15s %s" % (productName, pd))
91+
print(f"{productName:<15} {pd}")
9292

9393
if os.path.exists(binDir):
9494
fullDstDir = os.path.join(linkFarmDir, "bin")
@@ -111,7 +111,7 @@ creates a link farm for your current selection of products.
111111
if args.force:
112112
os.unlink(fullDst)
113113
else:
114-
print("%s already exists; use --force to overwrite" % fullDst, file=sys.stderr)
114+
print(f"{fullDst} already exists; use --force to overwrite", file=sys.stderr)
115115
sys.exit(1)
116116

117117
os.symlink(fullSrc, fullDst)

bin.src/sconsOpts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ if os.path.exists(args.configFile):
4141

4242
else:
4343
if not args.quiet:
44-
print("File %s doesn't exist" % args.configFile, file=sys.stderr)
44+
print(f"File {args.configFile} doesn't exist", file=sys.stderr)
4545

4646
print(f"cc={cc} opt={opt}")

python/lsst/sconsUtils/builders.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def SourcesForSharedLibrary(self, files):
9797
if opt == 0:
9898
opt = 3
9999

100-
CCFLAGS_OPT = re.sub(r"-O(\d|s)\s*", "-O%d " % opt, " ".join(self["CCFLAGS"]))
100+
CCFLAGS_OPT = re.sub(r"-O(\d|s)\s*", f"-O{opt} ", " ".join(self["CCFLAGS"]))
101101
CCFLAGS_NOOPT = re.sub(r"-O(\d|s)\s*", "-O0 ", " ".join(self["CCFLAGS"])) # remove -O flags from CCFLAGS
102102

103103
objs = []
@@ -168,7 +168,7 @@ def filesToTag(root=None, fileRegex=None, ignoreDirs=None):
168168
#
169169
for swigFile in [f for f in filenames if f.endswith(".i")]:
170170
name = os.path.splitext(swigFile)[0]
171-
candidates = [f for f in candidates if not re.search(r"%s(_wrap\.cc?|\.py)$" % name, f)]
171+
candidates = [f for f in candidates if not re.search(rf"{name}(_wrap\.cc?|\.py)$", f)]
172172

173173
files += [os.path.join(dirpath, f) for f in candidates]
174174

@@ -337,7 +337,7 @@ def __call__(self, env, config):
337337
)
338338
env.AlwaysBuild(config)
339339
doc = env.Command(
340-
target=self.targets, source=self.sources, action="doxygen %s" % shlex.quote(outConfigNode.abspath)
340+
target=self.targets, source=self.sources, action=f"doxygen {shlex.quote(outConfigNode.abspath)}"
341341
)
342342
for path in self.outputPaths:
343343
env.Clean(doc, path)
@@ -406,40 +406,40 @@ def _quote_paths(pathList):
406406
incFiles = []
407407
for incPath in self.includes:
408408
docDir, incFile = os.path.split(incPath)
409-
docPaths.append('"%s"' % docDir)
410-
incFiles.append('"%s"' % incFile)
409+
docPaths.append(f'"{docDir}"')
410+
incFiles.append(f'"{incFile}"')
411411
self.sources.append(SCons.Script.File(incPath))
412412
if docPaths:
413-
outConfigFile.write("@INCLUDE_PATH = %s\n" % _quote_paths(docPaths))
413+
outConfigFile.write(f"@INCLUDE_PATH = {_quote_paths(docPaths)}\n")
414414
for incFile in incFiles:
415-
outConfigFile.write("@INCLUDE = %s\n" % _quote_path(incFile))
415+
outConfigFile.write(f"@INCLUDE = {_quote_path(incFile)}\n")
416416

417417
for tagPath in self.useTags:
418418
docDir, tagFile = os.path.split(tagPath)
419419
htmlDir = os.path.join(docDir, "html")
420420
outConfigFile.write(f'TAGFILES += "{tagPath}={htmlDir}"\n')
421421
self.sources.append(SCons.Script.Dir(docDir))
422422
if self.projectName is not None:
423-
outConfigFile.write("PROJECT_NAME = %s\n" % self.projectName)
423+
outConfigFile.write(f"PROJECT_NAME = {self.projectName}\n")
424424
if self.projectNumber is not None:
425-
outConfigFile.write("PROJECT_NUMBER = %s\n" % self.projectNumber)
426-
outConfigFile.write("INPUT = %s\n" % _quote_paths(self.inputs))
427-
outConfigFile.write("EXCLUDE = %s\n" % _quote_paths(self.excludes))
428-
outConfigFile.write("FILE_PATTERNS = %s\n" % " ".join(self.patterns))
425+
outConfigFile.write(f"PROJECT_NUMBER = {self.projectNumber}\n")
426+
outConfigFile.write(f"INPUT = {_quote_paths(self.inputs)}\n")
427+
outConfigFile.write(f"EXCLUDE = {_quote_paths(self.excludes)}\n")
428+
outConfigFile.write(f"FILE_PATTERNS = {' '.join(self.patterns)}\n")
429429
outConfigFile.write("RECURSIVE = YES\n" if self.recursive else "RECURSIVE = NO\n")
430430
allOutputs = {"html", "latex", "man", "rtf", "xml"}
431431
for output, path in zip(self.outputs, self.outputPaths):
432432
try:
433433
allOutputs.remove(output.lower())
434434
except Exception:
435-
state.log.fail("Unknown Doxygen output format '%s'." % output)
435+
state.log.fail(f"Unknown Doxygen output format '{output}'.")
436436
state.log.finish()
437-
outConfigFile.write("GENERATE_%s = YES\n" % output.upper())
437+
outConfigFile.write(f"GENERATE_{output.upper()} = YES\n")
438438
outConfigFile.write(f"{output.upper()}_OUTPUT = {_quote_path(path.abspath)}\n")
439439
for output in allOutputs:
440-
outConfigFile.write("GENERATE_%s = NO\n" % output.upper())
440+
outConfigFile.write(f"GENERATE_{output.upper()} = NO\n")
441441
if self.makeTag is not None:
442-
outConfigFile.write("GENERATE_TAGFILE = %s\n" % _quote_path(self.makeTag))
442+
outConfigFile.write(f"GENERATE_TAGFILE = {_quote_path(self.makeTag)}\n")
443443
#
444444
# Append the local overrides (usually doxygen.conf.in)
445445
#
@@ -552,7 +552,7 @@ def VersionModule(self, filename, versionString=None):
552552
"hg",
553553
"svn",
554554
):
555-
if os.path.isdir(".%s" % n):
555+
if os.path.isdir(f".{n}"):
556556
versionString = n
557557

558558
if not versionString:
@@ -636,7 +636,7 @@ def makeVersionModule(target, source, env):
636636
outFile.write(")\n")
637637

638638
if calcMd5(target[0].abspath) != oldMd5: # only print if something's changed
639-
state.log.info('makeVersionModule(["%s"], [])' % str(target[0]))
639+
state.log.info(f'makeVersionModule(["{target[0]}"], [])')
640640

641641
result = self.Command(filename, [], self.Action(makeVersionModule, strfunction=lambda *args: None))
642642

python/lsst/sconsUtils/dependencies.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def configure(packageName, versionString=None, eupsProduct=None, eupsProductPath
4747
"""
4848

4949
if not state.env.GetOption("no_progress"):
50-
state.log.info("Setting up environment to build package '%s'." % packageName)
50+
state.log.info(f"Setting up environment to build package '{packageName}'.")
5151
if eupsProduct is None:
5252
eupsProduct = packageName
5353
if versionString is None:
@@ -65,8 +65,8 @@ def configure(packageName, versionString=None, eupsProduct=None, eupsProductPath
6565
state.env.linkFarmDir = os.path.abspath(os.path.expanduser(state.env.linkFarmDir))
6666
prefix = installation.setPrefix(state.env, versionString, eupsProductPath)
6767
state.env["prefix"] = prefix
68-
state.env["libDir"] = "%s/lib" % prefix
69-
state.env["pythonDir"] = "%s/python" % prefix
68+
state.env["libDir"] = f"{prefix}/lib"
69+
state.env["pythonDir"] = f"{prefix}/python"
7070
#
7171
# Process dependencies
7272
#
@@ -97,7 +97,7 @@ def configure(packageName, versionString=None, eupsProduct=None, eupsProductPath
9797
state.env["XCPPPATH"] = []
9898

9999
if use_conda_compilers():
100-
state.env.Append(XCPPPATH=["%s/include" % _conda_prefix])
100+
state.env.Append(XCPPPATH=[f"{_conda_prefix}/include"])
101101

102102
# XCPPPPREFIX is a replacement for SCons' built-in INCPREFIX. It is used
103103
# when compiling headers in XCPPPATH directories. Here, we set it to
@@ -242,10 +242,10 @@ def __init__(
242242
self.root = os.path.realpath(productDir)
243243
self.doxygen = {
244244
# Doxygen tag files generated by this package
245-
"tags": ([os.path.join(self.root, "doc", "%s.tag" % self.name)] if hasDoxygenTag else []),
245+
"tags": ([os.path.join(self.root, "doc", f"{self.name}.tag")] if hasDoxygenTag else []),
246246
# Doxygen include files to include in the configuration of
247247
# dependent products
248-
"includes": ([os.path.join(self.root, "doc", "%s.inc" % self.name)] if hasDoxygenInclude else []),
248+
"includes": ([os.path.join(self.root, "doc", f"{self.name}.inc")] if hasDoxygenInclude else []),
249249
}
250250
if libs is None:
251251
self.libs = {
@@ -320,7 +320,7 @@ def configure(self, conf, packages, check=False, build=True):
320320
"""
321321
assert not (check and build)
322322
conf.env.PrependUnique(**self.paths)
323-
state.log.info("Configuring package '%s'." % self.name)
323+
state.log.info(f"Configuring package '{self.name}'.")
324324
conf.env.doxygen["includes"].extend(self.doxygen["includes"])
325325
if not build:
326326
conf.env.doxygen["tags"].extend(self.doxygen["tags"])
@@ -558,7 +558,7 @@ def __init__(self, primaryName, noCfgFile=False):
558558

559559
self.primary = self._tryImport(primaryName)
560560
if self.primary is None:
561-
state.log.fail("Failed to load primary package configuration for %s." % primaryName)
561+
state.log.fail(f"Failed to load primary package configuration for {primaryName}.")
562562

563563
missingDeps = []
564564
for dependency in self.primary.dependencies.get("required", ()):
@@ -588,10 +588,10 @@ def configure(self, env, check=False):
588588
conf = env.Configure(custom_tests=self.customTests)
589589
for name, module in self.packages.items():
590590
if module is None:
591-
state.log.info("Skipping missing optional package %s." % name)
591+
state.log.info(f"Skipping missing optional package {name}.")
592592
continue
593593
if not module.config.configure(conf, packages=self.packages, check=check, build=False):
594-
state.log.fail("%s was found but did not pass configuration checks." % name)
594+
state.log.fail(f"{name} was found but did not pass configuration checks.")
595595
if self.primary:
596596
self.primary.config.configure(conf, packages=self.packages, check=False, build=True)
597597
env.AppendUnique(SWIGPATH=env["CPPPATH"])
@@ -648,15 +648,15 @@ def _tryImport(self, name):
648648
continue
649649
state.log.info(f"Using configuration for package '{name}' at '{filename}'.")
650650
if not hasattr(module, "dependencies") or not isinstance(module.dependencies, dict):
651-
state.log.warn("Configuration module for package '%s' lacks a dependencies dict." % name)
651+
state.log.warn(f"Configuration module for package '{name}' lacks a dependencies dict.")
652652
return None
653653
if not hasattr(module, "config") or not isinstance(module.config, Configuration):
654-
state.log.warn("Configuration module for package '%s' lacks a config object." % name)
654+
state.log.warn(f"Configuration module for package '{name}' lacks a config object.")
655655
return None
656656
else:
657657
module.config.addCustomTests(self.customTests)
658658
return module
659-
state.log.info("Failed to import configuration for optional package '%s'." % name)
659+
state.log.info(f"Failed to import configuration for optional package '{name}'.")
660660

661661
def _recurse(self, name):
662662
"""Recursively load a dependency.
@@ -672,7 +672,7 @@ def _recurse(self, name):
672672
Was the dependency loaded?
673673
"""
674674
if name in self._current:
675-
state.log.fail("Detected recursive dependency involving package '%s'" % name)
675+
state.log.fail(f"Detected recursive dependency involving package '{name}'")
676676
else:
677677
self._current.add(name)
678678
if name in self.packages:

python/lsst/sconsUtils/eupsForScons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def flavor():
3030
return env["PLATFORM"].title()
3131

3232
def productDir(name):
33-
return os.environ.get("%s_DIR" % name.upper())
33+
return os.environ.get(f"{name.upper()}_DIR")
3434

3535
def findSetupVersion(eupsProduct):
3636
return None, None, None, None, flavor()
@@ -49,7 +49,7 @@ class _Utils:
4949
utils = _Utils()
5050

5151
def setupEnvNameFor(productName):
52-
return "SETUP_%s" % productName
52+
return f"SETUP_{productName}"
5353

5454
utils.setupEnvNameFor = setupEnvNameFor
5555

python/lsst/sconsUtils/installation.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def setPrefix(env, versionString, eupsProductPath=None):
149149
env["version"] = "unknown"
150150
if (env.installing or env.declaring) and not env["force"]:
151151
state.log.fail(
152-
"%s\nFound problem with version number; update or specify force=True to proceed" % err
152+
f"{err}\nFound problem with version number; update or specify force=True to proceed"
153153
)
154154

155155
if state.env["no_eups"]:
@@ -175,7 +175,7 @@ def setPrefix(env, versionString, eupsProductPath=None):
175175
eupsPrefix = None
176176
if "prefix" in env:
177177
if env["version"] != "unknown" and eupsPrefix and eupsPrefix != env["prefix"]:
178-
state.log.warn("Ignoring prefix %s from EUPS_PATH" % eupsPrefix)
178+
state.log.warn(f"Ignoring prefix {eupsPrefix} from EUPS_PATH")
179179
return makeProductPath(env, env["prefix"])
180180
elif "eupsPath" in env and env["eupsPath"]:
181181
prefix = eupsPrefix
@@ -233,7 +233,7 @@ def Declare(self, products=None):
233233
product = self["eupsProduct"]
234234

235235
if "EUPS_DIR" in os.environ:
236-
self["ENV"]["PATH"] += os.pathsep + "%s/bin" % (os.environ["EUPS_DIR"])
236+
self["ENV"]["PATH"] += os.pathsep + f'{os.environ["EUPS_DIR"]}/bin'
237237
self["ENV"]["EUPS_LOCK_PID"] = os.environ.get("EUPS_LOCK_PID", "-1")
238238
if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS or self.GetOption("clean"):
239239
if version:
@@ -259,15 +259,15 @@ def Declare(self, products=None):
259259
)
260260

261261
if "eupsPath" in self:
262-
command += " -Z %s" % self["eupsPath"]
262+
command += f' -Z {self["eupsPath"]}'
263263

264264
if version:
265265
command += f" {product} {version}"
266266

267267
current += [command + " --current"]
268268

269269
if self.GetOption("tag"):
270-
command += " --tag=%s" % self.GetOption("tag")
270+
command += f' --tag={self.GetOption("tag")}'
271271

272272
declare += [command]
273273

@@ -310,7 +310,7 @@ def __call__(self, target, source, env):
310310
prefix = os.path.abspath(os.path.join(target[0].abspath, ".."))
311311
destpath = os.path.join(target[0].abspath)
312312
if not os.path.isdir(destpath):
313-
state.log.info("Creating directory %s" % destpath)
313+
state.log.info(f"Creating directory {destpath}")
314314
os.makedirs(destpath)
315315
for root, dirnames, filenames in os.walk(source[0].path):
316316
if not self.recursive:
@@ -320,7 +320,7 @@ def __call__(self, target, source, env):
320320
for dirname in dirnames:
321321
destpath = os.path.join(prefix, root, dirname)
322322
if not os.path.isdir(destpath):
323-
state.log.info("Creating directory %s" % destpath)
323+
state.log.info(f"Creating directory {destpath}")
324324
os.makedirs(destpath)
325325
for filename in filenames:
326326
if self.ignoreRegex.search(filename):
@@ -454,11 +454,11 @@ def InstallEups(env, dest, files=[], presetup=""):
454454
for i in build_obj:
455455
env.AlwaysBuild(i)
456456

457-
cmd = "eups expandbuild -i --version %s " % env["version"]
457+
cmd = f'eups expandbuild -i --version {env["version"]} '
458458
if "baseversion" in env:
459-
cmd += " --repoversion %s " % env["baseversion"]
459+
cmd += f' --repoversion {env["baseversion"]} '
460460
cmd += str(i)
461-
eupsTargets.extend(env.AddPostAction(build_obj, env.Action("%s" % (cmd), cmd)))
461+
eupsTargets.extend(env.AddPostAction(build_obj, env.Action(f"{cmd}", cmd)))
462462

463463
for i in table_obj:
464464
env.AlwaysBuild(i)
@@ -468,7 +468,7 @@ def InstallEups(env, dest, files=[], presetup=""):
468468
cmd += presetup + " "
469469
cmd += str(i)
470470

471-
act = env.Command("table", "", env.Action("%s" % (cmd), cmd))
471+
act = env.Command("table", "", env.Action(f"{cmd}", cmd))
472472
eupsTargets.extend(act)
473473
acts += act
474474
env.Depends(act, i)

python/lsst/sconsUtils/scripts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def key(path):
175175

176176
scripts.sort(key=key)
177177
for script in scripts:
178-
state.log.info("Using SConscript at %s" % script)
178+
state.log.info(f"Using SConscript at {script}")
179179
SConscript(script)
180180
cls._initializing = False
181181
return state.env
@@ -657,11 +657,11 @@ def s(ll):
657657
return ["None"]
658658
return [str(i) for i in ll]
659659

660-
state.log.info("SWIG modules for tests: %s" % s(swigFileList))
661-
state.log.info("Python tests: %s" % s(pyList))
662-
state.log.info("C++ tests: %s" % s(ccList))
663-
state.log.info("Files that will not be built: %s" % noBuildList)
664-
state.log.info("Ignored tests: %s" % ignoreList)
660+
state.log.info(f"SWIG modules for tests: {s(swigFileList)}")
661+
state.log.info(f"Python tests: {s(pyList)}")
662+
state.log.info(f"C++ tests: {s(ccList)}")
663+
state.log.info(f"Files that will not be built: {noBuildList}")
664+
state.log.info(f"Ignored tests: {ignoreList}")
665665
control = tests.Control(state.env, ignoreList=ignoreList, args=args, verbose=True)
666666
for ccTest in ccList:
667667
state.env.Program(ccTest, LIBS=state.env.getLibs("main test"))
@@ -756,8 +756,8 @@ def examples(ccList=None, swigNameList=None, swigSrc=None):
756756
for node in Glob("*.cc")
757757
if (not str(node).endswith("_wrap.cc")) and str(node) not in allSwigSrc
758758
]
759-
state.log.info("SWIG modules for examples: %s" % swigFileList)
760-
state.log.info("C++ examples: %s" % ccList)
759+
state.log.info(f"SWIG modules for examples: {swigFileList}")
760+
state.log.info(f"C++ examples: {ccList}")
761761
results = []
762762
for src in ccList:
763763
results.extend(state.env.Program(src, LIBS=state.env.getLibs("main")))

0 commit comments

Comments
 (0)