[Distutils] pkg_resources: parsing requires.txt without .egg-info/ directory

P.J. Eby pje at telecommunity.com
Wed Jul 22 06:23:00 CEST 2009


At 07:19 PM 7/21/2009 -0700, Sridhar Ratnakumar wrote:
>On Tue, 21 Jul 2009 18:04:00 -0700, P.J. Eby <pje at telecommunity.com> wrote:
>
>>Is there anyway to get access to this parsed _dep_map without having a
>>reference to the .egg-info directory? After all, everything needed to
>>parse requires.txt is that file alone.
>>  Note: requires.txt is extracted and stored elsewhere, so I cannot rely
>>in
>>it being inside .egg-info/ directory in order to parse it.
>>  print require('zope.component')[0]._dep_map would be the normal way to
>>get it, for a package that's already installed.
>>  However, from some of the rest of what you're saying, it sounds like
>>you're trying to parse this for an un-built package.  Is that the case?
>
>Yes. I am not bothered about installed packages. Long story short, I
>download packages from PyPI .. extract the PKG-INFO and requires.txt file
>for each of them. Then, I am trying to parse requires.txt (copied from the
>tarball).

If I were trying to do what you're doing, I'd just run a bdist_egg on 
the package and inspect it via the API.  Or, alternately, I'd run the 
egg_info command with an explicit target directory, then load it via 
the regular API.  (By "regular API" I mean such things as a 
find_distributions() call aimed at the parent of the .egg-info directory.)

And I'd do it that way because then I wouldn't need to care whether 
the distribution was created with setuptools or not.

Actually, I'd probably just use "easy_install -zmaxNd sometmpdir 
Projectname", followed by looping over 
find_distributions('sometmpdir') and returning the _dep_map of the 
first yielded Distribution.  (The "zmaxNd" means "install as a 
zipfile, don't munge .pth files or sys.path, ensure that you copy the 
needed file to the target directory, exclude scripts, no 
dependencies, and here's the directory to put it in".)

This recipe will handle source, eggs, or win32 .exe files without 
complaint, and work on distutils or setuptools-based projects, as 
long as they don't break sandboxing or do something silly in their setup.py.



More information about the Distutils-SIG mailing list