From f1caa2050c84ca52f5c5d2a202c7ca472fb19099 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sat, 16 Aug 2025 15:38:15 +0200 Subject: [PATCH] Change to new Make concept --- .gitmodules | 18 +-- _static/.gitkeep => .venv_required | 0 Makefile | 178 ++++++++++++++++++++--------- __make.d__/docs.mk | 28 +++++ caching | 1 - conf.py | 10 +- fstools | 1 - helpers | 1 - pylibs/caching | 1 + pylibs/fstools | 1 + pylibs/helpers | 1 + pylibs/report | 1 + pylibs/socket_protocol | 1 + pylibs/state_machine | 1 + pylibs/stringtools | 1 + pylibs/task | 1 + pylibs/tcp_socket | 1 + report | 1 - socket_protocol | 1 - state_machine | 1 - stringtools | 1 - task | 1 - tcp_socket | 1 - 23 files changed, 174 insertions(+), 78 deletions(-) rename _static/.gitkeep => .venv_required (100%) create mode 100644 __make.d__/docs.mk delete mode 160000 caching delete mode 160000 fstools delete mode 160000 helpers create mode 160000 pylibs/caching create mode 160000 pylibs/fstools create mode 160000 pylibs/helpers create mode 160000 pylibs/report create mode 160000 pylibs/socket_protocol create mode 160000 pylibs/state_machine create mode 160000 pylibs/stringtools create mode 160000 pylibs/task create mode 160000 pylibs/tcp_socket delete mode 160000 report delete mode 160000 socket_protocol delete mode 160000 state_machine delete mode 160000 stringtools delete mode 160000 task delete mode 160000 tcp_socket diff --git a/.gitmodules b/.gitmodules index 94e050f..fdb5616 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,27 +1,27 @@ [submodule "state_machine"] - path = state_machine + path = pylibs/state_machine url = https://git.mount-mockery.de/pylib/state_machine [submodule "socket_protocol"] - path = socket_protocol + path = pylibs/socket_protocol url = https://git.mount-mockery.de/pylib/socket_protocol [submodule "stringtools"] - path = stringtools + path = pylibs/stringtools url = https://git.mount-mockery.de/pylib/stringtools [submodule "report"] - path = report + path = pylibs/report url = https://git.mount-mockery.de/pylib/report [submodule "task"] - path = task + path = pylibs/task url = https://git.mount-mockery.de/pylib/task [submodule "caching"] - path = caching + path = pylibs/caching url = https://git.mount-mockery.de/pylib/caching [submodule "tcp_socket"] - path = tcp_socket + path = pylibs/tcp_socket url = https://git.mount-mockery.de/pylib/tcp_socket [submodule "fstools"] - path = fstools + path = pylibs/fstools url = https://git.mount-mockery.de/pylib/fstools [submodule "helpers"] - path = helpers + path = pylibs/helpers url = https://git.mount-mockery.de/pylib/helpers diff --git a/_static/.gitkeep b/.venv_required similarity index 100% rename from _static/.gitkeep rename to .venv_required diff --git a/Makefile b/Makefile index b57767f..1503a9f 100644 --- a/Makefile +++ b/Makefile @@ -1,67 +1,133 @@ -# Minimal makefile for Sphinx documentation -# +# git helper Makefile: Version 2.5 (2025-08-11) +default: help -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = venv/bin/sphinx-build -SOURCEDIR = . -BUILDDIR = _build -MODULES = $(sort \ - caching\ - fstools\ - helpers\ - socket_protocol\ - state_machine\ - stringtools\ - stringtools.csp\ - stringtools.stp\ - task\ - tcp_socket\ -) +.ONESHELL: +SHELL = /usr/bin/bash +MAKEFLAGS += --no-print-directory +.SILENT: -# Put it first so that "make" without argument is like "make help". +-include __make.d__/*.mk -.PHONY: all help Makefile +GIT_FLAG = ./.git +VENV_FLAG = ./.venv_required +VENV_FOLDER = ./venv -all: index.rst $(MODULES) html +localhelp: help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + echo "Possible common options are:" + echo " - init - Initialise the repository and all folders below with a Makefile" + echo " - giti - Get the git status of all submodules including their submodules" + echo " - update_submodules - Set all submodules to remote master" + echo " - venv_flag - Set the venev flag for the base folder. A venv will be generated" + echo " - clean - clean up" + echo " - deepclean - clean up this and all Makefiles below" + $(MAKE) localhelp + echo "You are able to create files make.d/*.mk and add local rules there. " + echo " - localinit: print_head - Will be executed as last step in the init process." + echo " - localhelp: print_head - Will be executed in th middle of the help text generation" + echo " - localclean:print_head - Will be executed before the clean rule" -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -html: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +localinit: -clean: Makefile - rm -f *.rst - @for module in $(MODULES) ; do \ - if [ -d "$$module/_examples_" ]; then make --no-print-directory -C $$module/_examples_ clean; fi \ - done - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -index.rst: Makefile - @echo Generating $@ - @echo "Indices and tables\n==================\n\n* :ref:\`genindex\`\n* :ref:\`modindex\`\n* :ref:\`search\`\n" > $@ - @echo "Modules\n=======\n\n.. toctree::\n :maxdepth: 2\n" >> $@ - -%: Makefile - @echo "Preparing $@" - @echo ".. automodule:: $@\n :members:" > $@.rst - @if [ "$(findstring .,$@)" != "." ]; then \ - git -C $@ checkout master 2>&1; \ - git -C $@ pull 2>&1;\ - make -C $@/_examples_ all; \ +init: print_head + # Init git repo + if [[ -e $(GIT_FLAG) ]]; then + echo -e "\033[1;33mInitialising git submodules...\e[0m" + git submodule init + git submodule update + echo fi - @echo " $@.rst" >> index.rst; \ + # Init submodules + SUBDIRS=$$(find . -maxdepth 2 -mindepth 2 -name Makefile | sort) + for subdir in $$SUBDIRS; do + $(MAKE) --no-print-directory -C $$(dirname $$subdir) init + done + if [[ $$SUBDIRS = *[![:space:]]* ]]; then + $(MAKE) print_head + fi + # Create venv if needed + if [[ -e $(VENV_FLAG) ]]; then + BASEPATH=$$(pwd -P) + # + # Create venv + # + if [ ! -e venv ];then + echo -e "\033[1;33mCreating venv in $$BASEPATH...\e[0m" + python3 -m venv $$BASEPATH/venv > /dev/null 2>&1 + else + echo -e "\033[1;33mVirtualenv already exists in $$BASEPATH...\e[0m" + fi + echo -update: - git pull - git submodule init - git submodule update - git submodule foreach git checkout master - git submodule foreach git pull + # + # Install modules + # + echo -e "\033[1;33mInstalling modules to venv in $$BASEPATH...\e[0m" + for req_file in $$(find -L $$BASEPATH -name requirements.txt 2> /dev/null); do + # echo " $$req_file" + while read req_mod; do + if [[ $$req_mod = *[![:space:]]* ]]; then + # req_mod is not empty + OUT=$$($$BASEPATH/venv/bin/pip install -U $$req_mod 2>&1 ) + if [[ $$OUT =~ "Successfully installed" ]]; then + echo -e " * \033[1;32m$$req_mod installed.\e[0m" + elif [[ $$OUT =~ "already satisfied" ]]; then + echo -e " * \033[1;36m$$req_mod already installed.\e[0m" + else + echo -e " * \033[1;31m$$req_mod installation FAILED!\e[0m" + #echo $$OUT + fi + fi + done < $$req_file + done + echo + fi + # Start local init + echo -e "\033[1;33mDoing localinit...\e[0m" + $(MAKE) localinit -copy: - rsync -av --delete _build/html/ /data/docker/apache/pylib_docs - chown www-data.www-data -R /data/docker/apache/pylib_docs +update_submodules: + git submodule foreach "git fetch && git checkout master && git pull && git submodule init && git submodule update" + +giti_this: print_head + giti + echo " Submodules:" + git submodule --quiet foreach "echo -n ' ' && giti" + +giti: + git submodule --quiet foreach "[ -e Makefile ] && make --no-print-directory giti_this || :" + +localclean: + +clean: localclean + if [[ ! -e $(VENV_FLAG) ]]; then + if [[ -d $(VENV_FOLDER) ]]; then + rm -rf $(VENV_FOLDER) + fi + fi + +cleanall: clean + for subdir in $$(find . -maxdepth 2 -mindepth 2 -name Makefile | sort); do + $(MAKE) --no-print-directory -C $$(dirname $$subdir) cleanall + done + + +venv_flag: + if [[ ! -e $(VENV_FLAG) ]]; then + touch $(VENV_FLAG) + if [[ -e $(GIT_FLAG) ]]; then + git add $(VENV_FLAG) + fi + fi + +print_head: + DIRNAME=$$(basename $$(pwd)) + DIRLENGTH=$${#DIRNAME} + echo -ne "\n\n\033[1;34m╔═" + for i in $$(seq 1 $$DIRLENGTH); do echo -n "═"; done + echo -e "═╗" + echo -e "║ $$DIRNAME ║" + echo -ne "╚═" + for i in $$(seq 1 $$DIRLENGTH); do echo -n "═"; done + echo -e "═╝\033[00m" diff --git a/__make.d__/docs.mk b/__make.d__/docs.mk new file mode 100644 index 0000000..87288bb --- /dev/null +++ b/__make.d__/docs.mk @@ -0,0 +1,28 @@ +SPHINXBUILD = venv/bin/sphinx-build +SPHINXAPIDOC = venv/bin/sphinx-apidoc +SOURCEDIR = pylibs +BUILDDIR = _build + +all: html + +pylibs/modules.rst: + $(SPHINXAPIDOC) -Mo $(SOURCEDIR) $(SOURCEDIR) + +examples: + for d in $$(find pylibs/**/_examples_ -name Makefile -exec dirname {} \;); do make -C $$d; done + +html: pylibs/modules.rst examples + @$(SPHINXBUILD) --conf-dir . "$(SOURCEDIR)" "$(BUILDDIR)" + +localclean: + rm -f $(SOURCEDIR)/*.rst + rm -rf $(BUILDDIR)/* + for d in $$(find pylibs/**/_examples_ -name Makefile -exec dirname {} \;); do make -C $$d clean; done + +update: + git pull + $(MAKE) update_submodules + +copy: + rsync -av --delete $(BUILDDIR)/ /data/docker/apache/pylib_docs + chown www-data.www-data -R /data/docker/apache/pylib_docs diff --git a/caching b/caching deleted file mode 160000 index 9a1fa9e..0000000 --- a/caching +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9a1fa9e0ab586f228b5614747a1953f36fb03793 diff --git a/conf.py b/conf.py index d3787a1..b76af91 100644 --- a/conf.py +++ b/conf.py @@ -14,7 +14,7 @@ # import os import sys -sys.path.insert(0, os.path.abspath('.')) +sys.path.insert(0, os.path.abspath('./pylibs')) # -- Project information ----------------------------------------------------- @@ -54,14 +54,14 @@ templates_path = ['_templates'] source_suffix = '.rst' # The master toctree document. -master_doc = 'index' +master_doc = 'modules' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -88,7 +88,9 @@ html_theme = 'python_docs_theme' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +# +# html_static_path = ['_static'] +html_static_path = [] # Custom sidebar templates, must be a dictionary that maps document names # to template names. diff --git a/fstools b/fstools deleted file mode 160000 index 9237f6f..0000000 --- a/fstools +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9237f6f7f77eed79b8163077c1b4d87189193fbe diff --git a/helpers b/helpers deleted file mode 160000 index c4f0551..0000000 --- a/helpers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c4f055189856dddf9f05c56189453370d25ba620 diff --git a/pylibs/caching b/pylibs/caching new file mode 160000 index 0000000..3d79e80 --- /dev/null +++ b/pylibs/caching @@ -0,0 +1 @@ +Subproject commit 3d79e803f62d92b860d4f8241ed2e8e1f7c16934 diff --git a/pylibs/fstools b/pylibs/fstools new file mode 160000 index 0000000..ef8d79b --- /dev/null +++ b/pylibs/fstools @@ -0,0 +1 @@ +Subproject commit ef8d79b1871839b662aa823c30ce912580995265 diff --git a/pylibs/helpers b/pylibs/helpers new file mode 160000 index 0000000..9b04dc4 --- /dev/null +++ b/pylibs/helpers @@ -0,0 +1 @@ +Subproject commit 9b04dc44607422052acc78d7cf191d1a43fcded6 diff --git a/pylibs/report b/pylibs/report new file mode 160000 index 0000000..a7fd940 --- /dev/null +++ b/pylibs/report @@ -0,0 +1 @@ +Subproject commit a7fd9404aa9fb3c977e38bee6aa6c794dbb04b1d diff --git a/pylibs/socket_protocol b/pylibs/socket_protocol new file mode 160000 index 0000000..449086b --- /dev/null +++ b/pylibs/socket_protocol @@ -0,0 +1 @@ +Subproject commit 449086b7c2f4055b409ef61301d36fbceef3aa4f diff --git a/pylibs/state_machine b/pylibs/state_machine new file mode 160000 index 0000000..2653d49 --- /dev/null +++ b/pylibs/state_machine @@ -0,0 +1 @@ +Subproject commit 2653d49a3e1eec2dec148b2eb77f83b1b3b9c176 diff --git a/pylibs/stringtools b/pylibs/stringtools new file mode 160000 index 0000000..9054a66 --- /dev/null +++ b/pylibs/stringtools @@ -0,0 +1 @@ +Subproject commit 9054a66a6d8a5ffbac4c729b476da4c5102d186d diff --git a/pylibs/task b/pylibs/task new file mode 160000 index 0000000..93ada5f --- /dev/null +++ b/pylibs/task @@ -0,0 +1 @@ +Subproject commit 93ada5fc6d4f945fbc7d5533465b13b7a951f976 diff --git a/pylibs/tcp_socket b/pylibs/tcp_socket new file mode 160000 index 0000000..d8683e0 --- /dev/null +++ b/pylibs/tcp_socket @@ -0,0 +1 @@ +Subproject commit d8683e060658ad6da5a3b1e62b29842536737483 diff --git a/report b/report deleted file mode 160000 index 7003c13..0000000 --- a/report +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7003c13ef8c7e7c3a55a545cbbad4039cc024a9f diff --git a/socket_protocol b/socket_protocol deleted file mode 160000 index 7f2b90c..0000000 --- a/socket_protocol +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7f2b90c99030ac39f5bf7bfd92d1dd3d6c3657fa diff --git a/state_machine b/state_machine deleted file mode 160000 index aef9958..0000000 --- a/state_machine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit aef99580e1cdc05e6ca80efe05461ab861d6ef39 diff --git a/stringtools b/stringtools deleted file mode 160000 index e1f76d9..0000000 --- a/stringtools +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e1f76d96312e540544b2328d0937b0aa41126aa9 diff --git a/task b/task deleted file mode 160000 index af35e83..0000000 --- a/task +++ /dev/null @@ -1 +0,0 @@ -Subproject commit af35e83d1f07fd4cb9070bdb77cf1f3bdda3a463 diff --git a/tcp_socket b/tcp_socket deleted file mode 160000 index 72741ff..0000000 --- a/tcp_socket +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 72741ff81280a19c728cbc151f8b3b083220130e