[Distutils] How to customize egg_info behavior

Jason R. Coombs jaraco at jaraco.com
Sun Aug 1 07:36:31 CEST 2010


Thanks for the tip, pje. Your suggestion was very helpful. Perhaps I can ask
a follow-up.

In addition to calculating the tag at package-time (when setup.py is run for
sdist/bdist*), I am calculating the version at package-time.

The problem I have with this approach is with source distributions (sdists).
Since the sdists get the same setup.py file, the calculations for version
and tag are done both at packaging time and at install time. I would like to
configure my setup.py such that when sdist is run, the version and tag are
calculated and added to the egg_info, but when a consumer of that sdist goes
to install it, the version and tag are not calculated and just consumed from
the egg_info (similar to what happens when installing a bdist_egg).

This leads to two questions:

1. Is there a way to determine that I'm installing from an sdist, so I can
bypass any package-time calculations and defer to the already-calculated
PKG_INFO present in the sdist zip? I can probably elicit that information
from the environment, but if there's an indicator in setuptools, that would
be helpful.
2. Once the setup script has determined that it is installing from an sdist,
how can it call setup() to actually defer to the existing PKG_INFO for
installation?

I suspect there may be a better approach; any suggestions are appreciated.
Using bdist_egg does exactly what I need, but I'd prefer to use sdist to
avoid the need to distribute versions for each Python version. I can almost
imagine an sdist_egg command that creates a source-only distribution
suitable for easy_install.

If it helps to have a concrete example, the project I'm working on is
[hgtools][1] and here is the [current state of the setup.py script][2].

Thanks!

Jason

[1] http://bitbucket.org/jaraco/hgtools
[2] http://bitbucket.org/jaraco/hgtools/src/6e18ec0cea4a/setup.py

> -----Original Message-----
> From: P.J. Eby [mailto:pje at telecommunity.com]
> Sent: Saturday, 31 July, 2010 19:01
> To: Jason R. Coombs; distutils-sig at python.org
> Subject: Re: [Distutils] How to customize egg_info behavior
> 
> At 12:39 PM 7/31/2010 -0700, Jason R. Coombs wrote:
> >I'm using setuptools 0.6c11.
> >
> >I'd like to programmatically customize the way the egg_info command is
> >run. That is, in my setup.py, I would like to run some functions to
> >determine the tag-build, tag-date, and tag-svn-revision parameters to
> >egg_info. Are there parameters
> >
> >How is this task best accomplished? Do I subclass the egg_info Command?
> >If so, do I just specify cmdclass={'egg_info':my_custom_egg_info} ?  Or
> >would you recommend another approach?
> 
> You can just do this in your setup script:
> 
> setup(
>      ...
>      options = dict(egg_info = dict(tag_build = "whatever", ...)),
>      ...
> )
> 
> Replacing "whatever", of course, with your programmatic calculation.
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6448 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20100731/5bf9ba66/attachment-0001.bin>


More information about the Distutils-SIG mailing list