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

Lint codebase with additional style restrictions #970

Merged
merged 37 commits into from
Oct 27, 2023

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Aug 12, 2023

Closes None. I'll probably tackle the style issues the new extensions catch after a few of the other PRs have been merged.

Changes proposed in this pull request:

  • Add more flake8 extensions.
    • flake8-absolute-import: Enforces absolute imports.
    • flake8-docstrings: Enforces numpydoc-style docstrings.
    • flake8-unused-arguments: Checks for unused arguments in classes and functions.
    • flake8-use-fstring: Checks that we use modern f-strings over .format() and %.
    • pep8-naming: Enforces PEP8-compliant variables, classes, and functions.

@tsalo tsalo added testing issues related to improving testing in the project refactoring issues proposing/requesting changes to the code which do not impact behavior labels Aug 12, 2023
@eurunuela
Copy link
Collaborator

Hey @tsalo, do you know if there's a way in flake8 to set the number of summary lines to 2?

With the pre-commit I added to this PR, we could get rid of most docstring issues related to summary lines and trailing periods.

If it isn't possible, I would ignore the D205 1 blank line required between summary line and description error.

@handwerkerd
Copy link
Member

If I understand correctly, flake8 vs rust should not change how the code is currently being linted. If we can get this working, I'd recommend merging and then consider rust. I really want this merged because it's going to affect everything else I'm working on and the sooner I can deal with the changes this creates, the better.

I don't think the speed boost matters to us so I'm not going to advocate for a change to rust, but I'm not opposed.

@handwerkerd
Copy link
Member

I also took a look at this since all the tests have now passed. I tried to make html for the docs and I'm seeing a bunch of problems.

/Users/handwerkerd/code/meica/tedana/tedana/decomposition/pca.py:docstring of tedana.decomposition.pca.tedpca:39: WARNING: Block quote ends without a blank line; unexpected unindent.
/Users/handwerkerd/code/meica/tedana/tedana/decomposition/pca.py:docstring of tedana.decomposition.pca.tedpca:41: WARNING: Block quote ends without a blank line; unexpected unindent.

In the same file, the following is now causing a LaTeX rendering failure

            .. math::
                {\\kappa}_c = \\frac{\\sum_{v}^V {\\zeta}_{c,v}^p * \
                      F_{c,v,R_2^*}}{\\sum {\\zeta}_{c,v}^p}

                {\\rho}_c = \\frac{\\sum_{v}^V {\\zeta}_{c,v}^p * \
                      F_{c,v,S_0}}{\\sum {\\zeta}_{c,v}^p}

@eurunuela
Copy link
Collaborator

That's odd... those lines have not been edited in 4 years...

I will have a look and see if I can fix it.

@eurunuela
Copy link
Collaborator

I have just fixed the issue with LaTeX.

7907c39 prepended an r to the docstring, which made the LaTeX fail because it contained double slashes. Apparently, either you use double slashes (e.g., \\lambda), or you use a single slash and prepend the r to the docstring.

@eurunuela
Copy link
Collaborator

eurunuela commented Oct 23, 2023

Okay, I see now why the r was added. It was one of the new flake8 requirements.

I have opted for using a single slash with the r.

Edit: I think we can merge this if you're happy with the changes @handwerkerd. I assume @tsalo is also happy with the changes?

@handwerkerd
Copy link
Member

Found another place with double slashes that need to be changed to single. I'm looking through the rest of this now.

https://github.com/tsalo/tedana/blob/e194bacc1c449790b19f432d56ac237abeb16b45/tedana/combine.py#L139-L141

@eurunuela
Copy link
Collaborator

Found another place with double slashes that need to be changed to single. I'm looking through the rest of this now.

https://github.com/tsalo/tedana/blob/e194bacc1c449790b19f432d56ac237abeb16b45/tedana/combine.py#L139-L141

Good catch! I must've missed it earlier. I think that should be all of them.

Copy link
Member

@handwerkerd handwerkerd left a comment

Choose a reason for hiding this comment

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

I've scanned all the changes and skimmed the docs to see if there were any unintended changes. I found a few minor things.

The one non-trivial thing, which I've commented in a few places is that we used a lot of capitalized acronyms in variable names T2 S0 and SSE. I'd like to keep these capitalized, but I assume the specification requires variables to use lowercase letters. If this is a headache to change back or others have a strong opinion on why they should all be lowercase (i.e. no accidental case differences in variable names) I'm fine keeping all lowercase.

