Skip to content

Commit 99cb89f

Browse files
authored
[airflow] Move rules from AIR312 to AIR302 (#17940)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> In the later development of Airflow 3.0, backward compatibility was not added for some cases. Thus, the following rules are moved back to AIR302 * airflow.hooks.subprocess.SubprocessResult → airflow.providers.standard.hooks.subprocess.SubprocessResult * airflow.hooks.subprocess.working_directory → airflow.providers.standard.hooks.subprocess.working_directory * airflow.operators.datetime.target_times_as_dates → airflow.providers.standard.operators.datetime.target_times_as_dates * airflow.operators.trigger_dagrun.TriggerDagRunLink → airflow.providers.standard.operators.trigger_dagrun.TriggerDagRunLink * airflow.sensors.external_task.ExternalTaskSensorLink → airflow.providers.standard.sensors.external_task.ExternalDagLink (**This one contains a minor change**) * airflow.sensors.time_delta.WaitSensor → airflow.providers.standard.sensors.time_delta.WaitSensor ## Test Plan <!-- How was it tested? -->
1 parent ac5df56 commit 99cb89f

File tree

6 files changed

+193
-132
lines changed

6 files changed

+193
-132
lines changed

crates/ruff_linter/resources/test/fixtures/airflow/AIR302_standard.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,16 @@
4747

4848
DummyOperator()
4949
EmptyOperator()
50+
51+
from airflow.hooks.subprocess import SubprocessResult
52+
SubprocessResult()
53+
from airflow.hooks.subprocess import working_directory
54+
working_directory()
55+
from airflow.operators.datetime import target_times_as_dates
56+
target_times_as_dates()
57+
from airflow.operators.trigger_dagrun import TriggerDagRunLink
58+
TriggerDagRunLink()
59+
from airflow.sensors.external_task import ExternalTaskSensorLink
60+
ExternalTaskSensorLink()
61+
from airflow.sensors.time_delta import WaitSensor
62+
WaitSensor()

crates/ruff_linter/resources/test/fixtures/airflow/AIR312.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from airflow.hooks.filesystem import FSHook
44
from airflow.hooks.package_index import PackageIndexHook
5-
from airflow.hooks.subprocess import SubprocessHook, SubprocessResult, working_directory
5+
from airflow.hooks.subprocess import SubprocessHook
66
from airflow.operators.bash import BashOperator
7-
from airflow.operators.datetime import BranchDateTimeOperator, target_times_as_dates
7+
from airflow.operators.datetime import BranchDateTimeOperator
88
from airflow.operators.empty import EmptyOperator
99
from airflow.operators.latest_only import LatestOnlyOperator
1010
from airflow.operators.python import (
@@ -13,16 +13,16 @@
1313
PythonVirtualenvOperator,
1414
ShortCircuitOperator,
1515
)
16-
from airflow.operators.trigger_dagrun import TriggerDagRunLink, TriggerDagRunOperator
16+
from airflow.operators.trigger_dagrun import TriggerDagRunOperator
1717
from airflow.operators.weekday import BranchDayOfWeekOperator
1818
from airflow.sensors.date_time import DateTimeSensor, DateTimeSensorAsync
1919
from airflow.sensors.external_task import (
2020
ExternalTaskMarker,
2121
ExternalTaskSensor,
22-
ExternalTaskSensorLink,
22+
2323
)
2424
from airflow.sensors.filesystem import FileSensor
25-
from airflow.sensors.time_delta import TimeDeltaSensor, TimeDeltaSensorAsync, WaitSensor
25+
from airflow.sensors.time_delta import TimeDeltaSensor, TimeDeltaSensorAsync
2626
from airflow.sensors.time_sensor import TimeSensor, TimeSensorAsync
2727
from airflow.sensors.weekday import DayOfWeekSensor
2828
from airflow.triggers.external_task import DagStateTrigger, WorkflowTrigger
@@ -31,10 +31,10 @@
3131

3232
FSHook()
3333
PackageIndexHook()
34-
SubprocessHook(), SubprocessResult(), working_directory()
34+
SubprocessHook()
3535
BashOperator()
36-
BranchDateTimeOperator(), target_times_as_dates()
37-
TriggerDagRunLink(), TriggerDagRunOperator()
36+
BranchDateTimeOperator()
37+
TriggerDagRunOperator()
3838
EmptyOperator()
3939
LatestOnlyOperator()
4040
(
@@ -45,10 +45,10 @@
4545
)
4646
BranchDayOfWeekOperator()
4747
DateTimeSensor(), DateTimeSensorAsync()
48-
ExternalTaskMarker(), ExternalTaskSensor(), ExternalTaskSensorLink()
48+
ExternalTaskMarker(), ExternalTaskSensor()
4949
FileSensor()
5050
TimeSensor(), TimeSensorAsync()
51-
TimeDeltaSensor(), TimeDeltaSensorAsync(), WaitSensor()
51+
TimeDeltaSensor(), TimeDeltaSensorAsync()
5252
DayOfWeekSensor()
5353
DagStateTrigger(), WorkflowTrigger()
5454
FileTrigger()

crates/ruff_linter/src/rules/airflow/rules/moved_to_provider_in_3.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,17 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan
10781078
},
10791079

