Skip to content

Commit aec775f

Browse files
committed
feat: suport local/build segments
1 parent 5ec54e0 commit aec775f

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

hatch_nodejs_version/version_source.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,69 @@
44
import json
55
import os
66
import re
7-
from hatchling.version.source.plugin.interface import VersionSourceInterface
87

8+
from hatchling.version.source.plugin.interface import VersionSourceInterface
99

1010
# The Python-aware NodeJS version regex
1111
# This is very similar to `packaging.version.VERSION_PATTERN`, with a few changes:
1212
# - Don't accept underscores
13-
# - Only support three-component release and prerelease segments
13+
# - Only support four-component release, prerelease, and build segments
1414
# - Require - to indicate prerelease
1515
NODE_VERSION_PATTERN = r"""
16-
(?P<major>[0-9]+) # major
16+
(?P<major>[0-9]+) # major
1717
\.
18-
(?P<minor>[0-9]+) # minor
18+
(?P<minor>[0-9]+) # minor
1919
\.
20-
(?P<patch>[0-9]+) # patch
21-
(?P<pre> # pre-release
20+
(?P<patch>[0-9]+) # patch
21+
(?P<pre> # pre-release
2222
-
2323
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
2424
[-\.]?
2525
(?P<pre_n>[0-9]+)?
2626
)?
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+
)?
2739
"""
2840

2941
# The NodeJS-aware Python version regex
3042
# 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
3244
PYTHON_VERSION_PATTERN = r"""
3345
v?
3446
(?:
35-
(?P<major>[0-9]+) # major
47+
(?P<major>[0-9]+) # major
3648
\.
37-
(?P<minor>[0-9]+) # minor
49+
(?P<minor>[0-9]+) # minor
3850
\.
39-
(?P<patch>[0-9]+) # patch
40-
(?P<pre> # pre-release
51+
(?P<patch>[0-9]+) # patch
52+
(?P<pre> # pre-release
4153
[-_\.]?
42-
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
54+
(?P<pre_l>(alpha|beta|preview|a|b|c|rc|pre))
4355
[-_\.]?
4456
(?P<pre_n>[0-9]+)?
4557
)?
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+
)?
4670
)
4771
"""
4872

@@ -74,6 +98,9 @@ def node_version_to_python(version: str) -> str:
7498
else:
7599
parts.append("{pre_l}{pre_n}".format_map(match))
76100

101+
if match["build"]:
102+
parts.append("+{build}".format_map(match))
103+
77104
return "".join(parts)
78105

79106
@staticmethod
@@ -95,6 +122,8 @@ def python_version_to_node(version: str) -> str:
95122
else:
96123
parts.append("-{pre_l}{pre_n}".format_map(match))
97124

125+
if match["local"]:
126+
parts.append("+{local}".format_map(match))
98127
return "".join(parts)
99128

100129
@property

0 commit comments

Comments
 (0)