Skip to content

Commit 589e598

Browse files
authored
Merge pull request spyder-ide#12 from CAM-Gerlach/add-autodocstring-build
Automatically generate API docs from a Spyder repo submodule
2 parents 70168c9 + 2052e2f commit 589e598

File tree

14 files changed

+481
-70
lines changed

14 files changed

+481
-70
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
count = True
3-
ignore = E123, E203, W504
3+
ignore = E123, E203, W503
44
max-doc-length = 79
55
max-complexity = 15
66
jobs = 1

.github/workflows/build.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@ permissions:
2020

2121
jobs:
2222
build:
23-
name: Build and Deploy
23+
name: Build and Deploy Autodoc=${{ matrix.build-autodoc }}
2424

2525
runs-on: ubuntu-latest
2626

2727
env:
2828
IS_DEPLOY: ${{ (github.event_name == 'push' && '1') || '0' }}
2929
IS_STAGING: ${{ (github.ref == 'refs/heads/staging' && '1') || '0' }}
3030
IS_MAIN: ${{ ((github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && '1') || '0' }}
31+
BUILD_AUTODOC: ${{ matrix.build-autodoc }}
32+
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
build-autodoc: ['Yes', 'No']
3137

3238
steps:
3339
- name: Check out repository
3440
uses: actions/checkout@v4
41+
with:
42+
submodules: true
3543
- name: Set up Python
3644
uses: actions/setup-python@v5
3745
with:
@@ -45,12 +53,13 @@ jobs:
4553
echo Deploy: $IS_DEPLOY
4654
echo Prod: $IS_PROD
4755
echo Main: $IS_MAIN
56+
echo Autodoc: $BUILD_AUTODOC
4857
pip list
4958
- name: Build project
5059
shell: bash
5160
run: ./ci/build.sh
5261
- name: Deploy to GitHub Pages
53-
if: env.IS_DEPLOY == '1'
62+
if: env.IS_DEPLOY == '1' && env.BUILD_AUTODOC == 'Yes'
5463
uses: JamesIves/github-pages-deploy-action@v4
5564
with:
5665
folder: docs/_build/html

.github/workflows/check.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
steps:
3232
- name: Checkout repository
3333
uses: actions/checkout@v4
34+
with:
35+
submodules: true
3436
- name: Set up Python
3537
uses: actions/setup-python@v5
3638
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ instance/
110110
.scrapy
111111

112112
# Sphinx documentation
113+
doc/_autosummary/
113114
doc/_build/
115+
docs/_autosummary/
114116
docs/_build/
115117

116118
# PyBuilder

.gitmodules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[submodule "spyder"]
2+
path = spyder
3+
url = https://github.com/spyder-ide/spyder.git
4+
branch = 6.x
5+
update = rebase

CONTRIBUTING.md

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ Let us know if you have any further questions, and we look forward to your contr
2525
- [Cloning the Repository](#cloning-the-repository)
2626
- [Setting Up a Development Environment with Nox (Recommended)](#setting-up-a-development-environment-with-nox-recommended)
2727
- [Setting Up a Development Environment Manually](#setting-up-a-development-environment-manually)
28+
- [Configure Git](#configure-git)
2829
- [Create and activate a fresh environment](#create-and-activate-a-fresh-environment)
2930
- [Install dependencies](#install-dependencies)
30-
- [Add the upstream remote](#add-the-upstream-remote)
3131
- [Installing and Using the Pre-Commit Hooks](#installing-and-using-the-pre-commit-hooks)
3232
- [Building the Project](#building-the-project)
3333
- [Build with Nox](#build-with-nox)
3434
- [Build manually](#build-manually)
3535
- [Contributing Changes](#contributing-changes)
3636
- [Decide which branch to use](#decide-which-branch-to-use)
3737
- [Prepare your topic branch](#prepare-your-topic-branch)
38-
- [Commit your changes](#commit-your-changes)
38+
- [Sync the latest Spyder docstrings (optional)](#sync-the-latest-spyder-docstrings-optional)
39+
- [Make and commit your changes](#make-and-commit-your-changes)
3940
- [Push your branch](#push-your-branch)
4041
- [Submit a Pull Request](#submit-a-pull-request)
4142
- [Standards and Conventions](#standards-and-conventions)
@@ -58,10 +59,10 @@ If referring to a specific line or file, please be sure to provide a snippet of
5859
## Cloning the Repository
5960

6061
First, navigate to the [project repository](https://github.com/spyder-ide/spyder-api-docs) in your web browser and press the ``Fork`` button to make a personal copy of the repository on your own GitHub account.
61-
Then, click the ``Clone or Download`` button on your repository, copy the link and run the following on the command line to clone the repo:
62+
Then, click the ``Clone or Download`` button on your repository, copy the link and run the following on the command line to clone the repo (with submodules):
6263

6364
```shell
64-
git clone <LINK-TO-YOUR-REPO>
65+
git clone --recurse-submodules <LINK-TO-YOUR-REPO>
6566
```
6667

6768
After cloning the repository, navigate to its new directory using the `cd` command:
@@ -119,6 +120,22 @@ For advanced users, if you'd prefer to also have your own local environment with
119120
**Note**: You may need to substitute ``python3`` for ``python`` in the commands below on some Linux distros where ``python`` isn't mapped to ``python3`` (yet).
120121

121122

123+
### Configure Git
124+
125+
Make sure to set the upstream Git remote to the official Spyder-API-Docs repo with:
126+
127+
```shell
128+
git remote add upstream https://github.com/spyder-ide/spyder-api-docs.git
129+
```
130+
131+
It's also a good idea to configure Git to automatically pull, checkout and push submodules:
132+
133+
```shell
134+
git config --local submodule.recurse true
135+
git config --local push.recurseSubmodules check
136+
```
137+
138+
122139
### Create and activate a fresh environment
123140

124141
We highly recommend you create and activate a virtual environment to avoid any conflicts with other packages on your system or causing any other issues.
@@ -128,7 +145,7 @@ Regardless of the tool you use, make sure to remember to always activate your en
128145

129146
#### Conda
130147

131-
To create an environment with Conda (recommended), simply execute the following:
148+
To create an environment with Conda (recommended), execute the following:
132149

133150
```shell
134151
conda create -c conda-forge -n spyder-api-docs-env python
@@ -177,17 +194,14 @@ Or if using ``pip``, you can grab them with:
177194
python -m pip install -r requirements.txt
178195
```
179196

180-
181-
### Add the upstream remote
182-
183-
Make sure to set the upstream Git remote to the official Spyder-API-Docs repo with:
197+
If you plan to generate and build the API reference documentation extracted from Spyder's docstrings, you'll also need to install Spyder in development mode as well as its dev dependencies.
198+
To do so, you can run the ``install_dev_repos.py`` script in the ``spyder`` submodule:
184199

185200
```shell
186-
git remote add upstream https://github.com/spyder-ide/spyder-api-docs.git
201+
python install_dev_repos.py
187202
```
188203

189204

190-
191205
## Installing and Using the Pre-Commit Hooks
192206

193207
This repository uses [Pre-Commit](https://pre-commit.com/) to install, configure and update a suite of pre-commit hooks that check for common problems and issues, and fix many of them automatically.
@@ -240,7 +254,13 @@ To build the project using Nox, just run
240254
nox -s build
241255
```
242256

243-
and can then open the rendered output in your default web browser with
257+
or, to also extract, generate and build the API reference from Spyder's docstrings (expensive the first time), pass the ``-t autodoc`` argument to any build command:
258+
259+
```shell
260+
nox -s build -- -t autodoc
261+
```
262+
263+
and then open the rendered output in your default web browser with
244264

245265
```shell
246266
nox -s serve
@@ -249,7 +269,7 @@ nox -s serve
249269
Alternatively, to automatically rebuild the project when changes occur, you can invoke
250270

251271
```shell
252-
nox -s autobuild
272+
nox -s autorebuild
253273
```
254274

255275
You can also pass your own custom [Sphinx build options](https://www.sphinx-doc.org/en/master/man/sphinx-build.html) after a ``--`` separator, which are added to the default set.
@@ -259,6 +279,12 @@ For example, to rebuild just the install guide and FAQ in verbose mode with the
259279
nox -s build -- --verbose --builder dirhtml -- index.rst
260280
```
261281

282+
When changing build options (particularly autodoc), cleaning the generated files avoids spurious errors:
283+
284+
```shell
285+
nox -s clean
286+
```
287+
262288

263289
### Build manually
264290

@@ -268,8 +294,21 @@ For manual installations, you can invoke Sphinx yourself with the appropriate op
268294
python -m sphinx -n -W --keep-going docs docs/_build/html
269295
```
270296

297+
or to also extract, generate and build the API reference from Spyder's docstrings (requires Spyder and its dependencies to be installed in your environment):
298+
299+
```shell
300+
python -I -m sphinx -n --keep-going -t autodoc docs docs/_build/html
301+
```
302+
271303
Then, navigate to the ``_build/html`` directory inside the ``spyder-docs`` repository and open ``index.html`` (the main page of the docs) in your preferred browser.
272304

305+
When changing build options (particularly autodoc), cleaning the generated files first avoids spurious errors:
306+
307+
```shell
308+
rm -r docs/_autosummary/
309+
rm -r docs/_build/
310+
```
311+
273312

274313

275314
## Contributing Changes
@@ -295,7 +334,40 @@ git switch -c <FEATURE-BRANCH>
295334
```
296335

297336

298-
### Commit your changes
337+
### Sync the latest Spyder docstrings (optional)
338+
339+
*If* your pull request requires the latest docstring changes from the Spyder repo, or there's a reason to manually update them, you can update the submodule to the latest stable branch either with Nox:
340+
341+
```shell
342+
nox -s sync-spyder
343+
```
344+
345+
or manually:
346+
347+
```shell
348+
git submodule update --remote
349+
```
350+
351+
**Note**: If using the manual command and you've checked out the submodule to a topic branch tracking your fork rather than the upstream Spyder repository, you'll need to either check out `6.x` first (setting it to track the main Spyder repo if it isn't already):
352+
353+
```shell
354+
cd spyder
355+
git switch 6.x
356+
git --set-upstream-to upstream 6.x # If required
357+
cd ..
358+
```
359+
360+
Or, to integrate the changes into your own branch (assuming `upstream` is the Spyder repository):
361+
362+
```shell
363+
cd spyder
364+
git fetch upstream 6.x
365+
git rebase FETCH_HEAD
366+
cd ..
367+
```
368+
369+
370+
### Make and commit your changes
299371

300372
Once you've made and tested your changes, add them to the staging area, and then commit them with a descriptive message.
301373
Commit messages should be

ci/build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
#!/bin/bash -ex
22

3-
nox -s build
3+
if [ "$BUILD_AUTODOC" = "No" ]; then
4+
ARGS=''
5+
else
6+
ARGS='-t autodoc'
7+
fi
8+
9+
nox -s build -- $ARGS
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. automodule:: {{ fullname }}
4+
5+
{% block attributes %}
6+
{%- if attributes %}
7+
.. rubric:: {{ _('Module Attributes') }}
8+
9+
.. autosummary::
10+
{% for item in attributes %}
11+
{{ item }}
12+
{%- endfor %}
13+
{% endif %}
14+
{%- endblock %}
15+
16+
{%- block functions %}
17+
{%- if functions %}
18+
.. rubric:: {{ _('Functions') }}
19+
20+
.. autosummary::
21+
{% for item in functions %}
22+
{{ item }}
23+
{%- endfor %}
24+
{% endif %}
25+
{%- endblock %}
26+
27+
{%- block classes %}
28+
{%- if classes %}
29+
.. rubric:: {{ _('Classes') }}
30+
31+
.. autosummary::
32+
{% for item in classes %}
33+
{{ item }}
34+
{%- endfor %}
35+
{% endif %}
36+
{%- endblock %}
37+
38+
{%- block exceptions %}
39+
{%- if exceptions %}
40+
.. rubric:: {{ _('Exceptions') }}
41+
42+
.. autosummary::
43+
{% for item in exceptions %}
44+
{{ item }}
45+
{%- endfor %}
46+
{% endif %}
47+
{%- endblock %}
48+
49+
{%- block modules %}
50+
{%- if modules %}
51+
.. rubric:: Modules
52+
53+
.. autosummary::
54+
:toctree:
55+
:template: custom-module-template.rst
56+
:recursive:
57+
{% for item in modules %}
58+
{% if not 'tests' in item %}
59+
{{ item }}
60+
{%- endif %}
61+
{%- endfor %}
62+
{% endif %}
63+
{%- endblock %}

0 commit comments

Comments
 (0)