[Distutils] Full egg name

Tarek Ziadé ziade.tarek at gmail.com
Fri Mar 26 13:42:55 CET 2010


On Fri, Mar 26, 2010 at 1:35 PM, Martin Raspaud <martin.raspaud at smhi.se> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Tarek Ziadé skrev:
>> On Fri, Mar 26, 2010 at 9:31 AM, Martin Raspaud <martin.raspaud at smhi.se> wrote:
>> Hi,
>>
>> I am writing a recipe for buildout, and as such I would like to get the full
>> name of a develop egg programatically as it would appear if I installed it.
>> For example if the setup.py defines the name to "myproject", I would like to get
>> myproject-0.3.0-py2.5-linux-x86_64.egg
>>
>> How to I get this ?
>>
>> I look a little bit in the setuptools source code, but it's not easy to find.
>>
>>> It's provided by the egg_name() function in the Distribution class
>>> (the one in pkg_resources, not the one in setuptools.dist)
>>
>>>>>> from pkg_resources import Distribution, get_build_platform
>>>>>> from distutils.sysconfig import get_python_version
>>>>>> dist = Distribution(None, None, 'myproject', '0.3.0', get_python_version(), get_build_platform())
>>>>>> dist.egg_name() + '.egg'
>>> 'myproject-0.3.0-py2.6-macosx-10.3-fat.egg'
>
> Nice, thanks !
>
> and how do I get 'myproject' and '0.3.0' from a setup.py file ? (I'm working
> with develop eggs)

It depends on what your recipe is doing really (and when). If the egg
is already installed in your
environment, by the time your recipe code is run, you can grab these
info using pkg_resources:

>>> pkg_resources.get_distribution('myproject').version, pkg_resources.get_distribution('myproject').project_name

If it's not installed, well, is a bit trickier because you need to run
a command on the project's setup.py.

What are you trying to achieve ?

Regards
Tarek

-- 
Tarek Ziadé | http://ziade.org


More information about the Distutils-SIG mailing list