Taragolis commented on code in PR #37330:
URL: https://github.com/apache/airflow/pull/37330#discussion_r1486344729


##########
airflow/providers/qdrant/__init__.py:
##########
@@ -14,3 +14,29 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+#
+# NOTE! THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE
+# OVERWRITTEN WHEN PREPARING DOCUMENTATION FOR THE PACKAGES.
+#
+# IF YOU WANT TO MODIFY THIS FILE, YOU SHOULD MODIFY THE TEMPLATE
+# `PROVIDER__INIT__PY_TEMPLATE.py.jinja2` IN the 
`dev/breeze/src/airflow_breeze/templates` DIRECTORY
+#
+from __future__ import annotations
+
+import packaging.version
+
+__all__ = ["__version__"]
+
+__version__ = "1.0.0"
+
+try:
+    from airflow import __version__ as airflow_version
+except ImportError:
+    from airflow.version import version as airflow_version
+
+if 
packaging.version.parse(packaging.version.parse(airflow_version).base_version) 
< packaging.version.parse(

Review Comment:
   I guess we talk about different things. 
   
   My point here that we should change source of the truth for the version to 
the `airflow.version` module, and use it from there in providers, hatch builds 
and elsewhere in core.
   
   Keep it for backward compatibility in `airflow.__init__`, e.g. lazy loaded 
from `airflow.version.`.
   
   This might open opportunity to add addition helpers for prevent common 
constructions like
   
   ```python
   packaging.version.parse(packaging.version.parse(airflow_version).base_version
   ```
   
   or
   
   ```python
   Version(Version(airflow_version).base_version)
   ```
   
   And turn it into the 
   
   ```python
   from airflow.version import base_version
   
   ...
   
   if base_version < Version("2.7.0"):
       raise ...
   ```
   
   
   The straightforward implementation would be
   
   ```diff
   diff --git a/airflow/__init__.py b/airflow/__init__.py
   index 4af74a44d2..c2b4c84702 100644
   --- a/airflow/__init__.py
   +++ b/airflow/__init__.py
   @@ -26,10 +26,6 @@ isort:skip_file
    """
    from __future__ import annotations
    
   -__version__ = "2.9.0.dev0"
   -
   -# flake8: noqa: F401
   -
    import os
    import sys
    from typing import Callable
   @@ -82,6 +78,7 @@ __lazy_imports: dict[str, tuple[str, str, bool]] = {
        "Dataset": (".datasets", "Dataset", False),
        "XComArg": (".models.xcom_arg", "XComArg", False),
        "version": (".version", "", False),
   +    "__version__": (".version", "__version__", False),
        # Deprecated lazy imports
        "AirflowException": (".exceptions", "AirflowException", True),
    }
   @@ -138,3 +135,4 @@ if STATICA_HACK:  # pragma: no cover
        from airflow.models.dag import DAG
        from airflow.models.dataset import Dataset
        from airflow.models.xcom_arg import XComArg
   +    from airflow.version import __version__
   diff --git a/airflow/version.py b/airflow/version.py
   index 38fb013244..c3a1064297 100644
   --- a/airflow/version.py
   +++ b/airflow/version.py
   @@ -17,7 +17,20 @@
    # under the License.
    from __future__ import annotations
    
   -# Compat -- somethings access `airflow.version.version` directly
   -from airflow import __version__ as version
   +__all__ = ["version", "__version__"]
    
   -__all__ = ["version"]
   +__version__ = "2.9.0.dev0"
   +version = __version__
   +
   +
   +def __getattr__(name: str):
   +    # PEP-562
   +    if name != "base_version":
   +        raise AttributeError(f"module {__name__!r} has no attribute 
{name!r}")
   +
   +    from packaging.version import Version
   +
   +    val = Version(Version(__version__).base_version)
   +    # Store for next time
   +    globals()[name] = val
   +    return val
   diff --git a/pyproject.toml b/pyproject.toml
   index d45c31e03e..29df73e952 100644
   --- a/pyproject.toml
   +++ b/pyproject.toml
   @@ -1221,7 +1221,7 @@ description = "Environment with Python 3.11. No devel 
installed"
    features = []
    
    [tool.hatch.version]
   -path = "airflow/__init__.py"
   +path = "airflow/version.py"
    
    [tool.hatch.build.targets.wheel.hooks.custom]
    path = "./hatch_build.py"
   ```
   
   ---
   
   For third parties more convenient and safe way would be importlib.
   There is not something new (in general, not about airflow) when a package 
distribution has a different version rather than defined in `__version__`
   
   In case of Airflow it would be even faster
   
   ```console
   ❯ time python -c "from importlib import metadata; version = 
metadata.version('apache-airflow'); print(version)"
   2.9.0.dev0
   python -c   0.06s user 0.03s system 50% cpu 0.175 total
   
   ❯ time python -c "from airflow import __version__ as version; print(version)"
   2.9.0.dev0
   python -c "from airflow import __version__ as version; print(version)"  
0.43s user 0.14s system 63% cpu 0.893 total
   
   ❯ export _AIRFLOW__AS_LIBRARY=1
   ❯ time python -c "from airflow import __version__ as version; print(version)"
   2.9.0.dev0
   python -c "from airflow import __version__ as version; print(version)"  
0.37s user 0.11s system 68% cpu 0.706 total
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to