detecting version match/mismatch between core/plugins

Michael Ellerman michael at ellerman.id.au
Wed Aug 16 05:03:06 BST 2006


On 8/16/06, Aaron Bentley <aaron.bentley at utoronto.ca> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Wichmann, Mats D wrote:
> >>>It would be easy enough to have a version number in the plugin and
> >>>fail to load it if it's too low or high, it would just
> >>>require someone to write the code :)
> >>
> >>I think its up to the plugin to do that... keeps them more like regular
> >>python files.
> >
> >
> > Haven't followed up to last few comments, but I
> > think I agree that it's the plugin that needs to
> > have most of the "smarts".
>
> Here's what I'm considering adding to bzrtools:
>
> import bzrlib
>
>
> __version__ = '0.9'
>
>
> def check_bzrlib_version(desired_str):
>     """Check that bzrlib is compatible.
>
>     If version is < bzrtools version, assume incompatible.
>     If version == bzrtools version, assume completely compatible
>     If version == bzrtools version + 1, assume compatible, with deprecations
>     Otherwise, assume incompatible.
>     """
>     desired = tuple([int(num) for num in desired_str.split('.')])
>     desired_plus = (desired[0], desired[1]+1)
>     bzrlib_version = [int(num) for num in bzrlib.__version__.split('.')[:2]]
>     bzrlib_version = tuple(bzrlib_version)
>     if bzrlib_version == desired:
>         return
>     try:
>         from bzrlib.trace import warning
>     except ImportError:
>         # get the message out any way we can
>         from warnings import warn as warning
>     if bzrlib_version < desired:
>         warning('Installed bzr version %s is too old to be used with
> bzrtools'
>                 ' %s.' % (bzrlib.__version__, __version__))
>         # Not using BzrNewError, because it may not exist.
>         raise Exception, 'Version mismatch'

This is going to look very ugly. It'd be better to at least try and
import BzrNewError wouldn't it?

>     else:
>         warning('Bzrtools is not up to date with installed bzr version'
>                 ' %s. Please upgrade to bzrtools %i.%i.'
>                 % (bzrlib.__version__, bzrlib_version[0],
> bzrlib_version[1]))

This could be a bit confusing if users are being asked to install a
version which doesn't exist yet. Perhaps the warning should be more of
a suggestion, ie. "There might a newer version available".

cheers




More information about the bazaar mailing list