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 update" requires a pyproject.toml file #9964

Closed
srittau opened this issue Jan 6, 2025 · 8 comments · Fixed by #9995
Closed

"poetry self update" requires a pyproject.toml file #9964

srittau opened this issue Jan 6, 2025 · 8 comments · Fixed by #9995
Labels
area/cli Related to the command line kind/bug Something isn't working as expected status/confirmed Issue is reproduced and confirmed status/triage This issue needs to be triaged

Comments

@srittau
Copy link
Contributor

srittau commented Jan 6, 2025

Description

When running "poetry self update" in a directory not containing a pyproject.toml file (such as the home directory), poetry quits with "Poetry could not find a pyproject.toml file in /home/srittau or its parents". It seems unnecessary to run self commands from a "real" project directory.

Workarounds

Running the self commands in any existing project directory. This is more difficult on a new system or installing poetry automatically (for example, using Ansible).

Poetry Installation Method

install.python-poetry.org

Operating System

Ubuntu 24.04.1

Poetry Version

Poetry (version 2.0.0)

Poetry Configuration

cache-dir = "/home/srittau/.cache/pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/srittau/.cache/pypoetry/virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

Platform: "linux-x86_64"
Python version: "3.12"
Current installation scheme: "venv"

Paths: 
	data = "/opt/ansible/ansible"
	include = "/usr/include/python3.12"
	platinclude = "/usr/include/python3.12"
	platlib = "/opt/ansible/ansible/lib/python3.12/site-packages"
	platstdlib = "/opt/ansible/ansible/lib/python3.12"
	purelib = "/opt/ansible/ansible/lib/python3.12/site-packages"
	scripts = "/opt/ansible/ansible/bin"
	stdlib = "/usr/lib/python3.12"

Variables: 
        [... please let me know if you require specific output]

Example pyproject.toml

No response

Poetry Runtime Logs

