Skip to content

Commit 5749635

Browse files
authored
Merge 1c06dfc into 23cb96b
2 parents 23cb96b + 1c06dfc commit 5749635

File tree

16 files changed

+114
-418
lines changed

16 files changed

+114
-418
lines changed

.coderabbit.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ reviews:
4141
github-checks:
4242
enabled: true
4343
ruff:
44-
# Should become true if we switch linters,
45-
# right now linting is done by a flake8 check (#14817).
46-
enabled: false
44+
enabled: true
4745
markdownlint:
4846
# We use custom markdown syntax such as {#Anchor} for anchors.
4947
# This is not supported by markdownlint.

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.4.10
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: [ --fix ]
9+
# Run the formatter.
10+
- id: ruff-format
Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
1-
if ($env:APPVEYOR_PULL_REQUEST_NUMBER -or $env:APPVEYOR_REPO_BRANCH.StartsWith("try-")) {
2-
$lintOutput = (Resolve-Path .\testOutput\lint\)
3-
$lintSource = (Resolve-Path .\tests\lint\)
4-
$flake8Output = "$lintOutput\Flake8.txt"
5-
# When Appveyor runs for a pr,
6-
# the build is made from a new temporary commit,
7-
# resulting from the pr branch being merged into its base branch.
8-
# Therefore to create a diff for linting, we must fetch the head of the base branch.
9-
# In a PR, APPVEYOR_REPO_BRANCH points to the head of the base branch.
10-
# Additionally, we can not use a clone_depth of 1, but must use an unlimited clone.
11-
if($env:APPVEYOR_PULL_REQUEST_NUMBER) {
12-
git fetch -q origin $env:APPVEYOR_REPO_BRANCH
13-
$msgBaseLabel = "PR"
14-
} else {
15-
# However in a pushed branch, we must fetch master.
16-
git fetch -q origin master:master
17-
$msgBaseLabel = "Branch"
18-
}
19-
.\runlint.bat FETCH_HEAD "$flake8Output"
20-
if($LastExitCode -ne 0) {
21-
Set-AppveyorBuildVariable "testFailExitCode" $LastExitCode
22-
Add-AppveyorMessage "FAIL: Lint check. See test results for more information."
23-
} else {
24-
Add-AppveyorMessage "PASS: Lint check."
25-
}
26-
Push-AppveyorArtifact $flake8Output
27-
$junitXML = "$lintOutput\PR-Flake8.xml"
28-
py "$lintSource\createJunitReport.py" "$flake8Output" "$junitXML"
29-
Push-AppveyorArtifact $junitXML
30-
$wc = New-Object 'System.Net.WebClient'
31-
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $junitXML)
1+
$lintOutput = (Resolve-Path .\testOutput\lint\)
2+
$lintOutput = "$lintOutput\PR-lint.xml"
3+
.\runlint.bat "$lintOutput"
4+
if ($LastExitCode -ne 0) {
5+
Set-AppveyorBuildVariable "testFailExitCode" $LastExitCode
6+
Add-AppveyorMessage "FAIL: Lint check. See test results for more information."
7+
} else {
8+
Add-AppveyorMessage "PASS: Lint check."
329
}
10+
Push-AppveyorArtifact $lintOutput
11+
$wc = New-Object 'System.Net.WebClient'
12+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $lintOutput)

projectDocs/dev/codingStandards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Code Style
22

