Skip to content

Commit 7796775

Browse files
authored
switch to ruff and fix some typing (#370)
* replace black and pylint with ruff * type ignore some arg types in monkeypatching * type ignore attr-defined * bump mypy * avoid using Annotated class in attr types of doc'd pydantic model
1 parent 4cc8b81 commit 7796775

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+213
-752
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
include:
23-
- nox-sessions: "black check_yaml check_json check_toml check_eof check_trailing_space check_lf"
23+
- nox-sessions: "ruff_format ruff_lint check_yaml check_json check_toml check_eof check_trailing_space check_lf"
2424
python-version: "3.x"
2525
node-version: "16.x"
26-
- nox-sessions: "mypy pylint"
26+
- nox-sessions: "mypy"
2727
python-version: "3.9"
28-
- nox-sessions: "mypy pylint"
28+
- nox-sessions: "mypy"
2929
python-version: "3.10"
30-
- nox-sessions: "mypy pylint"
30+
- nox-sessions: "mypy"
3131
python-version: "3.11"
32-
- nox-sessions: "mypy pylint"
32+
- nox-sessions: "mypy"
3333
python-version: "3.12"
3434
steps:
3535
- uses: actions/checkout@v4
@@ -54,9 +54,9 @@ jobs:
5454
if: matrix.node-version
5555
with:
5656
path: |
57-
.nox/black
57+
.nox/ruff_*
5858
.nox/check_*
59-
key: nox-${{ steps.python-setup.outputs.python-version }}-${{ hashFiles('requirements/dev-black.txt', 'requirements/dev-pre_commit_hooks.txt') }}
59+
key: nox-${{ steps.python-setup.outputs.python-version }}-${{ hashFiles('requirements/dev-ruff.txt', 'requirements/dev-pre_commit_hooks.txt') }}
6060
- run: npm install
6161
if: matrix.node-version
6262
- run: npm run check

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ nox
44
-r requirements/cpp.txt
55
-r requirements/dev-mypy.txt
66
-r requirements/dev-black.txt
7-
-r requirements/dev-pylint.txt
7+
-r requirements/dev-ruff.txt

docs/conf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def get_colors(color_t: str):
353353
unique_colors.append(m.group(1))
354354
return unique_colors
355355

356+
356357
# jinja contexts
357358
example_python_apigen_modules = {
358359
"my_module": "my_api/",
@@ -373,8 +374,12 @@ def get_colors(color_t: str):
373374
(
374375
full_name,
375376
overload_id,
376-
python_apigen._get_docname(example_python_apigen_modules, full_name, overload_id, False),
377-
python_apigen._get_docname(example_python_apigen_modules, full_name, overload_id, True),
377+
python_apigen._get_docname(
378+
example_python_apigen_modules, full_name, overload_id, False
379+
),
380+
python_apigen._get_docname(
381+
example_python_apigen_modules, full_name, overload_id, True
382+
),
378383
)
379384
for full_name, overload_id in example_python_apigen_objects
380385
],

docs/tensorstore_demo/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
from __future__ import annotations
88
import typing
9-
import _abc
109

11-
from ._tensorstore import *
10+
from ._tensorstore import * # noqa: F403
11+
12+
# fmt: off
1213

1314

1415
class Dim():

docs/test_py_module/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# -*- coding: utf-8 -*-
22
"""Test Module for sphinx_rtd_theme."""
3+
34
import functools
45
from typing import Union
56

67

78
class Foo:
8-
99
"""Docstring for class Foo.
1010
1111
This text tests for the formatting of docstrings generated from output

merge_from_mkdocs_material.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import json
2828
import os
2929
import pathlib
30-
import shutil
3130
import subprocess
3231
import tempfile
3332
from typing import Optional
@@ -243,7 +242,7 @@ def main():
243242
message=f"Original upstream {merge_base} (adjusted)",
244243
)
245244

246-
print(f"\nCreating adjusted commit for sphinx-immaterial")
245+
print("\nCreating adjusted commit for sphinx-immaterial")
247246
subprocess.run(
248247
["git", "remote", "rm", "local-sphinx-immaterial"],
249248
cwd=temp_workdir,
@@ -289,7 +288,7 @@ def main():
289288
parent=old_tree_commit,
290289
)
291290

292-
print(f"\nRebasing")
291+
print("\nRebasing")
293292
subprocess.run(["git", "rebase", new_tree_commit, "HEAD"], cwd=temp_workdir)
294293

295294
with open(patch_path, "wb") as patch_f:

noxfile.py

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

77
nox.options.reuse_existing_virtualenvs = True
88
nox.options.sessions = [
9-
"black",
10-
"pylint",
9+
"ruff_format",
10+
"ruff_lint",
1111
"mypy",
1212
"check_yaml",
1313
"check_json",
@@ -21,17 +21,17 @@
2121

2222

2323
@nox.session
24-
def black(session: nox.Session):
25-
"""Checks formatting linting and typing"""
26-
session.install("-r", "requirements/dev-black.txt")
27-
session.run("black", ".")
24+
def ruff_format(session: nox.Session):
25+
"""Checks formatting with ruff"""
26+
session.install("-r", "requirements/dev-ruff.txt")
27+
session.run("ruff", "format")
2828

2929

30-
@nox.session(python=False)
31-
def pylint(session: nox.Session):
32-
"""Run pylint using in default env"""
33-
session.run("pip", "install", "-r", "requirements/dev-pylint.txt")
34-
session.run("pylint", "sphinx_immaterial")
30+
@nox.session
31+
def ruff_lint(session: nox.Session):
32+
"""Run ruff as linter"""
33+
session.install("-r", "requirements/dev-ruff.txt")
34+
session.run("ruff", "check")
3535

3636

3737
@nox.session(python=False)
@@ -45,7 +45,7 @@ def mypy(session: nox.Session):
4545
"|".join(
4646
[
4747
"\\.git/",
48-
"^\\.(?:mypy|pylint|pytest|eslint)_?cache",
48+
"^\\.(?:mypy|ruff|pytest|eslint)_?cache",
4949
"^(?:\\.nox|\\.?env|\\.?venv)",
5050
"^\\.coverage.*",
5151
"^htmlcov/",

0 commit comments

Comments
 (0)