Skip to content

Bug: Exception thrown due to LicenseWithExceptionΒ #122

@mermerico

Description

@mermerico

Before You Begin

Before proceeding, please make sure to follow these steps:

  • I have checked for similar issues in the project's issue tracker.
  • I have searched closed issues to see if a similar problem was reported
    before.

Issue Details

Description

When running licensecheck on my project, I got the following error triggered by the pygit2 package:

Traceback (most recent call last):
  File "/home/mermerico/ds-blackbox.worktrees/dev-2025-q1/.ds/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/mermerico/ds-blackbox.worktrees/dev-2025-q1/.ds/lib/python3.11/site-packages/licensecheck/cli.py", line 117, in cli
    ec = main(args)
         ^^^^^^^^^^
  File "/home/mermerico/ds-blackbox.worktrees/dev-2025-q1/.ds/lib/python3.11/site-packages/licensecheck/cli.py", line 165, in main
    incompatible, depsWithLicenses = checker.check(
                                     ^^^^^^^^^^^^^^
  File "/home/mermerico/ds-blackbox.worktrees/dev-2025-q1/.ds/lib/python3.11/site-packages/licensecheck/checker.py", line 50, in check
    packages = package_info_manager.getPackages()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mermerico/ds-blackbox.worktrees/dev-2025-q1/.ds/lib/python3.11/site-packages/licensecheck/packageinfo.py", line 82, in getPackages
    package_info = self.get_package_info(package)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mermerico/ds-blackbox.worktrees/dev-2025-q1/.ds/lib/python3.11/site-packages/licensecheck/packageinfo.py", line 123, in get_package_info
    print(tokens[0].key)
          ^^^^^^^^^^^^^
AttributeError: 'LicenseWithExceptionSymbol' object has no attribute 'key'

I was able to resolve it by making the following modification to get_package_info() in packageinfo.py:

			tokens = sorted(parsed.literals)
			token_mapper = lambda x: x.key if type(x) is license_expression.LicenseSymbol else x.license_symbol.key + " WITH " + x.exception_symbol.key
			pkg_info.license = ucstr(JOINS.join(token_mapper(x) for x in tokens))

I don't know enough about the internal workings of licensecheck to know if this is a valid solution worthy of a PR. I just needed to use the tool for a one-off analysis. For context, tokens contains the following list after the parse() call for pygit2:
[LicenseWithExceptionSymbol(license_symbol=LicenseSymbol('GPLV2', is_exception=False), exception_symbol=LicenseSymbol('LINKING EXCEPTION', is_exception=False))]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions