Skip to content

Commit 81cccdf

Browse files
authored
Merge pull request #359 from machow/fix-griffe-compat
fix: support griffe v1, and backwards compat to v0.37.0
2 parents baa6c57 + e3cbdf4 commit 81cccdf

File tree

18 files changed

+101
-71
lines changed

18 files changed

+101
-71
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
# Checks based on python versions ---
19-
python-version: ['3.9', '3.10']
19+
python-version: ["3.9", "3.10"]
2020
requirements: [""]
2121

2222
include:
@@ -43,7 +43,11 @@ jobs:
4343
REQUIREMENTS: ${{ matrix.requirements }}
4444
- name: Run tests
4545
run: |
46-
pytest
46+
pytest --cov
47+
- name: Upload results to Codecov
48+
uses: codecov/codecov-action@v4
49+
with:
50+
token: ${{ secrets.CODECOV_TOKEN }}
4751

4852
pre-commit:
4953
name: "pre-commit checks"
@@ -55,8 +59,8 @@ jobs:
5559
python-version: "${{ matrix.python-version }}"
5660
- name: Install dev dependencies
5761
run: |
58-
python -m pip install --upgrade pip
59-
python -m pip install ".[dev]"
62+
python -m pip install --upgrade pip
63+
python -m pip install ".[dev]"
6064
- uses: pre-commit/[email protected]
6165

6266
release-pypi:
@@ -94,13 +98,10 @@ jobs:
9498
python -m pip install shiny shinylive
9599
python -m pip install --no-deps dascore==0.0.8
96100
- uses: quarto-dev/quarto-actions/setup@v2
97-
with:
98-
version: "1.2.475"
99101
- name: Build docs
100102
run: |
101103
make docs-build
102104
# push to netlify -------------------------------------------------------
103-
104105
# set release name ----
105106

106107
- name: Configure pull release name
@@ -115,7 +116,6 @@ jobs:
115116
# use branch name, but replace slashes. E.g. feat/a -> feat-a
116117
echo "RELEASE_NAME=${GITHUB_REF_NAME/\//-}" >> $GITHUB_ENV
117118
# deploy ----
118-
119119
- name: Create Github Deployment
120120
uses: bobheadxi/[email protected]
121121
id: deployment
@@ -125,7 +125,7 @@ jobs:
125125
env: ${{ env.RELEASE_NAME }}
126126
ref: ${{ github.head_ref }}
127127
transient: true
128-
logs: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
128+
logs: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
129129

130130
- name: Netlify docs preview
131131
run: |
@@ -149,8 +149,8 @@ jobs:
149149
token: ${{ secrets.GITHUB_TOKEN }}
150150
status: ${{ job.status }}
151151
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
152-
env_url: 'https://${{ steps.deployment.outputs.env }}--quartodoc.netlify.app'
153-
logs: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
152+
env_url: "https://${{ steps.deployment.outputs.env }}--quartodoc.netlify.app"
153+
logs: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
154154
- uses: peaceiris/actions-gh-pages@v3
155155
if: github.event_name == 'release'
156156
with:

case_studies/parsing.qmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ res["objects"][0]["children"]["some_package"]["children"]
5555
## Running griffe
5656

5757
```{python}
58-
from griffe.loader import GriffeLoader
59-
from griffe.docstrings.parsers import Parser, parse
58+
from griffe import GriffeLoader
59+
from griffe import Parser, parse
6060
61-
griffe = GriffeLoader()
61+
loader = GriffeLoader()
6262
63-
sb2 = griffe.load_module("some_package")
63+
sb2 = loader.load("some_package")
6464
6565
parse(sb2.functions["some_function"].docstring, Parser.numpy)
6666
```

docs/get-started/basic-content.qmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ By default, all attributes and functions (including methods on a class) are pres
6666
There are four styles for presenting child members:
6767

