Skip to content

Lint with flake8#9958

Merged
feerrenrut merged 22 commits into
masterfrom
lint-withFlake8
Aug 1, 2019
Merged

Lint with flake8#9958
feerrenrut merged 22 commits into
masterfrom
lint-withFlake8

Conversation

@feerrenrut

@feerrenrut feerrenrut commented Jul 22, 2019

Copy link
Copy Markdown
Contributor

Link to issue number:

Closes #5918

Summary of the issue:

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.

Description of how this pull request fixes the issue:

Automate checking 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.

This pr introduces 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:

  • 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.

Testing performed:

Tested locally:

  • Enured that uncommited and unstaged changes in the working tree are included in diff given to Flake8
  • Checked that #noqa: <code> comments work to suppress errors.

Tested on appveyor:

Known issues with pull request:

  • Add documentation to readme.
  • Test file to demonstrate, needs removal.
  • Using --disable-noqa to demonstrate test file, needs removal
  • Alters the users installed packages, see lintInstall
  • Requires git in path.

Change log entry:

Changes for developers:
- Flake8 linting tool has been integrated with SCons reflecting code requirements for Pull Requests. (#5918)

Uses flake8-tabs so that we can use tab rather than spaces.
Includes a default config file for flake8 (flake8.ini)

Scons build targets added:

lint:
	Produces a unified diff (against HEAD), and runs flake8 linter against this diff.
lintInstall:
	Uses pip (and a requirements file) to install flake8 dependency.

A file test.py is included as a demonstration, this will be removed prior to merging.
Test result must be converted to junit compatible xml.
We do a shallow clone when initially fetching the repo, so we need to get the base branch as well now.

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware of this still being a draft, but I'm pretty interested to see this finished.

Comment thread tests/lint/createJunitReport.py Outdated
Comment thread tests/lint/flake8.ini
Comment thread tests/lint/sconscript Outdated
@LeonarddeR

Copy link
Copy Markdown
Collaborator

I have the following suggestions for the configuration of flake8:

  • Add --count parameter to see number of errors
  • add miscDeps and source\louis to exclude
  • Add doctests = True

@feerrenrut

Copy link
Copy Markdown
Contributor Author

Add --count parameter to see number of errors

count is not so helpful, we already print statistics (giving the number of each error that occurred), count prints an extra number. See the last "1" in the following example output:

tests/lint/createJunitReport.py:44:1: E302 expected 2 blank lines, found 1
def main():
^
1     E302 expected 2 blank lines, found 1
1

@LeonarddeR

Copy link
Copy Markdown
Collaborator

@feerrenrut commented on 24 Jul 2019, 19:31 CEST:

Add --count parameter to see number of errors

count is not so helpful, we already print statistics (giving the number of each error that occurred), count prints an extra number. See the last "1" in the following example output:

tests/lint/createJunitReport.py:44:1: E302 expected 2 blank lines, found 1
def main():
^
1     E302 expected 2 blank lines, found 1
1

Ah, I had hoped that it was more descriptive. Never mind.

Comment thread appveyor.yml Outdated
Comment thread appveyor.yml Outdated
Errors should not be raised for adjacent code.
@AppVeyorBot

This comment has been minimized.

@AppVeyorBot

This comment has been minimized.

@AppVeyorBot

This comment has been minimized.

@AppVeyorBot

This comment has been minimized.

@AppVeyorBot

Copy link
Copy Markdown

PR introduces Flake8 errors 😲

See test results for Failed build of commit 02b3346201

Comment thread tests/lint/sconscript Outdated
Comment thread tests/lint/sconscript Outdated
feerrenrut and others added 2 commits July 25, 2019 22:30
Co-Authored-By: Leonard de Ruijter <leonardder@users.noreply.github.com>
Co-Authored-By: Leonard de Ruijter <leonardder@users.noreply.github.com>
@AppVeyorBot

Copy link
Copy Markdown

PR introduces Flake8 errors 😲

See test results for Failed build of commit 0def0c5900

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Testing with flake8 within VS Code reveals that it raises warnings for using _ and pgettext. I'm afraid this will also be the case for appveyor builds. It is likelike that scons has sourceEnv imported before it uses flake8

@feerrenrut

Copy link
Copy Markdown
Contributor Author

Are you using the config file from this PR?

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Ah I'm sorr, turns out that I was using an out of date version of the branch for my testing purposes.

@AppVeyorBot

Copy link
Copy Markdown

PR introduces Flake8 errors 😲

See test results for Failed build of commit dfe787d60b

@AppVeyorBot

Copy link
Copy Markdown

PR introduces Flake8 errors 😲

See test results for Failed build of commit 931f1598d7

Remove --disable-noqa
Remove test.py full of # noqa: comments
@feerrenrut feerrenrut marked this pull request as ready for review July 30, 2019 18:44
@feerrenrut feerrenrut requested a review from LeonarddeR July 30, 2019 18:54
W503 is: line break before binary operator.
Contrasted with W504: line break after binary operator, which we want to check for.

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to remove source/pylintrc while at it. According to @bramd, it has its issues anyway.

# 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an empty line above this line?

Comment thread tests/lint/createJunitReport.py
Comment thread appveyor.yml
Comment thread tests/lint/flake8.ini
Comment thread tests/lint/genDiff.py Outdated
Comment thread tests/lint/genDiff.py
Comment thread tests/lint/lintInstall/requirements.txt Outdated
Comment thread tests/lint/sconscript
Comment thread tests/lint/sconscript
feerrenrut and others added 2 commits August 1, 2019 15:30
Allow automatic changes to minor versions.

Co-Authored-By: Leonard de Ruijter <leonardder@users.noreply.github.com>
@LeonarddeR

Copy link
Copy Markdown
Collaborator

Note that the base of this is still threshold.

@feerrenrut

Copy link
Copy Markdown
Contributor Author

Note that the base of this is still threshold.

Thanks 👍

@feerrenrut feerrenrut changed the base branch from threshold to master August 1, 2019 14:57
@feerrenrut feerrenrut merged commit e68ce2d into master Aug 1, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Aug 1, 2019
feerrenrut added a commit that referenced this pull request Aug 1, 2019
@josephsl

josephsl commented Aug 2, 2019

Copy link
Copy Markdown
Contributor

Hi,

Coming back to this, I think it would be helpful to exclude checks for visual indents; although useful, it has drawbacks:

  1. Some text editors may not expose indentation formatting correctly, leading some to believe the code has been indented when it didn't.
  2. It produces E101 (mixture of tabs and spaces). For long lines, it can cause line length issue to pop up.
  3. For long conditional statements, splitting it into multiple lines may introduce more errors than intended, and without wrapping them inside parentheses, syntax error (E999) is raised.

I'll create a new issue to discuss these further.

Thanks.

@feerrenrut

Copy link
Copy Markdown
Contributor Author

@josephsl we have a few issues to work through with the indentation checks, but I would really like it if we can find an acceptable configuration. This will likely require people to think about the configuration of their tools.

@josephsl

josephsl commented Aug 2, 2019 via email

Copy link
Copy Markdown
Contributor

@bedenhofer bedenhofer mentioned this pull request Aug 10, 2019
@michaelDCurran

Copy link
Copy Markdown
Member

This pr breaks publishing of NVDA releases on our server. I was able to work around this for beta1, but this certainly needs to be addressed for the final release.
In appveyor.yaml, commands in deploy_script make use of the $artifacts variable, which is set by appveyor based on pushed artifacts. However, pushing of artifacts in the output directory, including the NVDA launcher executable, had been moved to the on_finish section, which is run after deploy_script, thus $artifacts does not contain them. Uploading of the output directory really needs to be done probably at the end of build_script.

@feerrenrut feerrenrut deleted the lint-withFlake8 branch January 17, 2020 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scons lint

6 participants