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

Error in "poetry config" when Poetry is not configured in pyproject.toml #3084

Closed
3 tasks done
pietrodn opened this issue Oct 5, 2020 · 6 comments · Fixed by #3172
Closed
3 tasks done

Error in "poetry config" when Poetry is not configured in pyproject.toml #3084

pietrodn opened this issue Oct 5, 2020 · 6 comments · Fixed by #3172
Labels
kind/bug Something isn't working as expected

Comments

@pietrodn
Copy link

pietrodn commented Oct 5, 2020

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: macOS 10.15.7
  • Poetry version: 1.1.1, 1.1.2
  • pyproject.toml file: it's simply:
[tool.black]
line-length = 100

Issue

It is impossible to configure any Poetry setting with poetry config if a pyproject.toml file does not exist, or if it exists and does not include any Poetry configuration.

Note: Poetry v. 1.1.1 fixed the issue in the case where pyproject.toml does not exists. The issue persists when pyproject.toml exists and does not include a Poetry configuration section.

Indeed, this is what happens:

Output:

$ poetry config -vvv
Loading configuration file /Users/pd/Library/Application Support/pypoetry/config.toml
Loading configuration file /Users/pd/Library/Application Support/pypoetry/auth.toml

  Stack trace:

  9  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py:131 in run
      129│             parsed_args = resolved_command.args
      130│
    → 131│             status_code = command.handle(parsed_args, io)
      132│         except KeyboardInterrupt:
      133│             status_code = 1

  8  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:120 in handle
      118│     def handle(self, args, io):  # type: (Args, IO) -> int
      119│         try:
    → 120│             status_code = self._do_handle(args, io)
      121│         except KeyboardInterrupt:
      122│             if io.is_debug():

  7  ~/.poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py:171 in _do_handle
      169│         handler_method = self._config.handler_method
      170│
    → 171│         return getattr(handler, handler_method)(args, io, self)
      172│
      173│     def __repr__(self):  # type: () -> str

  6  ~/.poetry/lib/poetry/_vendor/py3.8/cleo/commands/command.py:92 in wrap_handle
       90│         self._command = command
       91│
    →  92│         return self.handle()
       93│
       94│     def handle(self):  # type: () -> Optional[int]

  5  ~/.poetry/lib/poetry/console/commands/config.py:80 in handle
       78│
       79│         try:
    →  80│             local_config_file = TOMLFile(self.poetry.file.parent / "poetry.toml")
       81│             if local_config_file.exists():
       82│                 config.merge(local_config_file.read())

  4  ~/.poetry/lib/poetry/console/commands/command.py:10 in poetry
       8│     @property
       9│     def poetry(self):
    → 10│         return self.application.poetry
      11│
      12│     def reset_poetry(self):  # type: () -> None

  3  ~/.poetry/lib/poetry/console/application.py:69 in poetry
       67│             return self._poetry
       68│
    →  69│         self._poetry = Factory().create_poetry(Path.cwd())
       70│
       71│         return self._poetry

  2  ~/.poetry/lib/poetry/factory.py:33 in create_poetry
       31│             io = NullIO()
       32│
    →  33│         base_poetry = super(Factory, self).create_poetry(cwd)
       34│
       35│         locker = Locker(

  1  ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/factory.py:32 in create_poetry
       30│     def create_poetry(self, cwd=None):  # type: (Optional[Path]) -> Poetry
       31│         poetry_file = self.locate(cwd)
    →  32│         local_config = PyProjectTOML(path=poetry_file).poetry_config
       33│
       34│         # Checking validity

  PyProjectException

  [tool.poetry] section not found in /Users/pd/tmp/pyproject.toml

  at ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/pyproject/toml.py:55 in poetry_config
      51│     def poetry_config(self):  # type: () -> Optional[TOMLDocument]
      52│         if self._poetry_config is None:
      53│             self._poetry_config = self.data.get("tool", {}).get("poetry")
      54│             if self._poetry_config is None:
    → 55│                 raise PyProjectException(
      56│                     "[tool.poetry] section not found in {}".format(self._file)
      57│                 )
      58│         return self._poetry_config
      59│

I believe this issue was introduced in Poetry 1.1.0, because the same command was working on our CI with version 1.0.10.

@pietrodn pietrodn added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 5, 2020
@pietrodn
Copy link
Author

pietrodn commented Oct 5, 2020

This is similar to #3073 but for a different Poetry command.

@finswimmer
Copy link
Member

Looks like this is fixed by #3076 and is already included in poetry 1.1.1.

@pietrodn
Copy link
Author

pietrodn commented Oct 6, 2020

Actually, I tested this bug on Poetry 1.1.1 and it is still there:

$ poetry --version
Poetry version 1.1.1

$ poetry config

  PyProjectException

  [tool.poetry] section not found in /Users/pd/tmp/pyproject.toml

  at ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/pyproject/toml.py:55 in poetry_config
      51│     def poetry_config(self):  # type: () -> Optional[TOMLDocument]
      52│         if self._poetry_config is None:
      53│             self._poetry_config = self.data.get("tool", {}).get("poetry")
      54│             if self._poetry_config is None:
    → 55│                 raise PyProjectException(
      56│                     "[tool.poetry] section not found in {}".format(self._file)
      57│                 )
      58│         return self._poetry_config
      59│

@finswimmer
Copy link
Member

Ok, I can reproduce it, when there is a pyproject.toml, but not if there is not such a file.

@finswimmer finswimmer reopened this Oct 6, 2020
@abn abn added Good First Issue and removed status/triage This issue needs to be triaged labels Oct 6, 2020
@pietrodn
Copy link
Author

pietrodn commented Oct 6, 2020

I confirm, the problem has been solved in the case of a missing pyproject.toml. Updating title and description to reflect this.

Copy link

github-actions bot commented Mar 2, 2024

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 Mar 2, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants