From 6d815ea2db69ac13b4cfad15049dfcf7812aa1fb Mon Sep 17 00:00:00 2001 From: EllingOftedalKV Date: Wed, 24 Jan 2024 08:43:05 +0100 Subject: [PATCH 1/2] sphinx setup test --- Makefile | 20 ++++++++++++++++++++ conf.py | 37 +++++++++++++++++++++++++++++++++++++ index.rst | 22 ++++++++++++++++++++++ make.bat | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 Makefile create mode 100644 conf.py create mode 100644 index.rst create mode 100644 make.bat diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d4bb2cbb --- /dev/null +++ b/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/conf.py b/conf.py new file mode 100644 index 00000000..053e16d8 --- /dev/null +++ b/conf.py @@ -0,0 +1,37 @@ +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.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"] diff --git a/index.rst b/index.rst new file mode 100644 index 00000000..f25321b8 --- /dev/null +++ b/index.rst @@ -0,0 +1,22 @@ +.. 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:: + :maxdepth: 2 + :caption: Contents: + + generated_docs/* # Include all .rst files in the 'generated_docs' directory + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/make.bat b/make.bat new file mode 100644 index 00000000..954237b9 --- /dev/null +++ b/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 From 641c39a35eac8d29f6f1155982ef003af2ce5159 Mon Sep 17 00:00:00 2001 From: EllingOftedalKV Date: Wed, 24 Jan 2024 14:18:57 +0100 Subject: [PATCH 2/2] sphinx auto doc yml deploy test --- .../workflows/sphinx_documentation_build.yml | 41 +++++++++++++++++++ .gitignore | 6 ++- conf.py | 5 ++- file_manager/__init__.py | 0 generalization/__init__.py | 0 generalization/n100/__init__.py | 0 index.rst | 15 ++++++- update_index_rst.py | 37 +++++++++++++++++ 8 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/sphinx_documentation_build.yml create mode 100644 file_manager/__init__.py create mode 100644 generalization/__init__.py create mode 100644 generalization/n100/__init__.py create mode 100644 update_index_rst.py 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)