Path hacking [Long] (was Re: [Python-Dev] Relative Package Imports)

James C. Ahlstrom
Tue, 14 Sep 1999 15:11:54 -0400

"Barry A. Warsaw" wrote:
> So for Knowbots we wrote a small module called pathhack that all entry
> level executables imported.  pathhack was good because it put all that
> sys.path munging nonsense in one place so it was manageable from a s/w
> engineering standpoint.  But it sucked because those executables had
> to /find/!  Bootstrap lossage (we've actually gone back to
> sys.path.insert).

Yes, exactly the problem I had, bootstraping the import of pathhack.
Actually it gets worse because Python imports,
and during Py_Initialize(), so if you are having a
really bad day, you might pick up the wrong version of those.

AFAIK, the only way to solve that currently is to use freeze
to build pathhack into the binary executable.  That is what I
do anyway.  But it is not an ideal solution.

> What I've been thinking is that Python needs a registry <shudder>.

Yikes!  As you say, Window's registry is a mess.

> [Lots of good ideas omitted...]

> - The system-wide registry can be located in say
>   sys.prefix/lib/python<version>/site-packages.  The user registry
>   would reside somewhere in $HOME.  This could all be platform
>   specific so that on Windows, maybe the Python registry is integrated
>   with the Windows registry, while in JPython it would be integrated
>   with the standard JPython registry mechanism.

Python already has three directories it knows about: sys.executable is
the directory of the interpreter binary, sys.dllfullpath could be
the directory of the interpreter as a shared library (I have a
patch for this), and there is the directory of the main Python program
as given on the command line.  Perhaps we can put the registry
in one of these directories.  That would be consistent on all

> - You should be able to specify registry entries on the command line.

This is vital because I am worried about a bad registry.
> - There needs to be defined rules for resolving registry keys b/w
>   system, user, and command line specifications.  JPython has some
>   experience here (although there have been requests to change

I am not sure a full registry is required.  Once you can control
sys.path and can get an accurate import of, you
can do everything else there.  Maybe just a command line option
is enough.  But I will think about it...

Jim Ahlstrom