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

STY: Adopt ruff #20

Merged
merged 9 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
exclude: ".*/data/.*"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 23.1.0
- id: trailing-whitespace
exclude: '.*\.svg'
- id: end-of-file-fixer
exclude: '.*\.svg'
- 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.4.3
hooks:
- id: black
files: ^src/fmripost_aroma/
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
files: ^src/fmripost_aroma/
- id: ruff
args: [ --fix ]
- id: ruff-format
- id: ruff
args: [ --select, ISC001, --fix ]
120 changes: 60 additions & 60 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,89 +21,89 @@
# 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("../wrapper"))
sys.path.append(os.path.abspath('sphinxext'))
sys.path.insert(0, os.path.abspath('../wrapper'))

from github_link import make_linkcode_resolve # noqa: E402

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = "1.5.3"
needs_sphinx = '1.5.3'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.mathjax",
"sphinx.ext.linkcode",
"sphinx.ext.napoleon",
"sphinxarg.ext", # argparse extension
"nipype.sphinxext.plot_workflow",
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.linkcode',
'sphinx.ext.napoleon',
'sphinxarg.ext', # argparse extension
'nipype.sphinxext.plot_workflow',
]

# Mock modules in autodoc:
autodoc_mock_imports = [
"numpy",
"nitime",
"matplotlib",
'numpy',
'nitime',
'matplotlib',
]

if pver.parse(sphinxversion) >= pver.parse("1.7.0"):
if pver.parse(sphinxversion) >= pver.parse('1.7.0'):
autodoc_mock_imports += [
"pandas",
"nilearn",
"seaborn",
'pandas',
'nilearn',
'seaborn',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
templates_path = ['_templates']

# Accept custom section names to be parsed for numpy-style docstrings
# of parameters.
# Requires pinning sphinxcontrib-napoleon to a specific commit while
# https://github.com/sphinx-contrib/napoleon/pull/10 is merged.
napoleon_use_param = False
napoleon_custom_sections = [
("Inputs", "Parameters"),
("Outputs", "Parameters"),
('Inputs', 'Parameters'),
('Outputs', 'Parameters'),
]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
# source_suffix = [".rst", ".md"]
source_suffix = ".rst"
source_suffix = '.rst'

# 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 = "fMRIPost-AROMA"
author = "The fMRIPost-AROMA developers"
copyright = f"2016-, {author}"
project = 'fMRIPost-AROMA'
author = 'The fMRIPost-AROMA developers'
copyright = f'2016-, {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
# built documents.
#
# The short X.Y version.
version = "version"
version = 'version'
# The full version, including alpha/beta/rc tags.
release = "version"
release = 'version'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# 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 @@ -114,7 +114,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 @@ -132,7 +132,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
pygments_style = 'sphinx'

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -148,7 +148,7 @@

# 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 @@ -177,7 +177,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 @@ -242,7 +242,7 @@
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = "fmripost_aroma_doc"
htmlhelp_basename = 'fmripost_aroma_doc'

# -- Options for LaTeX output ---------------------------------------------

Expand All @@ -261,7 +261,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "fmripost_aroma.tex", "fMRIPost-AROMA Documentation", author, "manual"),
(master_doc, 'fmripost_aroma.tex', 'fMRIPost-AROMA Documentation', author, 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -289,7 +289,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "fmripost-aroma", "fMRIPost-AROMA Documentation", [author], 1)]
man_pages = [(master_doc, 'fmripost-aroma', 'fMRIPost-AROMA Documentation', [author], 1)]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -303,12 +303,12 @@
texinfo_documents = [
(
master_doc,
"fMRIPost-AROMA",
"fMRIPost-AROMA Documentation",
'fMRIPost-AROMA',
'fMRIPost-AROMA Documentation',
author,
"fMRIPost-AROMA",
"One line description of project.",
"Miscellaneous",
'fMRIPost-AROMA',
'One line description of project.',
'Miscellaneous',
),
]

Expand All @@ -326,31 +326,31 @@

