[Distutils] setup.py --install-requires?
P.J. Eby
pje at telecommunity.com
Wed Apr 8 23:53:07 CEST 2009
At 01:28 PM 4/8/2009 -0700, Sridhar Ratnakumar wrote:
>For example, zc.catalog declares these dependencies in its setup.py
>
> install_requires=['ZODB3',
> 'pytz',
> 'setuptools',
> 'zope.catalog',
> 'zope.container',
> 'zope.component',
> 'zope.i18nmessageid',
> 'zope.index>=3.5.1',
> 'zope.interface',
> 'zope.publisher',
> 'zope.schema',
> 'zope.security',
> ],
>
>Is it possible to reliably get this list in a custom Python code
>without having to parse setup.py?
Something like this should do the trick:
import tempfile, os.path
from setuptools.sandbox import run_setup
def get_requires(setup_dir, empty_tmpdir):
tmpdir = tempfile.mkdtemp(prefix="egginfotmp-")
run_setup(os.path.join(setup_dir,'setup.py'), ['-e', tmpdir])
for dist in pkg_resources.find_distributions(tmpdir, True):
return dist.requires()
else:
raise RuntimeError("egg_info didn't work")
You'll get back a list of pkg_resources.Requirement objects rather
than strings, but you can turn them back into strings if you like.
More information about the Distutils-SIG
mailing list