Skip to content

Ruff changes, expand pre-commit hooks to checkPot and unit tests#16767

Merged
seanbudd merged 11 commits intomasterfrom
minorRuffChanges
Jul 3, 2024
Merged

Ruff changes, expand pre-commit hooks to checkPot and unit tests#16767
seanbudd merged 11 commits intomasterfrom
minorRuffChanges

Conversation

@seanbudd
Copy link
Copy Markdown
Member

@seanbudd seanbudd commented Jun 28, 2024

Link to issue number:

Fix up for #16751

Summary of the issue:

  • Ruff recently updated, so we might as well use the latest version.
  • a warning is omitted for the section we added logger-objects to in ruff's config.
  • it was unclear in docs how to avoid pre-commit hooks from triggering.
  • more pre-commit hooks could be added
  • ruff whitespace formating is done through ruff format currently we are only linting with ruff check. We should also run a ruff format on the whole NVDA.
  • ruff was missing scons files, which should also be linted in a mass lint.

Summary of other changes:

  • Added pre commit hooks for unit tests and translation comment checks.
  • Added generic pre-commit hooks for python static syntax checking, basic whitespace rules, and file write safety checks
  • change the output of rununittests.bat to have simpler buffer output, only show failures. Ensure the verbose log is logged in AppVeyor.
  • add ruff format to lint checks
  • add scons files to lint checks
  • update coderabbit prompt for change log entry items

@coderabbitai summary

@seanbudd seanbudd requested a review from a team as a code owner June 28, 2024 01:51
@seanbudd seanbudd requested a review from gerald-hartig June 28, 2024 01:51
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 28, 2024

Walkthrough

The recent update primarily deals with enhancing linters and documentation within the project. Specifically, the ruff-pre-commit hook has been upgraded from version v0.4.10 to v0.5.0, and documentation now includes instructions for bypassing pre-commit hooks. Additionally, the pyproject.toml file underwent a minor revision where the logger-objects configuration was briefly removed and then restored.

Changes

Files Change Summary
.pre-commit-config.yaml Updated revision of ruff-pre-commit repository from v0.4.10 to v0.5.0.
projectDocs/dev/lint.md Added instructions on using --no-verify to avoid triggering pre-commit hooks, including an example.
pyproject.toml Removed and re-added logger-objects = ["logHandler.log"] at the end of the file.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
projectDocs/dev/lint.md (1)

Line range hint 9-9: Consider adding a comma for improved readability.

To enhance the readability of the sentence, consider adding a comma after "results" in the sentence:

- For faster lint results or greater integration with your tools you may want to set up Ruff with your IDE.
+ For faster lint results, or greater integration with your tools you may want to set up Ruff with your IDE.

This change aligns with the static analysis suggestion.

Tools
LanguageTool

[uncategorized] ~26-~26: Possible missing comma found.
Context: ...config To avoid pre-commit hooks from triggering use the--no-verify` CLI option. Examp...

(AI_HYDRA_LEO_MISSING_COMMA)

seanbudd and others added 3 commits June 28, 2024 12:00
@seanbudd seanbudd requested a review from a team as a code owner June 28, 2024 02:53
@seanbudd seanbudd requested a review from Qchristensen June 28, 2024 02:53
@seanbudd seanbudd changed the title minor Ruff changes Ruff changes, expand pre-commit hooks to checkPot and unit tests Jun 28, 2024
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Jul 2, 2024
@AppVeyorBot
Copy link
Copy Markdown

See test results for failed build of commit 9b142c3627

md %testOutput%

call "%scriptsDir%\venvCmd.bat" py -m xmlrunner discover -v -s "%unitTestsPath%" -t "%here%" --output-file "%testOutput%\unitTests.xml" %*
call "%scriptsDir%\venvCmd.bat" py -m xmlrunner discover -b -s "%unitTestsPath%" -t "%here%" --output-file "%testOutput%\unitTests.xml" %*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the change from -v to -b?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the test success output is incredibly noisy, to the point where it cannot be parsed reasonably. -b only shows test failures, and makes it easier to parse for both sighted and screen reader devs. the buffer output for screen reader users is F for each test failure, and without supressing punctuation, a "dot" for each test success.
we use -v for appveyor to retain a full log.

@AppVeyorBot
Copy link
Copy Markdown

See test results for failed build of commit d49215a8c0

@seanbudd seanbudd merged commit b47fdc5 into master Jul 3, 2024
@seanbudd seanbudd deleted the minorRuffChanges branch July 3, 2024 05:29
"*.py",
"*.pyw",
"sconstruct",
"*sconscript",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ugh, I now notice that this gets really noisy. We should either tell Ruff about scons internals like Return, Import, etc. or revert this, I think.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This seems fixable with

[tool.ruff.lint.per-file-ignores]
# sconscripts contains many inbuilt functions not recognised by the lint,
# so ignore F821.
"sconstruct" = ["F821"]
"*sconscript" = ["F821"]

seanbudd added a commit that referenced this pull request Jul 4, 2024
Closes #11905
Follow up to #16767

Summary of the issue:
scons files have a lot of inbuilt functions that the linter doesn't recognize. See also #11905

Ruff preserves indent/new-line formatting of function arguments, list items, and similar iterables, if a trailing comma is added.
Much of NVDA is missing these trailing commas causing the lint to collapse them.

Description of user facing changes
Description of development approach
A lint rule has been added to ignore F821 errors in scons files.

A pre-commit hook is added, which adds a trailing comma to python in case it was missed.
seanbudd added a commit that referenced this pull request Jul 4, 2024
run ruff format to fix whitespace changes

Follow up to #16767
Closes #12261

Summary of the issue:
When migrating to ruff in #16751, we failed to lint scons files, and also run ruff format on the repository.
Ruff format fixes whitespaces issues in python files.

Description of user facing changes
None

Description of development approach
Perform lint fixes on scons files and run ruff format.
@LeonarddeR LeonarddeR mentioned this pull request Jul 16, 2024
6 tasks
seanbudd pushed a commit that referenced this pull request Aug 1, 2024
Follow up to #16767, #16803
Preparation for #16852

Summary of the issue:
Pre-commit touches several files it shouldn't touch, e.g. symbol dictionaries, translated markdown.

Description of user facing changes
None

Description of development approach
Update Ruff to 0.5.2 in requirements
Add a hook for scons source
Update sconstruct to automatically use the max number of cores when passing -j 0, which can be used with pre-commit to have optimal performance
Run pre-commit autoupdate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants