File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 | r c ) ( [ 0 - 9 ] + ) ? ) ? ( \. p o s t ( [ 0 - 9 ] + ) ? ) ? ( \. d e v ( [ 0 - 9 ] + ) ? ) ? ( \+ [ a - z A - Z 0 - 9 . _ - ] + ) ? $ / ;
36+ / ^ v ? ( [ 0 - 9 ] + ! ) ? ( [ 0 - 9 ] + (?: \. [ 0 - 9 ] + ) * ) (?: [ - _ . ] ? ( a | b | c | r c | a l p h a | b e t a | p r e | p r e v i e w ) [ - _ . ] ? ( [ 0 - 9 ] + ) ? ) ? (?: (?: - ( [ 0 - 9 ] + ) ) | (?: [ - _ . ] ? ( p o s t | r e v | r ) [ - _ . ] ? ( [ 0 - 9 ] + ) ? ) ) ? (?: [ - _ . ] ? ( d e v ) [ - _ . ] ? ( [ 0 - 9 ] + ) ? ) ? (?: \+ ( [ a - z 0 - 9 ] + (?: [ - _ . ] [ a - z 0 - 9 ] + ) * ) ) ? $ / i ;
3537 if ( ! versionRegex . test ( version ) ) {
3638 return l10n . t ( 'Invalid version "{0}" in pyproject.toml.' , version ) ;
3739 }
You can’t perform that action at this time.
0 commit comments