Skip to content

Commit 0680407

Browse files
committed
sty: pacify ruff
1 parent 406ef77 commit 0680407

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

templateflow/api.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,23 @@ def get(template, raise_empty=False, **kwargs):
174174
not_fetched = [str(p) for p in out_file if not p.is_file() or p.stat().st_size == 0]
175175

176176
if not_fetched:
177-
msg = 'Could not fetch template files: %s.' % ', '.join(not_fetched)
177+
msg = 'Could not fetch template files: {}.'.format(', '.join(not_fetched))
178178
if dl_missing and not TF_USE_DATALAD:
179179
msg += (
180-
"""\
181-
The $TEMPLATEFLOW_HOME folder %s seems to contain an initiated DataLad \
180+
f"""\
181+
The $TEMPLATEFLOW_HOME folder {TF_LAYOUT.root} seems to contain an initiated DataLad \
182182
dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is not \
183183
set or set to one of (false, off, 0). Please set $TEMPLATEFLOW_USE_DATALAD \
184184
on (possible values: true, on, 1)."""
185-
% TF_LAYOUT.root
186185
)
187186

188187
if s3_missing and TF_USE_DATALAD:
189188
msg += (
190-
"""\
191-
The $TEMPLATEFLOW_HOME folder %s seems to contain an plain \
189+
f"""\
190+
The $TEMPLATEFLOW_HOME folder {TF_LAYOUT.root} seems to contain an plain \
192191
dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is \
193192
set to one of (true, on, 1). Please set $TEMPLATEFLOW_USE_DATALAD \
194193
off (possible values: false, off, 0)."""
195-
% TF_LAYOUT.root
196194
)
197195

198196
raise RuntimeError(msg)
@@ -249,7 +247,7 @@ def get_metadata(template):
249247
250248
"""
251249
tf_home = Path(TF_LAYOUT.root)
252-
filepath = tf_home / ('tpl-%s' % template) / 'template_description.json'
250+
filepath = tf_home / (f'tpl-{template}') / 'template_description.json'
253251

254252
# Ensure that template is installed and file is available
255253
if not filepath.is_file():
@@ -322,7 +320,7 @@ def _s3_get(filepath):
322320
path = filepath.relative_to(TF_LAYOUT.root).as_posix()
323321
url = f'{TF_S3_ROOT}/{path}'
324322

325-
print('Downloading %s' % url, file=stderr)
323+
print(f'Downloading {url}', file=stderr)
326324
# Streaming, so we can iterate over the response.
327325
r = requests.get(url, stream=True, timeout=TF_GET_TIMEOUT)
328326

templateflow/conf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _env_to_bool(envvar: str, default: bool) -> bool:
4848
try:
4949
from datalad.api import install
5050
except ImportError:
51-
warn('DataLad is not installed ➔ disabled.')
51+
warn('DataLad is not installed ➔ disabled.', stacklevel=2)
5252
TF_USE_DATALAD = False
5353

5454
if not TF_USE_DATALAD:

templateflow/conf/_s3.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,18 @@ def _update_skeleton(skel_file, dest, overwrite=True, silent=False):
8787
newfiles = allfiles
8888
else:
8989
current_files = [s.relative_to(dest) for s in dest.glob('**/*')]
90-
existing = sorted({'%s/' % s.parent for s in current_files}) + [
90+
existing = sorted({f'{s.parent}/' for s in current_files}) + [
9191
str(s) for s in current_files
9292
]
9393
newfiles = sorted(set(allfiles) - set(existing))
9494

9595
if newfiles:
9696
if not silent:
97-
print('Updating TEMPLATEFLOW_HOME using S3. Adding:\n%s' % '\n'.join(newfiles))
97+
print('Updating TEMPLATEFLOW_HOME using S3. Adding:')
98+
9899
for fl in newfiles:
100+
if not silent:
101+
print(fl)
99102
localpath = dest / fl
100103
if localpath.exists():
101104
continue

templateflow/tests/test_conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
8484

8585
out = capsys.readouterr().out
8686
assert _find_message(out, 'TemplateFlow was not cached')
87-
assert ('TEMPLATEFLOW_HOME=%s' % home) in out
87+
assert (f'TEMPLATEFLOW_HOME={home}') in out
8888
assert home.exists()
8989
assert len(list(home.iterdir())) > 0
9090

@@ -134,9 +134,9 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
134134
def test_layout(monkeypatch, tmp_path):
135135
monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', 'off')
136136

137-
lines = ('%s' % tfc.TF_LAYOUT).splitlines()
137+
lines = (f'{tfc.TF_LAYOUT}').splitlines()
138138
assert lines[0] == 'TemplateFlow Layout'
139-
assert lines[1] == ' - Home: %s' % tfc.TF_HOME
139+
assert lines[1] == f' - Home: {tfc.TF_HOME}'
140140
assert lines[2].startswith(' - Templates:')
141141

142142

0 commit comments

Comments
 (0)