Skip to content

BUG: packagedcode.pypi.get_declared_license breaks on some METADATA content #4174

@tdruez

Description

@tdruez

From aboutcode-org/scancode.io#1616 (comment)

Error raised when running the PythonInstalledWheelMetadataFile.parse on those files: metatdata_files.zip

>>> from packagedcode.pypi import PythonInstalledWheelMetadataFile

>>> location = "beartype-0.19.0.dist-info.METADATA"
>>> results = PythonInstalledWheelMetadataFile.parse(location=location, package_only=False)
>>> print(list(results))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Volumes/nexB/repos/scancode.io/.venv/lib/python3.12/site-packages/packagedcode/pypi.py", line 380, in parse
    yield parse_metadata(
          ^^^^^^^^^^^^^^^
  File "/Volumes/nexB/repos/scancode.io/.venv/lib/python3.12/site-packages/packagedcode/pypi.py", line 1013, in parse_metadata
    extracted_license_statement, license_file = get_declared_license(metainfo=meta)
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/nexB/repos/scancode.io/.venv/lib/python3.12/site-packages/packagedcode/pypi.py", line 1686, in get_declared_license
    license_file = lic.pop('file')
                   ^^^^^^^
AttributeError: 'str' object has no attribute 'pop'

Bug in the get_delcared_license function.

  1. The lic.pop('file') should have a default value in any cases, such as lic.pop('file', None)
  2. Fix the issue the licenses are properly detected on those 2 files.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions