Skip to content

Commit

Permalink
Merge pull request #56 from kartverket/sphinx_deployment
Browse files Browse the repository at this point in the history
Sphinx deployment
  • Loading branch information
EllingOftedalKV authored Jan 24, 2024
2 parents c4523cd + 641c39a commit 2f4de18
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/sphinx_documentation_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and Deploy Sphinx Documentation

on:
push:
branches:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install Dependencies
run: |
pip install sphinx
- name: Generate .rst files
run: |
sphinx-apidoc -o generated_docs/ .
- name: Update index.rst
run: |
update_index_rst.py
- name: Build Sphinx Documentation
run: |
make html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_build/html
branch: gh-pages
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ instance/
.scrapy

# Sphinx documentation
docs/_build/
_build/
/generated_docs/

# PyBuilder
.pybuilder/
Expand Down Expand Up @@ -200,4 +201,5 @@ cython_debug/
# 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/
#.idea/

20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
38 changes: 38 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import sys

sys.path.insert(0, os.path.abspath("."))

# 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

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "Automatisk Generalisering"
copyright = "2024, Kartverket"
author = "Kartverket"
release = "0.0.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc", # Add autodoc extension
"sphinx.ext.napoleon", # Uncomment this if you use Google/NumPy style docstrings
"sphinx.ext.viewcode", # Uncomment this to add links to your source code
"sphinx.ext.githubpages", # Add GitHub Pages extension
]


templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "alabaster"
html_static_path = ["_static"]
Empty file added file_manager/__init__.py
Empty file.
Empty file added generalization/__init__.py
Empty file.
Empty file added generalization/n100/__init__.py
Empty file.
35 changes: 35 additions & 0 deletions index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. Automatisk Generalisering documentation master file, created by
sphinx-quickstart on Tue Jan 23 13:29:36 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Automatisk Generalisering's documentation!
=====================================================

.. toctree::
# Start of auto-generated docs
generated_docs/config
generated_docs/custom_tools
generated_docs/env_setup
generated_docs/file_manager.n100
generated_docs/file_manager
generated_docs/generalization.n100.building
generated_docs/generalization.n100
generated_docs/generalization
generated_docs/input_data
generated_docs/modules
# End of auto-generated docs

# Manual documentation below
:maxdepth: 2
:caption: Contents:




Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions update_index_rst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

# Define the directory where auto-generated docs are stored
docs_dir = "generated_docs"
# List of .rst files to ignore
ignore_files = ["conf.rst", "update_index_rst.rst"]

# Gather all .rst files in the specified directory, excluding those in ignore_files
entries = [
" generated_docs/" + f.replace(".rst", "") # Maintain indentation for toctree
for f in os.listdir(docs_dir)
if f.endswith(".rst") and f not in ignore_files
]

# Join the entries with newlines to form the toctree content
toctree_entries = "\n".join(entries) + "\n"

# Open index.rst to read its contents
with open("index.rst", "r") as file:
lines = file.readlines()

# Find where the auto-generated toctree section starts and ends based on markers
start_marker = "# Start of auto-generated docs"
end_marker = "# End of auto-generated docs"
start_line = next(i for i, line in enumerate(lines) if start_marker in line) + 1
end_line = next(i for i, line in enumerate(lines) if end_marker in line)


# Remove existing auto-generated toctree entries
del lines[start_line:end_line]

# Insert the new auto-generated toctree entries
lines[start_line:start_line] = [toctree_entries]

# Write the modified contents back to index.rst
with open("index.rst", "w") as file:
file.writelines(lines)

0 comments on commit 2f4de18

Please sign in to comment.