Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

TomlParsingError when reading a TOML file #64

Open
ruslaniv opened this issue Aug 2, 2023 · 1 comment
Open

TomlParsingError when reading a TOML file #64

ruslaniv opened this issue Aug 2, 2023 · 1 comment

Comments

@ruslaniv
Copy link

ruslaniv commented Aug 2, 2023

I'm trying to read a poetry toml file (which I'd think should not matter since it's a regular toml file) like this:

import rtoml
obj = rtoml.load("pyproject.toml")
print(obj)

and I'm getting

_rtoml.TomlParsingError: expected an equals, found eof at line 1 column 15

Here are few first lines from that file

[tool.poetry]
name = "datascience"
version = "0.1.0"

So it looks like it can't read the section [tool.poetry] line?
But in the example it seems to read it without problems?

@Bogay
Copy link

Bogay commented Aug 30, 2023

According to the source. It seems that rtoml.load will pass the arg directly to rtoml.loads if you give it a str.

rtoml/rtoml/__init__.py

Lines 16 to 26 in d79d03f

def load(toml: Union[str, Path, TextIO]) -> Dict[str, Any]:
"""
Parse TOML via a string or file and return a python dict. The `toml` argument may be a `str`,
`Path` or file object from `open()`.
"""
if isinstance(toml, Path):
toml = toml.read_text(encoding='UTF-8')
elif isinstance(toml, (TextIOBase, TextIO)):
toml = toml.read()
return loads(toml)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants