From 229a1690bbfe554e84e63bff9e7e3ce3bef1126f Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Mon, 24 Jul 2017 17:14:58 -0700 Subject: [PATCH] Prevent deprecation error messages from pkg_resources Currently pkg_resources is creating this warning message: RuntimeWarning: You have iterated over the result of pkg_resources.parse_version. This is a legacy behavior which is inconsistent with the new version class introduced in setuptools 8.0. In most cases, conversion to a tuple is unnecessary. For comparison of versions, sort the Version instances directly. If you have another use case requiring the tuple, please file a bug with the setuptools project describing that need. Get the major_version directly from the version string passed in instead so that the warning message is not raised. Closes-Bug: #1706394 Change-Id: I663ed579c27e48a34fdd9565037110a43e5b5587 (cherry picked from commit 47b22208eaa6be2c0352514a66926dd2baeaa025) --- oslo_utils/versionutils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/oslo_utils/versionutils.py b/oslo_utils/versionutils.py index 09953ac8..311965d2 100644 --- a/oslo_utils/versionutils.py +++ b/oslo_utils/versionutils.py @@ -42,8 +42,12 @@ def is_compatible(requested_version, current_version, same_major=True): requested_parts = pkg_resources.parse_version(requested_version) current_parts = pkg_resources.parse_version(current_version) - if same_major and (requested_parts[0] != current_parts[0]): - return False + if same_major: + # NOTE(jlvillal) pkg_resources issues a warning if we try to access + # portions of the version, for example requested_parts[0] will issue a + # warning message. So get the major_version from the string instead. + if requested_version.split('.')[0] != current_version.split('.')[0]: + return False return current_parts >= requested_parts