Skip to content

Commit 84a5f72

Browse files
authored
🔧 Replace black/isort/pyupgrade/flake8 with ruff (#1080)
1 parent 8e2fcd6 commit 84a5f72

File tree

218 files changed

+6067
-1358
lines changed

Some content is hidden

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

218 files changed

+6067
-1358
lines changed

‎.flake8

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

‎.pre-commit-config.yaml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 24.2.0
4-
hooks:
5-
- id: black
6-
7-
- repo: https://github.com/PyCQA/flake8
8-
rev: 7.0.0
9-
hooks:
10-
- id: flake8
11-
additional_dependencies:
12-
- flake8-bugbear
13-
- flake8-comprehensions
14-
- flake8-simplify
15-
- pep8-naming
16-
17-
- repo: https://github.com/pycqa/isort
18-
rev: 5.13.2
19-
hooks:
20-
- id: isort
212

22-
- repo: https://github.com/asottile/pyupgrade
23-
rev: v3.15.0
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.1.6
245
hooks:
25-
- id: pyupgrade
26-
args:
27-
- --py38-plus
6+
- id: ruff
7+
args: [--fix]
8+
- id: ruff-format
289

2910
- repo: https://github.com/pre-commit/mirrors-mypy
3011
rev: v1.8.0

‎docs/conf.py

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
needs_debug_measurement = True
5656

5757
add_module_names = False # Used to shorten function name output
58-
autodoc_docstring_signature = True # Used to read spec. func-defs from docstring (e.g. get rid of self)
58+
autodoc_docstring_signature = (
59+
True # Used to read spec. func-defs from docstring (e.g. get rid of self)
60+
)
5961

6062
NOTE_TEMPLATE = """
6163
.. _{{id}}:
@@ -80,9 +82,7 @@
8082
{% endif %}
8183
"""
8284

83-
DEFAULT_DIAGRAM_TEMPLATE = (
84-
"<size:12>{{type_name}}</size>\\n**{{title|wordwrap(15, wrapstring='**\\\\n**')}}**\\n<size:10>{{id}}</size>"
85-
)
85+
DEFAULT_DIAGRAM_TEMPLATE = "<size:12>{{type_name}}</size>\\n**{{title|wordwrap(15, wrapstring='**\\\\n**')}}**\\n<size:10>{{id}}</size>"
8686

8787
# You can uncomment some of the following lines to override the default configuration for Sphinx-Needs.
8888
# needs_diagram_template = DEFAULT_DIAGRAM_TEMPLATE
@@ -110,16 +110,71 @@
110110
"color": "#BFD8D2",
111111
"style": "card",
112112
},
113-
{"directive": "sys", "title": "System", "content": "plantuml", "prefix": "S_", "color": "#BFD8D2", "style": "card"},
113+
{
114+
"directive": "sys",
115+
"title": "System",
116+
"content": "plantuml",
117+
"prefix": "S_",
118+
"color": "#BFD8D2",
119+
"style": "card",
120+
},
114121
# Normal types
115-
{"directive": "req", "title": "Requirement", "prefix": "R_", "color": "#BFD8D2", "style": "node"},
116-
{"directive": "spec", "title": "Specification", "prefix": "S_", "color": "#FEDCD2", "style": "node"},
117-
{"directive": "impl", "title": "Implementation", "prefix": "I_", "color": "#DF744A", "style": "node"},
118-
{"directive": "test", "title": "Test Case", "prefix": "T_", "color": "#DCB239", "style": "node"},
119-
{"directive": "feature", "title": "Feature", "prefix": "F_", "color": "#FFCC00", "style": "node"},
120-
{"directive": "user", "title": "User", "prefix": "U_", "color": "#777777", "style": "node"},
121-
{"directive": "action", "title": "Action", "prefix": "A_", "color": "#FFCC00", "style": "node"},
122-
{"directive": "milestone", "title": "Milestone", "prefix": "M_", "color": "#FF3333", "style": "node"},
122+
{
123+
"directive": "req",
124+
"title": "Requirement",
125+
"prefix": "R_",
126+
"color": "#BFD8D2",
127+
"style": "node",
128+
},
129+
{
130+
"directive": "spec",
131+
"title": "Specification",
132+
"prefix": "S_",
133+
"color": "#FEDCD2",
134+
"style": "node",
135+
},
136+
{
137+
"directive": "impl",
138+
"title": "Implementation",
139+
"prefix": "I_",
140+
"color": "#DF744A",
141+
"style": "node",
142+
},
143+
{
144+
"directive": "test",
145+
"title": "Test Case",
146+
"prefix": "T_",
147+
"color": "#DCB239",
148+
"style": "node",
149+
},
150+
{
151+
"directive": "feature",
152+
"title": "Feature",
153+
"prefix": "F_",
154+
"color": "#FFCC00",
155+
"style": "node",
156+
},
157+
{
158+
"directive": "user",
159+
"title": "User",
160+
"prefix": "U_",
161+
"color": "#777777",
162+
"style": "node",
163+
},
164+
{
165+
"directive": "action",
166+
"title": "Action",
167+
"prefix": "A_",
168+
"color": "#FFCC00",
169+
"style": "node",
170+
},
171+
{
172+
"directive": "milestone",
173+
"title": "Milestone",
174+
"prefix": "M_",
175+
"color": "#FF3333",
176+
"style": "node",
177+
},
123178
]
124179

