|
| 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 | +# |
| 23 | +from __future__ import annotations |
| 24 | + |
| 25 | + |
| 26 | +def 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 | + |
| 35 | +AIRFLOW_V_3_0_PLUS = get_base_airflow_version_tuple() >= (3, 0, 0) |
| 36 | + |
| 37 | +if AIRFLOW_V_3_0_PLUS: |
| 38 | + from airflow.sdk import BaseOperator |
| 39 | +else: |
| 40 | + from airflow.models import BaseOperator # type: ignore[no-redef] |
| 41 | + |
| 42 | +__all__ = [ |
| 43 | + "AIRFLOW_V_3_0_PLUS", |
| 44 | + "BaseOperator", |
| 45 | +] |
0 commit comments