aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/plugins/designer/designercustomwidgets.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-06-18 13:33:37 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-06-18 14:05:43 +0200
commit150a3fb5598f360a33467a6f6e5a686f2d50e2f9 (patch)
tree8eee4b818fccaa99002fcf70e21cfe7a28a0d21f /sources/pyside6/plugins/designer/designercustomwidgets.cpp
parentdf171ff9ee8851709fa69d55810603598d02e420 (diff)
Qt Designer plugin: Remove Python version check
Pre 3.8 is no longer supported. Move the code into a static helper for macOS only. This also fixes analyzer warnings about ignoring return codes. Pick-to: 6.7 Change-Id: Idd1a53729152f132958f94d288c13ac4399b6c78 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/plugins/designer/designercustomwidgets.cpp')
-rw-r--r--sources/pyside6/plugins/designer/designercustomwidgets.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/sources/pyside6/plugins/designer/designercustomwidgets.cpp b/sources/pyside6/plugins/designer/designercustomwidgets.cpp
index d23156a9d..dc8bdf435 100644
--- a/sources/pyside6/plugins/designer/designercustomwidgets.cpp
+++ b/sources/pyside6/plugins/designer/designercustomwidgets.cpp
@@ -17,6 +17,7 @@
#include <QtCore/QVariant>
#include <string_view>
+#include <utility>
using namespace Qt::StringLiterals;
@@ -123,26 +124,29 @@ static bool runPyScriptFile(const QString &fileName, QString *errorMessage)
return ok;
}
+static std::pair<int, int> pythonVersion()
+{
+ // read environment set by pyside_tool.py
+ bool majorOk{};
+ bool minorOk{};
+ const int majorVersion = qEnvironmentVariableIntValue("PY_MAJOR_VERSION", &majorOk);
+ const int minorVersion = qEnvironmentVariableIntValue("PY_MINOR_VERSION", &minorOk);
+ if (majorOk && minorVersion)
+ return {majorVersion, minorVersion};
+ return {PY_MAJOR_VERSION, PY_MINOR_VERSION};
+}
+
static void initVirtualEnvironment()
{
static const char virtualEnvVar[] = "VIRTUAL_ENV";
- // As of Python 3.8/Windows, Python is no longer able to run stand-alone in
- // a virtualenv due to missing libraries. Add the path to the modules
- // instead. macOS seems to be showing the same issues.
+ // Since Python 3.8 (Windows, macOS), Python is no longer able to run stand
+ // -alone in a virtualenv due to missing libraries. Add the path to the modules
+ // instead.
const auto os = QOperatingSystemVersion::currentType();
- bool ok;
- int majorVersion = qEnvironmentVariableIntValue("PY_MAJOR_VERSION", &ok);
- int minorVersion = qEnvironmentVariableIntValue("PY_MINOR_VERSION", &ok);
- if (!ok) {
- majorVersion = PY_MAJOR_VERSION;
- minorVersion = PY_MINOR_VERSION;
- }
-
if (!qEnvironmentVariableIsSet(virtualEnvVar)
- || (os != QOperatingSystemVersion::MacOS && os != QOperatingSystemVersion::Windows)
- || (majorVersion == 3 && minorVersion < 8)) {
+ || (os != QOperatingSystemVersion::MacOS && os != QOperatingSystemVersion::Windows)) {
return;
}
@@ -155,11 +159,13 @@ static void initVirtualEnvironment()
case QOperatingSystemVersion::Windows:
pythonPath.append(virtualEnvPath + R"(\Lib\site-packages)");
break;
- case QOperatingSystemVersion::MacOS:
+ case QOperatingSystemVersion::MacOS: {
+ const auto version = pythonVersion();
pythonPath.append(virtualEnvPath + "/lib/python"_ba +
- QByteArray::number(majorVersion) + '.'
- + QByteArray::number(minorVersion)
+ QByteArray::number(version.first) + '.'
+ + QByteArray::number(version.second)
+ "/site-packages"_ba);
+ }
break;
default:
break;