bitcoin-core / HWI

Bitcoin Hardware Wallet Interface
MIT License
499 stars 198 forks source link

bitbox02 should not be a hard dependency #675

Closed hossbeast closed 1 year ago

hossbeast commented 1 year ago

There is a hard install-time dependency on bitbox02 currently,

https://github.com/bitcoin-core/HWI/blob/master/pyproject.toml#L27

And, if it's not installed, hwi-qt will fail to run, with an error like,

Traceback (most recent call last):
  File "/usr/bin/hwi-qt", line 33, in <module>
    sys.exit(load_entry_point('hwi==2.2.1', 'console_scripts', 'hwi-qt')())
  File "/usr/bin/hwi-qt", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/hwilib/_gui.py", line 32, in <module>
    import bitbox02.util
  File "/usr/lib/python3.10/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 139, in _import
    return original_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'bitbox02'

But, you actually can use hwi without bitbox02, you just need to ignore a warning

% hwi enumerate
WARNING:root:No module named 'bitbox02', required for bitbox02. Ignore if you do not want this device.
WARNING:root:No module named 'cbor', required for jade. Ignore if you do not want this device.
   .. proceeds to work ...

For a user that does not have a bitbox device, this is an extra dependency and extra code that is not needed.

I don't believe this package has any other direct dependencies which exist solely to support one specific vendor.

For these reasons, I would like to see the bitbox02 dependency removed, and changed to runtime detection. That is, if you want to use HWI with bitbox, you install bitbox02 separately, and HWI notices that at runtime and uses it. Otherwise, you can use HWI with other devices without installing bitbox02.

Any support for this idea?

hossbeast commented 1 year ago

See also - https://aur.archlinux.org/packages/python-hwilib#comment-908596

dspicher commented 1 year ago

This could be done with Poetry extras, which are already used in this project.