whaleygeek / bitio

A micro:bit I/O device library for Python
Other
92 stars 31 forks source link

Better embed detection #14

Closed DavidWhaleMEF closed 7 years ago

DavidWhaleMEF commented 7 years ago

bitio uses code to detect whether it has loaded the pyserial embedded in the project, or whether sys pathing has meant that it found a (possibly incompatible and buggy) system installed one. Ubuntu 12 for example has a slightly buggy version of pyserial installed by default, which is why we package pyserial inside bitio to avoid this being used.

However, currently bitio looks for existence of a hacked-in 'BITIO' module attribute added to pyserial - this works nicely, but makes it slightly harder for people to update their embedded pyserial package without breaking this.

I had an idea that we could check the sys.modules["bitio"].__file__ attribute to find out which path was actually used to import the module (inside the outer package), and checking the basename of the path could tell us if it actually found the system installed one or the embedded one. This would make the pyserial embedded inside bitio completely unchanged from the original source.