Skip to content

Commit 56bcbaf

Browse files
authored
Merge pull request #135 from lsst/tickets/DM-48788
DM-48788: Use ruff format
2 parents bf3148c + 42345a3 commit 56bcbaf

File tree

11 files changed

+54
-62
lines changed

11 files changed

+54
-62
lines changed

.github/workflows/lint.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,16 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v5.0.0
44
hooks:
5-
- id: check-toml
65
- id: check-yaml
76
args:
87
- "--unsafe"
98
- id: end-of-file-fixer
109
- id: trailing-whitespace
11-
- repo: https://github.com/psf/black
12-
rev: 25.1.0
13-
hooks:
14-
- id: black
15-
# It is recommended to specify the latest version of Python
16-
# supported by your project here, or alternatively use
17-
# pre-commit's default_language_version, see
18-
# https://pre-commit.com/#top_level-default_language_version
19-
language_version: python3.11
20-
- repo: https://github.com/pycqa/isort
21-
rev: 6.0.0
22-
hooks:
23-
- id: isort
24-
name: isort (python)
10+
- id: check-toml
2511
- repo: https://github.com/astral-sh/ruff-pre-commit
2612
# Ruff version.
2713
rev: v0.9.4
2814
hooks:
2915
- id: ruff
16+
args: [--fix]
17+
- id: ruff-format

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ target-version = ["py311"]
55
[tool.isort]
66
profile = "black"
77
line_length = 110
8+
known_first_party = ["lsst"]
89

910
[tool.ruff]
1011
line-length = 110
@@ -28,11 +29,18 @@ select = [
2829
"F", # pyflakes
2930
"N", # pep8-naming
3031
"W", # pycodestyle
32+
"I", # isort
33+
"RUF022", # Sort __all__
34+
"C4", # comprehensions
35+
"B", # bugbear
3136
]
3237
extend-select = [
3338
"RUF100", # Warn about unused noqa
3439
]
3540

41+
[tool.lint.isort]
42+
known-first-party = ["lsst"]
43+
3644
[tool.ruff.lint.pycodestyle]
3745
max-doc-length = 79
3846

@@ -41,3 +49,8 @@ convention = "numpy"
4149

4250
[tool.pytest.ini_options]
4351
addopts = "--import-mode=importlib" # Recommended as best practice
52+
53+
[tool.ruff.format]
54+
docstring-code-format = true
55+
# ruff format does not seem to take indenting into account.
56+
docstring-code-line-length = 69

python/lsst/sconsUtils/builders.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class.
33
"""
44

5-
__all__ = ("filesToTag", "DoxygenBuilder")
5+
__all__ = ("DoxygenBuilder", "filesToTag")
66

77
import csv
88
import fnmatch
@@ -292,7 +292,7 @@ def ProductDir(env, product):
292292

293293
global _productDirs
294294
try:
295-
_productDirs
295+
_productDirs # noqa: B018
296296
except Exception:
297297
try:
298298
_productDirs = eupsForScons.productDir(eupsenv=eupsForScons.getEups())
@@ -431,7 +431,7 @@ def _quote_paths(pathList):
431431
outConfigFile.write(f"FILE_PATTERNS = {' '.join(self.patterns)}\n")
432432
outConfigFile.write("RECURSIVE = YES\n" if self.recursive else "RECURSIVE = NO\n")
433433
allOutputs = {"html", "latex", "man", "rtf", "xml"}
434-
for output, path in zip(self.outputs, self.outputPaths):
434+
for output, path in zip(self.outputs, self.outputPaths, strict=True):
435435
try:
436436
allOutputs.remove(output.lower())
437437
except Exception:
@@ -746,7 +746,7 @@ def makeRecordFile(target, source, env):
746746
# Do not attempt to write hashes and file sizes since these can
747747
# change if the package is not really installed into an EUPS tree.
748748
all_files = set()
749-
for root, dirs, files in os.walk(pythonDir):
749+
for root, _, files in os.walk(pythonDir):
750750
root = root.removeprefix(pythonDir)
751751
root = root.removeprefix("/")
752752
all_files.update({os.path.join(root, f) for f in files})
@@ -833,7 +833,7 @@ def makePythonScript(target, source, env):
833833
os.chmod(cmdfile, newmode)
834834

835835
results = []
836-
for cmd, code in scripts.items():
836+
for cmd in scripts:
837837
filename = f"bin/{cmd}"
838838

839839
# Do not do anything if there is an equivalent target in bin.src

python/lsst/sconsUtils/dependencies.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ class Configuration:
167167
name ``<root>/doc/<name>.inc``.
168168
hasDoxygenTag : `bool`, optional
169169
If True, the package generates a Doxygen TAG file.
170-
includeFileDirs : `list`, optional
170+
includeFileDirs : `collections.abc.Sequence`, optional
171171
List of directories that should be searched for include files.
172-
libFileDirs : `list`, optional
172+
libFileDirs : `collections.abs.Sequence`, optional
173173
List of directories that should be searched for libraries.
174174
eupsProduct : `str`
175175
Name of the EUPS product for the package, if different from the name
@@ -223,8 +223,8 @@ def __init__(
223223
headers=(),
224224
libs=None,
225225
hasSwigFiles=True,
226-
includeFileDirs=["include"],
227-
libFileDirs=["lib"],
226+
includeFileDirs=("include",),
227+
libFileDirs=("lib",),
228228
hasDoxygenInclude=False,
229229
hasDoxygenTag=True,
230230
eupsProduct=None,

python/lsst/sconsUtils/installation.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Builders and path setup for installation targets."""
22

