clikit icon indicating copy to clipboard operation
clikit copied to clipboard

Progress bar bug while publishing packages

Open geryogam opened this issue 6 years ago • 0 comments

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:

  • ANSI code pages (such as CP-1252) are used for applications with a graphical user interface;
  • OEM code pages (such as CP-437 or CP-850) are used for applications with a textual user interface.

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?

geryogam avatar Sep 18 '19 13:09 geryogam