Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: crash where no classifiers field exists #14

Closed
3 tasks done
takeda opened this issue Sep 13, 2021 · 16 comments
Closed
3 tasks done

Bug: crash where no classifiers field exists #14

takeda opened this issue Sep 13, 2021 · 16 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@takeda
Copy link

takeda commented Sep 13, 2021

Bug

  • I have read the comment above and have completed each step
  • I have filled out the system info
  • I have described the bug, filled in the expected outcome and the actual
    outcome including screenshots where appropriate

System info

  • OS: N/A
  • Browser: N/A
  • Version: 2021.4.1

Describe the bug

When classifiers is not defined in pyproject.toml licensecheck crashes with an error that can confuse new users.

Expected outcome

Program working

Actual outcome

Exception like this:

Traceback (most recent call last):
  File "<snip>/.venv/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
  File "<snip>/.venv/lib/python3.8/site-packages/licensecheck/__init__.py", line 84, in cli
    dependenciesWLicenses = get_deps.getDepsWLicenses(
  File "<snip>/.venv/lib/python3.8/site-packages/licensecheck/get_deps.py", line 107, in getDepsWLicenses
    myLiceTxt = packageinfo.getMyPackageLicense()
  File "<snip>/.venv/lib/python3.8/site-packages/licensecheck/packageinfo.py", line 201, in getMyPackageLicense
    licenseClassifier = licenseFromClassifierlist(metaData["classifiers"])  # type:ignore
  File "/<snip>/.venv/lib/python3.8/site-packages/tomlkit/items.py", line 1007, in __getitem__
    return self._value[key]
  File "<snip>/.venv/lib/python3.8/site-packages/tomlkit/container.py", line 553, in __getitem__
    raise NonExistentKey(key)
tomlkit.exceptions.NonExistentKey: 'Key "classifiers" does not exist.'
@takeda takeda added the bug Something isn't working label Sep 13, 2021
@FredHappyface
Copy link
Member

Have you specified the license at all in the pyproject.toml file?

For example

[tool.poetry]
license= "mit"

@takeda
Copy link
Author

takeda commented Sep 13, 2021

Yes I did, although my value is:

license = "proprietary"

I thought licensecheck completly ignored that.

@FredHappyface
Copy link
Member

If you change that to mit for the purposes of testing then it should work fine

What I'll need to do is provide some more useful warnings/errors in the case of an 'invalid' license and in the event license and classifiers are blank

@FredHappyface FredHappyface added this to the 2021.5 milestone Sep 13, 2021
@FredHappyface
Copy link
Member

Fixed in 746eace

@takeda
Copy link
Author

takeda commented Sep 14, 2021

@FredHappyface the #15 was fixed, but #14 is still there

746eace#diff-f57c096bd6398fbed56e24e43f5e856dbe357704addd15869f01809a20e9627eR204

licenseClassifier = licenseFromClassifierlist(metaData["classifiers"])

I believe should be

licenseClassifier = licenseFromClassifierlist(metaData.get("classifiers", []))

Note that I don't know if metaData is a dict() so this might still be wrong.

@bruceadams
Copy link

I am very confused. Even on pretty much the simplest poetry project I can imagine running licensecheck fails giving me the error:

tomlkit.exceptions.NonExistentKey: 'Key "classifiers" does not exist.'

Steps to reproduce:

$ git clone https://github.com/bruceadams/discovery-files.git
Cloning into 'discovery-files'...
remote: Enumerating objects: 239, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 239 (delta 0), reused 3 (delta 0), pack-reused 235
Receiving objects: 100% (239/239), 144.36 KiB | 4.25 MiB/s, done.
Resolving deltas: 100% (140/140), done.
$ cd discovery-files
$ poetry install
Creating virtualenv discovery-files-bb0M-Gbu-py3.9 in /Users/bruce/Library/Caches/pypoetry/virtualenvs
Installing dependencies from lock file

Package operations: 38 installs, 0 updates, 0 removals

  • Installing certifi (2021.10.8)
  • Installing charset-normalizer (2.0.11)
  • Installing idna (3.3)
  • Installing six (1.16.0)
  • Installing urllib3 (1.26.8)
  • Installing attrs (21.4.0)
  • Installing lazy-object-proxy (1.7.1)
  • Installing pyjwt (2.3.0)
  • Installing pyparsing (3.0.7)
  • Installing python-dateutil (2.8.2)
  • Installing requests (2.27.1)
  • Installing tomli (2.0.0)
  • Installing types-setuptools (57.4.8)
  • Installing typing-extensions (4.0.1)
  • Installing wrapt (1.13.3)
  • Installing astroid (2.9.3)
  • Installing click (8.0.3)
  • Installing fhconfparser (2022)
  • Installing ibm-cloud-sdk-core (0.5.2)
  • Installing iniconfig (1.1.1)
  • Installing isort (5.10.1)
  • Installing mccabe (0.6.1)
  • Installing mypy-extensions (0.4.3)
  • Installing packaging (21.3)
  • Installing pathspec (0.9.0)
  • Installing platformdirs (2.4.1)
  • Installing pluggy (1.0.0)
  • Installing py (1.11.0)
  • Installing requirements-parser (0.5.0)
  • Installing toml (0.10.2)
  • Installing tomlkit (0.9.0)
  • Installing websocket-client (0.48.0)
  • Installing black (22.1.0)
  • Installing ibm-watson (3.4.2)
  • Installing licensecheck (2022)
  • Installing mypy (0.931)
  • Installing pylint (2.12.2)
  • Installing pytest (6.2.5)
$ poetry run licensecheck
Traceback (most recent call last):
  File "/Users/bruce/Library/Caches/pypoetry/virtualenvs/discovery-files-bb0M-Gbu-py3.9/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
  File "/Users/bruce/Library/Caches/pypoetry/virtualenvs/discovery-files-bb0M-Gbu-py3.9/lib/python3.9/site-packages/licensecheck/__init__.py", line 90, in cli
    dependenciesWLicenses = get_deps.getDepsWLicenses(
  File "/Users/bruce/Library/Caches/pypoetry/virtualenvs/discovery-files-bb0M-Gbu-py3.9/lib/python3.9/site-packages/licensecheck/get_deps.py", line 107, in getDepsWLicenses
    myLiceTxt = packageinfo.getMyPackageLicense()
  File "/Users/bruce/Library/Caches/pypoetry/virtualenvs/discovery-files-bb0M-Gbu-py3.9/lib/python3.9/site-packages/licensecheck/packageinfo.py", line 143, in getMyPackageLicense
    licenseClassifier = licenseFromClassifierlist(metaData["classifiers"])
  File "/Users/bruce/Library/Caches/pypoetry/virtualenvs/discovery-files-bb0M-Gbu-py3.9/lib/python3.9/site-packages/tomlkit/items.py", line 1229, in __getitem__
    return cast(Item, self._value[key])
  File "/Users/bruce/Library/Caches/pypoetry/virtualenvs/discovery-files-bb0M-Gbu-py3.9/lib/python3.9/site-packages/tomlkit/container.py", line 606, in __getitem__
    raise NonExistentKey(key)
tomlkit.exceptions.NonExistentKey: 'Key "classifiers" does not exist.'

@takeda
Copy link
Author

takeda commented Feb 1, 2022

@bruceadams This is what I was talking about. I think you should open a brand new issue, and could reference this one. I believe this issue no longer notifies the author about responses.

@FredHappyface
Copy link
Member

You're correct, just seen this now - apologies for this. Reopened

@FredHappyface FredHappyface reopened this Feb 1, 2022
@bruceadams
Copy link

Oh! If I just add classifiers = [] in my pyproject.toml, the tool runs fine! (I'm not publishing my packages, so classifiers is not relevant to my packages.)

@FredHappyface
Copy link
Member

Yeah absolutely, I've updated with (hopefully) a fix and removed a couple packages - the update (2022.0.1) does require py >= 3.8 though

@FredHappyface
Copy link
Member

Keeping this open awaiting confirmation this time. Sorry again for missing the comments before

@bruceadams
Copy link

Updating to licensecheck 2022.0.1 and all is good! 🎉🎊 Thanks!

$ poetry run licensecheck
┌──────────┬────────────────────┬────────────────────┐
│Compatible│Package             │License             │
├──────────┼────────────────────┼────────────────────┤
│True      │certifi             │Mozilla Public Licen│
│True      │charset-normalizer  │MIT License         │
│True      │ibm-cloud-sdk-core  │Apache Software Lice│
│True      │ibm-watson          │Apache Software Lice│
│True      │idna                │BSD License         │
│True      │pyjwt               │MIT License         │
│True      │python-dateutil     │Apache Software Lice│
│True      │requests            │Apache Software Lice│
│True      │six                 │MIT License         │
│True      │urllib3             │MIT License         │
│True      │websocket-client    │Apache Software Lice│
└──────────┴────────────────────┴────────────────────┘

I'm mostly on Python 3.9; requiring 3.8 is no problem at all for me.

@takeda
Copy link
Author

takeda commented Feb 4, 2022

@FredHappyface after the update I got:

Traceback (most recent call last):
  File "~/.venv/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
  File "~/.venv/lib/python3.9/site-packages/licensecheck/__init__.py", line 90, in cli
    dependenciesWLicenses = get_deps.getDepsWLicenses(
  File "~/.venv/lib/python3.9/site-packages/licensecheck/get_deps.py", line 112, in getDepsWLicenses
    for package in packageinfo.getPackages(reqs):
  File "~/.venv/lib/python3.9/site-packages/licensecheck/packageinfo.py", line 115, in getPackages
    localReqs = getPackagesFromLocal(reqs)
  File "~/.venv/lib/python3.9/site-packages/licensecheck/packageinfo.py", line 49, in getPackagesFromLocal
    "size": getModuleSize(cast(Path, resources.files(requirement)), name),
  File "/nix/store/qx995zl14gqgx0ly0hwx3cy0fcz27ich-python3-3.9.6/lib/python3.9/importlib/resources.py", line 147, in files
    return _common.from_package(_get_package(package))
  File "/nix/store/qx995zl14gqgx0ly0hwx3cy0fcz27ich-python3-3.9.6/lib/python3.9/importlib/resources.py", line 51, in _get_package
    raise TypeError('{!r} is not a package'.format(package))
TypeError: 'tabulate' is not a package

Also I got this error when trying to update licensecheck:

 poetry add -D licensecheck@latest
Using version ^2022.0.1 for licensecheck

Updating dependencies
Resolving dependencies... (1.4s)

  SolverProblemError

  Because no versions of black match >21.9b0,<21.10b0 || >21.10b0,<21.11b0 || >21.11b0,<21.11b1 || >21.11b1,<21.12b0 || >21.12b0,<22.0
   and black (21.9b0) depends on tomli (>=0.2.6,<2.0.0), black (>=21.9b0,<21.10b0 || >21.10b0,<21.11b0 || >21.11b0,<21.11b1 || >21.11b1,<21.12b0 || >21.12b0,<22.0) requires tomli (>=0.2.6,<2.0.0).
  And because black (21.10b0) depends on tomli (>=0.2.6,<2.0.0)
   and black (21.11b0) depends on tomli (>=0.2.6,<2.0.0), black (>=21.9b0,<21.11b1 || >21.11b1,<21.12b0 || >21.12b0,<22.0) requires tomli (>=0.2.6,<2.0.0).
  And because black (21.11b1) depends on tomli (>=0.2.6,<2.0.0)
   and black (21.12b0) depends on tomli (>=0.2.6,<2.0.0), black (>=21.9b0,<22.0) requires tomli (>=0.2.6,<2.0.0).
  Because no versions of licensecheck match >2022.0.1,<2023.0.0
   and licensecheck (2022.0.1) depends on tomli (>=2.0.0,<3), licensecheck (>=2022.0.1,<2023.0.0) requires tomli (>=2.0.0,<3).
  Thus, licensecheck (>=2022.0.1,<2023.0.0) is incompatible with black (>=21.9b0,<22.0).
  So, because amiman depends on both black (^21.9b0) and licensecheck (^2022.0.1), version solving failed.

But, after I removed black then updated licensecheck then I was able to install black again.

@takeda
Copy link
Author

takeda commented Feb 4, 2022

I think the conflict could be that previously black was ^21.9b0 but when I removed and added it upgraded to ^22.1.0.

@Niccolum
Copy link

Niccolum commented Apr 4, 2022

Maybe close ticket? Or some problem still exists?
@takeda

@takeda
Copy link
Author

takeda commented Apr 4, 2022

Good point, after that I did not see it happening anymore, so I'm closing it.

@takeda takeda closed this as completed Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants