Skip to content

Commit 2b3e4d2

Browse files
fix: improve version regex to capture typed version attributes (#816)
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>
1 parent 411d2c4 commit 2b3e4d2

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Diff for: docs/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ input = "src/mypackage/__init__.py"
564564
You can set a custom regex with `regex=`; use `(?P<value>...)` to capture the
565565
value you want to use. By default when targeting version, you get a reasonable
566566
regex for python files,
567-
`'(?i)^(__version__|VERSION) *= *([\'"])v?(?P<value>.+?)\2'`.
567+
`'(?i)^(__version__|VERSION)(?: ?\: ?str)? *= *([\'"])v?(?P<value>.+?)\2'`.
568568

569569
```{versionadded} 0.5
570570

Diff for: src/scikit_build_core/metadata/regex.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def dynamic_metadata(
3737

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

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

0 commit comments

Comments
 (0)