[airflow]: Import modules that has been moved to airflow providers (AIR303)#14764
[airflow]: Import modules that has been moved to airflow providers (AIR303)#14764MichaReiser merged 1 commit intoastral-sh:mainfrom
Conversation
|
03288b2 to
46e0214
Compare
|
@MichaReiser would love to know whether the overall idea of this PR makes sense if you have some time. I plan on writing a guideline for folks from the airflow community to contribute to AIR303 more easily. 🙂 |
...linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR303_AIR303.py.snap
Show resolved
Hide resolved
|
Is it correct that the entire module itself has been moved to being used as a provider without changing any of the public symbols available in that module? i.e., are the symbols that were available in the old module the same as that in the provider module? If so, we could consider the rule to work on the module instead of individual symbols from the module and suggest to use the provider instead. That way we'll only emit a single diagnostic for the entire module which will be the import statement. |
Yep, that's what I think for some of the modules, but I'll confirm it again.
Yep, some of the modules can be done this way, but others might not, so that why I'd like to keep the individual symbols check as well |
That's sounds reasonable. |
MichaReiser
left a comment
There was a problem hiding this comment.
writing a guideline for folks from the airflow community to contribute to AIR303 more easily.
This sounds great. I'd appreciate your with reviewing and coordinating the PRs as you have the most knowledge about what the rules should cover.
...linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR303_AIR303.py.snap
Show resolved
Hide resolved
Will do 👍 |
f1399eb to
77e3c45
Compare
* import path (module/package) moved * `airflow.api.auth.backend.basic_auth` → `airflow.providers.fab.auth_manager.api.auth.backend.basic_auth` * `airflow.api.auth.backend.kerberos_auth` → `airflow.providers.fab.auth_manager.api.auth.backend.kerberos_auth` * `airflow.auth.managers.fab.api.auth.backend.kerberos_auth` → `airflow.providers.fab.auth_manager.api.auth.backend.kerberos_auth` * `airflow.auth.managers.fab.security_manager.override` → `airflow.providers.fab.auth_manager.security_manager.override` * other names (e.g., functions, classes) moved * `airflow.www.security.FabAirflowSecurityManagerOverride` → `airflow.providers.fab.auth_manager.security_manager.override.FabAirflowSecurityManagerOverride` * `airflow.auth.managers.fab.fab_auth_manager.FabAuthManager` → `airflow.providers.fab.auth_manager.security_manager.FabAuthManager`
* main: [red-knot] Display definition range in trace logs (#14955) [red-knot] Move the `ClassBase` enum to its own submodule (#14957) [red-knot] mdtest: python version requirements (#14954) [airflow]: Import modules that has been moved to airflow providers (AIR303) (#14764) [red-knot] Support `typing.TYPE_CHECKING` (#14952) Add tracing support to mdtest (#14935) Re-enable the fuzzer job on PRs (#14953) [red-knot] Improve `match` mdtests (#14951) Rename `custom-typeshed-dir`, `target-version` and `current-directory` CLI options (#14930) [red-knot] Add narrowing for 'while' loops (#14947) [`ruff`] Skip SQLModel base classes for `mutable-class-default` (`RUF012`) (#14949) [red-knot] Tests for 'while' loop boundness (#14944)
Summary
Many core Airflow features have been deprecated and moved to Airflow Providers since users might need to install an additional package (e.g.,
apache-airflow-provider-fab==1.0.0); a separate rule (AIR303) is created for this.As some of the changes only relate to the module/package moved, instead of listing out all the functions, variables, and classes in a module or a package, it warns the user to import from the new path instead of the specific name.
The following is the ones that has been moved to
apache-airflow-provider-fab==1.0.0airflow.api.auth.backend.basic_auth→airflow.providers.fab.auth_manager.api.auth.backend.basic_authairflow.api.auth.backend.kerberos_auth→airflow.providers.fab.auth_manager.api.auth.backend.kerberos_authairflow.auth.managers.fab.api.auth.backend.kerberos_auth→airflow.providers.fab.auth_manager.api.auth.backend.kerberos_authairflow.auth.managers.fab.security_manager.override→airflow.providers.fab.auth_manager.security_manager.overrideairflow.www.security.FabAirflowSecurityManagerOverride→airflow.providers.fab.auth_manager.security_manager.override.FabAirflowSecurityManagerOverrideairflow.auth.managers.fab.fab_auth_manager.FabAuthManager→airflow.providers.fab.auth_manager.security_manager.FabAuthManager#14764
How to contribute to AIR303
Browse the airflow / ruff migration guideline
How to create a Ruff lint rule for Airflow 2-to-3 migrations
Setup local development environment
Contributing to Ruff
Check the existing rules from airflow issue
All the ruff rules are listed down in Airflow 2 to 3 auto migration rules - ruff #44556
Go to
AIR303: moved to providerin the issue description and you'll find rules likeIt means
airflow.www.security.FabAirflowSecurityManagerOverridehas been moved to airflow provider and the import should be changed toairflow.providers.fab.auth_manager.security_manager.override.FabAirflowSecurityManagerOverride. This changed is made in apache/airflow#41758Some of the rules might not be correct, so checking the pull request again is suggested.
Add a new rule
Go to
crates/ruff_linter/src/rules/airflow/rules/moved_to_provider_in_3.rsIn function
moved_to_provider, add code section like the following"airflow", "www", "security", "FabAirflowSecurityManagerOverride": the deprecated import pathnameis the new name that should be used.provideris which provider this name has been moved to.versionis the first version of the provider that has been moved to.For rules like
The whole module/pacakge has been moved to the provider. Thus, we'll need to warn the users when something is imported from the old path instead.
"airflow", "api", "auth", "backend", "basic_auth", ..: anything under this import pathoriginal pathnew path: new import path in the providerprovideris which provider this name has been moved to.versionis the first version of the provider that has been moved to.Add test case
Add a case that violate this rule to
crates/ruff_linter/resources/test/fixtures/airflow/AIR303.pyTest and generate snapshop to review
cargo insta test cargo insta reviewNow you're ready to create a pull request
Test Plan
A test fixture has been included for the rule.