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

Interactive question fails in subcommand (poetry cache clear) #127

Closed
AndBondStyle opened this issue Jan 13, 2022 · 2 comments
Closed

Interactive question fails in subcommand (poetry cache clear) #127

AndBondStyle opened this issue Jan 13, 2022 · 2 comments
Milestone

Comments

@AndBondStyle
Copy link

I'm facing an issue with poetry, but I believe it isn't poetry's fault. Environment is: python 3.8.10, poetry 1.2.0a2 and cleo 1.0.0a4.

Command poetry cache clear pypi --all -vvv crashes and gives following traceback:

Toggle full output
(temp) abs@abs-pc:~$ poetry cache clear pypi --all -vvv
Delete 318 entries? (yes/no) [no]
  Stack trace:

  13  venv/temp/lib/python3.8/site-packages/cleo/application.py:330 in run
       328│
       329│             try:
     → 330│                 exit_code = self._run(io)
       331│             except Exception as e:
       332│                 if not self._catch_exceptions:

  12  venv/temp/lib/python3.8/site-packages/poetry/console/application.py:180 in _run
       178│         self._load_plugins(io)
       179│
     → 180│         return super()._run(io)
       181│
       182│     def _configure_io(self, io: IO) -> None:

  11  venv/temp/lib/python3.8/site-packages/cleo/application.py:425 in _run
       423│                 io.set_input(ArgvInput(argv))
       424│
     → 425│         exit_code = self._run_command(command, io)
       426│         self._running_command = None
       427│

  10  venv/temp/lib/python3.8/site-packages/cleo/application.py:467 in _run_command
       465│
       466│         if error is not None:
     → 467│             raise error
       468│
       469│         return event.exit_code

   9  venv/temp/lib/python3.8/site-packages/cleo/application.py:451 in _run_command
       449│
       450│             if event.command_should_run():
     → 451│                 exit_code = command.run(io)
       452│             else:
       453│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

   8  venv/temp/lib/python3.8/site-packages/cleo/commands/base_command.py:118 in run
       116│         io.input.validate()
       117│
     → 118│         status_code = self.execute(io)
       119│
       120│         if status_code is None:

   7  venv/temp/lib/python3.8/site-packages/cleo/commands/command.py:85 in execute
        83│
        84│         try:
     →  85│             return self.handle()
        86│         except KeyboardInterrupt:
        87│             return 1

   6  venv/temp/lib/python3.8/site-packages/poetry/console/commands/cache/clear.py:58 in handle
        56│                 entries_count += len(files)
        57│
     →  58│             delete = self.confirm(
        59│                 "Delete {} entries?".format(entries_count)
        60│             )

   5  venv/temp/lib/python3.8/site-packages/cleo/commands/command.py:143 in confirm
       141│         )
       142│
     → 143│         return question.ask(self._io)
       144│
       145│     def ask(

   4  venv/temp/lib/python3.8/site-packages/cleo/ui/question.py:75 in ask
        73│
        74│         if not self._validator:
     →  75│             return self._do_ask(io)
        76│
        77│         def interviewer():

   3  venv/temp/lib/python3.8/site-packages/cleo/ui/question.py:101 in _do_ask
        99│
       100│             if not ret:
     → 101│                 ret = self._read_from_input(io)
       102│         else:
       103│             ret = self._autocomplete(io)

   2  venv/temp/lib/python3.8/site-packages/cleo/ui/question.py:260 in _read_from_input
       258│         Read user input.
       259│         """
     → 260│         ret = io.read_line(4096)
       261│
       262│         if not ret:

   1  venv/temp/lib/python3.8/site-packages/cleo/io/io.py:42 in read_line
        40│         Reads a line from the input stream.
        41│         """
     →  42│         return self._input.read_line(length=length, default=default)
        43│
        44│     def write_line(

  AttributeError

  'NoneType' object has no attribute 'readline'

  at venv/temp/lib/python3.8/site-packages/cleo/io/inputs/input.py:77 in read_line
       73│         """
       74│         if not self._interactive:
       75│             return default
       76│
    →  77│         return self._stream.readline(length)
       78│
       79│     def close(self) -> None:
       80│         """
       81│         Closes the input.

My guess is that the problem is in cleo/application.py line 423: it sets a new input handler (instance of ArgvInput), which has no associated stream (thus the NoneType attribute error). The following patch is worked for me:

<<< application.py line 419 >>>
                if index is not None:
                    del argv[index + 1 : index + 1 + (len(name.split(" ")) - 1)]

-                io.set_input(ArgvInput(argv))
+                new_input = ArgvInput(argv)
+                new_input.set_stream(io.input.stream)
+                io.set_input(new_input)

        exit_code = self._run_command(command, io)
        self._running_command = None
<<< application.py line 427 >>>
@caniko
Copy link

caniko commented Apr 12, 2022

I also have this error.

@Secrus
Copy link
Member

Secrus commented Sep 10, 2022

This issue is resolved in the current main branch. Closing.

@Secrus Secrus closed this as completed Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants