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

Incorrect format toml file to json.dumps #18

Closed
3 tasks done
Niccolum opened this issue Jan 14, 2022 · 4 comments
Closed
3 tasks done

Incorrect format toml file to json.dumps #18

Niccolum opened this issue Jan 14, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@Niccolum
Copy link

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: Linux niccolum-HP-ProBook-650-G3 4.15.0-163-generic #171-Ubuntu SMP Fri Nov 5 11:55:11 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Version: 2021.5.2

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"
@Niccolum Niccolum added the bug Something isn't working label Jan 14, 2022
@FredHappyface
Copy link
Member

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
Copy link
Author

Thanks very much for very fast response and fix it!

@FredHappyface
Copy link
Member

No worries! Caught me at a good time :D

@Niccolum
Copy link
Author

Niccolum commented Jan 14, 2022

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!

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

2 participants