From 30fe6e6d499967b94e6a3af689aec2bb307804af Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Thu, 3 Sep 2020 00:31:47 +0800 Subject: [PATCH 1/2] Use f-string for better readability Since we are targeting 3.7+, it should be safe to use them now. --- nvchecker/core.py | 4 ++-- nvchecker/ctxvars.py | 2 +- nvchecker/slogconf.py | 2 +- nvchecker_source/gitea.py | 2 +- nvchecker_source/github.py | 9 ++++----- scripts/maintained_in_aur | 4 ++-- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/nvchecker/core.py b/nvchecker/core.py index e753eeb..e74a88a 100644 --- a/nvchecker/core.py +++ b/nvchecker/core.py @@ -57,7 +57,7 @@ def add_common_arguments(parser: argparse.ArgumentParser) -> None: parser.add_argument('-c', '--file', metavar='FILE', type=str, default=default_config, - help='software version configuration file [default: %s]' % default_config) + help=f'software version configuration file [default: {default_config}]') def process_common_arguments(args: argparse.Namespace) -> bool: '''return True if should stop''' @@ -94,7 +94,7 @@ def process_common_arguments(args: argparse.Namespace) -> bool: if args.version: progname = os.path.basename(sys.argv[0]) - print('%s v%s' % (progname, __version__)) + print(f'{progname} v{__version__}') return True return False diff --git a/nvchecker/ctxvars.py b/nvchecker/ctxvars.py index 2f5b49a..e9daf71 100644 --- a/nvchecker/ctxvars.py +++ b/nvchecker/ctxvars.py @@ -8,7 +8,7 @@ from typing import Optional from . import __version__ -DEFAULT_USER_AGENT = 'lilydjwg/nvchecker %s' % __version__ +DEFAULT_USER_AGENT = f'lilydjwg/nvchecker {__version__}' tries = ContextVar('tries', default=1) proxy: ContextVar[Optional[str]] = ContextVar('proxy', default=None) diff --git a/nvchecker/slogconf.py b/nvchecker/slogconf.py index c0db526..fefb86e 100644 --- a/nvchecker/slogconf.py +++ b/nvchecker/slogconf.py @@ -27,7 +27,7 @@ def _console_msg(event): msg = evt if 'name' in event: - msg = '%s: %s' % (event['name'], msg) + msg = f"{event['name']}: {msg}" del event['name'] event['msg'] = msg diff --git a/nvchecker_source/gitea.py b/nvchecker_source/gitea.py index 17cb558..0ff3a93 100644 --- a/nvchecker_source/gitea.py +++ b/nvchecker_source/gitea.py @@ -36,7 +36,7 @@ async def get_version( # Set private token if token exists. headers = {} if token: - headers["Authorization"] = 'token %s' % token + headers["Authorization"] = f'token {token}' data = await cache.get_json(url, headers = headers) if use_max_tag: diff --git a/nvchecker_source/github.py b/nvchecker_source/github.py index 36414b7..5d4b6b8 100644 --- a/nvchecker_source/github.py +++ b/nvchecker_source/github.py @@ -46,7 +46,7 @@ async def get_latest_tag(key: Tuple[str, str, str]) -> str: repo, query, token = key owner, reponame = repo.split('/') headers = { - 'Authorization': 'bearer %s' % token, + f'Authorization': 'bearer {token}', 'Content-Type': 'application/json', } q = QUERY_LATEST_TAG.format( @@ -109,7 +109,7 @@ async def get_version_real( 'Accept': 'application/vnd.github.quicksilver-preview+json', } if token: - headers['Authorization'] = 'token %s' % token + headers['Authorization'] = f'token {token}' data = await cache.get_json(url, headers = headers) @@ -140,9 +140,8 @@ def check_ratelimit(exc, name): n = int(res.headers.get('X-RateLimit-Remaining', -1)) if n == 0: reset = int(res.headers.get('X-RateLimit-Reset')) - logger.error('rate limited, resetting at %s. ' - 'Or get an API token to increase the allowance if not yet' - % time.ctime(reset), + logger.error(f'rate limited, resetting at {time.ctime(reset)}. ' + 'Or get an API token to increase the allowance if not yet', name = name, reset = reset) else: diff --git a/scripts/maintained_in_aur b/scripts/maintained_in_aur index c351996..37dff6b 100755 --- a/scripts/maintained_in_aur +++ b/scripts/maintained_in_aur @@ -9,10 +9,10 @@ import json import urllib.request def main(user): - url = 'https://aur.archlinux.org/rpc.php?type=msearch&arg=' + user + url = f'https://aur.archlinux.org/rpc.php?type=msearch&arg={user}' res = urllib.request.urlopen(url) if res.status != 200: - sys.exit('Error: %d %s' % (res.status, res.reason)) + sys.exit(f'Error: {res.status} {res.reason}') d = res.read().decode('utf-8') d = json.loads(d) print('\n'.join(sorted(pkg['Name'] for pkg in d['results']))) From 52ab39d92e6c329ca1644a30256d7fbaa7cb3761 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Thu, 3 Sep 2020 04:38:14 +0800 Subject: [PATCH 2/2] Fix f-string in github source --- nvchecker_source/github.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvchecker_source/github.py b/nvchecker_source/github.py index 5d4b6b8..0920d54 100644 --- a/nvchecker_source/github.py +++ b/nvchecker_source/github.py @@ -46,7 +46,7 @@ async def get_latest_tag(key: Tuple[str, str, str]) -> str: repo, query, token = key owner, reponame = repo.split('/') headers = { - f'Authorization': 'bearer {token}', + 'Authorization': f'bearer {token}', 'Content-Type': 'application/json', } q = QUERY_LATEST_TAG.format(