From 84381e8eea16d64c9e32e9d4f6ebce7fc43cb6f9 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Wed, 14 Apr 2021 12:36:41 +0200 Subject: [PATCH] Run latest pyupgrade --- livesync/indico_livesync/handler.py | 2 +- livesync/indico_livesync/marcxml.py | 2 +- piwik/indico_piwik/piwik.py | 4 ++-- piwik/indico_piwik/queries/graphs.py | 2 +- piwik/indico_piwik/reports.py | 2 +- storage_s3/indico_storage_s3/migrate.py | 12 ++++++------ storage_s3/indico_storage_s3/storage.py | 4 ++-- update-meta.py | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/livesync/indico_livesync/handler.py b/livesync/indico_livesync/handler.py index 5a96273..d27e7a3 100644 --- a/livesync/indico_livesync/handler.py +++ b/livesync/indico_livesync/handler.py @@ -87,7 +87,7 @@ def _created(obj, **kwargs): elif isinstance(obj, SubContribution): parent = obj.contribution else: - raise TypeError('Unexpected object: {}'.format(type(obj).__name__)) + raise TypeError(f'Unexpected object: {type(obj).__name__}') if parent: _register_change(parent, ChangeType.data_changed) _register_change(obj, ChangeType.created) diff --git a/livesync/indico_livesync/marcxml.py b/livesync/indico_livesync/marcxml.py index 0c9d851..fb11a89 100644 --- a/livesync/indico_livesync/marcxml.py +++ b/livesync/indico_livesync/marcxml.py @@ -58,7 +58,7 @@ class MARCXMLGenerator: xg = XMLGen(init=False) xg.openTag('record') xg.openTag('datafield', [['tag', '970'], ['ind1', ' '], ['ind2', ' ']]) - xg.writeTag('subfield', 'INDICO.{}'.format(compound_id(obj)), [['code', 'a']]) + xg.writeTag('subfield', f'INDICO.{compound_id(obj)}', [['code', 'a']]) xg.closeTag('datafield') xg.openTag('datafield', [['tag', '980'], ['ind1', ' '], ['ind2', ' ']]) xg.writeTag('subfield', 'DELETED', [['code', 'c']]) diff --git a/piwik/indico_piwik/piwik.py b/piwik/indico_piwik/piwik.py index e5b1201..8d3033f 100644 --- a/piwik/indico_piwik/piwik.py +++ b/piwik/indico_piwik/piwik.py @@ -53,12 +53,12 @@ class PiwikRequest: for key, value in query_params.items(): if isinstance(value, list): value = ','.join(value) - query += '{}={}&'.format(str(key), str(value)) + query += f'{key}={value}&' return query[:-1] def get_query_url(self, **query_params): """Return the url for a Piwik API query""" - return '{}?{}'.format(self.api_url, self.get_query(query_params)) + return f'{self.api_url}?{self.get_query(query_params)}' def _perform_call(self, query_url, default_response=None, timeout=10): """Returns the raw results from the API""" diff --git a/piwik/indico_piwik/queries/graphs.py b/piwik/indico_piwik/queries/graphs.py index 823399b..8fecf6d 100644 --- a/piwik/indico_piwik/queries/graphs.py +++ b/piwik/indico_piwik/queries/graphs.py @@ -35,7 +35,7 @@ class PiwikQueryReportEventGraphBase(PiwikQueryReportEventBase): if png.startswith(b'GD extension must be loaded'): current_plugin.logger.warning('Piwik server answered on ImageGraph.get: %s', png) return - return 'data:image/png;base64,{}'.format(b64encode(png).decode()) + return f'data:image/png;base64,{b64encode(png).decode()}' class PiwikQueryReportEventGraphCountries(PiwikQueryReportEventGraphBase): diff --git a/piwik/indico_piwik/reports.py b/piwik/indico_piwik/reports.py index 8804d72..175f752 100644 --- a/piwik/indico_piwik/reports.py +++ b/piwik/indico_piwik/reports.py @@ -120,7 +120,7 @@ class ReportGeneral(ReportBase): cid = (contribution.legacy_mapping.legacy_contribution_id if contribution.legacy_mapping else contribution.id) key = f'{contribution.event_id}t{cid}' - self.contributions[key] = '{} ({})'.format(contribution.title, format_time(contribution.start_dt)) + self.contributions[key] = f'{contribution.title} ({format_time(contribution.start_dt)})' class ReportVisitsPerDay(ReportBase): diff --git a/storage_s3/indico_storage_s3/migrate.py b/storage_s3/indico_storage_s3/migrate.py index ec5c0b5..216c13c 100644 --- a/storage_s3/indico_storage_s3/migrate.py +++ b/storage_s3/indico_storage_s3/migrate.py @@ -187,11 +187,11 @@ class S3Importer: match = _new_path_re.match(obj.storage_file_id) if match: # already in the current format - assert obj.storage_file_id == new_storage_path.replace('-0-', '-{}-'.format(match.group(2))) + assert obj.storage_file_id == new_storage_path.replace('-0-', f'-{match.group(2)}-') return obj.storage_file_id, new_filename else: match = _new_path_re.match(new_storage_path) - return '{}{}{}'.format(match.group(1), crc32(obj.storage_file_id), match.group(3)), new_filename + return f'{match.group(1)}{crc32(obj.storage_file_id)}{match.group(3)}', new_filename def queue_for_rclone(self, obj, bucket, key): # XXX: we assume the file is local so the context manager doesn't create a @@ -447,7 +447,7 @@ def copy(source_backend_names, bucket_names, static_bucket_name, s3_endpoint, s3 raise click.UsageError('All but the last bucket name need to contain criteria') matches = [(re.match(r'^(<|>|==|<=|>=)\s*(\d{4}):(.+)$', name), backend) for name, backend in bucket_names[:-1]] if not all(x[0] for x in matches): - raise click.UsageError("Could not parse '{}'".format(bucket_names[matches.index(None)])) + raise click.UsageError(f"Could not parse '{bucket_names[matches.index(None)]}'") criteria = [(match.groups(), backend) for match, backend in matches] # Build and compile a function to get the bucket/backend name to avoid # processing the criteria for every single file (can be millions for large @@ -456,11 +456,11 @@ def copy(source_backend_names, bucket_names, static_bucket_name, s3_endpoint, s3 if criteria: for i, ((op, value, bucket), backend) in enumerate(criteria): code.append(' {}if dt.year {} {}:'.format('el' if i else '', op, value)) - code.append(' bucket, backend = {!r}'.format((bucket, backend))) + code.append(f' bucket, backend = {(bucket, backend)!r}') code.append(' else:') - code.append(' bucket, backend = {!r}'.format(bucket_names[-1])) + code.append(f' bucket, backend = {bucket_names[-1]!r}') else: - code.append(' bucket, backend = {!r}'.format(bucket_names[-1])) + code.append(f' bucket, backend = {bucket_names[-1]!r}') code.append(' bucket = bucket.replace("", dt.strftime("%Y"))') code.append(' bucket = bucket.replace("", dt.strftime("%m"))') code.append(' bucket = bucket.replace("", dt.strftime("%W"))') diff --git a/storage_s3/indico_storage_s3/storage.py b/storage_s3/indico_storage_s3/storage.py index 966deee..7283afd 100644 --- a/storage_s3/indico_storage_s3/storage.py +++ b/storage_s3/indico_storage_s3/storage.py @@ -193,7 +193,7 @@ class S3Storage(S3StorageBase): raise StorageError('Bucket name cannot be longer than 63 chars') def __repr__(self): - return '<{}: {}>'.format(type(self).__name__, self.bucket_name) + return f'<{type(self).__name__}: {self.bucket_name}>' def _get_current_bucket_name(self): return self.bucket_name @@ -225,7 +225,7 @@ class DynamicS3Storage(S3StorageBase): self._check_bucket_secret() def __repr__(self): - return '<{}: {}>'.format(type(self).__name__, self.bucket_name_template) + return f'<{type(self).__name__}: {self.bucket_name_template}>' def _check_bucket_secret(self): if not self.bucket_secret: diff --git a/update-meta.py b/update-meta.py index c669e74..af803ec 100644 --- a/update-meta.py +++ b/update-meta.py @@ -53,7 +53,7 @@ def _get_config(): def _update_meta(data): path = Path('_meta/setup.cfg') content = path.read_text() - new_content = re.sub(r'(?<={}\n).*(?=\n{})'.format(re.escape(START_MARKER), re.escape(END_MARKER)), data, content, + new_content = re.sub(fr'(?<={re.escape(START_MARKER)}\n).*(?=\n{re.escape(END_MARKER)})', data, content, flags=re.DOTALL) if content == new_content: return False