4
4
5
5
from typing import TYPE_CHECKING
6
6
7
+ from poetry .core .constraints .version .exceptions import ParseConstraintError
8
+ from poetry .core .version .exceptions import InvalidVersion
9
+
7
10
8
11
if TYPE_CHECKING :
9
12
from poetry .core .constraints .version .version_constraint import VersionConstraint
@@ -66,7 +69,13 @@ def parse_single_constraint(constraint: str) -> VersionConstraint:
66
69
# Tilde range
67
70
m = TILDE_CONSTRAINT .match (constraint )
68
71
if m :
69
- version = Version .parse (m .group ("version" ))
72
+ try :
73
+ version = Version .parse (m .group ("version" ))
74
+ except InvalidVersion as e :
75
+ raise ParseConstraintError (
76
+ f"Could not parse version constraint: { constraint } "
77
+ ) from e
78
+
70
79
high = version .stable .next_minor ()
71
80
if version .release .precision == 1 :
72
81
high = version .stable .next_major ()
@@ -76,7 +85,13 @@ def parse_single_constraint(constraint: str) -> VersionConstraint:
76
85
# PEP 440 Tilde range (~=)
77
86
m = TILDE_PEP440_CONSTRAINT .match (constraint )
78
87
if m :
79
- version = Version .parse (m .group ("version" ))
88
+ try :
89
+ version = Version .parse (m .group ("version" ))
90
+ except InvalidVersion as e :
91
+ raise ParseConstraintError (
92
+ f"Could not parse version constraint: { constraint } "
93
+ ) from e
94
+
80
95
if version .release .precision == 2 :
81
96
high = version .stable .next_major ()
82
97
else :
@@ -87,7 +102,12 @@ def parse_single_constraint(constraint: str) -> VersionConstraint:
87
102
# Caret range
88
103
m = CARET_CONSTRAINT .match (constraint )
89
104
if m :
90
- version = Version .parse (m .group ("version" ))
105
+ try :
106
+ version = Version .parse (m .group ("version" ))
107
+ except InvalidVersion as e :
108
+ raise ParseConstraintError (
109
+ f"Could not parse version constraint: { constraint } "
110
+ ) from e
91
111
92
112
return VersionRange (version , version .next_breaking (), include_min = True )
93
113
@@ -127,8 +147,10 @@ def parse_single_constraint(constraint: str) -> VersionConstraint:
127
147
128
148
try :
129
149
version = Version .parse (version_string )
130
- except ValueError :
131
- raise ValueError (f"Could not parse version constraint: { constraint } " )
150
+ except InvalidVersion as e :
151
+ raise ParseConstraintError (
152
+ f"Could not parse version constraint: { constraint } "
153
+ ) from e
132
154
133
155
if op == "<" :
134
156
return VersionRange (max = version )
@@ -142,6 +164,4 @@ def parse_single_constraint(constraint: str) -> VersionConstraint:
142
164
return VersionUnion (VersionRange (max = version ), VersionRange (min = version ))
143
165
return version
144
166
145
- from poetry .core .constraints .version .exceptions import ParseConstraintError
146
-
147
167
raise ParseConstraintError (f"Could not parse version constraint: { constraint } " )
0 commit comments