Skip to content

Commit 0c6ac9b

Browse files
authored
Merge pull request #121 from lsst/tickets/DM-43369
DM-43369: Drop distutils and modernize ruff usage
2 parents 35fb3b6 + 0ac4d4c commit 0c6ac9b

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ubuntu-latest, macos-latest]
14-
pyversion: ["3.10", "3.11"]
14+
pyversion: ["3.10", "3.11", "3.12"]
1515

1616
runs-on: ${{ matrix.os }}
1717
steps:

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.5.0
44
hooks:
55
- id: check-toml
66
- id: check-yaml
@@ -9,7 +9,7 @@ repos:
99
- id: end-of-file-fixer
1010
- id: trailing-whitespace
1111
- repo: https://github.com/psf/black
12-
rev: 23.1.0
12+
rev: 24.3.0
1313
hooks:
1414
- id: black
1515
# It is recommended to specify the latest version of Python
@@ -18,12 +18,12 @@ repos:
1818
# https://pre-commit.com/#top_level-default_language_version
1919
language_version: python3.11
2020
- repo: https://github.com/pycqa/isort
21-
rev: 5.12.0
21+
rev: 5.13.2
2222
hooks:
2323
- id: isort
2424
name: isort (python)
2525
- repo: https://github.com/astral-sh/ruff-pre-commit
2626
# Ruff version.
27-
rev: v0.0.275
27+
rev: v0.3.3
2828
hooks:
2929
- id: ruff

pyproject.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ profile = "black"
77
line_length = 110
88

99
[tool.ruff]
10+
line-length = 110
11+
target-version = "py311"
1012
exclude = [
1113
"__init__.py",
1214
]
15+
16+
[tool.ruff.lint]
1317
ignore = [
1418
"N802",
1519
"N803",
@@ -19,22 +23,20 @@ ignore = [
1923
"N816",
2024
"N999",
2125
]
22-
line-length = 110
2326
select = [
2427
"E", # pycodestyle
2528
"F", # pyflakes
2629
"N", # pep8-naming
2730
"W", # pycodestyle
2831
]
29-
target-version = "py311"
3032
extend-select = [
3133
"RUF100", # Warn about unused noqa
3234
]
3335

34-
[tool.ruff.pycodestyle]
36+
[tool.ruff.lint.pycodestyle]
3537
max-doc-length = 79
3638

37-
[tool.ruff.pydocstyle]
39+
[tool.ruff.lint.pydocstyle]
3840
convention = "numpy"
3941

4042
[tool.pytest.ini_options]

python/lsst/sconsUtils/scripts.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import os.path
66
import re
77
import shlex
8+
import shutil
89
import warnings
9-
from distutils.spawn import find_executable
1010
from stat import ST_MODE
1111

1212
from SCons.Script import BUILD_TARGETS, Dir, File, Glob, SConscript
@@ -247,12 +247,12 @@ def finish(defaultTargets=DEFAULT_TARGETS, subDirList=None, ignoreRegex=None):
247247
checkTestStatus_command = state.env.Command(
248248
"checkTestStatus",
249249
[],
250-
"""
251-
@ if [ -d {0} ]; then \
252-
nfail=`find {0} -name "*.failed" | wc -l | sed -e 's/ //g'`; \
250+
f"""
251+
@ if [ -d {testsDir} ]; then \
252+
nfail=`find {testsDir} -name "*.failed" | wc -l | sed -e 's/ //g'`; \
253253
if [ $$nfail -gt 0 ]; then \
254254
echo "Failed test output:" >&2; \
255-
for f in `find {0} -name "*.failed"`; do \
255+
for f in `find {testsDir} -name "*.failed"`; do \
256256
case "$$f" in \
257257
*.xml.failed) \
258258
echo "Global pytest output is in $$f" >&2; \
@@ -263,13 +263,11 @@ def finish(defaultTargets=DEFAULT_TARGETS, subDirList=None, ignoreRegex=None):
263263
esac; \
264264
done; \
265265
echo "The following tests failed:" >&2;\
266-
find {0} -name "*.failed" >&2; \
266+
find {testsDir} -name "*.failed" >&2; \
267267
echo "$$nfail tests failed" >&2; exit 1; \
268268
fi; \
269269
fi; \
270-
""".format(
271-
testsDir
272-
),
270+
""",
273271
)
274272

275273
state.env.Depends(checkTestStatus_command, BUILD_TARGETS) # this is why the check runs last
@@ -372,8 +370,8 @@ def rewrite_shebang(target, source, env):
372370
else:
373371
if not match:
374372
state.log.warn(
375-
"Could not rewrite shebang of {}. Please check"
376-
" file or move it to bin directory.".format(str(src))
373+
f"Could not rewrite shebang of {src}. Please check"
374+
" file or move it to bin directory."
377375
)
378376
outfd.write(first_line)
379377
for line in srcfd.readlines():
@@ -534,7 +532,7 @@ def doc(config="doxygen.conf.in", projectName=None, projectNumber=None, **kwargs
534532
result : ???
535533
???
536534
"""
537-
if not find_executable("doxygen"):
535+
if not shutil.which("doxygen"):
538536
state.log.warn("doxygen executable not found; skipping documentation build.")
539537
return []
540538
if projectName is None:
@@ -677,8 +675,7 @@ def s(ll):
677675
for node in pySingles:
678676
if str(node).startswith("test_"):
679677
state.log.warn(
680-
"Warning: {} should be run independently but"
681-
" can be automatically discovered".format(node)
678+
f"Warning: {node} should be run independently but can be automatically discovered"
682679
)
683680

684681
# Ensure that python tests listed in pySingles are not included in

python/lsst/sconsUtils/tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def runPythonLinter(self):
313313
if no suitable linter configuration was found.
314314
"""
315315
linter: str | None = None
316+
lint_options = ""
316317
root = SCons.Script.Dir("#").abspath
317318

318319
# Never want linters to look in this directory.
@@ -333,6 +334,7 @@ def runPythonLinter(self):
333334
else:
334335
if "tool" in parsed and "ruff" in parsed["tool"]:
335336
linter = "ruff"
337+
lint_options = "check"
336338

337339
# Ruff can complain about noqa in shebang line
338340
# added by sconsUtils to bin/ scripts. Need to ignore.
@@ -371,8 +373,8 @@ def runPythonLinter(self):
371373
for path in glob.glob(os.path.join(self._tmpDir, "linter-*.log*")):
372374
os.unlink(path)
373375

374-
# Specify exclude directories.
375-
lint_options = f"--extend-exclude={','.join(exclude_dirs)}"
376+
# Specify exclude directories. Append to any existing lint options.
377+
lint_options += f" --extend-exclude={','.join(exclude_dirs)}"
376378

377379
cmd = f"""
378380
@printf "%s\\n" 'Running python linter {linter}...';

0 commit comments

Comments
 (0)