Aside from the fact that __init__.py just isn't the right place to do this:
Driver plugins have to import gpsdio.drivers in order to access BaseDriver(), which isn't a problem if the plugin only supplies a driver. If the plugin is a library that just happens to also have a plugin that also imports gpsdio then there are some circular imports that cause the logfile to show that the driver was not loaded even when it actually was.
(venv)Captain:gpsdio-vector-driver kwurster$ python
Python 3.4.3 (default, May 1 2015, 19:14:18)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.49)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gpsdio_vector_driver.core
ERROR:gpsdio:Attempted to load entry-point `Vector' but failed:
Traceback (most recent call last):
File "/Users/kwurster/github/gpsdio-vector-driver/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2353, in resolve
return functools.reduce(getattr, self.attrs, module)
AttributeError: 'module' object has no attribute 'Vector'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/kwurster/github/gpsdio-vector-driver/venv/lib/python3.4/site-packages/gpsdio/__init__.py", line 49, in <module>
ep.load()
File "/Users/kwurster/github/gpsdio-vector-driver/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2345, in load
return self.resolve()
File "/Users/kwurster/github/gpsdio-vector-driver/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2355, in resolve
raise ImportError(str(exc))
ImportError: 'module' object has no attribute 'Vector'
>>> import gpsdio
>>> import gpsdio.drivers
>>> gpsdio.drivers.BaseDriver.by_name
{'MsgPack': <class 'gpsdio.drivers.MsgPack'>, 'Vector': <class 'gpsdio_vector_driver.core.Vector'>, 'NewlineJSON': <class 'gpsdio.drivers.NewlineJSON'>}
>>>
@redhog FYI I moved gpsdio.drivers.BaseDriver() to gpsdio.base.BaseDriver() to avoid some import collisions so driver plugins will need to subclass the latter.
Aside from the fact that
__init__.py
just isn't the right place to do this:Driver plugins have to import
gpsdio.drivers
in order to accessBaseDriver()
, which isn't a problem if the plugin only supplies a driver. If the plugin is a library that just happens to also have a plugin that also imports gpsdio then there are some circular imports that cause the logfile to show that the driver was not loaded even when it actually was.