def get_package_metadata(database, name, gotoWWW=False, update=False): """Extract infos (description, url) from the local database""" # Note: we could use the PyPI database but this has been written on # machine which is not connected to the internet # we store only normalized names now (PEP 503) db = cp.ConfigParser() db.readfp(open(osp.join(DATA_PATH, database))) my_metadata = dict( description='', url='https://pypi.org/project/' + name, ) for key in my_metadata: name1 = name.lower() # wheel replace '-' per '_' in key for name2 in ( name1, name1.split('-')[0], name1.replace('-', '_'), '-'.join(name1.split('_')), normalize(name), ): try: my_metadata[key] = db.get(name2, key) break except (cp.NoSectionError, cp.NoOptionError): pass database_desc = my_metadata.get('description') if my_metadata.get('description') == '' and metadata: # nothing in package.ini try: my_metadata['description']=( metadata(name)['Summary']+'\n').splitlines()[0] except: pass if my_metadata['description'] == '' and gotoWWW: the_official = get_official_description(name) if the_official != '': my_metadata['description'] = the_official if update == True and database_desc == '' and my_metadata['description'] !='': try: db[normalize(name)]={} db[normalize(name)]['description'] = my_metadata['description'] with open(osp.join(DATA_PATH, database), 'w') as configfile: db.write(configfile) except: pass return my_metadata
def test_metadata_loads_egg_info(self): pkg_name = self.pkg_with_non_ascii_description_egg_info(self.site_dir) meta = metadata(pkg_name) assert meta.get_payload() == 'pôrˈtend\n'
def test_metadata_loads(self): pkg_name = self.pkg_with_non_ascii_description(self.site_dir) meta = metadata(pkg_name) assert meta['Description'] == 'pôrˈtend'