Skip to content

Commit 889c7cf

Browse files
Restyled by black
1 parent 0db7066 commit 889c7cf

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

test/core_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def test_set_status_message(self):
6262

6363
tox.status_message = b"x" * core.MAX_STATUS_MESSAGE_LENGTH
6464
with self.assertRaises(error.ApiException):
65-
tox.status_message = b"x" * (core.MAX_STATUS_MESSAGE_LENGTH +
66-
1)
65+
tox.status_message = b"x" * (core.MAX_STATUS_MESSAGE_LENGTH + 1)
6766

6867
def test_set_status(self):
6968
with core.Core() as tox:

tools/gen_api.py

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def needs_space(l: str, r: str) -> bool:
3737
def untokenize(tokens: Tuple[str, ...]) -> str:
3838
line = []
3939
for i in range(len(tokens) - 1):
40-
if tokens[i:i + 2] == ("void", ")"):
40+
if tokens[i : i + 2] == ("void", ")"):
4141
break
4242
line.append(tokens[i])
4343
if needs_space(tokens[i], tokens[i + 1]):
@@ -74,9 +74,10 @@ def parse_params(tokens: Tuple[str, ...]) -> List[Tuple[List[str], str]]:
7474
return params
7575

7676

77-
def finalize_handler(type_prefix: str, handlers: List[str], event: str,
78-
params: List[str]) -> None:
79-
#handlers[-1] += " noexcept"
77+
def finalize_handler(
78+
type_prefix: str, handlers: List[str], event: str, params: List[str]
79+
) -> None:
80+
# handlers[-1] += " noexcept"
8081
handlers[-1] += ":"
8182
self = ""
8283
array = ""
@@ -133,8 +134,9 @@ def handle_macro(tokens: Sequence[str], state: List[str]) -> bool:
133134
return False
134135

135136

136-
def handle_types(tokens: Sequence[str], state: List[str], extern: List[str],
137-
const_prefix: str) -> bool:
137+
def handle_types(
138+
tokens: Sequence[str], state: List[str], extern: List[str], const_prefix: str
139+
) -> bool:
138140
# struct definitions (members are ignored)
139141
if tokens[0] == "struct" and tokens[-1] == "{":
140142
state.append("struct")
@@ -146,8 +148,7 @@ def handle_types(tokens: Sequence[str], state: List[str], extern: List[str],
146148
extern.append(f" ctypedef struct {tokens[2]}")
147149

148150
# enums
149-
if (tokens[:2] == ("typedef", "enum")
150-
or tokens[0] == "enum") and tokens[-1] == "{":
151+
if (tokens[:2] == ("typedef", "enum") or tokens[0] == "enum") and tokens[-1] == "{":
151152
enum_name = tokens[-2]
152153
if enum_name != "Tox_Log_Level":
153154
extern.append("")
@@ -162,38 +163,41 @@ def handle_types(tokens: Sequence[str], state: List[str], extern: List[str],
162163

163164

164165
def handle_functions(
165-
tokens: Tuple[str, ...],
166-
state: List[str],
167-
extern: List[str],
168-
fun_prefix: str,
169-
type_prefix: str,
170-
event: str,
171-
params: List[str],
172-
handlers: List[str],
173-
install_handlers: List[str],
166+
tokens: Tuple[str, ...],
167+
state: List[str],
168+
extern: List[str],
169+
fun_prefix: str,
170+
type_prefix: str,
171+
event: str,
172+
params: List[str],
173+
handlers: List[str],
174+
install_handlers: List[str],
174175
) -> str:
175176
# functions and callbacks
176-
if ("(" in tokens and tokens[0].isidentifier()
177-
and token_before("(", tokens).startswith(fun_prefix)
178-
and tokens[0] != "typedef"):
177+
if (
178+
"(" in tokens
179+
and tokens[0].isidentifier()
180+
and token_before("(", tokens).startswith(fun_prefix)
181+
and tokens[0] != "typedef"
182+
):
179183
extern.append(f" cdef {untokenize_fun(tokens)}")
180184
if ";" not in tokens:
181185
state.append("fun")
182186
return event
183187
if tokens[:2] == ("typedef", "void"):
184188
extern.append(f" c{untokenize_fun(tokens)}")
185189

186-
event = tokens[2][len(fun_prefix):-3]
190+
event = tokens[2][len(fun_prefix) : -3]
187191
params.clear()
188192
params.extend(tokens[3:])
189193

190194
# TODO(iphydf): Handle this better (by checking whether we have a callback install
191195
# function for this event).
192196
if event != "log":
193-
handlers.append(
194-
f"cdef void handle_{untokenize_fun((event,) + tokens[3:])}")
197+
handlers.append(f"cdef void handle_{untokenize_fun((event,) + tokens[3:])}")
195198
install_handlers.append(
196-
f" {fun_prefix}callback_{event}(ptr, handle_{event})")
199+
f" {fun_prefix}callback_{event}(ptr, handle_{event})"
200+
)
197201
if ";" not in tokens:
198202
state.append("callback")
199203
else:
@@ -278,8 +282,7 @@ def gen_cython(lines: Sequence[str], fun_prefix: str, extern_line: str) -> List[
278282
)
279283

280284
if install_handlers:
281-
install_handlers = (
282-
["cdef void install_handlers(Tox *ptr):"] + install_handlers)
285+
install_handlers = ["cdef void install_handlers(Tox *ptr):"] + install_handlers
283286
return extern + [""] + handlers + [""] + install_handlers
284287

285288

@@ -291,25 +294,29 @@ def main() -> None:
291294
src = sys.argv[1]
292295
api_base = sys.argv[2]
293296

294-
cdef_extern_prefix = "cdef extern from \""
295-
cdef_extern_suffix = "\": pass\n"
297+
cdef_extern_prefix = 'cdef extern from "'
298+
cdef_extern_suffix = '": pass\n'
296299

297300
with open(src, "r", encoding="utf-8") as src_fh:
298301
for line in src_fh.readlines():
299-
if (line.startswith(cdef_extern_prefix) and
300-
line.endswith(cdef_extern_suffix)):
301-
api_file = (line
302-
.removeprefix(cdef_extern_prefix)
303-
.removesuffix(cdef_extern_suffix))
302+
if line.startswith(cdef_extern_prefix) and line.endswith(
303+
cdef_extern_suffix
304+
):
305+
api_file = line.removeprefix(cdef_extern_prefix).removesuffix(
306+
cdef_extern_suffix
307+
)
304308
api = os.path.join(api_base, api_file)
305309
extern_line = line.removesuffix(" pass\n")
306310
with open(api, "r", encoding="utf-8") as api_fh:
307-
print("\n".join(
308-
gen_cython(
309-
api_fh.readlines(),
310-
fun_prefix=get_fun_prefix(api),
311-
extern_line=extern_line,
312-
)))
311+
print(
312+
"\n".join(
313+
gen_cython(
314+
api_fh.readlines(),
315+
fun_prefix=get_fun_prefix(api),
316+
extern_line=extern_line,
317+
)
318+
)
319+
)
313320
else:
314321
print(line.rstrip())
315322

0 commit comments

Comments
 (0)