Skip to content

Commit

Permalink
🔧 Update pre-commit hooks (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored May 8, 2024
1 parent 0838672 commit 42962cc
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 66 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.4.3
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.10.0
hooks:
- id: mypy
files: sphinx_needs/.*
Expand All @@ -21,7 +21,7 @@ repos:
- types-requests

- repo: https://github.com/python-poetry/poetry
rev: 1.7.0
rev: 1.8.0
hooks:
- id: poetry-check

Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Fixed

* Fix external needs identifier checked by regex (`#1099 <https://github.com/useblocks/sphinx-needs/pull/1099>`_)
* Fix line number handling for errors and warnings
(PR `#1150 <https://github.com/useblocks/sphinx-needs/pull/1150>`_, Issue `#1077 <https://github.com/useblocks/sphinx-needs/issues/1077>`)
(PR `#1168 <https://github.com/useblocks/sphinx-needs/pull/1150>`_, Issue `#1077 <https://github.com/useblocks/sphinx-needs/issues/1077>`)


2.0.0
Expand Down
6 changes: 3 additions & 3 deletions sphinx_needs/diagrams_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def get_filter_para(node_element: NeedsFilteredBaseType) -> nodes.paragraph:
para = nodes.paragraph()
filter_text = "Used filter:"
filter_text += (
" status(%s)" % " OR ".join(node_element["status"])
" status({})".format(" OR ".join(node_element["status"]))
if len(node_element["status"]) > 0
else ""
)
if len(node_element["status"]) > 0 and len(node_element["tags"]) > 0:
filter_text += " AND "
filter_text += (
" tags(%s)" % " OR ".join(node_element["tags"])
" tags({})".format(" OR ".join(node_element["tags"]))
if len(node_element["tags"]) > 0
else ""
)
Expand All @@ -144,7 +144,7 @@ def get_filter_para(node_element: NeedsFilteredBaseType) -> nodes.paragraph:
) > 0:
filter_text += " AND "
filter_text += (
" types(%s)" % " OR ".join(node_element["types"])
" types({})".format(" OR ".join(node_element["types"]))
if len(node_element["types"]) > 0
else ""
)
Expand Down
6 changes: 3 additions & 3 deletions sphinx_needs/directives/list2need.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ def run(self) -> Sequence[nodes.Node]:
more_text = more_text.lstrip()
if more_text.startswith(":"):
more_text = f" {more_text}"
list_needs[-1][
"content"
] = f"{list_needs[-1]['content']}\n {more_text}"
list_needs[-1]["content"] = (
f"{list_needs[-1]['content']}\n {more_text}"
)

