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

Apply ruff/pyupgrade rules #35

Merged
merged 3 commits into from
May 14, 2024
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
2 changes: 1 addition & 1 deletion src/neurospin_to_bids/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions src/neurospin_to_bids/acquisition_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
7 changes: 4 additions & 3 deletions src/neurospin_to_bids/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 13 additions & 10 deletions src/neurospin_to_bids/exp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading