Skip to content

Commit c825242

Browse files
Restyled by yapf
1 parent 574edd7 commit c825242

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

test/core_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def test_set_status_message(self):
6161

6262
tox.status_message = b"x" * core.MAX_STATUS_MESSAGE_LENGTH
6363
with self.assertRaises(error.ApiException):
64-
tox.status_message = b"x" * (core.MAX_STATUS_MESSAGE_LENGTH + 1)
64+
tox.status_message = b"x" * (core.MAX_STATUS_MESSAGE_LENGTH +
65+
1)
6566

6667
def test_set_status(self):
6768
with core.Core() as tox:

tools/gen_api.py

Lines changed: 34 additions & 38 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,8 @@ def parse_params(tokens: Tuple[str, ...]) -> List[Tuple[List[str], str]]:
7474
return params
7575

7676

77-
def finalize_handler(
78-
type_prefix: str, handlers: List[str], event: str, params: List[str]
79-
) -> None:
77+
def finalize_handler(type_prefix: str, handlers: List[str], event: str,
78+
params: List[str]) -> None:
8079
handlers[-1] += " noexcept:"
8180
# handlers[-1] += ":"
8281
self = ""
@@ -134,9 +133,8 @@ def handle_macro(tokens: Sequence[str], state: List[str]) -> bool:
134133
return False
135134

136135

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

150148
# enums
151-
if (tokens[:2] == ("typedef", "enum") or tokens[0] == "enum") and tokens[-1] == "{":
149+
if (tokens[:2] == ("typedef", "enum")
150+
or tokens[0] == "enum") and tokens[-1] == "{":
152151
enum_name = tokens[-2]
153152
if enum_name != "Tox_Log_Level":
154153
extern.append("")
@@ -163,41 +162,38 @@ def handle_types(
163162

164163

165164
def handle_functions(
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],
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],
175174
) -> str:
176175
# functions and callbacks
177-
if (
178-
"(" in tokens
179-
and tokens[0].isidentifier()
180-
and token_before("(", tokens).startswith(fun_prefix)
181-
and tokens[0] != "typedef"
182-
):
176+
if ("(" in tokens and tokens[0].isidentifier()
177+
and token_before("(", tokens).startswith(fun_prefix)
178+
and tokens[0] != "typedef"):
183179
extern.append(f" cdef {untokenize_fun(tokens)}")
184180
if ";" not in tokens:
185181
state.append("fun")
186182
return event
187183
if tokens[:2] == ("typedef", "void"):
188184
extern.append(f" c{untokenize_fun(tokens)}")
189185

190-
event = tokens[2][len(fun_prefix) : -3]
186+
event = tokens[2][len(fun_prefix):-3]
191187
params.clear()
192188
params.extend(tokens[3:])
193189

194190
# TODO(iphydf): Handle this better (by checking whether we have a callback install
195191
# function for this event).
196192
if event != "log":
197-
handlers.append(f"cdef void handle_{untokenize_fun((event,) + tokens[3:])}")
193+
handlers.append(
194+
f"cdef void handle_{untokenize_fun((event,) + tokens[3:])}")
198195
install_handlers.append(
199-
f" {fun_prefix}callback_{event}(ptr, handle_{event})"
200-
)
196+
f" {fun_prefix}callback_{event}(ptr, handle_{event})")
201197
if ";" not in tokens:
202198
state.append("callback")
203199
else:
@@ -222,7 +218,8 @@ def handle_functions(
222218
return event
223219

224220

225-
def gen_cython(lines: Sequence[str], fun_prefix: str, extern_line: str) -> List[str]:
221+
def gen_cython(lines: Sequence[str], fun_prefix: str,
222+
extern_line: str) -> List[str]:
226223
const_prefix = fun_prefix.upper()
227224
type_prefix = fun_prefix.capitalize()
228225

@@ -282,7 +279,8 @@ def gen_cython(lines: Sequence[str], fun_prefix: str, extern_line: str) -> List[
282279
)
283280

284281
if install_handlers:
285-
install_handlers = ["cdef void install_handlers(Tox *ptr):"] + install_handlers
282+
install_handlers = ["cdef void install_handlers(Tox *ptr):"
283+
] + install_handlers
286284
return extern + [""] + handlers + [""] + install_handlers
287285

288286

@@ -295,15 +293,13 @@ def main() -> None:
295293
if line.startswith("cdef extern from"):
296294
extern_line = line.removesuffix(" pass\n")
297295
with open(api, "r", encoding="utf-8") as api_fh:
298-
print(
299-
"\n".join(
300-
gen_cython(
301-
api_fh.readlines(),
302-
fun_prefix=os.path.split(api)[-1].split(".")[0] + "_",
303-
extern_line=extern_line,
304-
)
305-
)
306-
)
296+
print("\n".join(
297+
gen_cython(
298+
api_fh.readlines(),
299+
fun_prefix=os.path.split(api)[-1].split(".")[0] +
300+
"_",
301+
extern_line=extern_line,
302+
)))
307303
else:
308304
print(line.rstrip())
309305

0 commit comments

Comments
 (0)