Skip to content

Commit 04f4db5

Browse files
committed
Fix lint issues
Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
1 parent 39e4d66 commit 04f4db5

3 files changed

Lines changed: 31 additions & 30 deletions

File tree

sphinx_markdown_builder/contexts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,15 @@ def make(self):
383383
_ContextT = TypeVar("_ContextT", bound=SubContext)
384384

385385
Translator = Callable[[Any, Any], Dict[str, Any]]
386-
DEFAULT_TRANSLATOR: Translator = lambda _node, _elem: {}
386+
default_translator: Translator = lambda _node, _elem: {}
387387

388388

389389
class PushContext(Generic[_ContextT]): # pylint: disable=too-few-public-methods
390390
def __init__(
391391
self,
392392
ctx: Type[_ContextT],
393393
*args,
394-
translator: Translator = DEFAULT_TRANSLATOR,
394+
translator: Translator = default_translator,
395395
**kwargs,
396396
):
397397
self.ctx = ctx
@@ -405,10 +405,10 @@ def create(self, node, element_key) -> _ContextT:
405405
return self.ctx(*self.args, **kwargs)
406406

407407

408-
ItalicContext = PushContext(WrappedContext, "*") # _ is more restrictive
409-
StrongContext = PushContext(WrappedContext, "**") # _ is more restrictive
410-
SubscriptContext = PushContext(WrappedContext, "<sub>", "</sub>")
411-
DocInfoContext = PushContext(
408+
ITALIC_CONTEXT = PushContext(WrappedContext, "*") # _ is more restrictive
409+
STRONG_CONTEXT = PushContext(WrappedContext, "**") # _ is more restrictive
410+
SUBSCRIPT_CONTEXT = PushContext(WrappedContext, "<sub>", "</sub>")
411+
DOC_INFO_CONTEXT = PushContext(
412412
MetaContext,
413413
translator=lambda _node, elem: {"name": f"{elem}: "},
414414
)

sphinx_markdown_builder/translator.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@
3434
from sphinx_markdown_builder.contexts import (
3535
CommaSeparatedContext,
3636
ContextStatus,
37-
DocInfoContext,
37+
DOC_INFO_CONTEXT,
3838
IndentContext,
39-
ItalicContext,
39+
ITALIC_CONTEXT,
4040
ListMarker,
4141
MetaContext,
4242
PushContext,
43-
StrongContext,
43+
STRONG_CONTEXT,
4444
SubContext,
4545
SubContextParams,
46-
SubscriptContext,
46+
SUBSCRIPT_CONTEXT,
4747
TableContext,
4848
TitleContext,
4949
UniqueString,
@@ -63,18 +63,18 @@
6363
# Defines context items, skip, or None (keep processing sub-tree).
6464
PREDEFINED_ELEMENTS: Dict[str, Union[PushContext, SKIP, None]] = dict( # pylint: disable=use-dict-literal
6565
# Doctree elements for which Markdown element is <prefix><content><suffix>
66-
emphasis=ItalicContext,
67-
strong=StrongContext,
68-
subscript=SubscriptContext,
69-
superscript=SubscriptContext,
70-
desc_annotation=ItalicContext,
71-
literal_strong=StrongContext,
72-
literal_emphasis=ItalicContext,
66+
emphasis=ITALIC_CONTEXT,
67+
strong=STRONG_CONTEXT,
68+
subscript=SUBSCRIPT_CONTEXT,
69+
superscript=SUBSCRIPT_CONTEXT,
70+
desc_annotation=ITALIC_CONTEXT,
71+
literal_strong=STRONG_CONTEXT,
72+
literal_emphasis=ITALIC_CONTEXT,
7373
field_name=PushContext(WrappedContext, "**", ":**"), # e.g 'returns', 'parameters'
7474
# Doc info elements
75-
docinfo=DocInfoContext,
76-
docinfo_item=DocInfoContext,
77-
**dict.fromkeys(DOC_INFO_FIELDS, DocInfoContext),
75+
docinfo=DOC_INFO_CONTEXT,
76+
docinfo_item=DOC_INFO_CONTEXT,
77+
**dict.fromkeys(DOC_INFO_FIELDS, DOC_INFO_CONTEXT),
7878
authors=None, # not used: visit_author is called anyway for each author.
7979
# Doctree elements to skip subtree
8080
autosummary_toc=SKIP,

tests/test_builder.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Integration tests for the markdown builder
33
"""
4+
45
import os
56
import shutil
67
import stat
@@ -98,6 +99,15 @@ def test_builder_access_issue(flags: Iterable[str], build_path: str):
9899
_chmod_output(build_path, lambda mode: mode | flag)
99100

100101

102+
def _has_suffix_in_path(path: str, suffix: str) -> bool:
103+
"""Checks that at least one file with the given suffix exists"""
104+
for root, dirs, files in os.walk(path):
105+
for file in files:
106+
if file.endswith(suffix):
107+
return True
108+
return False
109+
110+
101111
def test_custom_file_suffix():
102112
"""Test that markdown_file_suffix configuration generates files with correct suffix"""
103113
build_path = os.path.join(BUILD_PATH, "test_suffix")
@@ -112,16 +122,7 @@ def test_custom_file_suffix():
112122
assert os.path.exists(markdown_dir), f"Markdown output directory not found: {markdown_dir}"
113123

114124
# Check that at least one file with the custom suffix exists
115-
found_custom_suffix = False
116-
for root, dirs, files in os.walk(markdown_dir):
117-
for file in files:
118-
if file.endswith(suffix):
119-
found_custom_suffix = True
120-
break
121-
if found_custom_suffix:
122-
break
123-
124-
assert found_custom_suffix, f"No files with suffix '{suffix}' found in {markdown_dir}"
125+
assert _has_suffix_in_path(markdown_dir, suffix), f"No files with suffix '{suffix}' found in {markdown_dir}"
125126

126127
# Clean up
127128
_rm_build_path(build_path)

0 commit comments

Comments
 (0)