Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update string interpolation to f-strings #303

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions debian/msc-pygeoapi.cron.d
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
MAILTO=""
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2021 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down
4 changes: 2 additions & 2 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/sh
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2020 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down
4 changes: 2 additions & 2 deletions msc_pygeoapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2022 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down
4 changes: 2 additions & 2 deletions msc_pygeoapi/connector/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author: Etienne <[email protected]>
#
# Copyright (c) 2021 Etienne Pelletier
# Copyright (c) 2021 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -93,4 +93,4 @@ def delete(self, resources):
raise NotImplementedError()

def __repr__(self):
return '<BaseConnector> {}'.format(self.name)
return f'<BaseConnector> {self.name}'
4 changes: 2 additions & 2 deletions msc_pygeoapi/env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2021 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down
6 changes: 3 additions & 3 deletions msc_pygeoapi/event/file_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Author: Tom Kralidis <[email protected]>
#
# Copyright (c) 2021 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -48,10 +48,10 @@ def on_file(self, parent):
from msc_pygeoapi.handler.core import CoreHandler

filepath = parent.msg.local_file
parent.logger.debug('Filepath: {}'.format(filepath))
parent.logger.debug(f'Filepath: {filepath}')
handler = CoreHandler(filepath)
result = handler.handle()
parent.logger.debug('Result: {}'.format(result))
parent.logger.debug(f'Result: {result}')
return True
except Exception as err:
parent.logger.warning(err)
Expand Down
6 changes: 3 additions & 3 deletions msc_pygeoapi/event/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Author: Tom Kralidis <[email protected]>
#
# Copyright (c) 2021 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -48,10 +48,10 @@ def on_message(self, parent):
from msc_pygeoapi.handler.core import CoreHandler

