Skip to content

Commit 77ee98d

Browse files
committed
Remove dependency on colorclass
Closes #231 The colorclass module is not compatible with Python 3.10, and is currently [archived on github](https://github.com/Robpol86/colorclass) with issues open about future compatibility issues and no real suggestion of movement. This change replaces `colorclass` with the few color codes that were actually used so far, which removes the dependency entirely and should allow the CLI to work on python 3.10. This appears to work where I've tested it, and from what I read it aught to work the same on Windows too, but I'd like someone to give it a spin first to be sure.
1 parent 775b5e3 commit 77ee98d

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ added to Linode's OpenAPI spec:
389389
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+
390390
|x-linode-cli-action | method | The action name for operations under this path. If not present, operationId is used. |
391391
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+
392-
|x-linode-cli-color   | property | If present, defines key-value pairs of property value: color. Colors must be understood |
393-
|                     |         | by colorclass.Color. Must include a default.                         |
392+
|x-linode-cli-color   | property | If present, defines key-value pairs of property value: color. Colors must be one of |
393+
|                     |         | "red", "green", "yellow", "white", and "black". Must include a default. |
394394
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+
395395
|x-linode-cli-command | path | The command name for operations under this path. If not present, "default" is used. |
396396
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+

linodecli/response.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@
44
"""
55
from __future__ import print_function
66

7-
from colorclass import Color
7+
8+
CLEAR_COLOR = "\x1b[0m"
9+
COLOR_CODE_MAP = {
10+
"red": "\x1b[31m",
11+
"green": "\x1b[32m",
12+
"yellow": "\x1b[33m",
13+
"black": "\x1b[30m",
14+
"white": "\x1b[40m",
15+
}
16+
17+
18+
def colorize_string(string, color):
19+
col = COLOR_CODE_MAP.get(color, CLEAR_COLOR)
20+
21+
return "{}{}{}".format(
22+
col, string, CLEAR_COLOR,
23+
)
824

925

1026
class ModelAttr:
@@ -51,7 +67,7 @@ def render_value(self, model, colorize=True):
5167
# apply colors
5268
value = str(value) # just in case
5369
color = self.color_map.get(value) or self.color_map['default_']
54-
value = str(Color('{'+color+'}'+value+'{/'+color+'}'))
70+
value = colorize_string(value, color)
5571

5672
if value is None:
5773
# don't print the word "None"

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
terminaltables
2-
colorclass
32
requests
43
PyYAML
54
enum34; python_version < '3.4'

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def get_version():
4949
license="BSD 3-Clause License",
5050
install_requires=[
5151
"terminaltables",
52-
"colorclass",
5352
"requests",
5453
"PyYAML",
5554
"future; python_version <= '3.0.0'"

0 commit comments

Comments
 (0)