Skip to content

Commit 435cf7f

Browse files
authored
Ruff format. (#1507)
1 parent f9cd644 commit 435cf7f

30 files changed

+144
-412
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ repos:
66
# Run the linter.
77
- id: ruff
88
args: [ --fix ]
9-
# Run the formatter. TODO: uncomment when the rest of the code is ruff-formatted
10-
# - id: ruff-format
9+
# Run the formatter.
10+
- id: ruff-format

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ get this running in a development setup.
158158
https://github.com/dbcli/pgcli/blob/main/CONTRIBUTING.rst
159159

160160
Please feel free to reach out to us if you need help.
161+
161162
* Amjith, pgcli author: [email protected], Twitter: `@amjithr <http://twitter.com/amjithr>`_
162163
* Irina, pgcli maintainer: [email protected], Twitter: `@irinatruong <http://twitter.com/irinatruong>`_
163164

pgcli/auth.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def keyring_initialize(keyring_enabled, *, logger):
2626

2727
try:
2828
keyring = importlib.import_module("keyring")
29-
except (
30-
ModuleNotFoundError
31-
) as e: # ImportError for Python 2, ModuleNotFoundError for Python 3
29+
except ModuleNotFoundError as e: # ImportError for Python 2, ModuleNotFoundError for Python 3
3230
logger.warning("import keyring failed: %r.", e)
3331

3432

@@ -40,9 +38,7 @@ def keyring_get_password(key):
4038
passwd = keyring.get_password("pgcli", key) or ""
4139
except Exception as e:
4240
click.secho(
43-
keyring_error_message.format(
44-
"Load your password from keyring returned:", str(e)
45-
),
41+
keyring_error_message.format("Load your password from keyring returned:", str(e)),
4642
err=True,
4743
fg="red",
4844
)

pgcli/completion_refresher.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,14 @@ def refresh(self, executor, special, callbacks, history=None, settings=None):
4040
)
4141
self._completer_thread.daemon = True
4242
self._completer_thread.start()
43-
return [
44-
(None, None, None, "Auto-completion refresh started in the background.")
45-
]
43+
return [(None, None, None, "Auto-completion refresh started in the background.")]
4644

4745
def is_refreshing(self):
4846
return self._completer_thread and self._completer_thread.is_alive()
4947

5048
def _bg_refresh(self, pgexecute, special, callbacks, history=None, settings=None):
5149
settings = settings or {}
52-
completer = PGCompleter(
53-
smart_completion=True, pgspecial=special, settings=settings
54-
)
50+
completer = PGCompleter(smart_completion=True, pgspecial=special, settings=settings)
5551

5652
if settings.get("single_connection"):
5753
executor = pgexecute

pgcli/key_bindings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ def _(event):
107107
# history search, and one of several conditions are True
108108
@kb.add(
109109
"enter",
110-
filter=~(completion_is_selected | is_searching)
111-
& buffer_should_be_handled(pgcli),
110+
filter=~(completion_is_selected | is_searching) & buffer_should_be_handled(pgcli),
112111
)
113112
def _(event):
114113
_logger.debug("Detected enter key.")

pgcli/packages/formatter/sqlformatter.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,16 @@ def adapter(data, headers, table_format=None, **kwargs):
5252
yield 'UPDATE "{}" SET'.format(table_name)
5353
prefix = " "
5454
for i, v in enumerate(d[keys:], keys):
55-
yield '{}"{}" = {}'.format(
56-
prefix, headers[i], escape_for_sql_statement(v)
57-
)
55+
yield '{}"{}" = {}'.format(prefix, headers[i], escape_for_sql_statement(v))
5856
if prefix == " ":
5957
prefix = ", "
6058
f = '"{}" = {}'
61-
where = (
62-
f.format(headers[i], escape_for_sql_statement(d[i]))
63-
for i in range(keys)
64-
)
59+
where = (f.format(headers[i], escape_for_sql_statement(d[i])) for i in range(keys))
6560
yield "WHERE {};".format(" AND ".join(where))
6661

6762

6863
def register_new_formatter(TabularOutputFormatter):
6964
global formatter
7065
formatter = TabularOutputFormatter
7166
for sql_format in supported_formats:
72-
TabularOutputFormatter.register_new_formatter(
73-
sql_format, adapter, preprocessors, {"table_format": sql_format}
74-
)
67+
TabularOutputFormatter.register_new_formatter(sql_format, adapter, preprocessors, {"table_format": sql_format})

