Skip to content

Commit 4de7672

Browse files
committed
update pdoc doc generation
1 parent b1bf3d2 commit 4de7672

File tree

5 files changed

+87
-14
lines changed

5 files changed

+87
-14
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,8 @@ jobs:
167167
python-version: '3.12'
168168
cache: 'pip'
169169
- run: pip install -e .[dev]
170-
- id: get_version
171-
run: python -c 'import bioimageio.core;print(f"version={bioimageio.core.__version__}")' >> $GITHUB_OUTPUT
172170
- name: Generate developer docs
173-
run: |
174-
pdoc \
175-
--docformat google \
176-
--logo https://bioimage.io/static/img/bioimage-io-logo.svg \
177-
--logo-link https://bioimage.io/ \
178-
--favicon https://bioimage.io/static/img/bioimage-io-icon-small.svg \
179-
--footer-text 'bioimageio.core ${{steps.get_version.outputs.version}}' \
180-
-o ./dist bioimageio.core
171+
run: ./scripts/pdoc/run.sh
181172
- run: cp README.md ./dist/README.md
182173
- name: copy rendered presentations
183174
run: |

pyproject.toml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
[tool.black]
22
line-length = 88
3-
extend_exclude = "^/presentations/"
3+
extend_exclude = "^/presentations/ | ^/scripts/pdoc/original.py | ^/scripts/pdoc/patched.py"
44
target-version = ["py38", "py39", "py310", "py311", "py312"]
5+
preview = true
56

67
[tool.pyright]
7-
exclude = ["**/node_modules", "**/__pycache__", "tests/old_*", "presentations"]
8+
exclude = [
9+
"**/__pycache__",
10+
"**/node_modules",
11+
"presentations",
12+
"scripts/pdoc/original.py",
13+
"scripts/pdoc/patched.py",
14+
"tests/old_*",
15+
]
816
include = ["bioimageio", "scripts", "tests"]
917
pythonPlatform = "All"
10-
pythonVersion = "3.13"
18+
pythonVersion = "3.12"
1119
reportDuplicateImport = "error"
1220
reportImplicitStringConcatenation = "error"
1321
reportIncompatibleMethodOverride = true
@@ -35,8 +43,13 @@ addopts = "--cov=bioimageio --cov-report=xml -n auto --capture=no --doctest-modu
3543

3644
[tool.ruff]
3745
line-length = 88
46+
target-version = "py312"
3847
include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]
39-
exclude = ["presentations"]
48+
exclude = [
49+
"presentations",
50+
"scripts/pdoc/original.py",
51+
"scripts/pdoc/patched.py",
52+
]
4053

4154
[tool.coverage.report]
4255
exclude_also = ["if TYPE_CHECKING:", "assert_never\\("]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pydantic_root=$(python -c "import pydantic;from pathlib import Path;print(Path(pydantic.__file__).parent)")
2+
main=$pydantic_root'/main.py'
3+
original="$(dirname "$0")/original.py"
4+
patched="$(dirname "$0")/patched.py"
5+
6+
if [ -e $original ]
7+
then
8+
echo "found existing $original"
9+
else
10+
cp --verbose $main $original
11+
fi
12+
13+
if [ -e $patched ]
14+
then
15+
echo "found existing $patched"
16+
else
17+
cp --verbose $main $patched
18+
echo "Please update $patched, then press enter to continue"
19+
read
20+
fi
21+
22+
patch_file="$(dirname "$0")/mark_pydantic_attrs_private.patch"
23+
diff -au $original $patched > $patch_file
24+
echo "content of $patch_file:"
25+
cat $patch_file
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--- ./original.py 2024-11-08 15:18:37.493768700 +0100
2+
+++ ./patched.py 2024-11-08 15:13:54.288887700 +0100
3+
@@ -121,14 +121,14 @@
4+
# `GenerateSchema.model_schema` to work for a plain `BaseModel` annotation.
5+
6+
model_config: ClassVar[ConfigDict] = ConfigDict()
7+
- """
8+
+ """@private
9+
Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].
10+
"""
11+
12+
# Because `dict` is in the local namespace of the `BaseModel` class, we use `Dict` for annotations.
13+
# TODO v3 fallback to `dict` when the deprecated `dict` method gets removed.
14+
model_fields: ClassVar[Dict[str, FieldInfo]] = {} # noqa: UP006
15+
- """
16+
+ """@private
17+
Metadata about the fields defined on the model,
18+
mapping of field names to [`FieldInfo`][pydantic.fields.FieldInfo] objects.
19+
20+
@@ -136,7 +136,7 @@
21+
"""
22+
23+
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {} # noqa: UP006
24+
- """A dictionary of computed field names and their corresponding `ComputedFieldInfo` objects."""
25+
+ """@private A dictionary of computed field names and their corresponding `ComputedFieldInfo` objects."""
26+
27+
__class_vars__: ClassVar[set[str]]
28+
"""The names of the class variables defined on the model."""

scripts/pdoc/run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cd "$(dirname "$0")" # cd to folder this script is in
2+
3+
# patch pydantic to hide pydantic attributes that somehow show up in the docs
4+
# (not even as inherited, but as if the documented class itself would define them)
5+
pydantic_main=$(python -c "import pydantic;from pathlib import Path;print(Path(pydantic.__file__).parent / 'main.py')")
6+
7+
patch --verbose --forward -p1 $pydantic_main < mark_pydantic_attrs_private.patch
8+
9+
cd ../.. # cd to repo root
10+
pdoc \
11+
--docformat google \
12+
--logo "https://bioimage.io/static/img/bioimage-io-logo.svg" \
13+
--logo-link "https://bioimage.io/" \
14+
--favicon "https://bioimage.io/static/img/bioimage-io-icon-small.svg" \
15+
--footer-text "bioimageio.core $(python -c 'import bioimageio.core;print(bioimageio.core.__version__)')" \
16+
-o ./dist bioimageio.core bioimageio.spec # generate bioimageio.spec as well for references

0 commit comments

Comments
 (0)