Skip to content

Commit 678de01

Browse files
authored
Merge pull request #20 from StochasticTree/doc_overhaul
Overhaul of documentation site to combine R and Python vignettes and use quarto for more of the website
2 parents 05a5fee + dcd6cab commit 678de01

49 files changed

Lines changed: 10147 additions & 22731 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/docs.yml

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
pip install .
6262
cd ..
6363
64+
- name: Set RETICULATE_PYTHON for vignette rendering
65+
run: echo "RETICULATE_PYTHON=$(which python)" >> $GITHUB_ENV
66+
6467
- name: Setup pandoc
6568
uses: r-lib/actions/setup-pandoc@v2
6669

@@ -73,57 +76,42 @@ jobs:
7376
uses: r-lib/actions/setup-r-dependencies@v2
7477
with:
7578
working-directory: 'stochtree_repo'
76-
extra-packages: any::latex2exp, any::ggplot2, any::decor, any::pkgdown
79+
extra-packages: any::latex2exp, any::ggplot2, any::decor, any::pkgdown, any::reticulate, any::bayesplot, any::coda, any::doParallel, any::foreach, any::mvtnorm, any::rpart, any::rpart.plot, any::tgp, any::rprojroot
7780
needs: website
7881

7982
- name: Build R doc site
8083
run: |
8184
cd stochtree_repo
82-
Rscript cran-bootstrap.R 1 1 1
85+
Rscript cran-bootstrap.R 0 1 0
8386
cd ..
8487
mkdir -p docs/R_docs/pkgdown
8588
Rscript -e 'pkgdown::build_site_github_pages("stochtree_repo/stochtree_cran", dest_dir = "../../docs/R_docs/pkgdown", install = TRUE)'
8689
90+
- name: Install stochtree R package for vignettes
91+
run: Rscript -e 'install.packages("stochtree_repo/stochtree_cran", repos = NULL, type = "source")'
92+
8793
- name: Clean up the temporary stochtree_cran directory created
8894
run: |
8995
cd stochtree_repo
90-
Rscript cran-cleanup.R
96+
Rscript cran-cleanup.R
9197
cd ..
9298
93-
- name: Copy Jupyter notebook demos over to docs directory
94-
run: |
95-
cp stochtree_repo/demo/notebooks/supervised_learning.ipynb docs/python_docs/demo/supervised_learning.ipynb
96-
cp stochtree_repo/demo/notebooks/causal_inference.ipynb docs/python_docs/demo/causal_inference.ipynb
97-
cp stochtree_repo/demo/notebooks/heteroskedastic_supervised_learning.ipynb docs/python_docs/demo/heteroskedastic_supervised_learning.ipynb
98-
cp stochtree_repo/demo/notebooks/multivariate_treatment_causal_inference.ipynb docs/python_docs/demo/multivariate_treatment_causal_inference.ipynb
99-
cp stochtree_repo/demo/notebooks/reparameterized_causal_inference.ipynb docs/python_docs/demo/reparameterized_causal_inference.ipynb
100-
cp stochtree_repo/demo/notebooks/serialization.ipynb docs/python_docs/demo/serialization.ipynb
101-
cp stochtree_repo/demo/notebooks/tree_inspection.ipynb docs/python_docs/demo/tree_inspection.ipynb
102-
cp stochtree_repo/demo/notebooks/summary.ipynb docs/python_docs/demo/summary.ipynb
103-
cp stochtree_repo/demo/notebooks/ordinal_outcome.ipynb docs/python_docs/demo/ordinal_outcome.ipynb
104-
cp stochtree_repo/demo/notebooks/prototype_interface.ipynb docs/python_docs/demo/prototype_interface.ipynb
105-
cp stochtree_repo/demo/notebooks/sklearn_wrappers.ipynb docs/python_docs/demo/sklearn_wrappers.ipynb
106-
cp stochtree_repo/demo/notebooks/multi_chain.ipynb docs/python_docs/demo/multi_chain.ipynb
107-
108-
- name: Copy static vignettes over to docs directory
109-
run: |
110-
cp vignettes/Python/RDD/rdd.html docs/vignettes/Python/rdd.html
111-
cp vignettes/Python/RDD/RDD_DAG.png docs/vignettes/Python/RDD_DAG.png
112-
cp vignettes/Python/RDD/trees1.png docs/vignettes/Python/trees1.png
113-
cp vignettes/Python/RDD/trees2.png docs/vignettes/Python/trees2.png
114-
cp vignettes/Python/RDD/trees3.png docs/vignettes/Python/trees3.png
115-
cp vignettes/R/RDD/rdd.html docs/vignettes/R/rdd.html
116-
cp vignettes/Python/IV/iv.html docs/vignettes/Python/iv.html
117-
cp vignettes/Python/IV/IV_CDAG.png docs/vignettes/Python/IV_CDAG.png
118-
cp vignettes/R/IV/iv.html docs/vignettes/R/iv.html
119-
99+
- name: Install Quarto
100+
uses: quarto-dev/quarto-actions/setup@v2
101+
102+
- name: Install quartodoc
103+
run: pip install quartodoc "griffe<1.0"
104+
105+
- name: Regenerate Python API reference pages
106+
run: quartodoc build
107+
120108
- name: Build the overall doc site
121109
run: |
122-
mkdocs build
110+
quarto render
123111
124112
- name: Deploy to GitHub pages 🚀
125113
if: github.event_name != 'pull_request'
126114
uses: JamesIves/github-pages-deploy-action@v4
127115
with:
128116
branch: gh-pages
129-
folder: site
117+
folder: _site

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,24 @@ yarn-error.log*
3434
/site/
3535
/docs/cpp_docs/doxygen/
3636
/docs/R_docs/pkgdown/*
37+
_site/
38+
_freeze/
39+
40+
# Quarto render artifacts (output-dir should be _site/, but these appear in-place too)
41+
/*.html
42+
/site_libs/
43+
/objects.json
44+
/development/*.html
45+
/python-api/**/*.html
46+
/python-api/reference/*.qmd
3747

3848
# Virtual environments
3949
/python_venv
4050
/cpp_venv
4151
/venv
52+
.venv
4253
.Rproj.user
54+
55+
/.quarto/
56+
**/*.quarto_ipynb
57+
**/*.rmarkdown

.here

Whitespace-only changes.

README.md

Lines changed: 72 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,64 @@
44

55
### MacOS
66

7-
#### Cloning the repo
7+
#### Software dependencies
88

9-
First, you will need the stochtree repo on your local machine.
10-
Navigate to the `documentation` repo in your terminal (*replace `~/path/to/documentation` with the path to the documentation repo on your local system*).
9+
You'll need to have the following software installed
1110

12-
```{bash}
13-
cd ~/path/to/documentation
14-
```
15-
16-
Now, recursively clone the main `stochtree` repo into a `stochtree_repo` subfolder of the `documentation` repo
17-
18-
```{bash}
19-
git clone --recursive git@github.com:StochasticTree/stochtree.git stochtree_repo
20-
```
21-
22-
#### Setting up build dependencies
11+
- Python: can be installed via [homebrew](https://formulae.brew.sh/formula/python@3.14), [conda](https://www.anaconda.com/download), and [directly from the python site](https://www.python.org/downloads/)
12+
- R: can be installed via [CRAN](https://cran.r-project.org/) or [homebrew](https://formulae.brew.sh/formula/r)
13+
- Quarto: can be installed [directly from the Quarto site](https://quarto.org/docs/get-started/) or [homebrew](https://formulae.brew.sh/cask/quarto)
14+
- Doxygen: can be installed [directly from the Doxygen site](https://www.doxygen.nl/) or [homebrew](https://formulae.brew.sh/formula/doxygen)
2315

24-
The docs are largely built using [`mkdocs`](https://www.mkdocs.org), [`pkgdown`](https://pkgdown.r-lib.org) and [`doxygen`](https://www.doxygen.nl/index.html),
25-
with everything tied together using the ["Material for MkDocs"](https://squidfunk.github.io/mkdocs-material/) theme.
16+
#### Setting up R and Python build dependencies
2617

27-
We first create a virtual environment and install the dependencies for `stochtree` as well as the doc site (several python packages: `mkdocs-material`, `mkdocstrings-python`, and `mkdocs-jupyter`).
18+
Building multi-lingual (R and Python) vignettes requires installing the vignettes' package dependencies. In Python, this is done via a virtual environment (local `.venv`)
2819

2920
```{bash}
30-
python -m venv venv
31-
source venv/bin/activate
21+
python -m venv .venv
22+
source .venv/bin/activate
3223
pip install --upgrade pip
3324
pip install -r requirements.txt
25+
pip install git+https://github.com/StochasticTree/stochtree.git
3426
```
3527

36-
##### stochtree
37-
38-
Now, we build the `stochtree` python library locally in the virtual environment activated above
28+
And in R, this is typically done as a global system install, though you might also consider [`renv`](https://rstudio.github.io/renv/) for managing project-specific R dependencies
3929

4030
```{bash}
41-
cd stochtree_repo
42-
pip install .
43-
cd ..
31+
Rscript -e 'install.packages(c("remotes", "devtools", "roxygen2", "ggplot2", "latex2exp", "decor", "pkgdown", "cpp11", "BH", "doParallel", "foreach", "knitr", "Matrix", "MASS", "mvtnorm", "rmarkdown", "testthat", "tgp", "here", "reticulate"), repos="https://cloud.r-project.org/")'
32+
Rscript -e 'remotes::install_github("StochasticTree/stochtree", ref = "r-dev")'
4433
```
4534

46-
##### pkgdown
35+
#### Cloning the stochtree repo
4736

48-
To use `pkgdown`, you need to install [R](https://cran.r-project.org).
49-
One R is installed, make sure the dependendencies of the pkgdown build are installed
37+
Building the R API docs (roxygen2 / pkgdown) and C++ API docs (Doxygen) requires the stochtree source. Clone it into `stochtree_repo/` at the repo root:
5038

51-
```{bash}
52-
Rscript -e 'install.packages(c("remotes", "devtools", "roxygen2", "ggplot2", "latex2exp", "decor", "pkgdown", "cpp11", "BH", "doParallel", "foreach", "knitr", "Matrix", "MASS", "mvtnorm", "rmarkdown", "testthat", "tgp"), repos="https://cloud.r-project.org/")'
39+
```bash
40+
git clone --recurse-submodules https://github.com/StochasticTree/stochtree.git stochtree_repo
5341
```
5442

55-
### Building the R docs
43+
#### Building the pkgdown site for the R API
5644

57-
To build the R docs, first run a script that lays out the package as needed
45+
With the stochtree repo checked out and R dependencies installed (see above), run:
5846

59-
```{bash}
47+
```bash
6048
cd stochtree_repo
61-
Rscript cran-bootstrap.R 1 1 1
49+
Rscript cran-bootstrap.R 0 1 0
6250
cd ..
63-
```
64-
65-
Then run the `pkgdown` build workflow to put the R docs in the correct folder
66-
67-
```{bash}
6851
mkdir -p docs/R_docs/pkgdown
6952
Rscript -e 'pkgdown::build_site_github_pages("stochtree_repo/stochtree_cran", dest_dir = "../../docs/R_docs/pkgdown", install = TRUE)'
70-
rm -rf stochtree_repo/stochtree_cran
53+
cd stochtree_repo
54+
Rscript cran-cleanup.R
55+
cd ..
7156
```
7257

73-
### Building the doxygen site for the C++ API
58+
`cran-bootstrap.R 0 1 0` prepares a `stochtree_cran/` subdirectory with the pkgdown config but without vignette source (vignettes are served by the Quarto site instead). `cran-cleanup.R` removes that temporary directory when done. The output is written to `docs/R_docs/pkgdown/`.
7459

75-
First, ensure that you have [doxygen](https://www.doxygen.nl/index.html) installed.
76-
On MacOS, this can be [done via homebrew](https://formulae.brew.sh/formula/doxygen) (i.e. `brew install doxygen`).
60+
#### Building the Doxygen site for the C++ API
7761

78-
Then, modify the `Doxyfile` to build the C++ documentation as desired and build the doxygen site
62+
With the stochtree repo checked out and Doxygen installed (`brew install doxygen` on macOS), run:
7963

80-
```{bash}
64+
```bash
8165
sed -i '' 's|^OUTPUT_DIRECTORY *=.*|OUTPUT_DIRECTORY = ../docs/cpp_docs/|' stochtree_repo/Doxyfile
8266
sed -i '' 's|^GENERATE_XML *=.*|GENERATE_XML = NO|' stochtree_repo/Doxyfile
8367
sed -i '' 's|^GENERATE_HTML *=.*|GENERATE_HTML = YES|' stochtree_repo/Doxyfile
@@ -87,47 +71,58 @@ doxygen Doxyfile
8771
cd ..
8872
```
8973

90-
### Copying Jupyter notebook demos to the docs directory
74+
The output is written to `docs/cpp_docs/doxygen/`.
9175

92-
```{bash}
93-
cp stochtree_repo/demo/notebooks/supervised_learning.ipynb docs/python_docs/demo/supervised_learning.ipynb
94-
cp stochtree_repo/demo/notebooks/causal_inference.ipynb docs/python_docs/demo/causal_inference.ipynb
95-
cp stochtree_repo/demo/notebooks/heteroskedastic_supervised_learning.ipynb docs/python_docs/demo/heteroskedastic_supervised_learning.ipynb
96-
cp stochtree_repo/demo/notebooks/ordinal_outcome.ipynb docs/python_docs/demo/ordinal_outcome.ipynb
97-
cp stochtree_repo/demo/notebooks/multivariate_treatment_causal_inference.ipynb docs/python_docs/demo/multivariate_treatment_causal_inference.ipynb
98-
cp stochtree_repo/demo/notebooks/reparameterized_causal_inference.ipynb docs/python_docs/demo/reparameterized_causal_inference.ipynb
99-
cp stochtree_repo/demo/notebooks/serialization.ipynb docs/python_docs/demo/serialization.ipynb
100-
cp stochtree_repo/demo/notebooks/tree_inspection.ipynb docs/python_docs/demo/tree_inspection.ipynb
101-
cp stochtree_repo/demo/notebooks/summary.ipynb docs/python_docs/demo/summary.ipynb
102-
cp stochtree_repo/demo/notebooks/prototype_interface.ipynb docs/python_docs/demo/prototype_interface.ipynb
103-
cp stochtree_repo/demo/notebooks/sklearn_wrappers.ipynb docs/python_docs/demo/sklearn_wrappers.ipynb
104-
cp stochtree_repo/demo/notebooks/multi_chain.ipynb docs/python_docs/demo/multi_chain.ipynb
76+
#### Building the vignettes with quarto
77+
78+
The vignettes live in the `vignettes/` directory and are configured as a standalone Quarto website via `vignettes/_quarto.yml`. Each `.qmd` file uses `{.panel-tabset group="language"}` tabsets to present R and Python code side-by-side. Python cells are executed via `reticulate`; set the `RETICULATE_PYTHON` environment variable to point at your `.venv` interpreter if it isn't picked up automatically.
79+
80+
To render all vignettes at once:
81+
82+
```bash
83+
cd vignettes
84+
quarto render
10585
```
10686

107-
### Copy static vignettes over to docs directory
87+
To render a single vignette:
10888

109-
```{bash}
110-
cp vignettes/Python/RDD/rdd.html docs/vignettes/Python/rdd.html
111-
cp vignettes/Python/RDD/RDD_DAG.png docs/vignettes/Python/RDD_DAG.png
112-
cp vignettes/Python/RDD/trees1.png docs/vignettes/Python/trees1.png
113-
cp vignettes/Python/RDD/trees2.png docs/vignettes/Python/trees2.png
114-
cp vignettes/Python/RDD/trees3.png docs/vignettes/Python/trees3.png
115-
cp vignettes/R/RDD/rdd.html docs/vignettes/R/rdd.html
116-
cp vignettes/Python/IV/iv.html docs/vignettes/Python/iv.html
117-
cp vignettes/Python/IV/IV_CDAG.png docs/vignettes/Python/IV_CDAG.png
118-
cp vignettes/R/IV/iv.html docs/vignettes/R/iv.html
89+
```bash
90+
cd vignettes
91+
quarto render bart.qmd
11992
```
12093

121-
### Building the overall website
94+
To preview the vignette site locally with live reload:
12295

123-
To build and preview the site locally, run
96+
```bash
97+
cd vignettes
98+
quarto preview
99+
```
124100

125-
```{bash}
126-
mkdocs serve
101+
The rendered site is written to `vignettes/_site/`. Individual vignettes use `freeze: auto` in their frontmatter, so re-renders only re-execute cells whose source has changed. To force a full re-execution, delete `vignettes/_freeze/` before rendering.
102+
103+
#### Regenerating the Python API reference pages
104+
105+
The `python-api/reference/*.qmd` files are generated by quartodoc from the stochtree package's docstrings. They are checked into the repo, so a normal `quarto render` will render whatever is already there. If you've updated docstrings in the stochtree Python package, regenerate them first:
106+
107+
```bash
108+
source .venv/bin/activate
109+
quartodoc build
127110
```
128111

129-
To build the files underlying the static site, run
112+
This reads the `quartodoc:` block in `_quarto.yml` and writes updated `.qmd` files to `python-api/reference/`. Run it from the repo root. After regenerating, commit the updated `.qmd` files and run `quarto render` as normal.
130113

131-
```{bash}
132-
mkdocs build
114+
The CI workflow always runs `quartodoc build` before `quarto render` so the live site stays in sync with the latest package docstrings.
115+
116+
### Building the overall website
117+
118+
The full site (vignettes + Python API reference + embedded pkgdown/Doxygen) is built from the repo root with:
119+
120+
```bash
121+
quarto render
133122
```
123+
124+
This requires pkgdown and Doxygen output to already exist at `docs/R_docs/pkgdown/` and `docs/cpp_docs/doxygen/` respectively (the CI workflow builds these before running `quarto render`). For iterating on vignettes alone, the `cd vignettes && quarto render` workflow described above is faster.
125+
126+
**Freeze cache note:** The vignette `.qmd` files use `freeze: auto`, so re-renders only re-execute cells whose source has changed. The freeze cache lives at `_freeze/vignettes/` (top-level render) or `vignettes/_freeze/` (standalone vignette render). If you switch between the two render modes, copy the cache to the appropriate location before rendering to avoid unnecessary re-execution.
127+
128+
The CI workflow (`.github/workflows/docs.yml`) handles the full build and deploys the output `_site/` directory to the `gh-pages` branch.

0 commit comments

Comments
 (0)