Skip to content

Commit 3b34042

Browse files
authored
Merge branch 'main' into feat-subtitles
2 parents e9cb90a + bb33500 commit 3b34042

23 files changed

+796
-94
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@ on:
99
types: [published]
1010

1111
jobs:
12-
run-if:
13-
name: "Run If"
14-
runs-on: ubuntu-latest
15-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
16-
steps:
17-
- run: |
18-
echo "Running CI"
1912
test:
2013
name: "Test"
21-
needs: ["run-if"]
2214
runs-on: ubuntu-latest
2315
strategy:
2416
fail-fast: false

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exclude: ".*\\.(csv)|(md)|(json)"
1+
exclude: ".*\\.(csv)|(md)|(json)|(ambr)"
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: v2.4.0

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ examples/%/_site: examples/%/_quarto.yml
2121
cd examples/$* \
2222
&& quarto add --no-prompt ../.. \
2323
&& quarto add --no-prompt quarto-ext/shinylive
24-
cd examples/$* && quartodoc build _quarto.yml --verbose
24+
cd examples/$* && quartodoc build --config _quarto.yml --verbose
2525
cd examples/$* && quartodoc interlinks
2626
quarto render $(dir $<)
2727

@@ -30,7 +30,7 @@ docs/examples/%: examples/%/_site
3030
rm -rf docs/examples/$*
3131
cp -rv $< $@
3232

33-
docs-build-examples: docs/examples/single-page docs/examples/pkgdown
33+
docs-build-examples: docs/examples/single-page docs/examples/pkgdown docs/examples/auto-package
3434

3535
docs-build: docs-build-examples
3636
cd docs && quarto add --no-prompt ..

docs/_quarto.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project:
44
resources:
55
- examples/single-page
66
- examples/pkgdown
7+
- examples/auto-package
78

89
metadata-files:
910
- api/_sidebar.yml

docs/get-started/basic-building.qmd

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,46 @@ jupyter:
99

1010
**tl;dr**: Once you've configured quartodoc in your `_quarto.yml` file, use the following commands to build and preview a documentation site.
1111

12+
## `quartodoc build`: Create doc files
13+
14+
Automatically generate `.qmd` files with reference api documentation. This is written by default to the reference/ folder in your quarto project.
15+
1216
```bash
13-
# Create the documentation files. These are written
14-
# by default to the reference/ folder in your docs.
15-
quartodoc build --verbose
17+
quartodoc build
18+
```
1619

17-
# Create optional inventory files, which allow you to
18-
# link to API doc pages within and across documentation
19-
# sites. These are put in the _inv folder in your docs.
20-
quartodoc interlinks
20+
If you are iterating on your docstrings while previewing your site with `quarto preview`, you will likely want to rebuild the doc pages automatically when docstrings change. The `--watch` flag does exactly this.
2121

22-
# Preview the documentation site.
23-
# Use quarto render to generate the final site.
24-
quarto preview
22+
```bash
23+
quartodoc build --watch
2524
```
2625

27-
## Rebuilding doc pages
26+
For more information on the `quartodoc build` command, use `--help` in the terminal like so:
2827

29-
While using `quarto preview`, you can preview updates to your docstrings by regenerating their documentation pages:
28+
```bash
29+
quartodoc build --help
30+
```
31+
32+
```{python}
33+
#|echo: false
34+
!quartodoc build --help
35+
```
3036

37+
38+
## `quartodoc interlinks`: Create inventory files
39+
40+
Inventory files facilitate linking to API doc pages within and across `quartodoc` sites. This is optional.
41+
3142
```bash
32-
quartodoc build --verbose
43+
quartodoc interlinks
44+
```
45+
46+
## `quarto preview`: Preview the site
47+
48+
Use `quarto` to preview the site:
49+
50+
```bash
51+
quarto preview
3352
```
3453

3554
## Speeding up preview

docs/get-started/docstring-examples.qmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ Below is an example including each.
4848
```
4949
```
5050

