Skip to content

Commit

Permalink
sphinx auto doc yml deploy test
Browse files Browse the repository at this point in the history
  • Loading branch information
EllingOftedalKV committed Jan 24, 2024
1 parent 6d815ea commit 641c39a
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 5 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/

5 changes: 3 additions & 2 deletions conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
sys.path.insert(0, os.path.abspath('.'))

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

# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -13,7 +14,7 @@
project = "Automatisk Generalisering"
copyright = "2024, Kartverket"
author = "Kartverket"
release = "0.1"
release = "0.0.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
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.
15 changes: 14 additions & 1 deletion index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ 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:

generated_docs/* # Include all .rst files in the 'generated_docs' directory



Expand Down
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 641c39a

Please sign in to comment.