Skip to content

Commit 76f39f5

Browse files
author
Lukas Pühringer
authored
Merge pull request #2558 from NicholasTanz/replaceLintingTools
Replace most linting tools with ruff
2 parents b5bb27f + f156e21 commit 76f39f5

31 files changed

Lines changed: 109 additions & 162 deletions

.github/dependabot.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ updates:
1616
# Python dependencies that are only pinned to ensure test reproducibility
1717
patterns:
1818
- "bandit"
19-
- "black"
2019
- "coverage"
21-
- "isort"
2220
- "mypy"
23-
- "pydocstyle"
24-
- "pylint"
21+
- "ruff"
2522
- "tox"
2623
dependencies:
2724
# Python (developer) runtime dependencies. Also any new dependencies not

examples/repository/_simplerepo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def _get_verification_result(
112112
)
113113

114114
def open(self, role: str) -> Metadata:
115-
"""Return current Metadata for role from 'storage' (or create a new one)"""
115+
"""Return current Metadata for role from 'storage'
116+
(or create a new one)
117+
"""
116118

117119
if role not in self.role_cache:
118120
signed_init = _signed_init.get(role, Targets)

examples/uploader/_localrepo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def open(self, role: str) -> Metadata:
6262

6363
# if there is a metadata version fetched from remote, use that
6464
# HACK: access Updater internals
65-
# pylint: disable=protected-access
6665
if role in self.updater._trusted_set:
6766
return copy.deepcopy(self.updater._trusted_set[role])
6867

@@ -105,7 +104,7 @@ def add_target(self, role: str, targetpath: str) -> bool:
105104
with self.edit_targets(role) as delegated:
106105
delegated.targets[targetpath] = targetfile
107106

108-
except Exception as e: # pylint: disable=broad-except
107+
except Exception as e:
109108
print(f"Failed to submit new {role} with added target: {e}")
110109
return False
111110

pyproject.toml

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -75,67 +75,25 @@ include = [
7575
# from `tests` so the root directory must be added to Python's path for editable installations
7676
dev-mode-dirs = ["."]
7777

78-
# Black section
79-
# Read more here: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
80-
[tool.black]
78+
# Ruff section
79+
# Read more here: https://docs.astral.sh/ruff/linter/#rule-selection
80+
[tool.ruff]
8181
line-length=80
8282

83-
# Isort section
84-
# Read more here: https://pycqa.github.io/isort/docs/configuration/config_files.html
85-
[tool.isort]
86-
profile="black"
87-
line_length=80
88-
known_first_party = ["tuf"]
89-
90-
# Pylint section
91-
92-
# Minimal pylint configuration file for Secure Systems Lab Python Style Guide:
93-
# https://github.com/secure-systems-lab/code-style-guidelines
94-
#
95-
# Based on Google Python Style Guide pylintrc and pylint defaults:
96-
# https://google.github.io/styleguide/pylintrc
97-
# http://pylint.pycqa.org/en/latest/technical_reference/features.html
98-
99-
[tool.pylint.message_control]
100-
# Disable the message, report, category or checker with the given id(s).
101-
# NOTE: To keep this config as short as possible we only disable checks that
102-
# are currently in conflict with our code. If new code displeases the linter
103-
# (for good reasons) consider updating this config file, or disable checks with.
104-
disable=[
105-
"fixme",
106-
"too-few-public-methods",
107-
"too-many-arguments",
108-
"format",
109-
"duplicate-code"
110-
]
111-
112-
[tool.pylint.basic]
113-
good-names = ["i","j","k","v","e","f","fn","fp","_type","_"]
114-
# Regexes for allowed names are copied from the Google pylintrc
115-
# NOTE: Pylint captures regex name groups such as 'snake_case' or 'camel_case'.
116-
# If there are multiple groups it enfoces the prevalent naming style inside
117-
# each modules. Names in the exempt capturing group are ignored.
118-
function-rgx="^(?:(?P<exempt>setUp|tearDown|setUpModule|tearDownModule)|(?P<camel_case>_?[A-Z][a-zA-Z0-9]*)|(?P<snake_case>_?[a-z][a-z0-9_]*))$"
119-
method-rgx="(?x)^(?:(?P<exempt>_[a-z0-9_]+__|runTest|setUp|tearDown|setUpTestCase|tearDownTestCase|setupSelf|tearDownClass|setUpClass|(test|assert)_*[A-Z0-9][a-zA-Z0-9_]*|next)|(?P<camel_case>_{0,2}[A-Z][a-zA-Z0-9_]*)|(?P<snake_case>_{0,2}[a-z][a-z0-9_]*))$"
120-
argument-rgx="^[a-z][a-z0-9_]*$"
121-
attr-rgx="^_{0,2}[a-z][a-z0-9_]*$"
122-
class-attribute-rgx="^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$"
123-
class-rgx="^_?[A-Z][a-zA-Z0-9]*$"
124-
const-rgx="^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$"
125-
inlinevar-rgx="^[a-z][a-z0-9_]*$"
126-
module-rgx="^(_?[a-z][a-z0-9_]*|__init__)$"
127-
no-docstring-rgx="(__.*__|main|test.*|.*test|.*Test)$"
128-
variable-rgx="^[a-z][a-z0-9_]*$"
129-
docstring-min-length=10
130-
131-
[tool.pylint.logging]
132-
logging-format-style="old"
133-
134-
[tool.pylint.miscellaneous]
135-
notes="TODO"
136-
137-
[tool.pylint.STRING]
138-
check-quote-consistency="yes"
83+
[tool.ruff.lint]
84+
select = [
85+
"D", # pydocstyle
86+
"E", # pycodestyle
87+
"F", # pyflakes
88+
"I", # isort
89+
"N", # pep8-naming
90+
"PL", # pylint
91+
]
92+
ignore = ["D400","D415","D213","D205","D202","D107","D407","D413","D212","D104","D406","D105","D411","D401","D200","D203", "PLR0913", "PLR2004"]
93+
94+
[tool.ruff.lint.per-file-ignores]
95+
"tests/*" = ["D", "E"]
96+
"examples/*/*" = ["D"]
13997

14098
# mypy section
14199
# Read more here: https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file
@@ -156,7 +114,3 @@ module = [
156114
"securesystemslib.*",
157115
]
158116
ignore_missing_imports = "True"
159-
160-
[tool.pydocstyle]
161-
inherit = false
162-
ignore = "D400,D415,D213,D205,D202,D107,D407,D413,D212,D104,D406,D105,D411,D401,D200,D203"

requirements/lint.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
# Lint tools
77
# (We are not so interested in the specific versions of the tools: the versions
88
# are pinned to prevent unexpected linting failures when tools update)
9-
black==24.2.0
10-
isort==5.13.2
11-
pylint==3.0.3
9+
ruff==0.2.1
1210
mypy==1.8.0
1311
bandit==1.7.7
14-
pydocstyle==6.3.0

tests/repository_simulator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ class RepositoryTarget:
9999
class RepositorySimulator(FetcherInterface):
100100
"""Simulates a repository that can be used for testing."""
101101

102-
# pylint: disable=too-many-instance-attributes
103102
def __init__(self) -> None:
104103
self.md_delegates: Dict[str, Metadata[Targets]] = {}
105104

tests/test_api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
logger = logging.getLogger(__name__)
5757

5858

59-
# pylint: disable=too-many-public-methods,too-many-statements
6059
class TestMetadata(unittest.TestCase):
6160
"""Tests for public API of all classes in 'tuf/api/metadata.py'."""
6261

@@ -246,7 +245,7 @@ def test_sign_failures(self) -> None:
246245
os.path.join(self.repo_dir, "metadata", "snapshot.json")
247246
)
248247

