[Python-ideas] Python Environment Initialization Scripts

Eric Snow ericsnowcurrently at gmail.com
Sun Jul 29 02:56:53 CEST 2012


On Sat, Jul 28, 2012 at 6:47 PM, James William Pye <x at jwp.io> wrote:
> I posted a question on c.l.py[1] looking for a feature and I suspect it doesn't exist.
> Some quick searches on -ideas and -dev didn't reveal anything either.
>
> Has the idea of [python] environment initialization been pitched/rejected before or does it already exist?
>
> Simply, I'm looking for a mechanism to automatically load some meta_path hooks after site initialization.
>
> Without modifying libpython, I can achieve what I'm trying to do by:
>
>  * Mangling the site.py file to run the code. (in my case, "import c.lib; c.lib.install()")

No need to modify site.py.  Either create a sitecustomize.py in your
site-packages.  Here are some references:

http://docs.python.org/library/site.html
http://www.python.org/dev/peps/pep-0370

Nothing new is needed.

As to metapath hooks, one alternative is to make a helper function
that puts the hooks in place (or otherwise manages your hooks).  Then
you can call that API in each script that needs those hooks.

-eric



More information about the Python-ideas mailing list