Skip to content

Conversation

@arokem
Copy link
Member

@arokem arokem commented Sep 19, 2025

No description provided.

Copilot AI review requested due to automatic review settings September 19, 2025 21:42
Copy link
Contributor

Copilot AI left a 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.

@arokem
Copy link
Member Author

arokem commented Sep 19, 2025

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.

@36000
Copy link
Collaborator

36000 commented Sep 19, 2025

LGTM

@arokem
Copy link
Member Author

arokem commented Sep 19, 2025

This should follow merge of #103, so we don't end up in a sticky situation.

arokem and others added 2 commits December 19, 2025 11:05
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@arokem
Copy link
Member Author

arokem commented Dec 19, 2025

This PR now implements a range of changes that are the result of running uv run ruff check --fix. I think that most of these changes are in reordering the imports in many different files to comply with ruff rules, but there are potentially many other changes lurking, so a close look even after we let copilot review this again, would be great.

Copy link
Contributor

Copilot AI left a 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.

Comment on lines 1 to 31
# -*- 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
Copy link

Copilot AI Dec 19, 2025

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.

Copilot uses AI. Check for mistakes.

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
Copy link

Copilot AI Dec 19, 2025

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.

Suggested change
rev: v0.4.3
rev: v0.7.2

Copilot uses AI. Check for mistakes.
check_sls_with_inclusion,
check_sl_with_exclusion)

import AFQ.recognition.roi as abr
Copy link

Copilot AI Dec 19, 2025

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'.

Copilot uses AI. Check for mistakes.
arokem and others added 17 commits December 19, 2025 11:16
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>
Copy link
Contributor

Copilot AI left a 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

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
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
PVE data with CSF, GM, and WM segmentations.
"""
synthseg_labels = {
synthseg_labels = { # noqa: F841
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
# 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)
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
# 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)
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
as_percentage=False,
combine="and",
):
CombineImageMixin.__init__(self, combine)
Copy link

Copilot AI Dec 20, 2025

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.

Suggested change
CombineImageMixin.__init__(self, combine)

Copilot uses AI. Check for mistakes.
if logger is not None:
logger.info("Generating default configuration file.")
toml_file = open(toml_file, 'w')
toml_file = open(toml_file, "w")
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
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")
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
json_file.close()

json_file = open(json_file_their_trk, 'w')
json_file = open(json_file_their_trk, "w")
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
# there.
CP = configparser.ConfigParser()
CP.read_file(open(op.join(op.expanduser('~'), '.aws', 'credentials')))
CP.read_file(open(op.join(op.expanduser("~"), ".aws", "credentials")))
Copy link

Copilot AI Dec 20, 2025

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.

Copilot uses AI. Check for mistakes.
@arokem
Copy link
Member Author

arokem commented Dec 21, 2025

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.

@arokem
Copy link
Member Author

arokem commented Dec 21, 2025

Close in favor of #134

@arokem arokem closed this Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants