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(); }); 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); m_pysideProject->setFilePath(pySideProjectPath);
} }

View File

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

View File

@@ -140,9 +140,13 @@ private:
class PythonRunConfiguration : public RunConfiguration class PythonRunConfiguration : public RunConfiguration
{ {
public: public:
PythonRunConfiguration(Target *target, Id id) PythonRunConfiguration(Target *target, Id id);
void currentInterpreterChanged();
};
PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto interpreterAspect = addAspect<InterpreterAspect>(); auto interpreterAspect = addAspect<InterpreterAspect>();
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter"); interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID); interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID);
@@ -156,8 +160,7 @@ public:
QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs( QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(
project()->projectDirectory()); project()->projectDirectory());
interpreterAspect->updateInterpreters(PythonSettings::interpreters()); interpreterAspect->updateInterpreters(PythonSettings::interpreters());
Interpreter defaultInterpreter = interpreters.isEmpty() Interpreter defaultInterpreter = interpreters.isEmpty() ? PythonSettings::defaultInterpreter()
? PythonSettings::defaultInterpreter()
: interpreters.first(); : interpreters.first();
if (!defaultInterpreter.command.isExecutableFile()) if (!defaultInterpreter.command.isExecutableFile())
defaultInterpreter = PythonSettings::interpreters().value(0); defaultInterpreter = PythonSettings::interpreters().value(0);
@@ -199,15 +202,27 @@ public:
}); });
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
}
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;
}
} }
void currentInterpreterChanged()
{
const FilePath python = aspect<InterpreterAspect>()->currentInterpreter().command;
BuildStepList *buildSteps = target()->activeBuildConfiguration()->buildSteps();
if (auto pySideBuildStep = buildSteps->firstOfType<PySideBuildStep>()) if (auto pySideBuildStep = buildSteps->firstOfType<PySideBuildStep>())
pySideBuildStep->updateInterpreter(python); pySideBuildStep->updatePySideProjectPath(pySideProjectPath);
for (FilePath &file : project()->files(Project::AllFiles)) { for (FilePath &file : project()->files(Project::AllFiles)) {
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) { if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
@@ -217,8 +232,7 @@ public:
} }
} }
} }
} }
};
PythonRunConfigurationFactory::PythonRunConfigurationFactory() PythonRunConfigurationFactory::PythonRunConfigurationFactory()
{ {