[Distutils] Parsing setup()

Rob gentoodev at gmail.com
Tue Jun 5 00:58:15 CEST 2007

Ian Bicking wrote:

> If you have a built egg (which you can do with python setup.py egg_info, without actually installing
> anything) you can read the requires.txt file with pkg_resources.

I had tried that but I was having problems with un-installed packages.

I have this so far, which works with *nux, but I'll have to figure out
how to find the correct Python
executable in Windows (I think using different Python versions could
yield different requirements?).

pkg_name = "pycopia-net"
os.system("/usr/bin/env python %s egg_info" % setup_file)
ws = WorkingSet(setup_dir)
env = Environment()
dist = env.best_match(Requirement.parse(pkg_name), ws)
print dist.get_metadata("requires.txt").split()

['pycopia-process>=0.9', 'pycopia-utils>=0.9']

Thanks, Ian.

More information about the Distutils-SIG mailing list