Skip to content

Commit 135dafe

Browse files
committed
Fix import ordering in directive.py and nodes.py
- Move sphinx.locale imports to top of file - Fixes E402 pre-commit errors
1 parent 310cc6b commit 135dafe

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ recursive-include sphinx_exercise *.css
88
recursive-include sphinx_exercise *.json
99
recursive-include sphinx_exercise *.mo
1010
recursive-include sphinx_exercise *.po
11-
recursive-include sphinx_exercise *.py
11+
recursive-include sphinx_exercise *.py

sphinx_exercise/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
# Callback Functions
7373

74+
7475
def purge_exercises(app: Sphinx, env: BuildEnvironment, docname: str) -> None:
7576
"""Purge sphinx_exercise registry"""
7677

sphinx_exercise/directive.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
from typing import List
1212
from docutils.nodes import Node
13-
14-
from sphinx.util.docutils import SphinxDirective
13+
from docutils import nodes
1514
from docutils.parsers.rst import directives
15+
from sphinx.util.docutils import SphinxDirective
16+
from sphinx.util import logging
17+
from sphinx.locale import get_translation
18+
1619
from .nodes import (
1720
exercise_node,
1821
exercise_enumerable_node,
@@ -24,12 +27,9 @@
2427
exercise_subtitle,
2528
solution_title,
2629
)
27-
from docutils import nodes
28-
from sphinx.util import logging
2930

3031
logger = logging.getLogger(__name__)
3132

32-
from sphinx.locale import get_translation
3333
MESSAGE_CATALOG_NAME = "exercise"
3434
translate = get_translation(MESSAGE_CATALOG_NAME)
3535

sphinx_exercise/nodes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
from docutils import nodes as docutil_nodes
1414
from sphinx import addnodes as sphinx_nodes
1515
from sphinx.writers.latex import LaTeXTranslator
16+
from sphinx.locale import get_translation
17+
1618
from .latex import LaTeXMarkup
1719

1820
logger = logging.getLogger(__name__)
1921
LaTeX = LaTeXMarkup()
2022

21-
22-
from sphinx.locale import get_translation
2323
MESSAGE_CATALOG_NAME = "exercise"
2424
translate = get_translation(MESSAGE_CATALOG_NAME)
2525

@@ -54,7 +54,10 @@ class solution_end_node(docutil_nodes.Admonition, docutil_nodes.Element):
5454
class exercise_title(docutil_nodes.title):
5555
def default_title(self):
5656
title_text = self.children[0].astext()
57-
if title_text == f"{translate('Exercise')}" or title_text == f"{translate('Exercise')} %s":
57+
if (
58+
title_text == f"{translate('Exercise')}"
59+
or title_text == f"{translate('Exercise')} %s"
60+
):
5861
return True
5962
else:
6063
return False

sphinx_exercise/translations/_convert.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
MESSAGE_CATALOG_NAME = "exercise"
77

8+
89
def convert_json(folder=None):
910
folder = folder or Path(__file__).parent
1011

@@ -19,7 +20,13 @@ def convert_json(folder=None):
1920
english = data[0]["text"]
2021
for item in data[1:]:
2122
language = item["symbol"]
22-
out_path = folder / "locales" / language / "LC_MESSAGES" / f"{MESSAGE_CATALOG_NAME}.po"
23+
out_path = (
24+
folder
25+
/ "locales"
26+
/ language
27+
/ "LC_MESSAGES"
28+
/ f"{MESSAGE_CATALOG_NAME}.po"
29+
)
2330
if not out_path.parent.exists():
2431
out_path.parent.mkdir(parents=True)
2532
if not out_path.exists():

0 commit comments

Comments
 (0)