Skip to content

Commit c88e34a

Browse files
committed
tc-build: Switch to ruff for Python formatting
We started using ruff for linting a while ago. Since then, it has grown a formatting option, which is quite fast. While it is a little less flexible than YAPF, we don't customize it much other than style and line length, the latter of which ruff also allows us to customize. Switch to ruff for formatting. Most of the changes end up making the code a little more readable, at the expense of some extra lines. Switch to the generic fmt comments instead of the yapf specific ones. Use the option to preserve our quoting style, which uses single quotes for string literals and double quotes for f-string or raw strings. Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 52a278c commit c88e34a

13 files changed

Lines changed: 444 additions & 349 deletions

.style.yapf

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Run `./build-rust.py -h` for more options and information.
158158

159159
This repository openly welcomes pull requests! There are a few presubmit checks that run to make sure the code stays consistently formatted and free of bugs.
160160

161-
1. All Python files must be passed through [`ruff`](https://github.com/astral-sh/ruff) for linting and [`yapf`](https://github.com/google/yapf) for style.
161+
1. All Python files must be passed through [`ruff`](https://github.com/astral-sh/ruff) for linting and style via `ruff check .` and `ruff format .`.
162162

163163
2. All shell files must be passed through [`shellcheck`](https://github.com/koalaman/shellcheck) for linting and [`shfmt`](https://github.com/mvdan/sh) (specifically `shfmt -ci -i 4 -w`) for style.
164164

build-binutils.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,62 @@
1111
LATEST_BINUTILS_RELEASE = (2, 46, 0)
1212

1313
parser = ArgumentParser()
14-
parser.add_argument('-B',
15-
'--binutils-folder',
16-
help='''
14+
parser.add_argument(
15+
'-B',
16+
'--binutils-folder',
17+
help='''
1718
By default, the script will download a copy of the binutils source in the src folder within
1819
the same folder as this script. If you have your own copy of the binutils source that you
1920
would like to build from, pass it to this parameter. It can be either an absolute or
2021
relative path.
2122
''',
22-
type=str)
23-
parser.add_argument('-b',
24-
'--build-folder',
25-
help='''
23+
type=str,
24+
)
25+
parser.add_argument(
26+
'-b',
27+
'--build-folder',
28+
help='''
2629
By default, the script will create a "build/binutils" folder in the same folder as this
2730
script then build each target in its own folder within that containing folder. If you
2831
would like the containing build folder to be somewhere else, pass it to this parameter.
2932
that done somewhere else, pass it to this parameter. It can be either an absolute or
3033
relative path.
3134
''',
32-
type=str)
33-
parser.add_argument('-i',
34-
'--install-folder',
35-
help='''
35+
type=str,
36+
)
37+
parser.add_argument(
38+
'-i',
39+
'--install-folder',
40+
help='''
3641
By default, the script will build binutils but stop before installing it. To install
3742
them into a prefix, pass it to this parameter. This can be either an absolute or
3843
relative path.
3944
''',
40-
type=str)
41-
parser.add_argument('-m',
42-
'--march',
43-
metavar='ARCH',
44-
help='''
45+
type=str,
46+
)
47+
parser.add_argument(
48+
'-m',
49+
'--march',
50+
metavar='ARCH',
51+
help='''
4552
Add -march=ARCH to CFLAGS to optimize the toolchain for the processor that it will be
4653
running on.
4754
''',
48-
type=str)
49-
parser.add_argument('--show-build-commands',
50-
help='''
55+
type=str,
56+
)
57+
parser.add_argument(
58+
'--show-build-commands',
59+
help='''
5160
By default, the script only shows the output of the comands it is running. When this option
5261
is enabled, the invocations of configure and make will be shown to help with reproducing
5362
issues outside of the script.
5463
''',
55-
action='store_true')
56-
parser.add_argument('-t',
57-
'--targets',
58-
help='''
64+
action='store_true',
65+
)
66+
parser.add_argument(
67+
'-t',
68+
'--targets',
69+
help='''
5970
The script can build binutils targeting arm-linux-gnueabi, aarch64-linux-gnu,
6071
mips-linux-gnu, mipsel-linux-gnu, powerpc-linux-gnu, powerpc64-linux-gnu,
6172
powerpc64le-linux-gnu, riscv64-linux-gnu, s390x-linux-gnu, and x86_64-linux-gnu.
@@ -64,7 +75,8 @@
6475
specific targets only, pass them to this script. It can be either the full target
6576
or just the first part (arm, aarch64, x86_64, etc).
6677
''',
67-
nargs='+')
78+
nargs='+',
79+
)
6880
args = parser.parse_args()
6981

7082
script_start = time.time()

0 commit comments

Comments
 (0)