[Zope3-dev] Spaghetti-hunting
Patrick K. O'Brien
pobrien@orbtech.com
Wed, 15 May 2002 08:06:18 -0500
[Barry A. Warsaw]
> This is (IMO) an elegant way to allow those packages to have their own
> independent release cycle, be usable in non-related Python
> applications (promoting re-use), but still allow my application to be
> assured it will get the right version of the package.
I agree. Very nice.
> The one tricky bit is making sure $prefix/pythonlib is always first on
> sys.path. For my cgi's it's easy because I have a C wrapper that
> manipulates the environment before calling the Python cgi script (so I
> can twiddle $PYTHONPATH to my heart's content). Similarly for mail
> programs.
>
> For cron and command line scripts, I have a file called paths.py which
> contains the sys.path twiddling logic. As part of the configure
> process, I actually take a single paths.py.in template, fill in the
> right variables, and copy the resulting paths.py file to my bin/ and
> cron/ directories. The first thing any cron or command line script
> must do before it imports a non stdlib library is "import paths" which
> twiddles sys.path as a side-effect. Because there's always a paths.py
> file in the directory of the script, I know that it will always get
> properly imported, regardless of the path used to reach the script.
Dejavu! I just did the exact same thing for some cgi scripts that I moved to
a web host where I needed a way to modify sys.path to find python packages
installed in my home directory. I called it home.py, but the idea is the
same, do an "import home" early on to set the sys.path. Works like a charm.
---
Patrick K. O'Brien
Orbtech