zuzukin / whl2conda

Generate conda package from pure python wheel
https://zuzukin.github.io/whl2conda/
Apache License 2.0
6 stars 2 forks source link

Improve error for failure to download package from pypi #125

Open analog-cbarber opened 8 months ago

analog-cbarber commented 8 months ago

If you use whl2conda convert with --from-pypi or --from-index, failures just give you an uninformative stack dump, e.g.

$ whl2conda convert --from-pypi numpy
Traceback (most recent call last):
  File "/Users/Christopher.Barber/miniconda3/bin/whl2conda", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/Christopher.Barber/miniconda3/lib/python3.11/site-packages/whl2conda/cli/main.py", line 91, in main
    subcmds.run(parsed)
  File "/Users/Christopher.Barber/miniconda3/lib/python3.11/site-packages/whl2conda/cli/common.py", line 233, in run
    parsed.main(parsed.args, prog=f'{self._parser.prog} {parsed.subcmd}')
  File "/Users/Christopher.Barber/miniconda3/lib/python3.11/site-packages/whl2conda/cli/common.py", line 221, in _main
    real_main(args, prog)
  File "/Users/Christopher.Barber/miniconda3/lib/python3.11/site-packages/whl2conda/cli/convert.py", line 475, in convert_main
    wheel_file = download_wheel(
                 ^^^^^^^^^^^^^^^
  File "/Users/Christopher.Barber/miniconda3/lib/python3.11/site-packages/whl2conda/impl/download.py", line 69, in download_wheel
    p = subprocess.run(cmd, check=True, stderr=subprocess.PIPE)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Christopher.Barber/miniconda3/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['pip', 'download', '--only-binary', ':all:', '--no-deps', '--ignore-requires-python', '--implementation', 'py', '-d', '/Users/Christopher.Barber/tmp/whl2conda-download-hpfqnpms', 'numpy']' returned non-zero exit status 1.

In this case, the download fails because there is no pure python package for numpy, but you get the same error if there is not package with that name.

Instead we should report the download command along with stderr, e.g.:

Could not download `numpy` from pypi:

  ERROR: Could not find a version that satisfies the requirement implementation (from versions: none)
  ERROR: No matching distribution found for implementation

This could be because there is no pure python implementation