From 94bde9bf4088b5bda1f1f414af52f8a0189474b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Wed, 21 Jun 2023 23:07:06 +0200 Subject: [PATCH] Build docs using Sphinx & deliver under /docs/ Add requirements to automatically build the documentation using sphinx Add basic configuration for documentation Add django-docs app to deliver documentation as part of the app under /docs/ Add generating/updating of the docs to the setup and update scripts --- AKPlanning/settings.py | 6 ++++ AKPlanning/urls.py | 7 ++-- Utils/setup.sh | 5 +++ Utils/update.sh | 6 ++++ docs/.gitignore | 2 ++ docs/Makefile | 20 +++++++++++ docs/code.rst | 10 ++++++ docs/conf.py | 82 ++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 22 ++++++++++++ docs/make.bat | 35 ++++++++++++++++++ docs/usage/usage.rst | 5 +++ requirements.txt | 8 +++++ 12 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 docs/.gitignore create mode 100644 docs/Makefile create mode 100644 docs/code.rst create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/usage/usage.rst diff --git a/AKPlanning/settings.py b/AKPlanning/settings.py index c697b2e4..3dc46aa5 100644 --- a/AKPlanning/settings.py +++ b/AKPlanning/settings.py @@ -55,6 +55,7 @@ INSTALLED_APPS = [ 'bootstrap_datepicker_plus', 'django_tex', 'compressor', + 'docs', ] MIDDLEWARE = [ @@ -234,4 +235,9 @@ CSP_FONT_SRC = ("'self'", "data:", "fonts.gstatic.com") SEND_MAILS = True EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +# Documentation + +DOCS_ROOT = os.path.join(BASE_DIR, 'docs/_build/html') +DOCS_ACCESS = 'public' + include(optional("settings/*.py")) diff --git a/AKPlanning/urls.py b/AKPlanning/urls.py index cdbbea55..c97f0134 100644 --- a/AKPlanning/urls.py +++ b/AKPlanning/urls.py @@ -1,4 +1,5 @@ -"""AKPlanning URL Configuration +""" +AKPlanning URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.2/topics/http/urls/ @@ -13,13 +14,15 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + import debug_toolbar from django.apps import apps from django.contrib import admin -from django.urls import path, include +from django.urls import path, include, re_path urlpatterns = [ path('admin/', admin.site.urls), + re_path(r'^docs/', include('docs.urls')), path('accounts/', include('django.contrib.auth.urls')), path('accounts/', include('registration.backends.simple.urls')), path('', include('AKModel.urls', namespace='model')), diff --git a/Utils/setup.sh b/Utils/setup.sh index 7993082c..fafa334a 100755 --- a/Utils/setup.sh +++ b/Utils/setup.sh @@ -26,4 +26,9 @@ python manage.py compilemessages -l de_DE # Credentials are entered interactively on CLI python manage.py createsuperuser +# Generate documentation +cd docs +make html +cd .. + deactivate diff --git a/Utils/update.sh b/Utils/update.sh index 780baef2..a711b73b 100755 --- a/Utils/update.sh +++ b/Utils/update.sh @@ -27,4 +27,10 @@ pip install --upgrade -r requirements.txt ./manage.py collectstatic --noinput ./manage.py compilemessages -l de_DE + +# Update documentation +cd docs +make html +cd .. + touch AKPlanning/wsgi.py diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 00000000..6c87b539 --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,2 @@ +_build/ +code/ diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..d4bb2cbb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# 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 = . +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) diff --git a/docs/code.rst b/docs/code.rst new file mode 100644 index 00000000..690352ce --- /dev/null +++ b/docs/code.rst @@ -0,0 +1,10 @@ +Code +===== + +.. toctree:: + code/AKDashboard + code/AKModel + code/AKOnline + code/AKPlan + code/AKScheduling + code/AKSubmission diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..473f1b4f --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,82 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html +import os +import sys +from recommonmark.parser import CommonMarkParser +import django + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'AK Planning' +copyright = '2023, N. Geisler, B. Hättasch & more' +author = 'N. Geisler, B. Hättasch & more' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + 'sphinxcontrib.apidoc', # runs sphinx-apidoc automatically as part of sphinx-build + 'sphinx.ext.autodoc', # the autodoc extensions uses files generated by apidoc + "sphinx.ext.autosummary", + "sphinxcontrib_django", + 'sphinx.ext.viewcode', # enable viewing autodoc'd code +] + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# -- Django specific settings ------------------------------------------------ + +# Add source directory to sys.path +sys.path.insert(0, os.path.abspath("..")) + +# Configure the path to the Django settings module +django_settings = "AKPlanning.settings" +os.environ['DJANGO_SETTINGS_MODULE'] = django_settings + +django.setup() + +# Auto-generate API documentation. +os.environ['SPHINX_APIDOC_OPTIONS'] = "members,show-inheritance" + +# -- Input ---- + +source_parsers = { + '.md': CommonMarkParser, +} + +source_suffix = ['.rst', '.md'] + +# -- Extension Conf ---- + +autodoc_member_order = 'bysource' +autodoc_inherit_docstrings = False + +apidoc_module_dir = '../' +apidoc_output_dir = 'code' +apidoc_excluded_paths = ['AKDashboard/migrations', + 'AKModel/migrations', + 'AKOnline/migrations', + 'AKPlan/migrations', + 'AKScheduling/migrations', + 'AKSubmission/migrations', + 'AKPlanning/', + 'manage.py', + 'docs', + 'locale', + 'Utils' + ] +apidoc_separate_modules = True +apidoc_toc_file = False +apidoc_module_first = True +apidoc_extra_args = ['-f'] +apidoc_project = project + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_static_path = ['_static'] +html_theme = 'sphinx_rtd_theme' diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..50fb2772 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,22 @@ +.. AK Planning documentation master file, created by + sphinx-quickstart on Wed Jun 21 09:54:11 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Start +======================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + usage/usage + code + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..954237b9 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/usage/usage.rst b/docs/usage/usage.rst new file mode 100644 index 00000000..e29d849e --- /dev/null +++ b/docs/usage/usage.rst @@ -0,0 +1,5 @@ +Usage +===== + +.. toctree:: + diff --git a/requirements.txt b/requirements.txt index 8a886c58..c537d231 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,11 @@ django-libsass==0.9 django-betterforms==2.0.0 mysqlclient==2.2.0 # for production deployment tzdata==2023.3 + +# Documentation +sphinxcontrib-django==2.3 +sphinxcontrib-apidoc==0.3.0 +recommonmark==0.7.1 +django-docs==0.3.3 +sphinx-rtd-theme==1.2.2 +sphinx==6.2.1 \ No newline at end of file -- GitLab