From a7c75c7ee806e735c9f430724bc44eba4d3b6c46 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 07:57:52 +0000 Subject: [PATCH 01/14] First add --- tools/generate_doc_confpy.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index 58f657a1..e60edd1b 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -155,6 +155,34 @@ def process_repositories(args, service): out.write(conf_py_content) repo_to.index.add([doc["rst_location"]]) + + if args.update_sbv: + context = dict( + repo_name=target_repo["repo"], + project=service["service_title"], + # pdf_name=doc["pdf_name"], + title=f"{service['service_title']} - Service Based View", + ) + copy_path = pathlib.Path(copy_to, 'doc', 'source') + print(copy_path) + if not copy_path.exists(): + logging.info("Path for sbv does not exist") + copy_path.parent.mkdir(parents=True, exist_ok=True) + context["otc_sbv"] = True + if git_fqdn: + context["git_fqdn"] = git_fqdn + if target_repo.get("type") != "github": + context["git_type"] = target_repo["type"] + if args.target_environment == "internal": + context["html_options"] = dict( + disable_search=True, + site_name="Internal Documentation Portal", + logo_url="https://docs-int.otc-service.com", + ) + conf_py_content = conf_py_template.render(**context) + with open(pathlib.Path(copy_path, "conf.py"), "w", encoding="utf-8") as out: + out.write(conf_py_content) + if args.update_tox: context = dict(docs=[]) for doc in service_docs: @@ -265,6 +293,11 @@ def main(): ) parser.add_argument("--token", metavar="token", help="API token") parser.add_argument("--api-url", help="API base url of the Git hoster") + parser.add_argument( + "--update_sbv", + action="store_true", + help="Whether to update service-based-view" + ) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG) -- 2.34.1 From c597690ecd3687801644462f11fa7677d024eaea Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 08:30:44 +0000 Subject: [PATCH 02/14] Updated confpy template and tool --- otc_metadata/templates/conf.py.j2 | 6 +++++- tools/generate_doc_confpy.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/otc_metadata/templates/conf.py.j2 b/otc_metadata/templates/conf.py.j2 index 859d3b87..12a83c93 100644 --- a/otc_metadata/templates/conf.py.j2 +++ b/otc_metadata/templates/conf.py.j2 @@ -17,8 +17,12 @@ import os import sys + extensions = [ - 'otcdocstheme' + 'otcdocstheme', +{%- if otc_sbv %} + 'otc_sphinx_directives' +{%- endif %} ] otcdocs_auto_name = False diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index e60edd1b..c3de76d3 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -164,10 +164,9 @@ def process_repositories(args, service): title=f"{service['service_title']} - Service Based View", ) copy_path = pathlib.Path(copy_to, 'doc', 'source') - print(copy_path) if not copy_path.exists(): logging.info("Path for sbv does not exist") - copy_path.parent.mkdir(parents=True, exist_ok=True) + copy_path.mkdir(parents=True, exist_ok=True) context["otc_sbv"] = True if git_fqdn: context["git_fqdn"] = git_fqdn @@ -180,8 +179,12 @@ def process_repositories(args, service): logo_url="https://docs-int.otc-service.com", ) conf_py_content = conf_py_template.render(**context) - with open(pathlib.Path(copy_path, "conf.py"), "w", encoding="utf-8") as out: + with open( + pathlib.Path(copy_path, "conf.py"), + "w", + encoding="utf-8") as out: out.write(conf_py_content) + repo_to.index.add(pathlib.Path(copy_path, "conf.py")) if args.update_tox: context = dict(docs=[]) @@ -294,8 +297,8 @@ def main(): parser.add_argument("--token", metavar="token", help="API token") parser.add_argument("--api-url", help="API base url of the Git hoster") parser.add_argument( - "--update_sbv", - action="store_true", + "--update-sbv", + action="store_true", help="Whether to update service-based-view" ) -- 2.34.1 From 756aac375024350ccf5cb0d6a39f3149510213c3 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 09:53:29 +0000 Subject: [PATCH 03/14] New template --- otc_metadata/templates/index_sbv.rst.j2 | 7 +++++++ tools/generate_doc_confpy.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 otc_metadata/templates/index_sbv.rst.j2 diff --git a/otc_metadata/templates/index_sbv.rst.j2 b/otc_metadata/templates/index_sbv.rst.j2 new file mode 100644 index 00000000..1ac62966 --- /dev/null +++ b/otc_metadata/templates/index_sbv.rst.j2 @@ -0,0 +1,7 @@ +{{ sbv_title }} + +.. directive_wrapper:: + :class: container-sbv + + .. service_card:: + :service_type: {{ service_type }} \ No newline at end of file diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index c3de76d3..bf0e53e8 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -48,8 +48,10 @@ def process_repositories(args, service): env = Environment( loader=PackageLoader("otc_metadata"), autoescape=select_autoescape() ) + print(env.list_templates()) conf_py_template = env.get_template("conf.py.j2") tox_ini_template = env.get_template("tox.ini.j2") + index_sbv_template = env.get_template("index_sbv.rst.j2") doc_requirements_template = env.get_template("doc_requirements.txt.j2") for repo in service["repositories"]: @@ -162,6 +164,7 @@ def process_repositories(args, service): project=service["service_title"], # pdf_name=doc["pdf_name"], title=f"{service['service_title']} - Service Based View", + service_type=service["service_type"] ) copy_path = pathlib.Path(copy_to, 'doc', 'source') if not copy_path.exists(): @@ -178,13 +181,22 @@ def process_repositories(args, service): site_name="Internal Documentation Portal", logo_url="https://docs-int.otc-service.com", ) + sbv_title = (service["service_title"] + "\n" + ('=' * len(service["service_title"]))) + content["sbv_title"] = sbv_title conf_py_content = conf_py_template.render(**context) + index_sbv_content = index_sbv_template.render(**content) with open( pathlib.Path(copy_path, "conf.py"), "w", encoding="utf-8") as out: out.write(conf_py_content) + with open( + pathlib.Path(copy_path, "index.rst"), + "w", + encoding="utf-8") as out: + out.write(index_sbv_content) repo_to.index.add(pathlib.Path(copy_path, "conf.py")) + repo_to.index.add(pathlib.Path(copy_path, "index.rst")) if args.update_tox: context = dict(docs=[]) -- 2.34.1 From da72a366e230c4e6b95697cafe91c85b98e249eb Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 09:56:11 +0000 Subject: [PATCH 04/14] New line at end of file --- otc_metadata/templates/index_sbv.rst.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otc_metadata/templates/index_sbv.rst.j2 b/otc_metadata/templates/index_sbv.rst.j2 index 1ac62966..1ef5b688 100644 --- a/otc_metadata/templates/index_sbv.rst.j2 +++ b/otc_metadata/templates/index_sbv.rst.j2 @@ -4,4 +4,4 @@ :class: container-sbv .. service_card:: - :service_type: {{ service_type }} \ No newline at end of file + :service_type: {{ service_type }} -- 2.34.1 From 44c6d17aad7285fb62f16adf72171184422e96af Mon Sep 17 00:00:00 2001 From: tischrei Date: Tue, 18 Apr 2023 10:11:03 +0000 Subject: [PATCH 05/14] fix typos --- tools/generate_doc_confpy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index bf0e53e8..3f1d7aac 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -182,9 +182,9 @@ def process_repositories(args, service): logo_url="https://docs-int.otc-service.com", ) sbv_title = (service["service_title"] + "\n" + ('=' * len(service["service_title"]))) - content["sbv_title"] = sbv_title + context["sbv_title"] = sbv_title conf_py_content = conf_py_template.render(**context) - index_sbv_content = index_sbv_template.render(**content) + index_sbv_content = index_sbv_template.render(**context) with open( pathlib.Path(copy_path, "conf.py"), "w", -- 2.34.1 From 6fa5c76e94fbcc4b4b053b35ab00dd8508b7eb37 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 11:41:06 +0000 Subject: [PATCH 06/14] Added check for index.rst --- tools/generate_doc_confpy.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index 3f1d7aac..0856a74f 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -159,6 +159,7 @@ def process_repositories(args, service): repo_to.index.add([doc["rst_location"]]) if args.update_sbv: + copy_path = pathlib.Path(copy_to, 'doc', 'source') context = dict( repo_name=target_repo["repo"], project=service["service_title"], @@ -166,7 +167,6 @@ def process_repositories(args, service): title=f"{service['service_title']} - Service Based View", service_type=service["service_type"] ) - copy_path = pathlib.Path(copy_to, 'doc', 'source') if not copy_path.exists(): logging.info("Path for sbv does not exist") copy_path.mkdir(parents=True, exist_ok=True) @@ -190,13 +190,18 @@ def process_repositories(args, service): "w", encoding="utf-8") as out: out.write(conf_py_content) - with open( - pathlib.Path(copy_path, "index.rst"), - "w", - encoding="utf-8") as out: - out.write(index_sbv_content) repo_to.index.add(pathlib.Path(copy_path, "conf.py")) - repo_to.index.add(pathlib.Path(copy_path, "index.rst")) + + if not args.overwrite_index_sbv and pathlib.Path(copy_path, "index.rst").exists(): + logging.info("File index.rst for sbv exists. Skipping") + else: + with open( + pathlib.Path(copy_path, "index.rst"), + "w", + encoding="utf-8") as out: + out.write(index_sbv_content) + repo_to.index.add(pathlib.Path(copy_path, "index.rst")) + if args.update_tox: context = dict(docs=[]) @@ -313,6 +318,11 @@ def main(): action="store_true", help="Whether to update service-based-view" ) + parser.add_argument( + "--overwrite-index-sbv", + action="store_true", + help="Whether to overwrite index.rst for service-based-view" + ) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG) -- 2.34.1 From 389bc4bdaa1451da4b92a17ad892d632bfc61d3d Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 11:49:25 +0000 Subject: [PATCH 07/14] Fix pep8 and placeholder --- tools/generate_doc_confpy.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index 0856a74f..ce29a8dc 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -181,7 +181,8 @@ def process_repositories(args, service): site_name="Internal Documentation Portal", logo_url="https://docs-int.otc-service.com", ) - sbv_title = (service["service_title"] + "\n" + ('=' * len(service["service_title"]))) + sbv_title = (service["service_title"] + "\n" + + ('=' * len(service["service_title"]))) context["sbv_title"] = sbv_title conf_py_content = conf_py_template.render(**context) index_sbv_content = index_sbv_template.render(**context) @@ -192,7 +193,8 @@ def process_repositories(args, service): out.write(conf_py_content) repo_to.index.add(pathlib.Path(copy_path, "conf.py")) - if not args.overwrite_index_sbv and pathlib.Path(copy_path, "index.rst").exists(): + if (not args.overwrite_index_sbv + and pathlib.Path(copy_path, "index.rst").exists()): logging.info("File index.rst for sbv exists. Skipping") else: with open( @@ -201,7 +203,11 @@ def process_repositories(args, service): encoding="utf-8") as out: out.write(index_sbv_content) repo_to.index.add(pathlib.Path(copy_path, "index.rst")) - + + placeholder_path = pathlib.Path(copy_path, "_static") + if not placeholder_path.exists(): + placeholder_path.mkdir(parents=True, exist_ok=True) + open(pathlib.Path(placeholder_path, ".placeholder"), 'a').close() if args.update_tox: context = dict(docs=[]) -- 2.34.1 From b6cb96297416e9054cbf665f5c592e3a463e2954 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 11:59:28 +0000 Subject: [PATCH 08/14] Placeholder fix --- tools/generate_doc_confpy.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index ce29a8dc..ffd2eb6b 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -205,9 +205,10 @@ def process_repositories(args, service): repo_to.index.add(pathlib.Path(copy_path, "index.rst")) placeholder_path = pathlib.Path(copy_path, "_static") - if not placeholder_path.exists(): + if not pathlib.Path(placeholder_path, "placeholder").exists(): placeholder_path.mkdir(parents=True, exist_ok=True) - open(pathlib.Path(placeholder_path, ".placeholder"), 'a').close() + open(pathlib.Path(placeholder_path, "placeholder"), 'a').close() + repo_to.index.add(pathlib.Path(placeholder_path, "placeholder")) if args.update_tox: context = dict(docs=[]) -- 2.34.1 From ebe96bb99089762e94f8176b2f0c1d252efa8671 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 12:01:18 +0000 Subject: [PATCH 09/14] Removed print statement --- tools/generate_doc_confpy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index ffd2eb6b..b5d170f3 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -48,7 +48,6 @@ def process_repositories(args, service): env = Environment( loader=PackageLoader("otc_metadata"), autoescape=select_autoescape() ) - print(env.list_templates()) conf_py_template = env.get_template("conf.py.j2") tox_ini_template = env.get_template("tox.ini.j2") index_sbv_template = env.get_template("index_sbv.rst.j2") -- 2.34.1 From 06a441314d85fd46d406c815738cc13e22d68458 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 12:12:58 +0000 Subject: [PATCH 10/14] Function description --- tools/generate_doc_confpy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index b5d170f3..6a0e3bfd 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -158,6 +158,7 @@ def process_repositories(args, service): repo_to.index.add([doc["rst_location"]]) if args.update_sbv: + """Add or update service-based-view""" copy_path = pathlib.Path(copy_to, 'doc', 'source') context = dict( repo_name=target_repo["repo"], @@ -210,6 +211,7 @@ def process_repositories(args, service): repo_to.index.add(pathlib.Path(placeholder_path, "placeholder")) if args.update_tox: + """Update tox.ini""" context = dict(docs=[]) for doc in service_docs: if doc["type"] == "dev": -- 2.34.1 From 72c9a15f1368768bd49ca912b9de579d75dbb9d7 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 12:15:56 +0000 Subject: [PATCH 11/14] Update tox --- otc_metadata/templates/tox.ini.j2 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/otc_metadata/templates/tox.ini.j2 b/otc_metadata/templates/tox.ini.j2 index f8316308..e6ecf9d4 100644 --- a/otc_metadata/templates/tox.ini.j2 +++ b/otc_metadata/templates/tox.ini.j2 @@ -29,7 +29,11 @@ allowlist_externals = mkdir cp sh + rm + sphinx-build commands = + rm -rf doc/build/html doc/build/doctrees + sphinx-build -a -E -W -d doc/build/doctrees -b html doc/source doc/build/html {%- for doc in docs %} {[testenv:{{ doc.type }}]commands} {[testenv:json-{{ doc.type }}]commands} @@ -115,3 +119,7 @@ commands = cp {{ loc }}/build/pdf/{{ doc.pdf_name }}.pdf doc/build/pdf/ {% endif %} {% endfor %} + +[doc8] +ignore = D001 +extensions = .rst, .yaml \ No newline at end of file -- 2.34.1 From 64106b035fb7f25ca668552fd92d2ab61c45dc62 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 12:25:30 +0000 Subject: [PATCH 12/14] Update requirements --- otc_metadata/templates/doc_requirements.txt.j2 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/otc_metadata/templates/doc_requirements.txt.j2 b/otc_metadata/templates/doc_requirements.txt.j2 index a61c7060..ea0c4dee 100644 --- a/otc_metadata/templates/doc_requirements.txt.j2 +++ b/otc_metadata/templates/doc_requirements.txt.j2 @@ -2,3 +2,6 @@ sphinx>=2.0.0,!=2.1.0 # BSD otcdocstheme # Apache-2.0 # releasenotes reno>=3.1.0 # Apache-2.0 + +otc-sphinx-directives>=0.1.0 +git+https://gitea.eco.tsi-dev.otc-service.com/infra/otc-metadata.git#egg=otc_metadata \ No newline at end of file -- 2.34.1 From b9d73eb4419b2ff16fad8a11aaac9ba79be6ccfb Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 20 Apr 2023 07:17:23 +0000 Subject: [PATCH 13/14] Better description --- tools/generate_doc_confpy.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index 6a0e3bfd..31870e3b 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -329,12 +329,19 @@ def main(): parser.add_argument( "--overwrite-index-sbv", action="store_true", - help="Whether to overwrite index.rst for service-based-view" + help=("Whether to overwrite index.rst for service-based-view." + + "\nCan only be used if --update-sbv is also specified") ) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG) services = [] + if args.overwrite_index_sbv and not args.update_sbv: + logging.error( + "Cannot overwrite index.rst for service-based-view" + + " without updating service-based-view" + ) + exit(1) if args.service_type: services = [data.service_dict.get(args.service_type)] else: -- 2.34.1 From eb0901582951e5861f87160875c6c0879518ef27 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 20 Apr 2023 12:33:55 +0000 Subject: [PATCH 14/14] Removed empty line --- otc_metadata/templates/conf.py.j2 | 1 - 1 file changed, 1 deletion(-) diff --git a/otc_metadata/templates/conf.py.j2 b/otc_metadata/templates/conf.py.j2 index 12a83c93..3228eec8 100644 --- a/otc_metadata/templates/conf.py.j2 +++ b/otc_metadata/templates/conf.py.j2 @@ -17,7 +17,6 @@ import os import sys - extensions = [ 'otcdocstheme', {%- if otc_sbv %} -- 2.34.1