Skip to content

Commit 150a3fb

Browse files
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 <[email protected]>
1 parent df171ff commit 150a3fb

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

sources/pyside6/plugins/designer/designercustomwidgets.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QtCore/QVariant>
1818

1919
#include <string_view>
20+
#include <utility>
2021

2122
using namespace Qt::StringLiterals;
2223

@@ -123,26 +124,29 @@ static bool runPyScriptFile(const QString &fileName, QString *errorMessage)
123124
return ok;
124125
}
125126

127+
static std::pair<int, int> pythonVersion()
128+
{
129+
// read environment set by pyside_tool.py
130+
bool majorOk{};
131+
bool minorOk{};
132+
const int majorVersion = qEnvironmentVariableIntValue("PY_MAJOR_VERSION", &majorOk);
133+
const int minorVersion = qEnvironmentVariableIntValue("PY_MINOR_VERSION", &minorOk);
134+
if (majorOk && minorVersion)
135+
return {majorVersion, minorVersion};
136+
return {PY_MAJOR_VERSION, PY_MINOR_VERSION};
137+
}
138+
126139
static void initVirtualEnvironment()
127140
{
128141
static const char virtualEnvVar[] = "VIRTUAL_ENV";
129-
// As of Python 3.8/Windows, Python is no longer able to run stand-alone in
130-
// a virtualenv due to missing libraries. Add the path to the modules
131-
// instead. macOS seems to be showing the same issues.
142+
// Since Python 3.8 (Windows, macOS), Python is no longer able to run stand
143+
// -alone in a virtualenv due to missing libraries. Add the path to the modules
144+
// instead.
132145

133146
const auto os = QOperatingSystemVersion::currentType();
134147

135-
bool ok;
136-
int majorVersion = qEnvironmentVariableIntValue("PY_MAJOR_VERSION", &ok);
137-
int minorVersion = qEnvironmentVariableIntValue("PY_MINOR_VERSION", &ok);
138-
if (!ok) {
139-
majorVersion = PY_MAJOR_VERSION;
140-
minorVersion = PY_MINOR_VERSION;
141-
}
142-
143148
if (!qEnvironmentVariableIsSet(virtualEnvVar)
144-
|| (os != QOperatingSystemVersion::MacOS && os != QOperatingSystemVersion::Windows)
145-
|| (majorVersion == 3 && minorVersion < 8)) {
149+
|| (os != QOperatingSystemVersion::MacOS && os != QOperatingSystemVersion::Windows)) {
146150
return;
147151
}
148152

@@ -155,11 +159,13 @@ static void initVirtualEnvironment()
155159
case QOperatingSystemVersion::Windows:
156160
pythonPath.append(virtualEnvPath + R"(\Lib\site-packages)");
157161
break;
158-
case QOperatingSystemVersion::MacOS:
162+
case QOperatingSystemVersion::MacOS: {
163+
const auto version = pythonVersion();
159164
pythonPath.append(virtualEnvPath + "/lib/python"_ba +
160-
QByteArray::number(majorVersion) + '.'
161-
+ QByteArray::number(minorVersion)
165+
QByteArray::number(version.first) + '.'
166+
+ QByteArray::number(version.second)
162167
+ "/site-packages"_ba);
168+
}
163169
break;
164170
default:
165171
break;

0 commit comments

Comments
 (0)