2
2
import os
3
3
import importlib
4
4
import re
5
+ import ast
5
6
from typing import Union , IO
6
7
7
8
if sys .version_info .minor < 8 :
@@ -31,6 +32,11 @@ def splitdependencies(s: str):
31
32
"""Split a string of multiple (python) dependencies"""
32
33
begin = 0
33
34
depth = 0
35
+ if s and s .find ("{" ) != - 1 and s .strip ()[- 1 ] == "}" :
36
+ # dependency is a dict-like structures usually from pyproject.toml {'version':.. , 'extras':... }, it does not contain multiple, return as is
37
+ yield s
38
+ return
39
+ #normal behaviour; PEP-style dependency parsing
34
40
for i , c in enumerate (s ):
35
41
if c == "(" :
36
42
depth += 1
@@ -53,6 +59,7 @@ def parsedependency(s: str):
53
59
s .find ("~" ) if s .find ("~" ) != - 1 else 999999 ,
54
60
s .find ("=" ) if s .find ("=" ) != - 1 else 999999 ,
55
61
s .find ("^" ) if s .find ("^" ) != - 1 else 999999 ,
62
+ s .find ("{" ) if s .find ("{" ) != - 1 else 999999 ,
56
63
)
57
64
if end != 999999 :
58
65
identifier = s [:end ]
@@ -66,7 +73,20 @@ def parsedependency(s: str):
66
73
break
67
74
if versionbegin != - 1 :
68
75
operator = s [end :versionbegin ].strip ()
69
- if operator in ("=" , "==" ):
76
+ if s [versionbegin ] == "{" :
77
+ version = s [versionbegin :].strip ()
78
+ if version and version [0 ] == "{" and version [- 1 ] == "}" :
79
+ try :
80
+ data = ast .literal_eval (version )
81
+ if 'version' in data :
82
+ return identifier , data ['version' ]
83
+ else :
84
+ print ("Unable to parse dependency version (key not found):" , version ,file = sys .stderr )
85
+ version = ""
86
+ except :
87
+ print ("Unable to parse dependency version: " , version ,file = sys .stderr )
88
+ version = ""
89
+ elif operator in ("=" , "==" ):
70
90
version = s [versionbegin :].strip ()
71
91
else :
72
92
version = operator + " " + s [versionbegin :].strip ()
0 commit comments