33
__all__ = (
4-
"makeProductPath",
4+
"DirectoryInstaller",
5+
"SConsUtilsEnvironment",
56
"determineVersion",
67
"getFingerprint",
8+
"makeProductPath",
79
"setPrefix",
8-
"DirectoryInstaller",
9-
"SConsUtilsEnvironment",
1010
)
1111

1212
import glob
@@ -230,7 +230,7 @@ def Declare(self, products=None):
230230
product = self["eupsProduct"]
231231

232232
if "EUPS_DIR" in os.environ:
233-
self["ENV"]["PATH"] += os.pathsep + f'{os.environ["EUPS_DIR"]}/bin'
233+
self["ENV"]["PATH"] += os.pathsep + f"{os.environ['EUPS_DIR']}/bin"
234234
self["ENV"]["EUPS_LOCK_PID"] = os.environ.get("EUPS_LOCK_PID", "-1")
235235
if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS or self.GetOption("clean"):
236236
if version:
@@ -254,15 +254,15 @@ def Declare(self, products=None):
254254
)
255255

256256
if "eupsPath" in self:
257-
command += f' -Z {self["eupsPath"]}'
257+
command += f" -Z {self['eupsPath']}"
258258

259259
if version:
260260
command += f" {product} {version}"
261261

262262
current += [command + " --current"]
263263

264264
if self.GetOption("tag"):
265-
command += f' --tag={self.GetOption("tag")}'
265+
command += f" --tag={self.GetOption('tag')}"
266266

267267
declare += [command]
268268

