From 6520d82e4dbd3881606a5739d11ead0b146e1185 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 7 Feb 2023 13:43:32 +0100 Subject: [PATCH] ci: fix helpers doc regen + add auto app resource doc --- .gitlab/ci/doc.gitlab-ci.yml | 9 +++++--- doc/generate_resource_doc.py | 40 +++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.gitlab/ci/doc.gitlab-ci.yml b/.gitlab/ci/doc.gitlab-ci.yml index 528d8f5aa..4f6ea6ba1 100644 --- a/.gitlab/ci/doc.gitlab-ci.yml +++ b/.gitlab/ci/doc.gitlab-ci.yml @@ -13,15 +13,18 @@ generate-helpers-doc: script: - cd doc - python3 generate_helper_doc.py + - python3 generate_resource_doc.py > resources.md - hub clone https://$GITHUB_TOKEN:x-oauth-basic@github.com/YunoHost/doc.git doc_repo - - cp helpers.md doc_repo/pages/06.contribute/10.packaging_apps/11.helpers/packaging_apps_helpers.md + - cp helpers.md doc_repo/pages/06.contribute/10.packaging_apps/80.resources/11.helpers/packaging_apps_helpers.md + - cp resources.md doc_repo/pages/06.contribute/10.packaging_apps/80.resources/15.appresources/packaging_apps_resources.md - cd doc_repo # replace ${CI_COMMIT_REF_NAME} with ${CI_COMMIT_TAG} ? - hub checkout -b "${CI_COMMIT_REF_NAME}" - - hub commit -am "[CI] Helper for ${CI_COMMIT_REF_NAME}" - - hub pull-request -m "[CI] Helper for ${CI_COMMIT_REF_NAME}" -p # GITHUB_USER and GITHUB_TOKEN registered here https://gitlab.com/yunohost/yunohost/-/settings/ci_cd + - hub commit -am "[CI] Update app helpers/resources for ${CI_COMMIT_REF_NAME}" + - hub pull-request -m "[CI] Update app helpers/resources for ${CI_COMMIT_REF_NAME}" -p # GITHUB_USER and GITHUB_TOKEN registered here https://gitlab.com/yunohost/yunohost/-/settings/ci_cd artifacts: paths: - doc/helpers.md + - doc/resources.md only: - tags diff --git a/doc/generate_resource_doc.py b/doc/generate_resource_doc.py index 2063c4ab9..20a9a994d 100644 --- a/doc/generate_resource_doc.py +++ b/doc/generate_resource_doc.py @@ -1,11 +1,41 @@ -from yunohost.utils.resources import AppResourceClassesByType +import ast -resources = sorted(AppResourceClassesByType.values(), key=lambda r: r.priority) +print("""--- +title: App resources +template: docs +taxonomy: + category: docs +routes: + default: '/packaging_apps_resources' +--- -for klass in resources: - doc = klass.__doc__.replace("\n ", "\n") +""") + + +fname = "../src/utils/resources.py" +content = open(fname).read() + +# NB: This magic is because we want to be able to run this script outside of a YunoHost context, +# in which we cant really 'import' the file because it will trigger a bunch of moulinette/yunohost imports... +tree = ast.parse(content) + +ResourceClasses = [c for c in tree.body if isinstance(c, ast.ClassDef) and c.bases and c.bases[0].id == 'AppResource'] + +ResourceDocString = {} + +for c in ResourceClasses: + + assert c.body[1].targets[0].id == "type" + resource_id = c.body[1].value.value + docstring = ast.get_docstring(c) + + ResourceDocString[resource_id] = docstring + + +for resource_id, doc in sorted(ResourceDocString.items()): + doc = doc.replace("\n ", "\n") print("") - print(f"## {klass.type.replace('_', ' ').title()}") + print(f"## {resource_id.replace('_', ' ').title()}") print("") print(doc)