125180
needs_extra_links = [
@@ -208,7 +263,9 @@
208263
needs_id_required = False
209264
# needs_css = "dark.css"
210265

211-
local_plantuml_path = os.path.join(os.path.dirname(__file__), "utils", "plantuml-1.2022.14.jar")
266+
local_plantuml_path = os.path.join(
267+
os.path.dirname(__file__), "utils", "plantuml-1.2022.14.jar"
268+
)
212269
plantuml = f"java -Djava.awt.headless=true -jar {local_plantuml_path}"
213270

214271
# plantuml_output_format = 'png'
@@ -246,7 +303,10 @@
246303
"grid": "simple_side_right_partial",
247304
"layout": {
248305
"head": ['**<<meta("title")>>** for *<<meta("author")>>*'],
249-
"meta": ['**status**: <<meta("status")>>', '**author**: <<meta("author")>>'],
306+
"meta": [
307+
'**status**: <<meta("status")>>',
308+
'**author**: <<meta("author")>>',
309+
],
250310
"side": ['<<image("_images/{{author}}.png", align="center")>>'],
251311
},
252312
},
@@ -450,14 +510,22 @@ def custom_defined_func():
450510
# (source start file, target name, title,
451511
# author, documentclass [howto, manual, or own class]).
452512
latex_documents = [
453-
(master_doc, "needstestdocs.tex", "needs test docs Documentation", "team useblocks", "manual"),
513+
(
514+
master_doc,
515+
"needstestdocs.tex",
516+
"needs test docs Documentation",
517+
"team useblocks",
518+
"manual",
519+
),
454520
]
455521

456522
# -- Options for manual page output ---------------------------------------
457523

458524
# One entry per manual page. List of tuples
459525
# (source start file, name, description, authors, manual section).
460-
man_pages = [(master_doc, "needstestdocs", "needs test docs Documentation", [author], 1)]
526+
man_pages = [
527+
(master_doc, "needstestdocs", "needs test docs Documentation", [author], 1)
528+
]
461529

462530
# -- Options for Texinfo output -------------------------------------------
463531

@@ -478,7 +546,11 @@ def custom_defined_func():
478546

479547
# contains different constraints
480548
needs_constraints = {
481-
"critical": {"check_0": "'critical' in tags", "check_1": "'SECURITY_REQ' in links", "severity": "CRITICAL"},
549+
"critical": {
550+
"check_0": "'critical' in tags",
551+
"check_1": "'SECURITY_REQ' in links",
552+
"severity": "CRITICAL",
553+
},
482554
"security": {"check_0": "'security' in tags", "severity": "HIGH"},
483555
"team": {"check_0": 'author == "Bob"', "severity": "LOW"},
484556
}

