@@ -195,7 +195,7 @@ def make_base_requirements(reqs):
195
195
requirements .add (req )
196
196
elif isinstance (req , pkg_resources_requirements .Requirement ):
197
197
requirements .add (BaseRequirement .from_req (req ))
198
- elif req and not req .startswith ("#" ):
198
+ elif req and isinstance ( req , six . string_types ) and not req .startswith ("#" ):
199
199
requirements .add (BaseRequirement .from_string (req ))
200
200
return requirements
201
201
@@ -240,10 +240,15 @@ def get_package_dir_from_setupcfg(parser, base_dir=None):
240
240
if "package_dir" in setup_py :
241
241
package_lookup = setup_py ["package_dir" ]
242
242
if not isinstance (package_lookup , Mapping ):
243
- return package_lookup
244
- return package_lookup .get (
243
+ package_dir = package_lookup
244
+ package_dir = package_lookup .get (
245
245
next (iter (list (package_lookup .keys ()))), package_dir
246
246
)
247
+ if not os .path .isabs (package_dir ):
248
+ if not base_dir :
249
+ package_dir = os .path .join (os .path .getcwd (), package_dir )
250
+ else :
251
+ package_dir = os .path .join (base_dir , package_dir )
247
252
return package_dir
248
253
249
254
@@ -296,7 +301,8 @@ def parse_setup_cfg(setup_cfg_path):
296
301
parser = configparser .ConfigParser (default_opts )
297
302
parser .read (setup_cfg_path )
298
303
results = {}
299
- package_dir = get_package_dir_from_setupcfg (parser , base_dir = os .getcwd ())
304
+ base_dir = os .path .dirname (os .path .abspath (setup_cfg_path ))
305
+ package_dir = get_package_dir_from_setupcfg (parser , base_dir = base_dir )
300
306
name , version = get_name_and_version_from_setupcfg (parser , package_dir )
301
307
results ["name" ] = name
302
308
results ["version" ] = version
@@ -638,6 +644,8 @@ def __init__(self):
638
644
self .functions = []
639
645
self .strings = []
640
646
self .assignments = {}
647
+ self .binOps = []
648
+ self .binOps_map = {}
641
649
super (Analyzer , self ).__init__ ()
642
650
643
651
def generic_visit (self , node ):
@@ -652,6 +660,17 @@ def generic_visit(self, node):
652
660
self .assignments .update (ast_unparse (node , initial_mapping = True ))
653
661
super (Analyzer , self ).generic_visit (node )
654
662
663
+ def visit_BinOp (self , node ):
664
+ left = ast_unparse (node .left , initial_mapping = True )
665
+ right = ast_unparse (node .right , initial_mapping = True )
666
+ node .left = left
667
+ node .right = right
668
+ self .binOps .append (node )
669
+
670
+ def unmap_binops (self ):
671
+ for binop in self .binOps :
672
+ self .binOps_map [binop ] = ast_unparse (binop , analyzer = self )
673
+
655
674
def match_assignment_str (self , match ):
656
675
return next (
657
676
iter (k for k in self .assignments if getattr (k , "id" , "" ) == match ), None
@@ -678,6 +697,26 @@ def ast_unparse(item, initial_mapping=False, analyzer=None, recurse=True): # no
678
697
unparsed = item .s
679
698
elif isinstance (item , ast .Subscript ):
680
699
unparsed = unparse (item .value )
700
+ elif isinstance (item , ast .BinOp ):
701
+ if analyzer and item in analyzer .binOps_map :
702
+ unparsed = analyzer .binOps_map [item ]
703
+ elif isinstance (item .op , ast .Add ):
704
+ if not initial_mapping :
705
+ right_item = unparse (item .right )
706
+ left_item = unparse (item .left )
707
+ if not all (
708
+ isinstance (side , (six .string_types , int , float , list , tuple ))
709
+ for side in (left_item , right_item )
710
+ ):
711
+ item .left = left_item
712
+ item .right = right_item
713
+ unparsed = item
714
+ else :
715
+ unparsed = right_item + left_item
716
+ else :
717
+ unparsed = item
718
+ elif isinstance (item .op , ast .Sub ):
719
+ unparsed = unparse (item .left ) - unparse (item .right )
681
720
elif isinstance (item , ast .Name ):
682
721
if not initial_mapping :
683
722
unparsed = item .id
@@ -787,6 +826,7 @@ def ast_parse_setup_py(path):
787
826
# type: (S) -> Dict[Any, Any]
788
827
ast_analyzer = ast_parse_file (path )
789
828
setup = {} # type: Dict[Any, Any]
829
+ ast_analyzer .unmap_binops ()
790
830
for k , v in ast_analyzer .function_map .items ():
791
831
fn_name = ""
792
832
if isinstance (k , ast .Name ):
0 commit comments