Skip to content

Commit e36f747

Browse files
committed
Revert "PEP 8 (keep to 80 chars)"
This reverts commit 42ce014.
1 parent 42ce014 commit e36f747

File tree

7 files changed

+36
-117
lines changed

7 files changed

+36
-117
lines changed

Tools/jit/.ruff.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extend = "../../.ruff.toml" # Inherit the project-wide settings
22

3+
line-length = 88
4+
35
[format]
46
preview = true
57
docstring-code-format = true

Tools/jit/_llvm.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import typing
1010

1111
_LLVM_VERSION = 19
12-
_LLVM_VERSION_PATTERN = re.compile(
13-
rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\S*\s+"
14-
)
12+
_LLVM_VERSION_PATTERN = re.compile(rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\S*\s+")
1513

1614
_P = typing.ParamSpec("_P")
1715
_R = typing.TypeVar("_R")
@@ -35,9 +33,7 @@ async def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
3533
_CORES = asyncio.BoundedSemaphore(os.cpu_count() or 1)
3634

3735

38-
async def _run(
39-
tool: str, args: typing.Iterable[str], echo: bool = False
40-
) -> str | None:
36+
async def _run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str | None:
4137
command = [tool, *args]
4238
async with _CORES:
4339
if echo:
@@ -50,9 +46,7 @@ async def _run(
5046
return None
5147
out, _ = await process.communicate()
5248
if process.returncode:
53-
raise RuntimeError(
54-
f"{tool} exited with return code {process.returncode}"
55-
)
49+
raise RuntimeError(f"{tool} exited with return code {process.returncode}")
5650
return out.decode()
5751

5852

@@ -64,9 +58,7 @@ async def _check_tool_version(name: str, *, echo: bool = False) -> bool:
6458

6559
@_async_cache
6660
async def _get_brew_llvm_prefix(*, echo: bool = False) -> str | None:
67-
output = await _run(
68-
"brew", ["--prefix", f"llvm@{_LLVM_VERSION}"], echo=echo
69-
)
61+
output = await _run("brew", ["--prefix", f"llvm@{_LLVM_VERSION}"], echo=echo)
7062
return output and output.removesuffix("\n")
7163

7264

@@ -98,9 +90,7 @@ async def maybe_run(
9890
return path and await _run(path, args, echo=echo)
9991

10092

101-
async def run(
102-
tool: str, args: typing.Iterable[str], echo: bool = False
103-
) -> str:
93+
async def run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str:
10494
"""Run an LLVM tool if it can be found. Otherwise, raise RuntimeError."""
10595
output = await maybe_run(tool, args, echo=echo)
10696
if output is None:

Tools/jit/_schema.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ class COFFSection(typing.TypedDict):
9797
class ELFSection(typing.TypedDict):
9898
"""An ELF object file section."""
9999

100-
Flags: dict[
101-
typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]
102-
]
100+
Flags: dict[typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]]
103101
Index: int
104102
Info: int
105103
Relocations: list[dict[typing.Literal["Relocation"], ELFRelocation]]
@@ -112,15 +110,11 @@ class MachOSection(typing.TypedDict):
112110
"""A Mach-O object file section."""
113111

114112
Address: int
115-
Attributes: dict[
116-
typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]
117-
]
113+
Attributes: dict[typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]]
118114
Index: int
119115
Name: dict[typing.Literal["Value"], str]
120116
Relocations: typing.NotRequired[
121117
list[dict[typing.Literal["Relocation"], MachORelocation]]
122118
]
123119
SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]]
124-
Symbols: typing.NotRequired[
125-
list[dict[typing.Literal["Symbol"], _MachOSymbol]]
126-
]
120+
Symbols: typing.NotRequired[list[dict[typing.Literal["Symbol"], _MachOSymbol]]]

Tools/jit/_stencils.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,14 @@ class Stencil:
199199

200200
body: bytearray = dataclasses.field(default_factory=bytearray, init=False)
201201
holes: list[Hole] = dataclasses.field(default_factory=list, init=False)
202-
disassembly: list[str] = dataclasses.field(
203-
default_factory=list, init=False
204-
)
202+
disassembly: list[str] = dataclasses.field(default_factory=list, init=False)
205203

206204
def pad(self, alignment: int) -> None:
207205
"""Pad the stencil to the given alignment."""
208206
offset = len(self.body)
209207
padding = -offset % alignment
210208
if padding:
211-
self.disassembly.append(
212-
f"{offset:x}: {' '.join(['00'] * padding)}"
213-
)
209+
self.disassembly.append(f"{offset:x}: {' '.join(['00'] * padding)}")
214210
self.body.extend([0] * padding)
215211

216212
def add_nops(self, nop: bytes, alignment: int) -> None:
@@ -295,21 +291,13 @@ class StencilGroup:
295291
_trampolines: set[int] = dataclasses.field(default_factory=set, init=False)
296292

