diff --git a/guide/content/en/migrate.py b/guide/content/en/migrate.py index e58e2c91..bc783c6f 100644 --- a/guide/content/en/migrate.py +++ b/guide/content/en/migrate.py @@ -5,6 +5,7 @@ from textwrap import indent from emoji import EMOJI + COLUMN_PATTERN = re.compile(r"---:1\s*(.*?)\s*:--:1\s*(.*?)\s*:---", re.DOTALL) PYTHON_HIGHLIGHT_PATTERN = re.compile(r"```python\{+.*?\}", re.DOTALL) BASH_HIGHLIGHT_PATTERN = re.compile(r"```bash\{+.*?\}", re.DOTALL) diff --git a/guide/pyproject.toml b/guide/pyproject.toml index eb5e4b78..1d5780d3 100644 --- a/guide/pyproject.toml +++ b/guide/pyproject.toml @@ -3,5 +3,3 @@ extend = "../pyproject.toml" [tool.ruff.isort] known-first-party = ["webapp"] -lines-after-imports = 1 -lines-between-types = 1 diff --git a/guide/server.py b/guide/server.py index 9de1c500..00db05bd 100644 --- a/guide/server.py +++ b/guide/server.py @@ -2,4 +2,5 @@ from pathlib import Path from webapp.worker.factory import create_app + app = create_app(Path(__file__).parent) diff --git a/guide/webapp/display/base.py b/guide/webapp/display/base.py index 8624493c..7486d89a 100644 --- a/guide/webapp/display/base.py +++ b/guide/webapp/display/base.py @@ -2,6 +2,7 @@ from __future__ import annotations from html5tagger import Builder, Document # type: ignore + class BaseRenderer: def __init__(self, base_title: str): self.base_title = base_title diff --git a/guide/webapp/display/code_style.py b/guide/webapp/display/code_style.py index cf7c2b65..2a7403f9 100644 --- a/guide/webapp/display/code_style.py +++ b/guide/webapp/display/code_style.py @@ -7,6 +7,7 @@ from pygments.token import ( # Error,; Generic,; Number,; Operator, Token, ) + class SanicCodeStyle(Style): styles = { Token: "#777", diff --git a/guide/webapp/display/layouts/base.py b/guide/webapp/display/layouts/base.py index fd5c2733..8ffec4f0 100644 --- a/guide/webapp/display/layouts/base.py +++ b/guide/webapp/display/layouts/base.py @@ -6,6 +6,7 @@ from typing import Generator from html5tagger import Builder from sanic import Request + class BaseLayout: def __init__(self, builder: Builder): self.builder = builder diff --git a/guide/webapp/display/layouts/elements/footer.py b/guide/webapp/display/layouts/elements/footer.py index c7a54d42..4ef2051a 100644 --- a/guide/webapp/display/layouts/elements/footer.py +++ b/guide/webapp/display/layouts/elements/footer.py @@ -3,6 +3,7 @@ from datetime import datetime from html5tagger import Builder, E # type: ignore from sanic import Request + def do_footer(builder: Builder, request: Request) -> None: builder.footer( _pagination(request), diff --git a/guide/webapp/display/layouts/elements/navbar.py b/guide/webapp/display/layouts/elements/navbar.py index b50e728e..5581e4a6 100644 --- a/guide/webapp/display/layouts/elements/navbar.py +++ b/guide/webapp/display/layouts/elements/navbar.py @@ -3,6 +3,7 @@ from sanic import Request from webapp.display.layouts.models import MenuItem + def do_navbar(builder: Builder, request: Request) -> None: navbar_items = [ _render_navbar_item(item, request) diff --git a/guide/webapp/display/layouts/elements/sidebar.py b/guide/webapp/display/layouts/elements/sidebar.py index fac6a737..72a04082 100644 --- a/guide/webapp/display/layouts/elements/sidebar.py +++ b/guide/webapp/display/layouts/elements/sidebar.py @@ -4,6 +4,7 @@ from sanic import Request from webapp.display.layouts.models import MenuItem from webapp.display.text import slugify + def do_sidebar(builder: Builder, request: Request) -> None: builder.a(class_="burger")(E.span().span().span().span()) builder.aside(*_menu_items(request), class_="menu") diff --git a/guide/webapp/display/layouts/home.py b/guide/webapp/display/layouts/home.py index b4c31712..242f4b70 100644 --- a/guide/webapp/display/layouts/home.py +++ b/guide/webapp/display/layouts/home.py @@ -8,6 +8,7 @@ from sanic import Request from .base import BaseLayout + class HomeLayout(BaseLayout): @contextmanager def layout( diff --git a/guide/webapp/display/layouts/main.py b/guide/webapp/display/layouts/main.py index 870e6424..44f77918 100644 --- a/guide/webapp/display/layouts/main.py +++ b/guide/webapp/display/layouts/main.py @@ -9,6 +9,7 @@ from webapp.display.layouts.elements.sidebar import do_sidebar from .base import BaseLayout + class MainLayout(BaseLayout): @contextmanager def layout( diff --git a/guide/webapp/display/layouts/models.py b/guide/webapp/display/layouts/models.py index c2f1b616..d3d8105a 100644 --- a/guide/webapp/display/layouts/models.py +++ b/guide/webapp/display/layouts/models.py @@ -2,6 +2,7 @@ from __future__ import annotations from msgspec import Struct, field + class MenuItem(Struct, kw_only=False, omit_defaults=True): label: str path: str | None = None diff --git a/guide/webapp/display/markdown.py b/guide/webapp/display/markdown.py index 614bf9ec..d517ddcc 100644 --- a/guide/webapp/display/markdown.py +++ b/guide/webapp/display/markdown.py @@ -20,6 +20,7 @@ from .plugins.span import span from .plugins.tabs import Tabs from .text import slugify + class DocsRenderer(HTMLRenderer): def block_code(self, code: str, info: str | None = None): builder = Builder("Block") diff --git a/guide/webapp/display/page/__init__.py b/guide/webapp/display/page/__init__.py index 7ad390fc..7a873876 100644 --- a/guide/webapp/display/page/__init__.py +++ b/guide/webapp/display/page/__init__.py @@ -1,4 +1,5 @@ from .page import Page from .renderer import PageRenderer + __all__ = ["Page", "PageRenderer"] diff --git a/guide/webapp/display/page/docobject.py b/guide/webapp/display/page/docobject.py index 89343c3f..8287a4ad 100644 --- a/guide/webapp/display/page/docobject.py +++ b/guide/webapp/display/page/docobject.py @@ -15,6 +15,7 @@ from html5tagger import HTML, Builder, E # type: ignore from ..markdown import render_markdown, slugify + @dataclass class DocObject: name: str diff --git a/guide/webapp/display/page/page.py b/guide/webapp/display/page/page.py index a2c9d4cb..b4ddde58 100644 --- a/guide/webapp/display/page/page.py +++ b/guide/webapp/display/page/page.py @@ -11,6 +11,7 @@ from ..layouts.main import MainLayout from ..markdown import render_markdown from .docobject import organize_docobjects + _PAGE_CACHE: dict[ str, dict[str, tuple[Page | None, Page | None, Page | None]] ] = {} diff --git a/guide/webapp/display/page/renderer.py b/guide/webapp/display/page/renderer.py index 391d7e0d..987aa3c7 100644 --- a/guide/webapp/display/page/renderer.py +++ b/guide/webapp/display/page/renderer.py @@ -10,6 +10,7 @@ from webapp.display.base import BaseRenderer from ..layouts.base import BaseLayout from .page import Page + class PageRenderer(BaseRenderer): def render(self, request: Request, language: str, path: str) -> Builder: builder = self.get_builder( diff --git a/guide/webapp/display/plugins/attrs.py b/guide/webapp/display/plugins/attrs.py index 5355f647..f2f33363 100644 --- a/guide/webapp/display/plugins/attrs.py +++ b/guide/webapp/display/plugins/attrs.py @@ -7,6 +7,7 @@ from mistune.block_parser import BlockParser from mistune.core import BlockState from mistune.directives import DirectivePlugin + class Attributes(DirectivePlugin): def __call__(self, directive, md): directive.register("attrs", self.parse) diff --git a/guide/webapp/display/plugins/columns.py b/guide/webapp/display/plugins/columns.py index e0ba1cca..4ab7feab 100644 --- a/guide/webapp/display/plugins/columns.py +++ b/guide/webapp/display/plugins/columns.py @@ -8,6 +8,7 @@ from mistune.core import BlockState from mistune.directives import DirectivePlugin, RSTDirective from mistune.markdown import Markdown + class Column(DirectivePlugin): def parse( self, block: BlockParser, m: Match, state: BlockState diff --git a/guide/webapp/display/plugins/hook.py b/guide/webapp/display/plugins/hook.py index 6e9773bc..db1b647a 100644 --- a/guide/webapp/display/plugins/hook.py +++ b/guide/webapp/display/plugins/hook.py @@ -2,6 +2,7 @@ from mistune.core import BlockState from mistune.directives import DirectivePlugin, RSTDirective from mistune.markdown import Markdown + class Hook(DirectivePlugin): def __call__( # type: ignore self, directive: RSTDirective, md: Markdown diff --git a/guide/webapp/display/plugins/mermaid.py b/guide/webapp/display/plugins/mermaid.py index 2eb4ab61..935aae44 100644 --- a/guide/webapp/display/plugins/mermaid.py +++ b/guide/webapp/display/plugins/mermaid.py @@ -10,6 +10,7 @@ from mistune.core import BlockState from mistune.directives import DirectivePlugin, RSTDirective from mistune.markdown import Markdown + class Mermaid(DirectivePlugin): def parse( self, block: BlockParser, m: Match, state: BlockState diff --git a/guide/webapp/display/plugins/notification.py b/guide/webapp/display/plugins/notification.py index f264212c..15b0689f 100644 --- a/guide/webapp/display/plugins/notification.py +++ b/guide/webapp/display/plugins/notification.py @@ -1,6 +1,7 @@ from html5tagger import HTML, E from mistune.directives import Admonition + class Notification(Admonition): SUPPORTED_NAMES = { "success", diff --git a/guide/webapp/display/plugins/span.py b/guide/webapp/display/plugins/span.py index 500e73f6..0ea5a9cd 100644 --- a/guide/webapp/display/plugins/span.py +++ b/guide/webapp/display/plugins/span.py @@ -2,6 +2,7 @@ import re from mistune.markdown import Markdown + def parse_inline_span(inline, m: re.Match, state): state.append_token( { diff --git a/guide/webapp/display/plugins/tabs.py b/guide/webapp/display/plugins/tabs.py index ca67c074..b99e70db 100644 --- a/guide/webapp/display/plugins/tabs.py +++ b/guide/webapp/display/plugins/tabs.py @@ -8,6 +8,7 @@ from mistune.core import BlockState from mistune.directives import DirectivePlugin, RSTDirective from mistune.markdown import Markdown + class Tabs(DirectivePlugin): def parse( self, block: BlockParser, m: Match, state: BlockState diff --git a/guide/webapp/display/search/renderer.py b/guide/webapp/display/search/renderer.py index c04b08f6..284fd5bd 100644 --- a/guide/webapp/display/search/renderer.py +++ b/guide/webapp/display/search/renderer.py @@ -9,6 +9,7 @@ from webapp.display.search.search import Searcher from ..base import BaseRenderer from ..layouts.main import MainLayout + class SearchRenderer(BaseRenderer): def render( self, request: Request, language: str, searcher: Searcher, full: bool diff --git a/guide/webapp/display/search/search.py b/guide/webapp/display/search/search.py index 1d4d1085..a8a35cb4 100644 --- a/guide/webapp/display/search/search.py +++ b/guide/webapp/display/search/search.py @@ -8,6 +8,7 @@ from msgspec import Struct from webapp.display.page import Page + class Stemmer: STOP_WORDS: ClassVar[set[str]] = set( "a about above after again against all am an and any are aren't as at be because been before being below between both but by can't cannot could couldn't did didn't do does doesn't doing don't down during each few for from further had hadn't has hasn't have haven't having he he'd he'll he's her here here's hers herself him himself his how how's i i'd i'll i'm i've if in into is isn't it it's its itself let's me more most mustn't my myself no nor not of off on once only or other ought our ours ourselves out over own same shan't she she'd she'll she's should shouldn't so some such than that that's the their theirs them themselves then there there's these they they'd they'll they're they've this those through to too under until up very was wasn't we we'd we'll we're we've were weren't what what's when when's where where's which while who who's whom why why's with won't would wouldn't you you'd you'll you're you've your yours yourself yourselves".split() # noqa: E501 diff --git a/guide/webapp/display/text.py b/guide/webapp/display/text.py index 00518cdc..2157da7e 100644 --- a/guide/webapp/display/text.py +++ b/guide/webapp/display/text.py @@ -1,5 +1,6 @@ import re + SLUGIFY_PATTERN = re.compile(r"[^a-zA-Z0-9-]") diff --git a/guide/webapp/endpoint/search.py b/guide/webapp/endpoint/search.py index 030ed24d..2bbfc007 100644 --- a/guide/webapp/endpoint/search.py +++ b/guide/webapp/endpoint/search.py @@ -6,6 +6,7 @@ from webapp.display.page import Page from webapp.display.search.renderer import SearchRenderer from webapp.display.search.search import Document, Searcher, Stemmer + bp = Blueprint("search", url_prefix="//search") diff --git a/guide/webapp/endpoint/view.py b/guide/webapp/endpoint/view.py index 09f1d04a..220481c6 100644 --- a/guide/webapp/endpoint/view.py +++ b/guide/webapp/endpoint/view.py @@ -2,4 +2,5 @@ from sanic import Blueprint from .search import bp as search_bp + bp = Blueprint.group(search_bp) diff --git a/guide/webapp/worker/config.py b/guide/webapp/worker/config.py index fea7b0cd..f95a0d91 100644 --- a/guide/webapp/worker/config.py +++ b/guide/webapp/worker/config.py @@ -4,6 +4,7 @@ from msgspec import yaml from webapp.display.layouts.models import GeneralConfig, MenuItem + def load_menu(path: Path) -> list[MenuItem]: loaded = yaml.decode(path.read_bytes(), type=dict[str, list[MenuItem]]) return loaded["root"] diff --git a/guide/webapp/worker/factory.py b/guide/webapp/worker/factory.py index 9703b04e..3f5f454e 100644 --- a/guide/webapp/worker/factory.py +++ b/guide/webapp/worker/factory.py @@ -9,6 +9,7 @@ from webapp.worker.config import load_config, load_menu from webapp.worker.reload import setup_livereload from webapp.worker.style import setup_style + def _compile_sidebar_order(items: list[MenuItem]) -> list[str]: order = [] for item in items: diff --git a/guide/webapp/worker/reload.py b/guide/webapp/worker/reload.py index 2188151b..3269a12d 100644 --- a/guide/webapp/worker/reload.py +++ b/guide/webapp/worker/reload.py @@ -8,6 +8,7 @@ import ujson from sanic import Request, Sanic, Websocket + def setup_livereload(app: Sanic) -> None: @app.main_process_start async def main_process_start(app: Sanic): diff --git a/guide/webapp/worker/style.py b/guide/webapp/worker/style.py index 042b2413..01d6d92a 100644 --- a/guide/webapp/worker/style.py +++ b/guide/webapp/worker/style.py @@ -6,6 +6,7 @@ from sass import compile as compile_scss from webapp.display.code_style import SanicCodeStyle + def setup_style(app: Sanic) -> None: index = app.config.STYLE_DIR / "index.scss" style_output = app.config.PUBLIC_DIR / "assets" / "style.css"