Semantic Versioning & Version Specifiers (PEP 440)
PEP 440 standardizes Python version identifiers (`MAJOR.MINOR.PATCH`). Version specifiers allow strict pins (`==`), ranges (`>=`, `<`), and compatible release operators (`~= 1.4.0` allowing `>= 1.4.0, == 1.4.*`) 🏷️.
def is_compatible(installed, base):
inst = [int(x) for x in installed.split(".")]
b = [int(x) for x in base.split(".")]
# ~= 1.4.0 allows patch bumps within 1.4.x
return inst >= b and inst[:2] == b[:2]
print(f"1.4.3 ~= 1.4.0: {is_compatible('1.4.3', '1.4.0')} 🏷️")
print(f"1.5.0 ~= 1.4.0: {is_compatible('1.5.0', '1.4.0')} 🛑")
# 100. Semantic Versioning & Version Specifiers (PEP 440) PEP 440 standardizes Python version identifiers (`MAJOR.MINOR.PATCH`). Version specifiers allow strict pins (`==`), ranges (`>=`, `<`), and compatible release operators (`~= 1.4.0` allowing `>= 1.4.0, == 1.4.*`) 🏷️. ```python def is_compatible(installed, base): inst = [int(x) for x in installed.split(".")] b = [int(x) for x in base.split(".")] # ~= 1.4.0 allows patch bumps within 1.4.x return inst >= b and inst[:2] == b[:2] print(f"1.4.3 ~= 1.4.0: {is_compatible('1.4.3', '1.4.0')} 🏷️") print(f"1.5.0 ~= 1.4.0: {is_compatible('1.5.0', '1.4.0')} 🛑") ``` Under Semantic Versioning (SemVer): `MAJOR` indicates breaking API changes, `MINOR` introduces backward-compatible features, and `PATCH` applies backward-compatible bug fixes 🚀! --- ### Question What does the compatible release operator `~= 2.2.0` specify under PEP 440 rules? 🧠 - [ ] a. It allows any version `>= 2.2.0` and `< 2.3.0` (matching major and minor versions) 🏷️ - [ ] b. It strictly matches only version 2.2.0 exactly without patch variations - [ ] c. It permits any version up to `< 3.0.0` - [ ] d. It installs experimental pre-release alpha builds automatically --- ### Challenge Implement `compatible(installed, base)` for 3-part versions. Return `True` if `installed >= base` and `inst[:2] == base[:2]`. Test with `'1.4.3'` and `'1.4.0'`. Print the boolean. 🎯 <details> <summary>Solution</summary> ```python def compatible(installed, base): i = [int(x) for x in installed.split('.')] b = [int(x) for x in base.split('.')] return i >= b and i[:2] == b[:2] print(compatible('1.4.3', '1.4.0')) ``` </details>