@@ -95,7 +95,7 @@ def get_attribute(setup_location, attribute):
9595 setup_text = open (setup_location , 'rb' ).read ()
9696 # FIXME Use a valid parser for parsing 'setup.py'
9797 values = re .findall ('setup\(.*?' + attribute + '=[\" \' ]{1}.*?\' ,' , setup_text .replace ('\n ' , '' ))
98- if len (values ) > 1 :
98+ if len (values ) > 1 or len ( values ) == 0 :
9999 return
100100 else :
101101 values = '' .join (values )
@@ -107,6 +107,11 @@ def get_attribute(setup_location, attribute):
107107
108108
109109def parse_metadata (location ):
110+ """
111+ Check if the directory at 'location' has both 'METADATA' and
112+ 'DESCRIPTION.rst' files. Parse a 'metadata.json' file at 'location' and
113+ return a PythonPackage object.
114+ """
110115 parent_dir = fileutils .parent_directory (location )
111116 if os .path .exists (os .path .join (parent_dir , 'METADATA' )) and os .path .exists (os .path .join (parent_dir , 'DESCRIPTION.rst' )):
112117 infos = json .loads (open (location , 'rb' ).read ())
@@ -135,7 +140,8 @@ def parse_metadata(location):
135140
136141def parse (location ):
137142 """
138- Parse a 'setup.py' and return a PythonPackage object.
143+ Parse a file at 'location' and return a PythonPackage object. File at
144+ 'location' can be a'setup.py' or 'metadata.json' or a 'PKG-INFO' file.
139145 """
140146 file_name = fileutils .file_name (location )
141147 if file_name == 'setup.py' :
0 commit comments