Skip to content

Commit 3c99392

Browse files
committed
Add ruff fast linter and formatter in preparation for using it to replace black, isort, and flake8
1 parent 3062aaa commit 3c99392

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+300
-61
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ Pipfile.lock
4343

4444
# pyenv version file
4545
.python-version
46+
47+
# uv
48+
uv.lock

cmd2/ansi.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"""
33
Support for ANSI escape sequences which are used for things like applying style to text,
44
setting the window title, and asynchronous alerts.
5-
"""
5+
"""
6+
67
import functools
78
import re
89
from enum import (
@@ -62,25 +63,25 @@ def __repr__(self) -> str:
6263
"""
6364

6465
# Regular expression to match ANSI style sequence
65-
ANSI_STYLE_RE = re.compile(fr'{ESC}\[[^m]*m')
66+
ANSI_STYLE_RE = re.compile(rf'{ESC}\[[^m]*m')
6667

6768
# Matches standard foreground colors: CSI(30-37|90-97|39)m
68-
STD_FG_RE = re.compile(fr'{ESC}\[(?:[39][0-7]|39)m')
69+
STD_FG_RE = re.compile(rf'{ESC}\[(?:[39][0-7]|39)m')
6970

7071
# Matches standard background colors: CSI(40-47|100-107|49)m
71-
STD_BG_RE = re.compile(fr'{ESC}\[(?:(?:4|10)[0-7]|49)m')
72+
STD_BG_RE = re.compile(rf'{ESC}\[(?:(?:4|10)[0-7]|49)m')
7273

7374
# Matches eight-bit foreground colors: CSI38;5;(0-255)m
74-
EIGHT_BIT_FG_RE = re.compile(fr'{ESC}\[38;5;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])m')
75+
EIGHT_BIT_FG_RE = re.compile(rf'{ESC}\[38;5;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])m')
7576

7677
# Matches eight-bit background colors: CSI48;5;(0-255)m
77-
EIGHT_BIT_BG_RE = re.compile(fr'{ESC}\[48;5;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])m')
78+
EIGHT_BIT_BG_RE = re.compile(rf'{ESC}\[48;5;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])m')
7879

7980
# Matches RGB foreground colors: CSI38;2;(0-255);(0-255);(0-255)m
80-
RGB_FG_RE = re.compile(fr'{ESC}\[38;2(?:;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])){{3}}m')
81+
RGB_FG_RE = re.compile(rf'{ESC}\[38;2(?:;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])){{3}}m')
8182

8283
# Matches RGB background colors: CSI48;2;(0-255);(0-255);(0-255)m
83-
RGB_BG_RE = re.compile(fr'{ESC}\[48;2(?:;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])){{3}}m')
84+
RGB_BG_RE = re.compile(rf'{ESC}\[48;2(?:;(?:1?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5])){{3}}m')
8485

8586

8687
def strip_style(text: str) -> str:

cmd2/argparse_completer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _looks_like_flag(token: str, parser: argparse.ArgumentParser) -> bool:
9292
return False
9393

9494
# Flags have to start with a prefix character
95-
if not token[0] in parser.prefix_chars:
95+
if token[0] not in parser.prefix_chars:
9696
return False
9797

9898
# If it looks like a negative number, it is not a flag unless there are negative-number-like flags

cmd2/clipboard.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
This module provides basic ability to copy from and paste to the clipboard/pastebuffer.
44
"""
5+
56
import typing
67

78
import pyperclip # type: ignore[import]

cmd2/cmd2.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
Git repository on GitHub at https://github.com/python-cmd2/cmd2
2323
"""
24+
2425
# This module has many imports, quite a few of which are only
2526
# infrequently utilized. To reduce the initial overhead of
2627
# import this module, many of these imports are lazy-loaded
@@ -2019,9 +2020,7 @@ def _determine_ap_completer_type(parser: argparse.ArgumentParser) -> Type[argpar
20192020
:param parser: the parser to examine
20202021
:return: type of ArgparseCompleter
20212022
"""
2022-
completer_type: Optional[
2023-
Type[argparse_completer.ArgparseCompleter]
2024-
] = parser.get_ap_completer_type() # type: ignore[attr-defined]
2023+
completer_type: Optional[Type[argparse_completer.ArgparseCompleter]] = parser.get_ap_completer_type()
20252024

20262025
if completer_type is None:
20272026
completer_type = argparse_completer.DEFAULT_AP_COMPLETER
@@ -5537,7 +5536,7 @@ def cmdloop(self, intro: Optional[str] = None) -> int: # type: ignore[override]
55375536
"""
55385537
# cmdloop() expects to be run in the main thread to support extensive use of KeyboardInterrupts throughout the
55395538
# other built-in functions. You are free to override cmdloop, but much of cmd2's features will be limited.
5540-
if not threading.current_thread() is threading.main_thread():
5539+
if threading.current_thread() is not threading.main_thread():
55415540
raise RuntimeError("cmdloop must be run in the main thread")
55425541

55435542
# Register signal handlers

cmd2/command_definition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
Supports the definition of commands in separate classes to be composed into cmd2.Cmd
44
"""
5+
56
from typing import (
67
TYPE_CHECKING,
78
Callable,

cmd2/decorators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding=utf-8
22
"""Decorators for ``cmd2`` commands"""
3+
34
import argparse
45
from typing import (
56
TYPE_CHECKING,

cmd2/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
22
# coding=utf-8
33
"""Classes for the cmd2 plugin system"""
4+
45
from dataclasses import (
56
dataclass,
67
)

cmd2/rl_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
Imports the proper Readline for the platform and provides utility functions for it
44
"""
5+
56
import sys
67
from enum import (
78
Enum,

cmd2/table_creator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
The general use case is to inherit from TableCreator to create a table class with custom formatting options.
66
There are already implemented and ready-to-use examples of this below TableCreator's code.
77
"""
8+
89
import copy
910
import io
1011
from collections import (

0 commit comments

Comments
 (0)