Code

Semantic Versioning

Most packages use semantic versioning: MAJOR.MINOR.PATCH.

Bump When Example
PATCH bug fixes only 1.4.2 to 1.4.3
MINOR new features, still compatible 1.4.2 to 1.5.0
MAJOR breaking changes 1.4.2 to 2.0.0

A bump resets everything to its right to zero. Users can then write rich>=13,<14 to say "any compatible 13.x release".

The classic trap

Comparing versions as strings goes wrong:

"1.10.0" > "1.9.0"           # False! '1' < '9'
(1, 10, 0) > (1, 9, 0)       # True: compare numbers

Tuples compare item by item, left to right, which is exactly the rule versions need. So parse versions into tuples of ints.

(Real version strings can also have pre-release tags like 2.0.0rc1. The packaging library handles every case, but you'll build the core version here.)

Assignment

  1. Fix parse_version(text) so it returns a tuple of 3 ints. Allow a leading "v" ("v2.0.1"). Raise ValueError unless there are exactly 3 parts and they are all digits.
  2. compare_versions(a, b) returns -1, 0 or 1.
  3. bump(version, part) returns the new version string for part = "major", "minor" or "patch". Raise ValueError for anything else.