‎noxfile.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ def pre_commit(session):
7272
def linkcheck(session):
7373
session.install(".[docs]")
7474
with session.chdir("docs"):
75-
session.run("sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *session.posargs, external=True)
75+
session.run(
76+
"sphinx-build",
77+
"-b",
78+
"linkcheck",
79+
".",
80+
"_build/linkcheck",
81+
*session.posargs,
82+
external=True,
83+
)
7684

7785

7886
@session(python="3.11")

‎performance/performance_test.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ def cli():
2323

2424

2525
def start(
26-
needs=1000, needtables=0, dummies=0, pages=1, parallel=1, keep=False, browser=False, debug=False, basic=False
26+
needs=1000,
27+
needtables=0,
28+
dummies=0,
29+
pages=1,
30+
parallel=1,
31+
keep=False,
32+
browser=False,
33+
debug=False,
34+
basic=False,
2735
):
2836
"""
2937
Test run implementation
@@ -163,11 +171,31 @@ def start(
163171

164172

165173
@cli.command()
166-
@click.option("--profile", default=[], type=str, multiple=True, help="Activates profiling for given area")
167-
@click.option("--needs", default=[50, 10], type=int, multiple=True, help="Number of maximum needs.")
168-
@click.option("--needtables", default=-1, type=int, help="Number of maximum needtables.")
174+
@click.option(
175+
"--profile",
176+
default=[],
177+
type=str,
178+
multiple=True,
179+
help="Activates profiling for given area",
180+
)
181+
@click.option(
182+
"--needs",
183+
default=[50, 10],
184+
type=int,
185+
multiple=True,
186+
help="Number of maximum needs.",
187+
)
188+
@click.option(
189+
"--needtables", default=-1, type=int, help="Number of maximum needtables."
190+
)
169191
@click.option("--dummies", default=-1, type=int, help="Number of standard rst dummies.")
170-
@click.option("--pages", default=[5, 1], type=int, multiple=True, help="Number of additional pages with needs.")
192+
@click.option(
193+
"--pages",
194+
default=[5, 1],
195+
type=int,
196+
multiple=True,
197+
help="Number of additional pages with needs.",
198+
)
171199
@click.option(
172200
"--parallel",
173201
default=[1, 4],
@@ -177,9 +205,19 @@ def start(
177205
)
178206
@click.option("--keep", is_flag=True, help="Keeps the temporary src and build folders")
179207
@click.option("--browser", is_flag=True, help="Opens the project in your browser")
180-
@click.option("--snakeviz", is_flag=True, help="Opens snakeviz view for measured profiles in browser")
181-
@click.option("--debug", is_flag=True, help="Prints more information, incl. sphinx build output")
182-
@click.option("--basic", is_flag=True, help="Use only default config of Sphinx-Needs (e.g. no extra options)")
208+
@click.option(
209+
"--snakeviz",
210+
is_flag=True,
211+
help="Opens snakeviz view for measured profiles in browser",
212+
)
213+
@click.option(
214+
"--debug", is_flag=True, help="Prints more information, incl. sphinx build output"
215+
)
216+
@click.option(
217+
"--basic",
218+
is_flag=True,
219+
help="Use only default config of Sphinx-Needs (e.g. no extra options)",
220+
)
183221
def series(
184222
profile,
185223
needs,

‎pyproject.toml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,19 @@ markers = [
101101
"jstest: marks tests as JavaScript test (deselect with '-m \"not jstest\"')",
102102
]
103103

104-
[tool.black]
105-
line-length = 120
106-
107-
[tool.isort]
108-
profile = "black"
104+
[tool.ruff]
105+
extend-select = [
106+
"B", # flake8-bugbear
107+
"C4", # flake8-comprehensions
108+
"I", # isort
109+
"ICN", # flake8-import-conventions
110+
"ISC", # flake8-implicit-str-concat
111+
"N", # pep8-naming
112+
"RUF", # Ruff-specific rules
113+
"SIM", # flake8-simplify
114+
"UP", # pyupgrade
115+
]
116+
extend-ignore = ["B904", "ISC001", "ICN001", "N818", "RUF005", "RUF013", "RUF012", "SIM108", "SIM118"]
109117

110118
[tool.mypy]
111119
files = "sphinx_needs"

‎sphinx_needs/api/configuration.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def get_need_types(app: Sphinx) -> list[str]:
3737

3838

3939
def add_need_type(
40-
app: Sphinx, directive: str, title: str, prefix: str, color: str = "#ffffff", style: str = "node"
40+
app: Sphinx,
41+
directive: str,
42+
title: str,
43+
prefix: str,
44+
color: str = "#ffffff",
45+
style: str = "node",
4146
) -> None:
4247
"""
4348
Adds a new need_type to the configuration.
@@ -68,7 +73,15 @@ def add_need_type(
6873
if directive in type_names:
6974
raise NeedsApiConfigException(f"{directive} already exists as need type")
7075

71-
needs_types.append({"directive": directive, "title": title, "prefix": prefix, "color": color, "style": style})
76+
needs_types.append(
77+
{
78+
"directive": directive,
79+
"title": title,
80+
"prefix": prefix,
81+
"color": color,
82+
"style": style,
83+
}
84+
)
7285
app.add_directive(directive, sphinx_needs.directives.need.NeedDirective)
7386

7487

@@ -93,7 +106,9 @@ def add_extra_option(app: Sphinx, name: str) -> None:
93106
NEEDS_CONFIG.extra_options[name] = directives.unchanged
94107

95108

96-
def add_dynamic_function(app: Sphinx, function: DynamicFunction, name: str | None = None) -> None:
109+
def add_dynamic_function(
110+
app: Sphinx, function: DynamicFunction, name: str | None = None
111+
) -> None:
97112
"""
98113
Registers a new dynamic function for sphinx-needs.
99114
@@ -124,7 +139,12 @@ def my_function(app, need, needs, *args, **kwargs):
124139
WarningCheck = Callable[[NeedsInfoType, SphinxLoggerAdapter], bool]
125140

126141

127-
def add_warning(app: Sphinx, name: str, function: WarningCheck | None = None, filter_string: str | None = None) -> None:
142+
def add_warning(
143+
app: Sphinx,
144+
name: str,
145+
function: WarningCheck | None = None,
146+
filter_string: str | None = None,
147+
) -> None:
128148
"""
129149
Registers a warning.
130150
@@ -137,11 +157,14 @@ def add_warning(app: Sphinx, name: str, function: WarningCheck | None = None, fi
137157
:return: None
138158
"""
139159
if function is None and filter_string is None:
140-
raise NeedsApiConfigException("Function or filter_string must be given for add_warning_func")
160+
raise NeedsApiConfigException(
161+
"Function or filter_string must be given for add_warning_func"
162+
)
141163

142164
if function is not None and filter_string is not None:
143165
raise NeedsApiConfigException(
144-
"For add_warning_func only function or filter_string is allowed to be set, " "not both."
166+
"For add_warning_func only function or filter_string is allowed to be set, "
167+
"not both."
145168
)
146169

147170
warning_check = function or filter_string

0 commit comments

Comments
 (0)