use f-string consistently
This commit is contained in:
@@ -72,7 +72,7 @@ class Acquisition(BaseAcquisition):
|
||||
|
||||
def __repr__(self):
|
||||
name = typename(self)
|
||||
return "{}: {}/{}".format(name, self.instrument, self.pgroup) #TODO
|
||||
return f"{name}: {self.instrument}/{self.pgroup}" #TODO
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class DIAAcquisition(BaseAcquisition):
|
||||
self.default_dir = default_dir
|
||||
|
||||
if not api_address:
|
||||
api_address = "http://sf-daq-{}:10000".format(instrument)
|
||||
api_address = f"http://sf-daq-{instrument}:10000"
|
||||
|
||||
self.api_address = api_address
|
||||
self.client = DetectorIntegrationClient(api_address)
|
||||
@@ -91,7 +91,7 @@ class DIAAcquisition(BaseAcquisition):
|
||||
res = []
|
||||
for client in self.active_clients:
|
||||
client = client.upper()
|
||||
fn = "{}.{}.h5".format(base, client)
|
||||
fn = f"{base}.{client}.h5"
|
||||
res.append(fn)
|
||||
return res
|
||||
|
||||
@@ -146,7 +146,7 @@ class DIAAcquisition(BaseAcquisition):
|
||||
def __repr__(self):
|
||||
clients = self.active_clients
|
||||
clients = ", ".join(clients)
|
||||
return "Detector Integration API on {} (status: {})\nClients: {}".format(self.api_address, self.status, clients)
|
||||
return f"Detector Integration API on {self.api_address} (status: {self.status})\nClients: {clients}"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class DIAConfig:
|
||||
pgroup = "p" + pgroup
|
||||
|
||||
if len(pgroup) != 6:
|
||||
msg = "invalid pgroup \"{}\" should have the form \"p12345\"".format(pgroup)
|
||||
msg = f"invalid pgroup \"{pgroup}\" should have the form \"p12345\""
|
||||
raise ValueError(msg)
|
||||
|
||||
self.pgroup = pgroup
|
||||
|
||||
@@ -10,7 +10,7 @@ class DummyAcquisition(Acquisition):
|
||||
print("extra kwargs:", kwargs)
|
||||
args = (filename, n_pulses, channels)
|
||||
args = ", ".join(repr(i) for i in args)
|
||||
print("acquire({})".format(args))
|
||||
print(f"acquire({args})")
|
||||
print(f"dummy acquire to {filename}:")
|
||||
for i in trange(n_pulses):
|
||||
sleep(1/100)
|
||||
|
||||
@@ -52,7 +52,7 @@ class FakeAcquisition(BaseAcquisition):
|
||||
def _acquire():
|
||||
args = (filename, n_pulses)
|
||||
args = ", ".join(repr(i) for i in args)
|
||||
print("acquire({})".format(args))
|
||||
print(f"acquire({args})")
|
||||
print(f"fake acquire to {filename}:")
|
||||
self.running = True
|
||||
for n in xrange(n_repeat):
|
||||
|
||||
@@ -43,7 +43,7 @@ def find_last_pedestal(clients, directory="."):
|
||||
def extract_timestamp(fn):
|
||||
fn = strip_dir(fn)
|
||||
base = fn.split(".")[0]
|
||||
assert base.startswith(PREFIX), "\"{}\" does not start with \"{}\"".format(base, PREFIX)
|
||||
assert base.startswith(PREFIX), f"\"{base}\" does not start with \"{PREFIX}\""
|
||||
timestamp = base[len(PREFIX):]
|
||||
timestamp = datetime.strptime(timestamp, TIMESTAMP_FORMAT)
|
||||
return timestamp
|
||||
|
||||
@@ -34,14 +34,14 @@ class SwissFELPaths:
|
||||
|
||||
def __repr__(self):
|
||||
lines = [
|
||||
"raw: {}".format(self.raw),
|
||||
"res: {}".format(self.res),
|
||||
f"raw: {self.raw}",
|
||||
f"res: {self.res}",
|
||||
"",
|
||||
"gain: {}".format(self.gain),
|
||||
"pede: {}".format(self.pede),
|
||||
"pede files: {}".format(self.pede_files),
|
||||
f"gain: {self.gain}",
|
||||
f"pede: {self.pede}",
|
||||
f"pede files: {self.pede_files}",
|
||||
"",
|
||||
"channels: {}".format(self.default_channel_list)
|
||||
f"channels: {self.default_channel_list}"
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
@@ -157,13 +157,13 @@ class ScanBackend:
|
||||
if not self.running:
|
||||
n -= 1 # stopped before this iteration
|
||||
break
|
||||
cprint("Scan step {} of {}".format(n+1, ntotal), color="green")
|
||||
cprint(f"Scan step {n+1} of {ntotal}", color="green")
|
||||
do_step(n, val, step_info=step_info)
|
||||
|
||||
if self.running and n+1 == ntotal:
|
||||
cprint("All scan steps done", color="green")
|
||||
else:
|
||||
cprint("Stopped during scan step {} of {}".format(n+1, ntotal), color="red")
|
||||
cprint(f"Stopped during scan step {n+1} of {ntotal}", color="red")
|
||||
|
||||
|
||||
def do_checked_step(self, *args, **kwargs):
|
||||
@@ -241,7 +241,7 @@ class ScanBackend:
|
||||
filebase = os.path.basename(self.filename)
|
||||
filename = os.path.join(filename, filebase)
|
||||
|
||||
filename += "_step{:04d}".format(istep)
|
||||
filename += f"_step{istep:04d}"
|
||||
return filename
|
||||
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class ScanInfo:
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "Scan info in {}".format(self.filename)
|
||||
return f"Scan info in {self.filename}"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class Task(BaseTask):
|
||||
|
||||
def __repr__(self):
|
||||
name = typename(self)
|
||||
return "{}: {}".format(name, self.status)
|
||||
return f"{name}: {self.status}"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class TweakPanel(wx.Panel):
|
||||
timestamp = datetime.now()
|
||||
adjname = adjustable.name
|
||||
operation = "="
|
||||
delta_pm = "{:+g}".format(delta)
|
||||
delta_pm = f"{delta:+g}"
|
||||
entry = [timestamp, adjname, operation, delta_pm]
|
||||
color = None
|
||||
readback = adjustable.get_current_value()
|
||||
@@ -166,7 +166,7 @@ class TweakPanel(wx.Panel):
|
||||
timestamp = datetime.now()
|
||||
adjname = adj.name
|
||||
operation = TWEAK_OPERATIONS.get(direction, direction)
|
||||
delta_pm = "{:+g}".format(delta)
|
||||
delta_pm = f"{delta:+g}"
|
||||
entry = [timestamp, adjname, operation, delta_pm]
|
||||
color = TWEAK_COLORS.get(direction)
|
||||
self.next_entry_line = entry
|
||||
|
||||
@@ -52,7 +52,7 @@ def ask_yes_no(question, default=None, ctrl_c="n", ctrl_d=None):
|
||||
ctrl_d = default if ctrl_d is None else ctrl_d
|
||||
|
||||
option_prompt = OPTION_PROMPTS[default]
|
||||
prompt = question + "? [{}] ".format(option_prompt)
|
||||
prompt = question + f"? [{option_prompt}] "
|
||||
|
||||
ans = None
|
||||
while ans not in ANSWERS:
|
||||
|
||||
@@ -19,7 +19,7 @@ class ChainedException(Exception):
|
||||
def printable_exception(exc):
|
||||
name = typename(exc)
|
||||
message = str(exc)
|
||||
return "{}: {}".format(name, message)
|
||||
return f"{name}: {message}"
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class printed_exception(AbstractContextManager):
|
||||
if exc_type is not None:
|
||||
name = exc_type.__name__
|
||||
message = exc_val or ""
|
||||
print("{}: {}".format(name, message))
|
||||
print(f"{name}: {message}"
|
||||
return True # this causes the with statement to suppress the exception
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -15,9 +15,9 @@ def can_create_file(filename):
|
||||
if not os.path.isfile(filename):
|
||||
return True
|
||||
|
||||
delete = ask_yes_No("File \"{}\" exists already. Would you like to delete it".format(filename))
|
||||
delete = ask_yes_No(f"File \"{filename}\" exists already. Would you like to delete it")
|
||||
if delete:
|
||||
print("Deleting \"{}\".".format(filename))
|
||||
print(f"Deleting \"{filename}\".")
|
||||
os.remove(filename)
|
||||
return True
|
||||
|
||||
@@ -30,7 +30,7 @@ def make_missing_dir(p):
|
||||
return
|
||||
|
||||
printable = p.absolute().as_posix()
|
||||
msg = "Directory \"{}\" does not exist, creating it...".format(printable)
|
||||
msg = f"Directory \"{printable}\" does not exist, creating it..."
|
||||
print(msg)
|
||||
|
||||
p.mkdir(mode=0o775, parents=True, exist_ok=True)
|
||||
|
||||
@@ -3,6 +3,6 @@ ALLOWED_VALUES = (True, False, None)
|
||||
|
||||
def check_trinary(val, allowed_values=ALLOWED_VALUES):
|
||||
if val not in allowed_values:
|
||||
raise ValueError("Trinary {} not in {}".format(repr(val), allowed_values))
|
||||
raise ValueError(f"Trinary {val!r} not in {allowed_values}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user