23
23
[-\.]?
24
24
(?P<pre_n>[0-9]+)?
25
25
)?
26
- (?P<post> # post release
27
- (?:-(?P<post_n1>[0-9]+))
28
- |
29
- (?:
30
- [-\.]?
31
- (?P<post_l>post|rev|r)
32
- [-\.]?
33
- (?P<post_n2>[0-9]+)?
34
- )
35
- )?
36
- (?P<dev> # dev release
37
- [-\.]?
38
- (?P<dev_l>dev)
39
- [-\.]?
40
- (?P<dev_n>[0-9]+)?
41
- )?
42
26
"""
43
27
44
28
# The NodeJS-aware Python version regex
59
43
[-_\.]?
60
44
(?P<pre_n>[0-9]+)?
61
45
)?
62
- (?P<post> # post release
63
- (?:-(?P<post_n1>[0-9]+))
64
- |
65
- (?:
66
- [-_\.]?
67
- (?P<post_l>post|rev|r)
68
- [-_\.]?
69
- (?P<post_n2>[0-9]+)?
70
- )
71
- )?
72
- (?P<dev> # dev release
73
- [-_\.]?
74
- (?P<dev_l>dev)
75
- [-_\.]?
76
- (?P<dev_n>[0-9]+)?
77
- )?
78
46
)
79
47
"""
80
48
@@ -96,13 +64,10 @@ def node_version_to_python(self, version: str) -> str:
96
64
parts = ["{major}.{minor}.{patch}" .format_map (match )]
97
65
98
66
if match ["pre" ]:
99
- parts .append ("{pre_l}{pre_n}" .format_map (match ))
100
- if match ["post_n1" ]:
101
- parts .append (".post{post_n1}" .format_map (match ))
102
- elif match ["post_l" ]:
103
- parts .append (".{post_l}{post_n2}" .format_map (match ))
104
- if match ["dev" ]:
105
- parts .append ("{dev_l}{dev_n}" .format_map (match ))
67
+ if match ["pre_n" ] is None :
68
+ parts .append ("{pre_l}" .format_map (match ))
69
+ else :
70
+ parts .append ("{pre_l}{pre_n}" .format_map (match ))
106
71
107
72
return "" .join (parts )
108
73
@@ -115,22 +80,15 @@ def python_version_to_node(self, version: str) -> str:
115
80
re .VERBOSE | re .IGNORECASE ,
116
81
)
117
82
if match is None :
118
- raise ValueError (f"Version { node_version !r} did not match regex" )
83
+ raise ValueError (f"Version { version !r} did not match regex" )
119
84
120
85
parts = ["{major}.{minor}.{patch}" .format_map (match )]
121
86
122
- pre_parts = []
123
87
if match ["pre" ]:
124
- pre_parts .append ("{pre_l}{pre_n}" .format_map (match ))
125
- if match ["post_n1" ]:
126
- pre_parts .append (".post{post_n1}" .format_map (match ))
127
- elif match ["post_l" ]:
128
- pre_parts .append (".{post_l}{post_n2}" .format_map (match ))
129
- if match ["dev" ]:
130
- pre_parts .append ("{dev_l}{dev_n}" .format_map (match ))
131
-
132
- if pre_parts :
133
- parts .append ("-" + "" .join (pre_parts ))
88
+ if match ["pre_n" ] is None :
89
+ parts .append ("-{pre_l}" .format_map (match ))
90
+ else :
91
+ parts .append ("-{pre_l}{pre_n}" .format_map (match ))
134
92
135
93
return "" .join (parts )
136
94
0 commit comments