ruff-only #1

Open
leo wants to merge 17 commits from ruff-only into main
36 changed files with 52 additions and 61 deletions
Showing only changes of commit 9ae25e6744 - Show all commits

View File

@ -1,5 +1,6 @@
import requests import requests
# Warning: This is a heavy process. # Warning: This is a heavy process.
data = "" data = ""

View File

@ -1,4 +1,5 @@
import re import re
from pathlib import Path from pathlib import Path
from textwrap import indent from textwrap import indent

7
guide/pyproject.toml Normal file
View File

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

View File

@ -2,7 +2,6 @@ from __future__ import annotations
from html5tagger import Builder, Document # type: ignore from html5tagger import Builder, Document # type: ignore
class BaseRenderer: class BaseRenderer:
def __init__(self, base_title: str): def __init__(self, base_title: str):
self.base_title = base_title self.base_title = base_title

View File

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

View File

@ -6,7 +6,6 @@ from typing import Generator
from html5tagger import Builder from html5tagger import Builder
from sanic import Request from sanic import Request
class BaseLayout: class BaseLayout:
def __init__(self, builder: Builder): def __init__(self, builder: Builder):
self.builder = builder self.builder = builder

View File

@ -3,7 +3,6 @@ from datetime import datetime
from html5tagger import Builder, E # type: ignore from html5tagger import Builder, E # type: ignore
from sanic import Request from sanic import Request
def do_footer(builder: Builder, request: Request) -> None: def do_footer(builder: Builder, request: Request) -> None:
builder.footer( builder.footer(
_pagination(request), _pagination(request),

View File

@ -1,8 +1,7 @@
from webapp.display.layouts.models import MenuItem
from html5tagger import Builder, E # type: ignore from html5tagger import Builder, E # type: ignore
from sanic import Request from sanic import Request
from webapp.display.layouts.models import MenuItem
def do_navbar(builder: Builder, request: Request) -> None: def do_navbar(builder: Builder, request: Request) -> None:
navbar_items = [ navbar_items = [

View File

@ -1,9 +1,8 @@
from webapp.display.layouts.models import MenuItem
from webapp.display.text import slugify
from html5tagger import Builder, E # type: ignore from html5tagger import Builder, E # type: ignore
from sanic import Request 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: def do_sidebar(builder: Builder, request: Request) -> None:
builder.a(class_="burger")(E.span().span().span().span()) builder.a(class_="burger")(E.span().span().span().span())

View File

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

View File

@ -1,15 +1,14 @@
from contextlib import contextmanager from contextlib import contextmanager
from typing import Generator from typing import Generator
from sanic import Request
from webapp.display.layouts.elements.footer import do_footer from webapp.display.layouts.elements.footer import do_footer
from webapp.display.layouts.elements.navbar import do_navbar from webapp.display.layouts.elements.navbar import do_navbar
from webapp.display.layouts.elements.sidebar import do_sidebar from webapp.display.layouts.elements.sidebar import do_sidebar
from sanic import Request
from .base import BaseLayout from .base import BaseLayout
class MainLayout(BaseLayout): class MainLayout(BaseLayout):
@contextmanager @contextmanager
def layout( def layout(

View File

@ -2,7 +2,6 @@ from __future__ import annotations
from msgspec import Struct, field from msgspec import Struct, field
class MenuItem(Struct, kw_only=False, omit_defaults=True): class MenuItem(Struct, kw_only=False, omit_defaults=True):
label: str label: str
path: str | None = None path: str | None = None

View File

@ -1,6 +1,8 @@
import re import re
from textwrap import dedent from textwrap import dedent
from html5tagger import HTML, Builder, E # type: ignore
from mistune import HTMLRenderer, create_markdown, escape from mistune import HTMLRenderer, create_markdown, escape
from mistune.directives import RSTDirective, TableOfContents from mistune.directives import RSTDirective, TableOfContents
from mistune.util import safe_entity from mistune.util import safe_entity
@ -8,8 +10,6 @@ from pygments import highlight
from pygments.formatters import html from pygments.formatters import html
from pygments.lexers import get_lexer_by_name from pygments.lexers import get_lexer_by_name
from html5tagger import HTML, Builder, E # type: ignore
from .code_style import SanicCodeStyle from .code_style import SanicCodeStyle
from .plugins.attrs import Attributes from .plugins.attrs import Attributes
from .plugins.columns import Column from .plugins.columns import Column
@ -20,7 +20,6 @@ from .plugins.span import span
from .plugins.tabs import Tabs from .plugins.tabs import Tabs
from .text import slugify from .text import slugify
class DocsRenderer(HTMLRenderer): class DocsRenderer(HTMLRenderer):
def block_code(self, code: str, info: str | None = None): def block_code(self, code: str, info: str | None = None):
builder = Builder("Block") builder = Builder("Block")

View File

@ -3,6 +3,7 @@ from __future__ import annotations
import importlib import importlib
import inspect import inspect
import pkgutil import pkgutil
from collections import defaultdict from collections import defaultdict
from dataclasses import dataclass, field from dataclasses import dataclass, field
from html import escape from html import escape
@ -10,12 +11,10 @@ from html import escape
from docstring_parser import Docstring, DocstringParam, DocstringRaises from docstring_parser import Docstring, DocstringParam, DocstringRaises
from docstring_parser import parse as parse_docstring from docstring_parser import parse as parse_docstring
from docstring_parser.common import DocstringExample from docstring_parser.common import DocstringExample
from html5tagger import HTML, Builder, E # type: ignore from html5tagger import HTML, Builder, E # type: ignore
from ..markdown import render_markdown, slugify from ..markdown import render_markdown, slugify
@dataclass @dataclass
class DocObject: class DocObject:
name: str name: str

View File

@ -3,15 +3,14 @@ from __future__ import annotations
from contextlib import contextmanager from contextlib import contextmanager
from typing import Type from typing import Type
from webapp.display.base import BaseRenderer
from html5tagger import HTML, Builder # type: ignore from html5tagger import HTML, Builder # type: ignore
from sanic import Request from sanic import Request
from webapp.display.base import BaseRenderer
from ..layouts.base import BaseLayout from ..layouts.base import BaseLayout
from .page import Page from .page import Page
class PageRenderer(BaseRenderer): class PageRenderer(BaseRenderer):
def render(self, request: Request, language: str, path: str) -> Builder: def render(self, request: Request, language: str, path: str) -> Builder:
builder = self.get_builder( builder = self.get_builder(

View File

@ -2,13 +2,11 @@ from re import Match
from textwrap import dedent from textwrap import dedent
from typing import Any from typing import Any
from html5tagger import HTML, E
from mistune.block_parser import BlockParser from mistune.block_parser import BlockParser
from mistune.core import BlockState from mistune.core import BlockState
from mistune.directives import DirectivePlugin from mistune.directives import DirectivePlugin
from html5tagger import HTML, E
class Attributes(DirectivePlugin): class Attributes(DirectivePlugin):
def __call__(self, directive, md): def __call__(self, directive, md):
directive.register("attrs", self.parse) directive.register("attrs", self.parse)

View File

@ -8,7 +8,6 @@ from mistune.core import BlockState
from mistune.directives import DirectivePlugin, RSTDirective from mistune.directives import DirectivePlugin, RSTDirective
from mistune.markdown import Markdown from mistune.markdown import Markdown
class Column(DirectivePlugin): class Column(DirectivePlugin):
def parse( def parse(
self, block: BlockParser, m: Match, state: BlockState self, block: BlockParser, m: Match, state: BlockState

View File

@ -2,7 +2,6 @@ from mistune.core import BlockState
from mistune.directives import DirectivePlugin, RSTDirective from mistune.directives import DirectivePlugin, RSTDirective
from mistune.markdown import Markdown from mistune.markdown import Markdown
class Hook(DirectivePlugin): class Hook(DirectivePlugin):
def __call__( # type: ignore def __call__( # type: ignore
self, directive: RSTDirective, md: Markdown self, directive: RSTDirective, md: Markdown

View File

@ -3,15 +3,13 @@ from re import Match
from textwrap import dedent from textwrap import dedent
from typing import Any from typing import Any
from html5tagger import HTML, E
from mistune import HTMLRenderer from mistune import HTMLRenderer
from mistune.block_parser import BlockParser from mistune.block_parser import BlockParser
from mistune.core import BlockState from mistune.core import BlockState
from mistune.directives import DirectivePlugin, RSTDirective from mistune.directives import DirectivePlugin, RSTDirective
from mistune.markdown import Markdown from mistune.markdown import Markdown
from html5tagger import HTML, E
class Mermaid(DirectivePlugin): class Mermaid(DirectivePlugin):
def parse( def parse(
self, block: BlockParser, m: Match, state: BlockState self, block: BlockParser, m: Match, state: BlockState

View File

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

View File

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

View File

@ -8,7 +8,6 @@ from mistune.core import BlockState
from mistune.directives import DirectivePlugin, RSTDirective from mistune.directives import DirectivePlugin, RSTDirective
from mistune.markdown import Markdown from mistune.markdown import Markdown
class Tabs(DirectivePlugin): class Tabs(DirectivePlugin):
def parse( def parse(
self, block: BlockParser, m: Match, state: BlockState self, block: BlockParser, m: Match, state: BlockState

View File

@ -1,15 +1,14 @@
from contextlib import contextmanager from contextlib import contextmanager
from urllib.parse import unquote from urllib.parse import unquote
from webapp.display.search.search import Searcher
from html5tagger import Builder, E # type: ignore from html5tagger import Builder, E # type: ignore
from sanic import Request from sanic import Request
from webapp.display.search.search import Searcher
from ..base import BaseRenderer from ..base import BaseRenderer
from ..layouts.main import MainLayout from ..layouts.main import MainLayout
class SearchRenderer(BaseRenderer): class SearchRenderer(BaseRenderer):
def render( def render(
self, request: Request, language: str, searcher: Searcher, full: bool self, request: Request, language: str, searcher: Searcher, full: bool

View File

@ -5,8 +5,8 @@ from pathlib import Path
from typing import ClassVar from typing import ClassVar
from msgspec import Struct from msgspec import Struct
from webapp.display.page import Page
from webapp.display.page import Page
class Stemmer: class Stemmer:
STOP_WORDS: ClassVar[set[str]] = set( STOP_WORDS: ClassVar[set[str]] = set(

View File

@ -1,11 +1,11 @@
# from urllib.parse import unquote # from urllib.parse import unquote
from sanic import Blueprint, Request, Sanic, html
from webapp.display.page import Page from webapp.display.page import Page
from webapp.display.search.renderer import SearchRenderer from webapp.display.search.renderer import SearchRenderer
from webapp.display.search.search import Document, Searcher, Stemmer from webapp.display.search.search import Document, Searcher, Stemmer
from sanic import Blueprint, Request, Sanic, html
bp = Blueprint("search", url_prefix="/<language>/search") bp = Blueprint("search", url_prefix="/<language>/search")

View File

@ -1,8 +1,8 @@
from pathlib import Path from pathlib import Path
from msgspec import yaml from msgspec import yaml
from webapp.display.layouts.models import GeneralConfig, MenuItem
from webapp.display.layouts.models import GeneralConfig, MenuItem
def load_menu(path: Path) -> list[MenuItem]: def load_menu(path: Path) -> list[MenuItem]:
loaded = yaml.decode(path.read_bytes(), type=dict[str, list[MenuItem]]) loaded = yaml.decode(path.read_bytes(), type=dict[str, list[MenuItem]])

View File

@ -1,5 +1,7 @@
from pathlib import Path from pathlib import Path
from sanic import Request, Sanic, html, redirect
from webapp.display.layouts.models import MenuItem from webapp.display.layouts.models import MenuItem
from webapp.display.page import Page, PageRenderer from webapp.display.page import Page, PageRenderer
from webapp.endpoint.view import bp from webapp.endpoint.view import bp
@ -7,9 +9,6 @@ from webapp.worker.config import load_config, load_menu
from webapp.worker.reload import setup_livereload from webapp.worker.reload import setup_livereload
from webapp.worker.style import setup_style from webapp.worker.style import setup_style
from sanic import Request, Sanic, html, redirect
def _compile_sidebar_order(items: list[MenuItem]) -> list[str]: def _compile_sidebar_order(items: list[MenuItem]) -> list[str]:
order = [] order = []
for item in items: for item in items:

View File

@ -8,7 +8,6 @@ import ujson
from sanic import Request, Sanic, Websocket from sanic import Request, Sanic, Websocket
def setup_livereload(app: Sanic) -> None: def setup_livereload(app: Sanic) -> None:
@app.main_process_start @app.main_process_start
async def main_process_start(app: Sanic): async def main_process_start(app: Sanic):

View File

@ -1,11 +1,10 @@
# from scss.compiler import compile_string # from scss.compiler import compile_string
from pygments.formatters import html from pygments.formatters import html
from sass import compile as compile_scss
from webapp.display.code_style import SanicCodeStyle
from sanic import Sanic from sanic import Sanic
from sass import compile as compile_scss
from webapp.display.code_style import SanicCodeStyle
def setup_style(app: Sanic) -> None: def setup_style(app: Sanic) -> None:
index = app.config.STYLE_DIR / "index.scss" index = app.config.STYLE_DIR / "index.scss"

View File

@ -4,6 +4,13 @@ build-backend = "setuptools.build_meta"
[tool.ruff] [tool.ruff]
line-length = 79 line-length = 79
extend-select = ["I"]
[tool.ruff.isort]
known-first-party = ["sanic"]
known-third-party = ["pytest"]
lines-after-imports = 2
lines-between-types = 1
[tool.black] [tool.black]
line-length = 79 line-length = 79

View File

@ -1,7 +1,6 @@
from collections.abc import Mapping from collections.abc import Mapping
from typing import Any, Dict, ItemsView, Iterator, KeysView, List from typing import Any, Dict, ItemsView, Iterator, KeysView, List, ValuesView
from typing import Mapping as MappingType from typing import Mapping as MappingType
from typing import ValuesView
dict dict

View File

@ -1,12 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
from os import path
import sys import sys
from os import path
if __name__ == "__main__": if __name__ == "__main__":
try: try:
import towncrier
import click import click
import towncrier
except ImportError: except ImportError:
print( print(
"Please make sure you have a installed towncrier and click before using this tool" "Please make sure you have a installed towncrier and click before using this tool"

View File

@ -1,18 +1,21 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys
from argparse import ArgumentParser, Namespace from argparse import ArgumentParser, Namespace
from collections import OrderedDict from collections import OrderedDict
from configparser import RawConfigParser from configparser import RawConfigParser
from datetime import datetime from datetime import datetime
from json import dumps from json import dumps
from os import path, chdir from os import chdir, path
from subprocess import Popen, PIPE from subprocess import PIPE, Popen
from jinja2 import Environment, BaseLoader
from requests import patch
import sys
import towncrier import towncrier
from jinja2 import BaseLoader, Environment
from requests import patch
GIT_COMMANDS = { GIT_COMMANDS = {
"get_tag": ["git describe --tags --abbrev=0"], "get_tag": ["git describe --tags --abbrev=0"],
"commit_version_change": [ "commit_version_change": [

View File

@ -3,7 +3,6 @@ import os
import sys import sys
import timeit import timeit
from sanic.response import json from sanic.response import json

View File

@ -1,6 +1,5 @@
from asyncio import CancelledError from asyncio import CancelledError
from sanic import Request, Sanic, json from sanic import Request, Sanic, json

View File

@ -1,6 +1,5 @@
import sys import sys
import pytest import pytest
from sanic import Sanic from sanic import Sanic