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 24 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 36.48069% with 148 lines in your changes missing coverage. Please review.

Project coverage is 73.14%. Comparing base (3cbebe3) to head (8f84741).

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/utils/filemanip.py 12.50% 7 Missing ⚠️
nipype/algorithms/modelgen.py 50.00% 5 Missing ⚠️
...ype/interfaces/freesurfer/tests/test_preprocess.py 0.00% 5 Missing ⚠️
... and 32 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3690      +/-   ##
==========================================
+ Coverage   73.13%   73.14%   +0.01%     
==========================================
  Files        1278     1278              
  Lines       59356    59345      -11     
==========================================
- Hits        43411    43410       -1     
+ Misses      15945    15935      -10     

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


🚨 Try these New Features:

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

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
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.
B010 Do not call `setattr` with a constant attribute value.
     It is not any safer than normal property access.
F522 `.format` call has unused named argument
F821 Undefined name
RUF100 Unused blanket `noqa` directive
RUF100 Unused `noqa` directive
UP015 Unnecessary open mode parameters
UP025 Remove unicode literals from strings
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