Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests, add docstrings, and fix small bugs #28

Merged
merged 12 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This is a GitHub workflow defining a set of jobs with a set of steps.
# ref: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
#
name: Test

on:
pull_request:
paths-ignore:
- "**.md"
- ".github/workflows/*"
- "!.github/workflows/test.yaml"
push:
paths-ignore:
- "**.md"
- ".github/workflows/*"
- "!.github/workflows/test.yaml"
branches-ignore:
- "dependabot/**"
- "pre-commit-ci-update-config"
tags:
- "**"
workflow_dispatch:

jobs:
pytest:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
include:
# NOTE: jinja2<3.1 is added as a workaround to ensure we can test
# against sphinx 2 and 3 that otherwise breaks, see
# https://github.com/sphinx-doc/sphinx/issues/10291#issuecomment-1079709635.
#
- python-version: "3.8"
sphinx-version: "2.*"
traitlets-version: "4.*"
pip-install-addition: "'jinja2<3.1'"
- python-version: "3.9"
sphinx-version: "3.*"
traitlets-version: "4.*"
pip-install-addition: "'jinja2<3.1'"
- python-version: "3.10"
sphinx-version: "4.*"
traitlets-version: "5.*"
pip-install-addition: ""
- python-version: "3.11"
sphinx-version: "5.*"
traitlets-version: "5.*"
pip-install-addition: ""

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"

- run: pip install ".[test]" "sphinx==${{ matrix.sphinx-version }}" "traitlets==${{ matrix.traitlets-version }}" ${{ matrix.pip-install-addition }}

- run: pytest
69 changes: 66 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Manually added parts to .gitignore
# ----------------------------------
#

# Python .gitignore from https://github.com/github/gitignore/blob/HEAD/Python.gitignore
# -------------------------------------------------------------------------------------
#
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand All @@ -20,6 +27,7 @@ parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
Expand All @@ -38,14 +46,17 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -55,6 +66,7 @@ coverage.xml
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
Expand All @@ -67,16 +79,49 @@ instance/
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version
# IPython
profile_default/
ipython_config.py

# celery beat schedule file
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py
Expand All @@ -102,3 +147,21 @@ venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include MANIFEST.in
recursive-include autodoc_traits *
include autodoc_traits.py
include LICENSE
include *.md

Expand Down
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
[![Discourse](https://img.shields.io/badge/help_forum-discourse-blue?logo=discourse)](https://discourse.jupyter.org/c/jupyterhub)
[![Gitter](https://img.shields.io/badge/social_chat-gitter-blue?logo=gitter)](https://gitter.im/jupyterhub/jupyterhub)

`autodoc-traits` is a Sphinx extension that influences
[`sphinx.ext.autodoc`][]'s provided [Sphinx directives][], specifically
[`autoclass`][] and [`autoattribute`][], to better document classes with
[Traitlets][] based configuration.

The `autoclass` directive is updated to document class attributes inheriting
from [`traitlets.TraitType`][] by default. The `autoattribute` directive is
updated to provide a header looking like `default_url c.KubeSpawner.default_url
= Unicode('')`.

The extension also provides the `autoconfigurable` directive mapping to the
`autoclass` directive, and the `autotrait` directive mapping to the
`autoattributes` directive.
`autodoc-traits` is a Sphinx extension that builds on [`sphinx.ext.autodoc`][]
to better document classes with [Traitlets][] based configuration.
`autodoc-traits` provides the [Sphinx directives][] `autoconfigurable` (use with
classes) and `autotrait` (use with the traitlets based configuration options).

The `sphinx.ext.autodoc` provided directive [`automodule`][], which can overview
classes, will with `autodoc-traits` enabled use `autoconfigurable` over
[`autoclass`][] for classes has trait based configuration. Similarly, the
`sphinx.ext.autodoc` provided `autoclass` directive will use `autotrait` over
[`autoattribute`][] if configured to present the traitlets attributes normally
not presented.

The `autoattribute` directive will provide a header looking like `trait
c.TestConfigurable.trait = Bool(False)`, and as docstring it will use the
trait's configured help text.

## How to use it

Expand All @@ -42,13 +44,20 @@ The extension also provides the `autoconfigurable` directive mapping to the
]
```

3. Make use of a `sphinx.ext.autodoc` Sphinx directive like `autoclass`, or
`automodule` that make use of `autoclass`:
3. Make use of the `sphinx.ext.autodoc` Sphinx directive like `automodule` that
document classes, the `autodoc_traits` provided `autoconfigurable` that
documents traitlets configurable classes, or the `autodoc_traits` provided
`autotrait` that documents individual traitlets configuration options:

From a .rst document:

```rst
.. autoclass:: KubeSpawner
.. automodule:: test_module
:members:

.. autoconfigurable:: test_module.TestConfigurable

.. autotrait:: test_module.TestConfigurable.trait
```

## Use with MyST Parser
Expand All @@ -60,7 +69,7 @@ From a .md document, with `myst-parser`:

````markdown
```{eval-rst}
.. autoclass:: KubeSpawner
.. autoconfigurable:: test_module.TestConfigurable
```
````

Expand Down
Loading