FHPythonUtils/LicenseCheck

Bug: Pre-commit hook fails with PackageNotFoundError

Excidion opened this issue · 3 comments

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

Running the pre-commit-hook fails with a PackageNotFoundError even though running licensecheck from the command line works fine.

Description

I created a new project with poetry resulting the the following pyproject.toml:

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = [""]
readme = "README.md"
license = "Apache 2.0"

[tool.poetry.dependencies]
python = "^3.10"

[tool.poetry.group.docs.dependencies]
licensecheck = "^2024.1.4"

[tool.poetry.group.dev.dependencies]
ipykernel = "^6.29.4"
pre-commit = "^3.7.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.licensecheck]
using = "poetry:dev;docs"
format = "markdown"
file = "docs/licenses.md"

Expected Behavior

The hook should run and generate the report file.

Actual Behavior

(test-py3.10) excidion@thinkbook-14-gen-6:~/dev/lic$ pre-commit run licensecheck
licensecheck.............................................................Failed
- hook id: licensecheck
- exit code: 1

Traceback (most recent call last):
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 35, in getPackageInfoLocal
    pkgMetadata = metadata.metadata(requirement)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 986, in metadata
    return Distribution.from_name(distribution_name).metadata
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 548, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for IPYKERNEL

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 134, in getPackages
    packageinfo.add(getPackageInfoLocal(requirement))
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 59, in getPackageInfoLocal
    raise ModuleNotFoundError from error
ModuleNotFoundError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/cli.py", line 86, in cli
    sysexit(main(args))
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/cli.py", line 120, in main
    myLice, depsWithLicenses = get_deps.getDepsWithLicenses(
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/get_deps.py", line 232, in getDepsWithLicenses
    packages = packageinfo.getPackages(reqs)
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 137, in getPackages
    packageinfo.add(getPackageInfoPypi(requirement))
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 84, in getPackageInfoPypi
    homePage=_pkgMetadataGet(info, "home_page"),
  File "/home/excidion/.cache/pre-commit/repop8ow40km/py_env-python3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 21, in _pkgMetadataGet
    value = JOINS.join(value)
TypeError: can only join an iterable

The weirdest thing is, every time i run it the first error message No package metadata was found for IPYKERNEL references a different package name.

System Information

Please provide the following additional information about your system or
environment:

  • Operating System (OS): Zorin OS
  • OS Version: 16.3
  • Browser (if applicable): -
  • Browser Version (if applicable): -
  • Project Version (if applicable): 2024.1.4

Hey thanks for this! The issue is a super misleading bug but just released a fix for this now. Basically calling "".joins() on a non iterable type (like an int, or None) is what leads to this. It's likely this is caused by some missing metadata which is why I didn't pick it up with the existing tests. Added tests and fixed in https://github.com/FHPythonUtils/LicenseCheck/releases/tag/2024.1.5

That fixed it, thank you for the quick response! :)

Perfect! Really pleased that's sorted. And yeah no worries at all! Must admit it was very much a face palm moment that bug!