Skip to content

Commit fe6d4de

Browse files
authored
Fix PyQt5 version check (#1325)
2 parents e2f7e77 + c9fe0ca commit fe6d4de

File tree

8 files changed

+18
-78
lines changed

8 files changed

+18
-78
lines changed

novelwriter/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ def main(sysArgs=None):
179179
"At least Python 3.7 is required, found %s" % CONFIG.verPyString
180180
)
181181
errorCode |= 0x04
182-
if CONFIG.verQtValue < 51000:
182+
if CONFIG.verQtValue < 0x050a00:
183183
errorData.append(
184184
"At least Qt5 version 5.10 is required, found %s" % CONFIG.verQtString
185185
)
186186
errorCode |= 0x08
187-
if CONFIG.verPyQtValue < 51000:
187+
if CONFIG.verPyQtValue < 0x050a00:
188188
errorData.append(
189189
"At least PyQt5 version 5.10 is required, found %s" % CONFIG.verPyQtString
190190
)

novelwriter/common.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -277,33 +277,6 @@ def yesNo(value):
277277
return "yes" if value else "no"
278278

279279

280-
def splitVersionNumber(value):
281-
"""Split a version string on the form aa.bb.cc into major, minor
282-
and patch, and computes an integer value aabbcc.
283-
"""
284-
if not isinstance(value, str):
285-
return 0, 0, 0, 0
286-
287-
vMajor = 0
288-
vMinor = 0
289-
vPatch = 0
290-
vInt = 0
291-
292-
vBits = value.split(".")
293-
nBits = len(vBits)
294-
295-
if nBits > 0:
296-
vMajor = checkInt(vBits[0], 0)
297-
if nBits > 1:
298-
vMinor = checkInt(vBits[1], 0)
299-
if nBits > 2:
300-
vPatch = checkInt(vBits[2], 0)
301-
302-
vInt = vMajor*10000 + vMinor*100 + vPatch
303-
304-
return vMajor, vMinor, vPatch, vInt
305-
306-
307280
def transferCase(source, target):
308281
"""Transfers the case of the source word to the target word. This
309282
will consider all upper or lower, and first char capitalisation.

novelwriter/config.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030
from time import time
3131
from pathlib import Path
3232

33-
from PyQt5.Qt import PYQT_VERSION_STR
3433
from PyQt5.QtCore import (
35-
QT_VERSION_STR, QStandardPaths, QSysInfo, QLocale, QLibraryInfo,
36-
QTranslator
34+
QT_VERSION, QT_VERSION_STR, PYQT_VERSION, PYQT_VERSION_STR, QStandardPaths,
35+
QSysInfo, QLocale, QLibraryInfo, QTranslator
3736
)
3837

3938
from novelwriter.error import logException, formatException
40-
from novelwriter.common import checkPath, splitVersionNumber, formatTimeStamp, NWConfigParser
39+
from novelwriter.common import checkPath, formatTimeStamp, NWConfigParser
4140
from novelwriter.constants import nwFiles, nwUnicode
4241

4342
logger = logging.getLogger(__name__)
@@ -190,25 +189,13 @@ def __init__(self):
190189
# ==========================
191190

192191
# Check Qt5 Versions
193-
verQt = splitVersionNumber(QT_VERSION_STR)
194-
self.verQtString = QT_VERSION_STR
195-
self.verQtMajor = verQt[0]
196-
self.verQtMinor = verQt[1]
197-
self.verQtPatch = verQt[2]
198-
self.verQtValue = verQt[3]
199-
200-
verQt = splitVersionNumber(PYQT_VERSION_STR)
192+
self.verQtString = QT_VERSION_STR
193+
self.verQtValue = QT_VERSION
201194
self.verPyQtString = PYQT_VERSION_STR
202-
self.verPyQtMajor = verQt[0]
203-
self.verPyQtMinor = verQt[1]
204-
self.verPyQtPatch = verQt[2]
205-
self.verPyQtValue = verQt[3]
195+
self.verPyQtValue = PYQT_VERSION
206196

207197
# Check Python Version
208198
self.verPyString = sys.version.split()[0]
209-
self.verPyMajor = sys.version_info[0]
210-
self.verPyMinor = sys.version_info[1]
211-
self.verPyPatch = sys.version_info[2]
212199
self.verPyHexVal = sys.hexversion
213200

214201
# Check OS Type

novelwriter/error.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ def setMessage(self, exType, exValue, exTrace):
112112
"""
113113
from traceback import format_tb
114114
from novelwriter import __issuesurl__, __version__
115-
from PyQt5.Qt import PYQT_VERSION_STR
116-
from PyQt5.QtCore import QT_VERSION_STR, QSysInfo
115+
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR, QSysInfo
117116