6868
```{python}
69-
#| echo: false
70-
#| output: asis
69+
# | echo: false
70+
# | output: asis
7171
72-
# print out the attributes table of ChoicesChildren
72+
# print out the attributes table of ChoicesChildren
7373
# this is overkill, but maybe a nice case of dogfooding
7474
from quartodoc import get_object, MdRenderer
7575
from quartodoc.builder.utils import extract_type
76-
from griffe.docstrings.dataclasses import DocstringSectionAttributes
76+
from griffe import DocstringSectionAttributes
7777
7878
renderer = MdRenderer()
7979
choices = get_object("quartodoc.layout.ChoicesChildren")
@@ -420,12 +420,12 @@ Below is a summary of all the options that can be applied to individual content
420420

421421

422422
```{python}
423-
#| echo: false
424-
#| output: asis
423+
# | echo: false
424+
# | output: asis
425425
426426
from quartodoc import get_object, MdRenderer, Auto
427427
from quartodoc.builder.utils import extract_type
428-
from griffe.docstrings.dataclasses import DocstringSectionAttributes
428+
from griffe import DocstringSectionAttributes
429429
430430
renderer = MdRenderer()
431431
choices = get_object("quartodoc.Auto")

docs/get-started/dev-renderers.qmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,20 @@ types of objects.
5757
```{python}
5858
from plum import dispatch
5959
60-
import griffe.dataclasses as dc
61-
import griffe.docstrings.dataclasses as ds
60+
from griffe import Alias, Object, Docstring
6261
6362
6463
@dispatch
6564
def render(el: object):
6665
print(f"Default rendering: {type(el)}")
6766
67+
6868
@dispatch
69-
def render(el: dc.Alias):
69+
def render(el: Alias):
7070
print("Alias rendering")
7171
render(el.parameters)
7272
73+
7374
@dispatch
7475
def render(el: list):
7576
print("List rendering")
@@ -85,8 +86,7 @@ quartodoc uses tree visitors to render parsed docstrings to formats like markdow
8586
Tree visitors define how each type of object in the parse tree should be handled.
8687

8788
```{python}
88-
import griffe.dataclasses as dc
89-
import griffe.docstrings.dataclasses as ds
89+
from griffe import Alias, Object, Docstring
9090
9191
from quartodoc import get_object
9292
from plum import dispatch
@@ -102,17 +102,17 @@ class SomeRenderer:
102102
raise NotImplementedError(f"Unsupported type: {type(el)}")
103103
104104
@dispatch
105-
def render(self, el: Union[dc.Alias, dc.Object]):
105+
def render(self, el: Union[Alias, Object]):
106106
header = "#" * self.header_level
107107
str_header = f"{header} {el.name}"
108108
str_params = f"N PARAMETERS: {len(el.parameters)}"
109109
str_sections = "SECTIONS: " + self.render(el.docstring)
110-
110+
111111
# return something pretty
112112
return "\n".join([str_header, str_params, str_sections])
113113
114114
@dispatch
115-
def render(self, el: dc.Docstring):
115+
def render(self, el: Docstring):
116116
return f"A docstring with {len(el.parsed)} pieces"
117117
118118

docs/get-started/extending.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Then, create the file `reference/index.qmd` to have the form:
4040
Some custom content.
4141
4242
43-
{{< include /reference/_api_index.qmd >}}
43+
{{{< include /reference/_api_index.qmd >}}}
4444
4545
4646
More content stuff.

docs/get-started/sidebar.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ Here is what the sidebar for the [quartodoc reference page](/api) looks like:
2727

2828
<div class="sourceCode">
2929
<pre class="sourceCode yaml"><code class="sourceCode yaml">
30-
{{< include /api/_sidebar.yml >}}
30+
{{{< include /api/_sidebar.yml >}}}
3131
</code></pre>
3232
</div>

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ ci = "https://github.com/machow/quartodoc/actions"
5353

5454

