From 8b2f2c58b964d3a1810bcba95692f863014e83d8 Mon Sep 17 00:00:00 2001 From: Graham Pugh Date: Tue, 8 Mar 2022 15:11:59 +0100 Subject: [PATCH] Allow for removal of distutils in a future python --- installinstallmacos.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index 75eb38d..ece9ed4 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -42,14 +42,18 @@ except ImportError: from urlparse import urlsplit from xml.dom import minidom from xml.parsers.expat import ExpatError -from distutils.version import LooseVersion + +try: + from packaging.version import Version +except ImportError: + from distutils.version import LooseVersion as Version try: import xattr except ImportError: print( - "This tool requires the Python xattr module. " - "Perhaps run `pip install xattr` to install it." + "This tool requires the Python xattr and packaging modules. " + "Perhaps run `pip install xattr packaging` to install them." ) sys.exit(-1) @@ -698,7 +702,7 @@ def os_installer_product_info( def get_latest_version(current_item, latest_item): """Compares versions between two values and returns the latest (highest) value""" try: - if LooseVersion(current_item) > LooseVersion(latest_item): + if Version(current_item) > Version(latest_item): return current_item else: return latest_item