[Python-Dev] Re: Path hacking

Greg Stein gstein@lyra.org
Thu, 16 Sep 1999 07:19:41 -0700

Guido van Rossum wrote:
> [me]
> > > Why would you want your own exceptions.py and site.py?
> [JimA]
> > I don't.  I never change Python library files.  I am worried
> > that they won't be found because I don't trust PYTHONPATH.
> Hmm...  PYTHONPATH gets inserted in front of the default sys.path.
> (Many moons ago that was different.  But it has been like this for a
> loooooong time.)  So are you worried that someone put a *different*
> exceptions.py or site.py on their path?

When you jam every file into a module archive, you still have to leave
these two "outside" so that Python can find them when starting up. The
problem then breaks down into two parts:

1) locating them
2) ensuring they're the right versions

In my "small" distro, I relied on the current-dir always being in the
path, so I could always find these. The two files were distributed as
part of distro.

Anyhow: JimA is saying that he doesn't trust PYTHONPATH. Not so much bad
files/versions, but that he won't be able to find them because
PYTHONPATH has been monkeyed in some way.

> > > Again - why would anyone register their own site.py?
> >
> > I wouldn't, I am worried that someone else will break my installation.
> > Remember that site.py was invented as a site-specific module, although
> > that function moved to sitecustomize.py.
> Hm, I dug out the oldest site.py I have (used in Python 1.4), and it
> doesn't encourage editing it at all -- it tells you to use
> sitecustomize.py.  I guess they could break your installation anyway,
> but only by messing with the general Python installation.

If the file exists, then somebody can mess with it. JimA is trying to
create a bulletproof app here. To do this, you can distribute a
python.exe, exceptions.py, site.py, and an archive of your other
modules. site.py is scrapped in favor of installing an Importer to
access the archive (this implies you also distribute imputil.py). These
five files are the exact five in my "small" distro. It's pretty cool...
no need for registry changes and a very small "file count" footprint.
Gordon took this basis and added a bunch of features for bundling an
application in there. JimA has also been mixing in some frozen modules
(I forget exactly why/what).
[oh, my small distro doesn't ship a python15.dll, although it easily

> I hope that Mark Hammond can point you to a tool that you can use to
> edit a string resource in an executable or DLL.

The win32api module has resource manipulation functions such as
BeginUpdateResource, UpdateResource, and EndUpdateResource.

Write a Python script to modify your version string :-)

A demo of resource munging can be seen in <win32


Greg Stein, http://www.lyra.org/