3-
Python code style is enforced with the flake8 linter, see [`tests/lint/readme.md`](https://github.com/nvaccess/nvda/tree/master/tests/lint/readme.md) for more information.
3+
Python code style is enforced with the Ruff linter, see [linting](./lint.md) for more information.
44

55
### Encoding
66

projectDocs/dev/contributing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ If you are new to the project, or looking for some way to help take a look at:
3737
1. [Run automated tests](../testing/automated.md)
3838
- Run `rununittests` (`rununittests.bat`) before you open your Pull Request, and make sure all the unit tests pass.
3939
- If possible for your PR, please consider creating a set of unit or system tests to test your changes.
40-
- The lint check ensures your changes comply with our code style expectations. Use `runlint nvaccess/master` (`runlint.bat`)
40+
- The lint check ensures your changes comply with our code style expectations.
41+
Use `runlint.bat`.
4142
- Run `scons checkPot` to ensure translatable strings have comments for the translators
4243
1. [Create a change log entry](#change-log-entry)
4344
1. [Create a Pull Request (PR)](./githubPullRequestTemplateExplanationAndExamples.md)

projectDocs/dev/lint.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Linting
2+
3+
## Lint overview
4+
5+
Our linting process involves running [Ruff](https://docs.astral.sh/ruff) to pick up linting issues and auto-apply fixes where possible.
6+
7+
## Lint integration
8+
9+
For faster lint results, or greater integration with your tools you may want to set up Ruff with your IDE.
10+
11+
## Pre-commit hooks
12+
13+
[Pre-commit hooks](https://pre-commit.com/) can be used to automatically run linting on files staged for commit.
14+
This will automatically apply lint fixes where possible, otherwise cancelling the commit on lint issues.
15+
16+
From a shell, set up pre-commit scripts for your NVDA python environment:
17+
18+
1. `venvUtils\ensureAndActivate.bat`
19+
1. `pre-commit install`
20+
21+
Alternatively, set up pre-commit scripts globally:
22+
23+
1. `pip install pre-commit`
24+
1. `pre-commit install --allow-missing-config`

projectDocs/testing/automated.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ scons checkPot
2727
```
2828

2929
### Linting your changes
30-
In order to ensure your changes comply with NVDA's coding style you can run the Flake8 linter locally.
31-
Some developers have found certain linting error messages misleading, these are clarified in `tests/lint/readme.md`.
32-
runlint.bat will use Flake8 to inspect only the differences between your working directory and the specified `base` branch.
33-
If you create a Pull Request, the `base` branch you use here should be the same as the target you would use for a Pull Request. In most cases it will be `origin/master`.
30+
31+
In order to ensure your changes comply with NVDA's coding style you can run the Ruff linter locally.
32+
`runlint.bat` will use Ruff to lint and where possible, fix the code you have written.
33+
3434
```cmd
35-
runlint origin/master
35+
runlint.bat
3636
```
3737

38-
To be warned about linting errors faster, you may wish to integrate Flake8 with other development tools you are using.
39-
For more details, see `tests/lint/readme.md`
38+
To be warned about linting errors faster, you may wish to integrate Ruff with other development tools you are using.
39+
For more details, see the [linting docs](../dev/lint.md).
4040

4141
### Unit Tests
4242
Unit tests can be run with the `rununittests.bat` script.

pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
11
[build-system]
22
requires = ["setuptools<70", "wheel"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.ruff]
6+
line-length = 110
7+
8+
builtins = [
9+
# translation lookup
10+
"_",
11+
# translation lookup
12+
"ngettext",
13+
# translation lookup
14+
"pgettext",
15+
# translation lookup
16+
"npgettext",
17+
]
18+
19+
logger-objects = ["logHandler.log"]
20+
21+
include = [
22+
"*.py",
23+
"*.pyw",
24+
]
25+
26+
exclude = [
27+
".git",
28+
"__pycache__",
29+
".tox",
30+
"build",
31+
"output",
32+
# When excluding concrete paths relative to a directory,
33+
# not matching multiple folders by name e.g. `__pycache__`,
34+
# paths are relative to the configuration file.
35+
"./include/*",
36+
"./miscDeps",
37+
"./source/louis",
38+
# #10924: generated by third-party dependencies
39+
"./source/comInterfaces/*",
40+
]
41+
42+
[tool.ruff.format]
43+
indent-style = "tab"
44+
line-ending = "lf"
45+
46+
[tool.ruff.lint.mccabe]
47+
max-complexity = 15
48+
49+
[tool.ruff.lint]
50+
ignore = [
51+
# indentation contains tabs
52+
"W191",
53+
]

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ sphinx==7.2.6
3939
sphinx_rtd_theme==1.3.0
4040

4141
# Requirements for automated linting
42-
flake8 ~= 4.0.1
43-
flake8-tabs == 2.1.0
42+
ruff==0.4.10
43+
pre-commit==3.7.1
4444

4545
# Requirements for system tests
4646
robotframework==6.1.1

runlint.bat

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
@echo off
2-
rem runlint <base commit> [<output file>]
3-
rem Lints any changes after base commit up to and including current HEAD, plus any uncommitted changes.
2+
rem runlint [<output file>]
3+
rem Lints the entire repository
44
set hereOrig=%~dp0
55
set here=%hereOrig%
66
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
77
set scriptsDir=%here%\venvUtils
8-
set lintFilesPath=%here%\tests\lint
98

10-
call "%scriptsDir%\venvCmd.bat" py "%lintFilesPath%\genDiff.py" %1 "%lintFilesPath%\_lint.diff"
11-
if ERRORLEVEL 1 exit /b %ERRORLEVEL%
12-
set flake8Args=--diff --config="%lintFilesPath%\flake8.ini"
13-
if "%2" NEQ "" set flake8Args=%flake8Args% --tee --output-file=%2
14-
type "%lintFilesPath%\_lint.diff" | call "%scriptsDir%\venvCmd.bat" py -Xutf8 -m flake8 %flake8Args%
15-
9+
if "%1" NEQ "" set ruffArgs=--output-file=%1 --output-format=junit
10+
call "%scriptsDir%\venvCmd.bat" ruff check --fix %ruffArgs%
11+
if ERRORLEVEL 1 exit /b %ERRORLEVEL%

0 commit comments

Comments
 (0)