From 53a50211dc4336b2467d502d18560031113f27c3 Mon Sep 17 00:00:00 2001 From: Max Marrone Date: Thu, 18 Jul 2024 13:30:07 -0400 Subject: [PATCH] Hack to import packaging again. --- scripts/python_build_utils.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/python_build_utils.py b/scripts/python_build_utils.py index 317775cd2f2..69cf0820717 100644 --- a/scripts/python_build_utils.py +++ b/scripts/python_build_utils.py @@ -51,18 +51,28 @@ def get_version(package, project, extra_tag='', git_dir=None): version = builtin_ver return version -def normalize_version(package, project, extra_tag='', git_dir=None): - # Pipenv requires setuptools >= 36.2.1. Since 36.2.1, setuptools changed - # the way they vendor dependencies, like the packaging module that - # provides the way to normalize version numbers for wheel file names. So - # we try all the possible ways to find it. + +def normalize_version(package, project, extra_tag="", git_dir=None): + # We want packaging.Version. packaging is vendored by setuptools, + # but it's accessible in different ways depending on the setuptools version. + # Try all the possible ways to find it. + # + # todo(mm, 2024-07-18): We should either cut the packaging dependency or + # install packaging explicitly and import it directly. try: - # new way - from setuptools.extern import packaging + # setuptools≄71.0.0 + from setuptools._vendor import packaging except ImportError: - # old way - from pkg_resources.extern import packaging - vers_obj = packaging.version.Version(get_version(package, project, extra_tag, git_dir)) + try: + # setuptools≄36.2.1 + from setuptools.extern import packaging + except ImportError: + # old way + from pkg_resources.extern import packaging + + vers_obj = packaging.version.Version( + get_version(package, project, extra_tag, git_dir) + ) return str(vers_obj) def _latest_tag_for_prefix(prefix, git_dir):