249-
class FailingSigner(Signer): # pylint: disable=missing-class-docstring
248+
class FailingSigner(Signer):
250249
@classmethod
251250
def from_priv_key_uri(
252251
cls,
@@ -365,7 +364,6 @@ def test_metadata_verify_delegate(self) -> None:
365364
role2.verify_delegate("role1", role1)
366365

367366
def test_signed_verify_delegate(self) -> None:
368-
# pylint: disable=too-many-locals,too-many-statements
369367
root_path = os.path.join(self.repo_dir, "metadata", "root.json")
370368
root_md = Metadata[Root].from_file(root_path)
371369
root = root_md.signed
@@ -742,7 +740,6 @@ def test_root_add_key_and_revoke_key(self) -> None:
742740
root.signed.revoke_key(keyid, "nosuchrole")
743741

744742
def test_is_target_in_pathpattern(self) -> None:
745-
# pylint: disable=protected-access
746743
supported_use_cases = [
747744
("foo.tgz", "foo.tgz"),
748745
("foo.tgz", "*"),

tests/test_examples.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def _run_script_and_assert_files(
5353
CWD."""
5454
script_path = str(self.repo_examples_dir / script_name)
5555
with open(script_path, "rb") as f:
56-
# pylint: disable=exec-used
5756
exec(
5857
compile(f.read(), script_path, "exec"),
5958
{"__file__": script_path},

tests/test_metadata_eq_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def setUpClass(cls) -> None:
8989

9090
@utils.run_sub_tests_with_dataset(classes_attributes_modifications)
9191
def test_classes_eq_(self, test_case_data: Dict[str, Any]) -> None:
92-
obj = self.objects[self.case_name] # pylint: disable=no-member
92+
obj = self.objects[self.case_name]
9393

9494
# Assert that obj is not equal to an object from another type
9595
self.assertNotEqual(obj, "")

tests/test_metadata_serialization.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
logger = logging.getLogger(__name__)
3535

3636

37-
# pylint: disable=too-many-public-methods
3837
class TestSerialization(unittest.TestCase):
3938
"""Test serialization for all classes in 'tuf/api/metadata.py'."""
4039

0 commit comments

Comments
 (0)