297293
def process_relocations(
298-
self,
299-
known_symbols: dict[str, int],
300-
*,
301-
alignment: int = 1,
302-
nop: bytes = b"",
294+
self, known_symbols: dict[str, int], *, alignment: int = 1, nop: bytes = b""
303295
) -> None:
304296
"""Fix up all GOT and internal relocations for this stencil group."""
305297
for hole in self.code.holes.copy():
306298
if (
307299
hole.kind
308-
in {
309-
"R_AARCH64_CALL26",
310-
"R_AARCH64_JUMP26",
311-
"ARM64_RELOC_BRANCH26",
312-
}
300+
in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"}
313301
and hole.value is HoleValue.ZERO
314302
and hole.symbol not in self.symbols
315303
):
@@ -332,9 +320,7 @@ def process_relocations(
332320
if hole.value is HoleValue.GOT:
333321
assert hole.symbol is not None
334322
hole.value = HoleValue.DATA
335-
hole.addend += self._global_offset_table_lookup(
336-
hole.symbol
337-
)
323+
hole.addend += self._global_offset_table_lookup(hole.symbol)
338324
hole.symbol = None
339325
elif hole.symbol in self.symbols:
340326
hole.value, addend = self.symbols[hole.symbol]
@@ -352,9 +338,7 @@ def process_relocations(
352338
self.data.holes.sort(key=lambda hole: hole.offset)
353339

354340
def _global_offset_table_lookup(self, symbol: str) -> int:
355-
return len(self.data.body) + self._got.setdefault(
356-
symbol, 8 * len(self._got)
357-
)
341+
return len(self.data.body) + self._got.setdefault(symbol, 8 * len(self._got))
358342

359343
def _emit_global_offset_table(self) -> None:
360344
got = len(self.data.body)

Tools/jit/_targets.py

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import _writer
1818

1919
if sys.version_info < (3, 11):
20-
raise RuntimeError(
21-
"Building the JIT compiler requires Python 3.11 or newer!"
22-
)
20+
raise RuntimeError("Building the JIT compiler requires Python 3.11 or newer!")
2321

2422
TOOLS_JIT_BUILD = pathlib.Path(__file__).resolve()
2523
TOOLS_JIT = TOOLS_JIT_BUILD.parent
@@ -29,14 +27,9 @@
2927
TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
3028
ASYNCIO_RUNNER = asyncio.Runner()
3129

32-
_S = typing.TypeVar(
33-
"_S", _schema.COFFSection, _schema.ELFSection, _schema.MachOSection
34-
)
30+
_S = typing.TypeVar("_S", _schema.COFFSection, _schema.ELFSection, _schema.MachOSection)
3531
_R = typing.TypeVar(
36-
"_R",
37-
_schema.COFFRelocation,
38-
_schema.ELFRelocation,
39-
_schema.MachORelocation,
32+
"_R", _schema.COFFRelocation, _schema.ELFRelocation, _schema.MachORelocation
4033
)
4134

4235

@@ -102,9 +95,7 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
10295
# ...and also COFF:
10396
output = output[output.index("[", 1, None) :]
10497
output = output[: output.rindex("]", None, -1) + 1]
105-
sections: list[dict[typing.Literal["Section"], _S]] = json.loads(
106-
output
107-
)
98+
sections: list[dict[typing.Literal["Section"], _S]] = json.loads(output)
10899
for wrapped_section in sections:
109100
self._handle_section(wrapped_section["Section"], group)
110101
assert group.symbols["_JIT_ENTRY"] == (_stencils.HoleValue.CODE, 0)
@@ -113,9 +104,7 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
113104
group.data.disassembly.append(line)
114105
return group
115106

116-
def _handle_section(
117-
self, section: _S, group: _stencils.StencilGroup
118-
) -> None:
107+
def _handle_section(self, section: _S, group: _stencils.StencilGroup) -> None:
119108
raise NotImplementedError(type(self))
120109

121110
def _handle_relocation(
@@ -171,9 +160,7 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
171160
generated_cases = PYTHON_EXECUTOR_CASES_C_H.read_text()
172161
cases_and_opnames = sorted(
173162
re.findall(
174-
r"\n {8}(case (\w+): \{\n.*?\n {8}\})",
175-
generated_cases,
176-
flags=re.DOTALL,
163+
r"\n {8}(case (\w+): \{\n.*?\n {8}\})", generated_cases, flags=re.DOTALL
177164
)
178165
)
179166
tasks = []
@@ -213,9 +200,7 @@ def build(
213200
"""Build jit_stencils.h in the given directory."""
214201
if not self.stable:
215202
warning = f"JIT support for {self.triple} is still experimental!"
216-
request = "Please report any issues you encounter.".center(
217-
len(warning)
218-
)
203+
request = "Please report any issues you encounter.".center(len(warning))
219204
outline = "=" * len(warning)
220205
print("\n".join(["", outline, warning, request, outline, ""]))
221206
digest = f"// {self._compute_digest(out)}\n"
@@ -279,9 +264,7 @@ def _handle_section(
279264
hole = self._handle_relocation(base, relocation, stencil.body)
280265
stencil.holes.append(hole)
281266

282-
def _unwrap_dllimport(
283-
self, name: str
284-
) -> tuple[_stencils.HoleValue, str | None]:
267+
def _unwrap_dllimport(self, name: str) -> tuple[_stencils.HoleValue, str | None]:
285268
if name.startswith("__imp_"):
286269
name = name.removeprefix("__imp_")
287270
name = name.removeprefix(self.prefix)
@@ -308,17 +291,13 @@ def _handle_relocation(
308291
"Offset": offset,
309292
"Symbol": s,
310293
"Type": {
311-
"Name": "IMAGE_REL_AMD64_REL32"
312-
| "IMAGE_REL_I386_REL32" as kind
294+
"Name": "IMAGE_REL_AMD64_REL32" | "IMAGE_REL_I386_REL32" as kind
313295
},
314296
}:
315297
offset += base
316298
value, symbol = self._unwrap_dllimport(s)
317299
addend = (
318-
int.from_bytes(
319-
raw[offset : offset + 4], "little", signed=True
320-
)
321-
- 4
300+
int.from_bytes(raw[offset : offset + 4], "little", signed=True) - 4
322301
)
323302
case {
324303
"Offset": offset,
@@ -450,12 +429,7 @@ def _handle_section(
450429
base = section["Address"] - start_address
451430
group.symbols[section["Index"]] = value, base
452431
stencil.body.extend(
453-
[0]
454-
* (
455-
section["Address"]
456-
- len(group.code.body)
457-
- len(group.data.body)
458-
)
432+
[0] * (section["Address"] - len(group.code.body) - len(group.data.body))
459433
)
460434
stencil.body.extend(section["SectionData"]["Bytes"])
461435
assert "Symbols" in section
@@ -494,19 +468,13 @@ def _handle_relocation(
494468
case {
495469
"Offset": offset,
496470
"Symbol": {"Name": s},
497-
"Type": {
498-
"Name": "X86_64_RELOC_GOT"
499-
| "X86_64_RELOC_GOT_LOAD" as kind
500-
},
471+
"Type": {"Name": "X86_64_RELOC_GOT" | "X86_64_RELOC_GOT_LOAD" as kind},
501472
}:
502473
offset += base
503474
s = s.removeprefix(self.prefix)
504475
value, symbol = _stencils.HoleValue.GOT, s
505476
addend = (
506-
int.from_bytes(
507-
raw[offset : offset + 4], "little", signed=True
508-
)
509-
- 4
477+
int.from_bytes(raw[offset : offset + 4], "little", signed=True) - 4
510478
)
511479
case {
512480
"Offset": offset,
@@ -515,19 +483,13 @@ def _handle_relocation(
515483
} | {
516484
"Offset": offset,
517485
"Symbol": {"Name": s},
518-
"Type": {
519-
"Name": "X86_64_RELOC_BRANCH"
520-
| "X86_64_RELOC_SIGNED" as kind
521-
},
486+
"Type": {"Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind},
522487
}:
523488
offset += base
524489
s = s.removeprefix(self.prefix)
525490
value, symbol = _stencils.symbol_to_value(s)
526491
addend = (
527-
int.from_bytes(
528-
raw[offset : offset + 4], "little", signed=True
529-
)
530-
- 4
492+
int.from_bytes(raw[offset : offset + 4], "little", signed=True) - 4
531493
)
532494
case {
533495
"Offset": offset,

Tools/jit/_writer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def _dump_footer(
4040
yield "};"
4141

4242

43-
def _dump_stencil(
44-
opname: str, group: _stencils.StencilGroup
45-
) -> typing.Iterator[str]:
43+
def _dump_stencil(opname: str, group: _stencils.StencilGroup) -> typing.Iterator[str]:
4644
yield "void"
4745
yield f"emit_{opname}("
4846
yield " unsigned char *code, unsigned char *data, _PyExecutorObject *executor,"
@@ -64,9 +62,7 @@ def _dump_stencil(
6462
yield f" memcpy({part}, {part}_body, sizeof({part}_body));"
6563
skip = False
6664
stencil.holes.sort(key=lambda hole: hole.offset)
67-
for hole, pair in itertools.zip_longest(
68-
stencil.holes, stencil.holes[1:]
69-
):
65+
for hole, pair in itertools.zip_longest(stencil.holes, stencil.holes[1:]):
7066
if skip:
7167
skip = False
7268
continue

Tools/jit/build.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,13 @@
1717
help="a PEP 11 target triple to compile for",
1818
)
1919
parser.add_argument(
20-
"-d",
21-
"--debug",
22-
action="store_true",
23-
help="compile for a debug build of Python",
20+
"-d", "--debug", action="store_true", help="compile for a debug build of Python"
2421
)
2522
parser.add_argument(
26-
"-f",
27-
"--force",
28-
action="store_true",
29-
help="force the entire JIT to be rebuilt",
23+
"-f", "--force", action="store_true", help="force the entire JIT to be rebuilt"
3024
)
3125
parser.add_argument(
32-
"-v",
33-
"--verbose",
34-
action="store_true",
35-
help="echo commands as they are run",
26+
"-v", "--verbose", action="store_true", help="echo commands as they are run"
3627
)
3728
args = parser.parse_args()
3829
for target in args.target:

0 commit comments

Comments
 (0)