Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/sty: Replace black+flake8 with ruff, add pre-commit #904

Merged
merged 13 commits into from
Nov 22, 2024
Merged
5 changes: 0 additions & 5 deletions .codespellrc

This file was deleted.

12 changes: 0 additions & 12 deletions .flake8

This file was deleted.

25 changes: 16 additions & 9 deletions .github/workflows/pythonpackage.yml → .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,20 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
if: ${{ always() }}

flake8:
if: github.event_name != 'schedule'
runs-on: ubuntu-latest
checks:
runs-on: 'ubuntu-latest'
continue-on-error: true
strategy:
matrix:
check: ['style', 'spellcheck']

steps:
- uses: actions/checkout@v4
- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: 3
- run: pipx run flake8 niworkflows/
- uses: actions/checkout@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
- name: Show tox config
run: uvx tox c
- name: Show tox config (this call)
run: uvx tox c -e ${{ matrix.check }}
- name: Run check
run: uvx tox -e ${{ matrix.check }}
12 changes: 0 additions & 12 deletions .pep8speaks.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exclude: ".*/data/.*"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: 'examples'
- id: end-of-file-fixer
exclude: 'examples|docs/_static/.*\.(css|js)'
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
hooks:
- name: ruff check --fix
id: ruff
args: [ --fix ]
- name: ruff format
id: ruff-format
- name: fix implicit string concatenation
id: ruff
args: [ --select, ISC001, --fix ]
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

46 changes: 23 additions & 23 deletions docker/fetch_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def fetch_MNI2009():
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-02_desc-fMRIPrep_boldref.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_label-brain_probseg.nii.gz
"""
template = "MNI152NLin2009cAsym"
template = 'MNI152NLin2009cAsym'

tf.get(template, resolution=2, desc="brain", suffix="mask")
tf.get(template, resolution=2, desc="fMRIPrep", suffix="boldref")
tf.get(template, resolution=1, label="brain", suffix="probseg")
tf.get(template, resolution=2, desc='brain', suffix='mask')
tf.get(template, resolution=2, desc='fMRIPrep', suffix='boldref')
tf.get(template, resolution=1, label='brain', suffix='probseg')


def fetch_MNI152Lin():
Expand All @@ -33,10 +33,10 @@ def fetch_MNI152Lin():
tpl-MNI152Lin/tpl-MNI152Lin_res-02_T1w.nii.gz
tpl-MNI152Lin/tpl-MNI152Lin_res-02_desc-brain_mask.nii.gz
"""
template = "MNI152Lin"
template = 'MNI152Lin'

tf.get(template, resolution=2, desc=None, suffix="T1w")
tf.get(template, resolution=2, desc="brain", suffix="mask")
tf.get(template, resolution=2, desc=None, suffix='T1w')
tf.get(template, resolution=2, desc='brain', suffix='mask')


def fetch_OASIS():
Expand All @@ -50,13 +50,13 @@ def fetch_OASIS():
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-brain_mask.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-BrainCerebellumExtraction_mask.nii.gz
"""
template = "OASIS30ANTs"
template = 'OASIS30ANTs'

tf.get(template, resolution=1, desc="4", suffix="dseg")
tf.get(template, resolution=1, desc=None, suffix="T1w")
tf.get(template, resolution=1, label="brain", suffix="mask")
tf.get(template, resolution=1, desc="BrainCerebellumExtraction", suffix="mask")
tf.get(template, resolution=1, label="brain", suffix="probseg")
tf.get(template, resolution=1, desc='4', suffix='dseg')
tf.get(template, resolution=1, desc=None, suffix='T1w')
tf.get(template, resolution=1, label='brain', suffix='mask')
tf.get(template, resolution=1, desc='BrainCerebellumExtraction', suffix='mask')
tf.get(template, resolution=1, label='brain', suffix='probseg')


def fetch_fsaverage():
Expand All @@ -70,10 +70,10 @@ def fetch_fsaverage():
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_midthickness.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_midthickness.surf.gii
"""
template = "fsaverage"
template = 'fsaverage'

tf.get(template, density="164k", desc="std", suffix="sphere")
tf.get(template, density="164k", suffix="midthickness")
tf.get(template, density='164k', desc='std', suffix='sphere')
tf.get(template, density='164k', suffix='midthickness')


def fetch_fsLR():
Expand All @@ -89,7 +89,7 @@ def fetch_fsLR():
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-32k_sphere.surf.gii
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii
"""
tf.get("fsLR", density="32k")
tf.get('fsLR', density='32k')


def fetch_all():
Expand All @@ -100,21 +100,21 @@ def fetch_all():
fetch_fsLR()


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

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

import templateflow.api as tf

Expand Down
Loading
Loading