Skip to content
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

chore(python): Hackishly fix packaging import #15706

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions scripts/python_build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading