Re: Parsing and comparing version strings (was: Odd version scheme)

2015-02-12 Thread Tim Chase
On 2015-02-13 12:20, Ben Finney wrote:
  Not sure why this is ridiculous.
 
 Right, versions are effectively a special type [0], specifically
 *because* they intentionally don't compare as scalar numbers or
 strings. It's not “ridiculous” to need custom comparisons when
 that's the case.
 
 Python even comes with support for version parsing and comparison
 in the standard library [1]. So if anything's “ridiculous”, it's
 the act of re-implementing that and getting it wrong.
 
 (Or maybe that such an important part of the standard library is
 largely undocumented.)

I was surprised (pleasantly) to learn of that corner of distutils,
but can never remember where it is in the stdlib or what it's
called.  So it's pretty standard for my process to be something like

 - Hmm, I need to compare version-strings
 - search the web for python compare version number
 - note the top-ranked Stack Overflow answer
 - spot that it uses distutils.version.{LooseVersion,StrictVersion}
 - use that in my code, optionally searching to get full docs with 
   site:python.org LooseVersion StrictVersion, only to be
   surprised when something like
   https://docs.python.org/2/library/{module}
   isn't anywhere in the top umpteen hits.

largely undocumented is an understatement :-)

-tkc


-- 
https://mail.python.org/mailman/listinfo/python-list


Parsing and comparing version strings (was: Odd version scheme)

2015-02-12 Thread Ben Finney
Gisle Vanem gva...@yahoo.no writes:

 That's exactly what they do now in IPython/utils/version.py with
 the comment:
   Utilities for version comparison
   It is a bit ridiculous that we need these.

 Not sure why this is ridiculous.

Right, versions are effectively a special type [0], specifically
*because* they intentionally don't compare as scalar numbers or strings.
It's not “ridiculous” to need custom comparisons when that's the case.

Python even comes with support for version parsing and comparison in the
standard library [1]. So if anything's “ridiculous”, it's the act of
re-implementing that and getting it wrong.

(Or maybe that such an important part of the standard library is
largely undocumented.)


[0] URL:https://wiki.python.org/moin/Distutils/VersionComparison
[1] Unfortunately undocumented, like much of the Distutils API. Try

URL:http://epydoc.sourceforge.net/stdlib/distutils.version.StrictVersion-class.html.

-- 
 \  “Programs must be written for people to read, and only |
  `\incidentally for machines to execute.” —Abelson  Sussman, |
_o__)  _Structure and Interpretation of Computer Programs_ |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list