Skip to content

Commit 1ea8112

Browse files
committed
repo: format Python files with ruff
Run `ruff format` on all Python files, enforce afterwards. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent ad503ea commit 1ea8112

File tree

16 files changed

+2958
-2065
lines changed

16 files changed

+2958
-2065
lines changed

src/west/app/config.py

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,49 +83,67 @@
8383
class Config(WestCommand):
8484
def __init__(self):
8585
super().__init__(
86-
'config',
87-
'get or set config file values',
88-
CONFIG_DESCRIPTION,
89-
requires_workspace=False)
86+
'config', 'get or set config file values', CONFIG_DESCRIPTION, requires_workspace=False
87+
)
9088

9189
def do_add_parser(self, parser_adder):
9290
parser = parser_adder.add_parser(
9391
self.name,
9492
help=self.help,
9593
formatter_class=argparse.RawDescriptionHelpFormatter,
9694
description=self.description,
97-
epilog=CONFIG_EPILOG)
95+
epilog=CONFIG_EPILOG,
96+
)
9897

9998
group = parser.add_argument_group(
10099
"action to perform (give at most one)"
101100
).add_mutually_exclusive_group()
102101

103-
group.add_argument('-l', '--list', action='store_true',
104-
help='list all options and their values')
105-
group.add_argument('-d', '--delete', action='store_true',
106-
help='delete an option in one config file')
107-
group.add_argument('-D', '--delete-all', action='store_true',
108-
help="delete an option everywhere it's set")
109-
group.add_argument('-a', '--append', action='store_true',
110-
help='append to an existing value')
102+
group.add_argument(
103+
'-l', '--list', action='store_true', help='list all options and their values'
104+
)
105+
group.add_argument(
106+
'-d', '--delete', action='store_true', help='delete an option in one config file'
107+
)
108+
group.add_argument(
109+
'-D', '--delete-all', action='store_true', help="delete an option everywhere it's set"
110+
)
111+
group.add_argument(
112+
'-a', '--append', action='store_true', help='append to an existing value'
113+
)
111114

112115
group = parser.add_argument_group(
113116
"configuration file to use (give at most one)"
114117
).add_mutually_exclusive_group()
115118

116-
group.add_argument('--system', dest='configfile',
117-
action='store_const', const=SYSTEM,
118-
help='system-wide file')
119-
group.add_argument('--global', dest='configfile',
120-
action='store_const', const=GLOBAL,
121-
help='global (user-wide) file')
122-
group.add_argument('--local', dest='configfile',
123-
action='store_const', const=LOCAL,
124-
help="this workspace's file")
125-
126-
parser.add_argument('name', nargs='?',
127-
help='''config option in section.key format;
128-
e.g. "foo.bar" is section "foo", key "bar"''')
119+
group.add_argument(
120+
'--system',
121+
dest='configfile',
122+
action='store_const',
123+
const=SYSTEM,
124+
help='system-wide file',
125+
)
126+
group.add_argument(
127+
'--global',
128+
dest='configfile',
129+
action='store_const',
130+
const=GLOBAL,
131+
help='global (user-wide) file',
132+
)
133+
group.add_argument(
134+
'--local',
135+
dest='configfile',
136+
action='store_const',
137+
const=LOCAL,
138+
help="this workspace's file",
139+
)
140+
141+
parser.add_argument(
142+
'name',
143+
nargs='?',
144+
help='''config option in section.key format;
145+
e.g. "foo.bar" is section "foo", key "bar"''',
146+
)
129147
parser.add_argument('value', nargs='?', help='value to set "name" to')
130148

131149
return parser
@@ -136,8 +154,7 @@ def do_run(self, args, user_args):
136154
if args.name:
137155
self.parser.error('-l cannot be combined with name argument')
138156
elif not args.name:
139-
self.parser.error('missing argument name '
140-
'(to list all options and values, use -l)')
157+
self.parser.error('missing argument name (to list all options and values, use -l)')
141158
elif args.append:
142159
if args.value is None:
143160
self.parser.error('-a requires both name and value')
@@ -174,16 +191,14 @@ def delete(self, args):
174191
return
175192
except KeyError as err:
176193
if i == len(configfiles) - 1:
177-
self.dbg(
178-
f'{args.name} was not set in requested location(s)')
194+
self.dbg(f'{args.name} was not set in requested location(s)')
179195
raise CommandError(returncode=1) from err
180196
except PermissionError as pe:
181197
self._perm_error(pe, configfile, args.name)
182198

183199
def check_config(self, option):
184200
if '.' not in option:
185-
self.die(f'invalid configuration option "{option}"; '
186-
'expected "section.key" format')
201+
self.die(f'invalid configuration option "{option}"; expected "section.key" format')
187202

188203
def read(self, args):
189204
self.check_config(args.name)
@@ -199,8 +214,7 @@ def append(self, args):
199214
where = args.configfile or LOCAL
200215
value = self.config.get(args.name, configfile=where)
201216
if value is None:
202-
self.die(f'option {args.name} not found in the {where.name.lower()} '
203-
'configuration file')
217+
self.die(f'option {args.name} not found in the {where.name.lower()} configuration file')
204218
args.value = value + args.value
205219
self.write(args)
206220

@@ -213,7 +227,5 @@ def write(self, args):
213227
self._perm_error(pe, what, args.name)
214228

215229
def _perm_error(self, pe, what, name):
216-
rootp = ('; are you root/administrator?' if what in [SYSTEM, ALL]
217-
else '')
218-
self.die(f"can't update {name}: "
219-
f"permission denied when writing {pe.filename}{rootp}")
230+
rootp = '; are you root/administrator?' if what in [SYSTEM, ALL] else ''
231+
self.die(f"can't update {name}: permission denied when writing {pe.filename}{rootp}")

0 commit comments

Comments
 (0)