Skip to content

Commit

Permalink
Merge pull request #40 from mxstack/proxy-targets
Browse files Browse the repository at this point in the history
Proxy targets
  • Loading branch information
rnixx authored Oct 24, 2024
2 parents 64da216 + 3b3abd5 commit c0c5384
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 57 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
os:
- ubuntu-latest
- macos-latest
- windows-latest
exclude:
# python 3.8 and windows do not like each other here, so we do not support it
- python-version: "3.8"
os: windows-latest
# GH does not support macos and python 3.8
- python-version: "3.8"
os: macos-latest
# GH does not support macos and python 3.9
- python-version: "3.9"
os: macos-latest
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ jobs:
matrix:
python-version:
# we test on lowest and highest supported versions
- "3.8"
- "3.9"
- "3.12"
os:
- ubuntu-latest
- macos-latest
- windows-latest
exclude:
# python 3.8 and windows do not like each other here, so we do not support it
- python-version: "3.8"
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
16 changes: 12 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog

## 1.0a6 (unreleased)
## 1.0a7 (unreleased)

- Add proxy target support.

**Breaking changes**

- Rename `npm` domain to `nodejs` and add support for using `pnpm` as
alternative package manager.

## 1.0a6 (2024-08-02)

- Fix bug in `Template.write` when creating target folders to also create
parent folders if not exists.
Expand All @@ -9,10 +18,9 @@

- Add `plone-site` template configuration to `mx.ini` template.

**Breaking changes**
- More fine grained control over plone site creation and purging.

- Rename `npm` domain to `nodejs` and add support for using `pnpm` as
alternative package manager.
- Drop Python 3.8 and set all defaults to a Python 3.9 minimum.

## 1.0a5 (2024-06-07)

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PRIMARY_PYTHON?=python3

# Minimum required Python version.
# Default: 3.7
PYTHON_MIN_VERSION?=3.7
PYTHON_MIN_VERSION?=3.9

# Install packages using the given package installer method.
# Supported are `pip` and `uv`. If uv is used, its global availability is
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "mxmake"
description = "Generates a Python project-specific Makefile by using an extensible library of configurable Makefile snippets."
version = "1.0a6.dev0"
version = "1.0a7.dev0"
keywords = ["development", "deployment", "make"]
authors = [
{name = "MX Stack Developers", email = "[email protected]" }
]
requires-python = ">=3.7"
requires-python = ">=3.9"
license = { text = "BSD 2-Clause License" }
classifiers = [
"Development Status :: 3 - Alpha",
Expand Down
5 changes: 2 additions & 3 deletions src/mxmake/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ def create_config(
preseed_value = (
preseed_domain.get(setting.name, unset) if preseed_domain else unset
)
setting_default = (
preseed_value if preseed_value is not unset else setting_default
)
if preseed_value is unset:
preseed_value = setting_default
# use configured setting from parser if set
elif sfqn in parser.settings:
setting_default = parser.settings[sfqn]
Expand Down
41 changes: 40 additions & 1 deletion 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 @@ -525,3 +525,42 @@ def template_variables(self):
if not site["extension_ids"]:
site["extension_ids"] = ["plone.volto:default"]
return vars


##############################################################################
# proxy targets template
##############################################################################


@template("proxy")
class ProxyMk(MxIniBoundTemplate):
description: str = "Contains proxy targets for Makefiles of source folders"
target_name = "proxy.mk"
template_name = "proxy.mk"

@property
def target_folder(self) -> Path:
return mxmake_files()

@property
def template_variables(self):
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
44 changes: 33 additions & 11 deletions src/mxmake/templates/plone-site.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TRUTHY = frozenset(("t", "true", "y", "yes", "on", "1"))


def asbool(value: str|bool|None) -> bool:
def asbool(value: str | bool | None) -> bool:
"""Return the boolean value ``True`` if the case-lowered value of string
input ``s`` is a :term:`truthy string`. If ``s`` is already one of the
boolean values ``True`` or ``False``, return it.
Expand All @@ -22,7 +22,14 @@ def asbool(value: str|bool|None) -> bool:
return value.strip().lower() in TRUTHY


PLONE_SITE_PURGE = asbool(os.getenv("PLONE_SITE_PURGE"))
PLONE_SITE_PURGE = asbool(os.getenv("PLONE_SITE_PURGE", "false"))
PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS = asbool(
os.getenv("PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS", "true")
)
PLONE_SITE_CREATE = asbool(os.getenv("PLONE_SITE_CREATE", "true"))
PLONE_SITE_CREATE_FAIL_IF_EXISTS = asbool(
os.getenv("PLONE_SITE_CREATE_FAIL_IF_EXISTS", "true")
)

config = {
{% for key, value in site.items() %}
Expand All @@ -49,15 +56,30 @@ def asbool(value: str|bool|None) -> bool:
app.manage_delObjects([config["site_id"]])
transaction.commit()
app._p_jar.sync()
print(f"Existing site with id={config['site_id']} purged!")
if not PLONE_SITE_CREATE:
print("Done.")
exit(0)
else:
print(f"Site with id {config['site_id']} does not exist!")
exit(0)
print(f"Site with id={config['site_id']} does not exist!")
if PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS:
print("...failure!")
exit(1)
if not PLONE_SITE_CREATE:
print("Done.")
exit(0)

if PLONE_SITE_CREATE:
if config["site_id"] in app.objectIds():
print(f"Site with id={config['site_id']} already exists!")
if PLONE_SITE_CREATE_FAIL_IF_EXISTS:
print("...failure!")
exit(1)
print("Done.")
exit(0)

if config["site_id"] in app.objectIds():
print(f"Site with id {config['site_id']} already exists!")
exit(1)

site = create(app, "{{ distribution }}", config)
transaction.commit()
app._p_jar.sync()
site = create(app, "{{ distribution }}", config)
transaction.commit()
app._p_jar.sync()
print(f"New site with id={config['site_id']} created!")
print("Done.")
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 %}
Loading

0 comments on commit c0c5384

Please sign in to comment.