Skip to content

Commit 5c6d842

Browse files
Bastian-KrauseEmantor
authored andcommittedSep 22, 2021
package-wide: replace format/% notation with f-strings with manual help
These changes are a mixture of manual adjustment while considering flynt's suggestions in aggressive mode (-a). No change in behavior intended. Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent c66cf13 commit 5c6d842

25 files changed

+98
-131
lines changed
 

‎labgrid/binding.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def check_active(cls, func):
9191
def wrapper(self, *_args, **_kwargs):
9292
if self.state is not BindingState.active:
9393
raise StateError(
94-
'{} has not been activated, {} cannot be called in state "{}"'.format(
95-
self, func.__qualname__, self.state.name)
94+
f'{self} has not been activated, {func.__qualname__} cannot be called in state "{self.state.name}"' # pylint: disable=line-too-long
9695
)
9796
return func(self, *_args, **_kwargs)
9897

‎labgrid/consoleloggingreporter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def get_logfile(self, event):
6464

6565
if source.name:
6666
log.write(
67-
"Labgrid Console Logfile for {} {}\n".
68-
format(source.target.name, source.name).encode("utf-8")
67+
f"Labgrid Console Logfile for {source.target.name} {source.name}\n"
68+
.encode("utf-8")
6969
)
7070
else:
7171
log.write(

‎labgrid/driver/bareboxdriver.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ def _run(self, cmd: str, *, timeout: int = 30, codec: str = "utf-8", decodeerror
8383
marker = gen_marker()
8484
# hide marker from expect
8585
hidden_marker = f'"{marker[:4]}""{marker[4:]}"'
86-
cmp_command = '''echo -o /cmd {cmd}; echo {marker}; sh /cmd; echo {marker} $?;'''.format(
87-
cmd=shlex.quote(cmd), marker=hidden_marker)
86+
cmp_command = f'''echo -o /cmd {shlex.quote(cmd)}; echo {hidden_marker}; sh /cmd; echo {hidden_marker} $?;''' # pylint: disable=line-too-long
8887
if self._status == 1:
8988
self.console.sendline(cmp_command)
9089
_, _, match, _ = self.console.expect(
91-
r'{marker}(.*){marker}\s+(\d+)\s+.*{prompt}'.format(
92-
marker=marker, prompt=self.prompt),
90+
rf'{marker}(.*){marker}\s+(\d+)\s+.*{self.prompt}',
9391
timeout=timeout)
9492
# Remove VT100 Codes and split by newline
9593
data = self.re_vt100.sub('', match.group(1).decode('utf-8')).split('\r\n')[1:-1]
@@ -185,8 +183,9 @@ def _await_prompt(self):
185183
self.console.sendline("")
186184

187185
if timeout.expired:
188-
raise TIMEOUT("Timeout of {} seconds exceeded during waiting for login"
189-
.format(self.login_timeout))
186+
raise TIMEOUT(
187+
f"Timeout of {self.login_timeout} seconds exceeded during waiting for login" # pylint: disable=line-too-long
188+
)
190189

191190
last_before = before
192191

‎labgrid/driver/manualswitchdriver.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ def set(self, status):
2727
description = self.name
2828

2929
self.target.interact(
30-
"Set {description} for target {name} to {status} and press enter".format(
31-
description=description,
32-
name=self.target.name,
33-
status="ON" if status else "OFF",
34-
)
30+
f"Set {description} for target {self.target.name} to {'ON' if status else 'OFF'} and press enter" # pylint: disable=line-too-long
3531
)
3632
self.status = status
3733

‎labgrid/driver/onewiredriver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def __attrs_post_init__(self):
2121
self._onewire = None
2222
if "PIO" not in self.port.path:
2323
raise InvalidConfigError(
24-
"Invalid OneWire path {} (needs to be in the form of ??.????????????/PIO.?)"
25-
.format(self.port.path))
24+
f"Invalid OneWire path {self.port.path} (needs to be in the form of ??.????????????/PIO.?)" # pylint: disable=line-too-long
25+
)
2626

2727
def on_activate(self):
2828
# we can only forward if the backend knows which port to use

‎labgrid/driver/powerdriver.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ def __attrs_post_init__(self):
346346
self._port = None
347347

348348
def _build_url(self, cmd):
349-
res = "http://{}:{}/power/control/{}?hostname={}&port={}".format(
350-
self._host, self._port, cmd, self.port.pdu, self.port.index)
349+
res = f"http://{self._host}:{self._port}/power/control/{cmd}?hostname={self.port.pdu}&port={self.port.index}" # pylint: disable=line-too-long
351350
if cmd == 'reboot':
352351
res += f"&delay={math.ceil(self.delay)}"
353352
return res

‎labgrid/driver/qemudriver.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ def on_activate(self):
133133
if self.rootfs is not None:
134134
self._cmd.append("-fsdev")
135135
self._cmd.append(
136-
"local,id=rootfs,security_model=none,path={}".format(
137-
self.target.env.config.get_path(self.rootfs)))
136+
f"local,id=rootfs,security_model=none,path={self.target.env.config.get_path(self.rootfs)}") # pylint: disable=line-too-long
138137
self._cmd.append("-device")
139138
self._cmd.append(
140139
"virtio-9p-device,fsdev=rootfs,mount_tag=/dev/root")
@@ -145,8 +144,7 @@ def on_activate(self):
145144
if self.flash is not None:
146145
self._cmd.append("-drive")
147146
self._cmd.append(
148-
"if=pflash,format=raw,file={},id=nor0".format(
149-
self.target.env.config.get_image_path(self.flash)))
147+
f"if=pflash,format=raw,file={self.target.env.config.get_image_path(self.flash)},id=nor0") # pylint: disable=line-too-long
150148
if self.bios is not None:
151149
self._cmd.append("-bios")
152150
self._cmd.append(
@@ -201,8 +199,9 @@ def on(self):
201199
self.qmp = QMPMonitor(self._child.stdout, self._child.stdin)
202200
except QMPError as exc:
203201
if self._child.poll() is not None:
204-
raise IOError("QEMU process terminated with exit code {}"
205-
.format(self._child.returncode)) from exc
202+
raise IOError(
203+
f"QEMU process terminated with exit code {self._child.returncode}"
204+
) from exc
206205
raise
207206

208207
self.status = 1

‎labgrid/driver/quartushpsdriver.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ def _get_cable_number(self):
5757
regex = rf".*(\d+)\) .* \[{re.escape(self.interface.path)}]\n(.*)\n"
5858
jtag_mapping = re.search(regex, stdout.decode("utf-8"), re.MULTILINE)
5959
if jtag_mapping is None:
60-
raise ExecutionError("Could not get cable number for USB path {}"
61-
.format(self.interface.path))
60+
raise ExecutionError(
61+
f"Could not get cable number for USB path {self.interface.path}"
62+
)
6263

6364
cable_number, first_chain = jtag_mapping.groups()
6465
try:

‎labgrid/driver/shelldriver.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ def _run(self, cmd, *, timeout=30.0, codec="utf-8", decodeerrors="strict"):
9999
# hide marker from expect
100100
cmp_command = f'''MARKER='{marker[:4]}''{marker[4:]}' run {shlex.quote(cmd)}'''
101101
self.console.sendline(cmp_command)
102-
_, _, match, _ = self.console.expect(r'{marker}(.*){marker}\s+(\d+)\s+{prompt}'.format(
103-
marker=marker, prompt=self.prompt
104-
), timeout=timeout)
102+
_, _, match, _ = self.console.expect(
103+
rf'{marker}(.*){marker}\s+(\d+)\s+{self.prompt}',
104+
timeout=timeout
105+
)
105106
# Remove VT100 Codes, split by newline and remove surrounding newline
106107
data = self.re_vt100.sub('', match.group(1).decode(codec, decodeerrors)).split('\r\n')
107108
if data and not data[-1]:
@@ -198,7 +199,7 @@ def _check_prompt(self):
198199
self.console.sendline(f"echo '{marker[:4]}''{marker[4:]}'")
199200
try:
200201
self.console.expect(
201-
r"{marker}\s+{prompt}".format(marker=marker, prompt=self.prompt),
202+
rf"{marker}\s+{self.prompt}",
202203
timeout=5
203204
)
204205
self._status = 1

‎labgrid/driver/smallubootdriver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _run(self, cmd: str, *, timeout: int = 30, codec: str = "utf-8", decodeerror
8686
# handle it's error message as an echo-output.
8787
# additionally we are not able to get the command's return code and
8888
# will always return 0.
89-
cmp_command = "echo{marker}; {cmd}; echo{marker}".format(marker=marker, cmd=cmd)
89+
cmp_command = f"echo{marker}; {cmd}; echo{marker}"
9090

9191
self.console.sendline(cmp_command)
9292
_, before, _, _ = self.console.expect(self.prompt, timeout=timeout)

‎labgrid/driver/sshdriver.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,14 @@ def _start_own_master_once(self, timeout):
137137
proxy_error = open(self.tmpdir+'/proxy-stderr').read().strip()
138138
if proxy_error:
139139
raise ExecutionError(
140-
"Failed to connect to {} with {}: error from SSH ProxyCommand: {}".
141-
format(self.networkservice.address, " ".join(args), proxy_error),
140+
f"Failed to connect to {self.networkservice.address} with {' '.join(args)}: error from SSH ProxyCommand: {proxy_error}", # pylint: disable=line-too-long
142141
stdout=stdout,
143142
)
144143
except FileNotFoundError:
145144
pass
146145

147146
raise ExecutionError(
148-
"Failed to connect to {} with {}: return code {}".
149-
format(self.networkservice.address, " ".join(args), return_value),
147+
f"Failed to connect to {self.networkservice.address} with {' '.join(args)}: return code {return_value}", # pylint: disable=line-too-long
150148
stdout=stdout,
151149
)
152150
except subprocess.TimeoutExpired:
@@ -275,7 +273,7 @@ def forward_local_port(self, remoteport, localport=None):
275273
if localport is None:
276274
localport = get_free_port()
277275

278-
forward = "-L%d:localhost:%d" % (localport, remoteport)
276+
forward = f"-L{localport:d}:localhost:{remoteport:d}"
279277
with self._forward(forward):
280278
yield localport
281279

@@ -297,7 +295,7 @@ def forward_remote_port(self, remoteport, localport):
297295
if not self._check_keepalive():
298296
raise ExecutionError("Keepalive no longer running")
299297

300-
forward = "-R%d:localhost:%d" % (remoteport, localport)
298+
forward = f"-R{remoteport:d}:localhost:{localport:d}"
301299
with self._forward(forward):
302300
yield
303301

@@ -442,12 +440,7 @@ def get(self, filename, destination="."):
442440

443441
def _cleanup_own_master(self):
444442
"""Exit the controlmaster and delete the tmpdir"""
445-
complete_cmd = "ssh -x -o ControlPath={cpath} -O exit -p {port} -l {user} {host}".format(
446-
cpath=self.control,
447-
port=self.networkservice.port,
448-
user=self.networkservice.username,
449-
host=self.networkservice.address
450-
).split(' ')
443+
complete_cmd = f"ssh -x -o ControlPath={self.control} -O exit -p {self.networkservice.port} -l {self.networkservice.username} {self.networkservice.address}".split(' ') # pylint: disable=line-too-long
451444
res = subprocess.call(
452445
complete_cmd,
453446
stdin=subprocess.DEVNULL,

‎labgrid/driver/ubootdriver.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ def _run(self, cmd: str, *, timeout: int = 30, codec: str = "utf-8", decodeerror
7373
# TODO: use codec, decodeerrors
7474
# TODO: Shell Escaping for the U-Boot Shell
7575
marker = gen_marker()
76-
cmp_command = """echo '{}''{}'; {}; echo "$?"; echo '{}''{}';""".format(
77-
marker[:4],
78-
marker[4:],
79-
cmd,
80-
marker[:4],
81-
marker[4:],
82-
)
76+
cmp_command = f"""echo '{marker[:4]}''{marker[4:]}'; {cmd}; echo "$?"; echo '{marker[:4]}''{marker[4:]}';""" # pylint: disable=line-too-long
8377
if self._status == 1:
8478
self.console.sendline(cmp_command)
8579
_, before, _, _ = self.console.expect(self.prompt, timeout=timeout)

‎labgrid/driver/usbtmc/keysight_dsox2000.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
def get_channel_info(driver, channel):
22
info = {}
3-
info['BWLIMIT'] = driver.get_bool(":CHANnel%i:BWLimit?" % channel)
4-
info['COUPLING'] = driver.get_str(":CHANnel%i:COUPling?" % channel).strip()
5-
info['LABEL'] = driver.get_str(":CHANnel%i:LABel?" % channel)
6-
info['PROBE'] = driver.get_decimal(":CHANnel%i:PROBe?" % channel)
7-
info['PROBE:HEAD'] = driver.get_str(":CHANnel%i:PROBe:HEAD?" % channel).strip()
8-
info['PROBE:ID'] = driver.get_str(":CHANnel%i:PROBe:ID?" % channel).strip()
9-
info['PROBE:SKEW'] = driver.get_decimal(":CHANnel%i:PROBe:SKEW?" % channel)
10-
info['PROBE:STYPE'] = driver.get_str(":CHANnel%i:PROBe:STYPe?" % channel).strip()
11-
info['RANGE'] = driver.get_decimal(":CHANnel%i:RANGe?" % channel)
12-
info['SCALE'] = driver.get_decimal(":CHANnel%i:SCALe?" % channel)
13-
info['UNITS'] = driver.get_str(":CHANnel%i:UNITS?" % channel).strip()
3+
info['BWLIMIT'] = driver.get_bool(f":CHANnel{channel:d}:BWLimit?")
4+
info['COUPLING'] = driver.get_str(f":CHANnel{channel:d}:COUPling?").strip()
5+
info['LABEL'] = driver.get_str(f":CHANnel{channel:d}:LABel?")
6+
info['PROBE'] = driver.get_decimal(f":CHANnel{channel:d}:PROBe?")
7+
info['PROBE:HEAD'] = driver.get_str(f":CHANnel{channel:d}:PROBe:HEAD?").strip()
8+
info['PROBE:ID'] = driver.get_str(f":CHANnel{channel:d}:PROBe:ID?").strip()
9+
info['PROBE:SKEW'] = driver.get_decimal(f":CHANnel{channel:d}:PROBe:SKEW?")
10+
info['PROBE:STYPE'] = driver.get_str(f":CHANnel{channel:d}:PROBe:STYPe?").strip()
11+
info['RANGE'] = driver.get_decimal(f":CHANnel{channel:d}:RANGe?")
12+
info['SCALE'] = driver.get_decimal(f":CHANnel{channel:d}:SCALe?")
13+
info['UNITS'] = driver.get_str(f":CHANnel{channel:d}:UNITS?").strip()
1414
return info
1515

1616
def get_channel_values(driver, channel):
17-
driver.command(":MEASURE:SOURCE CHANNEL%i" % channel)
17+
driver.command(f":MEASURE:SOURCE CHANNEL{channel:d}")
1818
info = {}
1919
info['DUTYCYCLE'] = driver.get_decimal(":MEASURE:DUTYcycle?")
2020
info['FREQUENCY'] = driver.get_decimal(":MEASURE:FREQuency?")

‎labgrid/driver/usbtmc/tektronix_tds2000.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
def get_channel_info(driver, channel):
22
info = {}
3-
info['SELECTED'] = driver.get_str("SELect:CH%i?" % channel).strip()
4-
info['BWLIMIT'] = driver.get_str(":CH%i:BANdwidth?" % channel).strip()
5-
info['COUPLING'] = driver.get_str(":CH%i:COUPling?" % channel).strip()
6-
info['INVERT'] = driver.get_str(":CH%i:INVert?" % channel).strip()
7-
info['POSITION'] = driver.get_decimal(":CH%i:POSition?" % channel)
8-
info['PROBE'] = driver.get_decimal(":CH%i:PRObe?" % channel)
9-
info['SCALE'] = driver.get_decimal(":CH%i:SCAle?" % channel)
3+
info['SELECTED'] = driver.get_str(f"SELect:CH{channel:d)}?").strip()
4+
info['BWLIMIT'] = driver.get_str(f":CH{channel:d}:BANdwidth?").strip()
5+
info['COUPLING'] = driver.get_str(f":CH{channel:d}:COUPling?").strip()
6+
info['INVERT'] = driver.get_str(f":CH{channel:d}:INVert?").strip()
7+
info['POSITION'] = driver.get_decimal(f":CH{channel:d}:POSition?")
8+
info['PROBE'] = driver.get_decimal(f":CH{channel:d}:PRObe?")
9+
info['SCALE'] = driver.get_decimal(f":CH{channel:d}:SCAle?")
1010
return info
1111

1212
def get_channel_values(driver, channel):
13-
driver.command(":MEASUrement:IMMed:SOUrce1 CH%i" % channel)
13+
driver.command(f":MEASUrement:IMMed:SOUrce1 CH{channel:d}")
1414
info = {}
1515
driver.command(":MEASUrement:IMMed:TYPe MEAN")
1616
info['MEAN'] = driver.get_decimal(":MEASUrement:IMMed:VALue?")

‎labgrid/driver/usbvideodriver.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def select_caps(self, hint=None):
4242
for name, caps in variants:
4343
if name == variant:
4444
return caps
45-
raise InvalidConfigError("Unkown video format {} for device {:04x}:{:04x}".format(
46-
variant, self.video.vendor_id, self.video.model_id))
45+
raise InvalidConfigError(
46+
f"Unkown video format {variant} for device {self.video.vendor_id:04x}:{self.video.model_id:04x}" # pylint: disable=line-too-long
47+
)
4748

4849
def get_pipeline(self, path, caps, controls=None):
4950
match = (self.video.vendor_id, self.video.model_id)

‎labgrid/factory.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def make_resource(self, target, resource, name, args):
123123
r = cls(target, name, **args)
124124
except TypeError as e:
125125
raise InvalidConfigError(
126-
f"failed to create {resource} for target '{target}' using {args} ") from e
126+
f"failed to create {resource} for target '{target}' using {args} "
127+
) from e
127128
return r
128129

129130
def make_driver(self, target, driver, name, args):

‎labgrid/pytestplugin/hooks.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ def pytest_collection_modifyitems(config, items):
7676
missing_feature = want_feature - have_feature
7777
if missing_feature:
7878
if len(missing_feature) == 1:
79-
skip = pytest.mark.skip(reason="Skipping because feature \"{}\" is not supported"
80-
.format(missing_feature))
79+
skip = pytest.mark.skip(
80+
reason=f'Skipping because feature "{missing_feature}" is not supported'
81+
)
8182
else:
82-
skip = pytest.mark.skip(reason="Skipping because features \"{}\" are not supported"
83-
.format(missing_feature))
83+
skip = pytest.mark.skip(
84+
reason=f'Skipping because features "{missing_feature}" are not supported'
85+
)
8486
item.add_marker(skip)

0 commit comments

Comments
 (0)
Please sign in to comment.