From 7079656f8ae65ce612b4b96d59a67d5f87f8946a Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 6 Oct 2023 21:13:06 -0400 Subject: [PATCH] Remove dependence on distutils. As of Python 3.12, distutils is removed. --- vimgolf/version.txt | 2 +- vimgolf/vimgolf.py | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/vimgolf/version.txt b/vimgolf/version.txt index 8f0916f..4b9fcbe 100644 --- a/vimgolf/version.txt +++ b/vimgolf/version.txt @@ -1 +1 @@ -0.5.0 +0.5.1 diff --git a/vimgolf/vimgolf.py b/vimgolf/vimgolf.py index 10cebf2..d1396af 100644 --- a/vimgolf/vimgolf.py +++ b/vimgolf/vimgolf.py @@ -2,7 +2,6 @@ import concurrent.futures import contextlib import datetime -from distutils.version import StrictVersion from enum import Enum import filecmp import glob @@ -297,6 +296,34 @@ def working_directory(directory): os.chdir(existing) +class Version: + """A class for version comparisons.""" + + def __init__(self, str): + version = re.sub(r'(\.0+)*$', '', str) # remove trailing '.0+' occurrences + version = version.split('.') # split + version = [int(x) for x in version] # convert strings to ints + self._version = version + + def __lt__(self, other): + return self._version < other._version + + def __le__(self, other): + return self._version <= other._version + + def __eq__(self, other): + return self._version == other._version + + def __ne__(self, other): + return self._version != other._version + + def __gt__(self, other): + return self._version > other._version + + def __ge__(self, other): + return self._version >= other._version + + # ************************************************************ # * Core # ************************************************************ @@ -647,8 +674,8 @@ def put(challenge_id, init_keys=''): write('Uploading to vimgolf.com is disabled', stream=sys.stderr, color='red') write('vimgolf may not function properly', color='red') try: - client_compliance_version = StrictVersion(RUBY_CLIENT_VERSION_COMPLIANCE) - api_version = StrictVersion(challenge_spec['client']) + client_compliance_version = Version(RUBY_CLIENT_VERSION_COMPLIANCE) + api_version = Version(challenge_spec['client']) action = 'upgrade' if api_version > client_compliance_version else 'downgrade' except Exception: action = 'update'