sdispater / clikit

CliKit is a group of utilities to build beautiful and testable command line interfaces.
MIT License
72 stars 17 forks source link

Progress bar bug while publishing packages #4

Open geryogam opened 4 years ago

geryogam commented 4 years ago

While publishing a Python package to a private repository with Poetry, the "- Uploading {file} {percentage}" line gets printed three times for each file instead of once:

$ poetry publish -r local -u . -p .

Publishing file_proxy (0.0.1) to local
 - Uploading file_proxy-0.0.1-py3-none-any.whl 0%
 - Uploading file_proxy-0.0.1-py3-none-any.whl 100%
 - Uploading file_proxy-0.0.1-py3-none-any.whl 100%
 - Uploading file_proxy-0.0.1.tar.gz 0%
 - Uploading file_proxy-0.0.1.tar.gz 100%
 - Uploading file_proxy-0.0.1.tar.gz 100%

The body of the poetry.masonry.publishing.uploader._upload_file method indicates that a requests_toolbelt.multipart.MultipartEncoderMonitor decorator is used with a lambda monitor: bar.set_progress(monitor.bytes_read) callback. Here the progress bar is an instance of the clikit.ui.components.progress_bar.ProgressBar class. Looking at the method clikit.ui.components.progress_bar.ProgressBar.__init__ method, we see that output overwrite is disabled when the self._io.error_output.supports_ansi function considers that the output does not support ANSI code pages.

On Windows:

I am using Powershell 5.1 with the default OEM code page CP-850. Since it is not an ANSI code page, Poetry output is expected. However, switching to the ANSI code page CP-1252 gives the same output:

$ chcp 1252
$ poetry publish -r local -u . -p .

Publishing file_proxy (0.0.1) to local
 - Uploading file_proxy-0.0.1-py3-none-any.whl 0%
 - Uploading file_proxy-0.0.1-py3-none-any.whl 100%
 - Uploading file_proxy-0.0.1-py3-none-any.whl 100%
 - Uploading file_proxy-0.0.1.tar.gz 0%
 - Uploading file_proxy-0.0.1.tar.gz 100%
 - Uploading file_proxy-0.0.1.tar.gz 100%

So the only solution is to force ANSI output using the --ansi command-line argument:

$ poetry publish --ansi -r local -u . -p .

Publishing file_proxy (0.0.1) to local
 - Uploading file_proxy-0.0.1-py3-none-any.whl 100%
 - Uploading file_proxy-0.0.1.tar.gz 100%

But this is a workaround. Why does the self._io.error_output.supports_ansi function considers that Powershell 5.1 does not support ANSI code pages when using the ANSI code page CP-1252?