FHPythonUtils/LicenseCheck

Bug: exception thrown if package is not installed

esran opened this issue · 1 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

An exception is thrown if a package is not currently installed.

Description

If the requirements file contains packages that are not installed then an exception is thrown.

This was introduced in version 2024.1.4 and does not occur with version 2024.1.3.

Expected Behavior

Requirements file:

uvicorn

Expected behaviour is to output the license information for uvicorn (and dependents). Using the following command:

licensecheck -u requirements:test.req --format=csv

Expected output

name,version,size,homePage,author,license,licenseCompat,errorCode,namever
click,8.1.7,352124,https://palletsprojects.com/p/click/,UNKNOWN,BSD LICENSE,True,0,click-8.1.7
h11,0.14.0,190839,https://github.com/python-hyper/h11,Nathaniel J. Smith,MIT LICENSE,True,0,h11-0.14.0
typing_extensions,4.10.0,134587,UNKNOWN,UNKNOWN,PYTHON SOFTWARE FOUNDATION LICENSE,True,0,typing_extensions-4.10.0
uvicorn,0.29.0,190818,UNKNOWN,UNKNOWN,BSD LICENSE,True,0,uvicorn-0.29.0

Actual Behavior

If uvicorn is not installed in the current venv then the following exception output occurs.

Traceback (most recent call last):
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 35, in getPackageInfoLocal
    pkgMetadata = metadata.metadata(requirement)
  File "/home/sean/.pyenv/versions/3.10.10/lib/python3.10/importlib/metadata/__init__.py", line 986, in metadata
    return Distribution.from_name(distribution_name).metadata
  File "/home/sean/.pyenv/versions/3.10.10/lib/python3.10/importlib/metadata/__init__.py", line 548, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for UVICORN

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

Traceback (most recent call last):
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 134, in getPackages
    packageinfo.add(getPackageInfoLocal(requirement))
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/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/sean/.pyenv/versions/scratch/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/cli.py", line 86, in cli
    sysexit(main(args))
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/cli.py", line 120, in main
    myLice, depsWithLicenses = get_deps.getDepsWithLicenses(
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/get_deps.py", line 232, in getDepsWithLicenses
    packages = packageinfo.getPackages(reqs)
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 137, in getPackages
    packageinfo.add(getPackageInfoPypi(requirement))
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 84, in getPackageInfoPypi
    homePage=_pkgMetadataGet(info, "home_page"),
  File "/home/sean/.pyenv/versions/3.10.10/envs/scratch/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 21, in _pkgMetadataGet
    value = JOINS.join(value)
TypeError: can only join an iterable

System Information

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

  • Operating System (OS): Ubuntu
  • OS Version: 22.04
  • Browser (if applicable): N/A
  • Browser Version (if applicable): B/A
  • Project Version (if applicable): licensecheck version 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