Skip to content

Commit

Permalink
Run ruff and ignore lingering issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Nov 21, 2024
1 parent b6f2955 commit 07563ed
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 89 deletions.
152 changes: 75 additions & 77 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# QSIPrep documentation build configuration file, created by
# sphinx-quickstart on Mon May 9 09:04:25 2016.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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.
Expand All @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ---------------------------------------------

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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',
),
]

Expand All @@ -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')
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions qsiprep/interfaces/epi_fmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions qsiprep/interfaces/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -628,10 +628,9 @@ def _run_interface(self, runtime):
Analyses of this dataset MAY BE INVALID.
</p>
"""
snippet = '<h3 class="elem-title">%s</h3>\n%s:\n\t %s\n' % (
warning_txt,
self.inputs.in_file,
description,
snippet = (
f'<h3 class="elem-title">{warning_txt}</h3>\n{self.inputs.in_file}:\n\t '
f'{description}\n'
)
# Store new file and report
img.to_filename(out_fname)
Expand Down
4 changes: 2 additions & 2 deletions qsiprep/interfaces/itk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qsiprep/interfaces/tortoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qsiprep/utils/shm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
)
Expand Down

0 comments on commit 07563ed

Please sign in to comment.