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 <gavinmak@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Gavin Mak 2023-03-30 05:06:01 +00:00 committed by LUCI
parent e74d9046ee
commit 57cb42861d
3 changed files with 43 additions and 7 deletions

View File

@ -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__":

View File

@ -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"
>

View File

@ -28,6 +28,7 @@ python =
[testenv]
deps =
black
flake8
pytest
pytest-timeout
commands = {envpython} run_tests {posargs}