-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from airflow.www.security import FabAirflowSecurityManagerOverride | ||
|
||
FabAirflowSecurityManagerOverride |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub(crate) use dag_schedule_argument::*; | ||
pub(crate) use moved_to_provider_in_3::*; | ||
pub(crate) use removal_in_3::*; | ||
pub(crate) use task_variable_name::*; | ||
|
||
mod dag_schedule_argument; | ||
mod moved_to_provider_in_3; | ||
mod removal_in_3; | ||
mod task_variable_name; |
98 changes: 98 additions & 0 deletions
98
crates/ruff_linter/src/rules/airflow/rules/moved_to_provider_in_3.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use ruff_diagnostics::{Diagnostic, Violation}; | ||
use ruff_macros::{derive_message_formats, ViolationMetadata}; | ||
use ruff_python_ast::{Expr, ExprAttribute}; | ||
use ruff_python_semantic::Modules; | ||
use ruff_text_size::Ranged; | ||
|
||
use crate::checkers::ast::Checker; | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
enum Replacement { | ||
Message(String, String, String), | ||
} | ||
|
||
/// ## What it does | ||
/// Checks for uses of deprecated Airflow functions and values. | ||
/// | ||
/// ## Why is this bad? | ||
/// Airflow 3.0 removed various deprecated functions, members, and other | ||
/// values. Some have more modern replacements. Others are considered too niche | ||
/// and not worth to be maintained in Airflow. | ||
/// | ||
/// ## Example | ||
/// ```python | ||
/// from airflow.utils.dates import days_ago | ||
/// | ||
/// | ||
/// yesterday = days_ago(today, 1) | ||
/// ``` | ||
/// | ||
/// Use instead: | ||
/// ```python | ||
/// from datetime import timedelta | ||
/// | ||
/// | ||
/// yesterday = today - timedelta(days=1) | ||
/// ``` | ||
#[derive(ViolationMetadata)] | ||
pub(crate) struct Airflow3MoveToProvider { | ||
deprecated: String, | ||
replacement: Replacement, | ||
} | ||
|
||
impl Violation for Airflow3MoveToProvider { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
let Airflow3MoveToProvider { | ||
deprecated, | ||
replacement, | ||
} = self; | ||
match replacement { | ||
Replacement::Message(name, provider, provider_version) => { | ||
format!("`{deprecated}` is removed in Airflow 3.0; use `{name}` instead (in `{provider}=={provider_version}`)") | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn moved_to_provider(checker: &mut Checker, expr: &Expr, ranged: impl Ranged) { | ||
let result = | ||
checker | ||
.semantic() | ||
.resolve_qualified_name(expr) | ||
.and_then(|qualname| match qualname.segments() { | ||
["airflow", "www", "security", "FabAirflowSecurityManagerOverride"] => Some(( | ||
qualname.to_string(), | ||
Replacement::Message( | ||
"airflow.providers.fab.auth_manager.security_manager.override.FabAirflowSecurityManagerOverride".to_string(), | ||
"apache-airflow-providers-fab".to_string(), | ||
"1.0.0".to_string() | ||
), | ||
)), | ||
_ => None, | ||
}); | ||
if let Some((deprecated, replacement)) = result { | ||
checker.diagnostics.push(Diagnostic::new( | ||
Airflow3MoveToProvider { | ||
deprecated, | ||
replacement, | ||
}, | ||
ranged.range(), | ||
)); | ||
} | ||
} | ||
|
||
/// AIR303 | ||
pub(crate) fn moved_to_provider_in_3(checker: &mut Checker, expr: &Expr) { | ||
if !checker.semantic().seen_module(Modules::AIRFLOW) { | ||
return; | ||
} | ||
|
||
match expr { | ||
Expr::Attribute(ExprAttribute { attr: ranged, .. }) => { | ||
moved_to_provider(checker, expr, ranged); | ||
} | ||
ranged @ Expr::Name(_) => moved_to_provider(checker, expr, ranged), | ||
_ => {} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR303_AIR303.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/airflow/mod.rs | ||
snapshot_kind: text | ||
--- | ||
AIR303.py:3:1: AIR303 `airflow.www.security.FabAirflowSecurityManagerOverride` is removed in Airflow 3.0; use `airflow.providers.fab.auth_manager.security_manager.override.FabAirflowSecurityManagerOverride` instead (in `apache-airflow-providers-fab==1.0.0`) | ||
| | ||
1 | from airflow.www.security import FabAirflowSecurityManagerOverride | ||
2 | | ||
3 | FabAirflowSecurityManagerOverride | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR303 | ||
| |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.