Skip to content

Commit

Permalink
Merge pull request #654 from ddalcino/improve-combination-warnings
Browse files Browse the repository at this point in the history
Improve combination warnings
  • Loading branch information
miurahr authored Feb 17, 2023
2 parents 030b428 + 265c95d commit 15d9927
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
40 changes: 26 additions & 14 deletions aqt/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ def _check_qt_arg_versions(self, version):
def _check_qt_arg_version_offline(self, version):
return version in Settings.available_offline_installer_version

def _warning_unknown_qt_version(self, qt_version: str) -> str:
return self._warning_on_bad_combination(f'Qt version "{qt_version}"')

def _warning_unknown_target_arch_combo(self, args: List[str]) -> str:
return self._warning_on_bad_combination(f"target combination \"{' '.join(args)}\"")

def _warning_unexpected_modules(self, unexpected_modules: List[str]) -> str:
return self._warning_on_bad_combination(f"modules {unexpected_modules}")

def _warning_on_bad_combination(self, combo_message: str) -> str:
return (
f"Specified {combo_message} did not exist when this version of aqtinstall was released. "
"This may not install properly, but we will try our best."
)

def _set_sevenzip(self, external):
sevenzip = external
if sevenzip is None:
Expand Down Expand Up @@ -257,13 +272,10 @@ def _check_mirror(self, mirror):
return False
return True

def _check_modules_arg(self, qt_version, modules):
if modules is None:
return True
def _select_unexpected_modules(self, qt_version: str, modules: Optional[List[str]]) -> List[str]:
"""Returns a sorted list of all the requested modules that do not exist in the combinations.json file."""
available = Settings.available_modules(qt_version)
if available is None:
return False
return all([m in available for m in modules])
return sorted(set(modules or []) - set(available or []))

