Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Replace black/isort/pyupgrade/flake8 with ruff #1080

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

29 changes: 5 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
- pep8-naming

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: pyupgrade
args:
- --py38-plus
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
Expand Down
108 changes: 90 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
needs_debug_measurement = True

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

NOTE_TEMPLATE = """
.. _{{id}}:
Expand All @@ -80,9 +82,7 @@
{% endif %}
"""

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

# You can uncomment some of the following lines to override the default configuration for Sphinx-Needs.
# needs_diagram_template = DEFAULT_DIAGRAM_TEMPLATE
Expand Down Expand Up @@ -110,16 +110,71 @@
"color": "#BFD8D2",
"style": "card",
},
{"directive": "sys", "title": "System", "content": "plantuml", "prefix": "S_", "color": "#BFD8D2", "style": "card"},
{
"directive": "sys",
"title": "System",
"content": "plantuml",
"prefix": "S_",
"color": "#BFD8D2",
"style": "card",
},
# Normal types
{"directive": "req", "title": "Requirement", "prefix": "R_", "color": "#BFD8D2", "style": "node"},
{"directive": "spec", "title": "Specification", "prefix": "S_", "color": "#FEDCD2", "style": "node"},
{"directive": "impl", "title": "Implementation", "prefix": "I_", "color": "#DF744A", "style": "node"},
{"directive": "test", "title": "Test Case", "prefix": "T_", "color": "#DCB239", "style": "node"},
{"directive": "feature", "title": "Feature", "prefix": "F_", "color": "#FFCC00", "style": "node"},
{"directive": "user", "title": "User", "prefix": "U_", "color": "#777777", "style": "node"},
{"directive": "action", "title": "Action", "prefix": "A_", "color": "#FFCC00", "style": "node"},
{"directive": "milestone", "title": "Milestone", "prefix": "M_", "color": "#FF3333", "style": "node"},
{
"directive": "req",
"title": "Requirement",
"prefix": "R_",
"color": "#BFD8D2",
"style": "node",
},
{
"directive": "spec",
"title": "Specification",
"prefix": "S_",
"color": "#FEDCD2",
"style": "node",
},
{
"directive": "impl",
"title": "Implementation",
"prefix": "I_",
"color": "#DF744A",
"style": "node",
},
{
"directive": "test",
"title": "Test Case",
"prefix": "T_",
"color": "#DCB239",
"style": "node",
},
{
"directive": "feature",
"title": "Feature",
"prefix": "F_",
"color": "#FFCC00",
"style": "node",
},
{
"directive": "user",
"title": "User",
"prefix": "U_",
"color": "#777777",
"style": "node",
},
{
"directive": "action",
"title": "Action",
"prefix": "A_",
"color": "#FFCC00",
"style": "node",
},
{
"directive": "milestone",
"title": "Milestone",
"prefix": "M_",
"color": "#FF3333",
"style": "node",
},
]

needs_extra_links = [
Expand Down Expand Up @@ -208,7 +263,9 @@
needs_id_required = False
# needs_css = "dark.css"

local_plantuml_path = os.path.join(os.path.dirname(__file__), "utils", "plantuml-1.2022.14.jar")
local_plantuml_path = os.path.join(
os.path.dirname(__file__), "utils", "plantuml-1.2022.14.jar"
)
plantuml = f"java -Djava.awt.headless=true -jar {local_plantuml_path}"

# plantuml_output_format = 'png'
Expand Down Expand Up @@ -246,7 +303,10 @@
"grid": "simple_side_right_partial",
"layout": {
"head": ['**<<meta("title")>>** for *<<meta("author")>>*'],
"meta": ['**status**: <<meta("status")>>', '**author**: <<meta("author")>>'],
"meta": [
'**status**: <<meta("status")>>',
'**author**: <<meta("author")>>',
],
"side": ['<<image("_images/{{author}}.png", align="center")>>'],
},
},
Expand Down Expand Up @@ -450,14 +510,22 @@ def custom_defined_func():
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "needstestdocs.tex", "needs test docs Documentation", "team useblocks", "manual"),
(
master_doc,
"needstestdocs.tex",
"needs test docs Documentation",
"team useblocks",
"manual",
),
]

# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "needstestdocs", "needs test docs Documentation", [author], 1)]
man_pages = [
(master_doc, "needstestdocs", "needs test docs Documentation", [author], 1)
]

# -- Options for Texinfo output -------------------------------------------

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

