Skip to content

Commit 4fc2f4a

Browse files
committed
doc: Update documentation to account for Black/ruff
1 parent 2c1ed32 commit 4fc2f4a

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

Diff for: docs/.glossary.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
[Spacy's documentation]: https://spacy.io/api/doc/
99
[Black]: https://pypi.org/project/black/
1010
[Material for MkDocs]: https://squidfunk.github.io/mkdocs-material
11+
[Ruff]: https://docs.astral.sh/ruff
1112

1213
*[ToC]: Table of Contents

Diff for: docs/schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"default": false
146146
},
147147
"separate_signature": {
148-
"title": "Whether to put the whole signature in a code block below the heading. If Black is installed, the signature is also formatted using it.",
148+
"title": "Whether to put the whole signature in a code block below the heading. If a formatter (Black or Ruff) is installed, the signature is also formatted using it.",
149149
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/signatures/#separate_signature",
150150
"type": "boolean",
151151
"default": false

Diff for: docs/usage/configuration/signatures.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,15 @@ def convert(text: str, md: Markdown) -> Markup:
154154
Maximum line length when formatting code/signatures.
155155

156156
When separating signatures from headings with the [`separate_signature`][] option,
157-
the Python handler will try to format the signatures using [Black] and
157+
the Python handler will try to format the signatures using a formatter and
158158
the specified line length.
159159

160-
If Black is not installed, the handler issues an INFO log once.
160+
The handler will automatically try to format using :
161+
162+
1. [Black]
163+
2. [Ruff]
164+
165+
If a formatter is not found, the handler issues an INFO log once.
161166

162167
```yaml title="in mkdocs.yml (global configuration)"
163168
plugins:
@@ -380,10 +385,15 @@ function(param1, param2=None)
380385
Whether to put the whole signature in a code block below the heading.
381386

382387
When separating signatures from headings,
383-
the Python handler will try to format the signatures using [Black] and
388+
the Python handler will try to format the signatures using a formatter and
384389
the specified [line length][line_length].
385390

386-
If Black is not installed, the handler issues an INFO log once.
391+
The handler will automatically try to format using :
392+
393+
1. [Black]
394+
2. [Ruff]
395+
396+
If a formatter is not found, the handler issues an INFO log once.
387397

388398
```yaml title="in mkdocs.yml (global configuration)"
389399
plugins:

Diff for: src/mkdocstrings_handlers/python/handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class PythonHandler(BaseHandler):
201201
show_signature_annotations (bool): Show the type annotations in methods and functions signatures. Default: `False`.
202202
signature_crossrefs (bool): Whether to render cross-references for type annotations in signatures. Default: `False`.
203203
separate_signature (bool): Whether to put the whole signature in a code block below the heading.
204-
If Black is installed, the signature is also formatted using it. Default: `False`.
204+
If a formatter (Black or Ruff) is installed, the signature is also formatted using it. Default: `False`.
205205
unwrap_annotated (bool): Whether to unwrap `Annotated` types to show only the type without the annotations. Default: `False`.
206206
modernize_annotations (bool): Whether to modernize annotations, for example `Optional[str]` into `str | None`. Default: `False`.
207207
"""

Diff for: src/mkdocstrings_handlers/python/rendering.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ def _sort_key_source(item: CollectorItem) -> Any:
7272

7373

7474
def do_format_code(code: str, line_length: int) -> str:
75-
"""Format code using Black.
75+
"""Format code.
7676
7777
Parameters:
7878
code: The code to format.
79-
line_length: The line length to give to Black.
79+
line_length: The line length.
8080
8181
Returns:
8282
The same code, formatted.
@@ -138,13 +138,13 @@ def do_format_signature(
138138
annotations: bool | None = None,
139139
crossrefs: bool = False, # noqa: ARG001
140140
) -> str:
141-
"""Format a signature using Black.
141+
"""Format a signature.
142142
143143
Parameters:
144144
context: Jinja context, passed automatically.
145145
callable_path: The path of the callable we render the signature of.
146146
function: The function we render the signature of.
147-
line_length: The line length to give to Black.
147+
line_length: The line length.
148148
annotations: Whether to show type annotations.
149149
crossrefs: Whether to cross-reference types in the signature.
150150
@@ -200,13 +200,13 @@ def do_format_attribute(
200200
*,
201201
crossrefs: bool = False, # noqa: ARG001
202202
) -> str:
203-
"""Format an attribute using Black.
203+
"""Format an attribute.
204204
205205
Parameters:
206206
context: Jinja context, passed automatically.
207207
attribute_path: The path of the callable we render the signature of.
208208
attribute: The attribute we render the signature of.
209-
line_length: The line length to give to Black.
209+
line_length: The line length.
210210
crossrefs: Whether to cross-reference types in the signature.
211211
212212
Returns:
@@ -443,7 +443,7 @@ def _get_formatter() -> Callable[[str, int], str]:
443443
if (formatter := formatter_function()) is not None:
444444
return formatter
445445

446-
logger.info("Formatting signatures requires either Black or ruff to be installed.")
446+
logger.info("Formatting signatures requires either Black or Ruff to be installed.")
447447
return lambda text, _: text
448448

449449

@@ -461,7 +461,7 @@ def _get_ruff_formatter() -> Callable[[str, int], str] | None:
461461
def formatter(code: str, line_length: int) -> str:
462462
try:
463463
completed_process = subprocess.run( # noqa: S603
464-
[ # noqa: S607
464+
[
465465
ruff_bin,
466466
"format",
467467
"--config",

Diff for: tests/test_rendering.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
)
3333
def test_format_code(code: str, formatter: Callable[[str, int], str]) -> None:
34-
"""Assert code can be Black-formatted.
34+
"""Assert code can be formatted.
3535
3636
Parameters:
3737
code: Code to format.
@@ -45,7 +45,7 @@ def test_format_code(code: str, formatter: Callable[[str, int], str]) -> None:
4545
[("Class.method", "(param: str = 'hello') -> 'OtherClass'")],
4646
)
4747
def test_format_signature(name: Markup, signature: str) -> None:
48-
"""Assert signatures can be Black-formatted.
48+
"""Assert signatures can be formatted.
4949
5050
Parameters:
5151
signature: Signature to format.

0 commit comments

Comments
 (0)