Skip to content

Commit

Permalink
Merge d396e36 into 23cb96b
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd authored Jun 27, 2024
2 parents 23cb96b + d396e36 commit 1632f19
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 406 deletions.
4 changes: 1 addition & 3 deletions .coderabbit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ reviews:
github-checks:
enabled: true
ruff:
# Should become true if we switch linters,
# right now linting is done by a flake8 check (#14817).
enabled: false
enabled: true
markdownlint:
# We use custom markdown syntax such as {#Anchor} for anchors.
# This is not supported by markdownlint.
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.10
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
12 changes: 4 additions & 8 deletions appveyor/scripts/tests/lintCheck.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
if ($env:APPVEYOR_PULL_REQUEST_NUMBER -or $env:APPVEYOR_REPO_BRANCH.StartsWith("try-")) {
$lintOutput = (Resolve-Path .\testOutput\lint\)
$lintSource = (Resolve-Path .\tests\lint\)
$flake8Output = "$lintOutput\Flake8.txt"
$lintOutput = "$lintOutput\PR-lint.xml"
# When Appveyor runs for a pr,
# the build is made from a new temporary commit,
# resulting from the pr branch being merged into its base branch.
Expand All @@ -16,17 +15,14 @@ if ($env:APPVEYOR_PULL_REQUEST_NUMBER -or $env:APPVEYOR_REPO_BRANCH.StartsWith("
git fetch -q origin master:master
$msgBaseLabel = "Branch"
}
.\runlint.bat FETCH_HEAD "$flake8Output"
.\runlint.bat "$lintOutput"
if($LastExitCode -ne 0) {
Set-AppveyorBuildVariable "testFailExitCode" $LastExitCode
Add-AppveyorMessage "FAIL: Lint check. See test results for more information."
} else {
Add-AppveyorMessage "PASS: Lint check."
}
Push-AppveyorArtifact $flake8Output
$junitXML = "$lintOutput\PR-Flake8.xml"
py "$lintSource\createJunitReport.py" "$flake8Output" "$junitXML"
Push-AppveyorArtifact $junitXML
Push-AppveyorArtifact $lintOutput
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $junitXML)
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $lintOutput)
}
21 changes: 9 additions & 12 deletions projectDocs/dev/codingStandards.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
## Code Style

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.
Python code style is enforced with the Ruff linter, see [linting](./lint.md) for more information.

### Encoding