tedana/decomposition/_utils.py Outdated Show resolved Hide resolved
@@ -53,41 +50,30 @@ def low_mem_pca(data):
def tedpca(
data_cat,
data_oc,
combmode,
Copy link
Member

Choose a reason for hiding this comment

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

Interesting that combmode and t2sG are no longer used. They were only useful for the kundu options and my best guess is that they stopped being used here when metrics.collect.generate_metrics was added. The one work is that those are doe within generate_metrics, but the option for combmode can no longer be externally set. I don't think this a problem or needs correction, but figured I'd highlight in case others see an issue.

tedana/metrics/collect.py Show resolved Hide resolved
tedana/metrics/dependence.py Show resolved Hide resolved
tedana/reporting/static_figures.py Outdated Show resolved Hide resolved
tedana/selection/selection_nodes.py Show resolved Hide resolved
tedana/tests/test_metrics.py Show resolved Hide resolved
@handwerkerd
Copy link
Member

I think the plan was to merge this without it being counted in the tallies of lines-of-code changed. Is that properly set up?

@handwerkerd
Copy link
Member

FWIW, this is really close to merging. I made a few minor suggestions, but I hope they don't hold up the merge. I'd love to be able to update a few of the other PRs with this one before working on them more.

@eurunuela
Copy link
Collaborator

I don't know how we can keep the capitalized acronyms and still use the pep8-naming convention... @tsalo do you know if there is a way?

In any case, while I understand why we would want to keep them capitalized, it doesn't really bother me that they get changed to lowercase.

@tsalo
Copy link
Member Author

tsalo commented Oct 27, 2023

I don't know how we can keep the capitalized acronyms and still use the pep8-naming convention... @tsalo do you know if there is a way?

Not that I know of. Per PEP8, uppercase characters are limited to classes, rather than functions or variables (except constants). That said, I don't think we consistently refer to acronyms in uppercase throughout the package (e.g., t2s is lowercase in many cases), so I don't think it's an issue to make them lowercase. If there are cases where the lowercase version is less clear (e.g., f_t2), I think we can improve the variable names (e.g., fstat_t2).

handwerkerd
handwerkerd previously approved these changes Oct 27, 2023
Co-authored-by: Dan Handwerker <7406227+handwerkerd@users.noreply.github.com>
@eurunuela
Copy link
Collaborator

Since this is a PR that I believe you need merged @handwerkerd, shall we open an issue to rename the variables that are now lowercase? Or would you rather take care of that in this PR?

@handwerkerd
Copy link
Member

Just keep the variables lowercase. I made a suggestion, but I'm fine keeping them as is in this PR.

@eurunuela
Copy link
Collaborator

eurunuela commented Oct 27, 2023

Just keep the variables lowercase. I made a suggestion, but I'm fine keeping them as is in this PR.

I believe I already added your suggestion if you're referring to 964b0f6.

Edit: if that's the case, feel free to merge.

@tsalo tsalo merged commit b139386 into ME-ICA:main Oct 27, 2023
14 checks passed
@tsalo tsalo deleted the lint-aggressively branch October 27, 2023 17:49
@handwerkerd
Copy link
Member

I just tried to update one of the branches I was working on with the newly linted code with the pre-commit hooks. I'm seeing two weird things.

First, when I merged the PR and tried to commit the branch, it made a few more changes in tests. It was all for cases like the following where it tried to add an additional period after the first line of the doc string:

Tests to make sure validate_tree suceeds for all default
decision trees in decision trees.

I'm suspecting the pre-commit hooks are using a slightly different standard on my local version and trying to push this added changes. Any ideas on how to fix my local settings?

The second is weirder and I'm hoping it resolves itself. In trying to show the above issue, I tried to compare branches:
https://github.com/ME-ICA/tedana/compare/ME-ICA:tedana:main...handwerkerd:tedana:doc-tree-dh?expand=1
It looks to me like it's trying to compare my branch with main before this PR was merged. Maybe whatever was done to make sure style changes weren't counted in line counts also messed up comparing branches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring issues proposing/requesting changes to the code which do not impact behavior testing issues related to improving testing in the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants