From 01cc96f016b79f7af8f9d4c483cbd51307ef1ff1 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Mon, 29 Jul 2024 01:00:57 +0200 Subject: [PATCH 1/6] more fine grained control over plone-site creation/purging --- CHANGES.md | 2 ++ src/mxmake/templates/plone-site.py | 44 ++++++++++++++++++------- src/mxmake/topics/applications/plone.mk | 22 +++++++++++++ 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index be6ab5d..75cd3e1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,8 @@ - Add `plone-site` template configuration to `mx.ini` template. +- More fine grained control over plone site creation and purging. + ## 1.0a5 (2024-06-07) - Export `OS` environment variable in `mxenv` domain to prevent warning on diff --git a/src/mxmake/templates/plone-site.py b/src/mxmake/templates/plone-site.py index 7d8278a..617739f 100644 --- a/src/mxmake/templates/plone-site.py +++ b/src/mxmake/templates/plone-site.py @@ -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. @@ -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() %} @@ -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.") diff --git a/src/mxmake/topics/applications/plone.mk b/src/mxmake/topics/applications/plone.mk index 03bf7e4..664bab7 100644 --- a/src/mxmake/topics/applications/plone.mk +++ b/src/mxmake/topics/applications/plone.mk @@ -9,9 +9,21 @@ #:[target.plone-site-purge] #:description = Removes the Plone instance from the database, but the database itself is kept. #: +#:[target.plone-site-recreate] +#:description = Removes the Plone instance from the database like in plone-site-purge, +#: then creates a new one like in plone-site-create. +#: #:[setting.PLONE_SITE_SCRIPT] #:description = Path to the script to create or purge a Plone site #:default = .mxmake/files/plone-site.py +#:#: +#:[setting.PLONE_SITE_CREATE_FAIL_IF_EXISTS] +#:description = Exit with an error if the Plone site already exists +#:default = True + +#:[setting.PLONE_SITE_PURGE_FAIL_IF_NOT_EXISTS] +#:description = Exit with an error if the Plone site does not exists +#:default = True ############################################################################## # plone @@ -20,10 +32,20 @@ .PHONY: plone-site-create plone-site-create: $(ZOPE_RUN_TARGET) @echo "Creating Plone Site" + @export PLONE_SITE_PURGE=False + @export PLONE_SITE_CREATE=True @zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT) .PHONY: plone-site-purge plone-site-purge: $(ZOPE_RUN_TARGET) @echo "Purging Plone Site" @export PLONE_SITE_PURGE=True + @export PLONE_SITE_CREATE=False + @zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT) + +.PHONY: plone-site-recreate +plone-site-recreate: $(ZOPE_RUN_TARGET) + @echo "Purging Plone Site" + @export PLONE_SITE_PURGE=True + @export PLONE_SITE_CREATE=True @zconsole run $(ZOPE_INSTANCE_FOLDER)/etc/zope.conf $(PLONE_SITE_SCRIPT) From a2ee18053eecc1266bb08a779f677b30de38dccf Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Mon, 29 Jul 2024 01:06:39 +0200 Subject: [PATCH 2/6] drop Python 3.8 since dependencies broke --- .github/workflows/test.yml | 7 ------- .github/workflows/variants.yml | 6 +----- CHANGES.md | 2 ++ pyproject.toml | 2 +- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 94bff63..d4e6775 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,6 @@ jobs: fail-fast: false matrix: python-version: - - "3.8" - "3.9" - "3.10" - "3.11" @@ -18,12 +17,6 @@ jobs: - 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 diff --git a/.github/workflows/variants.yml b/.github/workflows/variants.yml index 33a0e51..f60f4ed 100644 --- a/.github/workflows/variants.yml +++ b/.github/workflows/variants.yml @@ -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 diff --git a/CHANGES.md b/CHANGES.md index 75cd3e1..729d174 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,8 @@ - More fine grained control over plone site creation and purging. +- Drop Python 3.8 in tests. + ## 1.0a5 (2024-06-07) - Export `OS` environment variable in `mxenv` domain to prevent warning on diff --git a/pyproject.toml b/pyproject.toml index 963a97b..779ec85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ keywords = ["development", "deployment", "make"] authors = [ {name = "MX Stack Developers", email = "dev@bluedynamics.com" } ] -requires-python = ">=3.7" +requires-python = ">=3.9" license = { text = "BSD 2-Clause License" } classifiers = [ "Development Status :: 3 - Alpha", From a02ac2667d644a9cca91f7a1009c1a5b3cacdd52 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Mon, 29 Jul 2024 01:09:28 +0200 Subject: [PATCH 3/6] fix test --- src/mxmake/tests/test_templates.py | 48 ++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/mxmake/tests/test_templates.py b/src/mxmake/tests/test_templates.py index 32e27ab..88a3379 100644 --- a/src/mxmake/tests/test_templates.py +++ b/src/mxmake/tests/test_templates.py @@ -877,7 +877,7 @@ def test_PloneSite_all_defaults(self, tempdir): 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. @@ -889,7 +889,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 = { "site_id": "Plone", @@ -913,18 +920,33 @@ 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) - - - if config["site_id"] in app.objectIds(): - print(f"Site with id {config['site_id']} already exists!") - exit(1) - - site = create(app, "", config) - transaction.commit() - app._p_jar.sync() + 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) + + site = create(app, "", config) + transaction.commit() + app._p_jar.sync() + print(f"New site with id={config['site_id']} created!") + print("Done.") ''', f.read(), ) From 5e1328f06e70728c120483c32aafd8392197d693 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Fri, 2 Aug 2024 16:41:14 +0200 Subject: [PATCH 4/6] set all defaults to a Python 3.9 minimum --- CHANGES.md | 2 +- Makefile | 2 +- src/mxmake/topics/core/mxenv.mk | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 729d174..5947e73 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ - More fine grained control over plone site creation and purging. -- Drop Python 3.8 in tests. +- Drop Python 3.8 and set all defaults to a Python 3.9 minimum. ## 1.0a5 (2024-06-07) diff --git a/Makefile b/Makefile index 6342d58..8b73f1f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/mxmake/topics/core/mxenv.mk b/src/mxmake/topics/core/mxenv.mk index 3157388..c352fcf 100644 --- a/src/mxmake/topics/core/mxenv.mk +++ b/src/mxmake/topics/core/mxenv.mk @@ -28,7 +28,7 @@ #: #:[setting.PYTHON_MIN_VERSION] #:description = Minimum required Python version. -#:default = 3.7 +#:default = 3.9 #: #:[setting.PYTHON_PACKAGE_INSTALLER] #:description = Install packages using the given package installer method. From 776935fcd6a1823a445ebb462eb2b4f4e66aee77 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Fri, 2 Aug 2024 16:50:04 +0200 Subject: [PATCH 5/6] Preparing release 1.0a6 --- CHANGES.md | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5947e73..438f272 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Changelog -## 1.0a6 (unreleased) +## 1.0a6 (2024-08-02) - Fix bug in `Template.write` when creating target folders to also create parent folders if not exists. diff --git a/pyproject.toml b/pyproject.toml index 779ec85..3869d4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [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.0a6" keywords = ["development", "deployment", "make"] authors = [ {name = "MX Stack Developers", email = "dev@bluedynamics.com" } From 1b77a306cfef456a29743f0ee7619011882b9b55 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Fri, 2 Aug 2024 16:50:23 +0200 Subject: [PATCH 6/6] Back to development: 1.0a7 --- CHANGES.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 438f272..b648880 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Changelog +## 1.0a7 (unreleased) + + +- Nothing changed yet. + + ## 1.0a6 (2024-08-02) - Fix bug in `Template.write` when creating target folders to also create diff --git a/pyproject.toml b/pyproject.toml index 3869d4a..6678850 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "mxmake" description = "Generates a Python project-specific Makefile by using an extensible library of configurable Makefile snippets." -version = "1.0a6" +version = "1.0a7.dev0" keywords = ["development", "deployment", "make"] authors = [ {name = "MX Stack Developers", email = "dev@bluedynamics.com" }