* Where Python files contain non-ASCII characters, they should be encoded in UTF-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`).
Instead, include this as the first line of the file, only if the file contains non-ASCII characters:

```py
# -*- coding: UTF-8 -*-
```

* 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"`.
* There should be no Unicode BOM at the start of the file, as this unfortunately breaks one of the translation tools we use (`xgettext`).
Instead, include this as the first line of the file, only if the file contains non-ASCII characters:
```py
# -*- coding: UTF-8 -*-
```
* 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"`.
This is particularly relevant for braille display drivers.
This is due to a `gettext` bug; see [comment on #2592](https://github.com/nvaccess/nvda/issues/2592#issuecomment-155299911).
* Text files should be committed with `LF` line endings.
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).
* New files should contain `LF` line endings, however NVDA currently uses a mix of LF and CRLF line endings.
See issue [#12387](https://github.com/nvaccess/nvda/issues/12387).

### Indentation
* Indentation must be done with tabs (one per level), not spaces.
Expand Down
3 changes: 2 additions & 1 deletion projectDocs/dev/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ If you are new to the project, or looking for some way to help take a look at:
1. [Run automated tests](../testing/automated.md)
- Run `rununittests` (`rununittests.bat`) before you open your Pull Request, and make sure all the unit tests pass.
- If possible for your PR, please consider creating a set of unit or system tests to test your changes.
- The lint check ensures your changes comply with our code style expectations. Use `runlint nvaccess/master` (`runlint.bat`)
- The lint check ensures your changes comply with our code style expectations.
Use `runlint.bat`.
- Run `scons checkPot` to ensure translatable strings have comments for the translators
1. [Create a change log entry](#change-log-entry)
1. [Create a Pull Request (PR)](./githubPullRequestTemplateExplanationAndExamples.md)
Expand Down
24 changes: 24 additions & 0 deletions projectDocs/dev/lint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Linting

## Lint overview

Our linting process involves running [Ruff](https://docs.astral.sh/ruff) to pick up linting issues and auto-apply fixes where possible.

## Lint integration

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

## Pre-commit hooks

[Pre-commit hooks](https://pre-commit.com/) can be used to automatically run linting on files staged for commit.
This will automatically apply lint fixes where possible, otherwise cancelling the commit on lint issues.

From a shell, set up pre-commit scripts for your NVDA python environment:

1. `venvUtils\ensureAndActivate.bat`
1. `pre-commit install`

Alternatively, set up pre-commit scripts globally:

1. `pip install pre-commit`
1. `pre-commit install --allow-missing-config`
14 changes: 7 additions & 7 deletions projectDocs/testing/automated.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ scons checkPot
```

### Linting your changes
In order to ensure your changes comply with NVDA's coding style you can run the Flake8 linter locally.
Some developers have found certain linting error messages misleading, these are clarified in `tests/lint/readme.md`.
runlint.bat will use Flake8 to inspect only the differences between your working directory and the specified `base` branch.
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`.

In order to ensure your changes comply with NVDA's coding style you can run the Ruff linter locally.
`runlint.bat` will use Ruff to lint and where possible, fix the code you have written.

```cmd
runlint origin/master
runlint.bat
```

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

### Unit Tests
Unit tests can be run with the `rununittests.bat` script.
Expand Down
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
[build-system]
requires = ["setuptools<70", "wheel"]
build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 110

builtins = [
# translation lookup
"_",
# translation lookup
"ngettext",
# translation lookup
"pgettext",
# translation lookup
"npgettext",
]

include = [
"*.py",
"*.pyw",
]

exclude = [
".git",
"__pycache__",
".tox",
"build",
"output",
# When excluding concrete paths relative to a directory,
# not matching multiple folders by name e.g. `__pycache__`,
# paths are relative to the configuration file.
"./include/*",
"./miscDeps",
"./source/louis",
# #10924: generated by third-party dependencies
"./source/comInterfaces/*",
]

[tool.ruff.format]
indent-style = "tab"

[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.ruff.lint]
ignore = [
# indentation contains tabs
"W191",
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ sphinx==7.2.6
sphinx_rtd_theme==1.3.0

# Requirements for automated linting
flake8 ~= 4.0.1
flake8-tabs == 2.1.0
ruff==0.4.10
pre-commit==3.7.1

# Requirements for system tests
robotframework==6.1.1
Expand Down
14 changes: 5 additions & 9 deletions runlint.bat
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
@echo off
rem runlint <base commit> [<output file>]
rem Lints any changes after base commit up to and including current HEAD, plus any uncommitted changes.
rem runlint [<output file>]
rem Lints the entire repository
set hereOrig=%~dp0
set here=%hereOrig%
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
set scriptsDir=%here%\venvUtils
set lintFilesPath=%here%\tests\lint

call "%scriptsDir%\venvCmd.bat" py "%lintFilesPath%\genDiff.py" %1 "%lintFilesPath%\_lint.diff"
if ERRORLEVEL 1 exit /b %ERRORLEVEL%
set flake8Args=--diff --config="%lintFilesPath%\flake8.ini"
if "%2" NEQ "" set flake8Args=%flake8Args% --tee --output-file=%2
type "%lintFilesPath%\_lint.diff" | call "%scriptsDir%\venvCmd.bat" py -Xutf8 -m flake8 %flake8Args%

if "%1" NEQ "" set ruffArgs=--output-file=%1 --output-format=junit
call "%scriptsDir%\venvCmd.bat" ruff check --fix %ruffArgs%
if ERRORLEVEL 1 exit /b %ERRORLEVEL%
3 changes: 0 additions & 3 deletions tests/lint/.gitignore

This file was deleted.

65 changes: 0 additions & 65 deletions tests/lint/createJunitReport.py

This file was deleted.

65 changes: 0 additions & 65 deletions tests/lint/flake8.ini

This file was deleted.

Loading

0 comments on commit 1632f19

Please sign in to comment.