repo-helper / pyproject-parser

Parser for 'pyproject.toml'
https://pyproject-parser.readthedocs.io/en/latest
MIT License
15 stars 0 forks source link

Mixed type arrays in pyproject.toml lead to error #47

Open apirogov opened 1 year ago

apirogov commented 1 year ago

Description

TOML 1.0.0 supports mixed type arrays, but the toml library does not, leading to parsing errors.

Steps to Reproduce

This is a valid poetry pyproject.toml working without issues:


[tool.poetry]
name = "dummy-project"
version = "0.1.0"
description = ""
authors = ["John Doe <j.doe@example.com>"]
readme = "README.md"
packages = [{include = "dummy_project"}]

include = [
  # having both a string and an object here seems to trigger the problem:
  "CHANGELOG.md",
  { path = "tests", format = "sdist" },
  # ----
]

[tool.poetry.dependencies]
python = "^3.8"
pyproject-parser = "^0.8.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Now let's parse it:

import pyproject_parser
pyproject_parser.PyProject.load("pyproject.toml")

Actual result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/pyproject_parser/__init__.py", line 176, in load
    config = dom_toml.load(filename)
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/dom_toml/__init__.py", line 217, in load
    return loads(
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/lib/python3.8/site-packages/dom_toml/__init__.py", line 171, in loads
    return toml.loads(  # type: ignore[return-value]
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/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/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/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/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/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/pypoetry/virtualenvs/dummy-project-oiKNdZ99-py3.8/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

Expected result:

No exception.

Reproduces how often:

Always

Version

Installation source

PyPI

Other Additional Information:

I think the simplest fix would be to switch from the toml to the tomli library, which parses the file just fine.

domdfcoding commented 1 year ago

Can you try with version 0.9.0b2? That version replaces the old toml library with tomli/tomllib so should support TOML 1.0.0

apirogov commented 1 year ago

With 0.9.0b2 it loads just fine! :) Then I hope 0.9 is fully released soon!

domdfcoding commented 1 year ago

@apirogov I've released 0.9.0