sys.path manipulation and relative imports

Bug #974655 reported by Martijn Faassen
6
This bug affects 1 person
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.calculator, the import fails.

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.calculator' to the WSGI app, but it doesn't work with the __import__ in the dispatcher.

Revision history for this message
jsgaarde (jakob-simon-gaarde) wrote :

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

Changed in ladon:
assignee: nobody → jsgaarde (jakob-simon-gaarde)
importance: Undecided → High
status: New → Confirmed
Revision history for this message
jsgaarde (jakob-simon-gaarde) wrote :

Fixed this problem so you can now use webservice modules defined in packages.

/ Jakob

Changed in ladon:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.