Skip to content

Commit 421a711

Browse files
ci: upgrade ruff (#1325)
Ruff was added at the beginning of the project in an experimental way but it has demonstrated to be a robust, performant and great tool. Now it is quitely outdated. This is the minimal change required to upgrade it. I want to iterate over its configuration to provide more coverage. Includes: - Upgrade ruff dependency in poetry - Update the syntax of commands and configuration - Refactor some parts of the code that would raise lint errors with the current config - type-comparison (E721) Signed-off-by: Alex <[email protected]>
1 parent e6e49f1 commit 421a711

File tree

6 files changed

+55
-51
lines changed

6 files changed

+55
-51
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: poetry run isort --check .
4141

4242
- name: Lint with ruff
43-
run: poetry run ruff --show-source .
43+
run: poetry run ruff check .
4444

4545
- name: Lint with flake8
4646
run: poetry run flake8 . --count --show-source --statistics

Taskfile.dist.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ tasks:
102102
lint:ruff:
103103
desc: "Check code with `ruff`."
104104
cmds:
105-
- poetry run ruff -- {{.CLI_ARGS | default "."}}
105+
- poetry run ruff check -- {{.CLI_ARGS | default "."}}
106106

107107
lint:flake8:
108108
desc: "Check code with `flake8`."

poetry.lock

Lines changed: 41 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ line_length = 79
120120

121121
[tool.ruff]
122122
line-length = 79
123+
124+
[tool.ruff.lint]
123125
select = [
124126
"E",
125127
"F",
@@ -130,7 +132,8 @@ extend-ignore = [
130132
"D1", # Missing docstrings errors
131133
]
132134

133-
[tool.ruff.per-file-ignores]
135+
136+
[tool.ruff.lint.per-file-ignores]
134137
"__init__.py" = ["F401"]
135138
"src/aap_eda/core/migrations/*" = ["E501"]
136139
"tests/**/*.py" = [
@@ -140,8 +143,8 @@ extend-ignore = [
140143
"D", # Docstrings are not required in tests
141144
]
142145

143-
[tool.ruff.flake8-tidy-imports]
146+
[tool.ruff.lint.flake8-tidy-imports]
144147
ban-relative-imports = "parents"
145148

146-
[tool.ruff.pydocstyle]
149+
[tool.ruff.lint.pydocstyle]
147150
convention = "pep257"

src/aap_eda/settings/post_load.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,19 @@ def _set_resource_server(settings: Dynaconf) -> None:
388388

389389
def _enforce_types(settings: Dynaconf) -> None:
390390
for key, key_type in get_type_hints(defaults).items():
391-
if key_type == defaults.StrToList:
391+
if key_type is defaults.StrToList:
392392
settings[key] = _get_list_from_str(settings, key)
393-
elif key_type == bool:
393+
elif key_type is bool:
394394
settings[key] = get_boolean(settings, key)
395-
elif key_type == int:
395+
elif key_type is int:
396396
settings[key] = _get_int(settings, key)
397-
elif key_type == defaults.UrlSlash:
397+
elif key_type is defaults.UrlSlash:
398398
settings[key] = _get_url_end_slash(settings, key)
399399
elif not isinstance(settings[key], key_type):
400400
raise ImproperlyConfigured(
401401
f"{key} setting must be a {key_type.__name__}"
402402
)
403-
elif key_type == str or key_type == Optional[str]:
403+
elif key_type is str or key_type is Optional[str]:
404404
settings[key] = _get_stripped_str(settings, key)
405405

406406

tests/unit/test_application_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_application_setting_bad_type():
6464
settings_registry.get_setting_type(
6565
"_GATEWAY_ANALYTICS_SETTING_SYNC_TIME"
6666
)
67-
== int
67+
is int
6868
)
6969
with pytest.raises(InvalidValueError):
7070
application_settings._GATEWAY_ANALYTICS_SETTING_SYNC_TIME = "bad_type"

0 commit comments

Comments
 (0)