pgcli/packages/parseutils/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def is_destructive(queries, keywords):
2929
for query in sqlparse.split(queries):
3030
if query:
3131
formatted_sql = sqlparse.format(query.lower(), strip_comments=True).strip()
32-
if "unconditional_update" in keywords and query_is_unconditional_update(
33-
formatted_sql
34-
):
32+
if "unconditional_update" in keywords and query_is_unconditional_update(formatted_sql):
3533
return True
3634
if query_starts_with(formatted_sql, keywords):
3735
return True

pgcli/packages/parseutils/meta.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from collections import namedtuple
22

3-
_ColumnMetadata = namedtuple(
4-
"ColumnMetadata", ["name", "datatype", "foreignkeys", "default", "has_default"]
5-
)
3+
_ColumnMetadata = namedtuple("ColumnMetadata", ["name", "datatype", "foreignkeys", "default", "has_default"])
64

75

86
def ColumnMetadata(name, datatype, foreignkeys=None, default=None, has_default=False):
@@ -143,11 +141,7 @@ def arg(name, typ, num):
143141
num_args = len(args)
144142
num_defaults = len(self.arg_defaults)
145143
has_default = num + num_defaults >= num_args
146-
default = (
147-
self.arg_defaults[num - num_args + num_defaults]
148-
if has_default
149-
else None
150-
)
144+
default = self.arg_defaults[num - num_args + num_defaults] if has_default else None
151145
return ColumnMetadata(name, typ, [], default, has_default)
152146

153147
return [arg(name, typ, num) for num, (name, typ) in enumerate(args)]

pgcli/packages/parseutils/tables.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
from sqlparse.sql import IdentifierList, Identifier, Function
44
from sqlparse.tokens import Keyword, DML, Punctuation
55

6-
TableReference = namedtuple(
7-
"TableReference", ["schema", "name", "alias", "is_function"]
8-
)
6+
TableReference = namedtuple("TableReference", ["schema", "name", "alias", "is_function"])
97
TableReference.ref = property(
10-
lambda self: self.alias
11-
or (
12-
self.name
13-
if self.name.islower() or self.name[0] == '"'
14-
else '"' + self.name + '"'
15-
)
8+
lambda self: self.alias or (self.name if self.name.islower() or self.name[0] == '"' else '"' + self.name + '"')
169
)
1710

1811

@@ -53,11 +46,7 @@ def extract_from_part(parsed, stop_at_punctuation=True):
5346
# Also 'SELECT * FROM abc JOIN def' will trigger this elif
5447
# condition. So we need to ignore the keyword JOIN and its variants
5548
# INNER JOIN, FULL OUTER JOIN, etc.
56-
elif (
57-
item.ttype is Keyword
58-
and (not item.value.upper() == "FROM")
59-
and (not item.value.upper().endswith("JOIN"))
60-
):
49+
elif item.ttype is Keyword and (not item.value.upper() == "FROM") and (not item.value.upper().endswith("JOIN")):
6150
tbl_prefix_seen = False
6251
else:
6352
yield item
@@ -116,15 +105,11 @@ def parse_identifier(item):
116105
try:
117106
schema_name = identifier.get_parent_name()
118107
real_name = identifier.get_real_name()
119-
is_function = allow_functions and _identifier_is_function(
120-
identifier
121-
)
108+
is_function = allow_functions and _identifier_is_function(identifier)
122109
except AttributeError:
123110
continue
124111
if real_name:
125-
yield TableReference(
126-
schema_name, real_name, identifier.get_alias(), is_function
127-
)
112+
yield TableReference(schema_name, real_name, identifier.get_alias(), is_function)
128113
elif isinstance(item, Identifier):
129114
schema_name, real_name, alias = parse_identifier(item)
130115
is_function = allow_functions and _identifier_is_function(item)

pgcli/packages/parseutils/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ def find_prev_keyword(sql, n_skip=0):
7979
logical_operators = ("AND", "OR", "NOT", "BETWEEN")
8080

8181
for t in reversed(flattened):
82-
if t.value == "(" or (
83-
t.is_keyword and (t.value.upper() not in logical_operators)
84-
):
82+
if t.value == "(" or (t.is_keyword and (t.value.upper() not in logical_operators)):
8583
# Find the location of token t in the original parsed statement
8684
# We can't use parsed.token_index(t) because t may be a child token
8785
# inside a TokenList, in which case token_index throws an error

0 commit comments

Comments
 (0)