# The following is used by sphinx.ext.linkcode to provide links to github
linkcode_resolve = make_linkcode_resolve(
"fmripost_aroma",
"https://github.com/nipreps/fMRIPost-AROMA/blob/{revision}/{package}/{path}#L{lineno}",
'fmripost_aroma',
'https://github.com/nipreps/fMRIPost-AROMA/blob/{revision}/{package}/{path}#L{lineno}',
)

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"bids": ("https://bids-standard.github.io/pybids/", None),
"nibabel": ("https://nipy.org/nibabel/", None),
"nipype": ("https://nipype.readthedocs.io/en/latest/", None),
"niworkflows": ("https://www.nipreps.org/niworkflows/", None),
"fmriprep": ("https://fmriprep.org/en/stable/", None),
"sdcflows": ("https://www.nipreps.org/sdcflows/", None),
"smriprep": ("https://www.nipreps.org/smriprep/", None),
"templateflow": ("https://www.templateflow.org/python-client", None),
"tedana": ("https://tedana.readthedocs.io/en/latest/", None),
'python': ('https://docs.python.org/3/', None),
'numpy': ('https://numpy.org/doc/stable/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/', None),
'matplotlib': ('https://matplotlib.org/stable/', None),
'bids': ('https://bids-standard.github.io/pybids/', None),
'nibabel': ('https://nipy.org/nibabel/', None),
'nipype': ('https://nipype.readthedocs.io/en/latest/', None),
'niworkflows': ('https://www.nipreps.org/niworkflows/', None),
'fmriprep': ('https://fmriprep.org/en/stable/', None),
'sdcflows': ('https://www.nipreps.org/sdcflows/', None),
'smriprep': ('https://www.nipreps.org/smriprep/', None),
'templateflow': ('https://www.templateflow.org/python-client', None),
'tedana': ('https://tedana.readthedocs.io/en/latest/', None),
}

suppress_warnings = ["image.nonlocal_uri"]
suppress_warnings = ['image.nonlocal_uri']


def setup(app):
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')
18 changes: 9 additions & 9 deletions docs/sphinxext/github_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
from functools import partial
from operator import attrgetter

REVISION_CMD = "git rev-parse --short HEAD"
REVISION_CMD = 'git rev-parse --short HEAD'


def _get_git_revision():
try:
revision = subprocess.check_output(REVISION_CMD.split()).strip()
except (subprocess.CalledProcessError, OSError):
print("Failed to execute git to get revision")
print('Failed to execute git to get revision')
return None
return revision.decode("utf-8")
return revision.decode('utf-8')


def _linkcode_resolve(domain, info, package, url_fmt, revision):
Expand All @@ -39,14 +39,14 @@ def _linkcode_resolve(domain, info, package, url_fmt, revision):

if revision is None:
return
if domain not in ("py", "pyx"):
if domain not in ('py', 'pyx'):
return
if not info.get("module") or not info.get("fullname"):
if not info.get('module') or not info.get('fullname'):
return

class_name = info["fullname"].split(".")[0]
module = __import__(info["module"], fromlist=[class_name])
obj = attrgetter(info["fullname"])(module)
class_name = info['fullname'].split('.')[0]
module = __import__(info['module'], fromlist=[class_name])
obj = attrgetter(info['fullname'])(module)

# Unwrap the object to get the correct source
# file in case that is wrapped by a decorator
Expand All @@ -68,7 +68,7 @@ def _linkcode_resolve(domain, info, package, url_fmt, revision):
try:
lineno = inspect.getsourcelines(obj)[1]
except Exception:
lineno = ""
lineno = ''
return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)


Expand Down
49 changes: 44 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,51 @@ exclude_lines = [
"if TYPE_CHECKING:",
]

# Disable black
[tool.black]
line-length = 99
target-version = ['py39']

[tool.isort]
profile = 'black'
exclude = ".*"

[tool.ruff]
line-length = 99

[tool.ruff.lint]
extend-select = [
"F",
"E",
"W",
"I",
"UP",
"YTT",
"S",
"BLE",
"B",
"A",
# "CPY",
"C4",
"DTZ",
"T10",
# "EM",
"EXE",
"FA",
"ISC",
"ICN",
"PT",
"Q",
]
ignore = [
"S311", # We are not using random for cryptographic purposes
"ISC001",
"S603",
]

[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"]
"docs/sphinxext/github_link.py" = ["BLE001"]

[tool.ruff.format]
quote-style = "single"
Loading
Loading