FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(config): support Python type-annotated version variables by Copilot · Pull Request #1485 · python-semantic-release/python-semantic-release · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 9 additions & 1 deletion docs/configuration/configuration.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,8 @@ version numbers.
]

First, the ``__version__`` variable in ``src/semantic_release/__init__.py`` will be updated
with the next version using the `SemVer`_ number format.
with the next version using the `SemVer`_ number format. As of $NEW_RELEASE_TAG, this works
both with and without a Python type annotation on the variable:

.. code-block:: diff

Expand All @@ -1386,6 +1387,10 @@ with the next version using the `SemVer`_ number format.
- __version__ = "0.1.0"
+ __version__ = "0.2.0"

# or with a type annotation ($NEW_RELEASE_TAG or greater):
- __version__: str = "0.1.0"
+ __version__: str = "0.2.0"

Then, the ``version`` variable in ``docs/conf.py`` will be updated with the next version
with the next version using the `SemVer`_ number format because of the explicit ``nf``.

Expand Down Expand Up @@ -1450,6 +1455,9 @@ The regular expression generated from the ``version_variables`` definition will:
the symbol. As of v10.0.0, a double-equals (``==``) operator is also supported
as a valid operand symbol. As of v10.5.0, PSR can omit all operands as long
as there is at least one whitespace character between the variable name and the version.
As of $NEW_RELEASE_TAG, an optional Python-style type annotation (e.g. ``: str``,
``: typing.Final[str]``) between the variable name and the assignment operator is
also supported.

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,
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ def from_string_definition(
# Supports optional matching quotations around variable name
# Negative lookbehind to ensure we don't match part of a variable name
f"""(?x)(?P<quote1>['"])?(?<![\\w.-]){regex_escape(variable)}(?P=quote1)?""",
# Supports optional Python type annotation (e.g., `: str`, `: Optional[str]`) where type annotation can be up to 100 characters
r"(?:\s{0,8}:\s{0,8}[^\s=:][^=:=]{0,100})?",
# Supports walrus, equals sign, double-equals, colon, or @ as assignment operator
# ignoring whitespace separation. Also allows a space as the separator for c-macro style definitions.
r"\s*(:=|==|[:=@ ])\s*",
r"\s{0,8}(:=|==|[:=@ ])\s{0,8}",
# Supports optional matching quotations around a version pattern (tag or raw format)
f"""(?P<quote2>['"])?{value_replace_pattern_str}(?P=quote2)?""",
],
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,58 @@ def test_pattern_declaration_is_version_replacer():
"""
),
),
(
"Python annotated variable with str type hint (number format)",
f"{test_file}:__version__:{VersionStampType.NUMBER_FORMAT.value}",
# irrelevant for this case
lazy_fixture(default_tag_format_str.__name__),
# Uses equals separator with single quotes and str type annotation
"""__version__: str = '1.0.0'""",
f"""__version__: str = '{next_version}'""",
),
(
"Python annotated variable with str type hint (tag format)",
f"{test_file}:__version__:{VersionStampType.TAG_FORMAT.value}",
lazy_fixture(default_tag_format_str.__name__),
# Uses equals separator with single quotes and str type annotation
"""__version__: str = 'v1.0.0'""",
f"""__version__: str = 'v{next_version}'""",
),
(
"Python annotated variable with quoted str type hint (number format)",
f"{test_file}:__version__:{VersionStampType.NUMBER_FORMAT.value}",
# irrelevant for this case
lazy_fixture(default_tag_format_str.__name__),
# Uses equals separator with single quotes and str type annotation
"""__version__: "str" = '1.0.0'""",
f"""__version__: "str" = '{next_version}'""",
),
(
"Python annotated variable with quoted str type hint (tag format)",
f"{test_file}:__version__:{VersionStampType.TAG_FORMAT.value}",
lazy_fixture(default_tag_format_str.__name__),
# Uses equals separator with single quotes and str type annotation
"""__version__: "str" = 'v1.0.0'""",
f"""__version__: "str" = 'v{next_version}'""",
),
(
"Python annotated variable with complex type hint",
f"{test_file}:__version__:{VersionStampType.NUMBER_FORMAT.value}",
# irrelevant for this case
lazy_fixture(default_tag_format_str.__name__),
# Uses equals separator with double quotes and complex type annotation
'''__version__: typing.Final[str] = "1.0.0"''',
f'''__version__: typing.Final[str] = "{next_version}"''',
),
(
"Python annotated variable with complex type hint (tag format)",
f"{test_file}:__version__:{VersionStampType.TAG_FORMAT.value}",
# irrelevant for this case
lazy_fixture(default_tag_format_str.__name__),
# Uses equals separator with double quotes and complex type annotation
'''__version__: typing.Final[str] = "v1.0.0"''',
f'''__version__: typing.Final[str] = "v{next_version}"''',
),
]
],
)
Expand Down
Loading

Back | FazBrowse Home | New Git URL