From 6ea80e300ccd962c5380a58a9ed811c19dd3eec8 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 16 Sep 2023 10:54:13 +0200 Subject: [PATCH] Switch line-length to 100 --- mkdocs_click/_docs.py | 22 +++++++++++++++++----- mkdocs_click/_extension.py | 8 ++++++-- mkdocs_click/_loader.py | 4 +++- mkdocs_click/_processing.py | 4 +++- pyproject.toml | 4 ++-- tests/test_docs.py | 7 +++++-- tests/test_loader.py | 4 +++- tests/test_processing.py | 10 ++++++++-- 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/mkdocs_click/_docs.py b/mkdocs_click/_docs.py index bf86c53..336393a 100644 --- a/mkdocs_click/_docs.py +++ b/mkdocs_click/_docs.py @@ -89,7 +89,9 @@ def _recursively_make_command_docs( ) -def _build_command_context(prog_name: str, command: click.BaseCommand, parent: click.Context | None) -> click.Context: +def _build_command_context( + prog_name: str, command: click.BaseCommand, parent: click.Context | None +) -> click.Context: return click.Context(cast(click.Command, command), info_name=prog_name, parent=parent) @@ -195,7 +197,9 @@ def _make_usage(ctx: click.Context) -> Iterator[str]: yield "" -def _make_options(ctx: click.Context, style: str = "plain", show_hidden: bool = False) -> Iterator[str]: +def _make_options( + ctx: click.Context, style: str = "plain", show_hidden: bool = False +) -> Iterator[str]: """Create the Markdown lines describing the options for the command.""" if style == "plain": @@ -203,13 +207,17 @@ def _make_options(ctx: click.Context, style: str = "plain", show_hidden: bool = elif style == "table": return _make_table_options(ctx, show_hidden=show_hidden) else: - raise MkDocsClickException(f"{style} is not a valid option style, which must be either `plain` or `table`.") + raise MkDocsClickException( + f"{style} is not a valid option style, which must be either `plain` or `table`." + ) @contextmanager def _show_options(ctx: click.Context) -> Iterator[None]: """Context manager that temporarily shows all hidden options.""" - options = [opt for opt in ctx.command.get_params(ctx) if isinstance(opt, click.Option) and opt.hidden] + options = [ + opt for opt in ctx.command.get_params(ctx) if isinstance(opt, click.Option) and opt.hidden + ] try: for option in options: @@ -340,7 +348,11 @@ def _make_subcommands_links( ctx = _build_command_context(command_name, command, parent) if ctx.command.hidden and not show_hidden: continue - command_bullet = command_name if not has_attr_list else f"[{command_name}](#{slugify(ctx.command_path, '-')})" + command_bullet = ( + command_name + if not has_attr_list + else f"[{command_name}](#{slugify(ctx.command_path, '-')})" + ) help_string = ctx.command.short_help or ctx.command.help if help_string is not None: help_string = help_string.splitlines()[0] diff --git a/mkdocs_click/_extension.py b/mkdocs_click/_extension.py index f799c77..60f1e07 100644 --- a/mkdocs_click/_extension.py +++ b/mkdocs_click/_extension.py @@ -48,14 +48,18 @@ def replace_command_docs(has_attr_list: bool = False, **options: Any) -> Iterato class ClickProcessor(Preprocessor): def __init__(self, md: Any) -> None: super().__init__(md) - self._has_attr_list = any(isinstance(ext, AttrListExtension) for ext in md.registeredExtensions) + self._has_attr_list = any( + isinstance(ext, AttrListExtension) for ext in md.registeredExtensions + ) def run(self, lines: list[str]) -> list[str]: return list( replace_blocks( lines, title="mkdocs-click", - replace=lambda **options: replace_command_docs(has_attr_list=self._has_attr_list, **options), + replace=lambda **options: replace_command_docs( + has_attr_list=self._has_attr_list, **options + ), ) ) diff --git a/mkdocs_click/_loader.py b/mkdocs_click/_loader.py index 102d478..1e95d95 100644 --- a/mkdocs_click/_loader.py +++ b/mkdocs_click/_loader.py @@ -18,7 +18,9 @@ def load_command(module: str, attribute: str) -> click.BaseCommand: command = _load_obj(module, attribute) if not isinstance(command, click.BaseCommand): - raise MkDocsClickException(f"{attribute!r} must be a 'click.BaseCommand' object, got {type(command)}") + raise MkDocsClickException( + f"{attribute!r} must be a 'click.BaseCommand' object, got {type(command)}" + ) return command diff --git a/mkdocs_click/_processing.py b/mkdocs_click/_processing.py index e620d4b..f02fc80 100644 --- a/mkdocs_click/_processing.py +++ b/mkdocs_click/_processing.py @@ -7,7 +7,9 @@ from typing import Callable, Iterable, Iterator -def replace_blocks(lines: Iterable[str], title: str, replace: Callable[..., Iterable[str]]) -> Iterator[str]: +def replace_blocks( + lines: Iterable[str], title: str, replace: Callable[..., Iterable[str]] +) -> Iterator[str]: """ Find blocks of lines in the form of: diff --git a/pyproject.toml b/pyproject.toml index 9f93d01..b4d135c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,11 +99,11 @@ format = [ ] [tool.black] -line-length = 120 +line-length = 100 [tool.isort] profile = "black" -line_length = 120 +line_length = 100 [tool.ruff] select = [ diff --git a/tests/test_docs.py b/tests/test_docs.py index ede4418..fb25587 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -81,7 +81,8 @@ def test_prog_name(): def test_style_invalid(): with pytest.raises( - MkDocsClickException, match="invalid is not a valid option style, which must be either `plain` or `table`." + MkDocsClickException, + match="invalid is not a valid option style, which must be either `plain` or `table`.", ): list(make_command_docs("hello", hello, style="invalid")) @@ -298,7 +299,9 @@ def test_show_hidden_option(show_hidden, style): def _test_cmd(hidden): """Test cmd.""" - output = "\n".join(make_command_docs("_test_cmd", _test_cmd, style=style, show_hidden=show_hidden)) + output = "\n".join( + make_command_docs("_test_cmd", _test_cmd, style=style, show_hidden=show_hidden) + ) assert ("--hidden" in output) == show_hidden diff --git a/tests/test_loader.py b/tests/test_loader.py index ac466d5..ff0ddb7 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -13,7 +13,9 @@ "module, command, exc", [ pytest.param("tests.app.cli", "cli", None, id="ok"), - pytest.param("tests.app.cli", "doesnotexist", MkDocsClickException, id="command-does-not-exist"), + pytest.param( + "tests.app.cli", "doesnotexist", MkDocsClickException, id="command-does-not-exist" + ), pytest.param("doesnotexist", "cli", ImportError, id="module-does-not-exist"), pytest.param("tests.app.cli", "NOT_A_COMMAND", MkDocsClickException, id="not-a-command"), ], diff --git a/tests/test_processing.py b/tests/test_processing.py index b78b052..11add4c 100644 --- a/tests/test_processing.py +++ b/tests/test_processing.py @@ -25,7 +25,11 @@ def test_replace_options(): bar """.strip() - output = list(replace_blocks(source.splitlines(), title="target", replace=lambda **options: [str(options)])) + output = list( + replace_blocks( + source.splitlines(), title="target", replace=lambda **options: [str(options)] + ) + ) assert output == expected.splitlines() @@ -46,7 +50,9 @@ def test_replace_no_options(): bar """.strip() - output = list(replace_blocks(source.splitlines(), title="target", replace=lambda **options: ["> mock"])) + output = list( + replace_blocks(source.splitlines(), title="target", replace=lambda **options: ["> mock"]) + ) assert output == expected.splitlines()