Ben Finney <ben+pyt...@benfinney.id.au> writes:

>     >>> from verlib import RationalVersion as V
>     >>> (V('1.0')
>     ...  < V('1.0.a1')
>     ...  < V('1.0.a2')
>     ...  < V('1.0.a2.1')
>     ...  < V('1.0.b2')
>     ...  < V('1.0.c1')
>     ...  < V('1.0.dev456post623')
>     ...  < V('1.0.post456'))
>     True

+1

With a caveat (or maybe this is the way it already works?) that every
series of adjacent digits in the version be compared as an integer
occupying a single character's worth of string, regardless of how many
digits compose the integer - which, I personally think, is how strings
should always be compared, and is the first thing I'd fix if I could go
back in time and improve something about Unix on the PDP in 1970 so that
it would have followed as the default string comparison mechanism
through the rest of time.  The fact that "log.7" sorts after "log.10" is
simply stupid, and trying to fix the problem with leading zeros is a
silly hack that breaks as soon as you get more log files that you
thought you'd need.

In other words:

  - Take the strings you are comparing:
         "1.0.post45pre12"
         "1.0.post9pre12"

  - Consider adjacent series of digits to be integers, not strings:
         (1, '.', 0, '.post', 45, 'pre', 12)
         (1, '.', 0, '.post',  9, 'pre', 12)

  - Compare the results, making (in this case) the number 9 come before
    the number 45, correcting the normal problem that the string "9" is
    lexicographically after the string "45".

-- 
Brandon Craig Rhodes   bran...@rhodesmill.org   http://rhodesmill.org/brandon
_______________________________________________
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig

Reply via email to