python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.14k stars 2.25k forks source link

poetry show > output.txt fails with a stacktrace, works fine to console. #5384

Closed dflock closed 1 year ago

dflock commented 2 years ago

Issue

I am successfully using Poetry to manage a fairly complex python project - installing, locking deps, building & publishing - all works fine.

Running this command works fine:

$ poetry show

However. If I try to redirect the output to a file:

❯ poetry show > deps.txt

I get the first 63 line output to the file, then, these tracebacks:

Traceback (most recent call last):
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\command\command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\command\command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\commands\command.py", line 92, in wrap_handle
    return self.handle()
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\commands\show.py", line 258, in handle
    self.line(line)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\commands\command.py", line 233, in line
    self._io.write_line(styled, verbosity)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\io\io_mixin.py", line 65, in write_line
    super(IOMixin, self).write_line(string, flags)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\io.py", line 66, in write_line
    self._output.write_line(string, flags=flags)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\output.py", line 69, in write_line
    self.write(string, flags=flags, new_line=True)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\output.py", line 61, in write
    self._stream.write(to_str(formatted))
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\io\output_stream\stream_output_stream.py", line 24, in write
    self._stream.write(string)
  File "C:\Program Files\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f40d' in position 69: character maps to <undefined>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\DuncanLock\AppData\Roaming\Python\Scripts\poetry.exe\__main__.py", line 7, in <module>
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\__init__.py", line 5, in main
    return Application().run()
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\console_application.py", line 142, in run
    trace.render(io, simple=isinstance(e, CliKitException))
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 232, in render
    return self._render_exception(io, self._exception)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 257, in _render_exception
    self._render_trace(io, inspector.frames)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 381, in _render_trace
    self._render_line(
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 402, in _render_line
    io.write_line("{}{}".format(indent * " ", line))
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\io\io_mixin.py", line 65, in write_line
    super(IOMixin, self).write_line(string, flags)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\io.py", line 66, in write_line
    self._output.write_line(string, flags=flags)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\output.py", line 69, in write_line
    self.write(string, flags=flags, new_line=True)
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\output.py", line 61, in write
    self._stream.write(to_str(formatted))
  File "C:\Users\DuncanLock\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\io\output_stream\stream_output_stream.py", line 24, in write
    self._stream.write(string)
  File "C:\Program Files\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2502' in position 10: character maps to <undefined>

The deps.txt file stops after 63 lines, after mccabe:

...
matplotlib                      3.5.1      Python plotting package
mccabe                          0.6.1      McCabe checker, plugin for flake8

  Stack trace:

  11  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\console_application.py:131 in run

The console output for that section looks like this:

matplotlib                      3.5.1      Python plotting package
mccabe                          0.6.1      McCabe checker, plugin for flake8
mergedeep                       1.3.4      A deep merge function for 🐍.
msal                            1.17.0     The Microsoft Authentication Library (MSAL) f...
msal-extensions                 0.3.1

Looks like that 🐍unicode char is making it fall over when redirecting to a file, for some reason?

I think this might be similar to #4014?

abn commented 2 years ago

@dflock this looks like a windows console issue. I cannot reproduce this on my system.

$ poetry show
anyio     3.6.1       High level compatibility layer for multiple asynchronous event loop implementations
certifi   2022.5.18.1 Python package for providing Mozilla's CA Bundle.
h11       0.12.0      A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
httpcore  0.15.0      A minimal low-level HTTP client.
httpx     0.23.0      The next generation HTTP client.
idna      3.3         Internationalized Domain Names in Applications (IDNA)
mergedeep 1.3.4       A deep merge function for 🐍.
rfc3986   1.5.0       Validating URI References per RFC 3986
sniffio   1.2.0       Sniff out which async library your code is running under
$ poetry show > dep.txt
$ cat dep.txt 
anyio     3.6.1       High level compatibility layer for multiple asynchronous event loop implementations
certifi   2022.5.18.1 Python package for providing Mozilla's CA Bundle.
h11       0.12.0      A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
httpcore  0.15.0      A minimal low-level HTTP client.
httpx     0.23.0      The next generation HTTP client.
idna      3.3         Internationalized Domain Names in Applications (IDNA)
mergedeep 1.3.4       A deep merge function for 🐍.
rfc3986   1.5.0       Validating URI References per RFC 3986
sniffio   1.2.0       Sniff out which async library your code is running under

Can you try the latest version from git?

pipx install --force --suffix=@git 'poetry @ git+https://github.com/python-poetry/poetry.git'
finswimmer commented 1 year ago

Hello @dflock,

you haven't come back to this issue for a long while. So I assume this is solved in the meantime and I can close this ticket.

Feel free to leave a comment if you disagree.

fin swimmer

github-actions[bot] commented 6 months ago

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.