4
4
import json
5
5
import os
6
6
import re
7
- from hatchling .version .source .plugin .interface import VersionSourceInterface
8
7
8
+ from hatchling .version .source .plugin .interface import VersionSourceInterface
9
9
10
10
# The Python-aware NodeJS version regex
11
11
# This is very similar to `packaging.version.VERSION_PATTERN`, with a few changes:
12
12
# - Don't accept underscores
13
- # - Only support three -component release and prerelease segments
13
+ # - Only support four -component release, prerelease, and build segments
14
14
# - Require - to indicate prerelease
15
15
NODE_VERSION_PATTERN = r"""
16
- (?P<major>[0-9]+) # major
16
+ (?P<major>[0-9]+) # major
17
17
\.
18
- (?P<minor>[0-9]+) # minor
18
+ (?P<minor>[0-9]+) # minor
19
19
\.
20
- (?P<patch>[0-9]+) # patch
21
- (?P<pre> # pre-release
20
+ (?P<patch>[0-9]+) # patch
21
+ (?P<pre> # pre-release
22
22
-
23
23
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
24
24
[-\.]?
25
25
(?P<pre_n>[0-9]+)?
26
26
)?
27
+ (?:
28
+ \+
29
+ (?P<build>
30
+ [0-9A-Za-z][0-9A-Za-z-_]* # non-hyphen/dash leading identifier
31
+ (?:
32
+ (?:\.[0-9A-Za-z-_]+)* # dot-prefixed identifier segments
33
+ \. # Final dot-delimited segment
34
+ [0-9A-Za-z_-]* # non-hyphen/dash trailing identifier
35
+ [0-9A-Za-z]
36
+ )?
37
+ )
38
+ )?
27
39
"""
28
40
29
41
# The NodeJS-aware Python version regex
30
42
# This is very similar to `packaging.version.VERSION_PATTERN`, with a few changes:
31
- # - Only support three -component release and prerelease segments
43
+ # - Only support four -component release, prerelease, and build segments
32
44
PYTHON_VERSION_PATTERN = r"""
33
45
v?
34
46
(?:
35
- (?P<major>[0-9]+) # major
47
+ (?P<major>[0-9]+) # major
36
48
\.
37
- (?P<minor>[0-9]+) # minor
49
+ (?P<minor>[0-9]+) # minor
38
50
\.
39
- (?P<patch>[0-9]+) # patch
40
- (?P<pre> # pre-release
51
+ (?P<patch>[0-9]+) # patch
52
+ (?P<pre> # pre-release
41
53
[-_\.]?
42
- (?P<pre_l>(a|b|c|rc|alpha|beta| pre|preview ))
54
+ (?P<pre_l>(alpha|beta|preview| a|b|c|rc|pre))
43
55
[-_\.]?
44
56
(?P<pre_n>[0-9]+)?
45
57
)?
58
+ (?:
59
+ \+
60
+ (?P<local>
61
+ [0-9A-Za-z][0-9A-Za-z-_]* # non-hyphen/dash leading identifier
62
+ (?:
63
+ (?:\.[0-9A-Za-z-_]+)* # dot-prefixed identifier
64
+ \.
65
+ [0-9A-Za-z_-]* # non-hyphen/dash trailing identifier
66
+ [0-9A-Za-z]
67
+ )?
68
+ )
69
+ )?
46
70
)
47
71
"""
48
72
@@ -74,6 +98,9 @@ def node_version_to_python(version: str) -> str:
74
98
else :
75
99
parts .append ("{pre_l}{pre_n}" .format_map (match ))
76
100
101
+ if match ["build" ]:
102
+ parts .append ("+{build}" .format_map (match ))
103
+
77
104
return "" .join (parts )
78
105
79
106
@staticmethod
@@ -95,6 +122,8 @@ def python_version_to_node(version: str) -> str:
95
122
else :
96
123
parts .append ("-{pre_l}{pre_n}" .format_map (match ))
97
124
125
+ if match ["local" ]:
126
+ parts .append ("+{local}" .format_map (match ))
98
127
return "" .join (parts )
99
128
100
129
@property
0 commit comments