[Distutils] Single version number

P.J. Eby pje at telecommunity.com
Fri Jul 10 20:07:18 CEST 2009


At 09:24 AM 7/10/2009 -0400, Barry Warsaw wrote:
>On Jul 10, 2009, at 8:58 AM, Marius Gedminas wrote:
>
>>What do people use to avoid repeating the version number both in the
>>setup.py as well as in application/library code, when the
>>application/library wants to know its own version number?
>>
>>I've seen several options:
>>
>>  1) put __version__ = '4.2' in yourpackage/__init__.py, have setup.py
>>     do from yourpackage import __version__ and pass that to setup()
>
>This is generally what I do and it seems to work pretty well for me.
>I remember talking with Gary Poster about some problems with this,
>related to our open source lazr packages, but I don't recall the
>details.

You'll have problems with this in the case where your __init__.py 
imports any of your dependencies (directly or indirectly), since it 
will effectively mean your setup.py will need its dependencies 
installed before it even says what they are.  ;-)

In such cases, putting a separate version.py or version.txt in the 
package, and execfile-ing it from setup.py is a better choice.

Personally, I don't even bother putting version info in the package 
code; that's what pkg_resources is for.  ;-)



More information about the Distutils-SIG mailing list