Skip to content

Commit

Permalink
Hack to import packaging again.
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring committed Jul 18, 2024
1 parent 67097d7 commit 53a5021
Showing 1 changed file with 20 additions and 10 deletions.
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

0 comments on commit 53a5021

Please sign in to comment.