Skip to content

Commit

Permalink
Implement proxy target geeration
Browse files Browse the repository at this point in the history
  • Loading branch information
rnixx committed Jun 18, 2024
1 parent a84678e commit 661d240
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 19 deletions.
26 changes: 21 additions & 5 deletions src/mxmake/templates.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions src/mxmake/templates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ TYPECHECK_TARGETS?=
FORMAT_TARGETS?=
{% endif %}
{{ sections.read() }}
##############################################################################
# Custom includes
##############################################################################

-include $(INCLUDE_MAKEFILE)

##############################################################################
Expand Down
10 changes: 10 additions & 0 deletions src/mxmake/templates/proxy.mk
Original file line number Diff line number Diff line change
@@ -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 %}
67 changes: 55 additions & 12 deletions src/mxmake/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ def test_Makefile(self, tempdir):
DIRTY_TARGETS+=mxenv-dirty
CLEAN_TARGETS+=mxenv-clean
##############################################################################
# Custom includes
##############################################################################
-include $(INCLUDE_MAKEFILE)
##############################################################################
Expand Down Expand Up @@ -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")
Expand All @@ -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(),
)
6 changes: 4 additions & 2 deletions src/mxmake/topics/applications/plone.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/mxmake/topics/core/proxy.mk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 661d240

Please sign in to comment.