Skip to content

Commit

Permalink
sty: run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Sep 13, 2024
1 parent 48ab265 commit 406ef77
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 43 deletions.
2 changes: 2 additions & 0 deletions templateflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""TemplateFlow is the Zone of Templates."""

from datetime import datetime as _dt
from datetime import timezone as _tz

Expand All @@ -30,6 +31,7 @@
from ._version import __version__
except ModuleNotFoundError:
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version(__packagename__)
except PackageNotFoundError:
Expand Down
1 change: 1 addition & 0 deletions templateflow/_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.. autoclass:: Loader
"""

from __future__ import annotations

import atexit
Expand Down
12 changes: 5 additions & 7 deletions templateflow/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""TemplateFlow's Python Client."""

import sys
from json import loads
from pathlib import Path
Expand All @@ -35,9 +36,7 @@
requires_layout,
)

_layout_dir = tuple(
item for item in dir(TF_LAYOUT) if item.startswith('get_')
)
_layout_dir = tuple(item for item in dir(TF_LAYOUT) if item.startswith('get_'))


@requires_layout
Expand Down Expand Up @@ -92,10 +91,9 @@ def ls(template, **kwargs):
kwargs['extension'] = _normalize_ext(kwargs['extension'])

return [
Path(p) for p in TF_LAYOUT.get(
template=Query.ANY if template is None else template,
return_type='file',
**kwargs
Path(p)
for p in TF_LAYOUT.get(
template=Query.ANY if template is None else template, return_type='file', **kwargs
)
]

Expand Down
35 changes: 14 additions & 21 deletions templateflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""The TemplateFlow Python Client command-line interface (CLI)."""

from __future__ import annotations

import json
Expand All @@ -31,20 +32,20 @@

from templateflow import __package__, api
from templateflow._loader import Loader as _Loader
from templateflow.conf import TF_HOME, TF_USE_DATALAD, TF_AUTOUPDATE
from templateflow.conf import TF_AUTOUPDATE, TF_HOME, TF_USE_DATALAD

load_data = _Loader(__package__)

ENTITY_SHORTHANDS = {
# 'template': ('--tpl', '-t'),
'resolution': ('--res', ),
'density': ('--den', ),
'atlas': ('-a', ),
'suffix': ('-s', ),
'resolution': ('--res',),
'density': ('--den',),
'atlas': ('-a',),
'suffix': ('-s',),
'desc': ('-d', '--description'),
'extension': ('--ext', '-x'),
'label': ('-l', ),
'segmentation': ('--seg', ),
'label': ('-l',),
'segmentation': ('--seg',),
}
ENTITY_EXCLUDE = {'template', 'description'}
TEMPLATE_LIST = api.get_templates()
Expand All @@ -57,16 +58,12 @@ def _nulls(s):
def entity_opts():
"""Attaches all entities as options to the command."""

entities = json.loads(
Path(load_data('conf/config.json')).read_text()
)['entities']
entities = json.loads(Path(load_data('conf/config.json')).read_text())['entities']

args = [
(
f"--{e['name']}",
*ENTITY_SHORTHANDS.get(e['name'], ())
)
for e in entities if e['name'] not in ENTITY_EXCLUDE
(f"--{e['name']}", *ENTITY_SHORTHANDS.get(e['name'], ()))
for e in entities
if e['name'] not in ENTITY_EXCLUDE
]

def decorator(f: FC) -> FC:
Expand Down Expand Up @@ -135,9 +132,7 @@ def update(local, overwrite):
def ls(template, **kwargs):
"""List the assets corresponding to template and optional filters."""
entities = {k: _nulls(v) for k, v in kwargs.items() if v != ''}
click.echo(
'\n'.join(f'{match}' for match in api.ls(template, **entities))
)
click.echo('\n'.join(f'{match}' for match in api.ls(template, **entities)))


@main.command()
Expand All @@ -146,9 +141,7 @@ def ls(template, **kwargs):
def get(template, **kwargs):
"""Fetch the assets corresponding to template and optional filters."""
entities = {k: _nulls(v) for k, v in kwargs.items() if v != ''}
click.echo(
'\n'.join(f'{match}' for match in api.get(template, **entities))
)
click.echo('\n'.join(f'{match}' for match in api.get(template, **entities)))


if __name__ == '__main__':
Expand Down
6 changes: 2 additions & 4 deletions templateflow/conf/_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Tooling to handle S3 downloads."""

from pathlib import Path
from tempfile import mkstemp

Expand Down Expand Up @@ -93,10 +94,7 @@ def _update_skeleton(skel_file, dest, overwrite=True, silent=False):

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%s' % '\n'.join(newfiles))
for fl in newfiles:
localpath = dest / fl
if localpath.exists():
Expand Down
5 changes: 2 additions & 3 deletions templateflow/conf/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Extending pyBIDS for querying TemplateFlow."""

from bids.layout import BIDSLayout, add_config_paths

from templateflow.conf import load_data
Expand All @@ -34,7 +35,5 @@ def __repr__(self):
s = """\
TemplateFlow Layout
- Home: {}
- Templates: {}.""".format(
self.root, ', '.join(sorted(self.get_templates()))
)
- Templates: {}.""".format(self.root, ', '.join(sorted(self.get_templates())))
return s
8 changes: 2 additions & 6 deletions templateflow/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def assert_same(self, other):
journal={Cerebral Cortex}
}"""

fslr_lbib = (
'https://github.com/Washington-University/HCPpipelines/tree/master/global/templates'
)
fslr_lbib = 'https://github.com/Washington-University/HCPpipelines/tree/master/global/templates'

fsaverage_fbib = """\
@article{Fischl_1999,
Expand All @@ -181,9 +179,7 @@ def assert_same(self, other):
('fsLR', fslr_urls, fslr_fbib, fslr_lbib),
(
'fsaverage',
[
'https://doi.org/10.1002/(sici)1097-0193(1999)8:4%3C272::aid-hbm10%3E3.0.co;2-4'
],
['https://doi.org/10.1002/(sici)1097-0193(1999)8:4%3C272::aid-hbm10%3E3.0.co;2-4'],
fsaverage_fbib,
None,
),
Expand Down
8 changes: 6 additions & 2 deletions templateflow/tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
# https://www.nipreps.org/community/licensing/
#
"""Check S3-type repo tooling."""

from importlib import reload
from pathlib import Path

import requests
from importlib import reload

from templateflow import conf as tfc

Expand All @@ -46,7 +48,9 @@ def test_get_skel_file(tmp_path, monkeypatch):
assert Path(new_skel).stat().st_size > 0

latest_md5 = (
requests.get(tfc._s3.TF_SKEL_URL(release='master', ext='md5', allow_redirects=True), timeout=10)
requests.get(
tfc._s3.TF_SKEL_URL(release='master', ext='md5', allow_redirects=True), timeout=10
)
.content.decode()
.split()[0]
)
Expand Down
1 change: 1 addition & 0 deletions templateflow/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Test version retrieval."""

import sys
from importlib import reload
from importlib.metadata import PackageNotFoundError
Expand Down

0 comments on commit 406ef77

Please sign in to comment.