118117
self.msgHead.setText((
119118
"<p>An unhandled error has been encountered.</p>"

novelwriter/gui/doceditor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,7 @@ def getSearchObject(self):
25122512
# Using the Unicode-capable QRegularExpression class was
25132513
# only added in Qt 5.13. Otherwise, 5.3 and up supports
25142514
# only the QRegExp class.
2515-
if self.mainConf.verQtValue >= 51300:
2515+
if self.mainConf.verQtValue >= 0x050d00:
25162516
rxOpt = QRegularExpression.UseUnicodePropertiesOption
25172517
if not self.isCaseSense:
25182518
rxOpt |= QRegularExpression.CaseInsensitiveOption

novelwriter/guimain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def __init__(self):
8787
logger.info("OS: %s", self.mainConf.osType)
8888
logger.info("Kernel: %s", self.mainConf.kernelVer)
8989
logger.info("Host: %s", self.mainConf.hostName)
90-
logger.info("Qt5: %s (%d)", self.mainConf.verQtString, self.mainConf.verQtValue)
91-
logger.info("PyQt5: %s (%d)", self.mainConf.verPyQtString, self.mainConf.verPyQtValue)
92-
logger.info("Python: %s (0x%x)", self.mainConf.verPyString, self.mainConf.verPyHexVal)
90+
logger.info("Qt5: %s (0x%06x)", self.mainConf.verQtString, self.mainConf.verQtValue)
91+
logger.info("PyQt5: %s (0x%06x)", self.mainConf.verPyQtString, self.mainConf.verPyQtValue)
92+
logger.info("Python: %s (0x%08x)", self.mainConf.verPyString, self.mainConf.verPyHexVal)
9393
logger.info("GUI Language: %s", self.mainConf.guiLocale)
9494

9595
# Core Classes

tests/test_base/test_base_common.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
checkStringNone, checkString, checkInt, checkFloat, checkBool, checkHandle,
3434
checkUuid, checkPath, isHandle, isTitleTag, isItemClass, isItemType,
3535
isItemLayout, hexToInt, minmax, checkIntTuple, formatInt, formatTimeStamp,
36-
formatTime, simplified, yesNo, splitVersionNumber, transferCase, fuzzyTime,
37-
numberToRoman, jsonEncode, readTextFile, makeFileNameSafe, sha256sum,
38-
getGuiItem, NWConfigParser
36+
formatTime, simplified, yesNo, transferCase, fuzzyTime, numberToRoman,
37+
jsonEncode, readTextFile, makeFileNameSafe, sha256sum, getGuiItem,
38+
NWConfigParser
3939
)
4040

4141

@@ -398,25 +398,6 @@ def testBaseCommon_YesNo():
398398
# END Test testBaseCommon_YesNo
399399

400400

401-
@pytest.mark.base
402-
def testBaseCommon_SplitVersionNumber():
403-
"""Test the splitVersionNumber function.
404-
"""
405-
# OK Values
406-
assert splitVersionNumber("1") == (1, 0, 0, 10000)
407-
assert splitVersionNumber("1.2") == (1, 2, 0, 10200)
408-
assert splitVersionNumber("1.2.3") == (1, 2, 3, 10203)
409-
assert splitVersionNumber("1.2.3.4") == (1, 2, 3, 10203)
410-
assert splitVersionNumber("99.99.99") == (99, 99, 99, 999999)
411-
412-
# Failed Values
413-
assert splitVersionNumber(None) == (0, 0, 0, 0)
414-
assert splitVersionNumber(1234) == (0, 0, 0, 0)
415-
assert splitVersionNumber("1.2abc") == (1, 0, 0, 10000)
416-
417-
# END Test testBaseCommon_SplitVersionNumber
418-
419-
420401
@pytest.mark.base
421402
def testBaseCommon_FormatInt():
422403
"""Test the formatInt function.

tests/test_base/test_base_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def testBaseInit_Imports(caplog, monkeypatch, tmpPath):
155155
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.showMessage", lambda *a: None)
156156
monkeypatch.setitem(sys.modules, "lxml", None)
157157
monkeypatch.setattr("sys.hexversion", 0x0)
158-
monkeypatch.setattr("novelwriter.CONFIG.verQtValue", 50000)
159-
monkeypatch.setattr("novelwriter.CONFIG.verPyQtValue", 50000)
158+
monkeypatch.setattr("novelwriter.CONFIG.verQtValue", 0x050000)
159+
monkeypatch.setattr("novelwriter.CONFIG.verPyQtValue", 0x050000)
160160

161161
with pytest.raises(SystemExit) as ex:
162162
_ = novelwriter.main(

0 commit comments

Comments
 (0)