-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Flake8 linting with SCons (PR #9958)
Code contributors regularly have to deal with ill-defined and inconsistently enforced code style requirements. Code reviewers spend much of their time reporting minor issues, time that would be better spent looking for architectural problems / product issues / logic errors. In this commit we introduce automated checking of python style. The diff from new PR's will be tested for compliance with Flake8. The NVDA Python code already contains several inconsistent styles, so rather than try to match it I have tried to configure Flake8 to use the default style guidelines as much as possible. Added two new SCons build targets: - `lint` - creates a unified diff with `git diff -U0 $(git merge-base <baseBranch>)` - A helper script is used to generate this diff (`tests\lint\genDiff.py`) - The diff is piped to `flake8` to perform the linting. - The output is printed to stdout and also to `tests/lint/current.lint` - `lintInstall` - required by `lint`. - Uses pip to install dependencies from a `requirements.txt` file. AppVeyor changes: - Adds a new script for tests phase of build - Mostly does what SCons does, does not need to worry about getting working tree / uncommit changes into the diff. - In order to preserve the availability of artifacts, these are uploaded from a `on_finish` phase rather than `artifacts` phase. - This acts like a "finally" block, and happens regardless of whether the build passes or fails. - The installer artifact is often used to test if a change fixes an issue before the PR is polished off / reviewed. It also can help reviewers to test a change locally without having to build the branch. - A message is sent when there are linting errors. - A failed lint will still halt the build, system tests are not run. Closes #5918
- Loading branch information
1 parent
00755f2
commit e68ce2d
Showing
14 changed files
with
396 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
current.diff | |||
current.lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,65 @@ | |||
# -*- coding: UTF-8 -*- | |||
# A part of NonVisual Desktop Access (NVDA) | |||
# This file is covered by the GNU General Public License. | |||
# See the file COPYING for more details. | |||
# Copyright (C) 2019 NV Access Limited | |||
|
|||
import os | |||
from sys import argv | |||
|
|||
NO_ERROR = r'''<?xml version="1.0" encoding="UTF-8"?> | |||
<testsuite name="flake8" tests="1" errors="0" failures="0" skip="0"> | |||
<testcase classname="flake8.lint" name="flake8_diff_lint" time="1.00"> | |||
</testcase> | |||
</testsuite> | |||
''' | |||
|
|||
# With Error: | |||
WE_PRE = r'''<?xml version="1.0" encoding="UTF-8"?> | |||
<testsuite name="flake8" tests="1" errors="1" failures="0" skip="0"> | |||
<testcase classname="flake8.lint" name="flake8_diff_lint" time="1.00"> | |||
<error type="lintError" message="Linting errors occurred"> | |||
<![CDATA[ | |||
''' | |||
WE_POST = r''' | |||
]]> | |||
</error> | |||
</testcase> | |||
</testsuite> | |||
''' | |||
|
|||
|
|||
def makeJunitXML(inFileName, outFileName): | |||
with open(inFileName, 'rt', encoding='UTF-8') as flake8In: | |||
errorText = flake8In.read() | |||
if len(errorText) > 0: | |||
# make "with error" xml content | |||
outContents = f'{WE_PRE}{errorText}{WE_POST}' | |||
else: | |||
# make "no error" xml content | |||
outContents = NO_ERROR | |||
|
|||
with open(outFileName, 'wt', encoding='UTF-8') as out: | |||
out.write(outContents) | |||
|
|||
|
|||
def main(): | |||
try: | |||
if len(argv) != 3: | |||
raise RuntimeError( | |||
f"{argv[0]} expects two arguments: flake8_output_file_name junit_file_name" | |||
) | |||
scriptName, flake8OutputFileName, junitFileName = argv | |||
if not os.path.isfile(flake8OutputFileName): | |||
raise RuntimeError( | |||
f"Flake8_output_file does not exist at {flake8OutputFileName}" | |||
) | |||
makeJunitXML(flake8OutputFileName, junitFileName) | |||
except Exception as e: | |||
print(e) | |||
raise e | |||
|
|||
|
|||
if __name__ == "__main__": | |||
# execute only if run as a script | |||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
[flake8] | |||
|
|||
# Plugins | |||
use-flake8-tabs = True | |||
use-pycodestyle-indent = True | |||
|
|||
# Reporting | |||
statistics = True | |||
doctests = True | |||
show-source = True | |||
|
|||
# Options | |||
max-complexity = 15 | |||
max-line-length = 110 | |||
hang-closing = True | |||
|
|||
ignore = | |||
W191, # indentation contains tabs | |||
E126, # continuation line over-indented for hanging indent | |||
E133, # closing bracket is missing indentation | |||
W503, # line break before binary operator. As opposed to W504 (line break after binary operator) which we want to check for. | |||
|
|||
builtins = # inform flake8 about functions we consider built-in. | |||
_, # translation lookup | |||
pgettext, # translation lookup | |||
|
|||
exclude = # don't bother looking in the following subdirectories / files. | |||
.git, | |||
__pycache__, | |||
.tox, | |||
build, | |||
output, | |||
include, | |||
miscDeps, | |||
source/louis, |
Oops, something went wrong.