5555
[project.optional-dependencies]
56-
dev = ["pytest<8.0.0", "jupyterlab", "jupytext", "syrupy", "pre-commit"]
56+
dev = [
57+
"pytest<8.0.0",
58+
"pytest-cov",
59+
"jupyterlab",
60+
"jupytext",
61+
"syrupy",
62+
"pre-commit"
63+
]
5764

5865
[project.scripts]
5966
quartodoc = "quartodoc.__main__:cli"

quartodoc/_griffe_compat.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# flake8: noqa
2+
3+
try:
4+
from griffe import GriffeLoader
5+
from griffe import ModulesCollection, LinesCollection
6+
7+
import _griffe.models as dataclasses
8+
import _griffe.docstrings.models as docstrings
9+
import _griffe.expressions as expressions
10+
11+
from griffe import Parser, parse, parse_numpy
12+
from griffe import AliasResolutionError
13+
except ImportError:
14+
from griffe.loader import GriffeLoader
15+
from griffe.collections import ModulesCollection, LinesCollection
16+
17+
import griffe.dataclasses as dataclasses
18+
import griffe.docstrings.dataclasses as docstrings
19+
import griffe.expressions as expressions
20+
21+
from griffe.docstrings.parsers import Parser, parse
22+
from griffe.exceptions import AliasResolutionError

quartodoc/ast.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import warnings
44

5+
from ._griffe_compat import docstrings as ds
6+
from ._griffe_compat import dataclasses as dc
7+
58
from enum import Enum
69
from dataclasses import dataclass
7-
from griffe.docstrings import dataclasses as ds
8-
from griffe import dataclasses as dc
910
from plum import dispatch
1011
from typing import Type, Union
1112

quartodoc/autosummary.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import warnings
66
import yaml
77

8+
from ._griffe_compat import GriffeLoader, ModulesCollection, LinesCollection
9+
from ._griffe_compat import dataclasses as dc
10+
from ._griffe_compat import Parser, parse
11+
812
from fnmatch import fnmatchcase
9-
from griffe.loader import GriffeLoader
10-
from griffe.collections import ModulesCollection, LinesCollection
11-
from griffe.dataclasses import Alias
12-
from griffe.docstrings.parsers import Parser, parse
13-
from griffe.docstrings import dataclasses as ds # noqa
14-
from griffe import dataclasses as dc
1513
from plum import dispatch # noqa
1614
from pathlib import Path
1715
from types import ModuleType
@@ -37,7 +35,7 @@
3735

3836
def parse_function(module: str, func_name: str):
3937
griffe = GriffeLoader()
40-
mod = griffe.load_module(module)
38+
mod = griffe.load(module)
4139

4240
f_data = mod.functions[func_name]
4341

@@ -66,7 +64,7 @@ def get_function(module: str, func_name: str, parser: str = "numpy") -> dc.Objec
6664
griffe = GriffeLoader(
6765
docstring_parser=Parser(parser), docstring_options=get_parser_defaults(parser)
6866
)
69-
mod = griffe.load_module(module)
67+
mod = griffe.load(module)
7068

7169
f_data = mod.functions[func_name]
7270

@@ -138,7 +136,7 @@ def get_object(
138136
# note that it is critical for performance that we only do this when necessary.
139137
root_mod = module.split(".", 1)[0]
140138
if root_mod not in loader.modules_collection:
141-
loader.load_module(module)
139+
loader.load(module)
142140

143141
# griffe uses only periods for the path
144142
griffe_path = f"{module}.{object_path}" if object_path else module
@@ -164,10 +162,10 @@ def get_object(
164162
# Alias objects can refer to objects imported from other modules.
165163
# in this case, we need to import the target's module in order to resolve
166164
# the alias
167-
if isinstance(f_data, Alias) and load_aliases:
165+
if isinstance(f_data, dc.Alias) and load_aliases:
168166
target_mod = f_data.target_path.split(".")[0]
169167
if target_mod != module:
170-
loader.load_module(target_mod)
168+
loader.load(target_mod)
171169

172170
return f_data
173171

0 commit comments

Comments
 (0)