Skip to content

Commit 22dba11

Browse files
committed
Correctly setup extensions
1 parent 4b31b9f commit 22dba11

File tree

5 files changed

+31
-28
lines changed

5 files changed

+31
-28
lines changed

scanpydoc/__init__.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,8 @@ def _setup_sig(fn):
3232
@_setup_sig
3333
def setup(app: Sphinx) -> Dict[str, Any]:
3434
"""Set up all included extensions!"""
35-
from . import (
36-
autosummary_generate_imported,
37-
definition_list_typed_field,
38-
elegant_typehints,
39-
rtd_github_links,
40-
)
41-
42-
autosummary_generate_imported.setup(app)
43-
definition_list_typed_field.setup(app)
44-
elegant_typehints.setup(app)
45-
rtd_github_links.setup(app)
46-
35+
app.setup_extension("scanpydoc.autosummary_generate_imported")
36+
app.setup_extension("scanpydoc.definition_list_typed_field")
37+
app.setup_extension("scanpydoc.elegant_typehints")
38+
app.setup_extension("scanpydoc.rtd_github_links")
4739
return metadata

tests/conftest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414

1515
@pytest.fixture
16-
def app_no_setup(make_app, tmp_path) -> Sphinx:
17-
(tmp_path / "conf.py").write_text("")
18-
return make_app(srcdir=STP(tmp_path))
16+
def make_app_no_setup(make_app, tmp_path) -> Callable[[], Sphinx]:
17+
def make_app_no_setup() -> Sphinx:
18+
(tmp_path / "conf.py").write_text("")
19+
return make_app(srcdir=STP(tmp_path))
20+
21+
return make_app_no_setup
1922

2023

2124
@pytest.fixture

tests/test_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import scanpydoc
66

77

8-
def test_all_get_installed(monkeypatch, app_no_setup):
8+
def test_all_get_installed(monkeypatch, make_app_no_setup):
99
setups_seen = set()
1010
setups_called = {}
1111
for finder, mod_name, _ in pkgutil.walk_packages(
@@ -15,8 +15,9 @@ def test_all_get_installed(monkeypatch, app_no_setup):
1515
setups_seen.add(mod_name)
1616
monkeypatch.setattr(mod, "setup", partial(setups_called.__setitem__, mod_name))
1717

18-
scanpydoc.setup(app_no_setup)
18+
app = make_app_no_setup()
19+
app.setup_extension("scanpydoc")
1920

2021
assert setups_called.keys() == setups_seen
2122
for mod_name, app2 in setups_called.items():
22-
assert app_no_setup is app2
23+
assert app is app2

tests/test_definition_list_typed_field.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import pytest
22
from sphinx.application import Sphinx
33
from sphinx.builders.html import StandaloneHTMLBuilder
4-
from sphinx.writers.html import HTMLTranslator, HTMLWriter
4+
from sphinx.writers.html import HTMLTranslator
55
from sphinx.writers.html5 import HTML5Translator
66

7-
from scanpydoc import definition_list_typed_field
8-
97

108
@pytest.fixture
11-
def app(app_no_setup) -> Sphinx:
12-
definition_list_typed_field.setup(app_no_setup)
13-
return app_no_setup
9+
def app(make_app_no_setup) -> Sphinx:
10+
app = make_app_no_setup()
11+
app.setup_extension("scanpydoc.definition_list_typed_field")
12+
return app
1413

1514

1615
# Avoid :class: to not get pending_xref. TODO: fix
@@ -31,6 +30,13 @@ def app(app_no_setup) -> Sphinx:
3130
"""
3231

3332

33+
def test_apps_separate(app, make_app_no_setup):
34+
app_no_setup = make_app_no_setup()
35+
assert app is not make_app_no_setup
36+
assert "scanpydoc.definition_list_typed_field" in app.extensions
37+
assert "scanpydoc.definition_list_typed_field" not in app_no_setup.extensions
38+
39+
3440
@pytest.mark.parametrize("code,n", [(params_code, 2), (params_code_single, 1)])
3541
def test_convert_params(app, parse, code, n):
3642
# the directive class is PyModuleLevel → PyObject → ObjectDescription
@@ -41,6 +47,7 @@ def test_convert_params(app, parse, code, n):
4147
# )
4248

4349
doc = parse(app, code)
50+
assert doc[1].tagname == "desc"
4451
assert doc[1]["desctype"] == "function"
4552
assert doc[1][1].tagname == "desc_content"
4653
assert doc[1][1][0].tagname == "field_list"

tests/test_elegant_typehints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import pytest
44
from sphinx.application import Sphinx
55

6-
from scanpydoc import elegant_typehints
76
from scanpydoc.elegant_typehints import format_annotation, _format_terse, _format_full
87

98

109
@pytest.fixture
11-
def app(app_no_setup) -> Sphinx:
12-
elegant_typehints.setup(app_no_setup)
13-
return app_no_setup
10+
def app(make_app_no_setup) -> Sphinx:
11+
app = make_app_no_setup()
12+
app.setup_extension("scanpydoc.elegant_typehints")
13+
return app
1414

1515

1616
def test_default(app):

0 commit comments

Comments
 (0)