Search code examples
pythoneasy-installpip

What is the standard sort order for Python release/version numbers?


Python's pip and easy_install follow some rules to sort packages by their release numbers. What are the rules for numbering beta/release/bugfix releases so these tools will know which is the newest?


Solution

  • This is a sore point for many folks. setuptools and easy_install have some rather bizarre rules in an attempt to play nice with everybody. You can read the full rules in setuptools's parse_version method, but here's the summary:

    • Version numbers are broken up by dots into a tuple of that many segments. 4.5.6.7 is parsed into a tuple equal to ("4", "5", "6", "7").

    • Trailing zeroes between dashes or alphanumerics are suppressed. 2.4.0 is the same as 2.4; 2.4.05 is the same as 2.4.5.

    • Alphanumeric parts are downcased. 2.4.a5 is equal to 2.4.A5.

    • Strings that come before "final" alphabetically are assumed to be pre-release versions, so 2.4.5b comes before, not after, 2.4.5.

    • Finally, "pre", "preview", and "rc" are treated as if they were "c". The word "dev" is replaced with "@", so that it comes before anything else with the same version. That is, x.y.z-dev is guaranteed to come before any other x.y.z version.

    There are a number of proposals to organize things a bit more, of which the most popular is probably PEP 386.