Skip to content

Commit 396625b

Browse files
authored
Fix coverage (#114)
1 parent f905c9d commit 396625b

21 files changed

+418
-254
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ concurrency:
1414

1515
env:
1616
PIP_ROOT_USER_ACTION: ignore
17-
COLUMNS: 200
17+
COLUMNS: "200"
18+
FORCE_COLOR: "1"
1819

1920
jobs:
2021
build:

codecov.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: 100%
6+
if_not_found: failure

docs/_templates/autosummary/base.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/_templates/autosummary/module.rst

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/index.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ Included extensions
1010
.. autosummary::
1111
:toctree: .
1212

13-
autosummary_generate_imported
1413
definition_list_typed_field
1514
elegant_typehints
1615
rtd_github_links
1716
theme
17+
18+
.. hidden deprecated extension(s):
19+
20+
.. toctree::
21+
:hidden:
22+
23+
scanpydoc.autosummary_generate_imported
24+
25+
..
26+
.. autosummary::
27+
:toctree: .
28+
29+
autosummary_generate_imported

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ strict = true
7676
length-sort = true
7777
lines-after-imports = 2
7878
known-first-party = ['scanpydoc']
79+
required-imports = ["from __future__ import annotations"]
7980

8081
[tool.mypy]
8182
strict = true
8283
explicit_package_bases = true
84+
disallow_untyped_defs = false # handled by Ruff
8385
mypy_path = ['$MYPY_CONFIG_FILE_DIR/src']
8486

8587
[tool.hatch.version]
@@ -103,6 +105,7 @@ features = ['test', 'typehints']
103105
run = 'pytest -vv {args}'
104106
cov = [
105107
'coverage run -m pytest -vv {args}',
108+
'coverage xml',
106109
'coverage-rich report',
107110
]
108111

@@ -111,6 +114,10 @@ addopts = [
111114
'--import-mode=importlib',
112115
'-psphinx.testing.fixtures',
113116
]
117+
filterwarnings = [
118+
'error',
119+
'ignore:The frontend.Option:DeprecationWarning',
120+
]
114121

115122
[tool.coverage.run]
116123
source_pkgs = ["scanpydoc"]
@@ -122,8 +129,6 @@ exclude_lines = [
122129
"if __name__ == .__main__.:",
123130
"if TYPE_CHECKING:",
124131
]
125-
[tool.coverage_rich]
126-
fail-under = 70
127132

128133
[build-system]
129134
requires = ['hatchling', 'hatch-vcs']

src/scanpydoc/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def _setup_sig(fn: C) -> C:
3737

3838
@_setup_sig
3939
def setup(app: Sphinx) -> dict[str, Any]:
40-
"""Set up all included extensions!."""
41-
app.setup_extension("scanpydoc.autosummary_generate_imported")
40+
"""Set up all included extensions!""" # noqa: D400
4241
app.setup_extension("scanpydoc.definition_list_typed_field")
4342
app.setup_extension("scanpydoc.elegant_typehints")
4443
app.setup_extension("scanpydoc.rtd_github_links")
Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,33 @@
1-
"""Generate autosummary docs for imported members.
1+
"""Generate autosummary for imported members.
22
3-
This extension patches the :mod:`~sphinx.ext.autosummary` extension
4-
to generate docs for imported members.
5-
It needs to be loaded and :confval:`autosummary_generate` needs to be set to ``True``.
3+
.. deprecated:: 0.11.0
64
7-
This will hopefully be superseded by the ability to add ``:imported-members:``
8-
to `autosummary templates`_ in the future. See `Sphinx issue 4372`_.
9-
10-
.. _autosummary templates: http://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html#customizing-templates
11-
.. _Sphinx issue 4372: https://github.com/sphinx-doc/sphinx/issues/4372
5+
Use ``autosummary_imported_members = True`` instead.
126
"""
7+
138
from __future__ import annotations
149

15-
import logging
16-
from typing import TYPE_CHECKING, Any
17-
from pathlib import Path
10+
import sys
11+
from typing import TYPE_CHECKING
1812

19-
from sphinx.ext import autosummary
20-
from sphinx.ext.autosummary.generate import generate_autosummary_docs
2113

22-
from . import metadata, _setup_sig
14+
if sys.version_info >= (3, 11):
15+
from typing import Never
16+
else: # pragma: no cover
17+
from typing import NoReturn as Never
18+
19+
from . import _setup_sig
2320

2421

2522
if TYPE_CHECKING:
2623
from sphinx.application import Sphinx
2724

2825

29-
logger = logging.getLogger(__name__)
30-
31-
32-
def _generate_stubs(app: Sphinx) -> None:
33-
gen_files = app.config.autosummary_generate
34-
35-
if gen_files and not hasattr(gen_files, "__len__"):
36-
env = app.builder.env
37-
gen_files = [
38-
env.doc2path(x, base=False)
39-
for x in env.found_docs
40-
if Path(env.doc2path(x)).is_file()
41-
]
42-
if not gen_files:
43-
return
44-
45-
ext = app.config.source_suffix
46-
gen_files = [
47-
genfile + ("" if genfile.endswith(tuple(ext)) else ext[0])
48-
for genfile in gen_files
49-
]
50-
51-
suffix = autosummary.get_rst_suffix(app)
52-
if suffix is None:
53-
return
54-
55-
generate_autosummary_docs(
56-
gen_files,
57-
suffix=suffix,
58-
base_path=app.srcdir,
59-
imported_members=True,
60-
app=app,
61-
)
62-
63-
6426
@_setup_sig
65-
def setup(_app: Sphinx) -> dict[str, Any]:
66-
"""Patch autosummary to generate docs for imported members as well."""
67-
autosummary.process_generate_options = _generate_stubs
68-
69-
return metadata
27+
def setup(_app: Sphinx) -> Never: # pragma: no cover
28+
"""Throws an :exc:`ImportError`."""
29+
msg = (
30+
"Please use `autosummary_imported_members = True` "
31+
f"instead of the {__name__} Sphinx extension."
32+
)
33+
raise ImportError(msg)

src/scanpydoc/definition_list_typed_field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from __future__ import annotations
99

10-
from typing import TYPE_CHECKING, cast
10+
from typing import TYPE_CHECKING
1111

1212
from sphinx import addnodes
1313
from docutils import nodes
@@ -60,11 +60,11 @@ def handle_item(
6060

6161
field_type = types.pop(fieldarg, None)
6262
if field_type is not None:
63+
# convert `param : SomeClass` into reference
6364
if len(field_type) == 1 and isinstance(field_type[0], nodes.Text):
64-
[text_node] = cast(tuple[nodes.Text], field_type)
6565
classifier_content = make_refs(
6666
self.typerolename,
67-
text_node.astext(),
67+
field_type[0].astext(),
6868
addnodes.literal_emphasis,
6969
)
7070
else:

src/scanpydoc/elegant_typehints/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@ def x() -> Tuple[int, float]:
4949

5050
from typing import TYPE_CHECKING, Any
5151
from pathlib import Path
52-
from functools import partial
5352
from collections import ChainMap
5453
from dataclasses import dataclass
5554

5655
from sphinx.ext.autodoc import ClassDocumenter
57-
from docutils.parsers.rst import roles
5856

5957
from scanpydoc import metadata, _setup_sig
6058

@@ -113,14 +111,9 @@ def setup(app: Sphinx) -> dict[str, Any]:
113111
app.add_config_value("annotate_defaults", default=True, rebuild="html")
114112
app.connect("config-inited", _init_vars)
115113

116-
from ._formatting import _role_annot, typehints_formatter
114+
from ._formatting import typehints_formatter
117115

118116
app.config["typehints_formatter"] = PickleableCallable(typehints_formatter)
119-
for name in ["annotation-terse", "annotation-full"]:
120-
roles.register_canonical_role(
121-
name,
122-
partial(_role_annot, additional_classes=name.split("-")),
123-
)
124117

125118
from ._autodoc_patch import dir_head_adder
126119

0 commit comments

Comments
 (0)