From 661d240cd939d1e63f36fbfa044a429b870133dc Mon Sep 17 00:00:00 2001 From: Robert Niederreiter Date: Tue, 18 Jun 2024 09:06:53 +0200 Subject: [PATCH] Implement proxy target geeration --- src/mxmake/templates.py | 26 ++++++++-- src/mxmake/templates/Makefile | 4 ++ src/mxmake/templates/proxy.mk | 10 ++++ src/mxmake/tests/test_templates.py | 67 ++++++++++++++++++++----- src/mxmake/topics/applications/plone.mk | 6 ++- src/mxmake/topics/core/proxy.mk | 29 +++++++++++ 6 files changed, 123 insertions(+), 19 deletions(-) create mode 100644 src/mxmake/templates/proxy.mk create mode 100644 src/mxmake/topics/core/proxy.mk diff --git a/src/mxmake/templates.py b/src/mxmake/templates.py index 1380587..deb67ac 100644 --- a/src/mxmake/templates.py +++ b/src/mxmake/templates.py @@ -1,6 +1,7 @@ from jinja2 import Environment from jinja2 import PackageLoader from mxmake.topics import Domain +from mxmake.topics import get_topic from mxmake.topics import load_topics from mxmake.utils import gh_actions_path from mxmake.utils import mxmake_files @@ -277,7 +278,6 @@ def template_variables(self) -> typing.Dict[str, typing.Any]: additional_targets = {} topics = {domain.topic for domain in self.domains} additional_targets["qa"] = "qa" in topics - # additional_targets["docs"] = "docs" in topics # return template variables return dict( settings=settings, @@ -544,7 +544,23 @@ def target_folder(self) -> Path: @property def template_variables(self): - targets = {} - for key, value in self.settings.items(): - ... - return targets + targets = [] + for folder, proxy in self.settings.items(): + for item in [item.strip() for item in proxy.split('\n') if item.strip()]: + topic_name, domain_names = item.split(':') + topic = get_topic(topic_name.strip()) + domain_names = domain_names.split(',') + domains = [] + for domain_name in domain_names: + if domain_name == '*': + domains = topic.domains + break + else: + domains.append(topic.domain(domain_name.strip())) + for domain in domains: + for target in domain.targets: + targets.append(dict( + name=target.name, + folder=folder + )) + return dict(targets=targets) diff --git a/src/mxmake/templates/Makefile b/src/mxmake/templates/Makefile index 5136b99..733b3ec 100644 --- a/src/mxmake/templates/Makefile +++ b/src/mxmake/templates/Makefile @@ -39,6 +39,10 @@ TYPECHECK_TARGETS?= FORMAT_TARGETS?= {% endif %} {{ sections.read() }} +############################################################################## +# Custom includes +############################################################################## + -include $(INCLUDE_MAKEFILE) ############################################################################## diff --git a/src/mxmake/templates/proxy.mk b/src/mxmake/templates/proxy.mk new file mode 100644 index 0000000..b1b36d8 --- /dev/null +++ b/src/mxmake/templates/proxy.mk @@ -0,0 +1,10 @@ +############################################################################## +# proxy targets +############################################################################## + +{% for target in targets %} +.PHONY: {{ target["folder"] }}-{{ target["name"] }} +{{ target["folder"] }}-{{ target["name"] }}: + $(MAKE) -C "./{{ target["folder"] }}/" {{ target["name"] }} + +{% endfor %} \ No newline at end of file diff --git a/src/mxmake/tests/test_templates.py b/src/mxmake/tests/test_templates.py index 28470ba..4aa1443 100644 --- a/src/mxmake/tests/test_templates.py +++ b/src/mxmake/tests/test_templates.py @@ -741,6 +741,10 @@ def test_Makefile(self, tempdir): DIRTY_TARGETS+=mxenv-dirty CLEAN_TARGETS+=mxenv-clean + ############################################################################## + # Custom includes + ############################################################################## + -include $(INCLUDE_MAKEFILE) ############################################################################## @@ -931,10 +935,9 @@ def test_ProxyMk(self, tempdir): "[settings]\n" "\n" "[mxmake-proxy]\n" - "folder1 = *\n" - "folder2 =\n" - " applications.plone\n" - " i18n-lingua\n" + "folder =\n" + " applications:plone\n" + " i18n:*\n" ) configuration = mxdev.Configuration(mxini, hooks=[hook.Hook()]) factory = templates.template.lookup("proxy") @@ -946,13 +949,53 @@ def test_ProxyMk(self, tempdir): self.assertEqual(template.template_name, "proxy.mk") self.assertEqual( template.template_variables, - {} + {'targets': [ + {'name': 'plone-site-create', 'folder': 'folder'}, + {'name': 'plone-site-purge', 'folder': 'folder'}, + {'name': 'gettext-create', 'folder': 'folder'}, + {'name': 'gettext-update', 'folder': 'folder'}, + {'name': 'gettext-compile', 'folder': 'folder'}, + {'name': 'lingua-extract', 'folder': 'folder'}, + {'name': 'lingua', 'folder': 'folder'} + ]} ) - #template.write() - #with (tempdir / "proxy.mk").open() as f: - # self.checkOutput( - # ''' - # ''', - # f.read(), - # ) + template.write() + with (tempdir / "proxy.mk").open() as f: + self.checkOutput( + ''' + ############################################################################## + # proxy targets + ############################################################################## + + .PHONY: folder-plone-site-create + folder-plone-site-create: + $(MAKE) -C "./folder/" plone-site-create + + .PHONY: folder-plone-site-purge + folder-plone-site-purge: + $(MAKE) -C "./folder/" plone-site-purge + + .PHONY: folder-gettext-create + folder-gettext-create: + $(MAKE) -C "./folder/" gettext-create + + .PHONY: folder-gettext-update + folder-gettext-update: + $(MAKE) -C "./folder/" gettext-update + + .PHONY: folder-gettext-compile + folder-gettext-compile: + $(MAKE) -C "./folder/" gettext-compile + + .PHONY: folder-lingua-extract + folder-lingua-extract: + $(MAKE) -C "./folder/" lingua-extract + + .PHONY: folder-lingua + folder-lingua: + $(MAKE) -C "./folder/" lingua + + ''', + f.read(), + ) diff --git a/src/mxmake/topics/applications/plone.mk b/src/mxmake/topics/applications/plone.mk index 03bf7e4..1fd5db5 100644 --- a/src/mxmake/topics/applications/plone.mk +++ b/src/mxmake/topics/applications/plone.mk @@ -4,10 +4,12 @@ #:depends = applications.zope #: #:[target.plone-site-create] -#:description = Creates a Plone site using the script provided in `PLONE_SITE_SCRIPT` configuration. +#:description = Creates a Plone site using the script provided in +#: `PLONE_SITE_SCRIPT` configuration. #: #:[target.plone-site-purge] -#:description = Removes the Plone instance from the database, but the database itself is kept. +#:description = Removes the Plone instance from the database, but the database +#: itself is kept. #: #:[setting.PLONE_SITE_SCRIPT] #:description = Path to the script to create or purge a Plone site diff --git a/src/mxmake/topics/core/proxy.mk b/src/mxmake/topics/core/proxy.mk new file mode 100644 index 0000000..aca3c56 --- /dev/null +++ b/src/mxmake/topics/core/proxy.mk @@ -0,0 +1,29 @@ +#:[proxy] +#:title = Proxy targets +#:description = This domain includes proxy targets which are configured in +#: `mx.ini`. I is expected that defined folder(s) contains a Makefile which +#: is generated by `mxmake` and this Makefile contains the domains for which +#: proxy targets are created. The proxy configuration in the `mx.ini` file +#: looks as follows: +#: +#: ```ini +#: mxmake-templates = proxy +#: +#: [mxmake-proxy] +#: foldername = +#: applications:plone,zest-releaser +#: i18n:* +#: ``` +#: +#: Each setting in the `mxmake-proxy` section defines a child folder. The +#: value contains the topic name and the desired domains as comma +#: separated list. Wildcard `*` means to include all domains of this topic. +#: Topic and domains are colon separated. +#: +#:depends = core.mxfiles + +############################################################################## +# proxy +############################################################################## + +-include $(MXMAKE_FILES)/proxy.mk