This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v2-9-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 037effd0d76e32a0af5e0c309133f8aa15f41f7b
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Wed Apr 3 16:30:46 2024 +0200

    Drop pre-release specification from pre-installed provider versions (#38703)
    
    When Airflow installs a pre-release provider version we can add
    the `>=x.y.zdev0` or `>=x.y.zrc1` to pre-release provider specification.
    
    This is necessary to install dev0 or rc* packages when we release them
    for testing, when the pre-installed provider is a "chicken-egg" provider
    that does not yet have an "official" version - because otherwise
    the dependency would not allow the provider to be installed.
    
    However, the "final" package should have just `>=x.y.z` without the
    pre-release specification, because by the time we release the final
    version, the pre-release provider package should be already released.
    
    This PR implements such pre-release stripping. In cse we prepare
    the "final" version of the airflow package, all the preinstalled
    provider's specifications got the `>=version` stripped off all the
    prerelease information. The `>=1.2.0dev0` or `>=1.2.0rc1` is for
    example turned into `>=`1.2.0`.
    
    Co-authored-by: Andrey Anshin <andrey.ans...@taragol.is>
    (cherry picked from commit 1759336c6b721ba70ff5260da32105c698b6bafb)
---
 .pre-commit-config.yaml |  2 +-
 hatch_build.py          | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0841f498d6..8d0a4bbfc0 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1073,7 +1073,7 @@ repos:
         entry: "^\\s*from re\\s|^\\s*import re\\s"
         pass_filenames: true
         files: \.py$
-        exclude: 
^airflow/providers|^dev/.*\.py$|^scripts/.*\.py$|^tests/|^\w+_tests/|^docs/.*\.py$|^airflow/utils/helpers.py$
+        exclude: 
^airflow/providers|^dev/.*\.py$|^scripts/.*\.py$|^tests/|^\w+_tests/|^docs/.*\.py$|^airflow/utils/helpers.py$|^hatch_build.py$
       - id: check-deferrable-default-value
         name: Check default value of deferrable attribute
         language: python
diff --git a/hatch_build.py b/hatch_build.py
index 4835c5af82..3453eaf7ec 100644
--- a/hatch_build.py
+++ b/hatch_build.py
@@ -20,6 +20,7 @@ import itertools
 import json
 import logging
 import os
+import re
 import sys
 from pathlib import Path
 from subprocess import run
@@ -554,7 +555,22 @@ def get_provider_id(provider_spec: str) -> str:
 
 def get_provider_requirement(provider_spec: str) -> str:
     if ">=" in provider_spec:
+        # we cannot import `airflow` here directly as it would pull re2 and a 
number of airflow
+        # dependencies so we need to read airflow version by matching a regexp
+        airflow_init_content = (AIRFLOW_ROOT_PATH / "airflow" / 
"__init__.py").read_text()
+        airflow_version_pattern = r'__version__ = "(\d+\.\d+\.\d+\S*)"'
+        airflow_version_match = re.search(airflow_version_pattern, 
airflow_init_content)
+        if not airflow_version_match:
+            raise RuntimeError("Cannot find Airflow version in 
airflow/__init__.py")
+        from packaging.version import Version
+
+        current_airflow_version = Version(airflow_version_match.group(1))
         provider_id, min_version = provider_spec.split(">=")
+        provider_version = Version(min_version)
+        if provider_version.is_prerelease and not 
current_airflow_version.is_prerelease:
+            # strip pre-release version from the pre-installed provider's 
version when we are preparing
+            # the official package
+            min_version = str(provider_version.base_version)
         return f"apache-airflow-providers-{provider_id.replace('.', 
'-')}>={min_version}"
     else:
         return f"apache-airflow-providers-{provider_spec.replace('.', '-')}"

Reply via email to