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

mavutil: WebSockets: fix wsproto import for newer python versions #975

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

IamPete1
Copy link
Member

@IamPete1 IamPete1 commented Sep 5, 2024

For reasons I don't really understand the import inside the class init works on Python 3.8.3 where I originally tested but not on Python 3.12.3. This moves the import out of the init which works for both versions. I now have the import in each function of the class that needs it, seems odd, but it does work.

@peterbarker
Copy link
Contributor

pbarker@fx:~/rc/pymavlink((HEAD detached at IamPete1/websockets2))$ mavproxy.py --master /dev/serial/by-id/usb-Hex_ProfiCNC_CubeOrange_3C0028001151383439343731-if00 
Traceback (most recent call last):
  File "/home/pbarker/.local/bin/mavproxy.py", line 4, in <module>
    __import__('pkg_resources').run_script('MAVProxy==1.8.70', 'mavproxy.py')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 656, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1460, in run_script
    exec(script_code, namespace, namespace)
  File "/home/pbarker/.local/lib/python3.10/site-packages/MAVProxy-1.8.70-py3.10.egg/EGG-INFO/scripts/mavproxy.py", line 39, in <module>
  File "/home/pbarker/.local/lib/python3.10/site-packages/MAVProxy-1.8.70-py3.10.egg/MAVProxy/modules/lib/rline.py", line 8, in <module>
  File "/home/pbarker/.local/lib/python3.10/site-packages/pymavlink-2.4.41-py3.10.egg/pymavlink/mavutil.py", line 1738, in <module>
    class mavwebsocket(mavfile):
  File "/home/pbarker/.local/lib/python3.10/site-packages/pymavlink-2.4.41-py3.10.egg/pymavlink/mavutil.py", line 1740, in mavwebsocket
    from wsproto import ConnectionType, WSConnection, utilities
ModuleNotFoundError: No module named 'wsproto'

... we shouldn't fail that way if someone doesn't have wsproto installed; we try to avoid adding hard dependencies in pymavlink whereever possible.

pbarker@fx:~$ python --version
Python 3.10.12
pbarker@fx:~$ 

@IamPete1
Copy link
Member Author

IamPete1 commented Sep 7, 2024

I have re-worked and re-tested.

Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@peterbarker peterbarker merged commit feb81c4 into ArduPilot:master Sep 8, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants