1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17#
18# NOTE! THIS FILE IS COPIED MANUALLY IN OTHER PROVIDERS DELIBERATELY TO AVOID ADDING UNNECESSARY
19# DEPENDENCIES BETWEEN PROVIDERS. IF YOU WANT TO ADD CONDITIONAL CODE IN YOUR PROVIDER THAT DEPENDS
20# ON AIRFLOW VERSION, PLEASE COPY THIS FILE TO THE ROOT PACKAGE OF YOUR PROVIDER AND IMPORT
21# THOSE CONSTANTS FROM IT RATHER THAN IMPORTING THEM FROM ANOTHER PROVIDER OR TEST CODE
22#
23from __future__ import annotations
24
25
26def get_base_airflow_version_tuple() -> tuple[int, int, int]:
27 from packaging.version import Version
28
29 from airflow import __version__
30
31 airflow_version = Version(__version__)
32 return airflow_version.major, airflow_version.minor, airflow_version.micro
33
34
35AIRFLOW_V_3_0_PLUS: bool = get_base_airflow_version_tuple() >= (3, 0, 0)
36AIRFLOW_V_3_1_PLUS: bool = get_base_airflow_version_tuple() >= (3, 1, 0)
37AIRFLOW_V_3_1_3_PLUS: bool = get_base_airflow_version_tuple() >= (3, 1, 3)
38AIRFLOW_V_3_2_PLUS: bool = get_base_airflow_version_tuple() >= (3, 2, 0)
39
40# BaseOperator: Use 3.1+ due to xcom_push method missing in SDK BaseOperator 3.0.x
41# This is needed for DecoratedOperator compatibility
42if AIRFLOW_V_3_1_PLUS:
43 from airflow.sdk import BaseOperator
44else:
45 from airflow.models.baseoperator import BaseOperator # type: ignore[no-redef]
46
47__all__ = [
48 "AIRFLOW_V_3_0_PLUS",
49 "AIRFLOW_V_3_1_PLUS",
50 "AIRFLOW_V_3_2_PLUS",
51 "BaseOperator",
52]