From 992f2aa1fce6124eb8631c363032ccdec7becc12 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 5 May 2024 13:04:06 +0200 Subject: [PATCH 1/3] Apply ruff/pyupgrade rule UP032 UP032 Use f-string instead of `format` call --- src/neurospin_to_bids/bids.py | 7 ++++--- src/neurospin_to_bids/exp_info.py | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/neurospin_to_bids/bids.py b/src/neurospin_to_bids/bids.py index 21f66ac..5cd7cd4 100644 --- a/src/neurospin_to_bids/bids.py +++ b/src/neurospin_to_bids/bids.py @@ -159,9 +159,10 @@ def validate_bids_label(label): def validate_metadata_dict(value): """Validate the additional metadata in each element of to_import.""" if not isinstance(value[3], dict): - raise BIDSError("the fourth value of each element of to_import " - "must be a dictionary (offending value is {!r})" - .format(value[3])) + raise BIDSError( + "the fourth value of each element of to_import " + f"must be a dictionary (offending value is {value[3]!r})" + ) try: json.dumps(value) except TypeError: diff --git a/src/neurospin_to_bids/exp_info.py b/src/neurospin_to_bids/exp_info.py index ab53f53..60aee91 100644 --- a/src/neurospin_to_bids/exp_info.py +++ b/src/neurospin_to_bids/exp_info.py @@ -98,18 +98,21 @@ def validate_element_to_import(value): raise ValidationError("each element of to_import must be of length 3 " "or 4") if not isinstance(value[0], (str, int)): - raise ValidationError("the first value of each element of to_import " - "must be a string (for MEG) or integer (for " - "MRI) (offending value is {!r})" - .format(value[0])) + raise ValidationError( + "the first value of each element of to_import " + "must be a string (for MEG) or integer (for " + f"MRI) (offending value is {value[0]!r})" + ) if not isinstance(value[1], str): - raise ValidationError("the second value of each element of to_import " - "must be a string (offending value is {!r})" - .format(value[1])) + raise ValidationError( + "the second value of each element of to_import " + f"must be a string (offending value is {value[1]!r})" + ) if not isinstance(value[2], str): - raise ValidationError("the third value of each element of to_import " - "must be a string (offending value is {!r})" - .format(value[2])) + raise ValidationError( + "the third value of each element of to_import " + f"must be a string (offending value is {value[2]!r})" + ) try: bids.validate_bids_partial_name(value[2]) if len(value) > 3: From 0d0a23c2bf329560ddf938d70451c59c2f027923 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 5 May 2024 13:06:46 +0200 Subject: [PATCH 2/3] Apply ruff/pyupgrade rule UP030 UP030 Use implicit references for positional format fields --- src/neurospin_to_bids/acquisition_db.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/neurospin_to_bids/acquisition_db.py b/src/neurospin_to_bids/acquisition_db.py index 359396a..4240788 100644 --- a/src/neurospin_to_bids/acquisition_db.py +++ b/src/neurospin_to_bids/acquisition_db.py @@ -41,9 +41,8 @@ def get_database_path(scanner): try: relative_db_path = NEUROSPIN_DATABASES[scanner.strip().lower()] except KeyError: - raise UserError('invalid scanner {0!r}, must be one of {{{1}}}' - .format(scanner, - ', '.join(NEUROSPIN_DATABASES.keys()))) + scanners = ', '.join(NEUROSPIN_DATABASES.keys()) + raise UserError(f'invalid scanner {scanner!r}, must be one of {{{scanners}}}') return os.path.join(ACQUISITION_ROOT_PATH, relative_db_path) From 84f94f110724c487b97214ea78b8678bd665a098 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 5 May 2024 13:07:48 +0200 Subject: [PATCH 3/3] Disable ruff/pyupgrade rule UP036 UP036 Version block is outdated for minimum Python version --- src/neurospin_to_bids/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neurospin_to_bids/__main__.py b/src/neurospin_to_bids/__main__.py index 00c62a0..669f638 100755 --- a/src/neurospin_to_bids/__main__.py +++ b/src/neurospin_to_bids/__main__.py @@ -605,7 +605,7 @@ def bids_acquisition_download(data_root_path='', def main(argv=sys.argv): prog = os.path.basename(argv[0]) - if sys.version_info < (3, 6): + if sys.version_info < (3, 6): # noqa: UP036 sys.stderr.write(f'ERROR: {prog} needs Python 3.6 or later\n') return 1 if argv is None: