From 07563ed249a69dadca733673297756a12421afef Mon Sep 17 00:00:00 2001
From: Taylor Salo
Date: Thu, 21 Nov 2024 08:42:18 -0500
Subject: [PATCH] Run ruff and ignore lingering issues.
---
docs/conf.py | 152 ++++++++++++++++-----------------
pyproject.toml | 12 ++-
qsiprep/interfaces/epi_fmap.py | 4 +-
qsiprep/interfaces/images.py | 9 +-
qsiprep/interfaces/itk.py | 4 +-
qsiprep/interfaces/tortoise.py | 2 +-
qsiprep/utils/shm.py | 2 +-
7 files changed, 96 insertions(+), 89 deletions(-)
diff --git a/docs/conf.py b/docs/conf.py
index 17374428..20941f83 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# QSIPrep documentation build configuration file, created by
# sphinx-quickstart on Mon May 9 09:04:25 2016.
@@ -30,66 +29,66 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-sys.path.append(os.path.abspath("sphinxext"))
-sys.path.insert(0, os.path.abspath("../qsiprep"))
+sys.path.append(os.path.abspath('sphinxext'))
+sys.path.insert(0, os.path.abspath('../qsiprep'))
from github_link import make_linkcode_resolve
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
-needs_sphinx = "4.2.0"
+needs_sphinx = '4.2.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
- "nbsphinx",
- "nipype.sphinxext.apidoc",
- "nipype.sphinxext.plot_workflow",
- "recommonmark",
- "sphinx.ext.autodoc",
- "sphinx.ext.coverage",
- "sphinx.ext.doctest",
- "sphinx.ext.intersphinx",
- "sphinx.ext.linkcode",
- "sphinx.ext.mathjax",
- "sphinx_markdown_tables",
- "sphinxarg.ext", # argparse extension
- "sphinxcontrib.apidoc",
- "sphinxcontrib.bibtex",
+ 'nbsphinx',
+ 'nipype.sphinxext.apidoc',
+ 'nipype.sphinxext.plot_workflow',
+ 'recommonmark',
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.coverage',
+ 'sphinx.ext.doctest',
+ 'sphinx.ext.intersphinx',
+ 'sphinx.ext.linkcode',
+ 'sphinx.ext.mathjax',
+ 'sphinx_markdown_tables',
+ 'sphinxarg.ext', # argparse extension
+ 'sphinxcontrib.apidoc',
+ 'sphinxcontrib.bibtex',
]
# Mock modules in autodoc:
autodoc_mock_imports = [
- "matplotlib",
- "nilearn",
- "numpy",
- "pandas",
- "pygraphviz",
- "seaborn",
+ 'matplotlib',
+ 'nilearn',
+ 'numpy',
+ 'pandas',
+ 'pygraphviz',
+ 'seaborn',
]
# NOTE: Not in qsiprep
# autosectionlabel_prefix_document = True
# Add any paths that contain templates here, relative to this directory.
-templates_path = ["_templates"]
+templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffixes as a list of string:
-source_suffix = [".rst", ".md"]
+source_suffix = ['.rst', '.md']
# The encoding of source files.
# source_encoding = 'utf-8-sig'
# The master toctree document.
-master_doc = "index"
+master_doc = 'index'
# General information about the project.
-project = "qsiprep"
-author = "qsiprep team"
-copyright = f"2021-{datetime.now().year}, {author}"
+project = 'qsiprep'
+author = 'qsiprep team'
+copyright = f'2021-{datetime.now().year}, {author}'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -105,7 +104,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
-language = "en"
+language = 'en'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
@@ -116,7 +115,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
-exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# The reST default role (used for this markup: `text`) to use for all
# documents.
@@ -134,7 +133,7 @@
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
-pygments_style = "default"
+pygments_style = 'default'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
@@ -169,26 +168,26 @@
# https://github.com/sphinx-contrib/napoleon/pull/10 is merged.
napoleon_use_param = False
napoleon_custom_sections = [
- ("Inputs", "Parameters"),
- ("Outputs", "Parameters"),
- ("Attributes", "Parameters"),
- ("Mandatory Inputs", "Parameters"),
- ("Optional Inputs", "Parameters"),
- ("License", "License"),
+ ('Inputs', 'Parameters'),
+ ('Outputs', 'Parameters'),
+ ('Attributes', 'Parameters'),
+ ('Mandatory Inputs', 'Parameters'),
+ ('Optional Inputs', 'Parameters'),
+ ('License', 'License'),
]
# -- Extension configuration -------------------------------------------------
-apidoc_module_dir = "../qsiprep"
-apidoc_output_dir = "api"
-apidoc_excluded_paths = ["conftest.py", "*/tests/*", "tests/*", "data/*"]
+apidoc_module_dir = '../qsiprep'
+apidoc_output_dir = 'api'
+apidoc_excluded_paths = ['conftest.py', '*/tests/*', 'tests/*', 'data/*']
apidoc_separate_modules = True
-apidoc_extra_args = ["--module-first", "-d 1", "-T"]
+apidoc_extra_args = ['--module-first', '-d 1', '-T']
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
-html_theme = "sphinx_rtd_theme"
+html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@@ -217,7 +216,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ["_static"]
+html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
@@ -282,7 +281,7 @@
# html_search_scorer = 'scorer.js'
# Output file base name for HTML help builder.
-htmlhelp_basename = "qsiprep_doc"
+htmlhelp_basename = 'qsiprep_doc'
# -- Options for LaTeX output ---------------------------------------------
@@ -301,7 +300,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
- (master_doc, "qsiprep.tex", "qsiprep Documentation", author, "manual"),
+ (master_doc, 'qsiprep.tex', 'qsiprep Documentation', author, 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -329,7 +328,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
-man_pages = [(master_doc, "qsiprep", "qsiprep Documentation", [author], 1)]
+man_pages = [(master_doc, 'qsiprep', 'qsiprep Documentation', [author], 1)]
# If true, show URL addresses after external links.
# man_show_urls = False
@@ -343,12 +342,12 @@
texinfo_documents = [
(
master_doc,
- "qsiprep",
- "QSIPrep Documentation",
+ 'qsiprep',
+ 'QSIPrep Documentation',
author,
- "qsiprep",
- "One line description of project.",
- "Miscellaneous",
+ 'qsiprep',
+ 'One line description of project.',
+ 'Miscellaneous',
),
]
@@ -366,47 +365,46 @@
# The following is used by sphinx.ext.linkcode to provide links to github
linkcode_resolve = make_linkcode_resolve(
- "qsiprep",
+ 'qsiprep',
(
- "https://github.com/pennlinc/qsiprep/blob/"
- "{revision}/{package}/{path}#L{lineno}" # noqa: FS003
+ 'https://github.com/pennlinc/qsiprep/blob/' '{revision}/{package}/{path}#L{lineno}' # noqa: FS003
),
)
# -----------------------------------------------------------------------------
# intersphinx
# -----------------------------------------------------------------------------
-_python_version_str = f"{sys.version_info.major}.{sys.version_info.minor}"
-_python_doc_base = f"https://docs.python.org/{_python_version_str}"
+_python_version_str = f'{sys.version_info.major}.{sys.version_info.minor}'
+_python_doc_base = f'https://docs.python.org/{_python_version_str}'
intersphinx_mapping = {
- "python": (_python_doc_base, None),
- "numpy": ("https://numpy.org/doc/stable/", None),
- "scipy": (
- "https://docs.scipy.org/doc/scipy/reference",
- (None, "./_intersphinx/scipy-objects.inv"),
+ 'python': (_python_doc_base, None),
+ 'numpy': ('https://numpy.org/doc/stable/', None),
+ 'scipy': (
+ 'https://docs.scipy.org/doc/scipy/reference',
+ (None, './_intersphinx/scipy-objects.inv'),
),
- "matplotlib": (
- "https://matplotlib.org/stable/",
- (None, "https://matplotlib.org/stable/objects.inv"),
+ 'matplotlib': (
+ 'https://matplotlib.org/stable/',
+ (None, 'https://matplotlib.org/stable/objects.inv'),
),
- "pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
- "nibabel": ("https://nipy.org/nibabel/", None),
- "nilearn": ("http://nilearn.github.io/stable/", None),
- "nipype": ("https://nipype.readthedocs.io/en/latest/", None),
+ 'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
+ 'nibabel': ('https://nipy.org/nibabel/', None),
+ 'nilearn': ('http://nilearn.github.io/stable/', None),
+ 'nipype': ('https://nipype.readthedocs.io/en/latest/', None),
}
-suppress_warnings = ["image.nonlocal_uri"]
+suppress_warnings = ['image.nonlocal_uri']
# -----------------------------------------------------------------------------
# sphinxcontrib-bibtex
# -----------------------------------------------------------------------------
-bibtex_bibfiles = ["../qsiprep/data/boilerplate.bib"]
-bibtex_style = "unsrt"
-bibtex_reference_style = "author_year"
-bibtex_footbibliography_header = ""
+bibtex_bibfiles = ['../qsiprep/data/boilerplate.bib']
+bibtex_style = 'unsrt'
+bibtex_reference_style = 'author_year'
+bibtex_footbibliography_header = ''
def setup(app):
"""Add extra formatting files."""
- app.add_css_file("theme_overrides.css")
+ app.add_css_file('theme_overrides.css')
# We need this for the boilerplate script
- app.add_js_file("https://cdn.rawgit.com/chrisfilo/zenodo.js/v0.1/zenodo.js")
+ app.add_js_file('https://cdn.rawgit.com/chrisfilo/zenodo.js/v0.1/zenodo.js')
diff --git a/pyproject.toml b/pyproject.toml
index 37d55c80..25c00e7c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -156,7 +156,17 @@ ignore = [
"S311", # We are not using random for cryptographic purposes
"ISC001",
"S603",
- "S605",
+ "S605", # TODO: Fix these
+ "DTZ005", # TODO: Fix these
+ "B904", # TODO: Fix these
+ "A001", # TODO: Fix these
+ "B006", # TODO: Fix these
+ "S607", # TODO: Fix these
+ "S108", # TODO: Fix these
+ "S602", # TODO: Fix these
+ "E402", # TODO: Fix these
+ "UP028", # TODO: Fix these
+ "BLE001", # TODO: Fix these
]
[tool.ruff.lint.flake8-quotes]
diff --git a/qsiprep/interfaces/epi_fmap.py b/qsiprep/interfaces/epi_fmap.py
index 8ea6efb7..3beea7ea 100644
--- a/qsiprep/interfaces/epi_fmap.py
+++ b/qsiprep/interfaces/epi_fmap.py
@@ -123,8 +123,8 @@ def load_epi_dwi_fieldmaps(fmap_list, b0_threshold):
_b0_indices = np.flatnonzero(bvals < b0_threshold) + starting_index
else:
raise Exception(
- 'Secret fieldmap file %s mismatches its image file %s'
- % (potential_bval_file, fmap_file)
+ f'Secret fieldmap file {potential_bval_file} mismatches its image file '
+ f'{fmap_file}'
)
else:
_b0_indices = np.arange(num_images) + starting_index
diff --git a/qsiprep/interfaces/images.py b/qsiprep/interfaces/images.py
index cc11aca6..16d408a8 100644
--- a/qsiprep/interfaces/images.py
+++ b/qsiprep/interfaces/images.py
@@ -221,7 +221,7 @@ def _run_interface(self, runtime):
if filedata.ndim == 5:
sqdata = np.squeeze(filedata)
if sqdata.ndim == 5:
- raise RuntimeError('Input image (%s) is 5D' % in_files[0])
+ raise RuntimeError(f'Input image ({in_files[0]}) is 5D')
else:
in_files = [
fname_presuffix(in_files[0], suffix='_squeezed', newpath=runtime.cwd)
@@ -628,10 +628,9 @@ def _run_interface(self, runtime):
Analyses of this dataset MAY BE INVALID.
"""
- snippet = '%s
\n%s:\n\t %s\n' % (
- warning_txt,
- self.inputs.in_file,
- description,
+ snippet = (
+ f'{warning_txt}
\n{self.inputs.in_file}:\n\t '
+ f'{description}\n'
)
# Store new file and report
img.to_filename(out_fname)
diff --git a/qsiprep/interfaces/itk.py b/qsiprep/interfaces/itk.py
index 80748824..63e00569 100644
--- a/qsiprep/interfaces/itk.py
+++ b/qsiprep/interfaces/itk.py
@@ -231,8 +231,8 @@ def disassemble_transform(transform_file, cwd):
def compose_affines(reference_image, affine_list, output_file):
"""Use antsApplyTransforms to get a single affine from multiple affines."""
- cmd = 'antsApplyTransforms -d 3 -r %s -o Linear[%s, 1] ' % (reference_image, output_file)
- cmd += ' '.join(['--transform %s' % trf for trf in affine_list])
+ cmd = f'antsApplyTransforms -d 3 -r {reference_image} -o Linear[{output_file}, 1] '
+ cmd += ' '.join([f'--transform {trf}' for trf in affine_list])
os.system(cmd)
assert os.path.exists(output_file)
return output_file
diff --git a/qsiprep/interfaces/tortoise.py b/qsiprep/interfaces/tortoise.py
index c13ef1dc..bc512e00 100644
--- a/qsiprep/interfaces/tortoise.py
+++ b/qsiprep/interfaces/tortoise.py
@@ -116,7 +116,7 @@ def _run_interface(self, runtime):
# Write the metadata
up_json = op.join(runtime.cwd, 'blip_up.json')
with open(up_json, 'w') as up_jsonf:
- up_jsonf.write('{"PhaseEncodingDirection": "%s"}\n' % self.inputs.dwi_series_pedir)
+ up_jsonf.write(f'{{"PhaseEncodingDirection": "{self.inputs.dwi_series_pedir}"}}\n')
self._results['blip_up_json'] = up_json
# Coerce the bvals and bvecs into lists of files
diff --git a/qsiprep/utils/shm.py b/qsiprep/utils/shm.py
index e42fe92e..42a1ecd0 100644
--- a/qsiprep/utils/shm.py
+++ b/qsiprep/utils/shm.py
@@ -902,7 +902,7 @@ def calculate_max_order(n_coeffs):
# Otherwise, the input didn't make sense:
raise ValueError(
'The input to ``calculate_max_order`` was ',
- '%s, but that is not a valid number' % n_coeffs,
+ f'{n_coeffs}, but that is not a valid number',
'of coefficients for a spherical harmonics ',
'basis set.',
)