Taragolis commented on PR #37585: URL: https://github.com/apache/airflow/pull/37585#issuecomment-1956794928
I also think about some caching mechanism, we parse all distributions which installed into the environment: https://github.com/apache/airflow/blob/ca3ce78fbaa4a04c061116acf2c86a311fdab30d/airflow/utils/entry_points.py#L35-L43 Distribution have the information about version also. So maybe it is a good point to have generalised util around `importlib.metadata` and `packaging` for retrieve and parse this information in reusable format, e.g. ```python from __future__ import annotations import sys from typing import NamedTuple from packaging.version import Version if sys.version_info >= (3, 10): from importlib import metadata else: # The “selectable” entry points were introduced in importlib_metadata 3.6 and Python 3.10. # Prior to those changes, entry_points accepted no parameters and always returned a dictionary of entry points, # keyed by group. With importlib_metadata 5.0 and Python 3.12, entry_points always returns an EntryPoints object. # See backports.entry_points_selectable for compatibility options. # source: https://docs.python.org/3/library/importlib.metadata.html import importlib_metadata as metadata class DistVersion(NamedTuple): distribution_name: str version: str version_info: Version base_version_tuple: tuple[int, int, int] @classmethod def from_distribution(cls, dist: metadata.Distribution) -> DistVersion: vi = Version(dist.version) return DistVersion( distribution_name=dist.name, version=dist.version, version_info=vi, base_version_tuple=(vi.major, vi.minor, vi.micro) ) airflow_dist = metadata.distribution("apache-airflow") dist_version = DistVersion.from_distribution(airflow_dist) print(dist_version) print(dist_version.base_version_tuple >= (2, 8)) print(dist_version.base_version_tuple >= (2, 9)) if dist_version.base_version_tuple < (2, ): raise RuntimeError("¯\_(ツ)_/¯") ``` That is idea for potential future improvements, not for particular this PR -- 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]
