Python: move pyside detection to runconfig

Change-Id: I781c4d005ced0c884081616696eae7f738f38c6f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-05-30 12:38:46 +02:00
parent 0f470982de
commit 3ad82a66f9
3 changed files with 79 additions and 80 deletions

View File

@@ -89,23 +89,8 @@ PySideBuildStep::PySideBuildStep(BuildStepList *bsl, Id id)
setWorkingDirectoryProvider([this] { return target()->project()->projectDirectory(); });
}
void PySideBuildStep::updateInterpreter(const Utils::FilePath &python)
void PySideBuildStep::updatePySideProjectPath(const Utils::FilePath &pySideProjectPath)
{
Utils::FilePath pySideProjectPath;
const PipPackage pySide6Package("PySide6");
const PipPackageInfo info = pySide6Package.info(python);
for (const FilePath &file : qAsConst(info.files)) {
if (file.fileName() == HostOsInfo::withExecutableSuffix("pyside6-project")) {
pySideProjectPath = info.location.resolvePath(file);
pySideProjectPath = pySideProjectPath.cleanPath();
break;
}
}
if (!pySideProjectPath.isExecutableFile())
pySideProjectPath = Environment::systemEnvironment().searchInPath("pyside6-project");
if (pySideProjectPath.isExecutableFile())
m_pysideProject->setFilePath(pySideProjectPath);
}

View File

@@ -50,7 +50,7 @@ class PySideBuildStep : public ProjectExplorer::AbstractProcessStep
Q_OBJECT
public:
PySideBuildStep(ProjectExplorer::BuildStepList *bsl, Utils::Id id);
void updateInterpreter(const Utils::FilePath &python);
void updatePySideProjectPath(const Utils::FilePath &pySideProjectPath);
private:
Utils::StringAspect *m_pysideProject;

View File

@@ -140,7 +140,11 @@ private:
class PythonRunConfiguration : public RunConfiguration
{
public:
PythonRunConfiguration(Target *target, Id id)
PythonRunConfiguration(Target *target, Id id);
void currentInterpreterChanged();
};
PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id)
{
auto interpreterAspect = addAspect<InterpreterAspect>();
@@ -156,8 +160,7 @@ public:
QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(
project()->projectDirectory());
interpreterAspect->updateInterpreters(PythonSettings::interpreters());
Interpreter defaultInterpreter = interpreters.isEmpty()
? PythonSettings::defaultInterpreter()
Interpreter defaultInterpreter = interpreters.isEmpty() ? PythonSettings::defaultInterpreter()
: interpreters.first();
if (!defaultInterpreter.command.isExecutableFile())
defaultInterpreter = PythonSettings::interpreters().value(0);
@@ -201,13 +204,25 @@ public:
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
}
void currentInterpreterChanged()
void PythonRunConfiguration::currentInterpreterChanged()
{
const FilePath python = aspect<InterpreterAspect>()->currentInterpreter().command;
BuildStepList *buildSteps = target()->activeBuildConfiguration()->buildSteps();
Utils::FilePath pySideProjectPath;
const PipPackage pySide6Package("PySide6");
const PipPackageInfo info = pySide6Package.info(python);
for (const FilePath &file : qAsConst(info.files)) {
if (file.fileName() == HostOsInfo::withExecutableSuffix("pyside6-project")) {
pySideProjectPath = info.location.resolvePath(file);
pySideProjectPath = pySideProjectPath.cleanPath();
break;
}
}
if (auto pySideBuildStep = buildSteps->firstOfType<PySideBuildStep>())
pySideBuildStep->updateInterpreter(python);
pySideBuildStep->updatePySideProjectPath(pySideProjectPath);
for (FilePath &file : project()->files(Project::AllFiles)) {
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
@@ -218,7 +233,6 @@ public:
}
}
}
};
PythonRunConfigurationFactory::PythonRunConfigurationFactory()
{