Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos-render-docs: De-lint using ruff --fix #237669

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,13 +1,10 @@
import argparse
import os
import sys
import textwrap
import traceback
from io import StringIO
from pprint import pprint
from typing import Any, Dict

from .md import Converter
from . import manual
from . import options
from . import parallel
Expand All @@ -26,7 +23,7 @@ def pretty_print_exc(e: BaseException, *, _desc_text: str = "error") -> None:
for arg in args:
pprint(arg, stream=buf)
if extra_info := buf.getvalue():
print(f"\x1b[1;34mextra info:\x1b[0m", file=sys.stderr)
print("\x1b[1;34mextra info:\x1b[0m", file=sys.stderr)
print(textwrap.indent(extra_info, "\t"), file=sys.stderr, end="")
else:
print(e)
Expand Down
@@ -1,6 +1,6 @@
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from typing import Any, cast, Optional
from typing import cast
from urllib.parse import quote

from .md import Renderer
Expand Down Expand Up @@ -104,7 +104,7 @@ def paragraph_close(self, token: Token, tokens: Sequence[Token], i: int) -> str:
def hardbreak(self, token: Token, tokens: Sequence[Token], i: int) -> str:
return " +\n"
def softbreak(self, token: Token, tokens: Sequence[Token], i: int) -> str:
return f" "
return " "
def code_inline(self, token: Token, tokens: Sequence[Token], i: int) -> str:
self._parstack[-1].continuing = True
return f"``{asciidoc_escape(token.content)}``"
Expand Down
@@ -1,6 +1,6 @@
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from typing import Any, cast, Optional
from typing import cast, Optional

from .md import md_escape, md_make_code, Renderer

Expand Down
@@ -1,7 +1,6 @@
from collections.abc import Mapping, Sequence
from typing import Any, cast, Optional, NamedTuple
from typing import cast, Optional, NamedTuple

import markdown_it
from markdown_it.token import Token
from xml.sax.saxutils import escape, quoteattr

Expand Down Expand Up @@ -197,7 +196,7 @@ def ordered_list_open(self, token: Token, tokens: Sequence[Token], i: int) -> st
spacing = ' spacing="compact"' if token.meta.get('compact', False) else ''
return f"<orderedlist{start}{spacing}>"
def ordered_list_close(self, token: Token, tokens: Sequence[Token], i: int) -> str:
return f"</orderedlist>"
return "</orderedlist>"
def heading_open(self, token: Token, tokens: Sequence[Token], i: int) -> str:
hlevel = int(token.tag[1:])
result = self._close_headings(hlevel)
Expand Down
Expand Up @@ -211,7 +211,7 @@ def ordered_list_open(self, token: Token, tokens: Sequence[Token], i: int) -> st
self._ordered_list_nesting += 1
return f'<div class="orderedlist"><ol class="orderedlist {extra}" {start} type="{style}">'
def ordered_list_close(self, token: Token, tokens: Sequence[Token], i: int) -> str:
self._ordered_list_nesting -= 1;
self._ordered_list_nesting -= 1
return "</ol></div>"
def example_open(self, token: Token, tokens: Sequence[Token], i: int) -> str:
if id := cast(str, token.attrs.get('id', '')):
Expand Down
@@ -1,10 +1,9 @@
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from typing import Any, cast, Iterable, Optional
from typing import cast, Iterable, Optional

import re

import markdown_it
from markdown_it.token import Token

from .md import Renderer
Expand Down
Expand Up @@ -7,17 +7,15 @@
from abc import abstractmethod
from collections.abc import Mapping, Sequence
from pathlib import Path
from typing import Any, cast, ClassVar, Generic, get_args, NamedTuple, Optional, Union
from typing import Any, cast, ClassVar, Generic, get_args, NamedTuple

import markdown_it
from markdown_it.token import Token

from . import md, options
from .docbook import DocBookRenderer, Heading, make_xml_id
from .html import HTMLRenderer, UnresolvedXrefError
from .manual_structure import check_structure, FragmentType, is_include, TocEntry, TocEntryType, XrefTarget
from .md import Converter, Renderer
from .utils import Freezeable

