style: replace black with ruff for Python formatting

Ruff's default format is very similar to black's, so there are only a
few changes made to our Python code. They are all contained in this
commit. The primary benefit of this change is that ruff's performance is
about an order of magnitude better, reducing runtime on this repo down
to under 20ms on my machine, compared to over 150ms with black, and even
more if any changes are performed by black.

Closes #11894

Closes #11918
This commit is contained in:
Daniel Rainer
2025-10-08 17:40:31 +02:00
committed by Johannes Altmanninger
parent 861002917a
commit 5ade4a037e
4 changed files with 10 additions and 14 deletions

View File

@@ -110,7 +110,7 @@ before committing your change. That will run our autoformatters:
- ``rustfmt`` for Rust
- ``fish_indent`` (shipped with fish) for fish script
- ``black`` for python
- ``ruff format`` for python
If youve already committed your changes thats okay since it will then
check the files in the most recent commit. This can be useful after

View File

@@ -44,7 +44,7 @@ if test $all = yes
end
end
set fish_files $workspace_root/{benchmarks,build_tools,etc,share}/**.fish
set python_files {doc_src,share,tests}/**.py
set python_files .
else
# Format the files specified as arguments.
set -l files $argv
@@ -76,19 +76,19 @@ if set -q fish_files[1]
end
if set -q python_files[1]
if not type -q black
if not type -q ruff
echo
echo $yellow'Please install `black` to style python'$normal
echo $yellow'Please install `ruff` to style python'$normal
exit 127
end
echo === Running "$green"black"$normal"
echo === Running "$green"ruff format"$normal"
if set -l -q _flag_check
if not black --check $python_files
if not ruff format --check $python_files
echo $red"Python files are not formatted correctly."$normal
exit 1
end
else
black $python_files
ruff format $python_files
end
end

View File

@@ -1423,7 +1423,7 @@ fish_bin_path = None
fish_bin_name = "fish.exe" if is_windows() else "fish"
if not fish_bin_dir:
print("The $__fish_bin_dir environment variable is not set. " "Looking in $PATH...")
print("The $__fish_bin_dir environment variable is not set. Looking in $PATH...")
fish_bin_path = find_executable(fish_bin_name)
if not fish_bin_path:
print("fish could not be found. Is fish installed correctly?")

View File

@@ -38,9 +38,7 @@ sendline(
echo Got SIGUSR1 $sigusr1_count;
commandline -f repaint;
end
""".strip().replace(
"\n", os.linesep
)
""".strip().replace("\n", os.linesep)
)
expect_prompt()
@@ -51,9 +49,7 @@ sendline(
set wacky_count (math $wacky_count + 1);
echo Wacky Handler $wacky_count
end
""".strip().replace(
"\n", os.linesep
)
""".strip().replace("\n", os.linesep)
)
expect_prompt()