[Distutils] Synchronizing version information

Greg Ward gward@python.net
Thu Sep 21 22:11:17 2000


On 20 September 2000, Martin von Loewis said:
> In my package, I have two places which carry version information: in
> the setup.py, when passing the version= keyword argument to setup, and
> in the package's __init__, to allow runtime access to the available
> version.

I have the same problem -- I always have to update the Distutils
setup.py and distutils/__init__.py in sync.  Yuck.

> I'd like these to be synchronized, having the information only in a
> single place, and fetching it from there in the other. Is there any
> mechanism in distutils to facilitate such synchronization?

I just had an idea which requires no funky substitution mechanism, and
no extra code in the Distutils: in the setup file, do this (or
equivalent for your scenario):

    from distutils import core
    import distutils

    setup(name = "Distutils",
          version = distutils.__version__,
          ...)

> One approach would be a autoconf-style replacement mechanism, where I
> put
> 
> version_info = distutils.version.StrictVersion(@VERSION@)

Yuck.  I'm not keen on this.  It Just Seems Wrong to go hacking up
Python source like that.  (Although, mind you, the "build_scripts"
command does hack up Python scripts a bit.  But only the first line!)

Another idea, stolen (as usual) from Perl's MakeMaker: have a
"version_from" option in the setup script, eg.

    setup(name = "Distutils",
          version_from = "distutils/__init__.py",
          ...)

A couple of models suggest themselves here:
  * grep the named file for /^__version__ = "([^"]+)"/ and use $1
  * execfile the named file and extract __version__ from the module dict
  * don't give a filename, give a module name, and import __version__
    from it

Obviously, 'version' and 'version_from' would be mutually exclusive.

Opinions?

        Greg
        Greg
-- 
Greg Ward                                      gward@python.net
http://starship.python.net/~gward/