-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Add get_airflow_version helper #44607
Conversation
from airflow import configuration, settings | ||
|
||
|
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 think - as discussed in slack - this is a nice proposal. that we might be able to use in some 8 months (if we back-port it and release in 2.11, but we need to figure out - as part of it - what we do now and how we do it for the rest of the code.
I proposed a solution there (this needs to be fixed) - #43773 (comment) - not sure if we can figure out something better. I think it's a good idea to discuss it there.
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.
so the only real material problem with the constants is if someone imports one of these constants across providers. otherwise, it's mostly a non-issue. in any case this will be a generally helpful helper func.
if we want to reduce the likelihood of cross provider imports of these kinds of version constants, we could remove the version_references module from the standard provider. i've done that in latest commit. take a look and lemme know what you think.
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.
Actually, after thinking a bit and seeing it - I think we can have cale And wat it too. Maybe we can generate the constants via __init__.py
template in all providers?
This way each procider could have automatically generated own set of constant (possibly even named differently to avoid confusion where to importit from.
I am at family funeral today with my mum and two aunt's but I can propose a PR when I am back if that seems appealing
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.
See #44686
This should be not needed any more (at least for providers) after the better and more complete fix ("eat cake and have it too") in #44686 |
bdd3e60
to
d0d0e31
Compare
The point of this helper is to make it simpler to figure out what airflow version is installed, in particular to implement conditional logic in providers. Currently the logic is too complicated and this has resulted in the proliferation of sort of redundant constants. Here's an example: ``` from airflow import __version__ as AIRFLOW_VERSION AIRFLOW_V_3_0_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("3.0.0") if AIRFLOW_V_3_0_PLUS: from airflow.sdk.definitions.asset import Asset ``` With this helper, we can do this instead: ``` from airflow import get_airflow_version if get_airflow_version() > Version("3.0.0"): from airflow.sdk.definitions.asset import Asset ```
d0d0e31
to
96e5fe8
Compare
from airflow import configuration, settings | ||
|
||
|
||
def get_airflow_version() -> Version: |
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.
def get_airflow_version() -> Version: | |
def get_base_airflow_version() -> Version: |
|
||
def get_airflow_version() -> Version: | ||
"""Return packaging Version object representing the base version.""" | ||
return Version(Version(__version__).base_version) |
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.
Can we make sure (add pre-commit?) that this method is not used until min-airflow-version is set to 2.11 in all providers?
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.
Likely it could just be a RUFF https://docs.astral.sh/ruff/settings/#lint_flake8-import-conventions_banned-from if instead adding it to airflow/__init__.py
you will move it to airflow/version_compat.py
module for example (following what I am proposing in #44686 as a solution until 2.11 is set as minimum version.
Implementing identical module will make it as simple as removing all version_compat.py
from providers and replacing local provider's imports with imports from airflow.version_compat
.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via #44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
This PR introduces consistent way of checking version of Airflow by Airflow providers. So far there were about 6 different ways on how Providers checked for Airflow version - this PR aims to unify this approach for now and in the future - at least until minimum version of Airflow set to 2.11 where we are likely to introduce a simpler check via apache#44607. Until then all providers are going to have `version_references.py` module copied in their sources that they will be importing the constants from. This PR also adds pre-commit that checks if the ``version_compat.py`` module is imported from local package copy or maybe from another provider or test code - both causing unneeded dependencies from the provider - to another package or to test code respectively.
The point of this helper is to make it simpler to figure out what airflow version is installed, in particular to implement conditional logic in providers.
Currently the logic is too complicated and this has resulted in the proliferation of sort of redundant constants. Here's an example:
With this helper, we can do this instead:
We can't make use of this helper in providers until they are bumped to min airflow version == 2.11.0.