From 57cb42861d37eec074a729f33d1c5aa90be86b3f Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Thu, 30 Mar 2023 05:06:01 +0000 Subject: [PATCH] run_tests: Check flake8 This also gets enforced in CQ. Bug: b/267675342 Change-Id: I8ffcc5d583275072fd61ae65ae4214b36bfa59f3 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/366799 Tested-by: Gavin Mak Reviewed-by: Mike Frysinger Commit-Queue: Gavin Mak --- run_tests | 26 +++++++++++++++++++------- run_tests.vpython3 | 23 +++++++++++++++++++++++ tox.ini | 1 + 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/run_tests b/run_tests index 69ba2769..2d92cae3 100755 --- a/run_tests +++ b/run_tests @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Wrapper to run black and pytest with the right settings.""" +"""Wrapper to run linters and pytest with the right settings.""" import os import subprocess @@ -21,19 +21,31 @@ import sys import pytest +ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) + + def run_black(): - """Returns the exit code of running `black --check`.""" - dirpath = os.path.dirname(os.path.realpath(__file__)) + """Returns the exit code from black.""" return subprocess.run( - [sys.executable, "-m", "black", "--check", dirpath], check=False + [sys.executable, "-m", "black", "--check", ROOT_DIR], check=False + ).returncode + + +def run_flake8(): + """Returns the exit code from flake8.""" + return subprocess.run( + [sys.executable, "-m", "flake8", ROOT_DIR], check=False ).returncode def main(argv): """The main entry.""" - pytest_ret = pytest.main(argv) - black_ret = run_black() - return 0 if not black_ret and not pytest_ret else 1 + checks = ( + lambda: pytest.main(argv), + run_black, + run_flake8, + ) + return 0 if all(not c() for c in checks) else 1 if __name__ == "__main__": diff --git a/run_tests.vpython3 b/run_tests.vpython3 index 0c790bca..3d0cd78e 100644 --- a/run_tests.vpython3 +++ b/run_tests.vpython3 @@ -100,3 +100,26 @@ wheel: < name: "infra/python/wheels/click-py3" version: "version:8.0.3" > + +wheel: < + name: "infra/python/wheels/flake8-py2_py3" + version: "version:6.0.0" +> + +# Required by flake8==6.0.0 +wheel: < + name: "infra/python/wheels/mccabe-py2_py3" + version: "version:0.7.0" +> + +# Required by flake8==6.0.0 +wheel: < + name: "infra/python/wheels/pyflakes-py2_py3" + version: "version:3.0.1" +> + +# Required by flake8==6.0.0 +wheel: < + name: "infra/python/wheels/pycodestyle-py2_py3" + version: "version:2.10.0" +> diff --git a/tox.ini b/tox.ini index 2575a713..ccf2ffff 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,7 @@ python = [testenv] deps = black + flake8 pytest pytest-timeout commands = {envpython} run_tests {posargs}