Uh oh!
There was an error while loading. Please reload this page.
Simplify checks for package versions - #37585
Conversation
potiuk
commented
Feb 21, 2024
cc: @Dev-iL |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Dev-iL
commented
Feb 21, 2024
In #37575, @Taragolis used defparse(version: str) ->"Version":
"""Parse the given version string. >>> parse('1.0.dev1') <Version('1.0.dev1')> :param version: The version string to parse. :raises InvalidVersion: When the version string is not a valid version. """returnVersion(version)Perhaps we should agree on a uniform way to import this? |
Build failed due to the patching path not being updated in the sqlalchemy tests - should be changed something like this: def test_is_sqlalchemy_v1(major_version, expected_result):
- with mock.patch("airflow.utils.sqlalchemy._get_lib_major_version") as mock_get_major_version:+ with mock.patch("airflow.utils.sqlalchemy.parse_version") as mock_get_major_version:And also entirely remove |
Uh oh!
There was an error while loading. Please reload this page.
potiuk
commented
Feb 21, 2024
Ah. Nice. I missed those, yes, good idea to fix them there - we had recently a long discussion about using |
potiuk
commented
Feb 21, 2024
Yep. This is why we have CI to tell us so. |
Replaces more complex package version checks with one-liners.
c67a245 to
6687cf3Comparepotiuk
commented
Feb 21, 2024
perhaps. you seem to be good at chasing all of those. Maybe a separate PR proposing such unification. This is best way here to get things done in the way you think things shoudl be done - just doing it. |
potiuk
commented
Feb 21, 2024
Right. Shoudl be nicer. simpler, more consistent and less code everywhere |
Taragolis
commented
Feb 21, 2024
I also think about some caching mechanism, we parse all distributions which installed into the environment: airflow/airflow/utils/entry_points.py Lines 35 to 43 in ca3ce78 Distribution have the information about version also. So maybe it is a good point to have generalised util around from __future__ importannotationsimportsysfromtypingimportNamedTuplefrompackaging.versionimportVersionifsys.version_info>= (3, 10):
fromimportlibimportmetadataelse:
# 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.htmlimportimportlib_metadataasmetadataclassDistVersion(NamedTuple):
distribution_name: strversion: strversion_info: Versionbase_version_tuple: tuple[int, int, int]
@classmethoddeffrom_distribution(cls, dist: metadata.Distribution) ->DistVersion:
vi=Version(dist.version)
returnDistVersion(
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))
ifdist_version.base_version_tuple< (2, ):
raiseRuntimeError("¯\_(ツ)_/¯")That is idea for potential future improvements, not for particular this PR |
potiuk
commented
Feb 21, 2024
Yep. If it can give measurable improvements - THAT could be the reason to introduce a common uitl (just retrieving it is IMHO not enough to extract common code. |
Taragolis
commented
Feb 21, 2024
I guess it is more common in general if compare to one time usage in the Provider Manager.
However it is required more time to introduce common interface for both core and providers, because if it will allow to use into the providers, than we cant change it. |
Yep. Unless/untll we introduce |
Taragolis
commented
Feb 21, 2024
The problem with Presumably good point to future discussion. |
Replaces more complex package version checks with one-liners.
^ 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 newsfragments.