diff --git a/.maint/update_requirements.py b/.maint/update_requirements.py old mode 100644 new mode 100755 index 3a10c150..c3b9fcec --- a/.maint/update_requirements.py +++ b/.maint/update_requirements.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from copy import copy from pathlib import Path + from packaging.requirements import Requirement, SpecifierSet try: @@ -9,13 +10,13 @@ from pip._vendor.tomli import loads repo_root = Path(__file__).parent.parent -pyproject = repo_root / "pyproject.toml" -reqs = repo_root / "requirements.txt" -min_reqs = repo_root / "min-requirements.txt" +pyproject = repo_root / 'pyproject.toml' +reqs = repo_root / 'requirements.txt' +min_reqs = repo_root / 'min-requirements.txt' requirements = [ Requirement(req) - for req in loads(pyproject.read_text())["project"]["dependencies"] + for req in loads(pyproject.read_text())['project']['dependencies'] ] script_name = Path(__file__).relative_to(repo_root) @@ -25,20 +26,20 @@ def to_min(req): if req.specifier: req = copy(req) try: - min_spec = [spec for spec in req.specifier if spec.operator in (">=", "~=")][0] + min_spec = [spec for spec in req.specifier if spec.operator in ('>=', '~=')][0] except IndexError: return req - min_spec._spec = ("==",) + min_spec._spec[1:] + min_spec._spec = ('==',) + min_spec._spec[1:] req.specifier = SpecifierSet(str(min_spec)) return req -lines = [f"# Auto-generated by {script_name}", ""] +lines = [f'# Auto-generated by {script_name}', ''] # Write requirements lines[1:-1] = [str(req) for req in requirements] -reqs.write_text("\n".join(lines)) +reqs.write_text('\n'.join(lines)) # Write minimum requirements lines[1:-1] = [str(to_min(req)) for req in requirements] -min_reqs.write_text("\n".join(lines)) +min_reqs.write_text('\n'.join(lines)) diff --git a/templateflow/api.py b/templateflow/api.py index eadb07eb..5b5f668f 100644 --- a/templateflow/api.py +++ b/templateflow/api.py @@ -1,6 +1,5 @@ """TemplateFlow's Python Client.""" import sys -from importlib import import_module from json import loads from pathlib import Path from bids.layout import Query @@ -11,6 +10,7 @@ item for item in dir(TF_LAYOUT) if item.startswith("get_") ) + @requires_layout def ls(template, **kwargs): """ diff --git a/templateflow/tests/test_api.py b/templateflow/tests/test_api.py index de8cd951..3e9f4e72 100644 --- a/templateflow/tests/test_api.py +++ b/templateflow/tests/test_api.py @@ -14,7 +14,7 @@ def __init__(self, bibtex): self.pairs = {} # DOI could not be converted - if self.text.startswith("http"): + if self.text.startswith('http'): self.url_only = True else: self._parse_bibtex() @@ -23,15 +23,15 @@ def _parse_bibtex(self): import re try: - self.etype = re.search(r"@(\w+)", self.text).group(1) + self.etype = re.search(r'@(\w+)', self.text).group(1) except AttributeError: - raise TypeError(f"Invalid bibtex: {self.text}") + raise TypeError(f'Invalid bibtex: {self.text}') try: - self.citekey = re.search(r"@[^{]*{([^,\s]+)", self.text).group(1) + self.citekey = re.search(r'@[^{]*{([^,\s]+)', self.text).group(1) except AttributeError: - raise TypeError(f"Invalid bibtex: {self.text}") + raise TypeError(f'Invalid bibtex: {self.text}') self.pairs = { - key: val for key, val in re.findall(r"(\w+)=(\{[^{}]+\})", self.text) + key: val for key, val in re.findall(r'(\w+)=(\{[^{}]+\})', self.text) } def get(self, val): @@ -41,7 +41,10 @@ def __str__(self): return self.text def __repr__(self): - return f'@{self.etype}{{{self.citekey}, {", ".join([f"{key} = {val}" for key, val in self.pairs.items()])}}}' + return ( + f'@{self.etype}{{{self.citekey}, ' + f'{", ".join([f"{key} = {val}" for key, val in self.pairs.items()])}}}' + ) def __eq__(self, other): if isinstance(other, Bibtex): @@ -58,26 +61,26 @@ def __eq__(self, other): def assert_same(self, other): """Convenience method to find deviations between two Bibtex objects""" assert isinstance(other, Bibtex) - assert self.etype == other.etype, "Mismatched entry types" - assert self.citekey == other.citekey, "Mismatched citekeys" + assert self.etype == other.etype, 'Mismatched entry types' + assert self.citekey == other.citekey, 'Mismatched citekeys' for key in self.pairs.keys(): - assert key in other.pairs, f"Key ({key}) missing from other" + assert key in other.pairs, f'Key ({key}) missing from other' assert ( self.pairs[key] == other.pairs[key] - ), f"Key ({key}) mismatched\n\n{self.pairs[key]}\n\n{other.pairs[key]}" + ), f'Key ({key}) mismatched\n\n{self.pairs[key]}\n\n{other.pairs[key]}' for key in other.pairs.keys(): - assert key in self.pairs, f"Key ({key}) missing from pairs" + assert key in self.pairs, f'Key ({key}) missing from pairs' - assert self.pairs == other.pairs, "Dictionaries do not match" + assert self.pairs == other.pairs, 'Dictionaries do not match' # test setup to avoid cluttering pytest parameterize mni2009_urls = [ - "https://doi.org/10.1016/j.neuroimage.2010.07.033", - "https://doi.org/10.1016/S1053-8119(09)70884-5", - "http://nist.mni.mcgill.ca/?p=904", - "https://doi.org/10.1007/3-540-48714-X_16", + 'https://doi.org/10.1016/j.neuroimage.2010.07.033', + 'https://doi.org/10.1016/S1053-8119(09)70884-5', + 'http://nist.mni.mcgill.ca/?p=904', + 'https://doi.org/10.1007/3-540-48714-X_16', ] mni2009_fbib = """\ @@ -111,8 +114,8 @@ def assert_same(self, other): }""" fslr_urls = [ - "https://doi.org/10.1093/cercor/bhr291", - "https://github.com/Washington-University/HCPpipelines/tree/master/global/templates", + 'https://doi.org/10.1093/cercor/bhr291', + 'https://github.com/Washington-University/HCPpipelines/tree/master/global/templates', ] fslr_fbib = """\ @@ -132,7 +135,7 @@ def assert_same(self, other): }""" fslr_lbib = ( - "https://github.com/Washington-University/HCPpipelines/tree/master/global/templates" + 'https://github.com/Washington-University/HCPpipelines/tree/master/global/templates' ) fsaverage_fbib = """\ @@ -152,14 +155,14 @@ def assert_same(self, other): @pytest.mark.parametrize( - "template,urls,fbib,lbib", + 'template,urls,fbib,lbib', [ - ("MNI152NLin2009cAsym", mni2009_urls, mni2009_fbib, mni2009_lbib), - ("fsLR", fslr_urls, fslr_fbib, fslr_lbib), + ('MNI152NLin2009cAsym', mni2009_urls, mni2009_fbib, mni2009_lbib), + ('fsLR', fslr_urls, fslr_fbib, fslr_lbib), ( - "fsaverage", + '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, @@ -189,12 +192,12 @@ def test_citations(tmp_path, template, urls, fbib, lbib): def test_pybids_magic_get(): """Check automatic entity expansion of the layout.""" assert sorted(api.ls_atlases()) == sorted(api.TF_LAYOUT.get_atlases()) - assert sorted(api.ls_atlases(template="MNI152NLin6ASym")) == sorted( - api.TF_LAYOUT.get_atlases(template="MNI152NLin6ASym") + assert sorted(api.ls_atlases(template='MNI152NLin6ASym')) == sorted( + api.TF_LAYOUT.get_atlases(template='MNI152NLin6ASym') ) with pytest.raises(TypeError): - api.ls_atlases("MNI152NLin6ASym") + api.ls_atlases('MNI152NLin6ASym') # Existing layout.get_* should not be bubbled to the layout # (that means, raise an AttributeError instead of a BIDSEntityError) diff --git a/templateflow/tests/test_version.py b/templateflow/tests/test_version.py index 30604d73..2972c8c2 100644 --- a/templateflow/tests/test_version.py +++ b/templateflow/tests/test_version.py @@ -1,6 +1,5 @@ """Test _version.py.""" import sys -from collections import namedtuple from importlib.metadata import PackageNotFoundError from importlib import reload import templateflow