Skip to content

poetry 1.7.0 poetry init fails with "Poetry could not find a pyproject.toml ..." #8634

@danielhoherd

Description

@danielhoherd
  • Poetry version: Poetry (version 1.7.0)

  • Python version: Python 3.11.6 (main, Nov 1 2023, 10:08:51) [GCC 12.2.0]

  • OS version and name: Debian 12, macOS 14.1

  • pyproject.toml: N/A, file was never created by poetry init

  • 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.

  • 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.

Issue

Running poetry init with poetry 1.7.0 and then interactively adding dependencies causes an error. The error is not seen if you skip adding dependencies.

$ docker run --rm -ti python:3.11 /bin/sh
# pip install poetry >/dev/null 2>&1
# poetry --version
Poetry (version 1.7.0)
# mkdir test
# cd test
# poetry init -vvv

This command will guide you through creating your pyproject.toml config.

Package name [test]:
Version [0.1.0]:
Description []:
Author [None, n to skip]:  n
License []:
Compatible Python versions [^3.11]:

Would you like to define your main dependencies interactively? (yes/no) [yes]
You can specify a package in the following forms:
  - A single name (requests): this will search for matches on PyPI
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)

Package to add or search for (leave blank to skip): requests

  Stack trace:

  5  /usr/local/lib/python3.11/site-packages/poetry/console/commands/init.py:430 in _parse_requirements
      428│
      429│         try:
    → 430│             cwd = self.poetry.file.path.parent
      431│             artifact_cache = self.poetry.pool.artifact_cache
      432│         except (PyProjectException, RuntimeError):

  4  /usr/local/lib/python3.11/site-packages/poetry/console/commands/command.py:23 in poetry
       21│     def poetry(self) -> Poetry:
       22│         if self._poetry is None:
    →  23│             return self.get_application().poetry
       24│
       25│         return self._poetry

  3  /usr/local/lib/python3.11/site-packages/poetry/console/application.py:129 in poetry
      127│             project_path = self._io.input.option("directory")
      128│
    → 129│         self._poetry = Factory().create_poetry(
      130│             cwd=project_path,
      131│             io=self._io,

  2  /usr/local/lib/python3.11/site-packages/poetry/factory.py:58 in create_poetry
       56│             io = NullIO()
       57│
    →  58│         base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
       59│
       60│         poetry_file = base_poetry.pyproject_path

  1  /usr/local/lib/python3.11/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│         local_config = PyProjectTOML(path=poetry_file).poetry_config
       50│

  RuntimeError

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

  at /usr/local/lib/python3.11/site-packages/poetry/core/factory.py:472 in locate
      468│             if poetry_file.exists():
      469│                 return poetry_file
      470│
      471│         else:
    → 472│             raise RuntimeError(
      473│                 f"Poetry could not find a pyproject.toml file in {cwd} or its parents"
      474│             )
      475│

The following error occurred when trying to handle this error:


  Stack trace:

  15  /usr/local/lib/python3.11/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

  14  /usr/local/lib/python3.11/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│

  13  /usr/local/lib/python3.11/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│

  12  /usr/local/lib/python3.11/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

  11  /usr/local/lib/python3.11/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

  10  /usr/local/lib/python3.11/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:

   9  /usr/local/lib/python3.11/site-packages/cleo/commands/command.py:61 in execute
        59│
        60│         try:
     →  61│             return self.handle()
        62│         except KeyboardInterrupt:
        63│             return 1

   8  /usr/local/lib/python3.11/site-packages/poetry/console/commands/init.py:200 in handle
       198│                 help_displayed = True
       199│             requirements.update(
     → 200│                 self._format_requirements(self._determine_requirements([]))
       201│             )
       202│             if self.io.is_interactive():

   7  /usr/local/lib/python3.11/site-packages/poetry/console/commands/init.py:295 in _determine_requirements
       293│             package = self.ask(question)
       294│             while package:
     → 295│                 constraint = self._parse_requirements([package])[0]
       296│                 if (
       297│                     "git" in constraint

   6  /usr/local/lib/python3.11/site-packages/poetry/console/commands/init.py:434 in _parse_requirements
       432│         except (PyProjectException, RuntimeError):
       433│             cwd = Path.cwd()
     → 434│             artifact_cache = self._get_pool().artifact_cache
       435│
       436│         parser = RequirementsParser(

   5  /usr/local/lib/python3.11/site-packages/poetry/console/commands/init.py:492 in _get_pool
       490│         if self._pool is None:
       491│             self._pool = RepositoryPool()
     → 492│             pool_size = self.poetry.config.installer_max_workers
       493│             self._pool.add_repository(PyPiRepository(pool_size=pool_size))
       494│

   4  /usr/local/lib/python3.11/site-packages/poetry/console/commands/command.py:23 in poetry
        21│     def poetry(self) -> Poetry:
        22│         if self._poetry is None:
     →  23│             return self.get_application().poetry
        24│
        25│         return self._poetry

   3  /usr/local/lib/python3.11/site-packages/poetry/console/application.py:129 in poetry
       127│             project_path = self._io.input.option("directory")
       128│
     → 129│         self._poetry = Factory().create_poetry(
       130│             cwd=project_path,
       131│             io=self._io,

   2  /usr/local/lib/python3.11/site-packages/poetry/factory.py:58 in create_poetry
        56│             io = NullIO()
        57│
     →  58│         base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
        59│
        60│         poetry_file = base_poetry.pyproject_path

   1  /usr/local/lib/python3.11/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│         local_config = PyProjectTOML(path=poetry_file).poetry_config
        50│

  RuntimeError

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

  at /usr/local/lib/python3.11/site-packages/poetry/core/factory.py:472 in locate
      468│             if poetry_file.exists():
      469│                 return poetry_file
      470│
      471│         else:
    → 472│             raise RuntimeError(
      473│                 f"Poetry could not find a pyproject.toml file in {cwd} or its parents"
      474│             )
      475│
#

This same thing does not fail with poetry 1.6.1:

$ docker run --rm -ti python:3.11 /bin/sh
# pip install poetry==1.6.1 >/dev/null 2>&1
# poetry --version
Poetry (version 1.6.1)
# mkdir test
# cd test
# poetry init

This command will guide you through creating your pyproject.toml config.

Package name [test]:
Version [0.1.0]:
Description []:
Author [None, n to skip]:  n
License []:
Compatible Python versions [^3.11]:

Would you like to define your main dependencies interactively? (yes/no) [yes] yes
You can specify a package in the following forms:
  - A single name (requests): this will search for matches on PyPI
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)

Package to add or search for (leave blank to skip): requests
Found 20 packages matching requests
Showing the first 10 matches

Enter package # to add, or the complete package name if it is not listed []:
 [ 0] requests
 [ 1] requests5
 [ 2] requests2
 [ 3] requests3
 [ 4] pycopy-requests
 [ 5] deskaone-requests
 [ 6] requests-cloudkit
 [ 7] requests-middleware
 [ 8] grasspy-requests
 [ 9] fed-requests
 [ 10]
 > 0
Enter the version constraint to require (or leave blank to use the latest version):
Using version ^2.31.0 for requests

Add a package (leave blank to skip):

Would you like to define your development dependencies interactively? (yes/no) [yes] no
Generated file

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
requests = "^2.31.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


Do you confirm generation? (yes/no) [yes]
#

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cliRelated to the command linearea/configRelated to configuration managementkind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions