diff --git a/.github/workflows/sphinx_documentation_build.yml b/.github/workflows/sphinx_documentation_build.yml new file mode 100644 index 00000000..99f4c1a7 --- /dev/null +++ b/.github/workflows/sphinx_documentation_build.yml @@ -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 diff --git a/.gitignore b/.gitignore index 7c8b1422..50196105 100644 --- a/.gitignore +++ b/.gitignore @@ -112,7 +112,8 @@ instance/ .scrapy # Sphinx documentation -docs/_build/ +_build/ +/generated_docs/ # PyBuilder .pybuilder/ @@ -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/ \ No newline at end of file +#.idea/ + diff --git a/conf.py b/conf.py index 053e16d8..e32916f3 100644 --- a/conf.py +++ b/conf.py @@ -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. # @@ -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 diff --git a/file_manager/__init__.py b/file_manager/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/generalization/__init__.py b/generalization/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/generalization/n100/__init__.py b/generalization/n100/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/index.rst b/index.rst index f25321b8..b39c998f 100644 --- a/index.rst +++ b/index.rst @@ -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 diff --git a/update_index_rst.py b/update_index_rst.py new file mode 100644 index 00000000..4b34e557 --- /dev/null +++ b/update_index_rst.py @@ -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)