Python: improve pyside tool detection

Look right next to the used python. For virtual env setups this should
be a lot faster than asking pip for the installed files. Additionally
this should work for pyside devenvs.

Change-Id: I2a8cf6877636785453426c348cfac252645aa4e1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2023-09-26 09:39:32 +02:00
parent 80633a59aa
commit ed6595a66e

View File

@@ -149,6 +149,13 @@ public:
void updateExtraCompilers();
void currentInterpreterChanged();
struct PySideTools
{
FilePath pySideProjectPath;
FilePath pySideUicPath;
};
void updateTools(const PySideTools &tools);
FilePath m_pySideUicPath;
PythonInterpreterAspect *q;
@@ -195,6 +202,14 @@ PythonInterpreterAspect::~PythonInterpreterAspect()
void PythonInterpreterAspectPrivate::checkForPySide(const FilePath &python)
{
PySideTools tools;
const FilePath dir = python.parentDir();
tools.pySideProjectPath = dir.pathAppended("pyside6-project").withExecutableSuffix();
tools.pySideUicPath = dir.pathAppended("pyside6-uic").withExecutableSuffix();
if (tools.pySideProjectPath.isExecutableFile() && tools.pySideUicPath.isExecutableFile())
updateTools(tools);
else
checkForPySide(python, "PySide6-Essentials");
}
@@ -215,24 +230,10 @@ void PythonInterpreterAspectPrivate::handlePySidePackageInfo(const PipPackageInf
const FilePath &python,
const QString &requestedPackageName)
{
struct PythonTools
{
FilePath pySideProjectPath;
FilePath pySideUicPath;
};
BuildStepList *buildSteps = nullptr;
if (Target *target = rc->target()) {
if (auto buildConfiguration = target->activeBuildConfiguration())
buildSteps = buildConfiguration->buildSteps();
}
if (!buildSteps)
return;
const auto findPythonTools = [](const FilePaths &files,
const FilePath &location,
const FilePath &python) -> PythonTools {
PythonTools result;
const FilePath &python) -> PySideTools {
PySideTools result;
const QString pySide6ProjectName
= OsSpecificAspects::withExecutableSuffix(python.osType(), "pyside6-project");
const QString pySide6UicName
@@ -253,18 +254,13 @@ void PythonInterpreterAspectPrivate::handlePySidePackageInfo(const PipPackageInf
return {};
};
PythonTools pythonTools = findPythonTools(pySideInfo.files, pySideInfo.location, python);
if (!pythonTools.pySideProjectPath.isExecutableFile() && requestedPackageName != "PySide6") {
PySideTools tools = findPythonTools(pySideInfo.files, pySideInfo.location, python);
if (!tools.pySideProjectPath.isExecutableFile() && requestedPackageName != "PySide6") {
checkForPySide(python, "PySide6");
return;
}
m_pySideUicPath = pythonTools.pySideUicPath;
updateExtraCompilers();
if (auto pySideBuildStep = buildSteps->firstOfType<PySideBuildStep>())
pySideBuildStep->updatePySideProjectPath(pythonTools.pySideProjectPath);
updateTools(tools);
}
void PythonInterpreterAspectPrivate::currentInterpreterChanged()
@@ -283,6 +279,22 @@ void PythonInterpreterAspectPrivate::currentInterpreterChanged()
}
}
void PythonInterpreterAspectPrivate::updateTools(const PySideTools &tools)
{
m_pySideUicPath = tools.pySideUicPath;
updateExtraCompilers();
if (Target *target = rc->target()) {
if (BuildConfiguration *buildConfiguration = target->activeBuildConfiguration()) {
if (BuildStepList *buildSteps = buildConfiguration->buildSteps()) {
if (auto buildStep = buildSteps->firstOfType<PySideBuildStep>())
buildStep->updatePySideProjectPath(tools.pySideProjectPath);
}
}
}
}
QList<PySideUicExtraCompiler *> PythonInterpreterAspect::extraCompilers() const
{
return d->m_extraCompilers;