Skip to content

Commit 03117ae

Browse files
authored
Remove click (#1262)
1 parent 59bb219 commit 03117ae

File tree

3 files changed

+0
-86
lines changed

3 files changed

+0
-86
lines changed

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"numpy>=1.17.0,<2.0",
5555
"requests>=2.0.0",
5656
"tqdm>=4.0.0",
57-
"click>=7.1.2,!=8.0.0", # 8.0.0 blocked due to reported bug
5857
"torch>=1.7.0",
5958
"transformers>4.0,<5.0",
6059
"datasets",

src/llmcompressor/utils/helpers.py

-79
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Common functions for interfacing with python primitives and directories/files.
44
"""
55

6-
import ast
76
import contextlib
87
import errno
98
import fnmatch
@@ -59,7 +58,6 @@
5958
"tensors_export",
6059
"json_to_jsonl",
6160
"deprecation_warning",
62-
"parse_kwarg_tuples",
6361
"is_package_available",
6462
"import_from_path",
6563
"getattr_chain",
@@ -882,83 +880,6 @@ def deprecation_warning(message: str):
882880
)
883881

884882

885-
def parse_kwarg_tuples(kwargs: tuple) -> Dict:
886-
"""
887-
Convert a tuple of kwargs to a dict of kwargs.
888-
This function is used to enable the click parsing of kwargs.
889-
890-
Example use:
891-
```
892-
@click.command(
893-
context_settings=dict(
894-
ignore_unknown_options=True)
895-
)
896-
@click.argument(...)
897-
@click.option(...)
898-
...
899-
@click.argument("kwargs", nargs=-1, type=click.UNPROCESSED)
900-
def main(..., kwargs):
901-
...
902-
kwargs: Dict[str, Any] = parse_kwarg_tuples(kwargs: Tuple)
903-
```
904-
905-
Example inputs, outputs:
906-
```
907-
input = ('--arg1', 1, 'arg2', 2, '-arg3', 3)
908-
output = parse_kwarg_tuples(input)
909-
output = {'arg1': 1, 'arg2': 2, 'arg3': 3}
910-
```
911-
912-
```
913-
input = ('--arg1', 1, '--args1', 2 , 'arg2', 2, '-arg3', 3)
914-
output = parse_kwarg_tuples(input)
915-
output = {'arg1': [1, 2], 'arg2': 2, 'arg3': 3}
916-
```
917-
918-
:param kwargs: The kwargs to convert. Should be a tuple of alternating
919-
kwargs names and kwargs values e.g.('--arg1', 1, 'arg2', 2, -arg3', 3).
920-
The names can optionally have a '-' or `--` in front of them.
921-
:return: The converted kwargs as a dict.
922-
"""
923-
if len(kwargs) == 0:
924-
return {}
925-
if len(kwargs) % 2 != 0:
926-
raise ValueError(
927-
"kwargs must be a tuple of alternating names and values "
928-
"i.e. the length of kwargs tuple must be even. Received "
929-
f"kwargs: {kwargs}"
930-
)
931-
# names are uneven indices, values are even indices
932-
kwargs_names = kwargs[0::2]
933-
kwargs_values = kwargs[1::2]
934-
# by default kwargs values are strings, so convert them
935-
# to the appropriate type if possible
936-
kwargs_values = list(kwargs_values)
937-
for i, value in enumerate(kwargs_values):
938-
try:
939-
kwargs_values[i] = ast.literal_eval(value)
940-
except Exception as e: # noqa E841
941-
logger.debug(
942-
f"Failed to infer non-string type"
943-
f"from kwarg value: {value}. It will"
944-
f"be left as a string."
945-
)
946-
pass
947-
# remove any '-' or '--' from the names
948-
kwargs_names = [name.lstrip("-") for name in kwargs_names]
949-
processed_kwargs = {}
950-
for kwarg_name, kwarg_value in zip(kwargs_names, kwargs_values):
951-
if kwarg_name in processed_kwargs:
952-
# if the kwarg name is already in the processed kwargs,
953-
# then we should convert the value to a list
954-
if not isinstance(processed_kwargs[kwarg_name], list):
955-
processed_kwargs[kwarg_name] = [processed_kwargs[kwarg_name]]
956-
processed_kwargs[kwarg_name].append(kwarg_value)
957-
else:
958-
processed_kwargs[kwarg_name] = kwarg_value
959-
return processed_kwargs
960-
961-
962883
def is_package_available(
963884
package_name: str,
964885
return_version: bool = False,

tests/llmcompressor/utils/test_helpers.py

-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
flatten_iterable,
1212
getattr_chain,
1313
interpolate,
14-
parse_kwarg_tuples,
1514
validate_str_iterable,
1615
)
1716

@@ -93,11 +92,6 @@ def test_interpolate(x_cur, x0, x1, y0, y1, inter_func, out):
9392
assert abs(out - interpolated) < 0.01
9493

9594

96-
def test_pass_kwargs_tuples():
97-
kwargs = parse_kwarg_tuples(("--input_1", 1, "--input_2", "two", "--input_3", "2"))
98-
assert kwargs == dict(input_1=1, input_2="two", input_3=2)
99-
100-
10195
def test_getattr_chain():
10296
base = SimpleNamespace()
10397
base.a = None

0 commit comments

Comments
 (0)