10801080
// apache-airflow-providers-standard
1081+
[
1082+
"airflow",
1083+
"hooks",
1084+
"subprocess",
1085+
rest @ ("SubprocessResult" | "working_directory"),
1086+
] => ProviderReplacement::SourceModuleMovedToProvider {
1087+
name: (*rest).to_string(),
1088+
module: "airflow.providers.standard.hooks.subprocess",
1089+
provider: "standard",
1090+
version: "0.0.3",
1091+
},
10811092
["airflow", "operators", "bash_operator", "BashOperator"] => {
10821093
ProviderReplacement::AutoImport {
10831094
module: "airflow.providers.standard.operators.bash",
@@ -1097,6 +1108,25 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan
10971108
provider: "standard",
10981109
version: "0.0.2",
10991110
},
1111+
[
1112+
"airflow",
1113+
"operators",
1114+
"trigger_dagrun",
1115+
"TriggerDagRunLink",
1116+
] => ProviderReplacement::AutoImport {
1117+
module: "airflow.providers.standard.operators.trigger_dagrun",
1118+
name: "TriggerDagRunLink",
1119+
provider: "standard",
1120+
version: "0.0.2",
1121+
},
1122+
["airflow", "operators", "datetime", "target_times_as_dates"] => {
1123+
ProviderReplacement::AutoImport {
1124+
module: "airflow.providers.standard.operators.datetime",
1125+
name: "target_times_as_dates",
1126+
provider: "standard",
1127+
version: "0.0.1",
1128+
}
1129+
}
11001130
[
11011131
"airflow",
11021132
"operators",
@@ -1133,17 +1163,34 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan
11331163
provider: "standard",
11341164
version: "0.0.1",
11351165
},
1166+
[
1167+
"airflow",
1168+
"sensors",
1169+
"external_task",
1170+
"ExternalTaskSensorLink",
1171+
] => ProviderReplacement::AutoImport {
1172+
module: "airflow.providers.standard.sensors.external_task",
1173+
name: "ExternalDagLink",
1174+
provider: "standard",
1175+
version: "0.0.3",
1176+
},
11361177
[
11371178
"airflow",
11381179
"sensors",
11391180
"external_task_sensor",
11401181
rest @ ("ExternalTaskMarker" | "ExternalTaskSensor" | "ExternalTaskSensorLink"),
11411182
] => ProviderReplacement::SourceModuleMovedToProvider {
1142-
name: (*rest).to_string(),
11431183
module: "airflow.providers.standard.sensors.external_task",
1184+
name: (*rest).to_string(),
11441185
provider: "standard",
11451186
version: "0.0.3",
11461187
},
1188+
["airflow", "sensors", "time_delta", "WaitSensor"] => ProviderReplacement::AutoImport {
1189+
module: "airflow.providers.standard.sensors.time_delta",
1190+
name: "WaitSensor",
1191+
provider: "standard",
1192+
version: "0.0.1",
1193+
},
11471194

11481195
_ => return,
11491196
};

