-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Improve prek hook to check for proper imports in shared distributions #58825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Improve prek hook to check for proper imports in shared distributions #58825
Conversation
ee1c3ca to
915a85f
Compare
jscheffl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
915a85f to
90412d0
Compare
|
Small thing - this one should fail. I restarted it with full-tests-needed. |
90412d0 to
7e2ba2e
Compare
|
OK. Figured out why it did not run - added "scripts/ci/prek" to also trigger full tests. |
0b0881d to
b537ffe
Compare
b537ffe to
79426a7
Compare
|
@amoghrajesh @xBis7 - I solved the "module_loading" import issue (I created a new shared distribution "import_utils") and added even more checks in the prek hook. It nicely shows now all the remaining issues that we have to solve (basically settings that already had some TODOs and issues). I will keep on extracting things from this PR to separate PRs (for example extraction of import_utils can be done as a separate PR) - and I think that might be a good idea for other changes - to rebase them on top of this one, because this one immediately shows now violations of imports that we still have :) |
b9d66dc to
8de0d2a
Compare
17fa532 to
e52d2e0
Compare
|
@amoghrajesh @xBis7 I rebased my change and added some changes:
|
e52d2e0 to
5b99a82
Compare
Good find, yes that will likely be needed. Let is be independent as and when possible |
amoghrajesh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some observations and comments, looks good otherwise.
| import attr | ||
|
|
||
| import airflow.serialization.serializers | ||
| from airflow._shared.module_loading import import_string, iter_namespace, qualname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: revisit this occurence as part of Move over serde library to task sdk
| core_masker.sensitive_variables_fields = list(sensitive_fields) | ||
| core_masker.secret_mask_adapter = secret_mask_adapter | ||
|
|
||
| # TODO: this should be moved out when settings are moved to `shared` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think I follow this one
providers/apache/kafka/src/airflow/providers/apache/kafka/hooks/consume.py
Show resolved
Hide resolved
| Raise ImportError if the import failed. | ||
| """ | ||
| # TODO: Add support for nested classes. Currently, it only works for top-level classes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to? I dont see a use case for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. I just copied it from the original code.
5b99a82 to
2e8b15b
Compare
|
Rebased it after observability was added :) |
2e8b15b to
ccd119e
Compare
Shared packages should not refer to airflow or airflow.sdk. This is the last "airflow" import remaining in the observability package. Fixed during implementation of apache#58825
Shared packages should not refer to airflow or airflow.sdk. This is the last "airflow" import remaining in the observability package. Fixed during implementation of #58825
Shared packages should not refer to airflow or airflow.sdk. This is the last "airflow" import remaining in the observability package. Fixed during implementation of apache#58825
a5b108f to
4752c49
Compare
Since we are quite close to having a completed separation between distributions, this PR will be rebased until we will fix all the issues - we might want to extract things from this PR as we rebase it and move the code between distributions. The following checks were added: * The shared distributions (neither in src nor tests) should never import `from airflow.` * The distributions that are using shared code "airlfow-core", "task-sdk" should never import anything from either "airflow_shared" or from "_shared" import coming from another distribution. * Neither "apache-airflow", "apache-airflow-task-sdk", "apache-airflow-core" should be added as dependency in a shared distribution. * The "devel-common" should also not refer to airflow.* - it should only import from airflow_shared.*
4752c49 to
b34e1b0
Compare

Since we are quite close to having a completed separation between
distributions, this PR will be rebased until we will fix all the
issues - we might want to extract things from this PR as we
rebase it and move the code between distributions.
The following checks were added:
The shared distributions (neither in src nor tests) should never
import
from airflow.The distributions that are using shared code "airlfow-core",
"task-sdk" should never import anything from either
"airflow_shared" or from "_shared" import coming from another
distribution.
Neither "apache-airflow", "apache-airflow-task-sdk", "apache-airflow-core"
should be added as dependency in a shared distribution.
The "devel-common" should also not refer to airflow.* - it should only
import from airflow_shared.*
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.