filepath = parent.msg.local_file
parent.logger.debug('Filepath: {}'.format(filepath))
parent.logger.debug(f'Filepath: {filepath}')
handler = CoreHandler(filepath)
result = handler.handle()
parent.logger.debug('Result: {}'.format(result))
parent.logger.debug(f'Result: {result}')
return True
except Exception as err:
parent.logger.warning(err)
Expand Down
4 changes: 2 additions & 2 deletions msc_pygeoapi/handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2020 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down
8 changes: 4 additions & 4 deletions msc_pygeoapi/handler/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2020 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -45,12 +45,12 @@ def __init__(self, filepath):
"""

self.filepath = filepath
LOGGER.debug('Filepath: {}'.format(self.filepath))
LOGGER.debug(f'Filepath: {self.filepath}')

def handle(self):
"""handle incoming file"""

raise NotImplementedError()

def __repr__(self):
return '<BaseHandler> {}'.format(self.filepath)
return f'<BaseHandler> {self.filepath}'
10 changes: 5 additions & 5 deletions msc_pygeoapi/handler/core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2020 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -62,7 +62,7 @@ def handle(self):
for key in PLUGINS['loader'].keys():
if PLUGINS['loader'][key]['filename_pattern'] in self.filepath:
plugin_def = PLUGINS['loader'][key]
LOGGER.debug('Loading plugin {}'.format(plugin_def))
LOGGER.debug(f'Loading plugin {plugin_def}')
self.plugin = load_plugin('loader', plugin_def)

if self.plugin is None:
Expand All @@ -72,9 +72,9 @@ def handle(self):

LOGGER.debug('Handling file')
status = self.plugin.load_data(self.filepath)
LOGGER.debug('Status: {}'.format(status))
LOGGER.debug(f'Status: {status}')

return True

def __repr__(self):
return '<CoreHandler> {}'.format(self.filepath)
return f'<CoreHandler> {self.filepath}'
12 changes: 5 additions & 7 deletions msc_pygeoapi/loader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# =================================================================
#
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
# Felix Laframboise <[email protected]>
#
# Copyright (c) 2022 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
# Copyright (c) 2021 Felix Laframboise
#
# Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -78,11 +78,9 @@ def metadata():
data.add_command(getattr(mod, name))
except ImportError as err:
command_name = name.replace('_', '-')
LOGGER.info(
'msc-pygeoapi data {} command unavailable.'.format(command_name)
)
module_name = '{}.{}'.format(module, name)
msg = 'Import error when loading {}: {}'.format(module_name, err)
LOGGER.info(f'msc-pygeoapi data {command_name} command unavailable')
module_name = f'{module}.{name}'
msg = f'Import error when loading {module_name}: {err}'
LOGGER.debug(msg)


Expand Down
24 changes: 12 additions & 12 deletions msc_pygeoapi/loader/ahccd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#
# Author: Alex Hurka <[email protected]>
# Author: Etienne Pelletier <[email protected]>
# Author: Tom Kralidis <tom.kralidis@canada.ca>
# Author: Tom Kralidis <tom.kralidis@ec.gc.ca>
#
# Copyright (c) 2019 Alex Hurka
# Copyright (c) 2021 Etienne Pelletier
# Copyright (c) 2020 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -472,7 +472,7 @@ def generate_docs(self, fp, index):
'seasonal',
'trends',
]:
LOGGER.error('Unrecognized AHCCD data type {}'.format(index))
LOGGER.error(f'Unrecognized AHCCD data type {index}')
return

try:
Expand All @@ -494,22 +494,22 @@ def generate_docs(self, fp, index):
record['properties']['identifier__identifiant'] = stn_id
elif index == 'monthly':
index_name = 'ahccd_monthly'
record['properties']['date'] = '{}-{}'.format(
record['properties']['date'] = '-'.join([
record['properties']['identifier__identifiant'].split('.')[
1
],
record['properties']['identifier__identifiant'].split('.')[
2
],
)
])
del record['properties']['year__annee']
elif index == 'trends':
index_name = 'ahccd_trends'
identifier = '{}.{}.{}'.format(
identifier = '.'.join([
record['properties']['station_id__id_station'],
record['properties']['period__periode'],
record['properties']['measurement_type__type_mesure'],
)
record['properties']['measurement_type__type_mesure']
])
record['properties']['identifier__identifiant'] = identifier

action = {
Expand Down Expand Up @@ -573,7 +573,7 @@ def add(
with open(ctl, 'r') as f:
ctl_dict = json.loads(f.read())
except Exception as err:
msg = 'Could not open JSON location file: {}'.format(err)
msg = f'Could not open JSON location file: {err}'
click.ClickException(err)

if dataset == 'all':
Expand All @@ -587,16 +587,16 @@ def add(
else:
datasets_to_process = [dataset]

click.echo('Processing dataset(s): {}'.format(datasets_to_process))
click.echo(f'Processing dataset(s): {datasets_to_process}')

for dtp in datasets_to_process:
try:
click.echo('Populating {} index'.format(dtp))
click.echo(f'Populating {dtp} index')
loader.create_index(dtp)
dtp_data = loader.generate_docs(ctl_dict[dtp], dtp)
loader.conn.submit_elastic_package(dtp_data, batch_size)
except Exception as err:
msg = 'Could not populate {} index: {}'.format(dtp, err)
msg = f'Could not populate {dtp} index: {err}'
raise click.ClickException(msg)


Expand Down
18 changes: 9 additions & 9 deletions msc_pygeoapi/loader/aqhi_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright (c) 2020 Etienne Pelletier
# Copyright (c) 2021 Felix Laframboise
# Copyright (c) 2021 Louis-Philippe Rousseau-Lambert
# Copyright (c) 2022 Tom Kralidis
# Copyright (c) 2023 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -156,7 +156,7 @@
SETTINGS = {
'order': 0,
'version': 1,
'index_patterns': ['{}*'.format(INDEX_BASENAME)],
'index_patterns': [f'{INDEX_BASENAME}*'],
'settings': {'number_of_shards': 1, 'number_of_replicas': 0},
'mappings': None
}
Expand Down Expand Up @@ -185,7 +185,7 @@ def __init__(self, conn_config={}):

for aqhi_type in template_mappings:
template_name = INDEX_BASENAME.format(aqhi_type)
SETTINGS['index_patterns'] = ['{}*'.format(template_name)]
SETTINGS['index_patterns'] = [f'{template_name}*']
SETTINGS['mappings'] = MAPPINGS[aqhi_type]
self.conn.create_template(template_name, SETTINGS)

Expand Down Expand Up @@ -289,7 +289,7 @@ def update_latest_status(self):
try:
self.conn.update_by_query(query, index_)
except Exception as err:
LOGGER.warning('{}: failed to update ES index'.format(err))
LOGGER.warning(f'Failed to update ES index: {err}')

return True

Expand All @@ -304,7 +304,7 @@ def load_data(self, filepath):
# set class variables from filename
self.parse_filename()

LOGGER.debug('Received file {}'.format(self.filepath))
LOGGER.debug(f'Received file {self.filepath}')

# generate geojson features
package = self.generate_geojson_features()
Expand Down Expand Up @@ -360,7 +360,7 @@ def add(ctx, file_, directory, es, username, password, ignore_certs):
@click.pass_context
@cli_options.OPTION_DAYS(
default=DAYS_TO_KEEP,
help='Delete indexes older than n days (default={})'.format(DAYS_TO_KEEP),
help=f'Delete indexes older than n days (default={DAYS_TO_KEEP})',
)
@cli_options.OPTION_DATASET(
help='AQHI dataset indexes to delete.',
Expand All @@ -387,7 +387,7 @@ def clean_indexes(ctx, days, dataset, es, username, password, ignore_certs):
if indexes:
indexes_to_delete = check_es_indexes_to_delete(indexes, days)
if indexes_to_delete:
click.echo('Deleting indexes {}'.format(indexes_to_delete))
click.echo(f'Deleting indexes {indexes_to_delete}')
conn.delete(','.join(indexes_to_delete))

click.echo('Done')
Expand Down Expand Up @@ -416,14 +416,14 @@ def delete_indexes(ctx, dataset, es, username, password, ignore_certs,
else:
indexes = '{}*'.format(INDEX_BASENAME.format(dataset))

click.echo('Deleting indexes {}'.format(indexes))
click.echo(f'Deleting indexes {indexes}')

conn.delete(indexes)

if index_template:
for type_ in ('forecasts', 'observations'):
index_name = INDEX_BASENAME.format(type_)
click.echo('Deleting index template {}'.format(index_name))
click.echo(f'Deleting index template {index_name}')
conn.delete_template(index_name)

click.echo('Done')
Expand Down
Loading
Loading