Skip to content

Commit b700fcc

Browse files
committed
ref: use more f-strings
1 parent c249655 commit b700fcc

19 files changed

Lines changed: 65 additions & 65 deletions

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
0.17.2
2+
- ref: use more f-strings
13
0.17.1
24
- fix: found culprit of regular segmentation faults (#14)
35
- reg: invalid use PyQt6 namespace after migration from PyQt5

dcoraid/api/ckan_api.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,19 @@ def handle_response(self, req, api_call):
180180
if rdata.startswith("Bad request"):
181181
raise APIBadRequest(rdata)
182182
else:
183-
raise ValueError(
184-
"Command did not succeed, output: '{}'".format(rdata))
183+
raise ValueError(f"Command did not succeed, output: '{rdata}'")
185184

186185
if not req.ok:
187186
error = rdata.get("error", {})
188187
e_type = error.get("__type", req.reason)
189188
etext = ""
190189
for key in error:
191190
if not key.startswith("_"):
192-
etext += "{}: {}".format(key, error[key])
191+
etext += f"{key}: {error[key]}"
193192
if not etext and len(req.reason) < 100:
194193
# Skip large html output, only use small error messages
195194
etext = req.content.decode("utf-8")
196-
msg = "{}: {} (for '{}')".format(e_type, etext, api_call)
195+
msg = f"{e_type}: {etext} (for '{api_call}')"
197196
if req.reason == "NOT FOUND":
198197
raise APINotFoundError(msg)
199198
elif req.reason == "CONFLICT":
@@ -211,8 +210,8 @@ def handle_response(self, req, api_call):
211210
elif not rdata["success"]:
212211
url_call = self.api_url + api_call
213212
raise ConnectionError(
214-
"Could not run API call '{}'! ".format(url_call)
215-
+ "Reason: {} ({})".format(req.reason, rdata["error"]))
213+
f"Could not run API call '{url_call}'! "
214+
f"Reason: {req.reason} ({rdata['error']})")
216215
return rdata
217216

218217
def copy(self):

