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

Apply ruff formatting and linting along with relevant refactoring #371

Merged
merged 16 commits into from
Mar 2, 2024

Conversation

kenibrewer
Copy link
Member

@kenibrewer kenibrewer commented Feb 12, 2024

Description

Code quality update adopting the use of ruff format instead black, and ruff check for a suite of linting checks.

This PR includes extended comments in the commits which are broken down using a commit for each new set of checks and the appropriate fixes. It is recommended to review the PR using this commit by commit approach.

Additional checks/fixes planned for the future are represented by commented out lines in pyproject.toml. I attempted to apply each of them but they represent more substantial changes that should be reviewed separately.

What is the nature of your change?

  • Bug fix (fixes an issue).
  • Enhancement (adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • This change requires a documentation update.

Checklist

Please ensure that all boxes are checked before indicating that a pull request is ready for review.

  • I have read the CONTRIBUTING.md guidelines.
  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • New and existing unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have deleted all non-relevant text in this pull request template.

📚 Documentation preview 📚: https://pycytominer--371.org.readthedocs.build/en/371/

@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2024

Codecov Report

Attention: Patch coverage is 98.78049% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.96%. Comparing base (b039ade) to head (7d74b35).

Files Patch % Lines
pycytominer/cyto_utils/collate.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #371      +/-   ##
==========================================
- Coverage   95.01%   94.96%   -0.05%     
==========================================
  Files          56       56              
  Lines        3187     3139      -48     
==========================================
- Hits         3028     2981      -47     
+ Misses        159      158       -1     
Flag Coverage Δ
unittests 94.96% <98.78%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@kenibrewer
Copy link
Member Author

@d33bs @gwaybio I'm currently traveling in Morocco and using the mobile app and can't figure out how to properly mark this ready for review and add you as reviewers. This is a big PR but I broke it up by commits to hopefully make it easier.

@kenibrewer kenibrewer marked this pull request as ready for review February 13, 2024 17:36
@kenibrewer kenibrewer assigned kenibrewer and unassigned d33bs and gwaybio Feb 14, 2024
Copy link
Member

@d33bs d33bs left a comment

Choose a reason for hiding this comment

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

Nice job! Looks like a lot of good changes here to help simplify things. I left a few comments for your consideration as part of this review.

Additional mentions:

  • I noticed that the Codecov.io comment mentioned something about a potential missing file. Is this something which could be addressed before a merge?
  • Consider updating the PR title to reflect the specific changes applied (i.e. ruff-format addition, applied formatting, etc).

.devcontainer/devcontainer.json Show resolved Hide resolved
docs/conf.py Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
pycytominer/cyto_utils/modz.py Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
tests/test_consensus.py Show resolved Hide resolved
tests/test_cyto_utils/test_cell_locations.py Show resolved Hide resolved
walkthroughs/nbconverted/single_cell_usage.py Show resolved Hide resolved
Copy link
Member Author

@kenibrewer kenibrewer left a comment

Choose a reason for hiding this comment

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

@d33bs Incorporated your feedback and made revisions to style guide section.

docs/conf.py Show resolved Hide resolved
tests/test_consensus.py Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pycytominer/cyto_utils/modz.py Show resolved Hide resolved
walkthroughs/nbconverted/single_cell_usage.py Show resolved Hide resolved
tests/test_cyto_utils/test_cell_locations.py Show resolved Hide resolved
Copy link
Member

@d33bs d33bs left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments @kenibrewer ! I'm going to give this my approval and would like to ask for a further review from @gwaybio to make sure we aren't missing something especially when it comes to the test changes. I'd still recommend changing the title of the PR to be more descriptive to the type of changes occurring - adding specificity if possible.

@kenibrewer kenibrewer changed the title Refactor/code quality updates Apply ruff formatting and linting along with relevant refactoring Feb 27, 2024
This change makes the dev dependency group optional so it won't be installed by default with `poetry install` unless included by `--with dev`. This brings this group in alignment with the docs group.
ruff-format is a rust implementation of the black formatter that is 10x faster with 99.9% compatiblity. This commit swaps out black for the ruff-format as the pre-commit hook that checks formatting.
pyupgrade checks for (and automatically fixes) code patterns from older python versions with the updated patterns. This commit turns on that check and applies the fixes to the codebase. These fix for our codebase consist mostly of replacing `"a{}c".format('b')` with `f"a{'b'}c".
To support a large collection of additional ruff checks that are applied to the codebase, this commit adds the ruff vscode extension to the devcontainer configuration. This will support developers in providing in-line highlighting and automatic fixing.
This applies some ruff native quality checks to the codebase. The two changes applied to our codebase are iliminating the use of an implicit Optional variable type and using *-expansion to generate combined lists instead of concatenation.
This applies pycodestyle E and W checks to the codebase. The most common change from these checks is replacing "!= None" with "is not None"
This commit applies flake8-simplify checks to the codebase. The non-style refactoring included in this commit is primarily condensing nested ifs and using or/and instead.
No additional changes required for codebase
This commit applies pyflakes checks to the codebase and removes a large number of unused variables and imports.
Notable non-automatic fixes in this commit include removing variables that are never checked while testing error conditions.
This also removes an unused invocation of consensus during the test_aggregate set of tests that appears to be left over from copy and pasting tests.
This commit applies the flake8 builtins checks that checks for variables shadowing python built-in functions and variables. As part of this, we rename the docs variable `copyright` to the alias `project_copyright` to avoid shadowing the python built-in function. https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-project_copyright
In preparation for turning on the flake8-bandit checks (which will need to be a separate PR), this adds the most important per-file ignore statement to allow the use of assert statements during tests, but keep them forbidden within the codebase itself.
@kenibrewer kenibrewer force-pushed the refactor/code-quality-updates branch from 19bbdd7 to 7d74b35 Compare March 2, 2024 20:09
Copy link
Member Author

@kenibrewer kenibrewer left a comment

Choose a reason for hiding this comment

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

I incorporated some more of @d33bs feedback in the docs and added an additional clarifying assert for the cell_loc tests.

I'll move ahead and merge these commits after tests finish running.

CONTRIBUTING.md Outdated Show resolved Hide resolved
tests/test_cyto_utils/test_cell_locations.py Show resolved Hide resolved
@kenibrewer kenibrewer merged commit 4e84a04 into cytomining:main Mar 2, 2024
10 checks passed
@kenibrewer kenibrewer deleted the refactor/code-quality-updates branch March 2, 2024 20:28
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.

4 participants