From af7b0802a8d9283db10c933de0c69973cce4b7a3 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 18 Oct 2022 12:07:24 +0200 Subject: [PATCH] Python: fix PySide project tool detection The tool moved to the PySide6-Essentials module. Change-Id: I204d2025bc51b6c5cffe82cba66878d077f03b72 Reviewed-by: Christian Stenger --- src/plugins/python/pythonrunconfiguration.cpp | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/plugins/python/pythonrunconfiguration.cpp b/src/plugins/python/pythonrunconfiguration.cpp index 9012556c81e..28937e0813b 100644 --- a/src/plugins/python/pythonrunconfiguration.cpp +++ b/src/plugins/python/pythonrunconfiguration.cpp @@ -206,51 +206,56 @@ PythonRunConfiguration::~PythonRunConfiguration() qDeleteAll(m_extraCompilers); } +struct PythonTools +{ + FilePath pySideProjectPath; + FilePath pySideUicPath; +}; + void PythonRunConfiguration::checkForPySide(const FilePath &python) { BuildStepList *buildSteps = target()->activeBuildConfiguration()->buildSteps(); - FilePath pySideProjectPath; - m_pySideUicPath.clear(); - const PipPackage pySide6Package("PySide6"); - const PipPackageInfo info = pySide6Package.info(python); - for (const FilePath &file : std::as_const(info.files)) { - if (file.fileName() == HostOsInfo::withExecutableSuffix("pyside6-project")) { - pySideProjectPath = info.location.resolvePath(file); - pySideProjectPath = pySideProjectPath.cleanPath(); - if (!m_pySideUicPath.isEmpty()) - break; - } else if (file.fileName() == HostOsInfo::withExecutableSuffix("pyside6-uic")) { - m_pySideUicPath = info.location.resolvePath(file); - m_pySideUicPath = m_pySideUicPath.cleanPath(); - if (!pySideProjectPath.isEmpty()) - break; + const auto findPythonTools = [](const FilePaths &files, + const FilePath &location, + const FilePath &python) -> PythonTools { + PythonTools result; + const QString pySide6ProjectName + = OsSpecificAspects::withExecutableSuffix(python.osType(), "pyside6-project"); + const QString pySide6UicName + = OsSpecificAspects::withExecutableSuffix(python.osType(), "pyside6-uic"); + for (const FilePath &file : files) { + if (file.fileName() == pySide6ProjectName) { + result.pySideProjectPath = location.resolvePath(file).onDevice(python); + result.pySideProjectPath = result.pySideProjectPath.cleanPath(); + if (!result.pySideUicPath.isEmpty()) + return result; + } else if (file.fileName() == pySide6UicName) { + result.pySideUicPath = location.resolvePath(file).onDevice(python); + result.pySideUicPath = result.pySideUicPath.cleanPath(); + if (!result.pySideProjectPath.isEmpty()) + return result; + } } + return {}; + }; + + const PipPackage pySide6EssentialPackage("PySide6-Essentials"); + PipPackageInfo info = pySide6EssentialPackage.info(python); + PythonTools pythonTools = findPythonTools(info.files, info.location, python); + if (!pythonTools.pySideProjectPath.isExecutableFile()) { + const PipPackage pySide6Package("PySide6"); + info = pySide6Package.info(python); + pythonTools = findPythonTools(info.files, info.location, python); } - // Workaround that pip might return an incomplete file list on windows - if (HostOsInfo::isWindowsHost() && !python.needsDevice() - && !info.location.isEmpty() && m_pySideUicPath.isEmpty()) { - // Scripts is next to the site-packages install dir for user installations - FilePath scripts = info.location.parentDir().pathAppended("Scripts"); - if (!scripts.exists()) { - // in global/venv installations Scripts is next to Lib/site-packages - scripts = info.location.parentDir().parentDir().pathAppended("Scripts"); - } - auto userInstalledPySideTool = [&](const QString &toolName) { - const FilePath tool = scripts.pathAppended(HostOsInfo::withExecutableSuffix(toolName)); - return tool.isExecutableFile() ? tool : FilePath(); - }; - m_pySideUicPath = userInstalledPySideTool("pyside6-uic"); - if (pySideProjectPath.isEmpty()) - pySideProjectPath = userInstalledPySideTool("pyside6-project"); - } + m_pySideUicPath = pythonTools.pySideUicPath; updateExtraCompilers(); if (auto pySideBuildStep = buildSteps->firstOfType()) - pySideBuildStep->updatePySideProjectPath(pySideProjectPath); + pySideBuildStep->updatePySideProjectPath(pythonTools.pySideProjectPath); } void PythonRunConfiguration::currentInterpreterChanged()