sys.path manipulation and relative imports
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ladon |
Fix Committed
|
High
|
jsgaarde |
Bug Description
Ladon uses __import__ in two places. Both places assume that the directory you are importing the service module from (i.e. calculator.py) is on the PYTHONPATH. This means __import__ only works with relative imports.
So if I define a service module in a namespace package, say: ladontest.
In fact, the first import during startup *does* succeed, but a later import that takes place during runtime in the dispatcher to reconstruct the module fails: 'calculator' cannot be imported.
Ladon offers the ability to give the WSGI application a list of paths that should be put on the PYTHONPATH. So what I can do is place 'ladontest' on the PYTHONPATH. This is however dangerous; I use the ladontest namespace package for a reason - the modules I place inside ladontest have names I don't want to end up on my PYTHONPATH.
I'm not a fan of Ladon's PYTHONPATH manipulation in general; I use tools to do that myself (buildout, pip, whatever). I cannot turn this *off* either; I *have* to supply a path there, or I get an error. Initially I didn't know what this was for, so I added '/', but that's not really something I want on my python path.. Please make it so that you can supply no paths at all here.
But that's not the most important point; what is needed is a way to support namespace packages. Dotted names already work with one of the two uses of __import__ already; I can supply 'ladontest.
I actually stumbled into this problem last week - I will fix it next week, cause I need to be able to add servicemodules origining from a package.
/ Jakob