Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy-load "qmk console" dependencies #12978

Closed
wants to merge 1 commit into from
Closed

Conversation

t-8ch
Copy link
Contributor

@t-8ch t-8ch commented May 22, 2021

Description

This keeps the rest of the cli usable even when hidapi and pyusb are not installed.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

PR checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

This keeps the rest of the cli usable even when `hidapi` and `pyusb` are
not installed.
@github-actions github-actions bot added cli qmk cli command python labels May 22, 2021
@t-8ch t-8ch mentioned this pull request May 22, 2021
9 tasks
@skullydazed
Copy link
Member

Thanks for the PR, but this is not something we're going to change. Those are listed in requirements.txt and will be necessary going forward.

@t-8ch
Copy link
Contributor Author

t-8ch commented May 22, 2021

Okay

@rgoulter
Copy link
Contributor

rgoulter commented Jun 7, 2021

This keeps the rest of the cli usable even when hidapi and pyusb are not installed.

The native dependencies of these packages also impact whether qmk is able to run.

hidapi has the native libhidapi as a dependency. Installing the python hid package isn't sufficient for the libhidapi to be installed in the system, on most systems.

qmk setup is the command recommended to run in the docs, it's supposed to be a user-friendly way install the dependencies. https://docs.qmk.fm/#/newbs_getting_started?id=set-up-qmk

i.e. there's a dependency cycle in some cases where, in order to be able to install dependencies with qmk setup you otherwise need some of extra dependencies which qmk setup would install.

Lazy-loading so that hid is only required when running the console command would allow qmk setup to run before the dependencies have installed.

@skullydazed
Copy link
Member

Im not sure why hid and pyusb ended up in dev, probably a merging error. I opened a pr to fix that. There is no dependency cycle to worry about because setup is one of a handful of commands which run even when dependencies aren’t satisfied.

@rgoulter
Copy link
Contributor

rgoulter commented Jun 8, 2021

There is no dependency cycle to worry about because setup is one of a handful of commands which run even when dependencies aren’t satisfied.

Currently, following the instructions at https://docs.qmk.fm/#/newbs_getting_started fails for a fresh installation.

This can be reproduced with Docker. e.g.:

docker run -it ubuntu

then in that:

apt update
apt install -y git python3-pip
python3 -m pip install --user qmk
~/.local/bin/qmk setup -y

This outputs:

...
Ψ Successfully cloned https://github.com/qmk/qmk_firmware to /root/qmk_firmware!
Ψ Added https://github.com/qmk/qmk_firmware as remote upstream.
Error: %s: %s ('ImportError', ImportError('Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll'))
Traceback (most recent call last):
  File "/root/.local/lib/python3.8/site-packages/qmk_cli/script_qmk.py", line 76, in main
    import qmk.cli  # noqa
  File "/root/qmk_firmware/lib/python/qmk/cli/__init__.py", line 158, in <module>
    from . import console  # noqa
  File "/root/qmk_firmware/lib/python/qmk/cli/console.py", line 9, in <module>
    import hid
  File "/root/.local/lib/python3.8/site-packages/hid/__init__.py", line 30, in <module>
    raise ImportError(error)
ImportError: Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll

@skullydazed
Copy link
Member

I’ll take a closer look in a few days. We may need to rework how those imports happen.

@rgoulter
Copy link
Contributor

rgoulter commented Jun 23, 2021

#13199 follows this up. :) EDIT: Hmm, still observe the same error.

@skullydazed skullydazed mentioned this pull request Jun 24, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli qmk cli command python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants