-
-
Notifications
You must be signed in to change notification settings - Fork 382
Support type annotations on version variable by default #2191
Description
Description
The default regex to find the __version__ or VERSION variable in the file specified in hatch.version.path does not currently handle typing. For example:
This works:
__version__ = "1.0.0"This fails with ValueError: Error getting the version from source regex: unable to parse the version from the file:
__version__: str = "1.0.0"Modifying the default regex with the below setting in pyproject.toml works in both cases:
[tool.hatch.version]
pattern = "(?i)^(__version__|VERSION)(?:: *str)? *= *([\\'\"])v?(?P<version>.+?)\\2"This change should be fairly safe, the only reason I'm not submitting a PR is because my use case requires Python 3.7 so I'm working with an old version of hatch (1.17.1).
Use case/motivation
Adding type annotations is best current practice and is increasingly common. Supporting them in the default regex statement would prevent a lot of developers from having to troubleshoot and fix this common case when setting up/migrating their projects.
Related issues
No response
Are you willing to submit a PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow the Python Software Foundation's Code of Conduct