Skip to content

Commit

Permalink
Remove dependence on distutils.
Browse files Browse the repository at this point in the history
As of Python 3.12, distutils is removed.
  • Loading branch information
dstein64 committed Oct 7, 2023
1 parent dd272e4 commit 7079656
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vimgolf/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.5.1
33 changes: 30 additions & 3 deletions vimgolf/vimgolf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import concurrent.futures
import contextlib
import datetime
from distutils.version import StrictVersion
from enum import Enum
import filecmp
import glob
Expand Down Expand Up @@ -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
# ************************************************************
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 7079656

Please sign in to comment.