Skip to content

Commit

Permalink
Merge pull request #1850 from freakboy3742/cookiecutter-uuid
Browse files Browse the repository at this point in the history
Add a UUID cookiecutter extension.
  • Loading branch information
mhsmith authored Jun 2, 2024
2 parents 85c27dd + ba53654 commit 2e8aa9c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/1850.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A UUID cookiecutter extension was added to support Windows MSI templating.
16 changes: 16 additions & 0 deletions src/briefcase/integrations/cookiecutter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Jinja2 extensions."""

import uuid

from jinja2.ext import Extension


Expand Down Expand Up @@ -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
19 changes: 19 additions & 0 deletions tests/integrations/cookiecutter/test_UUIDExtension.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2e8aa9c

Please sign in to comment.