adafruit / Adafruit_CircuitPython_seesaw

seesaw helper IC driver for circuitPython
MIT License
60 stars 35 forks source link

Add path check for neopixel.py #110

Closed caternuson closed 2 years ago

caternuson commented 2 years ago

A common issue is copying the seesaw version of neopixel.py into CIRCUITPY/lib instead of the "regular" non-seesaw neopixel.py. Then, when attempting to run a non-seesaw neopixel example, get:

TypeError: function missing required positional argument #4

This PR adds a simple path check to the seesaw neopixel.py to make sure it is located in a adafruit_seesaw folder. This should hopefully throw a more obvious error for the above scenario.

Attempting to import seesaw neopixel.py located in CIRCUITPY/lib:

Adafruit CircuitPython 7.3.2 on 2022-07-20; Adafruit Metro M4 Airlift Lite with samd51j19
>>> import neopixel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/neopixel.py", line 23, in <module>
ImportError: seesaw neopixel being imported from wrong location
>>> 

Attempting to import seesaw neopixel.py located in CIRCUITPY/lib/adafruit_seesaw:

Adafruit CircuitPython 7.3.2 on 2022-07-20; Adafruit Metro M4 Airlift Lite with samd51j19
>>> from adafruit_seesaw import neopixel
>>>  
caternuson commented 2 years ago

How about? seesaw neopixel being imported from unexpected location - is seesaw neopixel use intended?

I'm thinking the issue might not go away completely. But at least will be much easier to diagnose - based on exception message. Doubt there's a simple and concise message that would help people completely self remedy. They'll likely still ask "why this message?" etc.

FoamyGuy commented 2 years ago

How about? seesaw neopixel being imported from unexpected location - is seesaw neopixel use intended?

This wording sounds good to me.

Agree it's unlikely to go away completely but making the error easier to understand will make it easier to spot and probably increase the number of folks who can suggest the fix. Thanks for the improved error messaging @caternuson!

caternuson commented 2 years ago

OK, message updated.

caternuson commented 2 years ago

Yah, I'm not sure what the most robust logic would be. Could also do:

 if "adafruit_seesaw" not in __name__:

My two cents - just go with current logic and see how well it plays in the wild?

tekktrik commented 2 years ago

Sounds like a plan!