[Python-Dev] Embedded python module search path

Tom Emerson tree at basistech.com
Mon Aug 18 13:40:25 EDT 2003


Thomas Heller writes:
[...]
> >> Is it worth providing an alternative initialization API that allows
> >> these values to be specified explicitly instead of having them
> >> computed? Or is there a reason not to do this?
> 
> Wouldn't a Py_SetPath function do the trick, which would initially set
> module_search_path (if it's not already set)?

Yes, that is essentially what I propose adding:

void Py_SetPaths(modulepath, prefix, execprefix, fullpath);

It needs to do more than just set module_search_path though, since as
a side effect of determining module_search_path, calculate_path() also
sets the values for prefix, exec_prefix, and prog_path which are
returned by Py_GetPrefix, Py_GetExecPrefix, and Py_GetProgramFullPath
respectively, which are used by for sys.prefix and sys.exec_prefix,
and sys.executable.

Py_GetExecPrefix is also used by the _PyPopen function in posixmodule.c.

In any event, the idea is that an embedding application may know the
values for each of these paths and can force them by calling
Py_SetPaths prior to Py_Initialize, with the appropriate caveat that
the caller better know what they are doing or strange things might happen.

    -tree

-- 
Tom Emerson                                          Basis Technology Corp.
Software Architect                                 http://www.basistech.com
  "Beware the lollipop of mediocrity: lick it once and you suck forever"



More information about the Python-Dev mailing list