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 init fails when pyproject.toml exists and --dependency is specified #3073

Closed
3 tasks done
amaralbf opened this issue Oct 4, 2020 · 1 comment · Fixed by #3080
Closed
3 tasks done

poetry init fails when pyproject.toml exists and --dependency is specified #3073

amaralbf opened this issue Oct 4, 2020 · 1 comment · Fixed by #3080
Labels
kind/bug Something isn't working as expected

Comments

@amaralbf
Copy link

amaralbf commented Oct 4, 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: Ubuntu 16.04 (Xenial)

  • Poetry version: 1.1.0

  • Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/amaralbf/f5a2d2f24b72235f5f8ff53a3182c272

Issue

First of all, thank you so much for putting so much effort into this project! It's been my favorite tool for packaging and managing my projects' dependencies.

The issue I've encountered occurs when I try to execute the poetry init command and:

  1. a pyproject.toml already exists (and has no poetry sections);
  2. and one or more --dependency or --dev-dependency are specified.

If I run poetry init without specifying any --dependency or --dev-dependency, it works as expected.

Example

pyproject.toml

Command: poetry init -n --dependency numpy -vvv

  • (I get exact same Stack trace if I run the command interactively)
Output:
This command will guide you through creating your pyproject.toml config.



  Stack trace:

  11  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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

  10  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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():

   9  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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

   8  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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]

   7  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/poetry/console/commands/init.py:160 in handle
       158│         if self.option("dependency"):
       159│             requirements = self._format_requirements(
     → 160│                 self._determine_requirements(self.option("dependency"))
       161│             )
       162│ 

   6  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/poetry/console/commands/init.py:319 in _determine_requirements
       317│             return requires
       318│ 
     → 319│         requires = self._parse_requirements(requires)
       320│         result = []
       321│         for requirement in requires:

   5  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/poetry/console/commands/init.py:380 in _parse_requirements
       378│ 
       379│         try:
     → 380│             cwd = self.poetry.file.parent
       381│         except RuntimeError:
       382│             cwd = Path.cwd()

   4  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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  ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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 /home/amaralbf/dev/issue_poetry_init/pyproject.toml

  at ~/.local/pipx/venvs/poetry/lib/python3.8/site-packages/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│

Thanks again!

@amaralbf amaralbf added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 4, 2020
@abn abn removed the status/triage This issue needs to be triaged label Oct 4, 2020
abn added a commit to abn/poetry that referenced this issue Oct 4, 2020
This change ensures that we create closer to reality scenarios when
testing init command.

Relates-to: python-poetry#3073
abn added a commit to abn/poetry that referenced this issue Oct 4, 2020
abn added a commit to abn/poetry that referenced this issue Oct 4, 2020
This change ensures that we create closer to reality scenarios when
testing init command.

Relates-to: python-poetry#3073
abn added a commit to abn/poetry that referenced this issue Oct 4, 2020
finswimmer pushed a commit that referenced this issue Oct 5, 2020
This change ensures that we create closer to reality scenarios when
testing init command.

Relates-to: #3073
finswimmer pushed a commit that referenced this issue Oct 5, 2020
abn added a commit to abn/poetry that referenced this issue Oct 5, 2020
This change ensures that we create closer to reality scenarios when
testing init command.

Relates-to: python-poetry#3073
abn added a commit to abn/poetry that referenced this issue Oct 5, 2020
finswimmer pushed a commit that referenced this issue Oct 5, 2020
This change ensures that we create closer to reality scenarios when
testing init command.

Relates-to: #3073
finswimmer pushed a commit that referenced this issue Oct 5, 2020
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.

2 participants