From c2b72906ce6fa10895d334e3739d803cda1ac1e8 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 30 May 2024 14:01:17 +0800 Subject: [PATCH 1/2] Add a UUID cookiecutter extension. --- src/briefcase/integrations/cookiecutter.py | 16 ++++++++++++++++ .../cookiecutter/test_UUIDExtension.py | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/integrations/cookiecutter/test_UUIDExtension.py diff --git a/src/briefcase/integrations/cookiecutter.py b/src/briefcase/integrations/cookiecutter.py index 3c66ffd06..8367b94c7 100644 --- a/src/briefcase/integrations/cookiecutter.py +++ b/src/briefcase/integrations/cookiecutter.py @@ -1,5 +1,7 @@ """Jinja2 extensions.""" +import uuid + from jinja2.ext import Extension @@ -116,3 +118,17 @@ def bool_attr(obj): return "true" if obj else "false" environment.filters["bool_attr"] = bool_attr + + +class UUIDExtension(Extension): + """Extensions for generating UUIDs.""" + + def __init__(self, environment): + """Initialize the extension with the given environment.""" + super().__init__(environment) + + def dns_uuid5(obj): + """A DNS-based UUID5 object generated from the provided content.""" + return str(uuid.uuid5(uuid.NAMESPACE_DNS, obj)) + + environment.filters["dns_uuid5"] = dns_uuid5 diff --git a/tests/integrations/cookiecutter/test_UUIDExtension.py b/tests/integrations/cookiecutter/test_UUIDExtension.py new file mode 100644 index 000000000..6be2ebd28 --- /dev/null +++ b/tests/integrations/cookiecutter/test_UUIDExtension.py @@ -0,0 +1,19 @@ +from unittest.mock import MagicMock + +import pytest + +from briefcase.integrations.cookiecutter import UUIDExtension + + +@pytest.mark.parametrize( + "value, expected", + [ + ("example.com", "cfbff0d1-9375-5685-968c-48ce8b15ae17"), + ("foobar.example.com", "941bbcd9-03e1-568a-a728-8434055bc338"), + ], +) +def test_dns_uuid5_value(value, expected): + env = MagicMock() + env.filters = {} + UUIDExtension(env) + assert env.filters["dns_uuid5"](value) == expected From ba536544727150519893cf1e6c9e7b1c72b0c200 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 30 May 2024 14:03:24 +0800 Subject: [PATCH 2/2] Added a changenote. --- changes/1850.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1850.misc.rst diff --git a/changes/1850.misc.rst b/changes/1850.misc.rst new file mode 100644 index 000000000..a96b93dea --- /dev/null +++ b/changes/1850.misc.rst @@ -0,0 +1 @@ +A UUID cookiecutter extension was added to support Windows MSI templating.