-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from jbms/fix-138
Fix several issues with nav_adapt and add unit tests
- Loading branch information
Showing
50 changed files
with
2,450 additions
and
1,001 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ types-PyYAML | |
docutils-stubs | ||
types-jsonschema | ||
pytest | ||
pytest-snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Optional, List | ||
|
||
import docutils.nodes | ||
import sphinx.domains.python | ||
import sphinx.environment | ||
|
||
|
||
def ensure_wrapped_in_desc_type( | ||
nodes: List[docutils.nodes.Node], | ||
) -> List[docutils.nodes.Node]: | ||
if len(nodes) != 1 or not isinstance(nodes[0], sphinx.addnodes.desc_type): | ||
nodes = [sphinx.addnodes.desc_type("", "", *nodes)] | ||
return nodes | ||
|
||
|
||
def _monkey_patch_python_parse_annotation(): | ||
"""Ensures that type annotations in signatures are wrapped in `desc_type`. | ||
This allows them to be distinguished from parameter names in CSS rules. | ||
""" | ||
orig_parse_annotation = sphinx.domains.python._parse_annotation | ||
|
||
def parse_annotation( | ||
annotation: str, env: Optional[sphinx.environment.BuildEnvironment] = None | ||
) -> List[docutils.nodes.Node]: | ||
return ensure_wrapped_in_desc_type(orig_parse_annotation(annotation, env)) | ||
|
||
sphinx.domains.python._parse_annotation = parse_annotation | ||
|
||
|
||
_monkey_patch_python_parse_annotation() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Type, Tuple | ||
|
||
import docutils.nodes | ||
import sphinx.addnodes | ||
import sphinx.domains.python | ||
|
||
|
||
def _monkey_patch_pyattribute_handle_signature( | ||
directive_cls: Type[sphinx.domains.python.PyObject], | ||
): | ||
"""Modifies PyAttribute or PyVariable to improve styling of signature.""" | ||
|
||
def handle_signature( | ||
self, sig: str, signode: sphinx.addnodes.desc_signature | ||
) -> Tuple[str, str]: | ||
result = super(directive_cls, self).handle_signature(sig, signode) | ||
typ = self.options.get("type") | ||
if typ: | ||
signode += sphinx.addnodes.desc_sig_punctuation("", " : ") | ||
signode += sphinx.domains.python._parse_annotation(typ, self.env) | ||
|
||
value = self.options.get("value") | ||
if value: | ||
signode += sphinx.addnodes.desc_sig_punctuation("", " = ") | ||
signode += docutils.nodes.literal( | ||
text=value, classes=["code", "python"], language="python" | ||
) | ||
return result | ||
|
||
directive_cls.handle_signature = handle_signature # type: ignore | ||
|
||
|
||
_monkey_patch_pyattribute_handle_signature(sphinx.domains.python.PyAttribute) | ||
_monkey_patch_pyattribute_handle_signature(sphinx.domains.python.PyVariable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sphinx.application | ||
|
||
from . import annotation_style | ||
from . import object_ids | ||
from . import synopses | ||
from . import parameter_objects | ||
from . import style_default_values_as_code | ||
from . import subscript_methods | ||
from . import attribute_style | ||
from . import napoleon_admonition_classes | ||
from . import strip_property_prefix | ||
from . import section_titles | ||
from . import autodoc_property_type | ||
from . import type_annotation_transforms | ||
from . import strip_self_and_return_type_annotations | ||
|
||
|
||
def setup(app: sphinx.application.Sphinx): | ||
app.setup_extension(parameter_objects.__name__) | ||
app.setup_extension(strip_property_prefix.__name__) | ||
app.setup_extension(type_annotation_transforms.__name__) | ||
app.setup_extension(strip_self_and_return_type_annotations.__name__) | ||
|
||
return { | ||
"parallel_read_safe": True, | ||
"parallel_write_safe": True, | ||
} |
Oops, something went wrong.