dcoraid/dbmodel/db_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def search_dataset(self, query="*:*", filter_queries=None, circles=None,
123123
filter_queries = []
124124
# https://docs.ckan.org/en/latest/user-guide.html#search-in-detail
125125
if circles:
126-
solr_circles = ["organization:{}".format(ci) for ci in circles]
126+
solr_circles = [f"organization:{ci}" for ci in circles]
127127
if len(circles) == 1:
128128
solr_circle_query = solr_circles[0]
129129
else:
@@ -132,7 +132,7 @@ def search_dataset(self, query="*:*", filter_queries=None, circles=None,
132132
solr_circle_query = None
133133

134134
if collections:
135-
solr_collections = ["groups:{}".format(co) for co in collections]
135+
solr_collections = [f"groups:{co}" for co in collections]
136136
if len(collections) == 1:
137137
solr_collections_query = solr_collections[0]
138138
else:

dcoraid/download/job.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def get_rate_string(self):
221221
rate_label = "-- kB/s"
222222
else:
223223
if rate > 1e6:
224-
rate_label = "{:.1f} MB/s".format(rate / 1e6)
224+
rate_label = f"{rate / 1e6:.1f} MB/s"
225225
else:
226-
rate_label = "{:.0f} kB/s".format(rate / 1e3)
226+
rate_label = f"{rate / 1e3:.0f} kB/s"
227227
if state != "transfer":
228228
rate_label = "⌀ " + rate_label
229229
return rate_label
@@ -318,7 +318,7 @@ def set_state(self, state):
318318
The state is checked against :const:`JOB_STATES`
319319
"""
320320
if state not in JOB_STATES:
321-
raise ValueError("Unknown state: '{}'".format(state))
321+
raise ValueError(f"Unknown state: '{state}'")
322322
if state == "error":
323323
logger.error("Entered error state")
324324
if self.traceback:
@@ -406,9 +406,9 @@ def task_download_resource(self):
406406
self.end_time = time.perf_counter()
407407
self.set_state("downloaded")
408408
else:
409-
warnings.warn("Starting a download only possible when state is "
410-
+ "'init' or 'wait-disk', but current state is "
411-
+ "'{}'!".format(self.state))
409+
warnings.warn(f"Starting a download only possible when state is "
410+
f"'init' or 'wait-disk', but current state is "
411+
f"'{self.state}'!")
412412

413413
def task_verify_resource(self):
414414
"""Perform ETag/SHA256 verification"""
@@ -479,6 +479,6 @@ def task_verify_resource(self):
479479
self.set_state("done")
480480
elif self.state != "done": # ignore state "done" [sic!]
481481
# Only issue this warning if the download is not already done.
482-
warnings.warn("Resource verification is only possible when state "
483-
+ "is 'downloaded', but current state is "
484-
+ "'{}'!".format(self.state))
482+
warnings.warn(f"Resource verification is only possible when state "
483+
f"is 'downloaded', but current state is "
484+
f"'{self.state}'!")

dcoraid/download/queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def get_job(self, job_id):
139139
if job.job_id == job_id:
140140
return job
141141
else:
142-
raise KeyError("Job '{}' not found!".format(job_id))
142+
raise KeyError(f"Job '{job_id}' not found!")
143143

144144
def get_status(self):
145145
"""Return the status of a DownloadQueue"""

dcoraid/gui/download/widget_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def set_label_item(self, row, col, label):
198198
199199
User has to make sure that row and column count are set
200200
"""
201-
label = "{}".format(label)
201+
label = f"{label}"
202202
item = self.item(row, col)
203203
if item is None:
204204
item = QtWidgets.QTableWidgetItem(label)

dcoraid/gui/main.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,16 @@ def on_action_about(self):
145145
dcor = "https://dcor.mpl.mpg.de"
146146
gh = "DCOR-dev/DCOR-Aid"
147147
rtd = "dc.readthedocs.io"
148-
about_text = "This is the client for the <a href='{}'>".format(dcor) \
149-
+ "Deformability Cytometry Open Repository (DCOR)</a>.<br><br>" \
150-
+ "Author: Paul Müller<br>" \
151-
+ "GitHub: " \
152-
+ "<a href='https://github.com/{gh}'>{gh}</a><br>".format(gh=gh) \
153-
+ "Documentation: " \
154-
+ "<a href='https://{rtd}'>{rtd}</a><br>".format(rtd=rtd)
148+
about_text = (
149+
f"This is the client for the <a href='{dcor}'>"
150+
f"Deformability Cytometry Open Repository (DCOR)</a>.<br><br>"
151+
f"Author: Paul Müller<br>"
152+
f"GitHub: "
153+
f"<a href='https://github.com/{gh}'>{gh}</a><br>"
154+
f"Documentation: "
155+
f"<a href='https://{rtd}'>{rtd}</a><br>")
155156
QtWidgets.QMessageBox.about(self,
156-
"DCOR-Aid {}".format(__version__),
157+
f"DCOR-Aid {__version__}",
157158
about_text)
158159

159160
@QtCore.pyqtSlot(bool)
@@ -193,10 +194,10 @@ def on_action_check_update_finished(self, mdict):
193194
msg.setTextFormat(QtCore.Qt.TextFormat.RichText)
194195
text = f"You can install DCOR-Aid {ver} "
195196
if dlb is not None:
196-
text += 'from a <a href="{}">direct download</a>. '.format(dlb)
197+
text += f'from a <a href="{dlb}">direct download</a>. '
197198
else:
198199
text += 'by running `pip install --upgrade dcoraid`. '
199-
text += 'Visit the <a href="{}">official release page</a>!'.format(web)
200+
text += f'Visit the <a href="{web}">official release page</a>!'
200201
msg.setText(text)
201202
msg.exec()
202203

@@ -208,12 +209,12 @@ def on_action_software(self):
208209
requests_toolbelt,
209210
urllib3,
210211
]
211-
sw_text = "DCOR-Aid {}\n\n".format(__version__)
212-
sw_text += "Python {}\n\n".format(sys.version)
212+
sw_text = f"DCOR-Aid {__version__}\n\n"
213+
sw_text += f"Python {sys.version}\n\n"
213214
sw_text += "Modules:\n"
214215
for lib in libs:
215-
sw_text += "- {} {}\n".format(lib.__name__, lib.__version__)
216-
sw_text += "- PyQt6 {}\n".format(QtCore.QT_VERSION_STR)
216+
sw_text += f"- {lib.__name__} {lib.__version__}\n"
217+
sw_text += f"- PyQt6 {QtCore.QT_VERSION_STR}\n"
217218
sw_text += "\n Breeze icon theme by the KDE Community (LGPL)."
218219
sw_text += "\n Font-Awesome icons by Fort Awesome (CC BY 4.0)."
219220
if hasattr(sys, 'frozen'):
@@ -263,8 +264,7 @@ def excepthook(etype, value, trace):
263264
prints the standard Python header: ``Traceback (most recent
264265
call last)``.
265266
"""
266-
vinfo = "Unhandled exception in DCOR-Aid version {}:\n".format(
267-
__version__)
267+
vinfo = f"Unhandled exception in DCOR-Aid version {__version__}:\n"
268268
tmp = tb.format_exception(etype, value, trace)
269269
exception = "".join([vinfo] + tmp)
270270

dcoraid/gui/status_widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def run(self):
148148
name = user_data["name"]
149149
if not fullname:
150150
fullname = name
151-
text = "{}".format(fullname)
152-
tip = "user '{}'".format(name)
151+
text = f"{fullname}"
152+
tip = f"user '{name}'"
153153
icon = "user-lock"
154154
self.logger.info(text)
155155
self.signal.state_signal.emit(text, tip, icon, api.server)

dcoraid/gui/updater.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def check_for_update(version, ghrepo):
3737

3838
def check_release(ghrepo="user/repo", version=None, timeout=20):
3939
"""Check GitHub repository for latest release"""
40-
url = "https://api.github.com/repos/{}/releases/latest".format(ghrepo)
40+
url = f"https://api.github.com/repos/{ghrepo}/releases/latest"
4141
if "GITHUB_TOKEN" in os.environ:
4242
hdr = {'Authorization': os.environ["GITHUB_TOKEN"]}
4343
else:
4444
hdr = {}
45-
web = "https://github.com/{}/releases".format(ghrepo)
45+
web = f"https://github.com/{ghrepo}/releases"
4646
errors = None # error messages (str)
4747
update = False # whether an update is available
4848
binary = None # download link to binary file

dcoraid/gui/upload/circle_mgr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def ask_for_new_circle(parent_widget):
4141
+ "'{}').".format(ud["name"])
4242
+ "\n\nTo proceed with Circle creation, please choose a name:",
4343
QtWidgets.QLineEdit.EchoMode.Normal,
44-
"{}'s Circle".format(name))
44+
f"{name}'s Circle")
4545
if ok_pressed and text != '':
4646
cname = "user-circle-{}".format(ud["name"])
4747
cdict = api.post("organization_create",

0 commit comments

Comments
 (0)