[Distutils] pkg_resources: parsing requires.txt without .egg-info/ directory
P.J. Eby
pje at telecommunity.com
Thu Jul 23 03:49:42 CEST 2009
At 06:04 PM 7/22/2009 -0700, Sridhar Ratnakumar wrote:
>On Wed, 22 Jul 2009 12:14:11 -0700, P.J. Eby <pje at telecommunity.com> wrote:
>
>>t 12:08 PM 7/22/2009 -0700, Sridhar Ratnakumar wrote:
>>On Tue, 21 Jul 2009 21:23:00 -0700, P.J. Eby <pje at telecommunity.com>
>>wrote:
>>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.
>> How can you run egg_info ('python setup.py egg_info') on a distribution
>>that does not use setuptools?
>> By calling setuptools.sandbox.run_setup() with the appropriate
>>arguments. (When setuptools is imported, it monkeypatches the
>>distutils, such that distutils is really setuptools. That's how
>>easy_install is able to build eggs from packages that don't use
>>setuptools.)
>
>Ok, anyways .. running setup.py can be a pain (eg: running egg_info on
>numpy, using the sandbox, actually tries to build the extensions!).
>
>For now, I'll go with a custom parser (like pip) .. and wait for either
>you or Tarek to split setuptools into reusable modules.
Well, all the lower-level tools you need to do the parsing are in
pkg_resources also; the code actually used is just:
dm = self.__dep_map = {None: []}
for name in 'requires.txt', 'depends.txt':
for extra,reqs in split_sections(self._get_metadata(name)):
if extra: extra = safe_extra(extra)
dm.setdefault(extra,[]).extend(parse_requirements(reqs))
return dm
Both split_sections() and parse_requirements() are public functions,
and you can replace the _get_metadata call with a text-mode open() of
the relevant file, if it exists.
More information about the Distutils-SIG
mailing list