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: Enforce ruff rules #3690

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Oct 7, 2024

Summary

Disable some rules and postpone fixes.

Requires #3689.

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 34.78261% with 150 lines in your changes missing coverage. Please review.

Project coverage is 70.86%. Comparing base (fffc1c2) to head (2fff982).

Files with missing lines Patch % Lines
nipype/interfaces/spm/preprocess.py 6.25% 15 Missing ⚠️
nipype/interfaces/fsl/model.py 21.42% 11 Missing ⚠️
nipype/interfaces/cmtk/nx.py 0.00% 10 Missing ⚠️
nipype/interfaces/cmtk/convert.py 0.00% 8 Missing ⚠️
nipype/interfaces/fsl/preprocess.py 0.00% 8 Missing ⚠️
nipype/interfaces/fsl/utils.py 0.00% 8 Missing ⚠️
nipype/interfaces/io.py 11.11% 8 Missing ⚠️
nipype/algorithms/modelgen.py 40.00% 5 Missing and 1 partial ⚠️
nipype/interfaces/ants/registration.py 44.44% 5 Missing ⚠️
...ype/interfaces/freesurfer/tests/test_preprocess.py 0.00% 5 Missing ⚠️
... and 34 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3690      +/-   ##
==========================================
+ Coverage   70.84%   70.86%   +0.01%     
==========================================
  Files        1277     1277              
  Lines       59118    59106      -12     
  Branches     9803     8586    -1217     
==========================================
+ Hits        41884    41885       +1     
- Misses      16067    16076       +9     
+ Partials     1167     1145      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 comments, to avoid collapsing.

nipype/algorithms/modelgen.py Outdated Show resolved Hide resolved
nipype/algorithms/modelgen.py Outdated Show resolved Hide resolved
nipype/algorithms/modelgen.py Outdated Show resolved Hide resolved
self.inputs.regularization_gradient_field_sigma,
self.inputs.regularization_deformation_field_sigma,
)
return f"--regularization {self.inputs.regularization}[{self.inputs.regularization_gradient_field_sigma},{self.inputs.regularization_deformation_field_sigma}]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't strike me as more readable. Could do something like:

Suggested change
return f"--regularization {self.inputs.regularization}[{self.inputs.regularization_gradient_field_sigma},{self.inputs.regularization_deformation_field_sigma}]"
gfsigma = self.inputs.regularization_gradient_field_sigma
dfsigma = self.inputs.regularization_deformation_field_sigma
return f"--regularization {self.inputs.regularization}[{gfsigma},{dfsigma}]"

Alternately, we could use format strings sensibly using input_spec fields and then trait_get() to populate them:

Suggested change
return f"--regularization {self.inputs.regularization}[{self.inputs.regularization_gradient_field_sigma},{self.inputs.regularization_deformation_field_sigma}]"
fmt = "--regularization {regularization}[{regularization_gradient_field_sigma},{regularization_deformation_field_sigma}]"
return fmt.format(**self.inputs.trait_get())

I would do this throughout. I don't think f-strings are improving things here, even if they might be very slightly more efficient.

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'm not very happy with these changes either. I can't decide whether I should disable UP0032 altogether and discard these changes, or apply the changes that make sense and silence the rest with noqa. What would you do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do a per-file ignore, if it's only a couple files that get really ugly. Then we can revisit them separately or never. % and str.format aren't going away, so there's no time bomb if we end up just saying "ANTs is too special for UP032".

If it's broad, we could set the ignore to everything in "nipype/interfaces".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@effigies I still need to review all the UP032 changes and undo bad fixes.

nipype/interfaces/cmtk/nx.py Outdated Show resolved Hide resolved
nipype/interfaces/freesurfer/utils.py Outdated Show resolved Hide resolved
nipype/interfaces/freesurfer/utils.py Outdated Show resolved Hide resolved
nipype/interfaces/fsl/model.py Outdated Show resolved Hide resolved
nipype/interfaces/fsl/model.py Outdated Show resolved Hide resolved
nipype/interfaces/fsl/preprocess.py Outdated Show resolved Hide resolved
@effigies
Copy link
Member

effigies commented Oct 7, 2024

Just realized this is still in draft. Will hold off on further review for now.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestions.

nipype/algorithms/modelgen.py Outdated Show resolved Hide resolved
nipype/algorithms/modelgen.py Outdated Show resolved Hide resolved
nipype/interfaces/fsl/preprocess.py Outdated Show resolved Hide resolved
nipype/interfaces/spm/preprocess.py Outdated Show resolved Hide resolved
nipype/interfaces/spm/preprocess.py Outdated Show resolved Hide resolved
DimitriPapadopoulos and others added 13 commits October 9, 2024 20:58
B007 Loop control variable not used within loop body

Co-authored-by: Chris Markiewicz <[email protected]>
B015 Pointless comparison at end of function scope.
     Did you mean to return the expression result?
B018 Found useless expression. Either assign it to a variable or remove it.
E741 Ambiguous variable name
FURB154 Use of repeated consecutive `global`
PLE0101 Explicit return in `__init__`
PLE1205 Too many arguments for `logging` format string
PT006 Wrong type passed to first argument of `@pytest.mark.parametrize`; expected `tuple`
PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
PT014 Duplicate of test case in `@pytest_mark.parametrize`
Q000 Single quotes found but double quotes preferred
Q003 Change outer quotes to avoid escaping inner quotes
RUF100 Unused blanket `noqa` directive
DimitriPapadopoulos and others added 3 commits October 9, 2024 20:59
UP008 Use `super()` instead of `super(__class__, self)`
UP032 Use f-string instead of `format` call

Co-authored-by: Chris Markiewicz <[email protected]>
Disable some rules and postpone fixes.
effigies
effigies previously approved these changes Oct 9, 2024
@effigies effigies dismissed their stale review October 9, 2024 19:11

Pending review of UP032 changes

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