Skip to content

Commit ab1ff4d

Browse files
authored
FEAT: generate API for multiple packages (#12)
* DX: activate VSCode multi-file diff editor https://code.visualstudio.com/updates/v1_85\#_multifile-diff-editor * MAINT: autoupdate pre-commit hooks
1 parent e7e384a commit ab1ff4d

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
- id: blacken-docs
4646

4747
- repo: https://github.com/ComPWA/repo-maintenance
48-
rev: 0.1.7
48+
rev: 0.1.9
4949
hooks:
5050
- id: check-dev-files
5151
args:
@@ -56,7 +56,7 @@ repos:
5656
- --repo-title=sphinx-api-relink
5757

5858
- repo: https://github.com/streetsidesoftware/cspell-cli
59-
rev: v8.0.0
59+
rev: v8.1.1
6060
hooks:
6161
- id: cspell
6262

@@ -81,17 +81,17 @@ repos:
8181
- python
8282

8383
- repo: https://github.com/pre-commit/mirrors-prettier
84-
rev: v4.0.0-alpha.3
84+
rev: v4.0.0-alpha.3-1
8585
hooks:
8686
- id: prettier
8787

8888
- repo: https://github.com/ComPWA/mirrors-pyright
89-
rev: v1.1.338
89+
rev: v1.1.339
9090
hooks:
9191
- id: pyright
9292

9393
- repo: https://github.com/astral-sh/ruff-pre-commit
94-
rev: v0.1.6
94+
rev: v0.1.7
9595
hooks:
9696
- id: ruff
9797
args: [--fix]

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"git.rebaseWhenSync": true,
4646
"github-actions.workflows.pinned.refresh.enabled": true,
4747
"github-actions.workflows.pinned.workflows": [".github/workflows/ci.yml"],
48+
"multiDiffEditor.experimental.enabled": true,
4849
"mypy-type-checker.args": ["--config-file=${workspaceFolder}/pyproject.toml"],
4950
"mypy-type-checker.importStrategy": "fromEnvironment",
5051
"python.analysis.autoImportCompletions": false,

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ To generate the API for [`sphinx.ext.autodoc`](https://www.sphinx-doc.org/en/mas
6565
generate_apidoc_package_path = "../src/my_package" # relative to conf.py
6666
```
6767

68+
Multiple packages can be listed as well:
69+
70+
```python
71+
generate_apidoc_package_path = [
72+
"../src/package1",
73+
"../src/package2",
74+
]
75+
```
76+
6877
The API is generated with the same style used by the ComPWA repositories (see e.g. [ampform.rtfd.io/en/stable/api/ampform.html](https://ampform.readthedocs.io/en/stable/api/ampform.html)). To use the default template, set:
6978

7079
```python

src/sphinx_api_relink/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,23 @@ def set_linkcode_resolve(app: Sphinx, _: BuildEnvironment) -> None:
4646

4747
def generate_apidoc(app: Sphinx, _: BuildEnvironment) -> None:
4848
config_key = "generate_apidoc_package_path"
49-
package_path: str | None = getattr(app.config, config_key, None)
49+
package_path: list[str] | str | None = getattr(app.config, config_key, None)
5050
if package_path is None:
5151
return
52-
abs_package_path = Path(app.srcdir) / package_path
5352
apidoc_dir = Path(app.srcdir) / app.config.generate_apidoc_directory
54-
_run_sphinx_apidoc(
55-
abs_package_path,
56-
apidoc_dir,
57-
excludes=app.config.generate_apidoc_excludes,
58-
use_compwa_template=app.config.generate_apidoc_use_compwa_template,
59-
)
53+
shutil.rmtree(apidoc_dir, ignore_errors=True)
54+
if isinstance(package_path, str):
55+
package_dirs = [package_path]
56+
else:
57+
package_dirs = package_path
58+
for rel_dir in package_dirs:
59+
abs_package_path = Path(app.srcdir) / rel_dir
60+
_run_sphinx_apidoc(
61+
abs_package_path,
62+
apidoc_dir,
63+
excludes=app.config.generate_apidoc_excludes,
64+
use_compwa_template=app.config.generate_apidoc_use_compwa_template,
65+
)
6066

6167

6268
def _run_sphinx_apidoc(
@@ -68,7 +74,6 @@ def _run_sphinx_apidoc(
6874
if not package_path.exists():
6975
msg = f"Package under {package_path} does not exist"
7076
raise FileNotFoundError(msg)
71-
shutil.rmtree(apidoc_dir, ignore_errors=True)
7277
args: list[str] = [str(package_path)]
7378
if excludes is None:
7479
excludes = []

0 commit comments

Comments
 (0)