Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python module for handling version of software

I am looking for a python module / library which will be to operate on 'software versions'... Which means, for example:

  • compare versions "1.0-SNAPSHOT" and "1.1-SNAPSHOT" and tell which is newer
  • increment "1.0.1-SNAPSHOT" to "1.0.2-SNAPSHOT"
  • make "1.0" from "1.0-SNAPSHOT" and same with '-RELEASE'

Yes, versions naming comes in this came from java (maven) world - my python part should operate on them..

Any ideas?

like image 651
bluszcz Avatar asked Sep 16 '25 09:09

bluszcz


1 Answers

distutils has some support for this.

>>> from distutils.version import LooseVersion  # or StrictVersion
>>> LooseVersion("1.0-SNAPSHOT") < LooseVersion("1.1-SNAPSHOT")
True
>>> v = LooseVersion("1.0.1-SNAPSHOT")
>>> v.version
[1, 0, 1, '-SNAPSHOT']

You'll have to do the incrementing and other manipulation yourself though.

like image 136
Fred Foo Avatar answered Sep 19 '25 05:09

Fred Foo