econchick / interrogate

Explain yourself! Interrogate a codebase for docstring coverage.
https://interrogate.readthedocs.io
MIT License
586 stars 44 forks source link

Interrogate fails on certain pyproject.toml due to incorrect parsing by toml library #153

Closed apirogov closed 7 months ago

apirogov commented 1 year ago

Description of the bug

Using interrogate as a pre-commit hook:

  - repo: https://github.com/econchick/interrogate
    rev: "1.5.0"
    hooks:
      - id: interrogate
        files: "^src/"

results in:

interrogate..............................................................Failed
- hook id: interrogate
- exit code: 1

Traceback (most recent call last):
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/bin/interrogate", line 8, in <module>
    sys.exit(main())
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/click/core.py", line 1054, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/click/core.py", line 920, in make_context
    self.parse_args(ctx, args)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/click/core.py", line 1378, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/click/core.py", line 2360, in handle_parse_result
    value = self.process_value(ctx, value)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/click/core.py", line 2322, in process_value
    value = self.callback(ctx, self, value)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/interrogate/config.py", line 201, in read_config_file
    config = parse_pyproject_toml(value)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/interrogate/config.py", line 109, in parse_pyproject_toml
    pyproject_toml = toml.load(path_config)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/toml/decoder.py", line 134, in load
    return loads(ffile.read(), _dict, decoder)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/toml/decoder.py", line 511, in loads
    ret = decoder.load_line(line, currentlevel, multikey,
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/toml/decoder.py", line 778, in load_line
    value, vtype = self.load_value(pair[1], strictly_valid)
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/toml/decoder.py", line 880, in load_value
    return (self.load_array(v), "array")
  File "/local/home/a.pirogov/.cache/pre-commit/repofo1r4gjz/py_env-python3/lib/python3.8/site-packages/toml/decoder.py", line 1002, in load_array
    a[b] = a[b] + ',' + a[b + 1]
IndexError: list index out of range

What you expected to happen

No exception at config loading.

How to reproduce (as minimally and precisely as possible)

Have mixed array in pyproject.toml, e.g.:

include = [
  "*.md", "LICENSE",
  { path = "mkdocs.yml", format = "sdist" },
  { path = "docs", format = "sdist" },
  { path = "tests", format = "sdist" },
]

which is in fact valid and used by poetry.

Anthing else we need to know?

The toml library is not TOML 1.0 compliant.

To solve, toml should be replaced by tomli (which is essentially tomllib which is standardized with Python 3.11)

econchick commented 7 months ago

Heya - I've just merged a PR that drops toml for tomli (<py3.11) or tomllib (>=py3.11). I'll keep this issue open until I make another release for 1.7.0 (queued for this month).

econchick commented 7 months ago

Released! feel free to re-open if this is still an issue.