[Distutils] Specifying version information once

Jean-Paul Calderone exarkun at divmod.com
Tue May 19 22:28:14 CEST 2009


On Tue, 19 May 2009 16:23:16 -0400, "P.J. Eby" <pje at telecommunity.com> wrote:
>At 02:21 PM 5/19/2009 -0400, Jean-Paul Calderone wrote:
>>Hello,
>>
>>For a long time, the idiom I've used to specify version information in my
>>distutils-based packages has been this simple one: put version information
>>into the Python package somewhere, structure the source layout so that the
>>package can be imported directly from an unpacked source tarball (or vcs 
>>wc),
>>and import the version into setup.py.  This worked great.  And I only had 
>>to
>>define my version once.
>>
>>Increasingly, it seems that new distutils-related tools don't support this
>>idiom and break in various ways.  (eg
>>
>>  http://divmod.org/trac/ticket/2629
>>  http://divmod.org/trac/ticket/2831
>>)
>>
>>What is the recommendation for specifying version information in a way 
>>which
>>is compatible with all these new tools?
>
>Don't import the file with your version info; execfile() it instead.
>
>That is, you can have a somepackage.version module for importing, but from 
>within your setup.py, do execfile('somepackage/version.py') instead, so as 
>to avoid actually importing your package (and anything it depends on).
>

execfile() doesn't set __name__ properly; setting __name__ in a namespace
passed to execfile() produces a CPython SystemError.  At the moment my
version code depends on __name__ being set.  I'm sure I could work around
this, but it'd be better if I didn't have to worry about code in the
version module being executed in two unrelated contexts.  Any other
suggestions?

Jean-Paul


More information about the Distutils-SIG mailing list