[mod_python] psp_site example doesn't work

Nicolas Lehuen nicolas.lehuen at gmail.com
Tue Jan 25 02:31:32 EST 2005


On Mon, 24 Jan 2005 14:56:23 -0500, Jorey Bump <list at joreybump.com> wrote:
> Daniel Popowich wrote:
> 
> > Thank you Jorey for your detailed email, but I have to disagree with
> > you when you wrote:
> >
> >     This is consistent with normal Python behaviour, where an
> >     interpreter loads modules from the current directory or
> >     PYTHONPATH. [1]
> >
> > I came to mod_python after *many* years of intensive python
> > programming and as a newbie to mod_python was caught by this issue for
> > days.  The way mod_python imports files all at the same root level is
> > very UN-pythonic.
> 
> Yes, I'll concede that. But, mod_python.publisher must remove leading
> path information when the published modules are imported, otherwise
> Python wouldn't import them (unless they happen to be in sys.path). It's
> important to understand that the module in the URL is being imported by
> another module, not run directly by the interpreter, as when you type
> "python app.py" on the command line. It took a while for this to sink in
> completely, myself.
> 
> There is no mechanism in Python to import a module by file path, so it's
> consistent, but confusing. The alternative would have been to force a
> working directory onto the user, much like a cgi-bin, and prepend that
> to sys.path.

Jorey,

A lot of the problem caused by import_module() and the
mod_python.publisher come from two very simple mistakes :

1) it is not necessary IMHO to have published moduled imported in the
same namespace than other 'standard' modules.

2) Using the 'import' keyword or the 'imp' modules are not the only
ways to import modules. Like you wrote, import and imp use a dotted
naming scheme for the modules, and have a rather complicated search
path algorithm. This is NOT what should be used to import published
modules whose place in the filesystem follows a publication scheme
instead of a modularization scheme.

The daily message from a new puzzled user should remind us that
publishing a module is NOT the same thing as importing it in standard
Python parlance. mpservlets, Vampire and other publishers have shown
that it's quite easy to import modules without using import or imp.
Separating published modules from standard modules should be done
ASAP, and I think everybody will save mental health when it will be
done ;).

Another proof that mixing published and standard module is a bad
design choice is that you end up putting constraints (through the path
parameter in import_module) to make sure that only modules from the
published filesystem are published. This is inefficient at best. Have
a look at what CherryPy does, for example : function and object which
can be published are just marked as such. Anything else can't be
published. There's no need to worry about path restrictions and so on
and so forth.

I'm sorry to be a little harsh on the subject, but for now, I think
mod_python is far from being an user-friendly web development
environment. For power users who can wrap their head around the
various bugs^H^H^H^Hfeatures, it's perfect, but judging from the
volumes of "Can't make mptest.py to run" or "Can't import yada_yada
module from index.py" messages, there's still a lot of things to cope
with to get a bigger user base. I definitely think the import
mechanism and mod_python.publisher need urgent and radical
improvements.

Regards,
Nicolas


More information about the Mod_python mailing list