question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pyproject.toml 'include' directive parsing bug.

See original GitHub issue

Highlighting here but elaborated a bit in https://github.com/python-poetry/poetry/issues/6094#issuecomment-1326009538

Traceback (most recent call last):
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1157, in _preparse
    self._initini(args)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1076, in _initini
    rootpath, inipath, inicfg = determine_setup(
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/findpaths.py", line 184, in determine_setup
    rootdir, inipath, inicfg = locate_config([ancestor])
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/findpaths.py", line 106, in locate_config
    ini_config = load_config_dict_from_file(p)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/_pytest/config/findpaths.py", line 69, in load_config_dict_from_file
    config = toml.load(str(filepath))
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/toml/decoder.py", line 134, in load
    return loads(ffile.read(), _dict, decoder)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/toml/decoder.py", line 511, in loads
    ret = decoder.load_line(line, currentlevel, multikey,
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/toml/decoder.py", line 778, in load_line
    value, vtype = self.load_value(pair[1], strictly_valid)
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/toml/decoder.py", line 880, in load_value
    return (self.load_array(v), "array")
  File "/mnt/c/Users/richa/PycharmProjects/reasoner-validator/ubuntu/lib/python3.10/site-packages/toml/decoder.py", line 1002, in load_array
    a[b] = a[b] + ',' + a[b + 1]
IndexError: list index out of range

Issue

I added the following directive to a pyproject.toml file:

include = [
    "CHANGELOG.md",
    { path = "tests" },
    { path = "docs" }
]

Using my library, e.g. just running PyTests, triggers a IndexError: list index out of range exception reading in deep in the toml decoder.py module here:

                    while (not self.bounded_string(ab) or
                           (len(ab) > 2 and
                            ab[0] == ab[1] == ab[2] and
                            ab[-2] != ab[0] and
                            ab[-3] != ab[0])):
                        a[b] = a[b] + ',' + a[b + 1]  # <= site of error

but this error is not triggered either by

include = [
    "CHANGELOG.md"
]

alone, nor by

include = [
    { path = "tests" },
    { path = "docs" }
]

alone.

I guess I’ll remove one or the other components of the include, but it would be helpful to know what’s happening (and fix it!) or, at least, document the constraints of include usage accordingly.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
RichardBruskiewichcommented, Nov 26, 2022

@neersighted, I deeply appreciated your frank reply. I sincerely apologize for the consternation my own comments inspired on your part.

As a good colleague of mine remarked when I was once on the other (receiving) side of such comments: “…maybe so…and…so is just having a bad day on their (software engineering) side…”. I hope that you can make such allowances for me today.

I was obviously mistaken in considering the error within the remit of poetry: the pyproject.toml file in my project was only created when I migrated the project to Poetry… in fact, poetry created the initial file and I simply added to it following poetry documented additions. I guess I’d be forgiven for incorrectly assuming it was a poetry bug… I was inadvertently - not so blissfully - unaware that poetry and pytest share the same name for a configuration file. What an eye opener! Talk about (admirable!) standards reuse

I furthermore now also understand the point that there are multiple diverse implementations of TOML parsing, some more compliant than others with the expected constructs… and that Poetry and Pytest each use different libraries to parse their TOML file! Talk about lack of reuse of standards, in terms of libraries!

On the issue of open source, I’ve long been a fan of, and contributor to, many such projects, so I do understand your angst with my harsh comments.

Again, please accept my apologies… and also, my gratitude for your thoughtful reply.

For now, I’ll just avoid the offending construct in the TOML file in question since I don’t actually enough professional or personal degrees of freedom at the moment to jump into the fray of uiri/toml to fix this bug… although all of the information gleaned here about the coding landscape for this was very helpful (I’m truly sorry that I didn’t pick up on any of this earlier…)

0reactions
RichardBruskiewichcommented, Nov 26, 2022

@dimbleby thank you for the head’s up on this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poetry messes up pyproject.toml when [build-system] is not at ...
When I run poetry add -D pytest-mock -vvv on the pyproject.toml file linked here above, Poetry gives me the following error stacktrace:.
Read more >
tomllib — Parse TOML files — Python 3.11.1 documentation
This module provides an interface for parsing TOML (Tom's Obvious Minimal Language, ... The first argument should be a readable and binary file...
Read more >
Configuration — SQLFluff 1.4.5 documentation
For the pyproject.toml file, all valid sections start with tool.sqlfluff and ... [if parsing a file in a subdirectory of the current working...
Read more >
pyproject-parser - PyPI
pyproject -parser can be installed from PyPI or Anaconda. ... To install with conda: First add the required channels. $ conda config --add...
Read more >
How do I specify "extra" / bracket dependencies in a pyproject ...
I'm working on a project that specifies its dependencies using Poetry and a pyproject.toml file to manage dependencies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found