Skip to content

Commit

Permalink
sty: pacify ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Sep 13, 2024
1 parent 406ef77 commit 906dafd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
16 changes: 7 additions & 9 deletions templateflow/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,23 @@ def get(template, raise_empty=False, **kwargs):
not_fetched = [str(p) for p in out_file if not p.is_file() or p.stat().st_size == 0]

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

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

raise RuntimeError(msg)
Expand Down Expand Up @@ -249,7 +247,7 @@ def get_metadata(template):
"""
tf_home = Path(TF_LAYOUT.root)
filepath = tf_home / ('tpl-%s' % template) / 'template_description.json'
filepath = tf_home / (f'tpl-{template}') / 'template_description.json'

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

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

Expand Down
2 changes: 1 addition & 1 deletion templateflow/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _env_to_bool(envvar: str, default: bool) -> bool:
try:
from datalad.api import install
except ImportError:
warn('DataLad is not installed ➔ disabled.')
warn('DataLad is not installed ➔ disabled.', stacklevel=2)
TF_USE_DATALAD = False

if not TF_USE_DATALAD:
Expand Down
7 changes: 5 additions & 2 deletions templateflow/conf/_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ def _update_skeleton(skel_file, dest, overwrite=True, silent=False):
newfiles = allfiles
else:
current_files = [s.relative_to(dest) for s in dest.glob('**/*')]
existing = sorted({'%s/' % s.parent for s in current_files}) + [
existing = sorted({f'{s.parent}/' for s in current_files}) + [
str(s) for s in current_files
]
newfiles = sorted(set(allfiles) - set(existing))

if newfiles:
if not silent:
print('Updating TEMPLATEFLOW_HOME using S3. Adding:\n%s' % '\n'.join(newfiles))
print(
'Updating TEMPLATEFLOW_HOME using S3. Adding:\n'
f'{"\n".join(newfiles)}'
)
for fl in newfiles:
localpath = dest / fl
if localpath.exists():
Expand Down
6 changes: 3 additions & 3 deletions templateflow/tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):

out = capsys.readouterr().out
assert _find_message(out, 'TemplateFlow was not cached')
assert ('TEMPLATEFLOW_HOME=%s' % home) in out
assert (f'TEMPLATEFLOW_HOME={home}') in out
assert home.exists()
assert len(list(home.iterdir())) > 0

Expand Down Expand Up @@ -134,9 +134,9 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
def test_layout(monkeypatch, tmp_path):
monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', 'off')

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


Expand Down

0 comments on commit 906dafd

Please sign in to comment.