Skip to content

Commit 3271d5f

Browse files
authored
Migrate segment provider to common.compat (#57078)
This PR is a part of 57018 about provider segment.
1 parent f1f051c commit 3271d5f

4 files changed

Lines changed: 6 additions & 19 deletions

File tree

providers/segment/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ requires-python = ">=3.10"
5858
# After you modify the dependencies, and rebuild your Breeze CI image with ``breeze ci-image build``
5959
dependencies = [
6060
"apache-airflow>=2.10.0",
61+
"apache-airflow-providers-common-compat>=1.7.4", # + TODO: bump to next version
6162
# segment-analytics-python is in mantaincnce mode.
6263
# Review changing to https://github.com/segmentio/public-api-sdk-python when ready? (currently in beta)
6364
"segment-analytics-python>=2.3.0",
@@ -68,6 +69,7 @@ dev = [
6869
"apache-airflow",
6970
"apache-airflow-task-sdk",
7071
"apache-airflow-devel-common",
72+
"apache-airflow-providers-common-compat",
7173
# Additional devel dependencies (do not remove this line and add extra development dependencies)
7274
]
7375

providers/segment/src/airflow/providers/segment/hooks/segment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import segment.analytics as analytics
2828

2929
from airflow.exceptions import AirflowException
30-
from airflow.providers.segment.version_compat import BaseHook
30+
from airflow.providers.common.compat.sdk import BaseHook
3131

3232

3333
class SegmentHook(BaseHook):

providers/segment/src/airflow/providers/segment/operators/segment_track_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from collections.abc import Sequence
2121
from typing import TYPE_CHECKING
2222

23+
from airflow.providers.common.compat.sdk import BaseOperator
2324
from airflow.providers.segment.hooks.segment import SegmentHook
24-
from airflow.providers.segment.version_compat import BaseOperator
2525

2626
if TYPE_CHECKING:
27-
from airflow.providers.segment.version_compat import Context
27+
from airflow.providers.common.compat.sdk import Context
2828

2929

3030
class SegmentTrackEventOperator(BaseOperator):

providers/segment/src/airflow/providers/segment/version_compat.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,7 @@ def get_base_airflow_version_tuple() -> tuple[int, int, int]:
3535
AIRFLOW_V_3_0_PLUS = get_base_airflow_version_tuple() >= (3, 0, 0)
3636
AIRFLOW_V_3_1_PLUS: bool = get_base_airflow_version_tuple() >= (3, 1, 0)
3737

38-
if AIRFLOW_V_3_0_PLUS:
39-
from airflow.sdk import BaseOperator
40-
from airflow.sdk.definitions.context import Context
41-
else:
42-
from airflow.models import BaseOperator
43-
from airflow.utils.context import Context
44-
45-
if AIRFLOW_V_3_1_PLUS:
46-
from airflow.sdk import BaseHook
47-
else:
48-
from airflow.hooks.base import BaseHook # type: ignore[attr-defined,no-redef]
49-
50-
# Explicitly export these imports to protect them from being removed by linters
5138
__all__ = [
5239
"AIRFLOW_V_3_0_PLUS",
53-
"BaseHook",
54-
"BaseOperator",
55-
"Context",
40+
"AIRFLOW_V_3_1_PLUS",
5641
]

0 commit comments

Comments
 (0)