Skip to content

Commit

Permalink
refactor(providers/common/compat): extract airflow version to __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Nov 8, 2024
1 parent e70bc8f commit 97d78b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
14 changes: 9 additions & 5 deletions providers/src/airflow/providers/common/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
#
from __future__ import annotations

import packaging.version
from packaging.version import Version

from airflow import __version__ as airflow_version
from airflow import __version__ as AIRFLOW_VERSION

__all__ = ["__version__"]

__version__ = "1.2.1"

if packaging.version.parse(packaging.version.parse(airflow_version).base_version) < packaging.version.parse(
"2.8.0"
):

AIRFLOW_V_3_0_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("3.0.0")
AIRFLOW_V_2_10_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("2.10.0")
AIRFLOW_V_2_9_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("2.9.0")
AIRFLOW_V_2_8_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("2.8.0")

if Version(Version(AIRFLOW_VERSION).base_version) < Version("2.8.0"):
raise RuntimeError(
f"The package `apache-airflow-providers-common-compat:{__version__}` needs Apache Airflow 2.8.0+"
)
14 changes: 6 additions & 8 deletions providers/src/airflow/providers/common/compat/assets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

from typing import TYPE_CHECKING

from airflow import __version__ as AIRFLOW_VERSION
from airflow.providers.common.compat import (
AIRFLOW_V_2_8_PLUS,
AIRFLOW_V_2_9_PLUS,
AIRFLOW_V_2_10_PLUS,
AIRFLOW_V_3_0_PLUS,
)

if TYPE_CHECKING:
from airflow.auth.managers.models.resource_details import AssetDetails
Expand All @@ -32,13 +37,6 @@
expand_alias_to_assets,
)
else:
from packaging.version import Version

AIRFLOW_V_3_0_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("3.0.0")
AIRFLOW_V_2_10_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("2.10.0")
AIRFLOW_V_2_9_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("2.9.0")
AIRFLOW_V_2_8_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("2.8.0")

if AIRFLOW_V_3_0_PLUS:
from airflow.auth.managers.models.resource_details import AssetDetails
from airflow.sdk.definitions.asset import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.
from __future__ import annotations

from airflow.providers.common.compat.assets import AIRFLOW_V_2_10_PLUS, AIRFLOW_V_3_0_PLUS
from airflow.providers.common.compat import AIRFLOW_V_2_10_PLUS, AIRFLOW_V_3_0_PLUS


def _get_asset_compat_hook_lineage_collector():
Expand Down

0 comments on commit 97d78b2

Please sign in to comment.