@@ -659,19 +659,12 @@ def normalize(this):
659659 """apply https://peps.python.org/pep-0503/#normalized-names"""
660660 return re .sub (r"[-_.]+" , "-" , this ).lower ()
661661
662- def get_package_metadata (database , name , update = False , suggested_summary = None ):
662+ def get_package_metadata (database , name ):
663663 """Extract infos (description, url) from the local database"""
664- # for package.ini safety belt
665- # Note: we could use the PyPI database but this has been written on
666- # machine which is not connected to the internet
667- # we store only normalized names now (PEP 503)
668664 DATA_PATH = str (Path (sys .modules ['winpython' ].__file__ ).parent / 'data' )
669665 db = cp .ConfigParser ()
670666 filepath = Path (database ) if Path (database ).is_absolute () else Path (DATA_PATH ) / database
671- try :
672- db .read_file (open (str (filepath ), encoding = 'utf-8' ))
673- except :
674- db .read_file (open (str (filepath )))
667+ db .read_file (open (str (filepath ), encoding = guess_encoding (filepath )[0 ]))
675668 my_metadata = dict (
676669 description = "" ,
677670 url = "https://pypi.org/project/" + name ,
@@ -684,26 +677,7 @@ def get_package_metadata(database, name, update=False, suggested_summary=None):
684677 break
685678 except (cp .NoSectionError , cp .NoOptionError ):
686679 pass
687- db_desc = my_metadata .get ("description" )
688680
689- if my_metadata .get ("description" ) == "" and suggested_summary :
690- # nothing in package.ini, we look in our installed packages
691- try :
692- my_metadata ["description" ] = (
693- suggested_summary + "\n "
694- ).splitlines ()[0 ]
695- except :
696- pass
697-
698- if update == True and db_desc == "" and my_metadata ["description" ] != "" :
699- # we add new findings in our packgages.ini list, if it's required
700- try :
701- db [normalize (name )] = {}
702- db [normalize (name )]["description" ] = my_metadata ["description" ]
703- with open (str (Path (DATA_PATH ) / database ), "w" , encoding = 'UTF-8' ) as configfile :
704- db .write (configfile )
705- except :
706- pass
707681 return my_metadata
708682
709683
0 commit comments