Skip to content

Commit 0f5b65b

Browse files
authored
chore/sty: Replace black+flake8 with ruff, add pre-commit (#904)
* sty: Disable black, configure ruff * sty: ruff format [ignore-rev] Follow-up with ruff check --select ISC001 --fix * sty: ruff check --fix [ignore-rev] * rf: Remove unused sphinxext modules * sty: ruff check --fix --unsafe-fixes, reviewed and curated Follow up with ruff format and ruff check --select ISC001 --fix * sty: Manual fixes for remaining checks * Add pre-commit configuration * sty: Apply pre-commit hooks * chore: Remove flake8 config * chore(pre-commit): Improve names for ruff hooks * chore: Move codespell config to pyproject.toml * ci: Run tox checks * ci: Rename workflow to tox.yml
1 parent 4984e53 commit 0f5b65b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4708
-6871
lines changed

.codespellrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.flake8

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/pythonpackage.yml renamed to .github/workflows/tox.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,20 @@ jobs:
158158
token: ${{ secrets.CODECOV_TOKEN }}
159159
if: ${{ always() }}
160160

161-
flake8:
162-
if: github.event_name != 'schedule'
163-
runs-on: ubuntu-latest
161+
checks:
162+
runs-on: 'ubuntu-latest'
163+
continue-on-error: true
164+
strategy:
165+
matrix:
166+
check: ['style', 'spellcheck']
167+
164168
steps:
165-
- uses: actions/checkout@v4
166-
- name: Set up Python 3
167-
uses: actions/setup-python@v5
168-
with:
169-
python-version: 3
170-
- run: pipx run flake8 niworkflows/
169+
- uses: actions/checkout@v4
170+
- name: Install the latest version of uv
171+
uses: astral-sh/setup-uv@v3
172+
- name: Show tox config
173+
run: uvx tox c
174+
- name: Show tox config (this call)
175+
run: uvx tox c -e ${{ matrix.check }}
176+
- name: Run check
177+
run: uvx tox -e ${{ matrix.check }}

.pep8speaks.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
exclude: ".*/data/.*"
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.4.0
5+
hooks:
6+
- id: trailing-whitespace
7+
exclude: 'examples'
8+
- id: end-of-file-fixer
9+
exclude: 'examples|docs/_static/.*\.(css|js)'
10+
- id: check-yaml
11+
- id: check-json
12+
- id: check-toml
13+
- id: check-added-large-files
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
rev: v0.7.4
16+
hooks:
17+
- name: ruff check --fix
18+
id: ruff
19+
args: [ --fix ]
20+
- name: ruff format
21+
id: ruff-format
22+
- name: fix implicit string concatenation
23+
id: ruff
24+
args: [ --select, ISC001, --fix ]

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,3 @@
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202-

docker/fetch_templates.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def fetch_MNI2009():
1919
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-02_desc-fMRIPrep_boldref.nii.gz
2020
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_label-brain_probseg.nii.gz
2121
"""
22-
template = "MNI152NLin2009cAsym"
22+
template = 'MNI152NLin2009cAsym'
2323

24-
tf.get(template, resolution=2, desc="brain", suffix="mask")
25-
tf.get(template, resolution=2, desc="fMRIPrep", suffix="boldref")
26-
tf.get(template, resolution=1, label="brain", suffix="probseg")
24+
tf.get(template, resolution=2, desc='brain', suffix='mask')
25+
tf.get(template, resolution=2, desc='fMRIPrep', suffix='boldref')
26+
tf.get(template, resolution=1, label='brain', suffix='probseg')
2727

2828

2929
def fetch_MNI152Lin():
@@ -33,10 +33,10 @@ def fetch_MNI152Lin():
3333
tpl-MNI152Lin/tpl-MNI152Lin_res-02_T1w.nii.gz
3434
tpl-MNI152Lin/tpl-MNI152Lin_res-02_desc-brain_mask.nii.gz
3535
"""
36-
template = "MNI152Lin"
36+
template = 'MNI152Lin'
3737

38-
tf.get(template, resolution=2, desc=None, suffix="T1w")
39-
tf.get(template, resolution=2, desc="brain", suffix="mask")
38+
tf.get(template, resolution=2, desc=None, suffix='T1w')
39+
tf.get(template, resolution=2, desc='brain', suffix='mask')
4040

4141

4242
def fetch_OASIS():
@@ -50,13 +50,13 @@ def fetch_OASIS():
5050
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-brain_mask.nii.gz
5151
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-BrainCerebellumExtraction_mask.nii.gz
5252
"""
53-
template = "OASIS30ANTs"
53+
template = 'OASIS30ANTs'
5454

55-
tf.get(template, resolution=1, desc="4", suffix="dseg")
56-
tf.get(template, resolution=1, desc=None, suffix="T1w")
57-
tf.get(template, resolution=1, label="brain", suffix="mask")
58-
tf.get(template, resolution=1, desc="BrainCerebellumExtraction", suffix="mask")
59-
tf.get(template, resolution=1, label="brain", suffix="probseg")
55+
tf.get(template, resolution=1, desc='4', suffix='dseg')
56+
tf.get(template, resolution=1, desc=None, suffix='T1w')
57+
tf.get(template, resolution=1, label='brain', suffix='mask')
58+
tf.get(template, resolution=1, desc='BrainCerebellumExtraction', suffix='mask')
59+
tf.get(template, resolution=1, label='brain', suffix='probseg')
6060

6161

6262
def fetch_fsaverage():
@@ -70,10 +70,10 @@ def fetch_fsaverage():
7070
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_midthickness.surf.gii
7171
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_midthickness.surf.gii
7272
"""
73-
template = "fsaverage"
73+
template = 'fsaverage'
7474

75-
tf.get(template, density="164k", desc="std", suffix="sphere")
76-
tf.get(template, density="164k", suffix="midthickness")
75+
tf.get(template, density='164k', desc='std', suffix='sphere')
76+
tf.get(template, density='164k', suffix='midthickness')
7777

7878

7979
def fetch_fsLR():
@@ -89,7 +89,7 @@ def fetch_fsLR():
8989
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-32k_sphere.surf.gii
9090
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii
9191
"""
92-
tf.get("fsLR", density="32k")
92+
tf.get('fsLR', density='32k')
9393

9494

9595
def fetch_all():
@@ -100,21 +100,21 @@ def fetch_all():
100100
fetch_fsLR()
101101

102102

103-
if __name__ == "__main__":
103+
if __name__ == '__main__':
104104
parser = argparse.ArgumentParser(
105-
description="Helper script for pre-caching required templates to run fMRIPrep",
105+
description='Helper script for pre-caching required templates to run fMRIPrep',
106106
)
107107
parser.add_argument(
108-
"--tf-dir",
108+
'--tf-dir',
109109
type=os.path.abspath,
110-
help="Directory to save templates in. If not provided, templates will be saved to"
111-
" `${HOME}/.cache/templateflow`.",
110+
help='Directory to save templates in. If not provided, templates will be saved to'
111+
' `${HOME}/.cache/templateflow`.',
112112
)
113113
opts = parser.parse_args()
114114

115115
# set envvar (if necessary) prior to templateflow import
116116
if opts.tf_dir is not None:
117-
os.environ["TEMPLATEFLOW_HOME"] = opts.tf_dir
117+
os.environ['TEMPLATEFLOW_HOME'] = opts.tf_dir
118118

119119
import templateflow.api as tf
120120

0 commit comments

Comments
 (0)