Describe the bug
I've been successfully running poetry and the multiproject plugin with development version of poetry (and with 1.4.2 before that). After updating to the newly released 1.5.0, there's a TOMLDecodeError
exception thrown when reading the transient pyproject.toml when building a project.
The exception is thrown at lib\site-packages\tomli\_parser.py:127 in loads
, and is thrown because the compatibility TOML library, tomli expects a newline character exactly, and doesn't handle the \r\n
sequence. It seems to be an issue primarily with tomli, but could also be addressed by normalizing newlines when creating project files.
The relevant stack trace is:
7 .poetry-venv\lib\site-packages\poetry_multiproject_plugin\commands\buildproject\project.py:88 in handle
86โ self.rewrite_modules(project_path, top_ns)
87โ
โ 88โ self.prepare_for_build(project_path.absolute())
89โ
90โ super(ProjectBuildCommand, self).handle()
6 .poetry-venv\lib\site-packages\poetry_multiproject_plugin\commands\buildproject\project.py:73 in prepare_for_build
71โ
72โ def prepare_for_build(self, path: Path):
โ 73โ project_poetry = Factory().create_poetry(path)
74โ
75โ self.set_poetry(project_poetry)
The path comes from create.create_new_project_file
.
I tried with Python versions 3.8.10 and 3.11.2 on Windows 10.
To Reproduce
- Create a virtual environment
- Install
poetry==1.5.0
and poetry-multiproject-plugin
(optionally the poety-polylith-plugin
),
- Create a sample poetry project
- Create a project, for example with the polylith tool, for example at projects/test,
- Lock the project at project/test,
- Run the command
poetry -vvv build-project -C project/test
, (or to debug run python -m pdb -c continue -m poetry -vvv build-project -C project/test
,
- Observe the error.
Error Log
The error should be roughly:
Loading the poetry-multiproject-plugin plugin
Loading the export plugin
Loading the poetry-polylith-plugin plugin
Using virtualenv: C:\Users\...\.poetry-venv
Using C:\Users\...\projects\test\pyproject.toml
Copied project & packages into temporary folder C:\Users\...\projects\.prepare_test
Generated C:\Users\...\projects\.prepare_test\pyproject.toml
TOMLDecodeError
Expected newline or end of document after a statement (at line 1, column 14)
at .poetry-venv\lib\site-packages\tomli\_parser.py:127 in loads
123โ char = src[pos]
124โ except IndexError:
125โ break
126โ if char != "\n":
โ 127โ raise suffixed_err(
128โ src, pos, "Expected newline or end of document after a statement"
129โ )
130โ pos += 1
131โ
On 3.11.2, with built-in tomllib
the same error is thrown:
at ...\3.11.2\Lib\tomllib\_parser.py:127 in loads
123โ char = src[pos]
124โ except IndexError:
125โ break
126โ if char != "\n":
โ 127โ raise suffixed_err(
128โ src, pos, "Expected newline or end of document after a statement"
129โ )
130โ pos += 1
Expected behavior
Loading the intermediate/transient project file during build-project
should not fail due to TOML decoding errors.
The error does not appear when I insert the following line after components/project/create.py:11:
generated = generate.generate_valid_dist_project_file(original, top_ns)
+ generated = generated.replace("\r\n", "\n")
Desktop
- OS: Windows 10
- Python version: 3.8.10 and 3.11.2
- Poetry version: 1.5.0