Question

The setup.py file in a package I maintain, uses code from another package to build extensions:

from setuptools import setup, find_packages
from mydependence import build_ext
...
setup(
    name='mypackage',
    version='1.0.0',
    ...
    setup_requires = [
      'mydependence', # is this being checked properly?
    ],
    ...
    install_requires = [
      'mydependence',
    ],
    ...
    )

I would like to build the current package with zc.buildout, so I create a simple buildout.cfg file like:

[buildout]
parts = python
eggs = mypackage

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

Unfortunately that does not work as I expect - as I execute ./bin/buildout and setup.py is read, it complains mydependence is not found. When buildout runs my setup.py, its sys.path has no knowledge of packages installed under the directory eggs (except for setuptools itself!). Apparently, packages in "eggs" and "develop-eggs" are not included in ./bin/buildout's paths while it runs the package's setup.py.

The question: how to make that work?

Was it helpful?

Solution

The basic problem is that you're already importing from mydependence before you're calling the setup() method. I can see no way in which setuptools (or buildout for that matter) can ignore the ImportError you will get.

If I look at some example code from, for instance, http://pythonhosted.org/py2app/examples.html I see code like this:

from setuptools import setup
setup(
    app=["MyApplication.py"],
    setup_requires=["py2app"],
)

Note that there's no import of py2app. So setup_requires apparently is a way to load "extensions" to the basic setuptools functionality. It is not a way to circumvent basic python import errors.

Update: see comment below by @MartijnPieters who has a solution in https://stackoverflow.com/a/12061891/27401 .

Martijn's example would look like this in your case:

import setuptools

setuptools.dist.Distribution(dict(setup_requires='mydependence'))
# `setup_requires` is parsed and acted upon immediately; 
# from here on out the package `mydependence` is installed
# and importable.

from mydependence import build_ext

setup(
    ...
    install_requires = [
      'mydependence',
    ],
    ....
    )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top