From 8e27ba8f41e0bdac3614f72f864ed28b3a658d0c Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Sat, 1 Nov 2025 23:45:31 -0600 Subject: [PATCH 1/3] test(version-variables): add c-macro style version stamp unit test ref: #1348 --- .../declarations/test_pattern_declaration.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/unit/semantic_release/version/declarations/test_pattern_declaration.py b/tests/unit/semantic_release/version/declarations/test_pattern_declaration.py index 8280e95bb..ddca3dbf6 100644 --- a/tests/unit/semantic_release/version/declarations/test_pattern_declaration.py +++ b/tests/unit/semantic_release/version/declarations/test_pattern_declaration.py @@ -215,6 +215,59 @@ def test_pattern_declaration_is_version_replacer(): """ ), ), + ( + "Using default number format for c-macro style definition (see #1348)", + f"{test_file}:APP_VERSION:{VersionStampType.NUMBER_FORMAT.value}", + # irrelevant for this case + lazy_fixture(default_tag_format_str.__name__), + # Uses colon separator with double quotes + dedent( + """\ + #ifndef VERSION_H + #define VERSION_H + + #define APP_VERSION "0.0.0" + + #endif // VERSION_H + """ + ), + dedent( + f"""\ + #ifndef VERSION_H + #define VERSION_H + + #define APP_VERSION "{next_version}" + + #endif // VERSION_H + """ + ), + ), + ( + "Using default tag format for c-macro style definition (see #1348)", + f"{test_file}:APP_VERSION:{VersionStampType.TAG_FORMAT.value}", + lazy_fixture(default_tag_format_str.__name__), + # Uses colon separator with double quotes + dedent( + """\ + #ifndef VERSION_H + #define VERSION_H + + #define APP_VERSION "v0.0.0" + + #endif // VERSION_H + """ + ), + dedent( + f"""\ + #ifndef VERSION_H + #define VERSION_H + + #define APP_VERSION "v{next_version}" + + #endif // VERSION_H + """ + ), + ), ] ], ) From 5ae27d743878e0b500519cedbc6fd4f3042a0412 Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Sat, 1 Nov 2025 23:38:44 -0600 Subject: [PATCH 2/3] feat(cmd-version): adds c-macro style version definition support to `version_variables` Implements: #1348 --- src/semantic_release/version/declarations/pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/semantic_release/version/declarations/pattern.py b/src/semantic_release/version/declarations/pattern.py index f08c208a4..4d285b5a1 100644 --- a/src/semantic_release/version/declarations/pattern.py +++ b/src/semantic_release/version/declarations/pattern.py @@ -228,8 +228,8 @@ def from_string_definition( # Negative lookbehind to ensure we don't match part of a variable name f"""(?x)(?P['"])?(?['"])?{value_replace_pattern_str}(?P=quote2)?""", ], From 766674352778c3339199f584a70a492de242031b Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Sat, 1 Nov 2025 23:52:08 -0600 Subject: [PATCH 3/3] docs(configuration): update `version_variables` examples with a c-macro style replacement ref: #1348 --- docs/configuration/configuration.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/configuration/configuration.rst b/docs/configuration/configuration.rst index 2b2278382..cdd3604fb 100644 --- a/docs/configuration/configuration.rst +++ b/docs/configuration/configuration.rst @@ -1354,7 +1354,8 @@ The regular expression generated from the ``version_variables`` definition will: 2. The variable name defined by ``variable`` and the version must be separated by an operand symbol (``=``, ``:``, ``:=``, or ``@``). Whitespace is optional around the symbol. As of v10.0.0, a double-equals (``==``) operator is also supported - as a valid operand symbol. + as a valid operand symbol. As of $NEW_RELEASE_TAG, PSR can omit all operands as long + as there is at least one whitespace character between the variable name and the version. 3. The value of the variable must match a `SemVer`_ regular expression and can be enclosed by single (``'``) or double (``"``) quotation marks but they must match. However, @@ -1410,6 +1411,9 @@ will be matched and replaced by the new version: # requirements.txt my-package == 1.2.3 + # C-Macro style (no operand only whitespace required) + #define VERSION "1.2.3" + .. important:: The Regular Expression expects a version value to exist in the file to be replaced. It cannot be an empty string or a non-semver compliant string. If this is the very