Skip to content

Commit d39192c

Browse files
authored
chore: Remove click from dev.txt (#2893)
1 parent 2ccfc03 commit d39192c

File tree

4 files changed

+34
-92
lines changed

4 files changed

+34
-92
lines changed

integration/helpers/deployer/exceptions/exceptions.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,31 @@
22
Exceptions that are raised by sam deploy
33
This was ported over from the sam-cli repo
44
"""
5-
import click
65

76

8-
class UserException(click.ClickException):
7+
class UserException(Exception):
98
"""
109
Base class for all exceptions that need to be surfaced to the user. Typically, we will display the exception
1110
message to user and return the error code from CLI process
1211
"""
1312

14-
exit_code = 1
15-
16-
def __init__(self, message, wrapped_from=None):
17-
self.wrapped_from = wrapped_from
18-
19-
click.ClickException.__init__(self, message)
13+
def __init__(self, message: str) -> None:
14+
super().__init__(message)
2015

2116

2217
class ChangeEmptyError(UserException):
2318
def __init__(self, stack_name):
24-
self.stack_name = stack_name
2519
message_fmt = "No changes to deploy. Stack {stack_name} is up to date"
26-
super(ChangeEmptyError, self).__init__(message=message_fmt.format(stack_name=self.stack_name))
20+
super().__init__(message=message_fmt.format(stack_name=self.stack_name))
21+
self.stack_name = stack_name
2722

2823

2924
class ChangeSetError(UserException):
3025
def __init__(self, stack_name, msg):
3126
self.stack_name = stack_name
3227
self.msg = msg
3328
message_fmt = "Failed to create changeset for the stack: {stack_name}, {msg}"
34-
super(ChangeSetError, self).__init__(message=message_fmt.format(stack_name=self.stack_name, msg=self.msg))
29+
super().__init__(message=message_fmt.format(stack_name=self.stack_name, msg=self.msg))
3530

3631

3732
class DeployFailedError(UserException):
@@ -41,7 +36,7 @@ def __init__(self, stack_name, msg):
4136

4237
message_fmt = "Failed to create/update the stack: {stack_name}, {msg}"
4338

44-
super(DeployFailedError, self).__init__(message=message_fmt.format(stack_name=self.stack_name, msg=msg))
39+
super().__init__(message=message_fmt.format(stack_name=self.stack_name, msg=msg))
4540

4641

4742
class DeployStackOutPutFailedError(UserException):
@@ -51,9 +46,7 @@ def __init__(self, stack_name, msg):
5146

5247
message_fmt = "Failed to get outputs from stack: {stack_name}, {msg}"
5348

54-
super(DeployStackOutPutFailedError, self).__init__(
55-
message=message_fmt.format(stack_name=self.stack_name, msg=msg)
56-
)
49+
super().__init__(message=message_fmt.format(stack_name=self.stack_name, msg=msg))
5750

5851

5952
class DeployBucketInDifferentRegionError(UserException):
@@ -62,7 +55,7 @@ def __init__(self, msg):
6255

6356
message_fmt = "{msg} : deployment s3 bucket is in a different region, try sam deploy --guided"
6457

65-
super(DeployBucketInDifferentRegionError, self).__init__(message=message_fmt.format(msg=self.msg))
58+
super().__init__(message=message_fmt.format(msg=self.msg))
6659

6760

6861
class ThrottlingError(UserException):
@@ -72,7 +65,7 @@ def __init__(self, stack_name, msg):
7265

7366
message_fmt = "Throttling issue occurred: {stack_name}, {msg}"
7467

75-
super(ThrottlingError, self).__init__(message=message_fmt.format(stack_name=self.stack_name, msg=msg))
68+
super().__init__(message=message_fmt.format(stack_name=self.stack_name, msg=msg))
7669

7770

7871
class S3DoesNotExistException(UserException):
@@ -82,4 +75,4 @@ def __init__(self, bucket_name, msg):
8275

8376
message_fmt = "Companion S3 bucket used for resource upload does not exist: {bucket_name}, {msg}"
8477

85-
super(S3DoesNotExistException, self).__init__(message=message_fmt.format(bucket_name=self.bucket_name, msg=msg))
78+
super().__init__(message=message_fmt.format(bucket_name=self.bucket_name, msg=msg))

integration/helpers/deployer/utils/colors.py

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,28 @@
22
Wrapper to generated colored messages for printing in Terminal
33
This was ported over from the sam-cli repo
44
"""
5+
from typing import Dict
56

6-
import click
7+
from typing_extensions import Literal
78

9+
SupportedColor = Literal["red", "green", "yellow"]
810

9-
class Colored:
10-
"""
11-
Helper class to add ANSI colors and decorations to text. Given a string, ANSI colors are added with special prefix
12-
and suffix characters that are specially interpreted by Terminals to display colors.
11+
COLOR_CODES = {
12+
"red": "\33[31m",
13+
"green": "\33[32m",
14+
"yellow": "\33[33m",
15+
}
16+
CEND = "\033[0m"
1317

14-
Ex: "message" -> add red color -> \x1b[31mmessage\x1b[0m
1518

16-
This class serves two purposes:
17-
- Hide the underlying library used to provide colors: In this case, we use ``click`` library which is usually
18-
used to build a CLI interface. We use ``click`` just to minimize the number of dependencies we add to this
19-
project. This class allows us to replace click with any other color library like ``pygments`` without
20-
changing callers.
21-
22-
- Transparently turn off colors: In cases when the string is not written to Terminal (ex: log file) the ANSI
23-
color codes should not be written. This class supports the scenario by allowing you to turn off colors.
24-
Calls to methods like `red()` will simply return the input string.
25-
"""
26-
27-
def __init__(self, colorize=True):
28-
"""
29-
Initialize the object
30-
31-
Parameters
32-
----------
33-
colorize : bool
34-
Optional. Set this to True to turn on coloring. False will turn off coloring
35-
"""
36-
self.colorize = colorize
37-
38-
def red(self, msg):
39-
"""Color the input red"""
40-
return self._color(msg, "red")
41-
42-
def green(self, msg):
43-
"""Color the input green"""
44-
return self._color(msg, "green")
45-
46-
def cyan(self, msg):
47-
"""Color the input cyan"""
48-
return self._color(msg, "cyan")
49-
50-
def white(self, msg):
51-
"""Color the input white"""
52-
return self._color(msg, "white")
53-
54-
def yellow(self, msg):
55-
"""Color the input yellow"""
56-
return self._color(msg, "yellow")
57-
58-
def underline(self, msg):
59-
"""Underline the input"""
60-
return click.style(msg, underline=True) if self.colorize else msg
61-
62-
def _color(self, msg, color):
63-
"""Internal helper method to add colors to input"""
64-
kwargs = {"fg": color}
65-
return click.style(msg, **kwargs) if self.colorize else msg
19+
def cprint(text: str, color: SupportedColor) -> None:
20+
print(COLOR_CODES[color] + text + CEND)
6621

6722

6823
class DeployColor:
6924
def __init__(self):
70-
self._color = Colored()
71-
self.changeset_color_map = {"Add": "green", "Modify": "yellow", "Remove": "red"}
72-
self.status_color_map = {
25+
self.changeset_color_map: Dict[str, SupportedColor] = {"Add": "green", "Modify": "yellow", "Remove": "red"}
26+
self.status_color_map: Dict[str, SupportedColor] = {
7327
"CREATE_COMPLETE": "green",
7428
"CREATE_FAILED": "red",
7529
"CREATE_IN_PROGRESS": "yellow",

integration/helpers/deployer/utils/table_print.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
"""
2-
Utilities for table pretty printing using click
2+
Utilities for table pretty printing
33
This was ported over from the sam-cli repo
44
"""
55
import shutil
6-
from itertools import count
6+
from itertools import count, zip_longest
77

8-
try:
9-
from itertools import zip_longest
10-
except ImportError: # py2
11-
from itertools import izip_longest as zip_longest
128
import textwrap
139
from functools import wraps
1410

15-
import click
11+
from integration.helpers.deployer.utils.colors import cprint
1612

1713
MIN_OFFSET = 20
1814

@@ -83,18 +79,18 @@ def pprint_wrap(func):
8379
def wrap(*args, **kwargs):
8480
# The table is setup with the column names, format_string contains the column names.
8581
if table_header:
86-
click.secho("\n" + table_header)
87-
click.secho("-" * usable_width, fg=color)
88-
click.secho(format_string.format(*format_args, **format_kwargs), fg=color)
89-
click.secho("-" * usable_width, fg=color)
82+
print("\n" + table_header)
83+
cprint("-" * usable_width, color)
84+
cprint(format_string.format(*format_args, **format_kwargs), color)
85+
cprint("-" * usable_width, color)
9086
# format_args which have the minimumwidth set per {} in the format_string is passed to the function
9187
# which this decorator wraps, so that the function has access to the correct format_args
9288
kwargs["format_args"] = format_args
9389
kwargs["width"] = width_per_column
9490
kwargs["margin"] = margin if margin else min_margin
9591
result = func(*args, **kwargs)
9692
# Complete the table
97-
click.secho("-" * usable_width, fg=color)
93+
cprint("-" * usable_width, color)
9894
return result
9995

10096
return wrap
@@ -151,7 +147,7 @@ def pprint_columns(columns, width, margin, format_string, format_args, columns_d
151147
for k, _ in columns_dict.items():
152148
columns_dict[k] = columns_text[next(counter)]
153149

154-
click.secho(format_string.format(*format_args, **columns_dict), fg=color)
150+
cprint(format_string.format(*format_args, **columns_dict), color)
155151

156152

157153
def newline_per_item(iterable, counter):
@@ -166,4 +162,4 @@ def newline_per_item(iterable, counter):
166162
Current index within the iterable
167163
"""
168164
if counter < len(iterable) - 1:
169-
click.echo(message="", nl=True)
165+
print("")

requirements/dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pytest~=6.2.5
1111
parameterized~=0.7.4
1212

1313
# Integration tests
14-
click~=8.0
1514
dateparser~=0.7
1615
boto3>=1.23,<2
1716
tenacity~=7.0.0

0 commit comments

Comments
 (0)