[Python-Dev] PEP 396, Module Version Numbers

Barry Warsaw barry at python.org
Tue Apr 12 22:01:41 CEST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On Apr 06, 2011, at 11:04 AM, John Arbash Meinel wrote:

>> In other words, parse_version will return a tuple for each version string,
>> that is compatible with StrictVersion but also accept arbitrary version and
>> deal with them so they can be compared:
>> 
>>>>> from pkg_resources import parse_version as V
>>>>> V('1.2')
>> ('00000001', '00000002', '*final')
>>>>> V('1.2b2')
>> ('00000001', '00000002', '*b', '00000002', '*final')
>>>>> V('FunkyVersion')
>> ('*funkyversion', '*final')
>
>bzrlib has certainly used 'version_info' as a tuple indication such as:
>
>version_info = (2, 4, 0, 'dev', 2)
>
>and
>
>version_info = (2, 4, 0, 'beta', 1)
>
>and
>
>version_info = (2, 3, 1, 'final', 0)
>
>etc.
>
>This is mapping what we could sort out from Python's "sys.version_info".

It's probably worth specifying the __version_info__ tuple in more detail in
either PEP 386 or 396.  I think more detail should go *somewhere*, and it
feels like it could go in either PEP.  Maybe Tarek can chime in on that.

>The *really* nice bit is that you can do:
>
>if sys.version_info >= (2, 6):
>  # do stuff for python 2.6(.0) and beyond
>
>Doing that as:
>
>if sys.version_info >= ('000000002', '000000006'):
>
>is pretty ugly.

I personally often do tests against sys.hexversion, which is a little less
ugly (maybe ;).

if sys.hexversion >= 0x20600f0:
    # 2.6 or 2.7

- -Barry
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBCAAGBQJNpK+lAAoJEBJutWOnSwa/+pYP/R5x6siiCRpGGUjwQti7BZRg
fcddP1kUV/FU6fQFE44ZrXki0d7kx5SyNCTQTphtnBlUiqAvtjYK6oKon9xNqsq/
5KocKrbJZ/h806H0irzElzRXs3M+OcymC2ZQwvR1hqzMrdFRGRQMmanR0yz3LB1x
S2mF+TR2zEdMX4Ace6+Y5Vx4NYHTELapMOfamDgtft+lE+c8w6U7aZX/Gyzgagsd
yXDd33LI4/dRIENA/9NYycm05txebWpbEQsLLytczZqfLX7uXqOe5HTvO2g9CcmD
Yi8AT3ypERAHp+cLED7ICJkD3MY9AMlJBum7wgFjrKvwiJ7tu9x/9nTP3jhE6SaV
oDcyo2qLoCYbBBL+83bsRYK0AEBZAz4fsfJ/2A+a7vIjFrAFsRab7qiLrC9Pg1N+
DC4aFakRkrRBOoLoXnfYmTDq3zqvny4RzsbwP/eD/A13YfquLr8ECL6TFa3WOpNz
cmB6+h6O7AcMHlblON+Cf3PfHcPQC1h9atrkrjOBeG9m5812HcO/sC8lMWk0pUpa
D8OozOJI3ISQvw/rDEFMYKauc7eUIp/2hR4N7NBqBBo28TL38sRvQsQ6UoV0C/aF
3cjAhSHG5g2zsZZADUbyAel5h6MKoyoHkbA11yOHS3RXmE8XASa0zckRYwUwfGtC
M8PDejFisplJhDj2rGSa
=fpk4
-----END PGP SIGNATURE-----


More information about the Python-Dev mailing list