FHPythonUtils / LicenseCheck

Output the licenses used by dependencies and check if these are compatible with the project license
MIT License
52 stars 18 forks source link

Incorrect format toml file to json.dumps #18

Closed Niccolum closed 2 years ago

Niccolum commented 2 years ago

Bug

System info

Describe the bug

Fail on formatter Version to json.dumps

    # Format the results
    if simpleConf.get("format", "simple") in formatter.formatMap:
        print(dependenciesWLicenses)  # add here print
        print(
            formatter.formatMap[simpleConf.get("format", "simple")](dependenciesWLicenses),
            file=filename,
        )
    else:
        exitCode = 2
$ poetry run licensecheck --zero

Expected outcome

OK

Actual outcome

[{'name': 'uvicorn', 'version': <Version('0.16.0')>, 'namever': 'uvicorn 0.16.0', 'home_page': 'https://www.uvicorn.org/', 'author': 'Tom Christie', 'size': 158778, 'license': 'BSD License', 'license_compat': True}, {'name': 'typing-extensions', 'version': <Version('4.0.1')>, 'namever': 'typing_extensions 4.0.1', 'home_page': 'UNKNOWN', 'author': 'UNKNOWN', 'size': 22706, 'license': 'Python Software Foundation License', 'license_compat': True}, {'name': 'starlette', 'version': <Version('0.17.1')>, 'namever': 'starlette 0.17.1', 'home_page': 'https://github.com/encode/starlette', 'author': 'Tom Christie', 'size': 186061, 'license': 'BSD License', 'license_compat': True}, {'name': 'starlette-csrf', 'version': <Version('1.4.0')>, 'namever': 'starlette-csrf 1.4.0', 'home_page': 'https://github.com/frankie567/starlette-csrf', 'author': 'François Voron', 'size': 3968, 'license': 'MIT License', 'license_compat': True}, {'name': 'sniffio', 'version': <Version('1.2.0')>, 'namever': 'sniffio 1.2.0', 'home_page': 'https://github.com/python-trio/sniffio', 'author': 'Nathaniel J. Smith', 'size': 4750, 'license': 'MIT License, Apache Software License', 'license_compat': True}, {'name': 'single-source', 'version': <Version('0.2.0')>, 'namever': 'single-source 0.2.0', 'home_page': 'https://github.com/rabbit72/single-source', 'author': 'Daniil Shadrin', 'size': 3898, 'license': 'MIT License', 'license_compat': True}, {'name': 'secweb', 'version': <Version('1.3.0')>, 'namever': 'Secweb 1.3.0', 'home_page': 'https://github.com/tmotagam/Secweb', 'author': 'Motagamwala Taha Arif Ali', 'size': 19418, 'license': 'Mozilla Public License 2.0 (MPL 2.0)', 'license_compat': True}, {'name': 'rfc3986', 'version': <Version('1.5.0')>, 'namever': 'rfc3986 1.5.0', 'home_page': 'http://rfc3986.readthedocs.io', 'author': 'Ian Stapleton Cordasco', 'size': 94910, 'license': 'Apache Software License', 'license_compat': True}, {'name': 'pydantic', 'version': <Version('1.9.0')>, 'namever': 'pydantic 1.9.0', 'home_page': 'https://github.com/samuelcolvin/pydantic', 'author': 'Samuel Colvin', 'size': 43343619, 'license': 'MIT License', 'license_compat': True}, {'name': 'itsdangerous', 'version': <Version('2.0.1')>, 'namever': 'itsdangerous 2.0.1', 'home_page': 'https://palletsprojects.com/p/itsdangerous/', 'author': 'Armin Ronacher', 'size': 45403, 'license': 'BSD License', 'license_compat': True}, {'name': 'idna', 'version': <Version('3.3')>, 'namever': 'idna 3.3', 'home_page': 'https://github.com/kjd/idna', 'author': 'Kim Davies', 'size': 267666, 'license': 'BSD License', 'license_compat': True}, {'name': 'httpx', 'version': <Version('0.21.3')>, 'namever': 'httpx 0.21.3', 'home_page': 'https://github.com/encode/httpx', 'author': 'Tom Christie', 'size': 273039, 'license': 'BSD License', 'license_compat': True}, {'name': 'httpcore', 'version': <Version('0.14.4')>, 'namever': 'httpcore 0.14.4', 'home_page': 'https://github.com/encode/httpcore', 'author': 'Tom Christie', 'size': 180787, 'license': 'BSD License', 'license_compat': True}, {'name': 'h11', 'version': <Version('0.12.0')>, 'namever': 'h11 0.12.0', 'home_page': 'https://github.com/python-hyper/h11', 'author': 'Nathaniel J. Smith', 'size': 167163, 'license': 'MIT License', 'license_compat': True}, {'name': 'gunicorn', 'version': <Version('20.1.0')>, 'namever': 'gunicorn 20.1.0', 'home_page': 'https://gunicorn.org', 'author': 'Benoit Chesneau', 'size': 241482, 'license': 'MIT License', 'license_compat': True}, {'name': 'fastapi', 'version': <Version('0.71.0')>, 'namever': 'fastapi 0.71.0', 'home_page': 'https://github.com/tiangolo/fastapi', 'author': 'Sebastián Ramírez', 'size': 202999, 'license': 'MIT License', 'license_compat': True}, {'name': 'click', 'version': <Version('8.0.3')>, 'namever': 'click 8.0.3', 'home_page': 'https://palletsprojects.com/p/click/', 'author': 'Armin Ronacher', 'size': 341344, 'license': 'BSD License', 'license_compat': True}, {'name': 'charset-normalizer', 'version': <Version('2.0.10')>, 'namever': 'charset-normalizer 2.0.10', 'home_page': 'https://github.com/ousret/charset_normalizer', 'author': 'Ahmed TAHRI @Ousret', 'size': 130739, 'license': 'MIT License', 'license_compat': True}, {'name': 'certifi', 'version': <Version('2021.10.8')>, 'namever': 'certifi 2021.10.8', 'home_page': 'https://certifiio.readthedocs.io/en/latest/', 'author': 'Kenneth Reitz', 'size': 268577, 'license': 'Mozilla Public License 2.0 (MPL 2.0)', 'license_compat': True}, {'name': 'asgiref', 'version': <Version('3.4.1')>, 'namever': 'asgiref 3.4.1', 'home_page': 'https://github.com/django/asgiref/', 'author': 'Django Software Foundation', 'size': 59054, 'license': 'BSD License', 'license_compat': True}, {'name': 'anyio', 'version': <Version('3.4.0')>, 'namever': 'anyio 3.4.0', 'home_page': 'UNKNOWN', 'author': 'Alex Grönholm', 'size': 276992, 'license': 'MIT License', 'license_compat': True}, {'name': 'colorama', 'version': '0.4.4', 'namever': 'colorama 0.4.4', 'home_page': 'https://github.com/tartley/colorama', 'author': 'Jonathan Hartley', 'size': 27813, 'license': 'BSD License', 'license_compat': True}]

