Skip to content

Commit 5739ef7

Browse files
authored
Merge pull request #4 from UMassCDS/sphinx
integrated sphinx autodocumentation into the code
2 parents 6d64557 + 938fd3a commit 5739ef7

File tree

7 files changed

+156
-10
lines changed

7 files changed

+156
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
You should also add project tags for each release in Github, see [Managing releases in a repository](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository).
88

99
## [Unreleased]
10-
10+
- Added example auto-built Sphinx documentation in the `docs` folder
1111
## [1.0.0] - 2022-05-23
1212
### Added
1313
- README and CHANGELOG

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,37 @@ So what does each file in this repository do?
6363
```
6464
.
6565
├── cdstemplate # The python package root - Any code you'd like to be able to import lives here
66-
│   ├── corpus_counter_script.py # A script that takes a list of documents as input and outputs a CSV of word counts
67-
│   ├── __init__.py # Indicates that this directory is a python package, you can put special import instructions here
68-
   ├── word_count.py # A module that has functions and classes to import
69-
│   └── utils.py # A module that handles logging and other internals
66+
  ├── corpus_counter_script.py # A script that takes a list of documents as input and outputs a CSV of word counts
67+
  ├── __init__.py # Indicates that this directory is a python package, you can put special import instructions here
68+
   ├── word_count.py # A module that has functions and classes to import
69+
  └── utils.py # A module that handles logging and other internals
7070
├── CHANGELOG.md # Versioning information
7171
├── dag_workflow.png # An image that is linked to in this README
7272
├── data # Data files which may or may not be tracked in Git, but we reserve a folder for them so that users can all have the same relative paths
73-
│   ├── gutenberg # Sample text input files, the raw inputs to our experiment pipeline.
74-
│   └── gutenberg_counts.csv # The expected output file for our experiment. It's generated by `dvc repro` and is ignored by git.
73+
  ├── gutenberg # Sample text input files, the raw inputs to our experiment pipeline.
74+
  └── gutenberg_counts.csv # The expected output file for our experiment. It's generated by `dvc repro` and is ignored by git.
75+
├── docs # Sphinx auto-documentation uses this folder to run its scripts and store documentation
76+
  ├── _build # Contains the Sphinx doctree and html documentation source code
77+
├── doctrees # A folder with doctree construction information
78+
  └── html # A folder that contains the html code for all automatically created documentation
79+
  ├── _static # A folder that can contain static code
80+
  ├── _templates # A folder that can contain Sphinx templates
81+
├── conf.py # A function that configures Sphinx according to user specifications
82+
├── index.rst # A directory that users can input new functions into for auto-documentation
83+
├── make.bat # A function that runs auto-documentation
84+
└── Makefile # A function that creates html documentation based on functions in the index.rst file
7585
├── dvc.lock # Data Version Control uses this file to compare experiment versions. It's tracked in Git, but don't edit it manually.
7686
├── dvc.yaml # Create the Data Version Control pipeline stages here
7787
├── notebooks
78-
│   └── word_count_prototype.ipynb # A jupyter notebook that makes pretty plots
88+
  └── word_count_prototype.ipynb # A jupyter notebook that makes pretty plots
7989
├── pyproject.toml # The setuptools build tools are installed, so you project can be installed
8090
├── README.md # You're reading it now!
8191
├── setup.cfg # Project metadata and dependencies are declared for proper installation
8292
└── tests
8393
└── test_word_count.py # Unit and smoke tests for the word_count module
8494
├── .dvc # The configuration file for Data Version Control
8595
├── .github
86-
| └── workflows/python_package.yml # Github Workflow file, configures running tests on Github every time a pull request to the main branch is made
96+
└── workflows/python_package.yml # Github Workflow file, configures running tests on Github every time a pull request to the main branch is made
8797
├── .gitignore # Lists files that should not be included in version control, created from Github's template .gitignore for Python.
8898
└── .dvcignore # Lists files that Data Version Control should skip when checking for changes in stage dependencies.
8999
```
@@ -97,6 +107,7 @@ The README, CHANGELOG and docstrings are just as important.
97107
- _README.md_ : Summarize the project's purpose and give installation instructions.
98108
- _CHANGELOG.md_ : Tell the user what has changed between versions and why, see [Keep A CHANGELOG](https://keepachangelog.com/en/1.0.0/)
99109
- docstrings: Appear directly in your code and give an overview of each function or object. They can be printed using `help(object)` from the python interpreter or used to automatically generate API documentation with a tool like [Sphinx](https://www.sphinx-doc.org/en/master/index.html). There are many different docstring formats. Your team can choose any they like, just be consistent. This template uses [reStructuredText style](https://peps.python.org/pep-0287/).
110+
- Sphinx : Create html documentation for your functions based on the docstrings you write in the code. Use [Sphinx](https://www.sphinx-doc.org/en/master/index.html) to streamline the documentation process.
100111

101112
Read [Real Python's Documenting Python Code: A Complete Guide](https://realpython.com/documenting-python-code/) for more ideas about effectively documenting code. The `.md` files are written using [Markdown](https://www.markdownguide.org/), a handy formatting language that is automatically rendered in Github.
102113

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.abspath('..'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = 'testdoc'
21+
copyright = '2023, Luke Ruud'
22+
author = 'Luke Ruud'
23+
24+
# The full version, including alpha/beta/rc tags
25+
release = '0.1'
26+
27+
28+
# -- General configuration ---------------------------------------------------
29+
30+
# Add any Sphinx extension module names here, as strings. They can be
31+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32+
# ones.
33+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"
34+
]
35+
36+
# Add any paths that contain templates here, relative to this directory.
37+
templates_path = ['_templates']
38+
39+
# List of patterns, relative to source directory, that match files and
40+
# directories to ignore when looking for source files.
41+
# This pattern also affects html_static_path and html_extra_path.
42+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
43+
44+
45+
# -- Options for HTML output -------------------------------------------------
46+
47+
# The theme to use for HTML and HTML Help pages. See the documentation for
48+
# a list of builtin themes.
49+
#
50+
html_theme = 'alabaster'
51+
52+
# Add any paths that contain custom static files (such as style sheets) here,
53+
# relative to this directory. They are copied after the builtin static files,
54+
# so a file named "default.css" will overwrite the builtin "default.css".
55+
html_static_path = ['_static']

docs/index.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. testdoc documentation master file, created by
2+
sphinx-quickstart on Mon Jul 24 13:17:26 2023.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to testdoc's documentation!
7+
===================================
8+
9+
10+
.. automodule:: cdstemplate.word_count
11+
:members:
12+
13+
.. toctree::
14+
:maxdepth: 2
15+
:caption: Contents:
16+
17+
18+
19+
Indices and tables
20+
==================
21+
22+
* :ref:`genindex`
23+
* :ref:`modindex`
24+
* :ref:`search`

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ dev =
2727
black
2828
jupyter
2929
matplotlib
30-
seaborn
30+
seaborn
31+
sphinx

0 commit comments

Comments
 (0)