# contains different constraints
needs_constraints = {
"critical": {"check_0": "'critical' in tags", "check_1": "'SECURITY_REQ' in links", "severity": "CRITICAL"},
"critical": {
"check_0": "'critical' in tags",
"check_1": "'SECURITY_REQ' in links",
"severity": "CRITICAL",
},
"security": {"check_0": "'security' in tags", "severity": "HIGH"},
"team": {"check_0": 'author == "Bob"', "severity": "LOW"},
}
Expand Down
10 changes: 9 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ def pre_commit(session):
def linkcheck(session):
session.install(".[docs]")
with session.chdir("docs"):
session.run("sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *session.posargs, external=True)
session.run(
"sphinx-build",
"-b",
"linkcheck",
".",
"_build/linkcheck",
*session.posargs,
external=True,
)


@session(python="3.11")
Expand Down
54 changes: 46 additions & 8 deletions performance/performance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ def cli():


def start(
needs=1000, needtables=0, dummies=0, pages=1, parallel=1, keep=False, browser=False, debug=False, basic=False
needs=1000,
needtables=0,
dummies=0,
pages=1,
parallel=1,
keep=False,
browser=False,
debug=False,
basic=False,
):
"""
Test run implementation
Expand Down Expand Up @@ -163,11 +171,31 @@ def start(


@cli.command()
@click.option("--profile", default=[], type=str, multiple=True, help="Activates profiling for given area")
@click.option("--needs", default=[50, 10], type=int, multiple=True, help="Number of maximum needs.")
@click.option("--needtables", default=-1, type=int, help="Number of maximum needtables.")
@click.option(
"--profile",
default=[],
type=str,
multiple=True,
help="Activates profiling for given area",
)
@click.option(
"--needs",
default=[50, 10],
type=int,
multiple=True,
help="Number of maximum needs.",
)
@click.option(
"--needtables", default=-1, type=int, help="Number of maximum needtables."
)
@click.option("--dummies", default=-1, type=int, help="Number of standard rst dummies.")
@click.option("--pages", default=[5, 1], type=int, multiple=True, help="Number of additional pages with needs.")
@click.option(
"--pages",
default=[5, 1],
type=int,
multiple=True,
help="Number of additional pages with needs.",
)
@click.option(
"--parallel",
default=[1, 4],
Expand All @@ -177,9 +205,19 @@ def start(
)
@click.option("--keep", is_flag=True, help="Keeps the temporary src and build folders")
@click.option("--browser", is_flag=True, help="Opens the project in your browser")
@click.option("--snakeviz", is_flag=True, help="Opens snakeviz view for measured profiles in browser")
@click.option("--debug", is_flag=True, help="Prints more information, incl. sphinx build output")
@click.option("--basic", is_flag=True, help="Use only default config of Sphinx-Needs (e.g. no extra options)")
@click.option(
"--snakeviz",
is_flag=True,
help="Opens snakeviz view for measured profiles in browser",
)
@click.option(
"--debug", is_flag=True, help="Prints more information, incl. sphinx build output"
)
@click.option(
"--basic",
is_flag=True,
help="Use only default config of Sphinx-Needs (e.g. no extra options)",
)
def series(
profile,
needs,
Expand Down
18 changes: 13 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,19 @@ markers = [
"jstest: marks tests as JavaScript test (deselect with '-m \"not jstest\"')",
]

[tool.black]
line-length = 120

[tool.isort]
profile = "black"
[tool.ruff]
extend-select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"UP", # pyupgrade
]
extend-ignore = ["B904", "ISC001", "ICN001", "N818", "RUF005", "RUF013", "RUF012", "SIM108", "SIM118"]

[tool.mypy]
files = "sphinx_needs"
Expand Down
35 changes: 29 additions & 6 deletions sphinx_needs/api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@


def add_need_type(
app: Sphinx, directive: str, title: str, prefix: str, color: str = "#ffffff", style: str = "node"
app: Sphinx,
directive: str,
title: str,
prefix: str,
color: str = "#ffffff",
style: str = "node",
) -> None:
"""
Adds a new need_type to the configuration.
Expand Down Expand Up @@ -68,7 +73,15 @@
if directive in type_names:
raise NeedsApiConfigException(f"{directive} already exists as need type")

needs_types.append({"directive": directive, "title": title, "prefix": prefix, "color": color, "style": style})
needs_types.append(
{
"directive": directive,
"title": title,
"prefix": prefix,
"color": color,
"style": style,
}
)
app.add_directive(directive, sphinx_needs.directives.need.NeedDirective)


Expand All @@ -93,7 +106,9 @@
NEEDS_CONFIG.extra_options[name] = directives.unchanged


def add_dynamic_function(app: Sphinx, function: DynamicFunction, name: str | None = None) -> None:
def add_dynamic_function(
app: Sphinx, function: DynamicFunction, name: str | None = None
) -> None:
"""
Registers a new dynamic function for sphinx-needs.

Expand Down Expand Up @@ -124,7 +139,12 @@
WarningCheck = Callable[[NeedsInfoType, SphinxLoggerAdapter], bool]


def add_warning(app: Sphinx, name: str, function: WarningCheck | None = None, filter_string: str | None = None) -> None:
def add_warning(
app: Sphinx,
name: str,
function: WarningCheck | None = None,
filter_string: str | None = None,
) -> None:
"""
Registers a warning.

Expand All @@ -137,11 +157,14 @@
:return: None
"""
if function is None and filter_string is None:
raise NeedsApiConfigException("Function or filter_string must be given for add_warning_func")
raise NeedsApiConfigException(

Check warning on line 160 in sphinx_needs/api/configuration.py

View check run for this annotation

Codecov / codecov/patch

sphinx_needs/api/configuration.py#L160

Added line #L160 was not covered by tests
"Function or filter_string must be given for add_warning_func"
)

if function is not None and filter_string is not None:
raise NeedsApiConfigException(
"For add_warning_func only function or filter_string is allowed to be set, " "not both."
"For add_warning_func only function or filter_string is allowed to be set, "
"not both."
)

warning_check = function or filter_string
Expand Down
Loading
Loading