Skip to content

Commit

Permalink
Merge branch 'master' into docsFor2024.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd authored Jun 28, 2024
2 parents 53bf9a7 + 405f9bf commit 0d012d7
Show file tree
Hide file tree
Showing 169 changed files with 1,407 additions and 1,795 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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ e6a639bfe237ff7f98c4cbec2094a34ac4b879db
7afafc698a0c5e6689701f024764ca525acf50af
# Normalize all line endings
8fb8ffcaba3950b1e4ca7b58e165267fc5369eb9
# Lint the repository with Ruff
d3ce6b8879b14464058d5eaf3f914f803e8f22ac
8bdfbc2e8da78945e20c3b203b39b9a81227d596
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
1 change: 0 additions & 1 deletion appveyor/mozillaSyms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
To update the list of symbols uploaded to Mozilla, see the DLL_NAMES constant below.
"""

import argparse
import os
import subprocess
import sys
Expand Down
42 changes: 11 additions & 31 deletions appveyor/scripts/tests/lintCheck.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
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"
# 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.
# Therefore to create a diff for linting, we must fetch the head of the base branch.
# In a PR, APPVEYOR_REPO_BRANCH points to the head of the base branch.
# Additionally, we can not use a clone_depth of 1, but must use an unlimited clone.
if($env:APPVEYOR_PULL_REQUEST_NUMBER) {
git fetch -q origin $env:APPVEYOR_REPO_BRANCH
$msgBaseLabel = "PR"
} else {
# However in a pushed branch, we must fetch master.
git fetch -q origin master:master
$msgBaseLabel = "Branch"
}
.\runlint.bat FETCH_HEAD "$flake8Output"
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
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $junitXML)
$lintOutput = (Resolve-Path .\testOutput\lint\)
$lintOutput = "$lintOutput\PR-lint.xml"
.\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 $lintOutput
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", $lintOutput)
2 changes: 1 addition & 1 deletion projectDocs/dev/codingStandards.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 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

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
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
[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",
]

logger-objects = ["logHandler.log"]

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"
line-ending = "lf"

[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%
4 changes: 2 additions & 2 deletions site_scons/site_tools/doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def DoxyfileParse(file_contents):
lex.whitespace = lex.whitespace.replace("\n", "")
lex.escape = ""

lineno = lex.lineno
lineno = lex.lineno # noqa: F841
token = lex.get_token()
key = token # the first token should be a key
last_token = ""
key_token = False
next_key = False
next_key = False # noqa: F841
new_data = True

def append_data(data, key, new_data, token):
Expand Down
1 change: 0 additions & 1 deletion site_scons/site_tools/gettextTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
###

import os
import sys

# Get the path to msgfmt.
MSGFMT = os.path.abspath(os.path.join("miscDeps", "tools", "msgfmt.exe"))
Expand Down
2 changes: 1 addition & 1 deletion site_scons/site_tools/msrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def exists(env):
return midl.exists(env)

def generate(env):
if not 'MIDL' in env:
if 'MIDL' not in env:
from SCons.Tool import midl
midl.generate(env)
env['BUILDERS']['MSRPCStubs']=MSRPCStubs_builder
Expand Down
2 changes: 1 addition & 1 deletion site_scons/site_tools/recursiveInstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def RecursiveInstall(env, target, dir):
dir = env.Dir(dir).abspath
target = env.Dir(target).abspath

l = len(dir) + 1
l = len(dir) + 1 # noqa: E741

relnodes = [ n.abspath[l:] for n in nodes ]

Expand Down
8 changes: 4 additions & 4 deletions source/JABHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def internal_getWindowHandleFromAccContext(vmID,accContext):
return bridgeDll.getHWNDFromAccessibleContext(vmID,topAC)
finally:
bridgeDll.releaseJavaObject(vmID,topAC)
except:
except: # noqa: E722
return None

def getWindowHandleFromAccContext(vmID,accContext):
Expand Down Expand Up @@ -421,7 +421,7 @@ def __del__(self):
if isRunning:
try:
bridgeDll.releaseJavaObject(self.vmID,self.accContext)
except:
except: # noqa: E722
log.debugWarning("Error releasing java object",exc_info=True)


Expand Down Expand Up @@ -795,15 +795,15 @@ def enterJavaWindow_helper(hwnd):
while time.time()<timeout and not eventHandler.isPendingEvents("gainFocus"):
try:
bridgeDll.getAccessibleContextWithFocus(hwnd,byref(vmID),byref(accContext))
except:
except: # noqa: E722
pass
if vmID and accContext:
break
time.sleep(0.01)
if not vmID or not accContext:
try:
bridgeDll.getAccessibleContextFromHWND(hwnd,byref(vmID),byref(accContext))
except:
except: # noqa: E722
return
vmID=vmID.value
vmIDsToWindowHandles[vmID]=hwnd
Expand Down
Loading

0 comments on commit 0d012d7

Please sign in to comment.