@@ -90,10 +90,9 @@ def read_from_toml(cls, file, data):
9090
9191 # load the toml file as a dictionary
9292 try :
93- if not isinstance (toml_data := toml .load (file ), dict ):
94- return
95- except Exception as exc :
96- raise type (exc )(f"Something went wrong while reading the given file { file } " ) from exc
93+ toml_data = toml .load (file )
94+ except Exception :
95+ return
9796
9897 # harvest project table
9998 project_data = toml_data .get ("project" )
@@ -373,12 +372,11 @@ def handle_pypi_classifieres(cls, classifiers: str | list[str], data):
373372
374373 if not isinstance (classifiers , (str , list )):
375374 return
376- if isinstance (classifiers , str ):
375+ if isinstance (classifiers , str ) and len ( classifiers . split ( " :: " )) > 1 :
377376 classifiers = [classifiers ]
378377 else :
379- classifiers = [classifier for classifier in classifiers if isinstance (classifier , str )]
380- if len (classifiers ) == 0 :
381- return
378+ # remove non strings and to short classifiers
379+ classifiers = [clsf for clsf in classifiers if isinstance (clsf , str ) and len (clsf .split (" :: " )) > 1 ]
382380
383381 # remove duplicates
384382 classifiers = list (set (classifiers ))
@@ -390,15 +388,13 @@ def handle_pypi_classifieres(cls, classifiers: str | list[str], data):
390388 # iterate over all classifiers and put them into the correct buckets
391389 for classifier in classifiers :
392390 classifier = classifier .split (" :: " )
393- if len (classifier ) < 2 :
394- continue
395- if (classifier [0 ] == "Operating System" and not (len (classifier ) == 2 and classifier [1 ] == "Microsoft" )):
391+ if classifier [0 ] == "Operating System" and not (len (classifier ) == 2 and classifier [1 ] == "Microsoft" ):
396392 temp = {"@type" : "schema:SoftwareApplication" , "schema:name" : classifier [- 1 ]}
397393 sorted_classifiers ["schema:targetProduct" ].append (temp )
398394 elif classifier [0 ] == "Intended Audience" :
399395 temp = {"@type" : "schema:Audience" , "schema:name" : classifier [- 1 ]}
400396 sorted_classifiers ["schema:audience" ].append (temp )
401- elif ( classifier [0 ] == "License" and not (classifier [1 ] == "OSI Approved" and len (classifier ) == 2 ) ):
397+ elif classifier [0 ] == "License" and not (classifier [1 ] == "OSI Approved" and len (classifier ) == 2 ):
402398 temp = {"@type" : "schema:CreativeWork" , "schema:name" : classifier [- 1 ]}
403399 sorted_classifiers ["schema:license" ].append (temp )
404400 elif classifier [0 ] == "Natural Language" :
@@ -421,10 +417,9 @@ def handle_pypi_classifieres(cls, classifiers: str | list[str], data):
421417
422418 # add everything to the SoftwareMetadata object
423419 for key , value in sorted_classifiers .items ():
424- if len (value ) > 1 :
425- data [key ] = value
426- elif len (value ) == 1 :
427- data [key ] = value [0 ]
420+ if len (value ) == 0 :
421+ continue
422+ data [key ] = value if len (value ) > 1 else value [0 ]
428423
429424 @classmethod
430425 def handle_urls (cls , urls : dict [str , str ], data ):
0 commit comments