diff options
author | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2019-09-17 00:11:17 +0200 |
---|---|---|
committer | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2019-09-18 12:00:26 +0000 |
commit | 91634c3c9b8d4f68f0ebd2ac76a8b5b79e4b4c94 (patch) | |
tree | dc1913a6a30f886813901f9584221c1f37fa3c22 /util/cmake/cmakeconversionrate.py | |
parent | c1cf305be0f1f529b96a06dc70ce5ee7273006ef (diff) |
Improve styling of util/cmake scripts
flake8 was used to evaluate the file, with a couple of exeptions:
E501,E266,W503
black was used to reformat the code automatically
The changes were:
* Added a README that explains how to use pipenv and pip,
* Remove unnecessary return statements,
* Remove '\' from the end of the lines,
* Use f-strings (>= 3.6) since we are requiring Python 3.7,
* Commenting unused variables,
* Adding assert when Python >= 3.7 is not being used,
* Wrapping long lines to 100 (Qt Style),
* Re-factoring some lines,
* Re-ordering imports,
* Naming `except` for sympy (SympifyError, TypeError)
Change-Id: Ie05f754e7d8ee4bf427117c58e0eb1b903202933
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'util/cmake/cmakeconversionrate.py')
-rwxr-xr-x | util/cmake/cmakeconversionrate.py | 84 |
1 files changed, 49 insertions, 35 deletions
diff --git a/util/cmake/cmakeconversionrate.py b/util/cmake/cmakeconversionrate.py index 3496ed1b91..b87957df6c 100755 --- a/util/cmake/cmakeconversionrate.py +++ b/util/cmake/cmakeconversionrate.py @@ -32,27 +32,37 @@ from argparse import ArgumentParser import os import re import subprocess -import sys import typing def _parse_commandline(): - parser = ArgumentParser(description='Calculate the conversion rate to cmake.') - parser.add_argument('--debug', dest='debug', action='store_true', - help='Turn on debug output') - parser.add_argument('source_directory', metavar='<Source Directory>', type=str, - help='The Qt module source directory') - parser.add_argument('binary_directory', metavar='<CMake build direcotry>', type=str, - help='The CMake build directory (might be empty)') + parser = ArgumentParser(description="Calculate the conversion rate to cmake.") + parser.add_argument("--debug", dest="debug", action="store_true", help="Turn on debug output") + parser.add_argument( + "source_directory", + metavar="<Source Directory>", + type=str, + help="The Qt module source directory", + ) + parser.add_argument( + "binary_directory", + metavar="<CMake build direcotry>", + type=str, + help="The CMake build directory (might be empty)", + ) return parser.parse_args() -def calculate_baseline(source_directory: str, *, debug: bool=False) -> int: +def calculate_baseline(source_directory: str, *, debug: bool = False) -> int: if debug: - print('Scanning "{}" for qmake-based tests.'.format(source_directory)) - result = subprocess.run('/usr/bin/git grep -E "^\\s*CONFIG\\s*\\+?=.*\\btestcase\\b" | sort -u | wc -l', - shell=True, capture_output=True, cwd=source_directory) + print(f'Scanning "{source_directory}" for qmake-based tests.') + result = subprocess.run( + '/usr/bin/git grep -E "^\\s*CONFIG\\s*\\+?=.*\\btestcase\\b" | sort -u | wc -l', + shell=True, + capture_output=True, + cwd=source_directory, + ) return int(result.stdout) @@ -60,41 +70,45 @@ def build(source_directory: str, binary_directory: str, *, debug=False) -> None: abs_source = os.path.abspath(source_directory) if not os.path.isdir(binary_directory): os.makedirs(binary_directory) - if not os.path.exists(os.path.join(binary_directory, 'CMakeCache.txt')): + if not os.path.exists(os.path.join(binary_directory, "CMakeCache.txt")): if debug: - print('Running cmake in "{}".'.format(binary_directory)) - result = subprocess.run(['/usr/bin/cmake', '-GNinja', abs_source], cwd=binary_directory) + print(f'Running cmake in "{binary_directory}"') + result = subprocess.run(["/usr/bin/cmake", "-GNinja", abs_source], cwd=binary_directory) if debug: - print('CMake return code: {}.'.format(result.returncode)) + print(f"CMake return code: {result.returncode}.") assert result.returncode == 0 if debug: - print('Running ninja in "{}".'.format(binary_directory)) - result = subprocess.run('/usr/bin/ninja', cwd=binary_directory) + print(f'Running ninja in "{binary_directory}".') + result = subprocess.run("/usr/bin/ninja", cwd=binary_directory) if debug: - print('Ninja return code: {}.'.format(result.returncode)) + print(f"Ninja return code: {result.returncode}.") assert result.returncode == 0 def test(binary_directory: str, *, debug=False) -> typing.Tuple[int, int]: if debug: - print('Running ctest in "{}".'.format(binary_directory)) - result = subprocess.run('/usr/bin/ctest -j 250 | grep "tests passed, "', - shell=True, capture_output=True, cwd=binary_directory) - summary = result.stdout.decode('utf-8').replace('\n', '') + print(f'Running ctest in "{binary_directory}".') + result = subprocess.run( + '/usr/bin/ctest -j 250 | grep "tests passed, "', + shell=True, + capture_output=True, + cwd=binary_directory, + ) + summary = result.stdout.decode("utf-8").replace("\n", "") if debug: - print('Test summary: {} ({}).'.format(summary, result.returncode)) + print(f"Test summary: {summary} ({result.returncode}).") - matches = re.fullmatch(r'\d+% tests passed, (\d+) tests failed out of (\d+)', summary) + matches = re.fullmatch(r"\d+% tests passed, (\d+) tests failed out of (\d+)", summary) if matches: if debug: - print('Matches: failed {}, total {}.'.format(matches.group(1), matches.group(2))) - return (int(matches.group(2)), int(matches.group(2)) - int(matches.group(1)), ) + print(f"Matches: failed {matches.group(1)}, total {matches.group(2)}.") + return (int(matches.group(2)), int(matches.group(2)) - int(matches.group(1))) - return (0, 0,) + return (0, 0) def main() -> int: @@ -102,26 +116,26 @@ def main() -> int: base_line = calculate_baseline(args.source_directory, debug=args.debug) if base_line <= 0: - print('Could not find the qmake baseline in {}.'.format(args.source_directory)) + print(f"Could not find the qmake baseline in {args.source_directory}.") return 1 if args.debug: - print('qmake baseline: {} test binaries.'.format(base_line)) + print(f"qmake baseline: {base_line} test binaries.") cmake_total = 0 cmake_success = 0 try: build(args.source_directory, args.binary_directory, debug=args.debug) - (cmake_total, cmake_success, ) = test(args.binary_directory, debug=args.debug) + (cmake_total, cmake_success) = test(args.binary_directory, debug=args.debug) finally: if cmake_total == 0: - print('\n\n\nCould not calculate the cmake state.') + print("\n\n\nCould not calculate the cmake state.") return 2 else: - print('\n\n\nCMake test conversion rate: {:.2%}.'.format(cmake_total / base_line)) - print('CMake test success rate : {:.2%}.'.format(cmake_success / base_line)) + print(f"\n\n\nCMake test conversion rate: {cmake_total/base_line:.2f}.") + print(f"CMake test success rate : {cmake_success/base_line:.2f}.") return 0 -if __name__ == '__main__': +if __name__ == "__main__": main() |