crates/ruff_linter/src/rules/airflow/rules/suggested_to_move_to_provider_in_3.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,9 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan
127127
version: "0.0.1",
128128
}
129129
}
130-
[
131-
"airflow",
132-
"hooks",
133-
"subprocess",
134-
rest @ ("SubprocessHook" | "SubprocessResult" | "working_directory"),
135-
] => ProviderReplacement::SourceModuleMovedToProvider {
136-
name: (*rest).to_string(),
130+
["airflow", "hooks", "subprocess", "SubprocessHook"] => ProviderReplacement::AutoImport {
137131
module: "airflow.providers.standard.hooks.subprocess",
132+
name: "SubprocessHook",
138133
provider: "standard",
139134
version: "0.0.3",
140135
},
@@ -144,25 +139,22 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan
144139
provider: "standard",
145140
version: "0.0.1",
146141
},
147-
[
148-
"airflow",
149-
"operators",
150-
"datetime",
151-
rest @ ("BranchDateTimeOperator" | "target_times_as_dates"),
152-
] => ProviderReplacement::SourceModuleMovedToProvider {
153-
name: (*rest).to_string(),
154-
module: "airflow.providers.standard.operators.datetime",
155-
provider: "standard",
156-
version: "0.0.1",
157-
},
142+
["airflow", "operators", "datetime", "BranchDateTimeOperator"] => {
143+
ProviderReplacement::AutoImport {
144+
module: "airflow.providers.standard.operators.datetime",
145+
name: "BranchDateTimeOperator",
146+
provider: "standard",
147+
version: "0.0.1",
148+
}
149+
}
158150
[
159151
"airflow",
160152
"operators",
161153
"trigger_dagrun",
162-
rest @ ("TriggerDagRunLink" | "TriggerDagRunOperator"),
163-
] => ProviderReplacement::SourceModuleMovedToProvider {
164-
name: (*rest).to_string(),
154+
"TriggerDagRunOperator",
155+
] => ProviderReplacement::AutoImport {
165156
module: "airflow.providers.standard.operators.trigger_dagrun",
157+
name: "TriggerDagRunOperator",
166158
provider: "standard",
167159
version: "0.0.2",
168160
},
@@ -245,7 +237,7 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan
245237
"airflow",
246238
"sensors",
247239
"time_delta",
248-
rest @ ("TimeDeltaSensor" | "TimeDeltaSensorAsync" | "WaitSensor"),
240+
rest @ ("TimeDeltaSensor" | "TimeDeltaSensorAsync"),
249241
] => ProviderReplacement::SourceModuleMovedToProvider {
250242
name: (*rest).to_string(),
251243
module: "airflow.providers.standard.sensors.time_delta",

crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR302_AIR302_standard.py.snap

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,80 @@ AIR302_standard.py:49:1: AIR302 `airflow.operators.dummy_operator.EmptyOperator`
153153
48 | DummyOperator()
154154
49 | EmptyOperator()
155155
| ^^^^^^^^^^^^^ AIR302
156+
50 |
157+
51 | from airflow.hooks.subprocess import SubprocessResult
156158
|
157159
= help: Install `apache-airflow-providers-standard>=0.0.2` and use `airflow.providers.standard.operators.empty.EmptyOperator` instead.
160+
161+
AIR302_standard.py:52:1: AIR302 `airflow.hooks.subprocess.SubprocessResult` is moved into `standard` provider in Airflow 3.0;
162+
|
163+
51 | from airflow.hooks.subprocess import SubprocessResult
164+
52 | SubprocessResult()
165+
| ^^^^^^^^^^^^^^^^ AIR302
166+
53 | from airflow.hooks.subprocess import working_directory
167+
54 | working_directory()
168+
|
169+
= help: Install `apache-airflow-providers-standard>=0.0.3` and use `airflow.providers.standard.hooks.subprocess.SubprocessResult` instead.
170+
171+
AIR302_standard.py:54:1: AIR302 `airflow.hooks.subprocess.working_directory` is moved into `standard` provider in Airflow 3.0;
172+
|
173+
52 | SubprocessResult()
174+
53 | from airflow.hooks.subprocess import working_directory
175+
54 | working_directory()
176+
| ^^^^^^^^^^^^^^^^^ AIR302
177+
55 | from airflow.operators.datetime import target_times_as_dates
178+
56 | target_times_as_dates()
179+
|
180+
= help: Install `apache-airflow-providers-standard>=0.0.3` and use `airflow.providers.standard.hooks.subprocess.working_directory` instead.
181+
182+
AIR302_standard.py:56:1: AIR302 `airflow.operators.datetime.target_times_as_dates` is moved into `standard` provider in Airflow 3.0;
183+
|
184+
54 | working_directory()
185+
55 | from airflow.operators.datetime import target_times_as_dates
186+
56 | target_times_as_dates()
187+
| ^^^^^^^^^^^^^^^^^^^^^ AIR302
188+
57 | from airflow.operators.trigger_dagrun import TriggerDagRunLink
189+
58 | TriggerDagRunLink()
190+
|
191+
= help: Install `apache-airflow-providers-standard>=0.0.1` and use `airflow.providers.standard.operators.datetime.target_times_as_dates` instead.
192+
193+
AIR302_standard.py:58:1: AIR302 `airflow.operators.trigger_dagrun.TriggerDagRunLink` is moved into `standard` provider in Airflow 3.0;
194+
|
195+
56 | target_times_as_dates()
196+
57 | from airflow.operators.trigger_dagrun import TriggerDagRunLink
197+
58 | TriggerDagRunLink()
198+
| ^^^^^^^^^^^^^^^^^ AIR302
199+
59 | from airflow.sensors.external_task import ExternalTaskSensorLink
200+
60 | ExternalTaskSensorLink()
201+
|
202+
= help: Install `apache-airflow-providers-standard>=0.0.2` and use `airflow.providers.standard.operators.trigger_dagrun.TriggerDagRunLink` instead.
203+
204+
AIR302_standard.py:60:1: AIR302 [*] `airflow.sensors.external_task.ExternalTaskSensorLink` is moved into `standard` provider in Airflow 3.0;
205+
|
206+
58 | TriggerDagRunLink()
207+
59 | from airflow.sensors.external_task import ExternalTaskSensorLink
208+
60 | ExternalTaskSensorLink()
209+
| ^^^^^^^^^^^^^^^^^^^^^^ AIR302
210+
61 | from airflow.sensors.time_delta import WaitSensor
211+
62 | WaitSensor()
212+
|
213+
= help: Install `apache-airflow-providers-standard>=0.0.3` and use `airflow.providers.standard.sensors.external_task.ExternalDagLink` instead.
214+
215+
Safe fix
216+
57 57 | from airflow.operators.trigger_dagrun import TriggerDagRunLink
217+
58 58 | TriggerDagRunLink()
218+
59 59 | from airflow.sensors.external_task import ExternalTaskSensorLink
219+
60 |-ExternalTaskSensorLink()
220+
60 |+from airflow.providers.standard.sensors.external_task import ExternalDagLink
221+
61 |+ExternalDagLink()
222+
61 62 | from airflow.sensors.time_delta import WaitSensor
223+
62 63 | WaitSensor()
224+
225+
AIR302_standard.py:62:1: AIR302 `airflow.sensors.time_delta.WaitSensor` is moved into `standard` provider in Airflow 3.0;
226+
|
227+
60 | ExternalTaskSensorLink()
228+
61 | from airflow.sensors.time_delta import WaitSensor
229+
62 | WaitSensor()
230+
| ^^^^^^^^^^ AIR302
231+
|
232+
= help: Install `apache-airflow-providers-standard>=0.0.1` and use `airflow.providers.standard.sensors.time_delta.WaitSensor` instead.

0 commit comments

Comments
 (0)