From 2db4a1f448318cede16c712243e89232e92fa07b Mon Sep 17 00:00:00 2001
From: Hannes Feldt <feldt@astron.nl>
Date: Fri, 8 Mar 2024 09:17:38 +0000
Subject: [PATCH] Fix docs

---
 {{cookiecutter.project_slug}}/.gitignore      |  1 +
 {{cookiecutter.project_slug}}/docs/cleanup.py | 23 +++++++++++++++++++
 {{cookiecutter.project_slug}}/docs/cleanup.sh | 14 -----------
 {{cookiecutter.project_slug}}/tox.ini         |  4 +---
 4 files changed, 25 insertions(+), 17 deletions(-)
 create mode 100644 {{cookiecutter.project_slug}}/docs/cleanup.py
 delete mode 100644 {{cookiecutter.project_slug}}/docs/cleanup.sh

diff --git a/{{cookiecutter.project_slug}}/.gitignore b/{{cookiecutter.project_slug}}/.gitignore
index 36bb668..d5c650e 100644
--- a/{{cookiecutter.project_slug}}/.gitignore
+++ b/{{cookiecutter.project_slug}}/.gitignore
@@ -11,6 +11,7 @@ dist
 
 # Documentation
 docs/source/source_documentation
+!docs/source/source_documentation/index.rst
 docs/build
 
 # Setuptools SCM
diff --git a/{{cookiecutter.project_slug}}/docs/cleanup.py b/{{cookiecutter.project_slug}}/docs/cleanup.py
new file mode 100644
index 0000000..3a4508d
--- /dev/null
+++ b/{{cookiecutter.project_slug}}/docs/cleanup.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+#  Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy)
+#  SPDX-License-Identifier: Apache-2.0
+
+import os
+
+file_dir = os.path.dirname(os.path.realpath(__file__))
+
+clean_dir = os.path.join(file_dir, "source", "source_documentation")
+print(f"Cleaning.. {clean_dir}/*")
+
+if not os.path.exists(clean_dir):
+    exit()
+
+for file_name in os.listdir(clean_dir):
+    file = os.path.join(clean_dir, file_name)
+    
+    if file_name == "index.rst":
+        continue
+
+    print(f"Removing.. {file}")
+    os.remove(file)
diff --git a/{{cookiecutter.project_slug}}/docs/cleanup.sh b/{{cookiecutter.project_slug}}/docs/cleanup.sh
deleted file mode 100644
index aac4cef..0000000
--- a/{{cookiecutter.project_slug}}/docs/cleanup.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-FILE_DIR=$(dirname -- "$(readlink -f -- "${0}")")
-
-echo "Cleaning.. ${FILE_DIR}/source/source_documentation/*"
-
-for f in "${FILE_DIR}"/source/source_documentation/*
-do
-
-  case $f in
-    */index.rst) true;;
-    *) echo "Removing.. ${f}"; rm "${f}";;
-  esac
-done
diff --git a/{{cookiecutter.project_slug}}/tox.ini b/{{cookiecutter.project_slug}}/tox.ini
index a469b2d..0fff7af 100644
--- a/{{cookiecutter.project_slug}}/tox.ini
+++ b/{{cookiecutter.project_slug}}/tox.ini
@@ -41,8 +41,6 @@ commands =
     format: {envpython} -m black -v {{cookiecutter.project_slug}} tests
 
 [testenv:docs]
-allowlist_externals =
-    sh
 ; unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise
 setenv =
 deps =
@@ -50,7 +48,7 @@ deps =
     -r{toxinidir}/docs/requirements.txt
 changedir = {toxinidir}
 commands =
-    sh docs/cleanup.sh
+    {envpython} docs/cleanup.py
     sphinx-build -b html docs/source docs/build/html
 
 [testenv:build]
-- 
GitLab