Skip to content

Commit 78bc789

Browse files
authored
Enable ruff (#276)
* feat: upgrade to latest version of ruff * fix: run ruff --fix * fix(ruff): avoid using print in production code * fix(ruff): chain expection to avoid shadowing * fix(ruff): avoid 'except:' * feat: activate ruff * style(ruff): don't use + for concatenaiting strings * style(ruff): split too long lines * fix(ruff): chain exceptions to avoid shadowing * fix: don't create a datetime without a timezone * fix: avoid os.system * fix(ruff): avoid shadowing inner variable * fix(ruff/PLR1704): shadow chain argument * feat: integrate mypy.ini into pyproject.toml * feat: migrate test-docker to hatch * fix(ruff): use isintance for type comparison * fixup! feat: integrate mypy.ini into pyproject.toml * fixup! feat: integrate mypy.ini into pyproject.toml * fix(mypy): avoid changing variable type
1 parent ba35b91 commit 78bc789

File tree

26 files changed

+581
-494
lines changed

26 files changed

+581
-494
lines changed

.github/workflows/test-docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ jobs:
4141

4242
- name: Pytest in the Docker image
4343
run: |
44-
docker run --entrypoint /opt/venv/bin/pytest aleph-client:${GITHUB_REF##*/} /opt/aleph-client/
44+
docker run -w /opt/aleph-client --entrypoint /opt/venv/bin/hatch aleph-client:${GITHUB_REF##*/} run testing:test
4545
4646
- name: MyPy in the Docker image
4747
run: |-
48-
docker run --entrypoint /opt/venv/bin/mypy aleph-client:${GITHUB_REF##*/} --config-file /opt/aleph-client/mypy.ini /opt/aleph-client/src/ /opt/aleph-client/tests/
48+
docker run -w /opt/aleph-client --entrypoint /opt/venv/bin/hatch aleph-client:${GITHUB_REF##*/} run linting:all

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ RUN pip install --upgrade pip wheel twine
2121
# Preinstall dependencies for faster steps
2222
RUN pip install --upgrade secp256k1 coincurve aiohttp eciespy python-magic typer
2323
RUN pip install --upgrade 'aleph-message~=0.3.2' eth_account pynacl base58
24-
RUN pip install --upgrade pytest pytest-cov pytest-asyncio mypy types-setuptools pytest-asyncio fastapi httpx requests
24+
RUN pip install --upgrade hatch
2525

2626
WORKDIR /opt/aleph-client/
2727
COPY . .

docs/conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# This file is execfile()d with the current directory set to its containing dir.
43
#
@@ -52,8 +51,8 @@
5251
args = args[1:]
5352

5453
apidoc.main(args)
55-
except Exception as e:
56-
print("Running `sphinx-apidoc` failed!\n{}".format(e))
54+
except Exception:
55+
pass
5756

5857
# -- General configuration -----------------------------------------------------
5958

mypy.ini

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

pyproject.toml

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ python = [ "3.9", "3.10", "3.11", "3.12" ]
117117
dependencies = [
118118
"black==24.4.2",
119119
"mypy==1.10.0",
120-
"ruff==0.4.9",
120+
"ruff==0.9.*",
121121
"isort==5.13.2",
122122
"yamlfix==1.16.1",
123123
"pyproject-fmt==2.2.1",
@@ -129,15 +129,15 @@ dependencies = [
129129
[tool.hatch.envs.linting.scripts]
130130
typing = "mypy --config-file=pyproject.toml {args:} ./src/ ./tests/"
131131
style = [
132-
# "ruff {args:}",
132+
"ruff check {args:}",
133133
"black --check --diff {args:} ./src/ ./tests/",
134134
"isort --check-only --profile black {args:} ./src/ ./tests/",
135135
"yamlfix --check .",
136136
"pyproject-fmt --check pyproject.toml",
137137
]
138138
fmt = [
139139
"black {args:} ./src/ ./tests/",
140-
# "ruff --fix {args:}",
140+
"ruff check --fix {args:}",
141141
"isort --profile black {args:} ./src/ ./tests/",
142142
"yamlfix .",
143143
"pyproject-fmt pyproject.toml",
@@ -155,7 +155,9 @@ target-version = [ "py39" ]
155155
[tool.ruff]
156156
target-version = "py39"
157157
line-length = 120
158-
select = [
158+
exclude = [ "docs/", "scripts/gendoc.py" ]
159+
160+
lint.select = [
159161
"A",
160162
"ARG",
161163
"B",
@@ -182,21 +184,44 @@ select = [
182184
"W",
183185
"YTT",
184186
]
185-
ignore = [
186-
# # Allow non-abstract empty methods in abstract base classes
187-
# "B027",
188-
# # Allow boolean positional values in function calls, like `dict.get(... True)`
189-
# "FBT003",
190-
# # Ignore checks for possible passwords
191-
# "S105", "S106", "S107",
192-
# # Ignore complexity
193-
# "C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
187+
lint.ignore = [
188+
"A001",
189+
"A002",
190+
"ARG001",
191+
"ARG002",
192+
# Be compatible with typer
193+
"B008",
194+
# Ignore complexity
195+
"C901",
196+
# Allow boolean arguments in functions definitions
197+
"FBT001",
198+
"FBT002",
199+
"FBT003",
200+
# to avoid errors on variables like total_kB
201+
"N815",
202+
"PLR0911",
203+
"PLR0912",
204+
"PLR0913",
205+
"PLR0915",
206+
"PLR2004",
207+
"RUF012",
194208
# Allow the use of assert statements
195209
"S101",
210+
# Ignore checks for possible passwords
211+
"S105", # "S106", "S107",
212+
# ignore false positive
213+
"S603",
214+
# don't perform this modification:
215+
# Union[a, b] -> a | b /Optional[type] -> type | None
216+
# since python 3.9 doesn't support it
217+
"UP007",
196218
]
197-
198219
#[tool.ruff.isort]
199220
#known-first-party = ["aleph_client"]
221+
lint.per-file-ignores."src/aleph_client/commands/help_strings.py" = [ "E501" ]
222+
lint.per-file-ignores."tests/unit/*" = [ "T201" ]
223+
224+
lint.per-file-ignores."tests/unit/test_instance.py" = [ "S106", "T201" ]
200225

201226
[tool.pytest.ini_options]
202227
pythonpath = [
@@ -227,9 +252,60 @@ exclude_lines = [
227252
python_version = "3.9"
228253
install_types = true
229254
non_interactive = true
230-
ignore_missing_imports = true
231255
explicit_package_bases = true
256+
exclude = "conftest.py"
257+
show_column_numbers = true
258+
259+
# Suppressing errors
260+
# Shows errors related to strict None checking, if the global strict_optional flag is enabled
261+
strict_optional = true
262+
no_implicit_optional = true
263+
264+
# Import discovery
265+
# Suppresses error messages about imports that cannot be resolved
266+
ignore_missing_imports = true
267+
# Forces import to reference the original source file
268+
no_implicit_reexport = true
269+
# show error messages from unrelated files
270+
follow_imports = "silent"
271+
follow_imports_for_stubs = false
272+
273+
# Disallow dynamic typing
274+
# Disallows usage of types that come from unfollowed imports
275+
disallow_any_unimported = false
276+
# Disallows all expressions in the module that have type Any
277+
disallow_any_expr = false
278+
# Disallows functions that have Any in their signature after decorator transformation.
279+
disallow_any_decorated = false
280+
# Disallows explicit Any in type positions such as type annotations and generic type parameters.
281+
disallow_any_explicit = false
282+
# Disallows usage of generic types that do not specify explicit type parameters.
283+
disallow_any_generics = false
284+
# Disallows subclassing a value of type Any.
285+
disallow_subclassing_any = false
286+
287+
# Untyped definitions and calls
288+
# Disallows calling functions without type annotations from functions with type annotations.
289+
disallow_untyped_calls = false
290+
# Disallows defining functions without type annotations or with incomplete type annotations
291+
disallow_untyped_defs = false
292+
# Disallows defining functions with incomplete type annotations.
232293
check_untyped_defs = true
294+
# Type-checks the interior of functions without type annotations.
295+
disallow_incomplete_defs = false
296+
# Reports an error whenever a function with type annotations is decorated with a decorator without annotations.
297+
disallow_untyped_decorators = false
298+
299+
# Prohibit comparisons of non-overlapping types (ex: 42 == "no")
300+
strict_equality = true
301+
302+
# Configuring warnings
303+
# Warns about unneeded # type: ignore comments.
304+
warn_unused_ignores = true
305+
# Shows errors for missing return statements on some execution paths.
306+
warn_no_return = true
307+
# Shows a warning when returning a value with type Any from a function declared with a non- Any return type.
308+
warn_return_any = false
233309

234310
[tool.spinx]
235311
source-dir = "docs"

scripts/gendoc.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"""
55

66
import importlib.util
7-
import os
87
import re
98
import sys
109
from pathlib import Path
11-
from typing import Any, List, Optional
10+
from typing import Any, Optional
1211

1312
import click
1413
import typer
@@ -52,7 +51,7 @@ def maybe_update_state(ctx: click.Context) -> None:
5251

5352

5453
class TyperCLIGroup(typer.core.TyperGroup):
55-
def list_commands(self, ctx: click.Context) -> List[str]:
54+
def list_commands(self, ctx: click.Context) -> list[str]:
5655
self.maybe_add_run(ctx)
5756
return super().list_commands(ctx)
5857

@@ -273,7 +272,7 @@ def docs(
273272
),
274273
title: Optional[str] = typer.Option(
275274
None,
276-
help="The title for the documentation page. If not provided, the name of " "the program is used.",
275+
help="The title for the documentation page. If not provided, the name of the program is used.",
277276
),
278277
) -> None:
279278
"""

src/aleph_client/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
def __getattr__(name):
1414
if name in moved_types:
15-
raise ImportError(
16-
f"The 'aleph_client.{name}' type is deprecated and has been removed from aleph_client. Please use `aleph.sdk.{name}` instead."
15+
msg = (
16+
f"The 'aleph_client.{name}' type is deprecated and has been removed from "
17+
f"aleph_client. Please use `aleph.sdk.{name}` instead."
1718
)
19+
raise ImportError(msg)

0 commit comments

Comments
 (0)