CMake: pro2cmake: Fix errors reported by flake8 and mypy

Change-Id: I842c0f8d7ec1d173fa1dbd74e769e2c370e70518
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alexandru Croitor 2020-07-30 15:56:37 +02:00
parent ca103f357c
commit 4ed483b0e2
5 changed files with 18 additions and 19 deletions

View File

@ -11,7 +11,7 @@ black_format_check:
black *.py --line-length 100 --check black *.py --line-length 100 --check
flake8: flake8:
flake8 *.py --ignore=E501,E266,E203,W503 flake8 *.py --ignore=E501,E266,E203,W503,F541
pytest: pytest:
pytest pytest

View File

@ -586,7 +586,7 @@ qt_config_compile_test("{config_test_name}"
if packages: if packages:
packages_string = " ".join(packages) packages_string = " ".join(packages)
cm_fh.write(f" PACKAGES {packages_string}") cm_fh.write(f" PACKAGES {packages_string}")
cm_fh.write(f")\n") cm_fh.write(")\n")
def write_compile_test( def write_compile_test(
@ -1205,7 +1205,7 @@ def processSummaryHelper(ctx, entries, cm_fh):
entry_args_string = "".join(function_args) entry_args_string = "".join(function_args)
cm_fh.write(f"qt_configure_add_summary_entry(\n{entry_args_string})\n") cm_fh.write(f"qt_configure_add_summary_entry(\n{entry_args_string})\n")
elif "type" in entry and entry["type"] == "buildTypeAndConfig": elif "type" in entry and entry["type"] == "buildTypeAndConfig":
cm_fh.write(f"qt_configure_add_summary_build_type_and_config()\n") cm_fh.write("qt_configure_add_summary_build_type_and_config()\n")
elif "type" in entry and entry["type"] == "buildMode": elif "type" in entry and entry["type"] == "buildMode":
message = entry["message"] message = entry["message"]
cm_fh.write(f"qt_configure_add_summary_build_mode({message})\n") cm_fh.write(f"qt_configure_add_summary_build_mode({message})\n")

View File

@ -760,12 +760,12 @@ def generate_find_package_info(
if cmake_target_name.endswith("_nolink") or cmake_target_name.endswith("/nolink"): if cmake_target_name.endswith("_nolink") or cmake_target_name.endswith("/nolink"):
cmake_target_name = cmake_target_name[:-7] cmake_target_name = cmake_target_name[:-7]
initial_package_name = lib.packageName initial_package_name: str = lib.packageName if lib.packageName else ""
package_name = initial_package_name package_name: str = initial_package_name
if use_system_package_name: if use_system_package_name:
replace_args = ["Wrap", "WrapSystem"] replace_args = ["Wrap", "WrapSystem"]
package_name = package_name.replace(*replace_args) package_name = package_name.replace(*replace_args) # type: ignore
cmake_target_name = cmake_target_name.replace(*replace_args) cmake_target_name = cmake_target_name.replace(*replace_args) # type: ignore
if use_qt_find_package: if use_qt_find_package:
if cmake_target_name: if cmake_target_name:

View File

@ -50,7 +50,6 @@ import xml.etree.ElementTree as ET
from argparse import ArgumentParser from argparse import ArgumentParser
from textwrap import dedent from textwrap import dedent
from textwrap import indent as textwrap_indent
from functools import lru_cache from functools import lru_cache
from shutil import copyfile from shutil import copyfile
from collections import defaultdict from collections import defaultdict
@ -548,7 +547,7 @@ def write_add_qt_resource_call(
" PROPERTIES QT_SKIP_QUICKCOMPILER 1)\n\n" " PROPERTIES QT_SKIP_QUICKCOMPILER 1)\n\n"
) )
prefix_expanded = scope.expandString(prefix) prefix_expanded = scope.expandString(str(prefix))
if prefix_expanded: if prefix_expanded:
prefix = prefix_expanded prefix = prefix_expanded
params = "" params = ""
@ -1478,7 +1477,7 @@ def unwrap_if(input_string):
# Compute the grammar only once. # Compute the grammar only once.
if not hasattr(unwrap_if, "if_grammar"): if not hasattr(unwrap_if, "if_grammar"):
def handle_expr_with_parentheses(s, l, t): def handle_expr_with_parentheses(s, l_unused, t):
# The following expression unwraps the condition via the # The following expression unwraps the condition via the
# additional info set by originalTextFor, thus returning the # additional info set by originalTextFor, thus returning the
# condition without parentheses. # condition without parentheses.
@ -3270,7 +3269,7 @@ def write_generic_library(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> s
return target_name return target_name
def forward_target_info(scope: Scope, extra: [str], skip: Optional[Dict[str]] = None): def forward_target_info(scope: Scope, extra: List[str], skip: Optional[Dict[str, bool]] = None):
s = scope.get_string("QMAKE_TARGET_PRODUCT") s = scope.get_string("QMAKE_TARGET_PRODUCT")
if s: if s:
extra.append(f'TARGET_PRODUCT "{s}"') extra.append(f'TARGET_PRODUCT "{s}"')
@ -3349,7 +3348,7 @@ def write_module(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
return target_name return target_name
def write_tool(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str: def write_tool(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> Tuple[str, str]:
tool_name = scope.TARGET tool_name = scope.TARGET
if "force_bootstrap" in scope.get("CONFIG"): if "force_bootstrap" in scope.get("CONFIG"):
@ -3380,7 +3379,7 @@ def write_tool(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
def write_qt_app(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str: def write_qt_app(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
app_name = scope.TARGET app_name = scope.TARGET
extra = [] extra: List[str] = []
target_info_skip = {} target_info_skip = {}
target_info_skip["QMAKE_TARGET_DESCRIPTION"] = True target_info_skip["QMAKE_TARGET_DESCRIPTION"] = True
@ -3493,8 +3492,8 @@ def write_find_package_section(
packages = [] # type: List[LibraryMapping] packages = [] # type: List[LibraryMapping]
all_libs = public_libs + private_libs all_libs = public_libs + private_libs
for l in all_libs: for one_lib in all_libs:
info = find_library_info_for_target(l) info = find_library_info_for_target(one_lib)
if info and info not in packages: if info and info not in packages:
packages.append(info) packages.append(info)
@ -4154,7 +4153,7 @@ def create_top_level_cmake_conf():
try: try:
with open(conf_file_name, "x") as file: with open(conf_file_name, "x") as file:
file.write('set(QT_REPO_MODULE_VERSION "6.0.0")\n') file.write('set(QT_REPO_MODULE_VERSION "6.0.0")\n')
except FileExistsError as _: except FileExistsError:
pass pass

View File

@ -71,9 +71,9 @@ def fixup_comments(contents: str) -> str:
return contents return contents
def flatten_list(l): def flatten_list(input_list):
""" Flattens an irregular nested list into a simple list.""" """ Flattens an irregular nested list into a simple list."""
for el in l: for el in input_list:
if isinstance(el, collections.abc.Iterable) and not isinstance(el, (str, bytes)): if isinstance(el, collections.abc.Iterable) and not isinstance(el, (str, bytes)):
yield from flatten_list(el) yield from flatten_list(el)
else: else:
@ -227,7 +227,7 @@ class QmakeParser:
Option = add_element("Option", pp.Keyword("option") + CallArgs("option")) Option = add_element("Option", pp.Keyword("option") + CallArgs("option"))
RequiresCondition = add_element("RequiresCondition", pp.originalTextFor(pp.nestedExpr())) RequiresCondition = add_element("RequiresCondition", pp.originalTextFor(pp.nestedExpr()))
def parse_requires_condition(s, l, t): def parse_requires_condition(s, l_unused, t):
# The following expression unwraps the condition via the additional info # The following expression unwraps the condition via the additional info
# set by originalTextFor. # set by originalTextFor.
condition_without_parentheses = s[t._original_start + 1 : t._original_end - 1] condition_without_parentheses = s[t._original_start + 1 : t._original_end - 1]