From b541e9b0a136fee5e210832bc47cb90a21ff0630 Mon Sep 17 00:00:00 2001
From: lukken <lukken@astron.nl>
Date: Sat, 25 Mar 2023 10:03:46 +0000
Subject: [PATCH] Enable source code documentation

---
 tangostationcontrol/docs/docs-requirements.txt  |  3 ++-
 tangostationcontrol/docs/source/conf.py         | 17 ++++++++++++++++-
 tangostationcontrol/docs/source/developer.rst   |  5 +++++
 .../docs/source/source_documentation/index.rst  |  7 +++++++
 .../toolkit/udp_simulator.py                    | 13 +++++++------
 5 files changed, 37 insertions(+), 8 deletions(-)
 create mode 100644 tangostationcontrol/docs/source/source_documentation/index.rst

diff --git a/tangostationcontrol/docs/docs-requirements.txt b/tangostationcontrol/docs/docs-requirements.txt
index 3a9106789..756ea268a 100644
--- a/tangostationcontrol/docs/docs-requirements.txt
+++ b/tangostationcontrol/docs/docs-requirements.txt
@@ -1,3 +1,4 @@
 importlib-metadata<2.0.0,>=0.12;python_version<"3.8"
 sphinx>=4.3.2 # BSD
-sphinx-rtd-theme>=1.0.0 # MIT
\ No newline at end of file
+sphinx-rtd-theme>=1.0.0 # MIT
+sphinxcontrib-apidoc>=0.3.0 #BSD
diff --git a/tangostationcontrol/docs/source/conf.py b/tangostationcontrol/docs/source/conf.py
index f1cd59b63..696055140 100644
--- a/tangostationcontrol/docs/source/conf.py
+++ b/tangostationcontrol/docs/source/conf.py
@@ -27,7 +27,22 @@ author = "Stichting ASTRON"
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
-extensions = ["sphinx.ext.graphviz"]
+extensions = [
+    "sphinx.ext.graphviz",
+    "sphinx.ext.autodoc",
+    "sphinx.ext.viewcode",
+    "sphinxcontrib.apidoc",
+]
+
+apidoc_module_dir = "../../tangostationcontrol"
+apidoc_output_dir = "source_documentation"
+apidoc_excluded_paths = []
+apidoc_separate_modules = True
+apidoc_toc_file = False
+# This should include private methods but does not work
+# https://github.com/sphinx-contrib/apidoc/issues/14
+apidoc_extra_args = ["--private"]
+
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ["_templates"]
diff --git a/tangostationcontrol/docs/source/developer.rst b/tangostationcontrol/docs/source/developer.rst
index d3a725740..35df2820f 100644
--- a/tangostationcontrol/docs/source/developer.rst
+++ b/tangostationcontrol/docs/source/developer.rst
@@ -3,6 +3,11 @@ Developer information
 
 This chapter describes key areas useful for developers.
 
+.. toctree::
+   :maxdepth: 2
+
+   source_documentation/index
+
 Docker compose
 -------------------------
 
diff --git a/tangostationcontrol/docs/source/source_documentation/index.rst b/tangostationcontrol/docs/source/source_documentation/index.rst
new file mode 100644
index 000000000..7770d6cb3
--- /dev/null
+++ b/tangostationcontrol/docs/source/source_documentation/index.rst
@@ -0,0 +1,7 @@
+Source code documentation
+=========================
+
+.. toctree::
+   :maxdepth: 3
+
+   tangostationcontrol
diff --git a/tangostationcontrol/tangostationcontrol/toolkit/udp_simulator.py b/tangostationcontrol/tangostationcontrol/toolkit/udp_simulator.py
index a7d41001c..26488aaf7 100644
--- a/tangostationcontrol/tangostationcontrol/toolkit/udp_simulator.py
+++ b/tangostationcontrol/tangostationcontrol/toolkit/udp_simulator.py
@@ -15,10 +15,11 @@ print(f"UDP target port: {UDP_PORT}")
 
 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # create UDP socket
 
-while True:
-    sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))
-    i += 1
-    MESSAGE = "{}".format(i)
+if __name__ == "__main__":
+    while True:
+        sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))
+        i += 1
+        MESSAGE = "{}".format(i)
 
-    # sleep for an arbitrary amount of time. Currently 0.2 settings for visual testing.
-    time.sleep(0.2)
+        # sleep for an arbitrary amount of time. Currently 0.2 settings for visual testing.
+        time.sleep(0.2)
-- 
GitLab