# Finally creating the rst code
overall_text = []
Expand Down
26 changes: 13 additions & 13 deletions sphinx_needs/directives/needfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ def process_needfilters(
description = "{}: {}".format(need_info["id"], need_info["title"])

if current_needfilter["show_status"] and need_info["status"]:
description += " (%s)" % need_info["status"]
description += " ({})".format(need_info["status"])

if current_needfilter["show_tags"] and need_info["tags"]:
description += " [%s]" % "; ".join(need_info["tags"])
description += " [{}]".format("; ".join(need_info["tags"]))

title = nodes.Text(description)

Expand Down Expand Up @@ -227,14 +227,14 @@ def process_needfilters(
**need_info, **needs_config.render_context
)

puml_node[
"uml"
] += '{style} "{node_text}" as {id} [[{link}]] {color}\n'.format(
id=need_info["id"],
node_text=node_text,
link=link,
color=need_info["type_color"],
style=need_info["type_style"],
puml_node["uml"] += (
'{style} "{node_text}" as {id} [[{link}]] {color}\n'.format(
id=need_info["id"],
node_text=node_text,
link=link,
color=need_info["type_color"],
style=need_info["type_style"],
)
)
for link in need_info["links"]:
puml_connections += "{id} --> {link}\n".format(
Expand Down Expand Up @@ -266,7 +266,7 @@ def process_needfilters(
para_node = nodes.paragraph()
filter_text = "Used filter:"
filter_text += (
" status(%s)" % " OR ".join(current_needfilter["status"])
" status({})".format(" OR ".join(current_needfilter["status"]))
if len(current_needfilter["status"]) > 0
else ""
)
Expand All @@ -276,7 +276,7 @@ def process_needfilters(
):
filter_text += " AND "
filter_text += (
" tags(%s)" % " OR ".join(current_needfilter["tags"])
" tags({})".format(" OR ".join(current_needfilter["tags"]))
if len(current_needfilter["tags"]) > 0
else ""
)
Expand All @@ -286,7 +286,7 @@ def process_needfilters(
) and len(current_needfilter["types"]) > 0:
filter_text += " AND "
filter_text += (
" types(%s)" % " OR ".join(current_needfilter["types"])
" types({})".format(" OR ".join(current_needfilter["types"]))
if len(current_needfilter["types"]) > 0
else ""
)
Expand Down
6 changes: 3 additions & 3 deletions sphinx_needs/directives/needflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def process_needflow(
para = nodes.paragraph()
filter_text = "Used filter:"
filter_text += (
" status(%s)" % " OR ".join(current_needflow["status"])
" status({})".format(" OR ".join(current_needflow["status"]))
if len(current_needflow["status"]) > 0
else ""
)
Expand All @@ -518,7 +518,7 @@ def process_needflow(
):
filter_text += " AND "
filter_text += (
" tags(%s)" % " OR ".join(current_needflow["tags"])
" tags({})".format(" OR ".join(current_needflow["tags"]))
if len(current_needflow["tags"]) > 0
else ""
)
Expand All @@ -527,7 +527,7 @@ def process_needflow(
) and len(current_needflow["types"]) > 0:
filter_text += " AND "
filter_text += (
" types(%s)" % " OR ".join(current_needflow["types"])
" types({})".format(" OR ".join(current_needflow["types"]))
if len(current_needflow["types"]) > 0
else ""
)
Expand Down
10 changes: 5 additions & 5 deletions sphinx_needs/directives/needgantt.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def run(self) -> Sequence[nodes.Node]:
# datetime.fromisoformat(start_date) # > py3.7 only
except Exception:
raise NeedGanttException(
"Given start date {} is not valid. Please use YYYY-MM-DD as format. "
"E.g. 2020-03-27".format(start_date)
f"Given start date {start_date} is not valid. Please use YYYY-MM-DD as format. "
"E.g. 2020-03-27"
)
else:
start_date = None # If None we do not set a start date later
Expand Down Expand Up @@ -277,9 +277,9 @@ def process_needgantt(
puml_node["uml"] += gantt_element

puml_node["uml"] += "\n' Element links definition \n\n"
puml_node[
"uml"
] += "\n' Deactivated, as currently supported by plantuml beta only"
puml_node["uml"] += (
"\n' Deactivated, as currently supported by plantuml beta only"
)

puml_node["uml"] += "\n' Element completion definition \n\n"
puml_node["uml"] += el_completion_string + "\n"
Expand Down
4 changes: 1 addition & 3 deletions sphinx_needs/directives/needimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ def run(self) -> Sequence[nodes.Node]:
needs_list_filtered[key] = need
except Exception as e:
logger.warning(
"needimport: Filter {} not valid. Error: {}. {}{} [needs]".format(
filter_string, e, self.docname, self.lineno
),
f"needimport: Filter {filter_string} not valid. Error: {e}. {self.docname}{self.lineno} [needs]",
type="needs",
location=(self.env.docname, self.lineno),
)
Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/directives/needlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ def process_needlist(
description = "{}: {}".format(need_info["id"], need_info["title"])

if current_needfilter["show_status"] and need_info["status"]:
description += " (%s)" % need_info["status"]
description += " ({})".format(need_info["status"])

if current_needfilter["show_tags"] and need_info["tags"]:
description += " [%s]" % "; ".join(need_info["tags"])
description += " [{}]".format("; ".join(need_info["tags"]))

title = nodes.Text(description)

Expand Down
12 changes: 5 additions & 7 deletions sphinx_needs/directives/needpie.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import hashlib
from typing import Iterable, Sequence
from typing import Any, Iterable, Sequence

from docutils import nodes
from docutils.parsers.rst import directives
Expand Down Expand Up @@ -177,7 +177,7 @@ def process_needpie(
)
# execute filter_func code
# Provides only a copy of needs to avoid data manipulations.
context = {
context: dict[str, Any] = {
"needs": need_list,
"results": [],
}
Expand All @@ -190,7 +190,7 @@ def process_needpie(

if filter_func:
filter_func(**context)
sizes = context["results"] # type: ignore[assignment]
sizes = context["results"]
# check items in sizes
if not isinstance(sizes, list):
logger.error(
Expand Down Expand Up @@ -267,10 +267,8 @@ def process_needpie(
if legend_enforced:
for i in range(len(sizes)):
if sum(sizes) > 0:
labels[i] = "{label} {percent:.1f}% ({size:.0f})".format(
label=labels[i],
percent=100 * sizes[i] / sum(sizes),
size=sizes[i],
labels[i] = (
f"{labels[i]} {100 * sizes[i] / sum(sizes):.1f}% ({sizes[i]:.0f})"
)
else:
labels[i] = f"{labels[i]} {0.0:.1f}% ({sizes[i]:.0f})"
Expand Down
6 changes: 3 additions & 3 deletions sphinx_needs/directives/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def used_filter_paragraph(current_needfilter: NeedsFilteredBaseType) -> nodes.pa
para = nodes.paragraph()
filter_text = "Used filter:"
filter_text += (
" status(%s)" % " OR ".join(current_needfilter["status"])
" status({})".format(" OR ".join(current_needfilter["status"]))
if len(current_needfilter["status"]) > 0
else ""
)
if len(current_needfilter["status"]) > 0 and len(current_needfilter["tags"]) > 0:
filter_text += " AND "
filter_text += (
" tags(%s)" % " OR ".join(current_needfilter["tags"])
" tags({})".format(" OR ".join(current_needfilter["tags"]))
if len(current_needfilter["tags"]) > 0
else ""
)
Expand All @@ -40,7 +40,7 @@ def used_filter_paragraph(current_needfilter: NeedsFilteredBaseType) -> nodes.pa
) and len(current_needfilter["types"]) > 0:
filter_text += " AND "
filter_text += (
" types(%s)" % " OR ".join(current_needfilter["types"])
" types({})".format(" OR ".join(current_needfilter["types"]))
if len(current_needfilter["types"]) > 0
else ""
)
Expand Down
6 changes: 3 additions & 3 deletions sphinx_needs/external_needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def load_external_needs(app: Sphinx, env: BuildEnvironment, _docname: str) -> No
cal_target_url = mem_template.render(**{"need": need})
need_params["external_url"] = f'{source["base_url"]}/{cal_target_url}'
else:
need_params[
"external_url"
] = f'{source["base_url"]}/{need.get("docname", "__error__")}.html#{need["id"]}'
need_params["external_url"] = (
f'{source["base_url"]}/{need.get("docname", "__error__")}.html#{need["id"]}'
)

need_params["content"] = need["description"]
need_params["links"] = need.get("links", [])
Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/filter_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def process_filters(
)
else:
# Provides only a copy of needs to avoid data manipulations.
context = {
context: dict[str, Any] = {
"needs": all_needs_incl_parts,
"results": [],
}
Expand All @@ -226,7 +226,7 @@ def process_filters(
return []

# The filter results may be dirty, as it may continue manipulated needs.
found_dirty_needs: list[NeedsInfoType] = context["results"] # type: ignore
found_dirty_needs: list[NeedsInfoType] = context["results"]
found_needs = []

# Check if config allow unsafe filters
Expand Down
8 changes: 3 additions & 5 deletions sphinx_needs/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,15 @@ def execute_func(app: Sphinx, need: NeedsInfoType, func_string: str) -> Any:

if not isinstance(func_return, (str, int, float, list, unicode)) and func_return:
raise SphinxError(
"Return value of function {} is of type {}. Allowed are str, int, float".format(
func_name, type(func_return)
)
f"Return value of function {func_name} is of type {type(func_return)}. Allowed are str, int, float"
)

if isinstance(func_return, list):
for element in func_return:
if not isinstance(element, (str, int, float, unicode)):
raise SphinxError(
"Element of return list of function {} is of type {}. "
"Allowed are str, int, float".format(func_name, type(func_return))
f"Element of return list of function {func_name} is of type {type(func_return)}. "
"Allowed are str, int, float"
)
return func_return

Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ def check_configuration(_app: Sphinx, config: Config) -> None:
and option not in NEED_DEFAULT_OPTIONS.keys()
):
raise NeedsConfigException(
"Variant option `{}` is not added in either extra options or extra links. "
"This is not allowed.".format(option)
f"Variant option `{option}` is not added in either extra options or extra links. "
"This is not allowed."
)


Expand Down
5 changes: 1 addition & 4 deletions sphinx_needs/roles/need_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ def process_need_ref(
try:
link_text = needs_config.role_need_template.format(**dict_need)
except KeyError as e:
link_text = (
'"the config parameter needs_role_need_template uses not supported placeholders: %s "'
% e
)
link_text = f'"the config parameter needs_role_need_template uses not supported placeholders: {e} "'
log.warning(link_text + " [needs]", type="needs")

node_need_ref[0].children[0] = nodes.Text(link_text) # type: ignore[index]
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ def test_app(make_app, sphinx_test_tempdir, request):
if not builder_params.get("no_plantuml", False):
# Since we don't want copy the plantuml.jar file for each test function,
# we need to override the plantuml conf variable and set it to what we have already
plantuml = "java -Djava.awt.headless=true -jar %s" % os.path.join(
sphinx_test_tempdir, "utils", "plantuml.jar"
plantuml = "java -Djava.awt.headless=true -jar {}".format(
os.path.join(sphinx_test_tempdir, "utils", "plantuml.jar")
)
sphinx_conf_overrides.update(plantuml=plantuml)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_needs_external_needs_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_doc_build_html(test_app, sphinx_test_tempdir):

src_dir = Path(app.srcdir)
out_dir = Path(app.outdir)
plantuml = r"java -Djava.awt.headless=true -jar %s" % os.path.join(
sphinx_test_tempdir, "utils", "plantuml.jar"
plantuml = r"java -Djava.awt.headless=true -jar {}".format(
os.path.join(sphinx_test_tempdir, "utils", "plantuml.jar")
)
output = subprocess.run(
["sphinx-build", "-b", "html", "-D", rf"plantuml={plantuml}", src_dir, out_dir],
Expand Down

0 comments on commit 42962cc

Please sign in to comment.