Skip to content

Print error about missing waveform library #29

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

Merged
merged 7 commits into from
Dec 9, 2021

Conversation

FoamyGuy
Copy link
Contributor

@FoamyGuy FoamyGuy commented Dec 8, 2021

This resolves: #28

The root cause was that audioio did exist but I did not properly load the adafruit_waveform library which gets caught by the same except block that is checking for audioio. That caused the library to fall back to pwm which is invalid for the PyPortals pin so raising the exception from that makes sense.

This PR adds a more clear message to let the user know specifically that they do have audioio but are missing the adafruit_waveform library.

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Dec 8, 2021

After sleeping on it I think it may be best to re-raise the ImportError instead of just printing it out. This will cause it to crash and give the exact reason as to why which is the typical behavior when missing an import.

I'll add a new commit today to raise instead of print the ImportError.

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Dec 9, 2021

I'm not sure why Sphinx was failing with:

Warning, treated as error:
autodoc: failed to import module 'adafruit_rtttl'; the following exception was raised:
No module named 'adafruit_waveform'

The waveform library is listed in requirements.txt and seems to have gotten installed correctly according to the logs from the actions run. But for some reason Sphinx was unable to to use it from there it seems.

I've added adafruit_waveform to the list of mocked packages in the docs/conf.py file to resolve that issue for now.

After the latest commits this change will now raise the ImportError in cases where audioio does exist but adafruit_waveform was not found:

code.py output:
Traceback (most recent call last):
  File "code.py", line 30, in <module>
  File "/lib/adafruit_rtttl.py", line 36, in <module>
  File "/lib/adafruit_rtttl.py", line 25, in <module>
ImportError: no module named 'adafruit_waveform'

Tested successfully on PyPortal with 7.1.0 beta.

@FoamyGuy FoamyGuy requested a review from a team December 9, 2021 20:04
Copy link
Contributor

@KeithTheEE KeithTheEE left a comment

Choose a reason for hiding this comment

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

I think it would make sense to move the AUDIOIO_AVAILABLE = True above the adafruit_waveform import. In it's current state audioio could successfully import but report that AUDIOIO_AVAILABLE is not available because of an issue with waveform sine.

It should still error out because of the except ImportError as e on line 34, but if further down the line something in the code changes later on it could cause confusion.

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Dec 9, 2021

@KeithTheEE good catch, thanks for the review!

Latest commit moves setting AUDIOIO_AVAILABLE to immediately after the import succeeds.

I also figured it would make sense to be consistent in the naming of the variables so I renamed the waveform one to WAVEFORM_AVAILABLE to match the existing audioio one.

@KeithTheEE
Copy link
Contributor

KeithTheEE commented Dec 9, 2021

Could you try one more thing for me? Don't include audioio in your lib folder.

I'm afraid it'll continue like everything is normal and crash much later on because the only reason this raises the exception is if adafruit_waveform isn't there, not if audioio isn't there

@KeithTheEE
Copy link
Contributor

Nevermind, that's true to the original behavior, my bad. This looks good to me!

Copy link
Contributor

@KeithTheEE KeithTheEE left a comment

Choose a reason for hiding this comment

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

It looks like it should fail only when appropriate, and should correctly explain what was missing.

@KeithTheEE KeithTheEE merged commit fe7ea12 into adafruit:main Dec 9, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 14, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_GPS to 3.9.6 from 3.9.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#76 from mrdalgaard/main
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 6.1.0 from 6.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#116 from joebaird/main
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_Seesaw to 1.10.4 from 1.10.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#90 from todbot/main
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes to 2.4.1 from 2.4.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Shapes#45 from dhalbert/make-package

Updating https://github.com/adafruit/Adafruit_CircuitPython_RTTTL to 2.4.10 from 2.4.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_RTTTL#29 from FoamyGuy/pyportal_fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_TinyLoRa to 2.2.5 from 2.2.4:
  > update rtd py version
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.

Invalid Pin error on PyPortal
2 participants