Version comparison by semantic_version (#263)

* Version comparison by packaging.version

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Use semantic_version instead of packaging.version

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Use more semantic_version

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Fix typo and imports

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Fix missing imports

and fix typo, reduce redundancies.

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* PEP8

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Add 5.12.11 to known version

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2021-06-12 10:46:45 +09:00
committed by GitHub
parent 089b2efdb1
commit fe38fb0e62
5 changed files with 74 additions and 52 deletions

View File

@@ -23,13 +23,15 @@
import xml.etree.ElementTree as ElementTree
from logging import getLogger
from semantic_version import SimpleSpec, Version
from aqt.exceptions import ArchiveListError, NoPackageFound
from aqt.helper import Settings, getUrl
class TargetConfig:
def __init__(self, version, target, arch, os_name):
self.version = version
self.version = str(version)
self.target = target
self.arch = arch
self.os_name = os_name
@@ -66,7 +68,7 @@ class PackagesList:
"""
def __init__(self, version, os_name, target, base, timeout=(5, 5)):
self.version = version
self.version = Version(version)
self.os_name = os_name
self.target = target
self.archives = []
@@ -76,26 +78,21 @@ class PackagesList:
self._get_archives()
def _get_archives(self):
qt_ver_num = self.version.replace(".", "")
self.qt_ver_base = self.version[0:1]
# Get packages index
if self.qt_ver_base == "6" and self.target == "android":
if self.version.major == 6 and self.target == "android":
arch_ext = ["_armv7/", "_x86/", "_x86_64/", "_arm64_v8a/"]
elif (
self.qt_ver_base == "5"
and int(qt_ver_num) >= 5130
and self.target == "desktop"
):
elif self.version in SimpleSpec(">=5.13.0,<6.0") and self.target == "desktop":
arch_ext = ["/", "_wasm/"]
else:
arch_ext = ["/"]
for ext in arch_ext:
archive_path = "{0}{1}{2}/qt{3}_{4}{5}".format(
archive_path = "{0}{1}{2}/qt{3}_{3}{4}{5}{6}".format(
self.os_name,
"_x86/" if self.os_name == "windows" else "_x64/",
self.target,
self.qt_ver_base,
qt_ver_num,
self.version.major,
self.version.minor,
self.version.patch,
ext,
)
update_xml_url = "{0}{1}Updates.xml".format(self.base, archive_path)
@@ -141,7 +138,7 @@ class QtArchives:
all_extra=False,
timeout=(5, 5),
):
self.version = version
self.version = Version(version)
self.target = target
self.arch = arch
self.os_name = os_name
@@ -155,44 +152,66 @@ class QtArchives:
self.logger = getLogger("aqt")
self.archives = []
self.mod_list = []
qt_ver_num = self.version.replace(".", "")
self.qt_ver_base = self.version[0:1]
if all_extra:
self.all_extra = True
else:
for m in modules if modules is not None else []:
self.mod_list.append(
"qt.qt{}.{}.{}.{}".format(self.qt_ver_base, qt_ver_num, m, arch)
"qt.qt{0}.{0}{1}{2}.{3}.{4}".format(
self.version.major,
self.version.minor,
self.version.patch,
m,
arch,
)
)
self.mod_list.append(
"qt.{0}{1}{2}.{3}.{4}".format(
self.version.major,
self.version.minor,
self.version.patch,
m,
arch,
)
)
self.mod_list.append("qt.{}.{}.{}".format(qt_ver_num, m, arch))
self.timeout = timeout
self._get_archives(qt_ver_num)
self._get_archives()
if not all_archives:
self.archives = list(filter(lambda a: a.name in subarchives, self.archives))
def _get_archives(self, qt_ver_num):
def _get_archives(self):
# Get packages index
if self.arch == "wasm_32":
arch_ext = "_wasm"
elif self.arch.startswith("android_") and qt_ver_num[0:1] == "6":
elif self.arch.startswith("android_") and self.version.major == 6:
arch_ext = "{}".format(self.arch[7:])
else:
arch_ext = ""
archive_path = "{0}{1}{2}/qt{3}_{4}{5}/".format(
archive_path = "{0}{1}{2}/qt{3}_{3}{4}{5}{6}/".format(
self.os_name,
"_x86/" if self.os_name == "windows" else "_x64/",
self.target,
self.qt_ver_base,
qt_ver_num,
self.version.major,
self.version.minor,
self.version.patch,
arch_ext,
)
update_xml_url = "{0}{1}Updates.xml".format(self.base, archive_path)
archive_url = "{0}{1}".format(self.base, archive_path)
target_packages = []
target_packages.append(
"qt.qt{}.{}.{}".format(self.qt_ver_base, qt_ver_num, self.arch)
"qt.qt{0}.{0}{1}{2}.{3}".format(
self.version.major,
self.version.minor,
self.version.patch,
self.arch,
)
)
target_packages.append(
"qt.{0}{1}{2}.{3}".format(
self.version.major, self.version.minor, self.version.patch, self.arch
)
)
target_packages.append("qt.{}.{}".format(qt_ver_num, self.arch))
target_packages.extend(self.mod_list)
self._download_update_xml(update_xml_url)
self._parse_update_xml(archive_url, target_packages)
@@ -302,20 +321,26 @@ class SrcDocExamplesArchives(QtArchives):
timeout=timeout,
)
def _get_archives(self, qt_ver_num):
archive_path = "{0}{1}{2}/qt{3}_{4}{5}".format(
def _get_archives(self):
archive_path = "{0}{1}{2}/qt{3}_{3}{4}{5}{6}".format(
self.os_name,
"_x86/" if self.os_name == "windows" else "_x64/",
self.target,
self.qt_ver_base,
qt_ver_num,
self.version.major,
self.version.minor,
self.version.patch,
"_src_doc_examples/",
)
archive_url = "{0}{1}".format(self.base, archive_path)
update_xml_url = "{0}/Updates.xml".format(archive_url)
target_packages = []
target_packages.append(
"qt.qt{}.{}.{}".format(self.qt_ver_base, qt_ver_num, self.flavor)
"qt.qt{0}.{0}{1}{2}.{3}".format(
self.version.major,
self.version.minor,
self.version.patch,
self.flavor,
)
)
target_packages.extend(self.mod_list)
self._download_update_xml(update_xml_url)
@@ -346,7 +371,7 @@ class ToolArchives(QtArchives):
os_name, "desktop", version, arch, base, logging=logging, timeout=timeout
)
def _get_archives(self, qt_ver_num):
def _get_archives(self):
if self.os_name == "windows":
archive_url = self.base + self.os_name + "_x86/" + self.target + "/"
else:
@@ -371,15 +396,15 @@ class ToolArchives(QtArchives):
downloadable_archives = _archives.split(", ")
else:
downloadable_archives = []
full_version = packageupdate.find("Version").text
if not full_version.startswith(self.version):
named_version = packageupdate.find("Version").text
full_version = Version(named_version)
if not full_version.base_version == self.version.base_version:
self.logger.warning(
"Version {} differ from requested version {} -- skip.".format(
full_version, self.version
"Base Version of {} is different from requested version {} -- skip.".format(
named_version, self.version
)
)
continue
named_version = full_version
package_desc = packageupdate.find("Description").text
for archive in downloadable_archives:
package_url = (

View File

@@ -99,7 +99,7 @@
], "versions": [
"5.9", "5.9.1", "5.9.2", "5.9.3", "5.9.4", "5.9.5", "5.9.6", "5.9.7", "5.9.8", "5.9.9",
"5.10.0", "5.10.1", "5.11.0", "5.11.1", "5.11.2", "5.11.3",
"5.12.0", "5.12.1", "5.12.2", "5.12.3", "5.12.4", "5.12.5", "5.12.6", "5.12.7", "5.12.8", "5.12.9", "5.12.10",
"5.12.0", "5.12.1", "5.12.2", "5.12.3", "5.12.4", "5.12.5", "5.12.6", "5.12.7", "5.12.8", "5.12.9", "5.12.10", "5.12.11",
"5.13.0", "5.13.1", "5.13.2",
"5.14.0", "5.14.1", "5.14.2",
"5.15.0", "5.15.1", "5.15.2",

View File

@@ -33,7 +33,7 @@ import subprocess
import time
from logging import getLogger
from packaging.version import Version, parse
from semantic_version import Version
from texttable import Texttable
import aqt
@@ -144,7 +144,7 @@ class Cli:
arch = "clang_64"
elif os_name == "mac" and target == "ios":
arch = "ios"
elif target == "android" and parse(qt_version) >= Version("5.14.0"):
elif target == "android" and Version(qt_version) >= Version("5.14.0"):
arch = "android"
else:
print("Please supply a target architecture.")

View File

@@ -23,6 +23,8 @@ import os
import pathlib
import subprocess
from semantic_version import SimpleSpec, Version
class Updater:
def __init__(self, prefix: pathlib.Path, logger):
@@ -205,7 +207,6 @@ class Updater:
Make Qt configuration files, qt.conf and qtconfig.pri.
And update pkgconfig and patch Qt5Core and qmake
"""
qt_version = target.version
arch = target.arch
if arch is None:
arch_dir = ""
@@ -220,7 +221,7 @@ class Updater:
try:
prefix = pathlib.Path(base_dir) / target.version / arch_dir
updater = Updater(prefix, logger)
updater.set_license(base_dir, qt_version, arch_dir)
updater.set_license(base_dir, target.version, arch_dir)
if target.arch not in [
"ios",
"android",
@@ -230,22 +231,18 @@ class Updater:
"android_x86",
"android_armv7",
]: # desktop version
updater.make_qtconf(base_dir, qt_version, arch_dir)
updater.make_qtconf(base_dir, target.version, arch_dir)
updater.patch_qmake()
if target.os_name == "linux":
updater.patch_pkgconfig()
if versiontuple(target.version) < (5, 14, 0):
if Version(target.version) < Version("5.14.0"):
updater.patch_qtcore(target)
elif qt_version.startswith("5."): # qt5 non-desktop
elif Version(target.version) in SimpleSpec(">=5.0,<6.0"):
updater.patch_qmake()
else: # qt6 non-desktop
updater.patch_qmake_script(base_dir, qt_version, target.os_name)
updater.patch_qmake_script(base_dir, target.version, target.os_name)
updater.patch_target_qt_conf(
base_dir, qt_version, arch_dir, target.os_name
base_dir, target.version, arch_dir, target.os_name
)
except IOError as e:
raise e
def versiontuple(v: str):
return tuple(map(int, (v.split("."))))

View File

@@ -33,8 +33,8 @@ classifiers =
python_requires = >= 3.6
install_requires =
requests
semantic_version
py7zr>=0.15.1
packaging
texttable
setup_requires =
setuptools-scm[toml]>=6.0.1