Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

poetry self commands cannot be executed: Expected newline or end of document after a statement #7885

Closed
3 of 4 tasks
madebylydia opened this issue May 5, 2023 · 8 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@madebylydia
Copy link

  • Poetry version: 1.4.2

  • Python version: 3.10.8

  • OS version and name: Windows 11 Version 10.0.22621 Build 22621

  • pyproject.toml: https://gist.github.com/Predeactor/c6c4ae3cda2939a2dc02f43126da5721 (Note: Spaces were removed)

  • I am on the latest stable Poetry version, installed using a recommended method.

  • I have searched the issues of this repo and believe that this is not a duplicate.

    • See below.
  • I have consulted the FAQ and blog for any relevant entries or release notes.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

> poetry self update
Updating Poetry version ...


  Stack trace:

  21  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:327 in run
       325│ 
       326│             try:
     → 327│                 exit_code = self._run(io)
       328│             except BrokenPipeError:
       329│                 # If we are piped to another process, it may close early and send a

  20  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\application.py:190 in _run
       188│         self._load_plugins(io)
       189│
     → 190│         exit_code: int = super()._run(io)
       191│         return exit_code
       192│

  19  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poethepoet\plugin.py:274 in _run
       272│                 tokens.insert(task_name_index, "--")
       273│
     → 274│             return continue_run(self, io)
       275│
       276│         # Apply the patch

  18  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:431 in _run
       429│             io.input.interactive(interactive)
       430│
     → 431│         exit_code = self._run_command(command, io)
       432│         self._running_command = None
       433│

  17  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:473 in _run_command
       471│ 
       472│         if error is not None:
     → 473│             raise error
       474│
       475│         return terminate_event.exit_code

  16  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:457 in _run_command
       455│ 
       456│             if command_event.command_should_run():
     → 457│                 exit_code = command.run(io)
       458│             else:
       459│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  15  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\base_command.py:119 in run
       117│         io.input.validate()
       118│
     → 119│         status_code = self.execute(io)
       120│
       121│         if status_code is None:

  14  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\command.py:62 in execute
        60│
        61│         try:
     →  62│             return self.handle()
        63│         except KeyboardInterrupt:
        64│             return 1

  13  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\commands\self\self_command.py:130 in handle
       128│ 
       129│         with directory(self.system_pyproject.parent):
     → 130│             return self._system_project_handle()
       131│

  12  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\commands\self\update.py:43 in _system_project_handle
        41│         assert isinstance(add_command, AddCommand)
        42│         add_command.set_env(self.env)
     →  43│         application.configure_installer_for_command(add_command, self.io)
        44│
        45│         argv = ["add", f"poetry@{self.argument('version')}"]

  11  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\application.py:329 in configure_installer_for_command
       327│ 
       328│         poetry = command.poetry
     → 329│         installer = Installer(
       330│             io,
       331│             command.env,

  10  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\installation\installer.py:71 in __init__
        69│ 
        70│         if executor is None:
     →  71│             executor = Executor(
        72│                 self._env, self._pool, config, self._io, disable_cache=disable_cache
        73│             )

   9  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\installation\executor.py:65 in __init__
        63│         self._enabled = True
        64│         self._verbose = False
     →  65│         self._wheel_installer = WheelInstaller(self._env)
        66│         self._use_modern_installation = config.get(
        67│             "installer.modern-installation", True

   8  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\installation\wheel_installer.py:90 in __init__
        88│                 script_kind = "win-amd64" if sys.maxsize > 2**32 else "win-ia32"
        89│
     →  90│         schemes = self._env.paths
        91│         schemes["headers"] = schemes["include"]
        92│

   7  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env.py:1423 in paths
       1421│     def paths(self) -> dict[str, str]:
       1422│         if self._paths is None:
     → 1423│             self._paths = self.get_paths()
       1424│
       1425│             if self.is_venv():

   6  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env.py:1642 in get_paths
       1640│ 
       1641│         d = Distribution()
     → 1642│         d.parse_config_files()
       1643│         with warnings.catch_warnings():
       1644│             warnings.filterwarnings("ignore", "setup.py install is deprecated")

   5  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\setuptools\dist.py:868 in parse_config_files
        866│         )
        867│         for filename in tomlfiles:
     →  868│             pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
        869│
        870│         self._finalize_requires()

   4  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\setuptools\config\pyprojecttoml.py:62 in apply_configuration
        60│     distribution object.
        61│     """
     →  62│     config = read_configuration(filepath, True, ignore_option_errors, dist)
        63│     return _apply(dist, config, filepath)
        64│

   3  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\setuptools\config\pyprojecttoml.py:98 in read_configuration
        96│         raise FileError(f"Configuration file {filepath!r} does not exist.")
        97│
     →  98│     asdict = load_file(filepath) or {}
        99│     project_table = asdict.get("project", {})
       100│     tool_table = asdict.get("tool", {})

   2  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\setuptools\config\pyprojecttoml.py:30 in load_file
        28│ 
        29│     with open(filepath, "rb") as file:
     →  30│         return tomli.load(file)
        31│
        32│

   1  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\setuptools\_vendor\tomli\_parser.py:66 in load
        64│             "File must be opened in binary mode, e.g. use `open('foo.toml', 'rb')`"
        65│         ) from None
     →  66│     return loads(s, parse_float=parse_float)
        67│
        68│

  TOMLDecodeError

  Expected newline or end of document after a statement (at line 12, column 44)

  at ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\setuptools\_vendor\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│

Issue

This issue appears to be related to #7705 and #6457, which seems to be code that has been merged (By the end of March) and published to PyPI (By the beginning of April), but still appears to happen.

This exception seems to happen for every poetry self commands.

I tried everything I could and looked for issues/PRs fixing this, but unfortunately, there's nothing helping me, I'm sadly opening this issue even if there already was one that existed…

@madebylydia madebylydia added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels May 5, 2023
@radoering
Copy link
Member

#7705 has been merged into master, but is not included in a release. Only minor releases (e.g. 1.4.0, 1.5.0) may be built from master. Patch releases (e.g. 1.4.1, 1.4.2) are built from the corresponding release branch (e.g. 1.4). You have to try poetry@master in order to check if #7705 solves your issue.

Further, IIRC #7705 only makes sure that the pyproject.toml file is written correctly. pyproject.toml files with invalid line endings may still cause issues and should be fixed manually (once).

@Gazzzzyy
Copy link

Hi all,
I'm also running into the exact same problem. What should I be doing to work around this issue? Should I be manually changing the end of my pyproject.toml file?

@radoering
Copy link
Member

Yes, I suppose you have to fix the pyproject.toml manually. Afterwards, the issue should not appear again if you use poetry 1.5 or later.

@Gazzzzyy
Copy link

Hi again, sorry I don't think I'm following what actually needs to be fixed. I get the same problem as @Predeactor. Any idea what line needs to be added/changed?

@radoering
Copy link
Member

IIRC, you have to replace \r\r with a single \r.

@madebylydia
Copy link
Author

Fixed after updating to 1.5.0.

This will still require a manual edit in the pyproject.toml.

  • Do Win+R
  • Type %AppData%/pypoetry and Enter.
  • Open pyproject.toml and remove the unnecessary blank lines, then save the file.

Hope this settle things down. :)

@nmlen
Copy link

nmlen commented Nov 23, 2023

Fixed after updating to 1.5.0.

This will still require a manual edit in the pyproject.toml.

* Do `Win+R`

* Type `%AppData%/pypoetry` and Enter.

* Open `pyproject.toml` and remove the unnecessary blank lines, then save the file.

Hope this settle things down. :)

I'm getting a similar error, but I genuinely don't see any extra lines in either the pyproject.toml associated with poetry or my specific app.

image

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants