[Distutils] Package versioning

David Ascher da@ski.org
Wed, 21 Apr 1999 14:32:23 -0700 (Pacific Daylight Time)

On Wed, 21 Apr 1999, Greg Ward wrote:

> On 19 April 1999, Timothy Docker said:

> > Assuming it does, then how will this be achieved? I am presently
> > managing this with a messy arrangement of symlinks. 
> That's about the only thing I can think of.  

Symlinks aren't portable.  

I use a package which imports a subpackage based on code performed in the
toplevel __init__.py file.  

So, for example, my Snow directory (in my sys.path):


The code in __init__.py is a bit ugly but looks something like:

import sys, os, imp, string
_dir = __path__[0]
_listdir = os.listdir(_dir)
_thisdir = os.path.basename(_dir)
_instdirs = filter(lambda x: x[:len(_thisdir)+1] == _thisdir+'_', _listd

def datesort(f1, f2):
    parts1 = string.split(f1, '_')
    parts1[1:] = map(int, parts1[1:])
    parts2 = string.split(f2, '_')
    parts2[1:] = map(int, parts2[1:])
    return cmp(parts1, parts2)

_latest = _instdirs[-1]
_file, _pathname, _description = imp.find_module(_latest, __path__)
_module = imp.load_module(_latest, _file, _pathname, _description)

This is similar to Pmw's scheme.

mknewversion.py is a similar-looking script which makes copies of the
current version, comes up with the directory name based on the date and
existing versions, and does some platform-specific things (add symbolic
links for the programmer's sake, not the user's).

It's not ideal, but it's portable and customizable.