[Python-Dev] pep-3108.txt

M.-A. Lemburg mal at egenix.com
Wed Jan 3 12:07:48 CET 2007


On 2007-01-03 00:35, Barry Warsaw wrote:
> On Jan 2, 2007, at 5:41 PM, M.-A. Lemburg wrote:
> 
>> Note that as side-effect of this it becomes a lot harder to manipulate
>> PYTHONPATH to trick Python into loading a standard module from a
>> non-standard location, improving security and robustness of the
>> Python installations.
> 
> Sometimes though you want to do this, as when you want your application
> to ensure it gets a particular version of a standard library module,
> regardless of the version of Python being used.  And now we're back to
> application-specific site-packages ;).

Well, I guess that's a rather particular use case and can probably
only be safely implemented by the maintainer of the module or package
in question ;-)

In such (rare) cases, it should be possible to use one of the harder
ways to achieve this:

 * monkey patching the package
 * using package.__path__ to redirect the in-package search
 * creating a private copy of the whole package which then has
   the modified modules and packages in place

Regarding application specific package setups:

In my experience it's better to have an application specific
sys.path setup function that manages this, rather than trying
to manipulate PYTHONPATH or trying to tweak Python's stdlib
site.py into using some particular way of setting up application
specific paths which then makes interop harder for all
applications using Python, rather than just the few that
require such setups.

The application can then call this path setup function early
on in the startup phase to make sure that the rest of the
startup and the application's main code then imports the
right modules and packages.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 03 2007)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::


More information about the Python-Dev mailing list