Skip to content

Commit

Permalink
Handle file substitution with type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Mar 9, 2022
1 parent eac2f68 commit b40453b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## Unreleased

* Changed the build backend to poetry-core.
([Contributed by fabaff](https://github.com/mtkennerly/poetry-dynamic-versioning/pull/63))
* Changed:
* The build backend is now poetry-core.
([Contributed by fabaff](https://github.com/mtkennerly/poetry-dynamic-versioning/pull/63))
* The default list of `substitution.patterns` now handles `__version__`
when it has a type annotation.
([Draft by da2ce7](https://github.com/mtkennerly/poetry-dynamic-versioning/pull/64))

## v0.13.1 (2021-08-09)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ In your pyproject.toml file, you may configure the following options:
* `patterns`: List of regular expressions for the text to replace.
Each regular expression must have two capture groups, which are any
text to preserve before and after the replaced text. Default:
`["(^__version__\s*=\s*['\"])[^'\"]*(['\"])"]`.
`["(^__version__\s*(?::.*?)?=\s*['\"])[^'\"]*(['\"])"]`.

Remember that the backslashes must be escaped (`\\`) in the TOML file.

Expand Down
2 changes: 1 addition & 1 deletion poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _default_config() -> Mapping:
"subversion": {"tag-dir": "tags"},
"substitution": {
"files": ["*.py", "*/__init__.py", "*/__version__.py", "*/_version.py"],
"patterns": [r"(^__version__\s*=\s*['\"])[^'\"]*(['\"])"],
"patterns": [r"(^__version__\s*(?::.*?)?=\s*['\"])[^'\"]*(['\"])"],
},
"style": None,
"metadata": None,
Expand Down
1 change: 1 addition & 0 deletions tests/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function test_cli_mode_and_substitution {
poetry-dynamic-versioning && \
# Changes persist after the command is done:
should_fail grep 'version = "0.0.999"' $dummy/pyproject.toml && \
should_fail grep '__version__: str = "0.0.0"' $dummy/project/__init__.py && \
should_fail grep '__version__ = "0.0.0"' $dummy/project/__init__.py
}

Expand Down
1 change: 1 addition & 0 deletions tests/project/project/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__version__: str = "0.0.0"
__version__ = "0.0.0"

0 comments on commit b40453b

Please sign in to comment.