Skip to content

Commit cb484a1

Browse files
maxbachmannpre-commit-ci[bot]
authored andcommitted
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 8b6df55 commit cb484a1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ input = "src/mypackage/__init__.py"
535535
You can set a custom regex with `regex=`; use `(?P<value>...)` to capture the
536536
value you want to use. By default when targeting version, you get a reasonable
537537
regex for python files,
538-
`'(?i)^(__version__|VERSION) *= *([\'"])v?(?P<value>.+?)\2'`.
538+
`'(?i)^(__version__|VERSION)(?: ?\: ?str)? *= *([\'"])v?(?P<value>.+?)\2'`.
539539

540540
```{versionadded} 0.5
541541

src/scikit_build_core/metadata/regex.py

Lines changed: 2 additions & 1 deletion
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)