class BaseConverter(Converter[md.TR], Generic[md.TR]):
# per-converter configuration for ns:arg=value arguments to include blocks, following
Expand Down Expand Up @@ -519,7 +517,7 @@ def _parse(self, src: str) -> list[Token]:
# we use blender-style //path to denote paths relative to the origin file
# (usually index.html). this makes everything a lot easier and clearer.
if not into.startswith("//") or '/' in into[2:]:
raise RuntimeError(f"html:into-file must be a relative-to-origin //filename", into)
raise RuntimeError("html:into-file must be a relative-to-origin //filename", into)
into = token.meta['include-args']['into-file'] = into[2:]
if into in self._redirection_targets:
raise RuntimeError(f"redirection target {into} in line {token.map[0] + 1} is already in use")
Expand Down Expand Up @@ -617,7 +615,7 @@ def _postprocess(self, infile: Path, outfile: Path, tokens: Sequence[Token]) ->
for item in xref_queue:
try:
target = item if isinstance(item, XrefTarget) else self._render_xref(*item)
except UnresolvedXrefError as e:
except UnresolvedXrefError:
if failed:
raise
deferred.append(item)
Expand Down
@@ -1,6 +1,6 @@
from abc import ABC
from collections.abc import Mapping, MutableMapping, Sequence
from typing import Any, Callable, cast, Generic, get_args, Iterable, Literal, NoReturn, Optional, TypeVar
from typing import Any, cast, Generic, get_args, Iterable, Literal, NoReturn, Optional, TypeVar

import dataclasses
import re
Expand Down
Expand Up @@ -11,7 +11,6 @@
from typing import Any, Generic, Optional
from urllib.parse import quote

import markdown_it

from . import md
from . import parallel
Expand Down Expand Up @@ -265,7 +264,7 @@ def finalize(self, *, fragment: bool = False) -> str:
' <title>Configuration Options</title>',
]
result += [
f'<variablelist xmlns:xlink="http://www.w3.org/1999/xlink"',
'<variablelist xmlns:xlink="http://www.w3.org/1999/xlink"',
' xmlns:nixos="tag:nixos.org"',
' xmlns="http://docbook.org/ns/docbook"',
f' xml:id="{self._varlist_id}">',
Expand Down
Expand Up @@ -4,7 +4,7 @@

import multiprocessing

from typing import Any, Callable, ClassVar, Iterable, Optional, TypeVar
from typing import Any, Callable, Iterable, Optional, TypeVar

R = TypeVar('R')
S = TypeVar('S')
Expand Down
@@ -1,5 +1,5 @@
from collections.abc import Sequence
from typing import Any, Callable, Optional, Tuple, NamedTuple
from typing import Callable, Optional, NamedTuple

from markdown_it.token import Token

Expand Down
5 changes: 2 additions & 3 deletions pkgs/tools/nix/nixos-render-docs/src/tests/test_commonmark.py
Expand Up @@ -2,9 +2,8 @@

from sample_md import sample1

from typing import Mapping, Optional
from typing import Mapping

import markdown_it

class Converter(nrd.md.Converter[nrd.commonmark.CommonMarkRenderer]):
def __init__(self, manpage_urls: Mapping[str, str]):
Expand All @@ -27,7 +26,7 @@ def test_indented_fence() -> None:

def test_full() -> None:
c = Converter({ 'man(1)': 'http://example.org' })
assert c._render(sample1) == f"""\
assert c._render(sample1) == """\
**Warning:** foo

**Note:** nested
Expand Down
3 changes: 1 addition & 2 deletions pkgs/tools/nix/nixos-render-docs/src/tests/test_manpage.py
Expand Up @@ -2,9 +2,8 @@

from sample_md import sample1

from typing import Mapping, Optional
from typing import Mapping

import markdown_it

class Converter(nrd.md.Converter[nrd.manpage.ManpageRenderer]):
def __init__(self, manpage_urls: Mapping[str, str], options_by_id: dict[str, str] = {}):
Expand Down