@@ -359,7 +359,7 @@ def InstallDir(self, prefix, dir, ignoreRegex=r"(~$|\.pyc$|\.os?$)", recursive=T
359359

360360

361361
@memberOf(SConsEnvironment)
362-
def InstallEups(env, dest, files=[], presetup=""):
362+
def InstallEups(env, dest, files=(), presetup=""):
363363
"""Install a ups directory, setting absolute versions as appropriate
364364
(unless you're installing from the trunk, in which case no versions
365365
are expanded).
@@ -370,7 +370,7 @@ def InstallEups(env, dest, files=[], presetup=""):
370370
Environment to use.
371371
dest : `str`
372372
Destination directory.
373-
files : `list`, optional
373+
files : `collections.abc.Sequence`, optional
374374
List of files to install. Any build/table files present in ``./ups``
375375
are automatically added to this list.
376376
presetup : `dict`, optional
@@ -389,8 +389,10 @@ def InstallEups(env, dest, files=[], presetup=""):
389389
390390
.. code-block:: python
391391
392-
env.InstallEups(os.path.join(env['prefix'], "ups"),
393-
presetup={"sconsUtils" : env['version']})
392+
env.InstallEups(
393+
os.path.join(env["prefix"], "ups"),
394+
presetup={"sconsUtils": env["version"]},
395+
)
394396
"""
395397
acts = []
396398
if not env.installing:
@@ -449,9 +451,9 @@ def InstallEups(env, dest, files=[], presetup=""):
449451
for i in build_obj:
450452
env.AlwaysBuild(i)
451453

452-
cmd = f'eups expandbuild -i --version {env["version"]} '
454+
cmd = f"eups expandbuild -i --version {env['version']} "
453455
if "baseversion" in env:
454-
cmd += f' --repoversion {env["baseversion"]} '
456+
cmd += f" --repoversion {env['baseversion']} "
455457
cmd += str(i)
456458
eupsTargets.extend(env.AddPostAction(build_obj, env.Action(f"{cmd}", cmd)))
457459

python/lsst/sconsUtils/scripts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def rewrite_shebang(target, source, env):
369369
"""Copy source to target, rewriting the shebang"""
370370
# Currently just use this python
371371
usepython = utils.whichPython()
372-
for targ, src in zip(target, source):
372+
for targ, src in zip(target, source, strict=True):
373373
with open(str(src)) as srcfd:
374374
with open(str(targ), "w") as outfd:
375375
first_line = srcfd.readline()
@@ -455,7 +455,7 @@ def python(module=None, src=None, extra=(), libs="main python"):
455455
return result
456456

457457
@staticmethod
458-
def pybind11(nameList=[], libs="main python", extraSrc=None, addUnderscore=True):
458+
def pybind11(nameList=(), libs="main python", extraSrc=None, addUnderscore=True):
459459
"""Convenience function to replace standard ``python/*/SConscript``
460460
boilerplate.
461461
@@ -467,7 +467,7 @@ def pybind11(nameList=[], libs="main python", extraSrc=None, addUnderscore=True)
467467
468468
Parameters
469469
----------
470-
nameList : `list`, optional
470+
nameList : `collections.abc.Sequence`, optional
471471
Sequence of pybind11 modules to be built (does not include the
472472
file extensions).
473473
libs : `str` or `list`, optional
@@ -642,7 +642,7 @@ def tests(
642642
if swigSrc is None:
643643
swigSrc = {}
644644
allSwigSrc = set()
645-
for name, node in zip(swigNameList, swigFileList):
645+
for name, node in zip(swigNameList, swigFileList, strict=True):
646646
src = swigSrc.setdefault(name, [])
647647
allSwigSrc.update(str(element) for element in src)
648648
src.append(node)
@@ -760,7 +760,7 @@ def examples(ccList=None, swigNameList=None, swigSrc=None):
760760
if swigSrc is None:
761761
swigSrc = {}
762762
allSwigSrc = set()
763-
for name, node in zip(swigNameList, swigFileList):
763+
for name, node in zip(swigNameList, swigFileList, strict=True):
764764
src = swigSrc.setdefault(name, [])
765765
allSwigSrc.update(str(element) for element in src)
766766
src.append(node)

python/lsst/sconsUtils/state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _initOptions():
7272
action="store_true",
7373
default=False,
7474
help="Filter out a class of warnings deemed irrelevant",
75-
),
75+
)
7676
SCons.Script.AddOption(
7777
"--force",
7878
dest="force",
@@ -579,13 +579,13 @@ def ClassifyCc(context):
579579
#
580580
if re.search(r"^(Linux|Linux64)$", env["eupsFlavor"]) and "LD_LIBRARY_PATH" in os.environ:
581581
env.Append(LINKFLAGS=["-Wl,-rpath-link"])
582-
env.Append(LINKFLAGS=[f'-Wl,{os.environ["LD_LIBRARY_PATH"]}'])
582+
env.Append(LINKFLAGS=[f"-Wl,{os.environ['LD_LIBRARY_PATH']}"])
583583
#
584584
# Set the optimization level.
585585
#
586586
if env["opt"]:
587587
env["CCFLAGS"] = [o for o in env["CCFLAGS"] if not re.search(r"^-O(\d|s|g|fast)$", o)]
588-
env.MergeFlags(f'-O{env["opt"]}')
588+
env.MergeFlags(f"-O{env['opt']}")
589589
#
590590
# Set compiler-specific warning flags.
591591
#

python/lsst/sconsUtils/tools/cuda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
# the extra .linkinfo files when calling scons -c
2020
def CUDANVCCStaticObjectEmitter(target, source, env):
2121
tgt, src = SCons.Defaults.StaticObjectEmitter(target, source, env)
22-
for file in src:
22+
for _ in src:
2323
lifile = os.path.splitext(src[0].rstr())[0] + ".linkinfo" # noqa F841
2424
# tgt.append(lifile)
2525
return tgt, src
2626

2727

2828
def CUDANVCCSharedObjectEmitter(target, source, env):
2929
tgt, src = SCons.Defaults.SharedObjectEmitter(target, source, env)
30-
for file in src:
30+
for _ in src:
3131
lifile = os.path.splitext(src[0].rstr())[0] + ".linkinfo" # noqa F841
3232
# tgt.append(lifile)
3333
return tgt, src

python/lsst/sconsUtils/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
__all__ = (
66
"Log",
77
"_has_OSX_SIP",
8+
"get_conda_prefix",
9+
"libraryLoaderEnvironment",
810
"libraryPathPassThrough",
9-
"whichPython",
11+
"memberOf",
1012
"needShebangRewrite",
11-
"libraryLoaderEnvironment",
1213
"runExternal",
13-
"memberOf",
14-
"get_conda_prefix",
14+
"whichPython",
1515
)
1616

1717
import os

0 commit comments

Comments
 (0)