Skip to content

Commit b18e19e

Browse files
committed
improve version regex
1 parent d277639 commit b18e19e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/managers/builtin/pipUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ function validatePyprojectToml(toml: tomljs.JsonMap): string | undefined {
3030
const version = (toml.project as tomljs.JsonMap).version as string;
3131
// PEP 440 version regex. Versions must follow PEP 440 format (e.g., "1.0.0", "2.1a3").
3232
// See https://peps.python.org/pep-0440/
33+
// This regex is adapted from the official python 'packaging' library:
34+
// https://github.com/pypa/packaging/blob/main/src/packaging/version.py
3335
const versionRegex =
34-
/^([0-9]+!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|c|rc)([0-9]+)?)?(\.post([0-9]+)?)?(\.dev([0-9]+)?)?(\+[a-zA-Z0-9._-]+)?$/;
36+
/^v?([0-9]+!)?([0-9]+(?:\.[0-9]+)*)(?:[-_.]?(a|b|c|rc|alpha|beta|pre|preview)[-_.]?([0-9]+)?)?(?:(?:-([0-9]+))|(?:[-_.]?(post|rev|r)[-_.]?([0-9]+)?))?(?:[-_.]?(dev)[-_.]?([0-9]+)?)?(?:\+([a-z0-9]+(?:[-_.][a-z0-9]+)*))?$/i;
3537
if (!versionRegex.test(version)) {
3638
return l10n.t('Invalid version "{0}" in pyproject.toml.', version);
3739
}

0 commit comments

Comments
 (0)