Skip to content

Bug: crash if setup.cfg exists with no metadata section #34

@nikaro

Description

@nikaro

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: Darwin ***** 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64
  • Version: licensecheck==2023.0.1

Describe the bug

It crashes if you have a setup.cfg file that does not contain [metadata] section (for example, with only flake8 configuration).

Expected outcome

List licenses used.

Actual outcome

Traceback (most recent call last):
  File "/Users/nicolas.karolak/Library/Caches/pypoetry/virtualenvs/silvr-app-EZRmeXuX-py3.10/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
  File "/Users/nicolas.karolak/Library/Caches/pypoetry/virtualenvs/silvr-app-EZRmeXuX-py3.10/lib/python3.10/site-packages/licensecheck/__init__.py", line 90, in cli
    depsWithLicenses = get_deps.getDepsWithLicenses(
  File "/Users/nicolas.karolak/Library/Caches/pypoetry/virtualenvs/silvr-app-EZRmeXuX-py3.10/lib/python3.10/site-packages/licensecheck/get_deps.py", line 112, in getDepsWithLicenses
    myLiceTxt = packageinfo.getMyPackageLicense()
  File "/Users/nicolas.karolak/Library/Caches/pypoetry/virtualenvs/silvr-app-EZRmeXuX-py3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 157, in getMyPackageLicense
    metaData = getMyPackageMetadata()
  File "/Users/nicolas.karolak/Library/Caches/pypoetry/virtualenvs/silvr-app-EZRmeXuX-py3.10/lib/python3.10/site-packages/licensecheck/packageinfo.py", line 136, in getMyPackageMetadata
    if "license" in config["metadata"]:
  File "/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/configparser.py", line 965, in __getitem__
    raise KeyError(key)
KeyError: 'metadata'

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