12
12
from typing import Iterable
13
13
14
14
from poetry .core .constraints .version import VersionConstraint
15
+ from poetry .core .constraints .version .exceptions import ParseConstraintError
15
16
from poetry .core .version .grammars import GRAMMAR_PEP_508_MARKERS
16
17
from poetry .core .version .parser import Parser
17
18
@@ -212,12 +213,12 @@ def __init__(
212
213
self ._constraint : BaseConstraint | VersionConstraint
213
214
self ._parser : Callable [[str ], BaseConstraint | VersionConstraint ]
214
215
self ._name = ALIASES .get (name , name )
215
- constraint_string = str (constraint )
216
+ original_constraint_string = constraint_string = str (constraint )
216
217
217
218
# Extract operator and value
218
219
m = self ._CONSTRAINT_RE .match (constraint_string )
219
220
if m is None :
220
- raise InvalidMarker (f"Invalid marker ' { constraint_string } ' " )
221
+ raise InvalidMarker (f"Invalid marker: { constraint_string } " )
221
222
222
223
self ._operator = m .group (1 )
223
224
if self ._operator is None :
@@ -245,9 +246,7 @@ def __init__(
245
246
if self ._operator == "in" :
246
247
glue = " || "
247
248
248
- self ._constraint = self ._parser (glue .join (versions ))
249
- else :
250
- self ._constraint = self ._parser (constraint_string )
249
+ constraint_string = glue .join (versions )
251
250
else :
252
251
# if we have a in/not in operator we split the constraint
253
252
# into a union/multi-constraint of single constraint
@@ -256,7 +255,10 @@ def __init__(
256
255
values = re .split ("[ ,]+" , self ._value )
257
256
constraint_string = glue .join (f"{ op } { value } " for value in values )
258
257
258
+ try :
259
259
self ._constraint = self ._parser (constraint_string )
260
+ except ParseConstraintError as e :
261
+ raise InvalidMarker (f"Invalid marker: { original_constraint_string } " ) from e
260
262
261
263
@property
262
264
def name (self ) -> str :
0 commit comments