Skip to content

Commit 61a9dae

Browse files
ref: Remove usage of deprecated distutils version system (#405)
## 📝 Description This pull request removes the dependency on the deprecated `distutils` version parser. ## ✔️ How to Test ``` make testunit ```
1 parent 99de488 commit 61a9dae

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

linodecli/api_request.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44

55
import json
66
import sys
7-
from distutils.version import ( # pylint: disable=deprecated-module
8-
LooseVersion,
9-
StrictVersion,
10-
)
117
from sys import version_info
128
from typing import Optional
139

1410
import requests
11+
from packaging import version
1512

1613

1714
def do_request(
@@ -160,26 +157,24 @@ def _attempt_warn_old_version(ctx, result):
160157

161158
try:
162159
# Parse the spec versions from the API and local CLI.
163-
StrictVersion(spec_version)
164-
StrictVersion(ctx.spec_version)
160+
spec_version_parsed = version.parse(spec_version)
161+
current_version_parsed = version.parse(ctx.spec_version)
165162

166163
# Get only the Major/Minor version of the API Spec and CLI Spec,
167164
# ignore patch version differences
168165
spec_major_minor_version = (
169-
spec_version.split(".")[0] + "." + spec_version.split(".")[1]
166+
f"{spec_version_parsed.major}.{spec_version_parsed.minor}"
170167
)
171168
current_major_minor_version = (
172-
ctx.spec_version.split(".")[0]
173-
+ "."
174-
+ ctx.spec_version.split(".")[1]
169+
f"{current_version_parsed.major}.{current_version_parsed.minor}"
175170
)
176171
except ValueError:
177172
# If versions are non-standard like, "DEVELOPMENT" use them and don't complain.
178173
spec_major_minor_version = spec_version
179174
current_major_minor_version = ctx.spec_version
180175

181176
try:
182-
if LooseVersion(spec_major_minor_version) > LooseVersion(
177+
if version.parse(spec_major_minor_version) > version.parse(
183178
current_major_minor_version
184179
):
185180
api_version_higher = True
@@ -209,7 +204,7 @@ def _attempt_warn_old_version(ctx, result):
209204
pypi_version = pypi_response.json()["info"]["version"]
210205

211206
# no need to be fancy; these should always be valid versions
212-
if LooseVersion(pypi_version) > LooseVersion(ctx.version):
207+
if version.parse(pypi_version) > version.parse(ctx.version):
213208
new_version_exists = True
214209
except:
215210
# I know, but if anything happens here the end user should still

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
terminaltables
22
requests
33
PyYAML
4+
packaging>=23.0

0 commit comments

Comments
 (0)