ruff-only #1

Open
leo wants to merge 17 commits from ruff-only into main
33 changed files with 32 additions and 2 deletions
Showing only changes of commit 6fac60c6fe - Show all commits

View File

@ -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)

View File

@ -3,5 +3,3 @@ extend = "../pyproject.toml"
[tool.ruff.isort]
known-first-party = ["webapp"]
lines-after-imports = 1
lines-between-types = 1

View File

@ -2,4 +2,5 @@ from pathlib import Path
from webapp.worker.factory import create_app
app = create_app(Path(__file__).parent)

View File

@ -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

View File

@ -7,6 +7,7 @@ from pygments.token import ( # Error,; Generic,; Number,; Operator,
Token,
)
class SanicCodeStyle(Style):
styles = {
Token: "#777",

View File

@ -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

View File

@ -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),

View File

@ -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)

View File

@ -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")

View File

@ -8,6 +8,7 @@ from sanic import Request
from .base import BaseLayout
class HomeLayout(BaseLayout):
@contextmanager
def layout(

View File

@ -9,6 +9,7 @@ from webapp.display.layouts.elements.sidebar import do_sidebar
from .base import BaseLayout
class MainLayout(BaseLayout):
@contextmanager
def layout(

View File

@ -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

View File

@ -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")

View File

@ -1,4 +1,5 @@
from .page import Page
from .renderer import PageRenderer
__all__ = ["Page", "PageRenderer"]

View File

@ -15,6 +15,7 @@ from html5tagger import HTML, Builder, E # type: ignore
from ..markdown import render_markdown, slugify
@dataclass
class DocObject:
name: str

View File

@ -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]]
] = {}

View File

@ -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(

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,7 @@
from html5tagger import HTML, E
from mistune.directives import Admonition
class Notification(Admonition):
SUPPORTED_NAMES = {
"success",

View File

@ -2,6 +2,7 @@ import re
from mistune.markdown import Markdown
def parse_inline_span(inline, m: re.Match, state):
state.append_token(
{

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,6 @@
import re
SLUGIFY_PATTERN = re.compile(r"[^a-zA-Z0-9-]")

View File

@ -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="/<language>/search")

View File

@ -2,4 +2,5 @@ from sanic import Blueprint
from .search import bp as search_bp
bp = Blueprint.group(search_bp)

View File

@ -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"]

View File

@ -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:

View File

@ -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):

View File

@ -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"