From 0ef071a91d5a21806587f36f76e9a61c7d55e31a Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Mon, 2 Mar 2020 11:24:29 +0200 Subject: [PATCH] dspace_statistics_api: Use f-strings instead of format() We had previously been avoiding the f-strings because we needed to run on Python 3.5 and they were only available in Python 3.6+, but now the black formatter requires Python 3.6 and all our systems are running Python 3.6+ anyways. --- dspace_statistics_api/app.py | 4 +--- dspace_statistics_api/database.py | 4 +--- dspace_statistics_api/indexer.py | 12 ++++-------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/dspace_statistics_api/app.py b/dspace_statistics_api/app.py index 058e154..abbf12a 100644 --- a/dspace_statistics_api/app.py +++ b/dspace_statistics_api/app.py @@ -77,9 +77,7 @@ class ItemResource: if cursor.rowcount == 0: raise falcon.HTTPNotFound( title="Item not found", - description='The item with id "{}" was not found.'.format( - str(item_id) - ), + description=f'The item with id "{str(item_id)}" was not found.', ) else: results = cursor.fetchone() diff --git a/dspace_statistics_api/database.py b/dspace_statistics_api/database.py index 07dc68a..ab991a9 100644 --- a/dspace_statistics_api/database.py +++ b/dspace_statistics_api/database.py @@ -15,9 +15,7 @@ class DatabaseManager: """Manage database connection.""" def __init__(self): - self._connection_uri = "dbname={} user={} password={} host={} port={}".format( - DATABASE_NAME, DATABASE_USER, DATABASE_PASS, DATABASE_HOST, DATABASE_PORT - ) + self._connection_uri = f"dbname={DATABASE_NAME} user={DATABASE_USER} password={DATABASE_PASS} host={DATABASE_HOST} port={DATABASE_PORT}" def __enter__(self): try: diff --git a/dspace_statistics_api/indexer.py b/dspace_statistics_api/indexer.py index 40b0506..5b495cb 100644 --- a/dspace_statistics_api/indexer.py +++ b/dspace_statistics_api/indexer.py @@ -70,13 +70,13 @@ def get_statistics_shards(): if len(statistics_core_years) > 0: # Begin building a string of shards starting with the default one - shards = "{}/statistics".format(SOLR_SERVER) + shards = f"{SOLR_SERVER}/statistics" for core in statistics_core_years: # Create a comma-separated list of shards to pass to our Solr query # # See: https://wiki.apache.org/solr/DistributedSearch - shards += ",{}/{}".format(SOLR_SERVER, core) + shards += f",{SOLR_SERVER}/{core}" # Return the string of shards, which may actually be empty. Solr doesn't # seem to mind if the shards query parameter is empty and I haven't seen @@ -134,9 +134,7 @@ def index_views(): while results_current_page <= results_num_pages: # "pages" are zero based, but one based is more human readable print( - "Indexing item views (page {} of {})".format( - results_current_page + 1, results_num_pages + 1 - ) + f"Indexing item views (page {results_current_page + 1} of {results_num_pages + 1})" ) solr_query_params = { @@ -219,9 +217,7 @@ def index_downloads(): while results_current_page <= results_num_pages: # "pages" are zero based, but one based is more human readable print( - "Indexing item downloads (page {} of {})".format( - results_current_page + 1, results_num_pages + 1 - ) + f"Indexing item downloads (page {results_current_page + 1} of {results_num_pages + 1})" ) solr_query_params = {