Skip to content

Commit a32b244

Browse files
committed
maint: refactor to f-strings outside logging
1 parent 45944ce commit a32b244

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

jupyterhub_idle_culler/__init__.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ async def fetch_paginated(req):
165165
# Starting with jupyterhub 1.3.0 the users can be filtered in the server
166166
# using the `state` filter parameter. "ready" means all users who have any
167167
# ready servers (running, not pending).
168-
auth_header = {"Authorization": "token %s" % api_token}
169-
resp = await fetch(HTTPRequest(url=url + "/", headers=auth_header))
168+
auth_header = {"Authorization": f"token {api_token}"}
169+
resp = await fetch(HTTPRequest(url=f"{url}/", headers=auth_header))
170170

171171
resp_model = json.loads(resp.body.decode("utf8", "replace"))
172172
state_filter = V(resp_model["version"]) >= STATE_FILTER_MIN_VERSION
@@ -183,7 +183,7 @@ async def handle_server(user, server_name, server, max_age, inactive_limit):
183183
"""
184184
log_name = user["name"]
185185
if server_name:
186-
log_name = "{}/{}".format(user["name"], server_name)
186+
log_name = f"{user['name']}/{server_name}"
187187
if server.get("pending"):
188188
app_log.warning(
189189
"Not culling server %s with pending %s", log_name, server["pending"]
@@ -271,14 +271,18 @@ async def handle_server(user, server_name, server, max_age, inactive_limit):
271271
# for starting again or stopped and removed. To remove the named
272272
# server we have to pass an additional option in the body of our
273273
# DELETE request.
274-
delete_url = url + "/users/{}/servers/{}".format(
274+
delete_url = "{}/users/{}/servers/{}".format(
275+
url,
275276
quote(user["name"]),
276277
quote(server["name"]),
277278
)
278279
if remove_named_servers:
279280
body = json.dumps({"remove": True})
280281
else:
281-
delete_url = url + "/users/%s/server" % quote(user["name"])
282+
delete_url = "{}/users/{}/server".format(
283+
url,
284+
quote(user["name"]),
285+
)
282286

283287
req = HTTPRequest(
284288
url=delete_url,
@@ -372,24 +376,20 @@ async def handle_user(user):
372376
# which doesn't define the 'started' field
373377
if age is not None and age.total_seconds() >= max_age:
374378
app_log.info(
375-
"Culling user %s (age: %s, inactive for %s)",
376-
user["name"],
377-
format_td(age),
378-
format_td(inactive),
379+
f"Culling user {user['name']} "
380+
f"(age: {format_td(age)}, inactive for {format_td(inactive)})"
379381
)
380382
should_cull = True
381383

382384
if not should_cull:
383385
app_log.debug(
384-
"Not culling user %s (created: %s, last active: %s)",
385-
user["name"],
386-
format_td(age),
387-
format_td(inactive),
386+
f"Not culling user {user['name']} "
387+
f"(created: {format_td(age)}, last active: {format_td(inactive)})"
388388
)
389389
return False
390390

391391
req = HTTPRequest(
392-
url=url + "/users/%s" % user["name"], method="DELETE", headers=auth_header
392+
url=f"{url}/users/{user['name']}", method="DELETE", headers=auth_header
393393
)
394394
await fetch(req)
395395
return True
@@ -400,11 +400,10 @@ async def handle_user(user):
400400
if api_page_size:
401401
params["limit"] = str(api_page_size)
402402

403-
users_url = url + "/users"
404-
405403
# If we filter users by state=ready then we do not get back any which
406404
# are inactive, so if we're also culling users get the set of users which
407405
# are inactive and see if they should be culled as well.
406+
users_url = f"{url}/users"
408407
if state_filter and cull_users:
409408
inactive_params = {"state": "inactive"}
410409
inactive_params.update(params)

0 commit comments

Comments
 (0)