From 8511da3996a589f03ce07e6e5fd038d5e75e0720 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Tue, 25 Mar 2025 16:29:47 +0100 Subject: [PATCH] Change version handling in provider documentation to packaging version We have been using SemVer to handle version updates in provider documentation breeze commands, which started to break at the moment we started to have pre-release packages - Puthon packaging follows PEP-440 and it is implemented in packaging.version module. This module does not have all the nice features semver has (like bumping the major/minor/patchlevel versions so we had to implement it ourselves (packaging Versions are immutable and we need to recreate the version after bump. --- dev/breeze/README.md | 2 +- dev/breeze/pyproject.toml | 1 - .../provider_documentation.py | 30 +++++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/dev/breeze/README.md b/dev/breeze/README.md index 692a4bcd335e3..c333845992b40 100644 --- a/dev/breeze/README.md +++ b/dev/breeze/README.md @@ -135,6 +135,6 @@ PLEASE DO NOT MODIFY THE HASH BELOW! IT IS AUTOMATICALLY UPDATED BY PRE-COMMIT. --------------------------------------------------------------------------------------------------------- -Package config hash: afd9da2026a8ef459e604a86236da3295475a883c9479a87746635b9790aa2eaa2e678aa06ea3522d9e3f93c88b172ba4914d707800c060c6d003eb68ea1e415 +Package config hash: 9d5c8788a7125a0db14fdfbe8a6a1873c4590a2b2d60ac362a6597e64b845cb033ea398cb55548d47605d4730f66aac8fba0c501c8eacf84a3cb6027a121acca --------------------------------------------------------------------------------------------------------- diff --git a/dev/breeze/pyproject.toml b/dev/breeze/pyproject.toml index 7dbc2fc219a87..6e56bce064a00 100644 --- a/dev/breeze/pyproject.toml +++ b/dev/breeze/pyproject.toml @@ -75,7 +75,6 @@ dependencies = [ "restructuredtext-lint>=1.4.0", "rich-click>=1.7.1", "rich>=13.6.0", - "semver>=3.0.2", "tabulate>=0.9.0", "tomli>=2.0.1; python_version < '3.11'", "twine>=4.0.2", diff --git a/dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py b/dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py index 64a1e73116229..222905b7031f8 100644 --- a/dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py +++ b/dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py @@ -32,6 +32,7 @@ from time import time from typing import Any, NamedTuple +from packaging.version import Version, parse from rich.syntax import Syntax from airflow_breeze.utils.black_utils import black_format @@ -482,6 +483,24 @@ def _mark_latest_changes_as_documentation_only( raise PrepareReleaseDocsChangesOnlyException() +VERSION_MAJOR_INDEX = 0 +VERSION_MINOR_INDEX = 1 +VERSION_PATCHLEVEL_INDEX = 2 + + +def bump_version(v: Version, index: int) -> Version: + versions = list(v.release) + versions[index] += 1 + # Packaging version returns None for pre and dev if they are not set + # In PEP-440 it is perfectly fine to have 1.2.3b1.dev0 or 1.2.3.dev0 + # Unlike dev, pre-release does not have "." to separate it from the version + pre = f"{v.pre[0]}{v.pre[1]}" if v.pre else "" + dev = f".dev{v.dev}" if v.dev is not None else "" + return parse( + f"{versions[VERSION_MAJOR_INDEX]}.{versions[VERSION_MINOR_INDEX]}.{versions[VERSION_PATCHLEVEL_INDEX]}{pre}{dev}" + ) + + def _update_version_in_provider_yaml( provider_id: str, type_of_change: TypeOfChange, @@ -494,23 +513,22 @@ def _update_version_in_provider_yaml( """ provider_details = get_provider_details(provider_id) version = provider_details.versions[0] - import semver - v = semver.VersionInfo.parse(version) + v = parse(version) with_breaking_changes = False maybe_with_new_features = False if type_of_change == TypeOfChange.BREAKING_CHANGE: - v = v.bump_major() + v = bump_version(v, VERSION_MAJOR_INDEX) with_breaking_changes = True # we do not know, but breaking changes may also contain new features maybe_with_new_features = True elif type_of_change == TypeOfChange.FEATURE: - v = v.bump_minor() + v = bump_version(v, VERSION_MINOR_INDEX) maybe_with_new_features = True elif type_of_change == TypeOfChange.BUGFIX: - v = v.bump_patch() + v = bump_version(v, VERSION_PATCHLEVEL_INDEX) elif type_of_change == TypeOfChange.MISC: - v = v.bump_patch() + v = bump_version(v, VERSION_PATCHLEVEL_INDEX) provider_yaml_path = get_provider_yaml(provider_id) original_provider_yaml_content = provider_yaml_path.read_text() updated_provider_yaml_content = re.sub(