[mod_python] Graham's New Importer

Dan Eloff dan.eloff at gmail.com
Wed May 10 12:18:09 EDT 2006

>Perhaps you can explain the sys.path bit in some more detail.

Modifying sys.path is not a good idea, but what I wanted to accomplish
is to make sure that when your module importer falls back to python's
import, the modules are not suddenly unable to be found. It is
possible that that is completely unnecessary, I don't know under what
circumstances you fall back to python's import. As long as it stays
consistent regardless of PythonAutoReload or PythonDebug or
PythonOptimize for a given module then it works perfectly.

>    from mod_python import apache
>    __info__.path.extend(eval(apache.main_server.get_options().get
> ('my_import_path','[]')))

I like that, but I agree __info__.path is not ideal.

> Overall, I have been thinking whether the following naming changes
> should be
> made:
>    __info__ --> __mp__
>    __clone__ --> __mp_clone__
>    __purge__ --> __mp_purge__
> Ie., use "mp" designator to make it clear that this is mod_python stuff.

Yes, perfect, do that.

> At the same time, could add:
>    __mp_path__ == __mp__.path

I don't really see __mp_path__ and an improvement over __mp__.path,
and if you go with the latter you don't have to fiddle with alias or
worry about assignment. I'll leave the call to you though, I'm sure
whatever you decide will be fine.

> By a module explicitly adding items to the embedded search path, it
> would be
> more predictable perhaps than blindly always using what the option
> may be set
> to, as by adding the code in you are making a conscious decision that
> you want
> it to work that way. You need not even use an option to obtain what
> the path
> should be set to, you could also use hard coded paths, or a path
> determined by
> taking a relative path and adding it to the dirname of the __file__
> attribute of the
> module.

Not ideal for me, since I would simply add this to the top of every
single python file. But I can live with that because it does solve all
the issues related to a global setting. All in all a pretty good

> If you understand the feature above I am describing, will be
> interested in your
> comments as to usability and also as to what naming conventions
> should be
> used. It is because I hadn't worked out naming that I hadn't
> mentioned this
> feature before.

When you make the changes let me know and I'll update from the cvs and
give it a try. I suspect it is a good balance between power and


More information about the Mod_python mailing list