From b34dad4f7e8c7e466cdfc5c9e1436ac98caf8be4 Mon Sep 17 00:00:00 2001 From: Kenji Brameld Date: Thu, 9 Mar 2023 18:35:51 -0600 Subject: [PATCH] Replace pkg_resources.parse_version with packaging.version.parse (#693) * replace parse_version with packaging.version.parse Signed-off-by: ijnek * lstrip upstream/ Signed-off-by: ijnek * prevent conflict of "version" word Signed-off-by: ijnek * use regex to get version number Signed-off-by: ijnek * Update bloom/logging.py Co-authored-by: Jochen Sprickerhof * import version.parse as parse_version Signed-off-by: ijnek * change to use parse_version instead of version.parse, because "version" is used as variables everywhere Signed-off-by: ijnek --------- Signed-off-by: ijnek Co-authored-by: Jochen Sprickerhof --- .github/workflows/ci.yaml | 2 +- bloom/commands/git/import_upstream.py | 2 +- bloom/commands/release.py | 2 -- bloom/commands/update.py | 2 +- bloom/generators/debian/generator.py | 2 +- bloom/generators/release.py | 2 +- bloom/git.py | 7 ++++--- bloom/logging.py | 17 ++++++----------- bloom/rosdistro_api.py | 2 +- setup.py | 1 + 10 files changed, 17 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3c13a4b6..8ef2e688 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip setuptools - python -m pip install PyYAML argparse empy rosdep vcstools catkin-pkg python-dateutil + python -m pip install PyYAML argparse empy rosdep vcstools catkin-pkg python-dateutil packaging python -m pip install nose coverage pep8 - name: Run tests run: | diff --git a/bloom/commands/git/import_upstream.py b/bloom/commands/git/import_upstream.py index 74bbbbfd..3a2d79b9 100755 --- a/bloom/commands/git/import_upstream.py +++ b/bloom/commands/git/import_upstream.py @@ -39,7 +39,7 @@ import tarfile import tempfile -from pkg_resources import parse_version +from packaging.version import parse as parse_version try: from urlparse import urlparse diff --git a/bloom/commands/release.py b/bloom/commands/release.py index dc68d50e..35837e00 100644 --- a/bloom/commands/release.py +++ b/bloom/commands/release.py @@ -49,8 +49,6 @@ import webbrowser import yaml -from pkg_resources import parse_version - # python2/3 compatibility try: from urllib.error import HTTPError, URLError diff --git a/bloom/commands/update.py b/bloom/commands/update.py index 63486f08..692c849c 100644 --- a/bloom/commands/update.py +++ b/bloom/commands/update.py @@ -51,7 +51,7 @@ from bloom.util import add_global_arguments from bloom.util import handle_global_arguments -from pkg_resources import parse_version +from packaging.version import parse as parse_version from threading import Lock _updater_running = False diff --git a/bloom/generators/debian/generator.py b/bloom/generators/debian/generator.py index 6e1a9af3..fe629c8d 100644 --- a/bloom/generators/debian/generator.py +++ b/bloom/generators/debian/generator.py @@ -49,7 +49,7 @@ except ImportError: from ConfigParser import SafeConfigParser from dateutil import tz -from pkg_resources import parse_version +from packaging.version import parse as parse_version from bloom.generators import BloomGenerator from bloom.generators import GeneratorError diff --git a/bloom/generators/release.py b/bloom/generators/release.py index 067edfcb..5eeb4a34 100755 --- a/bloom/generators/release.py +++ b/bloom/generators/release.py @@ -53,7 +53,7 @@ try: import catkin_pkg - from pkg_resources import parse_version + from packaging.version import parse as parse_version if parse_version(catkin_pkg.__version__) < parse_version('0.3.8'): warning("This version of bloom requires catkin_pkg version >= '0.3.8'," " the used version of catkin_pkg is '{0}'".format(catkin_pkg.__version__)) diff --git a/bloom/git.py b/bloom/git.py index e22e48a8..6a0ea58f 100755 --- a/bloom/git.py +++ b/bloom/git.py @@ -36,6 +36,7 @@ import os import functools +import re import shutil import subprocess import tempfile @@ -43,8 +44,6 @@ from subprocess import PIPE from subprocess import CalledProcessError -from pkg_resources import parse_version - from bloom.logging import debug from bloom.logging import error from bloom.logging import fmt @@ -686,7 +685,9 @@ def get_last_tag_by_version(directory=None): versions = [] for line in output.splitlines(): tags.append(line.strip()) - versions.append(parse_version(line.strip())) + ver = re.match(r"[0-9]+\.[0-9]+\.[0-9]+", line) + if ver: + versions.append(ver) return tags[versions.index(max(versions))] if versions else '' diff --git a/bloom/logging.py b/bloom/logging.py index efc9931b..c38c828d 100755 --- a/bloom/logging.py +++ b/bloom/logging.py @@ -39,11 +39,6 @@ import datetime import os from platform import mac_ver -try: - from pkg_resources import parse_version -except OSError: - os.chdir(os.path.expanduser('~')) - from pkg_resources import parse_version import re import string import sys @@ -60,7 +55,7 @@ _emoji_check_mark = "✅ " _emoji_cross_mark = "❌ " -_is_mac_lion_or_greater = parse_version(mac_ver()[0]) >= parse_version('10.7.0') +_is_mac = (mac_ver()[0] != '') def ansi(key): @@ -127,17 +122,17 @@ def disable_ANSI_colors(): _ansi[key] = '' -def is_mac_lion_or_greater(): - global _is_mac_lion_or_greater - return _is_mac_lion_or_greater +def _is_mac(): + global _is_mac + return _is_mac def get_success_prefix(): - return _emoji_check_mark if _is_mac_lion_or_greater else "@{gf}<== @|" + return _emoji_check_mark if _is_mac else "@{gf}<== @|" def get_error_prefix(): - return _emoji_cross_mark if _is_mac_lion_or_greater else "@{rf}@!<== @|" + return _emoji_cross_mark if _is_mac else "@{rf}@!<== @|" # Default to ansi colors on diff --git a/bloom/rosdistro_api.py b/bloom/rosdistro_api.py index 72e03e15..b951952c 100644 --- a/bloom/rosdistro_api.py +++ b/bloom/rosdistro_api.py @@ -38,7 +38,7 @@ import sys import traceback -from pkg_resources import parse_version +from packaging.version import parse as parse_version # python2/3 compatibility try: diff --git a/setup.py b/setup.py index 159b9645..8729e72f 100755 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ 'catkin_pkg >= 0.4.3', 'setuptools', 'empy', + 'packaging', 'python-dateutil', 'PyYAML', 'rosdep >= 0.15.0',