diff options
author | Gavin Mak <gavinmak@google.com> | 2023-03-11 06:46:20 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-22 17:46:28 +0000 |
commit | ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch) | |
tree | dc33ba0e56825b3e007d0589891756724725a465 /run_tests | |
parent | 1604cf255f8c1786a23388db6d5277ac7949a24a (diff) | |
download | git-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz |
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught
by flake8. Also check black formatting in run_tests (and CQ).
Bug: b/267675342
Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'run_tests')
-rwxr-xr-x | run_tests | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -13,10 +13,28 @@ | |||
13 | # See the License for the specific language governing permissions and | 13 | # See the License for the specific language governing permissions and |
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | """Wrapper to run pytest with the right settings.""" | 16 | """Wrapper to run black and pytest with the right settings.""" |
17 | 17 | ||
18 | import os | ||
19 | import subprocess | ||
18 | import sys | 20 | import sys |
19 | import pytest | 21 | import pytest |
20 | 22 | ||
21 | if __name__ == '__main__': | 23 | |
22 | sys.exit(pytest.main(sys.argv[1:])) | 24 | def run_black(): |
25 | """Returns the exit code of running `black --check`.""" | ||
26 | dirpath = os.path.dirname(os.path.realpath(__file__)) | ||
27 | return subprocess.run( | ||
28 | [sys.executable, "-m", "black", "--check", dirpath], check=False | ||
29 | ).returncode | ||
30 | |||
31 | |||
32 | def main(argv): | ||
33 | """The main entry.""" | ||
34 | black_ret = 0 if argv else run_black() | ||
35 | pytest_ret = pytest.main(argv) | ||
36 | return 0 if not black_ret and not pytest_ret else 1 | ||
37 | |||
38 | |||
39 | if __name__ == "__main__": | ||
40 | sys.exit(main(sys.argv[1:])) | ||