Skip to content

Commit 73ac9a2

Browse files
authored
resolve the import_cycle warning (#143)
* remove obsolete check * install other deps before `sphinx` * pin `sphinx_rtd_theme` to <3 if we're testing `sphinx=5` * install `imghdr` for python 3.13 * skip `sphinx=5.3` on `python=3.13` * change the simple example module to a package * adapt the example docs * suppress the import cycle warning * add the forgotten `__init__.py` * don't use `sphinx>=8.2` for now (that appears to break backwards compatibility with other extensions)
1 parent 65c2599 commit 73ac9a2

File tree

8 files changed

+53
-40
lines changed

8 files changed

+53
-40
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ jobs:
1717
python-version: ["3.9", "3.12", "3.13"]
1818
sphinx-version: ["5.3", "6.2", "7.3", "7.4", "8.0", "8.1"]
1919
exclude:
20+
# sphinx>=8 requires at least python 3.10
2021
- python-version: "3.9"
2122
sphinx-version: "8.0"
2223
- python-version: "3.9"
2324
sphinx-version: "8.1"
25+
# sphinx<6.2 uses imghdr, which was removed in python 3.13
26+
- python-version: "3.13"
27+
sphinx-version: "5.3"
2428

2529
steps:
2630
- name: checkout the repository
@@ -44,15 +48,15 @@ jobs:
4448
- name: upgrade pip
4549
run: python -m pip install --upgrade pip
4650

51+
- name: install other dependencies
52+
run: python -m pip install -r ci/requirements.txt
53+
4754
- name: install sphinx
4855
run: |
49-
python -m pip install "sphinx==${{matrix.sphinx-version}}"
50-
if [[ "${{matrix.sphinx-version}}" < "4.0" ]]; then
51-
python -m pip install "jinja2<3.1" "docutils<0.18"
56+
if [[ "${{matrix.sphinx-version}}" < "6.0" ]]; then
57+
python -m pip install "sphinx_rtd_theme<3.0"
5258
fi
53-
54-
- name: install other dependencies
55-
run: python -m pip install -r ci/requirements.txt
59+
python -m pip install "sphinx==${{matrix.sphinx-version}}"
5660
5761
- name: install the extension
5862
run: python -m pip install .

docs/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
master_doc = "index"
6969
suffix = ".rst"
7070

71+
# temporarily supress warnings
72+
suppress_warnings = [
73+
# emitted because we're trying to redirect to a absolute import path
74+
"autosummary.import_cycle",
75+
]
7176

7277
# -- Options for HTML output -------------------------------------------------
7378

docs/example/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from example.accessors import Test2Accessor, TestAccessor # noqa: F401
2+
from example.object import Example # noqa: F401

docs/example.py renamed to docs/example/accessors.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
1-
class CachedAccessor:
2-
def __init__(self, name, accessor):
3-
self._name = name
4-
self._accessor = accessor
5-
6-
def __get__(self, obj, cls):
7-
if obj is None:
8-
return self._accessor
9-
10-
accessor_obj = self._accessor(obj)
11-
setattr(obj, self._name, accessor_obj)
12-
13-
return accessor_obj
14-
15-
16-
class Example:
17-
"""test class"""
18-
19-
def __init__(self, data):
20-
self._data = data
21-
22-
23-
def register_accessor(name):
24-
def func(accessor):
25-
setattr(Example, name, CachedAccessor(name, accessor))
26-
27-
return accessor
28-
29-
return func
1+
from example.extensions import CachedAccessor, register_accessor
302

313

324
@register_accessor("test")

docs/example/extensions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from example.object import Example
2+
3+
4+
class CachedAccessor:
5+
def __init__(self, name, accessor):
6+
self._name = name
7+
self._accessor = accessor
8+
9+
def __get__(self, obj, cls):
10+
if obj is None:
11+
return self._accessor
12+
13+
accessor_obj = self._accessor(obj)
14+
setattr(obj, self._name, accessor_obj)
15+
16+
return accessor_obj
17+
18+
19+
def register_accessor(name):
20+
def func(accessor):
21+
setattr(Example, name, CachedAccessor(name, accessor))
22+
23+
return accessor
24+
25+
return func

docs/example/object.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Example:
2+
"""test class"""
3+
4+
def __init__(self, data):
5+
self._data = data

docs/examples.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Examples
1010
========
1111
Consider the accessor class:
1212

13-
.. literalinclude:: example.py
13+
.. literalinclude:: example/accessors.py
1414
:language: python
15-
:lines: 32-68
15+
:lines: 4-40
1616

1717
for a class named :py:class:`Example`:
1818

@@ -58,9 +58,9 @@ becomes:
5858

5959
Methods on nested accessors can be documented, too:
6060

61-
.. literalinclude:: example.py
61+
.. literalinclude:: example/accessors.py
6262
:language: python
63-
:lines: 71-86
63+
:lines: 43-59
6464

6565
and
6666

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
packaging
2-
sphinx>=6
2+
sphinx>=6,<8.2
33
sphinx_rtd_theme

0 commit comments

Comments
 (0)