$ poetry -vvv self update
Loading configuration file /home/srittau/.config/pypoetry/config.toml
Updating Poetry version ...


  Stack trace:

  14  /opt/ansible/poetry/venv/lib/python3.12/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

  13  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/console/application.py:236 in _run
       234│ 
       235│         with directory(self._working_directory):
     → 236│             exit_code: int = super()._run(io)
       237│ 
       238│         return exit_code

  12  /opt/ansible/poetry/venv/lib/python3.12/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│ 

  11  /opt/ansible/poetry/venv/lib/python3.12/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

  10  /opt/ansible/poetry/venv/lib/python3.12/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

   9  /opt/ansible/poetry/venv/lib/python3.12/site-packages/cleo/commands/base_command.py:117 in run
       115│         io.input.validate()
       116│ 
     → 117│         return self.execute(io) or 0
       118│ 
       119│     def merge_application_definition(self, merge_args: bool = True) -> None:

   8  /opt/ansible/poetry/venv/lib/python3.12/site-packages/cleo/commands/command.py:61 in execute
        59│ 
        60│         try:
     →  61│             return self.handle()
        62│         except KeyboardInterrupt:
        63│             return 1

   7  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/console/commands/self/self_command.py:132 in handle
       130│ 
       131│         with directory(self.system_pyproject.parent):
     → 132│             return self._system_project_handle()
       133│ 

   6  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/console/commands/self/update.py:49 in _system_project_handle
        47│         assert isinstance(add_command, AddCommand)
        48│         add_command.set_env(self.env)
     →  49│         application.configure_installer_for_command(add_command, self.io)
        50│ 
        51│         argv = ["add", f"poetry@{self.argument('version')}"]

   5  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/console/application.py:375 in configure_installer_for_command
       373│         from poetry.installation.installer import Installer
       374│ 
     → 375│         poetry = command.poetry
       376│         installer = Installer(
       377│             io,

   4  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/console/commands/command.py:24 in poetry
        22│     def poetry(self) -> Poetry:
        23│         if self._poetry is None:
     →  24│             return self.get_application().poetry
        25│ 
        26│         return self._poetry

   3  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/console/application.py:181 in poetry
       179│             return self._poetry
       180│ 
     → 181│         self._poetry = Factory().create_poetry(
       182│             cwd=self._project_directory,
       183│             io=self._io,

   2  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/factory.py:60 in create_poetry
        58│             io = NullIO()
        59│ 
     →  60│         base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
        61│ 
        62│         if version_str := base_poetry.local_config.get("requires-poetry"):

   1  /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/core/factory.py:48 in create_poetry
        46│         from poetry.core.pyproject.toml import PyProjectTOML
        47│ 
     →  48│         poetry_file = self.locate(cwd)
        49│         pyproject = PyProjectTOML(path=poetry_file)
        50│ 

  RuntimeError

  Poetry could not find a pyproject.toml file in /home/srittau or its parents

  at /opt/ansible/poetry/venv/lib/python3.12/site-packages/poetry/core/factory.py:802 in locate
      798│             if poetry_file.exists():
      799│                 return poetry_file
      800│ 
      801│         else:
    → 802│             raise RuntimeError(
      803│                 f"Poetry could not find a pyproject.toml file in {cwd} or its parents"
      804│             )
      805│
@srittau srittau added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jan 6, 2025
@srittau srittau changed the title "poetry self ..." requires a pyproject.toml file "poetry self update" requires a pyproject.toml file Jan 6, 2025
@andrei-shabanski
Copy link

Moreover, running poetry self update in an existing project within an activated virtual environment installs poetry package in the current project

@thinh9e
Copy link

thinh9e commented Jan 7, 2025

This issue also occurs on Windows.
I was able to work around this by navigating to the Poetry installation directory (%APPDATA%\pypoetry on Windows) and running poetry self update to update.

@mr-mare
Copy link

mr-mare commented Jan 7, 2025

It seems to me that poetry self update command messes up with both project virtual environment and poetry virtual environment.

With freshly installed poetry (using the official installer), I ran these commands:

/tmp/my_project$ poetry init --no-interaction --python="^3.13"
/tmp/my_project$ poetry add django
Creating virtualenv my-project-AnYL-V66-py3.13 in /Users/user/Library/Caches/pypoetry/virtualenvs
Using version ^5.1.4 for django

Updating dependencies
Resolving dependencies... (0.1s)

Package operations: 3 installs, 0 updates, 0 removals

  - Installing asgiref (3.8.1)
  - Installing sqlparse (0.5.3)
  - Installing django (5.1.4)

Writing lock file
/tmp/my_project$ cat pyproject.toml 
[project]
name = "my-project"
version = "0.1.0"
description = ""
authors = [
    {name = "User"}
]
readme = "README.md"
requires-python = "^3.13"
dependencies = [
    "django (>=5.1.4,<6.0.0)"
]


[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
/tmp/my_project$ poetry self update 
Updating Poetry version ...

Using version ^2.0.0 for poetry

Updating dependencies
Resolving dependencies... (1.5s)

Package operations: 3 installs, 0 updates, 0 removals

  - Installing asgiref (3.8.1)
  - Installing sqlparse (0.5.3)
  - Installing django (5.1.4)

Writing lock file
/tmp/my_project$ poetry install --no-root 
Installing dependencies from lock file

Package operations: 35 installs, 0 updates, 0 removals

  - Installing certifi (2024.12.14)
  - Installing charset-normalizer (3.4.1)
  - Installing idna (3.10)
  - Installing more-itertools (10.5.0)
  - Installing pycparser (2.22)
  - Installing urllib3 (2.3.0)
  - Installing cffi (1.17.1)
  - Installing filelock (3.16.1)
  - Installing distlib (0.3.9)
  - Installing jaraco-context (6.0.1)
  - Installing crashtest (0.4.1)
  - Installing packaging (24.2)
  - Installing jaraco-classes (3.4.0)
  - Installing platformdirs (4.3.6)
  - Installing msgpack (1.1.0)
  - Installing pyproject-hooks (1.2.0)
  - Installing rapidfuzz (3.11.0)
  - Installing requests (2.32.3)
  - Installing jaraco-functools (4.1.0)
  - Installing virtualenv (20.28.1)
  - Installing cachecontrol (0.14.2)
  - Installing cleo (2.1.0)
  - Installing dulwich (0.22.7)
  - Installing fastjsonschema (2.21.1)
  - Installing installer (0.7.0)
  - Installing keyring (25.6.0)
  - Installing pkginfo (1.12.0)
  - Installing poetry-core (2.0.0)
  - Installing requests-toolbelt (1.0.0)
  - Installing shellingham (1.5.4)
  - Installing tomlkit (0.13.2)
  - Installing trove-classifiers (2025.1.7.14)
  - Installing build (1.2.2.post1)
  - Installing xattr (1.1.4)
  - Installing poetry (2.0.0)
/tmp/my_project$ poetry env info 

Virtualenv
Python:         3.13.1
Implementation: CPython
Path:           /Users/user/Library/Caches/pypoetry/virtualenvs/my-project-AnYL-V66-py3.13
Executable:     /Users/user/Library/Caches/pypoetry/virtualenvs/my-project-AnYL-V66-py3.13/bin/python
Valid:          True

Base
Platform:   darwin
OS:         posix
Python:     3.13.1
Path:       /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.13
Executable: /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.13/bin/python3.13
/tmp/my_project$ ls /Users/user/Library/Caches/pypoetry/virtualenvs/my-project-AnYL-V66-py3.13/lib/python3.13/site-packages/
Django-5.1.4.dist-info                  charset_normalizer-3.4.1.dist-info      installer                               pip-24.3.1.virtualenv                   requests_toolbelt
__pycache__                             cleo                                    installer-0.7.0.dist-info               pkginfo                                 requests_toolbelt-1.0.0.dist-info
_cffi_backend.cpython-313-darwin.so     cleo-2.1.0.dist-info                    jaraco                                  pkginfo-1.12.0.dist-info                shellingham
_virtualenv.pth                         crashtest                               jaraco.classes-3.4.0.dist-info          platformdirs                            shellingham-1.5.4.dist-info
_virtualenv.py                          crashtest-0.4.1.dist-info               jaraco.context-6.0.1.dist-info          platformdirs-4.3.6.dist-info            sqlparse
asgiref                                 distlib                                 jaraco.functools-4.1.0.dist-info        poetry                                  sqlparse-0.5.3.dist-info
asgiref-3.8.1.dist-info                 distlib-0.3.9.dist-info                 keyring                                 poetry-2.0.0.dist-info                  tomlkit
build                                   django                                  keyring-25.6.0.dist-info                poetry_core-2.0.0.dist-info             tomlkit-0.13.2.dist-info
build-1.2.2.post1.dist-info             dulwich                                 more_itertools                          pycparser                               trove_classifiers
cachecontrol                            dulwich-0.22.7.dist-info                more_itertools-10.5.0.dist-info         pycparser-2.22.dist-info                trove_classifiers-2025.1.7.14.dist-info
cachecontrol-0.14.2.dist-info           fastjsonschema                          msgpack                                 pyproject_hooks                         urllib3
certifi                                 fastjsonschema-2.21.1.dist-info         msgpack-1.1.0.dist-info                 pyproject_hooks-1.2.0.dist-info         urllib3-2.3.0.dist-info
certifi-2024.12.14.dist-info            filelock                                packaging                               rapidfuzz                               virtualenv
cffi                                    filelock-3.16.1.dist-info               packaging-24.2.dist-info                rapidfuzz-3.11.0.dist-info              virtualenv-20.28.1.dist-info
cffi-1.17.1.dist-info                   idna                                    pip                                     requests                                xattr
charset_normalizer                      idna-3.10.dist-info                     pip-24.3.1.dist-info                    requests-2.32.3.dist-info               xattr-1.1.4.dist-info
/tmp/my_project$ ls /Users/user/Library/Application\ Support/pypoetry/venv/lib/python3.13/site-packages/
Django-5.1.4.dist-info                  crashtest                               jaraco.classes-3.4.0.dist-info          platformdirs-4.3.6.dist-info            sqlparse
_cffi_backend.cpython-313-darwin.so     crashtest-0.4.1.dist-info               jaraco.context-6.0.1.dist-info          poetry                                  sqlparse-0.5.3.dist-info
asgiref                                 distlib                                 jaraco.functools-4.1.0.dist-info        poetry-2.0.0.dist-info                  tomlkit
asgiref-3.8.1.dist-info                 distlib-0.3.9.dist-info                 keyring                                 poetry_core-2.0.0.dist-info             tomlkit-0.13.2.dist-info
build                                   django                                  keyring-25.6.0.dist-info                pycparser                               trove_classifiers
build-1.2.2.post1.dist-info             dulwich                                 more_itertools                          pycparser-2.22.dist-info                trove_classifiers-2025.1.7.14.dist-info
cachecontrol                            dulwich-0.22.7.dist-info                more_itertools-10.5.0.dist-info         pyproject_hooks                         urllib3
cachecontrol-0.14.2.dist-info           fastjsonschema                          msgpack                                 pyproject_hooks-1.2.0.dist-info         urllib3-2.3.0.dist-info
certifi                                 fastjsonschema-2.21.1.dist-info         msgpack-1.1.0.dist-info                 rapidfuzz                               virtualenv
certifi-2024.12.14.dist-info            filelock                                packaging                               rapidfuzz-3.11.0.dist-info              virtualenv-20.28.1.dist-info
cffi                                    filelock-3.16.1.dist-info               packaging-24.2.dist-info                requests                                xattr
cffi-1.17.1.dist-info                   idna                                    pip                                     requests-2.32.3.dist-info               xattr-1.1.4.dist-info
charset_normalizer                      idna-3.10.dist-info                     pip-24.3.1.dist-info                    requests_toolbelt
charset_normalizer-3.4.1.dist-info      installer                               pkginfo                                 requests_toolbelt-1.0.0.dist-info
cleo                                    installer-0.7.0.dist-info               pkginfo-1.12.0.dist-info                shellingham
cleo-2.1.0.dist-info                    jaraco                                  platformdirs                            shellingham-1.5.4.dist-info
/tmp/my_project$ cat pyproject.toml 
[project]
name = "my-project"
version = "0.1.0"
description = ""
authors = [
    {name = "User"}
]
readme = "README.md"
requires-python = "^3.13"
dependencies = [
    "django (>=5.1.4,<6.0.0)",
    "poetry (>=2.0.0,<3.0.0)"
]


[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

As you can see it installs project dependencies into poetry virtual environment and vice versa poetry and its dependencies into project virtual environment.

@finswimmer
Copy link
Member

Hey,

I'm not able to reproduce this. How have you installed Poetry? From what version are you trying to update?

fin swimmer

@mr-mare
Copy link

mr-mare commented Jan 8, 2025

As I mentioned, I used the official installer (i.e. the same method as in the first post).

curl -sSL https://install.python-poetry.org | python3 -

I ran poetry self update command with version 2.0.0.

~$ poetry --version
Poetry (version 2.0.0)

@mr-mare
Copy link

mr-mare commented Jan 8, 2025

I tried it in docker with the same behaviour. Here are the steps to reproduce the problem from the first post.

  • I ran python:3.13-slim image:
    $ docker run -it python:3.13-slim bash
    
  • in running docker container I installed curl and then poetry:
    root@839b7de64ade:/# apt-get update && apt-get install -y curl
    root@839b7de64ade:/# curl -sSL https://install.python-poetry.org | python3 -
    
  • now if I attempt to update poetry, it complains about missing pyproject.toml file:
    root@839b7de64ade:/# poetry --version
    Poetry (version 2.0.0)
    root@839b7de64ade:/# poetry self update
    Updating Poetry version ...
    
    
    Poetry could not find a pyproject.toml file in / or its parents
    

When poetry self update command is run in an existing project, it behaves as I described earlier.

@finswimmer
Copy link
Member

Thanks for the reproducer 👍 I have an idea where to search ...

@Secrus
Copy link
Member

Secrus commented Jan 10, 2025

poetry version is also requiring a pyproject.toml.

Screenshot from 2025-01-10 10-16-01

that is expected. are you maybe looking for poetry --version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Related to the command line kind/bug Something isn't working as expected status/confirmed Issue is reproduced and confirmed status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants