[Distutils] Buildout: How to include installed packages in sys.path?

Gustavo Narea gustavonarea at 2degreesnetwork.com
Fri Feb 12 12:48:43 CET 2010


Hello, Jim.

Thank you very much for your response.

I modified by recipe to use zc.recipe.egg like this:
====
from zc.recipe.egg import Scripts
# ...
egg = Scripts(buildout, name, options)
egg.working_set((distribution_name,))
# ...
do_something_useful(distribution_name)
====

But still do_something_useful() is failing (distribution_name is not in
sys.path) and I think that's because I didn't use pkg_resources as you
suggested. I tried to do it, and read the documentation and source code
for pkg_resources, but I was not able to find the functionality I should
use.

I'll elaborate on what the recipe actually does, just in case: It loads
options from an external INI file into the parts section, so other parts
can use such variables. To be precise, it loads the variables from a
PasteDeploy configuration file.

Here's its code (it's just ~30 LOC):
http://bitbucket.org/2degrees/deployrecipes/src/tip/deployrecipes.py

And here's its documentation:
http://packages.python.org/deployrecipes/

The tricky thing is, these files contain an option which is the string
representation of a function. I don't need to load the actual function,
all I want is to get all those options as strings. But PasteDeploy will
always attempt to resolve that option and thus I must make it available.

I hope it's not that hard to do with zc.recipe.eggs.

Cheers,

 - Gustavo.

On 11/02/10 22:48, Jim Fulton wrote:
> The short answer is that buildout doesn't support this. You can do it, but
> with a lot of work.  As the documentation for install,
> http://pypi.python.org/pypi/zc.buildout#distribution-installation,
> says, if the second argument is None, it will fail unless the package
> is already installed.  You need to specify the place to
> install to.
>
> It might be easier to use the zc.recipe.egg recipe from your recipe:
>
>   http://pypi.python.org/pypi/zc.recipe.egg#egg-recipe-api-for-other-recipes
>
> After using that recipe to install the needed package, you'd need to use
> pkg_resources APIs to load the distribution into the running process.
>
> You might also look at the code buildout uses to load recipes.
>
>   

-- 
Gustavo Narea.
Software Developer.
2degrees, Ltd. <http://www.2degreesnetwork.com/>.



More information about the Distutils-SIG mailing list