Skip to content

Commit 1632f19

Browse files
authored
Merge d396e36 into 23cb96b
2 parents 23cb96b + d396e36 commit 1632f19

File tree

16 files changed

+112
-406
lines changed

16 files changed

+112
-406
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: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
if ($env:APPVEYOR_PULL_REQUEST_NUMBER -or $env:APPVEYOR_REPO_BRANCH.StartsWith("try-")) {
22
$lintOutput = (Resolve-Path .\testOutput\lint\)
3-
$lintSource = (Resolve-Path .\tests\lint\)
4-
$flake8Output = "$lintOutput\Flake8.txt"
3+
$lintOutput = "$lintOutput\PR-lint.xml"
54
# When Appveyor runs for a pr,
65
# the build is made from a new temporary commit,
76
# resulting from the pr branch being merged into its base branch.
@@ -16,17 +15,14 @@ if ($env:APPVEYOR_PULL_REQUEST_NUMBER -or $env:APPVEYOR_REPO_BRANCH.StartsWith("
1615
git fetch -q origin master:master
1716
$msgBaseLabel = "Branch"
1817
}
19-
.\runlint.bat FETCH_HEAD "$flake8Output"
18+
.\runlint.bat "$lintOutput"
2019
if($LastExitCode -ne 0) {
2120
Set-AppveyorBuildVariable "testFailExitCode" $LastExitCode
2221
Add-AppveyorMessage "FAIL: Lint check. See test results for more information."
2322
} else {
2423
Add-AppveyorMessage "PASS: Lint check."
2524
}
26-
Push-AppveyorArtifact $flake8Output
27-
$junitXML = "$lintOutput\PR-Flake8.xml"
28-
py "$lintSource\createJunitReport.py" "$flake8Output" "$junitXML"
29-
Push-AppveyorArtifact $junitXML
25+
Push-AppveyorArtifact $lintOutput
3026
$wc = New-Object 'System.Net.WebClient'
31-
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $junitXML)
27+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $lintOutput)
3228
}

projectDocs/dev/codingStandards.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
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
6-
76
* Where Python files contain non-ASCII characters, they should be encoded in UTF-8.
8-
* There should be no Unicode BOM at the start of the file, as this unfortunately breaks one of the translation tools we use (`xgettext`).
9-
Instead, include this as the first line of the file, only if the file contains non-ASCII characters:
10-
11-
```py
12-
# -*- coding: UTF-8 -*-
13-
```
14-
15-
* This coding comment must also be included if strings in the code (even strings that aren't translatable) contain escape sequences that produce non-ASCII characters; e.g. `"\xff"`.
7+
* There should be no Unicode BOM at the start of the file, as this unfortunately breaks one of the translation tools we use (`xgettext`).
8+
Instead, include this as the first line of the file, only if the file contains non-ASCII characters:
9+
```py
10+
# -*- coding: UTF-8 -*-
11+
```
12+
* This coding comment must also be included if strings in the code (even strings that aren't translatable) contain escape sequences that produce non-ASCII characters; e.g. `"\xff"`.
1613
This is particularly relevant for braille display drivers.
1714
This is due to a `gettext` bug; see [comment on #2592](https://github.com/nvaccess/nvda/issues/2592#issuecomment-155299911).
18-
* Text files should be committed with `LF` line endings.
19-
Files can be checked out locally using CRLF if needed for Windows development using [git](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_autocrlf).
15+
* New files should contain `LF` line endings, however NVDA currently uses a mix of LF and CRLF line endings.
16+
See issue [#12387](https://github.com/nvaccess/nvda/issues/12387).
2017

2118
### Indentation
2219
* Indentation must be done with tabs (one per level), not spaces.

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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
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+
include = [
20+
"*.py",
21+
"*.pyw",
22+
]
23+
24+
exclude = [
25+
".git",
26+
"__pycache__",
27+
".tox",
28+
"build",
29+
"output",
30+
# When excluding concrete paths relative to a directory,
31+
# not matching multiple folders by name e.g. `__pycache__`,
32+
# paths are relative to the configuration file.
33+
"./include/*",
34+
"./miscDeps",
35+
"./source/louis",
36+
# #10924: generated by third-party dependencies
37+
"./source/comInterfaces/*",
38+
]
39+
40+
[tool.ruff.format]
41+
indent-style = "tab"
42+
43+
[tool.ruff.lint.mccabe]
44+
max-complexity = 15
45+
46+
[tool.ruff.lint]
47+
ignore = [
48+
# indentation contains tabs
49+
"W191",
50+
]

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)