diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7ad829c94d50f3..39e8d1451583f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,12 +26,9 @@ repos: name: Run Ruff (format) on Tools/build/check_warnings.py args: [--check, --config=Tools/build/.ruff.toml] files: ^Tools/build/check_warnings.py - - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.1.0 - hooks: - - id: black - name: Run Black on Tools/jit/ + - id: ruff-format + name: Run Ruff (format) on Tools/jit/ + args: [--check, --config=Tools/jit/.ruff.toml] files: ^Tools/jit/ - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/Tools/jit/.ruff.toml b/Tools/jit/.ruff.toml new file mode 100644 index 00000000000000..6c4b0e77664384 --- /dev/null +++ b/Tools/jit/.ruff.toml @@ -0,0 +1,7 @@ +extend = "../../.ruff.toml" # Inherit the project-wide settings + +line-length = 88 # slightly longer than PEP 8, for readability + +[format] +preview = true +docstring-code-format = true diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py index f09a8404871b24..00207d1beac5c9 100644 --- a/Tools/jit/_llvm.py +++ b/Tools/jit/_llvm.py @@ -24,9 +24,7 @@ def _async_cache(f: _C[_P, _R]) -> _C[_P, _R]: lock = asyncio.Lock() @functools.wraps(f) - async def wrapper( - *args: _P.args, **kwargs: _P.kwargs # pylint: disable = no-member - ) -> _R: + async def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R: # pylint: disable = no-member async with lock: if args not in cache: cache[args] = await f(*args, **kwargs) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 03b0ba647b0db7..dc178c78a824a6 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -230,35 +230,41 @@ def remove_jump(self) -> None: """Remove a zero-length continuation jump, if it exists.""" hole = max(self.holes, key=lambda hole: hole.offset) match hole: - case Hole( - offset=offset, - kind="IMAGE_REL_AMD64_REL32", - value=HoleValue.GOT, - symbol="_JIT_CONTINUE", - addend=-4, - ) as hole: + case ( + Hole( + offset=offset, + kind="IMAGE_REL_AMD64_REL32", + value=HoleValue.GOT, + symbol="_JIT_CONTINUE", + addend=-4, + ) as hole + ): # jmp qword ptr [rip] jump = b"\x48\xff\x25\x00\x00\x00\x00" offset -= 3 - case Hole( - offset=offset, - kind="IMAGE_REL_I386_REL32" | "R_X86_64_PLT32" | "X86_64_RELOC_BRANCH", - value=HoleValue.CONTINUE, - symbol=None, - addend=addend, - ) as hole if ( - _signed(addend) == -4 - ): + case ( + Hole( + offset=offset, + kind="IMAGE_REL_I386_REL32" + | "R_X86_64_PLT32" + | "X86_64_RELOC_BRANCH", + value=HoleValue.CONTINUE, + symbol=None, + addend=addend, + ) as hole + ) if _signed(addend) == -4: # jmp 5 jump = b"\xe9\x00\x00\x00\x00" offset -= 1 - case Hole( - offset=offset, - kind="R_AARCH64_JUMP26", - value=HoleValue.CONTINUE, - symbol=None, - addend=0, - ) as hole: + case ( + Hole( + offset=offset, + kind="R_AARCH64_JUMP26", + value=HoleValue.CONTINUE, + symbol=None, + addend=0, + ) as hole + ): # b #4 jump = b"\x00\x00\x00\x14" case _: diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 6ceb4404e74ce7..7975f917ea997a 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -233,9 +233,7 @@ def build( jit_stencils_new.unlink(missing_ok=True) -class _COFF( - _Target[_schema.COFFSection, _schema.COFFRelocation] -): # pylint: disable = too-few-public-methods +class _COFF(_Target[_schema.COFFSection, _schema.COFFRelocation]): # pylint: disable = too-few-public-methods def _handle_section( self, section: _schema.COFFSection, group: _stencils.StencilGroup ) -> None: @@ -321,9 +319,7 @@ def _handle_relocation( return _stencils.Hole(offset, kind, value, symbol, addend) -class _ELF( - _Target[_schema.ELFSection, _schema.ELFRelocation] -): # pylint: disable = too-few-public-methods +class _ELF(_Target[_schema.ELFSection, _schema.ELFRelocation]): # pylint: disable = too-few-public-methods def _handle_section( self, section: _schema.ELFSection, group: _stencils.StencilGroup ) -> None: @@ -411,9 +407,7 @@ def _handle_relocation( return _stencils.Hole(offset, kind, value, symbol, addend) -class _MachO( - _Target[_schema.MachOSection, _schema.MachORelocation] -): # pylint: disable = too-few-public-methods +class _MachO(_Target[_schema.MachOSection, _schema.MachORelocation]): # pylint: disable = too-few-public-methods def _handle_section( self, section: _schema.MachOSection, group: _stencils.StencilGroup ) -> None: