@@ -60,27 +60,25 @@ def project2licenses(project: dict[str, Any], lfac: 'LicenseFactory', *,
6060 # https://peps.python.org/pep-0621/#classifiers
6161 # https://packaging.python.org/en/latest/specifications/core-metadata/#classifier-multiple-use
6262 yield from classifiers2licenses (classifiers , lfac , lack )
63- if plicense := project .get ('license' ):
64- # Only handle PEP 621 (dict) license formats
65- if isinstance (plicense , dict ):
66- if 'file' in plicense and 'text' in plicense :
67- raise ValueError ('`license.file` and `license.text` are mutually exclusive,' )
68- if 'file' in plicense :
69- with open (join (dirname (fpath ), plicense ['file' ]), 'rb' ) as plicense_fileh :
70- yield DisjunctiveLicense (name = f"declared license of '{ project ['name' ]} '" ,
71- acknowledgement = lack ,
72- text = AttachedText (encoding = Encoding .BASE_64 ,
73- content = b64encode (plicense_fileh .read ()).decode ()))
74- elif len (plicense_text := plicense .get ('text' , '' )) > 0 :
75- license = lfac .make_from_string (plicense_text ,
76- license_acknowledgement = lack )
77- if isinstance (license , DisjunctiveLicense ) and license .id is None :
78- yield DisjunctiveLicense (name = f"declared license of '{ project ['name' ]} '" ,
79- acknowledgement = lack ,
80- text = AttachedText (content = plicense_text ))
81- else :
82- yield license
83- # Silently skip any other types (including string/PEP 639)
63+ if isinstance (plicense := project .get ('license' ), dict ):
64+ if 'file' in plicense and 'text' in plicense :
65+ raise ValueError ('`license.file` and `license.text` are mutually exclusive,' )
66+ if 'file' in plicense :
67+ with open (join (dirname (fpath ), plicense ['file' ]), 'rb' ) as plicense_fileh :
68+ yield DisjunctiveLicense (name = f"declared license of '{ project ['name' ]} '" ,
69+ acknowledgement = lack ,
70+ text = AttachedText (encoding = Encoding .BASE_64 ,
71+ content = b64encode (plicense_fileh .read ()).decode ()))
72+ elif len (plicense_text := plicense .get ('text' , '' )) > 0 :
73+ license = lfac .make_from_string (plicense_text ,
74+ license_acknowledgement = lack )
75+ if isinstance (license , DisjunctiveLicense ) and license .id is None :
76+ yield DisjunctiveLicense (name = f"declared license of '{ project ['name' ]} '" ,
77+ acknowledgement = lack ,
78+ text = AttachedText (content = plicense_text ))
79+ else :
80+ yield license
81+ # Silently skip any other types (including string/PEP 639)
8482
8583
8684def project2extrefs (project : dict [str , Any ]) -> Generator ['ExternalReference' , None , None ]:
0 commit comments