From 2dea754adefa7c38e6b747df77e3c7a4449a8fdf Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Feb 2024 12:05:21 -0500 Subject: [PATCH 1/7] MNT: Configure ruff for wrapper, disable black --- wrapper/pyproject.toml | 45 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/wrapper/pyproject.toml b/wrapper/pyproject.toml index fb5800a8a..4fa776574 100644 --- a/wrapper/pyproject.toml +++ b/wrapper/pyproject.toml @@ -63,10 +63,47 @@ universal = true # Developer tool configurations # +# Disable black [tool.black] +exclude = ".*" + +[tool.ruff] line-length = 99 -target-version = ['py39'] -skip-string-normalization = true -[tool.isort] -profile = 'black' +[tool.ruff.lint] +extend-select = [ + "F", + "E", + "W", + "I", + "YTT", + "BLE", + "B", + "A", + # "CPY", + "C4", + "DTZ", + "T10", + # "EM", + "EXE", + "FA", + "ISC", + "ICN", + "PT", + "Q", +] +extend-ignore = [ + "S311", # We are not using random for cryptographic purposes + "ISC001", +] + +[tool.ruff.lint.flake8-quotes] +inline-quotes = "single" + +[tool.ruff.lint.extend-per-file-ignores] +"*/test_*.py" = ["S101"] +"fmriprep/utils/debug.py" = ["A002", "T100"] +"docs/conf.py" = ["A001"] + +[tool.ruff.format] +quote-style = "single" From e7dc59fbc7df88dfabbff154f4cc3d24721b6b4f Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Feb 2024 12:06:27 -0500 Subject: [PATCH 2/7] STY: ruff --fix + 1 ignore [git-blame-ignore-rev] --- wrapper/src/fmriprep_docker/__main__.py | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/wrapper/src/fmriprep_docker/__main__.py b/wrapper/src/fmriprep_docker/__main__.py index 04fffe0b5..44d6e1a3b 100755 --- a/wrapper/src/fmriprep_docker/__main__.py +++ b/wrapper/src/fmriprep_docker/__main__.py @@ -93,7 +93,7 @@ def _run(args, stdout=None, stderr=None): # De-fang Python 2's input - we don't eval user input try: - input = raw_input + input = raw_input # noqa: A001 except NameError: pass @@ -116,7 +116,7 @@ def check_docker(): if e.errno == ENOENT: return -1 raise e - if ret.stderr.startswith(b"Cannot connect to the Docker daemon."): + if ret.stderr.startswith(b'Cannot connect to the Docker daemon.'): return 0 return 1 @@ -154,11 +154,11 @@ def _get_posargs(usage): line = targ.lstrip() if line.startswith('usage'): continue - if line[0].isalnum() or line[0] == "{": + if line[0].isalnum() or line[0] == '{': posargs.append(line) - elif line[0] == '[' and (line[1].isalnum() or line[1] == "{"): + elif line[0] == '[' and (line[1].isalnum() or line[1] == '{'): posargs.append(line) - return " ".join(posargs) + return ' '.join(posargs) # Matches all flags with up to two nested square brackets # I'm sorry. @@ -203,7 +203,7 @@ def _get_posargs(usage): 'w', } - assert overlap == expected_overlap, "Clobbering options: {}".format( + assert overlap == expected_overlap, 'Clobbering options: {}'.format( ', '.join(overlap - expected_overlap) ) @@ -263,7 +263,7 @@ class ToDict(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): d = {} for kv in values: - k, v = kv.split("=") + k, v = kv.split('=') d[k] = os.path.abspath(v) setattr(namespace, self.dest, d) @@ -271,7 +271,7 @@ def _is_file(path, parser): """Ensure a given path exists and it is a file.""" path = os.path.abspath(path) if not os.path.isfile(path): - raise parser.error("Path should point to a file (or symlink of file): <%s>." % path) + raise parser.error('Path should point to a file (or symlink of file): <%s>.' % path) return path parser = argparse.ArgumentParser( @@ -288,7 +288,7 @@ def _is_file(path, parser): ) parser.add_argument( - '-h', '--help', action='store_true', help="show this help message and exit" + '-h', '--help', action='store_true', help='show this help message and exit' ) parser.add_argument( '--version', action='store_true', help="show program's version number and exit" @@ -319,7 +319,7 @@ def _is_file(path, parser): ) g_wrap.add_argument( '--output-spaces', - nargs="*", + nargs='*', ) g_wrap.add_argument( @@ -370,8 +370,8 @@ def _is_file(path, parser): ) g_dev.add_argument( '--patch', - nargs="+", - metavar="PACKAGE=PATH", + nargs='+', + metavar='PACKAGE=PATH', action=ToDict, help='Sequence of PACKAGE=PATH specifications to patch a Python package into the ' 'container Python environment.', @@ -431,7 +431,7 @@ def main(): if opts.help: parser.print_help() if check == -1: - print("fmriprep: Could not find docker command... Is it installed?") + print('fmriprep: Could not find docker command... Is it installed?') else: print("fmriprep: Make sure you have permission to run 'docker'") return 1 @@ -477,7 +477,7 @@ def main(): return 0 ret = subprocess.run( - ['docker', 'version', '--format', "{{.Server.Version}}"], stdout=subprocess.PIPE + ['docker', 'version', '--format', '{{.Server.Version}}'], stdout=subprocess.PIPE ) docker_version = ret.stdout.decode('ascii').strip() @@ -566,7 +566,7 @@ def main(): if space.split(':')[0] not in (TF_TEMPLATES + NONSTANDARD_REFERENCES): tpl = os.path.basename(space) if not tpl.startswith('tpl-'): - raise RuntimeError("Custom template %s requires a `tpl-` prefix" % tpl) + raise RuntimeError('Custom template %s requires a `tpl-` prefix' % tpl) target = '/home/fmriprep/.cache/templateflow/' + tpl command.extend(['-v', ':'.join((os.path.abspath(space), target, 'ro'))]) spaces.append(tpl[4:]) @@ -599,10 +599,10 @@ def main(): command.extend(main_args) command.extend(unknown_args) - print("RUNNING: " + ' '.join(command)) + print('RUNNING: ' + ' '.join(command)) ret = subprocess.run(command) if ret.returncode: - print("fMRIPrep: Please report errors to {}".format(__bugreports__)) + print('fMRIPrep: Please report errors to {}'.format(__bugreports__)) return ret.returncode From e5c46a8db4121474eefdb8b931ba11d03e121276 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Feb 2024 12:08:03 -0500 Subject: [PATCH 3/7] MNT: Update .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index c1bfd8669..d930a2d21 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,3 +1,5 @@ +# 2024-02-05 - effigies@gmail.com - STY: ruff --fix + 1 ignore [git-blame-ignore-rev] +e7dc59fbc7df88dfabbff154f4cc3d24721b6b4f # 2024-01-16 - effigies@gmail.com - STY: ruff --fix --unsafe-fixes (with cleanup) [git-blame-ignore-rev] 66734bd0164d1dae3cf299fa9d9d682c22eeda66 # 2024-01-16 - effigies@gmail.com - STY: ruff format and ruff --fix [git-blame-ignore-rev] From bf632631a5d5ff4d06acb79024ee89cd5868139d Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Feb 2024 12:09:10 -0500 Subject: [PATCH 4/7] MNT: chmod +x --- .maint/paper_author_list.py | 0 .maint/update_authors.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .maint/paper_author_list.py mode change 100644 => 100755 .maint/update_authors.py diff --git a/.maint/paper_author_list.py b/.maint/paper_author_list.py old mode 100644 new mode 100755 diff --git a/.maint/update_authors.py b/.maint/update_authors.py old mode 100644 new mode 100755 From 4ffce8d35210c0c14bfb7255871265e158ca3189 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Feb 2024 14:45:24 -0500 Subject: [PATCH 5/7] STY: Disable S603 --- fmriprep/cli/workflow.py | 4 ++-- fmriprep/utils/bids.py | 2 +- pyproject.toml | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fmriprep/cli/workflow.py b/fmriprep/cli/workflow.py index a4ff1b73a..903ce6127 100644 --- a/fmriprep/cli/workflow.py +++ b/fmriprep/cli/workflow.py @@ -215,7 +215,7 @@ def build_boilerplate(config_file, workflow): config.loggers.cli.info('Generating an HTML version of the citation boilerplate...') try: - check_call(cmd, timeout=10) # noqa: S603 + check_call(cmd, timeout=10) except (FileNotFoundError, CalledProcessError, TimeoutExpired): config.loggers.cli.warning('Could not generate CITATION.html file:\n%s', ' '.join(cmd)) @@ -232,6 +232,6 @@ def build_boilerplate(config_file, workflow): ] config.loggers.cli.info('Generating a LaTeX version of the citation boilerplate...') try: - check_call(cmd, timeout=10) # noqa: S603 + check_call(cmd, timeout=10) except (FileNotFoundError, CalledProcessError, TimeoutExpired): config.loggers.cli.warning('Could not generate CITATION.tex file:\n%s', ' '.join(cmd)) diff --git a/fmriprep/utils/bids.py b/fmriprep/utils/bids.py index 6a4003025..700f30def 100644 --- a/fmriprep/utils/bids.py +++ b/fmriprep/utils/bids.py @@ -233,7 +233,7 @@ def validate_input_dir(exec_env, bids_dir, participant_label, need_T1w=True): temp.write(json.dumps(validator_config_dict)) temp.flush() try: - subprocess.check_call(['bids-validator', str(bids_dir), '-c', temp.name]) # noqa: S603, S607 + subprocess.check_call(['bids-validator', str(bids_dir), '-c', temp.name]) # noqa: S607 except FileNotFoundError: print('bids-validator does not appear to be installed', file=sys.stderr) diff --git a/pyproject.toml b/pyproject.toml index 65b0aa0d4..f0e7c29f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -176,6 +176,7 @@ extend-select = [ extend-ignore = [ "S311", # We are not using random for cryptographic purposes "ISC001", + "S603", ] [tool.ruff.lint.flake8-quotes] From 52be90a29bc82ea5a126854e75f7166a743b64f7 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Feb 2024 14:45:44 -0500 Subject: [PATCH 6/7] MNT: Ignore BLE001 (blind exceptions) for sphinxext module --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index f0e7c29f9..320c3da77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -186,6 +186,7 @@ inline-quotes = "single" "*/test_*.py" = ["S101"] "fmriprep/utils/debug.py" = ["A002", "T100"] "docs/conf.py" = ["A001"] +"docs/sphinxext/github_link.py" = ["BLE001"] [tool.ruff.format] quote-style = "single" From 44ff6d0f85b702d57497d7211ec3eee177266b25 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Tue, 6 Feb 2024 08:56:26 -0500 Subject: [PATCH 7/7] CI: Lint and style check full repository --- .github/workflows/contrib.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 5d0d723a2..32dbec8b3 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -26,8 +26,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: pipx run ruff fmriprep - - run: pipx run ruff format --diff fmriprep + - run: pipx run ruff . + - run: pipx run ruff format --diff . codespell: name: Check for spelling errors