Traceback (most recent call last):
  File "/home/niccolum/projects/github/fellowmate/auth/.venv/bin/licensecheck", line 8, in <module>
    sys.exit(cli())
  File "/home/niccolum/projects/github/fellowmate/auth/.venv/lib/python3.10/site-packages/licensecheck/__init__.py", line 96, in cli
    formatter.formatMap[simpleConf.get("format", "simple")](dependenciesWLicenses),
  File "/home/niccolum/projects/github/fellowmate/auth/.venv/lib/python3.10/site-packages/licensecheck/formatter.py", line 96, in json
    return dumps(out, indent="\t")
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.10/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.10/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/usr/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.10/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Version is not JSON serializable

My pyproject.toml (only poetry tool):

[tool.poetry]
name = "auth backend"
version = "0.1.0"
description = ""
authors = ["Niccolum <lastsal@mail.ru>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/fellowmate"
repository = "https://github.com/fellowmate/auth"
classifiers = [
    "Development Status :: 1 - Planning",
    "Environment :: Web Environment",
    "Framework :: FastAPI",
    "License :: OSI Approved :: MIT License",
    "Operating System :: POSIX :: Linux",
    "Programming Language :: Python :: 3.10",
    "Topic :: Home Automation",
]

[tool.poetry.dependencies]
python = "^3.10"
gunicorn = "^20.1.0"
uvicorn = {extras = ["standart"], version = "^0.16.0"}
single-source = "^0.2.0"
fastapi = "^0.71.0"
httpx = "^0.21.3"
starlette-csrf = "^1.4.0"
Secweb = "^1.3.0"

[tool.poetry.dev-dependencies]
black = "^21.12b0"
flake8 = "^4.0.1"
bandit = "^1.7.1"
isort = "^5.10.1"
pre-commit = "^2.16.0"

pytest = "^6.2.5"
pytest-cov = "^3.0.0"
pytest-custom-report = "^1.0.1"
pytest-reverse = "^1.3.0"
pytest-lazy-fixture = "^0.6.3"
pytest-nice-parametrize = "^1.0.1"
pytest-asyncio = "^0.16.0"
pytest-pythonpath = "^0.7.3"
licensecheck = "^2021.5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
FredHappyface commented 2 years ago

I'm hoping the fact it's trying to format as json is because you have a config file somewhere with that set. So you'll need to override that. eg.

$ poetry run licensecheck -fsimple --zero

The issue with the json.dumps has been fixed in 2022

Niccolum commented 2 years ago

Thanks very much for very fast response and fix it!

FredHappyface commented 2 years ago

No worries! Caught me at a good time :D

Niccolum commented 2 years ago

I'm hoping the fact it's trying to format as json is because you have a config file somewhere with that set. So you'll need to override that. eg.

$ poetry run licensecheck -fsimple --zero

The issue with the json.dumps has been fixed in 2022

Maybe add flag fsimple to precommit hook? UPD: not need. I Just update my config. Thanks one more time!