51+
Note that different syntaxes are handled differently:
52+
53+
* doctest and markdown syntax: rendered without executing.
54+
* quarto syntax: executed by quarto when you run commands like `quarto render`.
55+
56+
See the quarto documentation on [code blocks](https://quarto.org/docs/computations/python.html#code-blocks) for more detail.
57+
5158

5259
## Examples, etc..: the "s" matters
5360

docs/get-started/overview.qmd

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,18 @@ quarto preview
8585

8686
## Rebuilding site
8787

88-
As mentioned in the previous section, you can preview your quartodoc site using these commands:
88+
You can preview your `quartodoc` site using the following commands:
89+
90+
First, watch for changes to the library you are documenting so that your docs will automatically re-generate:
8991

9092
```bash
91-
quartodoc build
92-
quarto preview
93+
quartodoc build --watch
9394
```
9495

95-
In order to rebuild your API documentation pages during a quarto preview, re-run
96-
the quartodoc build command:
96+
Second, preview your site:
9797

9898
```bash
99-
# with quarto preview running, you only need to re-run quartodoc build,
100-
# which will re-create the pages of your API documentation.
101-
quartodoc build
99+
quarto preview
102100
```
103101

104102
## Looking up objects

examples/auto-package/_quarto.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
project:
2+
type: website
3+
resources:
4+
- objects.json
5+
6+
website:
7+
title: pkgdown example
8+
navbar:
9+
left:
10+
- href: https://machow.github.io/quartodoc/
11+
text: quartodoc home
12+
- file: reference/index.qmd
13+
text: "Reference"
14+
right:
15+
- icon: github
16+
href: https://github.com/machow/quartodoc/tree/main/examples/pkgdown
17+
18+
format:
19+
html:
20+
toc: true
21+
22+
quartodoc:
23+
style: pkgdown
24+
dir: reference
25+
package: quartodoc

quartodoc/__init__.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1+
"""quartodoc is a package for building delightful python API documentation.
2+
"""
3+
14
# flake8: noqa
25

3-
from .autosummary import (
4-
get_function,
5-
get_object,
6-
Builder,
7-
BuilderPkgdown,
8-
BuilderSinglePage,
9-
)
6+
from .autosummary import get_function, get_object, Builder
107
from .renderers import MdRenderer
118
from .inventory import convert_inventory, create_inventory
129
from .ast import preview
1310
from .builder.blueprint import blueprint
1411
from .builder.collect import collect
1512
from .layout import Auto
13+
14+
__all__ = (
15+
"Auto",
16+
"blueprint",
17+
"collect",
18+
"convert_inventory",
19+
"create_inventory",
20+
"get_object",
21+
"preview",
22+
"Builder",
23+
"BuilderPkgdown",
24+
"BuilderSinglePage",
25+
"MdRenderer",
26+
)

quartodoc/__main__.py

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
import click
22
import contextlib
33
import os
4+
import time
45
import sphobjinv as soi
56
import yaml
6-
7+
import importlib
78
from pathlib import Path
8-
9+
from watchdog.observers import Observer
10+
from functools import partial
11+
from watchdog.events import FileSystemEventHandler
912
from quartodoc import Builder, convert_inventory
1013

14+
def get_package_path(package_name):
15+
"""
16+
Get the path to a package installed in the current environment.
17+
"""
18+
try:
19+
lib = importlib.import_module(package_name)
20+
return lib.__path__[0]
21+
except ModuleNotFoundError:
22+
raise ModuleNotFoundError(f"Package {package_name} not found. Please install it in your environment.")
23+
24+
class FileChangeHandler(FileSystemEventHandler):
25+
"""
26+
A handler for file changes.
27+
"""
28+
def __init__(self, callback):
29+
self.callback = callback
30+
31+
@classmethod
32+
def print_event(cls, event):
33+
print(f'Rebuilding docs. Detected: {event.event_type} path : {event.src_path}')
34+
35+
def on_modified(self, event):
36+
self.print_event(event)
37+
self.callback()
38+
39+
def on_created(self, event):
40+
self.print_event(event)
41+
self.callback()
1142

1243
def _enable_logs():
1344
import logging
@@ -40,24 +71,44 @@ def cli():
4071
pass
4172

4273

74+
75+
76+
4377
@click.command()
44-
@click.argument("config", default="_quarto.yml")
45-
@click.option("--filter", nargs=1, default="*")
46-
@click.option("--dry-run", is_flag=True, default=False)
47-
@click.option("--verbose", is_flag=True, default=False)
48-
def build(config, filter, dry_run, verbose):
78+
@click.option("--config", default="_quarto.yml", help="Change the path to the configuration file. The default is `./_quarto.yml`")
79+
@click.option("--filter", nargs=1, default="*", help="Specify the filter to select specific files. The default is '*' which selects all files.")
80+
@click.option("--dry-run", is_flag=True, default=False, help="If set, prevents new documents from being generated.")
81+
@click.option("--watch", is_flag=True, default=False, help="If set, the command will keep running and watch for changes in the package directory.")
82+
@click.option("--verbose", is_flag=True, default=False, help="Enable verbose logging.")
83+
def build(config, filter, dry_run, watch, verbose):
84+
"""
85+
Generate API docs based on the given configuration file (`./_quarto.yml` by default).
86+
"""
4987
if verbose:
5088
_enable_logs()
5189

5290
builder = Builder.from_quarto_config(config)
91+
doc_build = partial(builder.build, filter=filter)
5392

5493
if dry_run:
55-
# click.echo(builder.render_index())
5694
pass
5795
else:
5896
with chdir(Path(config).parent):
59-
builder.build(filter=filter)
60-
97+
if watch:
98+
pkg_path = get_package_path(builder.package)
99+
print(f"Watching {pkg_path} for changes...")
100+
event_handler = FileChangeHandler(callback=doc_build)
101+
observer = Observer()
102+
observer.schedule(event_handler, pkg_path, recursive=True)
103+
observer.start()
104+
try:
105+
while True:
106+
time.sleep(1)
107+
except KeyboardInterrupt:
108+
observer.stop()
109+
observer.join()
110+
else:
111+
doc_build()
61112

62113
@click.command()
63114
@click.argument("config", default="_quarto.yml")

0 commit comments

Comments
 (0)