@staticmethod
def _determine_qt_version(
Expand Down Expand Up @@ -388,14 +400,14 @@ def to_archives(baseurl: str) -> QtArchives:
auto_desktop_archives: List[QtPackage] = get_auto_desktop_archives()

if not self._check_qt_arg_versions(qt_version):
self.logger.warning("Specified Qt version is unknown: {}.".format(qt_version))
self.logger.warning(self._warning_unknown_qt_version(qt_version))
if not self._check_qt_arg_combination(qt_version, os_name, target, arch):
self.logger.warning(
"Specified target combination is not valid or unknown: {} {} {}".format(os_name, target, arch)
)
self.logger.warning(self._warning_unknown_target_arch_combo([os_name, target, arch]))
all_extra = True if modules is not None and "all" in modules else False
if not all_extra and not self._check_modules_arg(qt_version, modules):
self.logger.warning("Some of specified modules are unknown.")
if not all_extra:
unexpected_modules = self._select_unexpected_modules(qt_version, modules)
if unexpected_modules:
self.logger.warning(self._warning_unexpected_modules(unexpected_modules))

qt_archives: QtArchives = retry_on_bad_connection(
lambda base_url: QtArchives(
Expand Down Expand Up @@ -465,7 +477,7 @@ def _run_src_doc_examples(self, flavor, args, cmd_name: Optional[str] = None):
archives = args.archives
all_extra = True if modules is not None and "all" in modules else False
if not self._check_qt_arg_versions(qt_version):
self.logger.warning("Specified Qt version is unknown: {}.".format(qt_version))
self.logger.warning(self._warning_unknown_qt_version(qt_version))

srcdocexamples_archives: SrcDocExamplesArchives = retry_on_bad_connection(
lambda base_url: SrcDocExamplesArchives(
Expand Down Expand Up @@ -562,7 +574,7 @@ def run_install_tool(self, args: InstallToolArgParser):

for arch in archs:
if not self._check_tools_arg_combination(os_name, tool_name, arch):
self.logger.warning("Specified target combination is not valid: {} {} {}".format(os_name, tool_name, arch))
self.logger.warning(self._warning_unknown_target_arch_combo([os_name, tool_name, arch]))

tool_archives: ToolArchives = retry_on_bad_connection(
lambda base_url: ToolArchives(
Expand Down
20 changes: 15 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ def test_cli_help(capsys):
assert expected_help(out)


def test_cli_check_module():
@pytest.mark.parametrize(
"qt_version, modules, unexpected_modules",
(
("5.11.3", ["qtcharts", "qtwebengine"], []),
("5.11.3", ["not_exist"], ["not_exist"]),
("5.11.3", ["qtcharts", "qtwebengine", "not_exist"], ["not_exist"]),
("5.11.3", None, []),
("5.15.0", ["Unknown"], ["Unknown"]),
),
)
def test_cli_select_unexpected_modules(qt_version: str, modules: Optional[List[str]], unexpected_modules: List[str]):
cli = Cli()
cli._setup_settings()
assert cli._check_modules_arg("5.11.3", ["qtcharts", "qtwebengine"])
assert not cli._check_modules_arg("5.7", ["not_exist"])
assert cli._check_modules_arg("5.14.0", None)
assert not cli._check_modules_arg("5.15.0", ["Unknown"])
assert cli._select_unexpected_modules(qt_version, modules) == unexpected_modules

nonexistent_qt = "5.16.0"
assert cli._select_unexpected_modules(nonexistent_qt, modules) == sorted(modules or [])


def test_cli_check_combination():
Expand Down
15 changes: 10 additions & 5 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,23 +1052,26 @@ def test_install(
(
"install-qt windows desktop 5.16.0 win32_mingw73",
None,
"WARNING : Specified Qt version is unknown: 5.16.0.\n"
'WARNING : Specified Qt version "5.16.0" did not exist when this version of aqtinstall was released. '
"This may not install properly, but we will try our best.\n"
"ERROR : Failed to locate XML data for Qt version '5.16.0'.\n"
"==============================Suggested follow-up:==============================\n"
"* Please use 'aqt list-qt windows desktop' to show versions available.\n",
),
(
"install-qt windows desktop 5.15.0 bad_arch",
"windows-5150-update.xml",
"WARNING : Specified target combination is not valid or unknown: windows desktop bad_arch\n"
'WARNING : Specified target combination "windows desktop bad_arch" did not exist when this version of '
"aqtinstall was released. This may not install properly, but we will try our best.\n"
"ERROR : The packages ['qt_base'] were not found while parsing XML of package information!\n"
"==============================Suggested follow-up:==============================\n"
"* Please use 'aqt list-qt windows desktop --arch 5.15.0' to show architectures available.\n",
),
(
"install-qt windows desktop 5.15.0 win32_mingw73 -m nonexistent foo",
"windows-5150-update.xml",
"WARNING : Some of specified modules are unknown.\n"
"WARNING : Specified modules ['foo', 'nonexistent'] did not exist when this version of aqtinstall "
"was released. This may not install properly, but we will try our best.\n"
"ERROR : The packages ['foo', 'nonexistent', 'qt_base'] were not found"
" while parsing XML of package information!\n"
"==============================Suggested follow-up:==============================\n"
Expand Down Expand Up @@ -1106,15 +1109,17 @@ def test_install(
(
"install-tool windows desktop tools_vcredist nonexistent",
"windows-desktop-tools_vcredist-update.xml",
"WARNING : Specified target combination is not valid: windows tools_vcredist nonexistent\n"
'WARNING : Specified target combination "windows tools_vcredist nonexistent" did not exist when this version of '
"aqtinstall was released. This may not install properly, but we will try our best.\n"
"ERROR : The package 'nonexistent' was not found while parsing XML of package information!\n"
"==============================Suggested follow-up:==============================\n"
"* Please use 'aqt list-tool windows desktop tools_vcredist' to show tool variants available.\n",
),
(
"install-tool windows desktop tools_nonexistent nonexistent",
None,
"WARNING : Specified target combination is not valid: windows tools_nonexistent nonexistent\n"
'WARNING : Specified target combination "windows tools_nonexistent nonexistent" did not exist when this '
"version of aqtinstall was released. This may not install properly, but we will try our best.\n"
"ERROR : Failed to locate XML data for the tool 'tools_nonexistent'.\n"
"==============================Suggested follow-up:==============================\n"
"* Please use 'aqt list-tool windows desktop' to show tools available.\n",
Expand Down

0 comments on commit 15d9927

Please sign in to comment.