-
Notifications
You must be signed in to change notification settings - Fork 9
[MAINT] Use ruff for linting #113
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces ruff as the primary linting tool for the project, replacing the previous linting setup. The changes modernize the development workflow by configuring ruff for both linting and formatting, along with pre-commit hooks for automated code quality checks.
- Configures ruff linting rules and target Python version in pyproject.toml
- Sets up pre-commit hooks for ruff linting/formatting and codespell checking
- Updates build system requirements to use more recent setuptools versions
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyproject.toml | Adds ruff configuration with linting rules and updates build system requirements |
| .pre-commit-config.yaml | Introduces pre-commit hooks for ruff and codespell |
| .codespellrc | Configures codespell to skip setup.cfg file |
| setup.cfg | Adds setuptools version requirement |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
I am hoping that this will be part of an overhaul/modernization of our installation machinery so that we can finally get rid of the setup.py file. |
|
LGTM |
|
This should follow merge of #103, so we don't end up in a sticky situation. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
This PR now implements a range of changes that are the result of running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 106 out of 107 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # -*- coding: utf-8 -*-# -*- coding: utf-8 -*- | ||
| import warnings | ||
| import tempfile | ||
| import warnings | ||
|
|
||
| import AFQ.api.bundle_dict as abd | ||
| from AFQ.definitions.mapping import SynMap | ||
| from AFQ.definitions.utils import Definition | ||
| import AFQ.api.bundle_dict as abd | ||
|
|
||
| warnings.simplefilter(action='ignore', category=FutureWarning) # noqa | ||
|
|
||
| import glob | ||
| import json | ||
| import logging | ||
| from AFQ.api.participant import ParticipantAFQ | ||
| from AFQ.api.utils import ( | ||
| check_attribute, AFQclass_doc, | ||
| export_all_helper, valid_exports_string) | ||
| import AFQ.utils.streamlines as aus | ||
| from AFQ.viz.utils import get_eye | ||
| from AFQ.data.utils import aws_import_msg_error | ||
| from AFQ.definitions.utils import find_file | ||
|
|
||
| from dipy.utils.parallel import paramap | ||
| from dipy.io.stateful_tractogram import StatefulTractogram, Space | ||
| import dipy.tracking.streamlinespeed as dps | ||
| import dipy.tracking.streamline as dts | ||
| from dipy.io.streamline import save_tractogram | ||
|
|
||
| from AFQ.version import version as pyafq_version | ||
| from AFQ.viz.utils import trim | ||
| import pandas as pd | ||
| import pydra | ||
| import numpy as np | ||
| import os | ||
| import os.path as op | ||
| from tqdm import tqdm | ||
| import json | ||
| from time import time | ||
|
|
||
| import dipy.tracking.streamline as dts | ||
| import dipy.tracking.streamlinespeed as dps | ||
| import nibabel as nib | ||
| import numpy as np | ||
| import pandas as pd | ||
| import pydra | ||
| from bids.layout import BIDSLayout, BIDSLayoutIndexer | ||
| from dipy.io.stateful_tractogram import Space, StatefulTractogram | ||
| from dipy.io.streamline import save_tractogram | ||
| from dipy.utils.parallel import paramap | ||
| from PIL import Image | ||
| import glob | ||
| from tqdm import tqdm | ||
|
|
||
| import AFQ.utils.streamlines as aus |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import order is incorrect. Local imports from AFQ modules (lines 5-7) appear before the warnings.simplefilter call, which itself appears before other stdlib imports (lines 11-16). All stdlib imports should be grouped together at the top, followed by third-party imports, and then local imports. The warnings.simplefilter configuration should come after all imports.
.pre-commit-config.yaml
Outdated
|
|
||
| repos: | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: v0.4.3 |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ruff version in the pre-commit config (v0.4.3) is from April 2024 and is outdated. Since the knowledge cutoff is January 2025, consider updating to a more recent version of ruff-pre-commit to benefit from bug fixes and improvements.
| rev: v0.4.3 | |
| rev: v0.7.2 |
| check_sls_with_inclusion, | ||
| check_sl_with_exclusion) | ||
|
|
||
| import AFQ.recognition.roi as abr |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module 'AFQ.recognition.roi' is imported with both 'import' and 'import from'.
We are currently getting a few of these: ``` ../../../opt/hostedtoolcache/Python/3.11.14/x64/lib/python3.11/site-packages/AFQ/tests/test_api.py:235 /opt/hostedtoolcache/Python/3.11.14/x64/lib/python3.11/site-packages/AFQ/tests/test_api.py:235: PytestUnknownMarkWarning: Unknown pytest.mark.nightly_custom - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html @pytest.mark.nightly_custom ```
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 107 out of 108 changed files in this pull request and generated 9 comments.
Comments suppressed due to low confidence (1)
AFQ/definitions/image.py:679
- This class does not call ScalarImage.init during initialization. (ThresholdedScalarImage.init may be missing a call to a base class init)
class ThresholdedScalarImage(ThresholdMixin, ScalarImage):
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # set logging level to your choice | ||
| logging.basicConfig(level=logging.INFO) | ||
| log = logging.getLogger(__name__) | ||
| log = logging.getLogger(__name__) # noqa F841 |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable log is not used.
| PVE data with CSF, GM, and WM segmentations. | ||
| """ | ||
| synthseg_labels = { | ||
| synthseg_labels = { # noqa: F841 |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable synthseg_labels is not used.
| # second gives the layout of the figure (eg. 3 rows 4 columns) and finally is | ||
| # the view. | ||
|
|
||
| montage = my_afq.group_montage("L_SLF1", (3, 4), "Sagittal", "left", slice_pos=0.5) |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to 'montage' is unnecessary as it is redefined before this value is used.
| # the view. | ||
|
|
||
| montage = my_afq.group_montage("L_SLF1", (3, 4), "Sagittal", "left", slice_pos=0.5) | ||
| montage = my_afq.group_montage("L_SLF2", (3, 4), "Sagittal", "left", slice_pos=0.5) |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to 'montage' is unnecessary as it is redefined before this value is used.
| as_percentage=False, | ||
| combine="and", | ||
| ): | ||
| CombineImageMixin.__init__(self, combine) |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This initialization method calls CombineImageMixin.init multiple times, via this call and this call, resolving to CombineImageMixin.init and ThresholdMixin.init respectively.
| CombineImageMixin.__init__(self, combine) |
| if logger is not None: | ||
| logger.info("Generating default configuration file.") | ||
| toml_file = open(toml_file, 'w') | ||
| toml_file = open(toml_file, "w") |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File may not be closed if this operation raises an exception.
| arg_dict = func_dict_to_arg_dict(func_dict, logger=logger) | ||
|
|
||
| json_file = open(json_file_our_trk, 'w') | ||
| json_file = open(json_file_our_trk, "w") |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File may not be closed if this operation raises an exception.
File may not be closed if this operation raises an exception.
File may not be closed if this operation raises an exception.
| json_file.close() | ||
|
|
||
| json_file = open(json_file_their_trk, 'w') | ||
| json_file = open(json_file_their_trk, "w") |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File may not be closed if this operation raises an exception.
File may not be closed if this operation raises an exception.
File may not be closed if this operation raises an exception.
| # there. | ||
| CP = configparser.ConfigParser() | ||
| CP.read_file(open(op.join(op.expanduser('~'), '.aws', 'credentials'))) | ||
| CP.read_file(open(op.join(op.expanduser("~"), ".aws", "credentials"))) |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File is opened but is not closed.
|
I think that maybe I will redo this one, but ignore this rule: https://docs.astral.sh/ruff/rules/unnecessary-collection-call/, because it's really not a performance hit in the overall scheme of things and introduced a lot of changes all over the place that we might not really need. |
|
Close in favor of #134 |
No description provided.