5

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?

joeforker
  • 40,459
  • 37
  • 151
  • 246

3 Answers3

9

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.

John Feminella
  • 303,634
  • 46
  • 339
  • 357
  • 2
    PEP 386 is now accepted and implemented in packaging (Python 3.3 stdlib) and distutils2 (standalone version for 2.4-3.2). – merwok Feb 11 '12 at 03:40
  • And PEP 386 was superseded by [PEP 440](https://peps.python.org/pep-0440/). – Socowi Aug 05 '22 at 11:35
2

See the documentation or look at the source: doc string in pkg_resources.py function parse_version().

Peter Hansen
  • 21,046
  • 5
  • 50
  • 72