[Distutils] Specifying version information once

Jean-Paul Calderone exarkun at divmod.com
Wed May 20 03:05:07 CEST 2009

On Tue, 19 May 2009 20:49:37 -0400, "P.J. Eby" <pje at telecommunity.com> wrote:
>At 04:28 PM 5/19/2009 -0400, Jean-Paul Calderone wrote:
>>On Tue, 19 May 2009 16:23:16 -0400, "P.J. Eby" <pje at telecommunity.com> 
>>>At 02:21 PM 5/19/2009 -0400, Jean-Paul Calderone wrote:
>>>>What is the recommendation for specifying version information in a way 
>>>>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
>Well, if you're okay with depending on setuptools, you could have your 
>version code do this:
>   version = pkg_resources.require('ThisProject')[0].version
>And *only* define the version in setup.py, but don't import or run that 

I don't think I'm ready to make setuptools a mandatory dependency yet.

>Of, if you can't depend on setuptools (no pun intended), the only other 
>thing I can think of would be to put the version in a text file by itself, 
>and have both the version code and setup.py read that file.

That's an idea that's come up before.  I'm curious to here if anyone has
tried it and what their experiences have been.


More information about the Distutils-SIG mailing list