Skip to content

Commit

Permalink
Merge pull request #1 from cta-observatory/docs
Browse files Browse the repository at this point in the history
Add basic sphinx doc
  • Loading branch information
maxnoe authored Jun 25, 2022
2 parents aee4987 + 2e49ee3 commit 1de7b12
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,37 @@ jobs:
-v
- uses: codecov/codecov-action@v2

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Install doc dependencies
run: |
pip install -e .[docs]
git describe --tags
python -c 'import project_template_python_pure; print(project_template_python_pure.__version__)'
# no files here yet, so not tracked by git
mkdir -p docs/_static
- name: Build docs
run: make html SPHINXOPTS="-W --keep-going -n --color -j auto"

- name: Deploy to gihub pages
# only run on push to master
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: build/html
CLEAN: true
SINGLE_COMMIT: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ instance/

# Sphinx documentation
docs/_build/
docs/api

# PyBuilder
target/
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = docs
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
68 changes: 68 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------
import project_template_python_pure

project = 'project_template_python_pure'
copyright = '2022, Maximilian Nöthe'
author = 'Maximilian Nöthe'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.githubpages",
"sphinx.ext.intersphinx",
"sphinx_automodapi.automodapi",
"numpydoc",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# have all links automatically associated with the right domain.
default_role = "py:obj"

version = project_template_python_pure.__version__
# The full version, including alpha/beta/rc tags.
release = version


intersphinx_mapping = {
"python": ("https://docs.python.org/3.8", None),
}

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'pydata_sphinx_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
24 changes: 24 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. project_template_python_pure documentation master file, created by
sphinx-quickstart on Sat Jun 25 14:39:18 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to project_template_python_pure's documentation!
========================================================

.. toctree::
:maxdepth: 2
:caption: Contents:

reference





Indices and tables
------------------

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
5 changes: 5 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
API Reference
=============

.. automodapi:: project_template_python_pure
:no-inheritance-diagram:
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ tests =
all =
%(tests)s

docs =
sphinx ~= 5.0
pydata-sphinx-theme
sphinx_automodapi
numpydoc

# and one for developers that includes even more
dev =
%(all)s
%(docs)s
setuptools_scm
39 changes: 39 additions & 0 deletions src/project_template_python_pure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,43 @@

__all__ = [
"__version__",
"fibonacci",
]


def fibonacci(n):
'''
Calculate the nth fibonacci number.
Parameters
----------
n : `int`
Which number to calculate, n >= 0.
Returns
-------
fib_n : `int`
The nth fibonacci number
Examples
--------
>>> fibonacci(0)
0
>>> fibonacci(1)
1
>>> fibonacci(2)
1
>>> fibonacci(3)
2
'''

if n < 0:
raise ValueError(f'n must be >= 0, got {n}')

if n == 0:
return 0

if n == 1:
return 1

return fibonacci(n - 1) + fibonacci(n - 2)

0 comments on commit 1de7b12

Please sign in to comment.