Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

Commit 52863a1

Browse files
committed
Re-run black
This fixes all the docstrings - neat
1 parent f8f87f1 commit 52863a1

3 files changed

Lines changed: 43 additions & 49 deletions

File tree

cli_ui/__init__.py

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def setup(
5454
title: str = "auto",
5555
timestamp: bool = False,
5656
) -> None:
57-
""" Configure behavior of message functions.
57+
"""Configure behavior of message functions.
5858
5959
:param verbose: Whether :func:`debug` messages should get printed
6060
:param quiet: Hide every message except :func:`warning`, :func:`error`, and
@@ -73,7 +73,7 @@ def _setup(**kwargs: ConfigValue) -> None:
7373

7474

7575
class Color:
76-
"""Represent an ANSI escape sequence """
76+
"""Represent an ANSI escape sequence"""
7777

7878
def __init__(self, name: str, code: str):
7979
self.name = name
@@ -120,7 +120,7 @@ def __repr__(self) -> str:
120120

121121
# Other nice-to-have characters:
122122
class UnicodeSequence:
123-
""" Represent a sequence containing a color followed by a Unicode symbol """
123+
"""Represent a sequence containing a color followed by a Unicode symbol"""
124124

125125
def __init__(self, color: Color, as_unicode: str, as_ascii: str):
126126
if os.name == "nt":
@@ -176,7 +176,7 @@ def write_title_string(mystr: str, fileobj: FileObj) -> None:
176176
def process_tokens(
177177
tokens: Sequence[Token], *, end: str = "\n", sep: str = " "
178178
) -> Tuple[str, str]:
179-
""" Returns two strings from a list of tokens.
179+
"""Returns two strings from a list of tokens.
180180
One containing ASCII escape codes, the other
181181
only the 'normal' characters
182182
@@ -238,9 +238,7 @@ def message(
238238
fileobj: FileObj = sys.stdout,
239239
update_title: bool = False,
240240
) -> None:
241-
""" Helper method for error, warning, info, debug
242-
243-
"""
241+
"""Helper method for error, warning, info, debug"""
244242
should_use_colors = colors_enabled(fileobj)
245243
with_color, without_color = process_tokens(tokens, end=end, sep=sep)
246244
if CONFIG["record"]:
@@ -252,27 +250,27 @@ def message(
252250

253251

254252
def fatal(*tokens: Token, **kwargs: Any) -> None:
255-
""" Print an error message and call ``sys.exit`` """
253+
"""Print an error message and call ``sys.exit``"""
256254
error(*tokens, **kwargs)
257255
sys.exit(1)
258256

259257

260258
def error(*tokens: Token, **kwargs: Any) -> None:
261-
""" Print an error message """
259+
"""Print an error message"""
262260
tokens = [bold, red, "Error:"] + list(tokens) # type: ignore
263261
kwargs["fileobj"] = sys.stderr
264262
message(*tokens, **kwargs)
265263

266264

267265
def warning(*tokens: Token, **kwargs: Any) -> None:
268-
""" Print a warning message """
266+
"""Print a warning message"""
269267
tokens = [brown, "Warning:"] + list(tokens) # type: ignore
270268
kwargs["fileobj"] = sys.stderr
271269
message(*tokens, **kwargs)
272270

273271

274272
def info(*tokens: Token, **kwargs: Any) -> None:
275-
r""" Print an informative message
273+
r"""Print an informative message
276274
277275
:param tokens: list of `ui` constants or strings, like ``(cli_ui.red, 'this is an error')``
278276
:param sep: separator, defaults to ``' '``
@@ -286,7 +284,7 @@ def info(*tokens: Token, **kwargs: Any) -> None:
286284

287285

288286
def info_section(*tokens: Token, **kwargs: Any) -> None:
289-
""" Print an underlined section name """
287+
"""Print an underlined section name"""
290288
# We need to know the length of the section:
291289
process_tokens_kwargs = kwargs.copy()
292290
process_tokens_kwargs["color"] = False
@@ -296,22 +294,22 @@ def info_section(*tokens: Token, **kwargs: Any) -> None:
296294

297295

298296
def info_1(*tokens: Token, **kwargs: Any) -> None:
299-
""" Print an important informative message """
297+
"""Print an important informative message"""
300298
info(bold, blue, "::", reset, *tokens, **kwargs)
301299

302300

303301
def info_2(*tokens: Token, **kwargs: Any) -> None:
304-
""" Print an not so important informative message """
302+
"""Print an not so important informative message"""
305303
info(bold, blue, "=>", reset, *tokens, **kwargs)
306304

307305

308306
def info_3(*tokens: Token, **kwargs: Any) -> None:
309-
""" Print an even less important informative message """
307+
"""Print an even less important informative message"""
310308
info(bold, blue, "*", reset, *tokens, **kwargs)
311309

312310

313311
def dot(*, last: bool = False, fileobj: FileObj = sys.stdout) -> None:
314-
""" Print a dot without a newline unless it is the last one.
312+
"""Print a dot without a newline unless it is the last one.
315313
316314
Useful when you want to display a progress with very little
317315
knowledge.
@@ -323,7 +321,7 @@ def dot(*, last: bool = False, fileobj: FileObj = sys.stdout) -> None:
323321

324322

325323
def info_count(i: int, n: int, *rest: Token, **kwargs: Any) -> None:
326-
""" Display a counter before the rest of the message.
324+
"""Display a counter before the rest of the message.
327325
328326
``rest`` and ``kwargs`` are passed to :func:`info`
329327
@@ -339,7 +337,7 @@ def info_count(i: int, n: int, *rest: Token, **kwargs: Any) -> None:
339337

340338

341339
def info_progress(prefix: str, value: float, max_value: float) -> None:
342-
""" Display info progress in percent.
340+
"""Display info progress in percent.
343341
344342
:param value: the current value
345343
:param max_value: the max value
@@ -354,7 +352,7 @@ def info_progress(prefix: str, value: float, max_value: float) -> None:
354352

355353

356354
def debug(*tokens: Token, **kwargs: Any) -> None:
357-
""" Print a debug message.
355+
"""Print a debug message.
358356
359357
Messages are shown only when ``CONFIG["verbose"]`` is true
360358
"""
@@ -375,9 +373,7 @@ def indent(text: str, num: int = 2) -> str:
375373

376374

377375
def tabs(num: int) -> str:
378-
""" Compute a blank tab
379-
380-
"""
376+
"""Compute a blank tab"""
381377
return " " * num
382378

383379

@@ -420,7 +416,7 @@ def info_table(
420416

421417

422418
def message_for_exception(exception: Exception, message: str) -> Sequence[Token]:
423-
""" Returns a tuple suitable for cli_ui.error()
419+
"""Returns a tuple suitable for cli_ui.error()
424420
from the given exception.
425421
(Traceback will be part of the message, after
426422
the ``message`` argument)
@@ -443,17 +439,13 @@ def message_for_exception(exception: Exception, message: str) -> Sequence[Token]
443439

444440

445441
def read_input() -> str:
446-
""" Read input from the user
447-
448-
"""
442+
"""Read input from the user"""
449443
info(green, "> ", end="")
450444
return input()
451445

452446

453447
def read_password() -> str:
454-
""" Read a password from the user
455-
456-
"""
448+
"""Read a password from the user"""
457449
info(green, "> ", end="")
458450
return getpass.getpass(prompt="")
459451

@@ -463,8 +455,7 @@ def get_ask_tokens(tokens: Sequence[Token]) -> List[Token]:
463455

464456

465457
def ask_string(*question: Token, default: Optional[str] = None) -> Optional[str]:
466-
"""Ask the user to enter a string.
467-
"""
458+
"""Ask the user to enter a string."""
468459
tokens = get_ask_tokens(question)
469460
if default:
470461
tokens.append("(%s)" % default)
@@ -476,8 +467,7 @@ def ask_string(*question: Token, default: Optional[str] = None) -> Optional[str]
476467

477468

478469
def ask_password(*question: Token) -> str:
479-
"""Ask the user to enter a password.
480-
"""
470+
"""Ask the user to enter a password."""
481471
tokens = get_ask_tokens(question)
482472
info(*tokens)
483473
answer = read_password()
@@ -563,9 +553,7 @@ def ask_yes_no(*question: Token, default: bool = False) -> bool:
563553

564554

565555
class Timer:
566-
""" Display time taken when executing a list of statements.
567-
568-
"""
556+
"""Display time taken when executing a list of statements."""
569557

570558
def __init__(self, description: str):
571559
self.description = description
@@ -591,11 +579,11 @@ def __exit__(self, *unused: Any) -> None:
591579
self.stop()
592580

593581
def start(self) -> None:
594-
""" Start the timer """
582+
"""Start the timer"""
595583
self.start_time = datetime.datetime.now()
596584

597585
def stop(self) -> None:
598-
""" Stop the timer and emit a nice log """
586+
"""Stop the timer and emit a nice log"""
599587
end_time = datetime.datetime.now()
600588
elapsed_time = end_time - self.start_time
601589
elapsed_seconds = elapsed_time.seconds
@@ -611,7 +599,7 @@ def stop(self) -> None:
611599

612600

613601
def did_you_mean(message: str, user_input: str, choices: Sequence[str]) -> str:
614-
""" Given a list of choices and an invalid user input, display the closest
602+
"""Given a list of choices and an invalid user input, display the closest
615603
items in the list that match the input.
616604
617605
"""

cli_ui/tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@
77

88

99
class MessageRecorder:
10-
""" Helper class to tests emitted messages """
10+
"""Helper class to tests emitted messages"""
1111

1212
def __init__(self) -> None:
1313
cli_ui._MESSAGES = list()
1414

1515
def start(self) -> None:
16-
""" Start recording messages """
16+
"""Start recording messages"""
1717
cli_ui.CONFIG["record"] = True
1818

1919
def stop(self) -> None:
20-
""" Stop recording messages """
20+
"""Stop recording messages"""
2121
cli_ui.CONFIG["record"] = False
2222
cli_ui._MESSAGES = list()
2323

2424
def reset(self) -> None:
25-
""" Reset the list """
25+
"""Reset the list"""
2626
cli_ui._MESSAGES = list()
2727

2828
def find(self, pattern: str) -> Optional[str]:
29-
""" Find a message in the list of recorded message
29+
"""Find a message in the list of recorded message
3030
3131
:param pattern: regular expression pattern to use
3232
when looking for recorded message

cli_ui/tests/test_cli_ui.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,14 @@ def test_table_with_dict_no_color(dumb_tty: DumbTTY) -> None:
166166

167167
def test_table_with_dict_and_color(always_color: None, smart_tty: SmartTTY) -> None:
168168
data = {
169-
(cli_ui.bold, "Name",): [(cli_ui.green, "Alice"), (cli_ui.green, "Bob")],
170-
(cli_ui.bold, "Age",): [(cli_ui.blue, 24), (cli_ui.blue, 9)],
169+
(
170+
cli_ui.bold,
171+
"Name",
172+
): [(cli_ui.green, "Alice"), (cli_ui.green, "Bob")],
173+
(
174+
cli_ui.bold,
175+
"Age",
176+
): [(cli_ui.blue, 24), (cli_ui.blue, 9)],
171177
}
172178
cli_ui.info_table(data, headers="keys", fileobj=smart_tty)
173179
actual = smart_tty.getvalue()
@@ -258,7 +264,7 @@ def test_empty_password() -> None:
258264

259265

260266
def test_ask_yes_no() -> None:
261-
""" Test that you can answer with several types of common answers """
267+
"""Test that you can answer with several types of common answers"""
262268
with mock.patch("builtins.input") as m:
263269
m.side_effect = ["y", "yes", "Yes", "n", "no", "No"]
264270
expected_res = [True, True, True, False, False, False]
@@ -268,15 +274,15 @@ def test_ask_yes_no() -> None:
268274

269275

270276
def test_ask_yes_no_default() -> None:
271-
""" Test that just pressing enter returns the default value """
277+
"""Test that just pressing enter returns the default value"""
272278
with mock.patch("builtins.input") as m:
273279
m.side_effect = ["", ""]
274280
assert cli_ui.ask_yes_no("coffee?", default=True) is True
275281
assert cli_ui.ask_yes_no("coffee?", default=False) is False
276282

277283

278284
def test_ask_yes_no_wrong_input() -> None:
279-
""" Test that we keep asking when answer does not make sense """
285+
"""Test that we keep asking when answer does not make sense"""
280286
with mock.patch("builtins.input") as m:
281287
m.side_effect = ["coffee!", "n"]
282288
assert cli_ui.ask_yes_no("tea?") is False

0 commit comments

Comments
 (0)