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 1.7.0 poetry init fails with "Poetry could not find a pyproject.toml ..." #8634

Closed
4 tasks done
danielhoherd opened this issue Nov 7, 2023 · 6 comments · Fixed by #8655
Closed
4 tasks done
Labels
area/cli Related to the command line area/config Related to configuration management kind/bug Something isn't working as expected

Comments

@danielhoherd
Copy link

danielhoherd commented Nov 7, 2023

  • 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]
#
@danielhoherd danielhoherd added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 7, 2023
@danielhoherd danielhoherd changed the title poetry init fails with poetry init fails with "Poetry could not find a pyproject.toml ..." Nov 7, 2023
@danielhoherd danielhoherd changed the title poetry init fails with "Poetry could not find a pyproject.toml ..." poetry 1.7.0 poetry init fails with "Poetry could not find a pyproject.toml ..." Nov 7, 2023
@dimaqq
Copy link
Contributor

dimaqq commented Nov 8, 2023

Confirming, interactive dependencies are busted when creating a new project.

@duncanariey
Copy link

Am also running into this - I guess the solution is to pin 1.6.1 for now

@finswimmer
Copy link
Member

Hey,

thanks for reporting.

This one is a bit strange. I can reproduce it within a docker container, but not on my "normal" system.

Also a RuntimeError is thrown. But how you can see in the stacktrace, this is an expected usecase which should be catched and handled.

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):

@Secrus any chance this has something to do with cleo?

fin swimmer

@dimbleby
Copy link
Contributor

dimbleby commented Nov 8, 2023

I think it's a regression from #8559, which now tries to get hold of the poetry configuration before the poetry object exists.

(untested theory, but it sounds plausible)

@danielhoherd
Copy link
Author

danielhoherd commented Nov 8, 2023

@duncanariey alternatively if you touch pyproject.toml in shell or open('pyproject.toml', 'a').close() in python it will work in 1.7.0.

@radoering radoering mentioned this issue Nov 12, 2023
2 tasks
@radoering radoering added area/config Related to configuration management area/ci Related to CI/CD area/cli Related to the command line and removed status/triage This issue needs to be triaged area/ci Related to CI/CD labels Nov 12, 2023
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
area/cli Related to the command line area/config Related to configuration management kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants