Skip to content

Commit e95e695

Browse files
authored
Enforce Python type annotations in continuous integration (#1202)
* add initial configuration for ruff * update pre-commit hook versions * test_engine_unittest.py: add type annotations * enforce type annotations in pre-commit and CI * test_PortModule.py: fix import * sst_unittest_support.py: add missing type annotation * test_engine_unittest.py: fix type annotations for Python 3.6 * pre-commit: use newest version of mypy that supports Python 3.6 * test_engine_unittest.py: fix for when testtools isn't installed * pyproject.toml: set (minimum) Python version for pyright * test_engine_unittest.py: type annotation for stream argument
1 parent 80ff4b9 commit e95e695

File tree

5 files changed

+239
-145
lines changed

5 files changed

+239
-145
lines changed

.pre-commit-config.yaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
- id: check-hooks-apply
77
- id: check-useless-excludes
88
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: "v4.6.0"
9+
rev: "v5.0.0"
1010
hooks:
1111
- id: check-case-conflict
1212
- id: check-merge-conflict
@@ -32,6 +32,26 @@ repos:
3232
external/
3333
)
3434
- repo: https://github.com/Mateusz-Grzelinski/actionlint-py
35-
rev: "v1.7.1.15"
35+
rev: "v1.7.7.23"
3636
hooks:
3737
- id: actionlint
38+
- repo: https://github.com/astral-sh/ruff-pre-commit
39+
rev: "v0.9.4"
40+
hooks:
41+
- id: ruff
42+
- repo: https://github.com/pre-commit/mirrors-mypy
43+
# This needs to match the last version that still supports the minimum
44+
# required Python version
45+
rev: "v1.5.1"
46+
hooks:
47+
- id: mypy
48+
additional_dependencies:
49+
- blessings
50+
- testtools
51+
- types-Pygments
52+
# Work around config file setting exclusion rules being bypassed when
53+
# filenames are explicitly passed on the command line. See
54+
# https://github.com/python/mypy/pull/12373#issuecomment-1071662559
55+
# for the idea.
56+
args: [.]
57+
pass_filenames: false

pyproject.toml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
cache_dir = "build/.mypy_cache"
33
explicit_package_bases = true
44
mypy_path = "$MYPY_CONFIG_FILE_DIR/src/sst/core/testingframework"
5-
# This should be 3.6 but is not supported with the newest versions of mypy.
6-
python_version = "3.8"
5+
python_version = "3.6"
76

87
strict = true
8+
warn_unused_ignores = true
99

1010
exclude = [
1111
'^scripts/',
@@ -20,3 +20,42 @@ module = [
2020
"testtools.testsuite",
2121
]
2222
ignore_missing_imports = true
23+
24+
[tool.pyright]
25+
pythonVersion = "3.6"
26+
27+
[tool.ruff]
28+
cache-dir = "build/.ruff_cache"
29+
line-length = 100
30+
# This should be 3.6 but is not supported with the newest versions of ruff.
31+
target-version = "py37"
32+
33+
[tool.ruff.lint]
34+
ignore = [
35+
"E401",
36+
"E402",
37+
"E701",
38+
"E703",
39+
"E713",
40+
"E722",
41+
"E731",
42+
"F401",
43+
"F403",
44+
"F405",
45+
"F523",
46+
"F841",
47+
]
48+
49+
[tool.ruff.lint.isort]
50+
known-first-party = ["sst"]
51+
lines-after-imports = 2
52+
section-order = [
53+
"future",
54+
"standard-library",
55+
"first-party",
56+
"third-party",
57+
"local-folder",
58+
]
59+
60+
[tool.ruff.lint.flake8-tidy-imports]
61+
ban-relative-imports = "all"

src/sst/core/testingframework/sst_unittest_support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def testing_stat_output_diff(
11911191

11921192
### Built in LineFilters for filtering diffs
11931193
class LineFilter:
1194-
def __init__(self):
1194+
def __init__(self) -> None:
11951195
self.apply_to_ref_file = True
11961196
self.apply_to_out_file = True
11971197

@@ -1883,7 +1883,7 @@ def os_extract_tar(tarfilepath: str, targetdir: str = ".") -> bool:
18831883
try:
18841884
this_tar = tarfile.open(tarfilepath)
18851885
if sys.version_info.minor >= 12:
1886-
this_tar.extractall(targetdir, filter="data")
1886+
this_tar.extractall(targetdir, filter="data") # type: ignore [call-arg]
18871887
else:
18881888
this_tar.extractall(targetdir)
18891889
this_tar.close()

0 commit comments

Comments
 (0)