Skip to content

Commit

Permalink
fix: improve version regex to capture typed version attributes (#816)
Browse files Browse the repository at this point in the history
This allows capturing the version when typing the version attribute
using `__version__: str = "1.0.1"` as well.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
maxbachmann and pre-commit-ci[bot] authored Jul 19, 2024
1 parent 411d2c4 commit 2b3e4d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ input = "src/mypackage/__init__.py"
You can set a custom regex with `regex=`; use `(?P<value>...)` to capture the
value you want to use. By default when targeting version, you get a reasonable
regex for python files,
`'(?i)^(__version__|VERSION) *= *([\'"])v?(?P<value>.+?)\2'`.
`'(?i)^(__version__|VERSION)(?: ?\: ?str)? *= *([\'"])v?(?P<value>.+?)\2'`.

```{versionadded} 0.5
Expand Down
3 changes: 2 additions & 1 deletion src/scikit_build_core/metadata/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def dynamic_metadata(

input_filename = settings["input"]
regex = settings.get(
"regex", r'(?i)^(__version__|VERSION) *= *([\'"])v?(?P<value>.+?)\2'
"regex",
r'(?i)^(__version__|VERSION)(?: ?\: ?str)? *= *([\'"])v?(?P<value>.+?)\2',
)

with Path(input_filename).open(encoding="utf-8") as f:
Expand Down

0 comments on commit 2b3e4d2

Please sign in to comment.