Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle cases where extensions don't exist. #852

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions aqt/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,21 +438,33 @@ def _get_archives_base(self, name, target_packages):
"online/qtsdkrepository", os_name, "extensions", ext, self._version_str(), arch
)
extensions_xml_url = posixpath.join(extensions_target_folder, "Updates.xml")
extensions_xml_text = self._download_update_xml(extensions_xml_url)
update_xmls.append(UpdateXmls(extensions_target_folder, extensions_xml_text))
# The extension may or may not exist for this version and arch.
try:
extensions_xml_text = self._download_update_xml(extensions_xml_url, True)
except ArchiveDownloadError:
# In case _download_update_xml ignores the hash and tries to get the url.
pass
if extensions_xml_text:
self.logger.info("Found extension {}".format(ext))
update_xmls.append(UpdateXmls(extensions_target_folder, extensions_xml_text))

self._parse_update_xmls(update_xmls, target_packages)

def _download_update_xml(self, update_xml_path):
def _download_update_xml(self, update_xml_path, silent=False):
"""Hook for unit test."""
if not Settings.ignore_hash:
try:
xml_hash = get_hash(update_xml_path, Settings.hash_algorithm, self.timeout)
except ChecksumDownloadFailure:
self.logger.warning(
"Failed to download checksum for the file 'Updates.xml'. This may happen on unofficial mirrors."
)
xml_hash = None
if silent:
return None
else:
self.logger.warning(
"Failed to download checksum for the file '{}'. This may happen on unofficial mirrors.".format(
update_xml_path
)
)
xml_hash = None
else:
xml_hash = None
return getUrl(posixpath.join(self.base, update_xml_path), self.timeout, xml_hash)
Expand Down
37 changes: 31 additions & 6 deletions aqt/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
from semantic_version import Version as SemanticVersion
from texttable import Texttable

from aqt.exceptions import ArchiveConnectionError, ArchiveDownloadError, ArchiveListError, CliInputError, EmptyMetadata
from aqt.exceptions import (
ArchiveConnectionError,
ArchiveDownloadError,
ArchiveListError,
ChecksumDownloadFailure,
CliInputError,
EmptyMetadata,
)
from aqt.helper import Settings, get_hash, getUrl, xml_to_modules


Expand Down Expand Up @@ -556,6 +563,12 @@ def is_in_wasm_range(host: str, version: Version) -> bool:
def is_in_wasm_threaded_range(version: Version) -> bool:
return version in SimpleSpec(">=6.5.0")

@staticmethod
def known_extensions(version: Version) -> List[str]:
if version >= Version("6.8.0"):
return ["qtpdf", "qtwebengine"]
return []


class MetadataFactory:
"""Retrieve metadata of Qt variations, versions, and descriptions from Qt site."""
Expand Down Expand Up @@ -886,9 +899,19 @@ def to_module_arch(name: str) -> Tuple[Optional[str], Optional[str]]:
module, _arch = to_module_arch(name)
if _arch == arch:
modules.add(cast(str, module))
if version >= Version("6.8.0"):
for ext in self.fetch_extensions():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch_extensions is no longer used.

modules.add(ext)

ext_pattern = re.compile(r"^extensions\." + r"(?P<module>[^.]+)\." + qt_ver_str + r"\." + arch + r"$")
for ext in QtRepoProperty.known_extensions(version):
try:
ext_meta = self._fetch_extension_metadata(self.archive_id.to_extension_folder(ext, qt_ver_str, arch))
for key, value in ext_meta.items():
ext_match = ext_pattern.match(key)
if ext_match is not None:
module = ext_match.group("module")
if module is not None:
modules.add(ext)
except (ChecksumDownloadFailure, ArchiveDownloadError):
pass
return sorted(modules)

@staticmethod
Expand Down Expand Up @@ -930,15 +953,17 @@ def matches_arch(element: Element) -> bool:
# Examples: extensions.qtwebengine.680.debug_information
# extensions.qtwebengine.680.win64_msvc2022_64
ext_pattern = re.compile(r"^extensions\." + r"(?P<module>[^.]+)\." + qt_ver_str + r"\." + arch + r"$")
if version >= Version("6.8.0"):
for ext in self.fetch_extensions():
for ext in QtRepoProperty.known_extensions(version):
try:
ext_meta = self._fetch_extension_metadata(self.archive_id.to_extension_folder(ext, qt_ver_str, arch))
for key, value in ext_meta.items():
ext_match = ext_pattern.match(key)
if ext_match is not None:
module = ext_match.group("module")
if module is not None:
m[module] = value
except (ChecksumDownloadFailure, ArchiveDownloadError):
pass
return ModuleData(m)

def fetch_modules_sde(self, cmd_type: str, version: Version) -> List[str]:
Expand Down
Loading