19
19
from poetry .core .constraints .generic import MultiConstraint
20
20
from poetry .core .constraints .generic import UnionConstraint
21
21
from poetry .core .constraints .version import VersionConstraint
22
+ from poetry .core .constraints .version .exceptions import ParseConstraintError
22
23
from poetry .core .version .grammars import GRAMMAR_PEP_508_MARKERS
23
24
from poetry .core .version .parser import Parser
24
25
@@ -313,12 +314,12 @@ def __init__(
313
314
314
315
parsed_constraint : BaseConstraint | VersionConstraint
315
316
parser : Callable [[str ], BaseConstraint | VersionConstraint ]
316
- constraint_string = str (constraint )
317
+ original_constraint_string = constraint_string = str (constraint )
317
318
318
319
# Extract operator and value
319
320
m = self ._CONSTRAINT_RE .match (constraint_string )
320
321
if m is None :
321
- raise InvalidMarker (f"Invalid marker ' { constraint_string } ' " )
322
+ raise InvalidMarker (f"Invalid marker for ' { name } ': { constraint_string } " )
322
323
323
324
self ._operator = m .group (1 )
324
325
if self ._operator is None :
@@ -346,9 +347,7 @@ def __init__(
346
347
if self ._operator == "in" :
347
348
glue = " || "
348
349
349
- parsed_constraint = parser (glue .join (versions ))
350
- else :
351
- parsed_constraint = parser (constraint_string )
350
+ constraint_string = glue .join (versions )
352
351
else :
353
352
# if we have a in/not in operator we split the constraint
354
353
# into a union/multi-constraint of single constraint
@@ -357,7 +356,12 @@ def __init__(
357
356
values = re .split ("[ ,]+" , self ._value )
358
357
constraint_string = glue .join (f"{ op } { value } " for value in values )
359
358
359
+ try :
360
360
parsed_constraint = parser (constraint_string )
361
+ except ParseConstraintError as e :
362
+ raise InvalidMarker (
363
+ f"Invalid marker for '{ name } ': { original_constraint_string } "
364
+ ) from e
361
365
362
366
super ().__init__ (name , parsed_constraint )
363
367
0 commit comments