chore: add pyupgrade pre-commit hook

- add --py3-plus flag to pyupgrade hook
- add --py36-plus flag to pyupgrade hook
This commit is contained in:
jo 2022-01-25 23:45:00 +01:00 committed by Kyle Robbertze
parent 21aaf9bca1
commit 32cb67806a
26 changed files with 90 additions and 86 deletions

View file

@ -35,7 +35,7 @@ class IncompleteUrl(UrlException):
self.url = url
def __str__(self):
return "Incomplete url: '{}'".format(self.url)
return f"Incomplete url: '{self.url}'"
class UrlBadParam(UrlException):
@ -44,7 +44,7 @@ class UrlBadParam(UrlException):
self.param = param
def __str__(self):
return "Bad param '{}' passed into url: '{}'".format(self.param, self.url)
return f"Bad param '{self.param}' passed into url: '{self.url}'"
class KeyAuth(AuthBase):
@ -52,7 +52,7 @@ class KeyAuth(AuthBase):
self.key = key
def __call__(self, r):
r.headers["Authorization"] = "Api-Key {}".format(self.key)
r.headers["Authorization"] = f"Api-Key {self.key}"
return r
@ -195,7 +195,7 @@ class RequestProvider:
if attr in self:
return self.requests[attr]
else:
return super(RequestProvider, self).__getattribute__(attr)
return super().__getattribute__(attr)
def time_in_seconds(value):

View file

@ -126,7 +126,7 @@ api_config["bin_dir"] = "/usr/lib/airtime/api_clients/"
################################################################################
# Airtime API Version 1 Client
################################################################################
class AirtimeApiClient(object):
class AirtimeApiClient:
def __init__(self, logger=None, config_path="/etc/airtime/airtime.conf"):
if logger is None:
self.logger = logging
@ -282,7 +282,7 @@ class AirtimeApiClient(object):
if self.config["general"]["base_dir"].startswith("/"):
self.config["general"]["base_dir"] = self.config["general"]["base_dir"][1:]
protocol = get_protocol(self.config)
url = "%s://%s:%s/%s%s/%s" % (
url = "{}://{}:{}/{}{}/{}".format(
protocol,
self.config["general"]["base_url"],
str(self.config["general"]["base_port"]),
@ -298,7 +298,7 @@ class AirtimeApiClient(object):
if self.config["general"]["base_dir"].startswith("/"):
self.config["general"]["base_dir"] = self.config["general"]["base_dir"][1:]
protocol = get_protocol(self.config)
url = "%s://%s:@%s:%s/%s/%s" % (
url = "{}://{}:@{}:{}/{}/{}".format(
protocol,
self.config["general"]["api_key"],
self.config["general"]["base_url"],
@ -348,9 +348,7 @@ class AirtimeApiClient(object):
# Note that we must prefix every key with: mdX where x is a number
# Is there a way to format the next line a little better? The
# parenthesis make the code almost unreadable
md_list = dict(
(("md%d" % i), json.dumps(md)) for i, md in enumerate(valid_actions)
)
md_list = {("md%d" % i): json.dumps(md) for i, md in enumerate(valid_actions)}
# For testing we add the following "dry" parameter to tell the
# controller not to actually do any changes
if dry:

View file

@ -53,7 +53,7 @@ class AirtimeApiClient:
str_end = end_time.isoformat(timespec="seconds")
data = self.services.schedule_url(
params={
"ends__range": ("{}Z,{}Z".format(str_current, str_end)),
"ends__range": (f"{str_current}Z,{str_end}Z"),
"is_valid": True,
"playout_status__gt": 0,
}
@ -104,7 +104,7 @@ class AirtimeApiClient:
# Stream events are instantaneous
current["end"] = current["start"]
result["{}_0".format(key)] = {
result[f"{key}_0"] = {
"id": current["id"],
"type": "stream_output_start",
"start": current["start"],
@ -123,7 +123,7 @@ class AirtimeApiClient:
"independent_event": current["independent_event"],
}
result["{}_0".format(end.isoformat())] = {
result[f"{end.isoformat()}_0"] = {
"type": "stream_output_end",
"start": current["end"],
"end": current["end"],