Skip to content

Commit f261b38

Browse files
committed
Avoid runtime errors in binary builds from docutils dynamically importing modules.
1 parent e967469 commit f261b38

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

snooty/rstparser.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import docutils.nodes
55
import docutils.parsers.rst
66
import docutils.parsers.rst.directives
7+
import docutils.parsers.rst.directives.misc
78
import docutils.parsers.rst.roles
89
import docutils.parsers.rst.states
910
import docutils.statemachine
@@ -26,6 +27,13 @@
2627
if PACKAGE_ROOT.is_file():
2728
PACKAGE_ROOT = PACKAGE_ROOT.parent
2829

30+
# Remove the built-in directives we don't want
31+
# TODO: This hack can be removed once we refactor role and directive handling
32+
docutils.parsers.rst.directives._directive_registry = {
33+
k: v for k, v in docutils.parsers.rst.directives._directive_registry.items()
34+
if k in {'replace', 'unicode'}
35+
}
36+
2937

3038
@checked
3139
@dataclass
@@ -221,7 +229,7 @@ class TabsDirective(BaseDocutilsDirective):
221229

222230
def run(self) -> List[docutils.nodes.Node]:
223231
# Transform the old YAML-based syntax into the new pure-rst syntax.
224-
# This heuristic gusses whether we have the old syntax or the NEW.
232+
# This heuristic guesses whether we have the old syntax or the NEW.
225233
if any(line == 'tabs:' for line in self.content):
226234
parsed = load_yaml('\n'.join(self.content))[0]
227235
try:

stubs/docutils/parsers/rst/directives.pyi renamed to stubs/docutils/parsers/rst/directives/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Collection, List, Type, Tuple
1+
from typing import Any, Collection, Dict, List, Type, Tuple
22
import docutils.nodes
33
from docutils.parsers.rst import Directive
44

@@ -12,3 +12,5 @@ def flag(argument: str) -> None: ...
1212
def length_or_percentage_or_unitless(argument: str) -> str: ...
1313

1414
def register_directive(name: str, directive: Type[Directive]) -> None: ...
15+
16+
_directive_registry: Dict[str, Tuple[str, str]] = ...

stubs/docutils/parsers/rst/directives/misc.pyi

Whitespace-only changes.

0 commit comments

Comments
 (0)