diff --git a/src/plugins/python/pysidebuildconfiguration.cpp b/src/plugins/python/pysidebuildconfiguration.cpp index c344d0d1708..1df0c4ea672 100644 --- a/src/plugins/python/pysidebuildconfiguration.cpp +++ b/src/plugins/python/pysidebuildconfiguration.cpp @@ -89,24 +89,9 @@ 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); + m_pysideProject->setFilePath(pySideProjectPath); } void PySideBuildStep::doRun() diff --git a/src/plugins/python/pysidebuildconfiguration.h b/src/plugins/python/pysidebuildconfiguration.h index 943c995f472..3a199f25388 100644 --- a/src/plugins/python/pysidebuildconfiguration.h +++ b/src/plugins/python/pysidebuildconfiguration.h @@ -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; diff --git a/src/plugins/python/pythonrunconfiguration.cpp b/src/plugins/python/pythonrunconfiguration.cpp index 12813f6829b..4c184bbdc19 100644 --- a/src/plugins/python/pythonrunconfiguration.cpp +++ b/src/plugins/python/pythonrunconfiguration.cpp @@ -140,85 +140,99 @@ private: class PythonRunConfiguration : public RunConfiguration { public: - PythonRunConfiguration(Target *target, Id id) - : RunConfiguration(target, id) - { - auto interpreterAspect = addAspect(); - interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter"); - interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID); + PythonRunConfiguration(Target *target, Id id); + void currentInterpreterChanged(); +}; - connect(interpreterAspect, &InterpreterAspect::changed, - this, &PythonRunConfiguration::currentInterpreterChanged); +PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id) + : RunConfiguration(target, id) +{ + auto interpreterAspect = addAspect(); + interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter"); + interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID); - connect(PythonSettings::instance(), &PythonSettings::interpretersChanged, - interpreterAspect, &InterpreterAspect::updateInterpreters); + connect(interpreterAspect, &InterpreterAspect::changed, + this, &PythonRunConfiguration::currentInterpreterChanged); - QList interpreters = PythonSettings::detectPythonVenvs( - project()->projectDirectory()); - interpreterAspect->updateInterpreters(PythonSettings::interpreters()); - Interpreter defaultInterpreter = interpreters.isEmpty() - ? PythonSettings::defaultInterpreter() - : interpreters.first(); - if (!defaultInterpreter.command.isExecutableFile()) - defaultInterpreter = PythonSettings::interpreters().value(0); - interpreterAspect->setDefaultInterpreter(defaultInterpreter); + connect(PythonSettings::instance(), &PythonSettings::interpretersChanged, + interpreterAspect, &InterpreterAspect::updateInterpreters); - auto bufferedAspect = addAspect(); - bufferedAspect->setSettingsKey("PythonEditor.RunConfiguation.Buffered"); - bufferedAspect->setLabel(tr("Buffered output"), BoolAspect::LabelPlacement::AtCheckBox); - bufferedAspect->setToolTip(tr("Enabling improves output performance, " - "but results in delayed output.")); + QList interpreters = PythonSettings::detectPythonVenvs( + project()->projectDirectory()); + interpreterAspect->updateInterpreters(PythonSettings::interpreters()); + Interpreter defaultInterpreter = interpreters.isEmpty() ? PythonSettings::defaultInterpreter() + : interpreters.first(); + if (!defaultInterpreter.command.isExecutableFile()) + defaultInterpreter = PythonSettings::interpreters().value(0); + interpreterAspect->setDefaultInterpreter(defaultInterpreter); - auto scriptAspect = addAspect(); - scriptAspect->setSettingsKey("PythonEditor.RunConfiguation.Script"); - scriptAspect->setLabelText(tr("Script:")); - scriptAspect->setDisplayStyle(StringAspect::LabelDisplay); + auto bufferedAspect = addAspect(); + bufferedAspect->setSettingsKey("PythonEditor.RunConfiguation.Buffered"); + bufferedAspect->setLabel(tr("Buffered output"), BoolAspect::LabelPlacement::AtCheckBox); + bufferedAspect->setToolTip(tr("Enabling improves output performance, " + "but results in delayed output.")); - addAspect(target); + auto scriptAspect = addAspect(); + scriptAspect->setSettingsKey("PythonEditor.RunConfiguation.Script"); + scriptAspect->setLabelText(tr("Script:")); + scriptAspect->setDisplayStyle(StringAspect::LabelDisplay); - auto argumentsAspect = addAspect(macroExpander()); + addAspect(target); - addAspect(macroExpander(), nullptr); - addAspect(); + auto argumentsAspect = addAspect(macroExpander()); - setCommandLineGetter([bufferedAspect, interpreterAspect, argumentsAspect, scriptAspect] { - CommandLine cmd{interpreterAspect->currentInterpreter().command}; - if (!bufferedAspect->value()) - cmd.addArg("-u"); - cmd.addArg(scriptAspect->filePath().fileName()); - cmd.addArgs(argumentsAspect->arguments(), CommandLine::Raw); - return cmd; - }); + addAspect(macroExpander(), nullptr); + addAspect(); - setUpdater([this, scriptAspect] { - const BuildTargetInfo bti = buildTargetInfo(); - const QString script = bti.targetFilePath.toUserOutput(); - setDefaultDisplayName(tr("Run %1").arg(script)); - scriptAspect->setValue(script); - aspect()->setDefaultWorkingDirectory(bti.targetFilePath.parentDir()); - }); + setCommandLineGetter([bufferedAspect, interpreterAspect, argumentsAspect, scriptAspect] { + CommandLine cmd{interpreterAspect->currentInterpreter().command}; + if (!bufferedAspect->value()) + cmd.addArg("-u"); + cmd.addArg(scriptAspect->filePath().fileName()); + cmd.addArgs(argumentsAspect->arguments(), CommandLine::Raw); + return cmd; + }); - connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); + setUpdater([this, scriptAspect] { + const BuildTargetInfo bti = buildTargetInfo(); + const QString script = bti.targetFilePath.toUserOutput(); + setDefaultDisplayName(tr("Run %1").arg(script)); + scriptAspect->setValue(script); + aspect()->setDefaultWorkingDirectory(bti.targetFilePath.parentDir()); + }); + + connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); +} + +void PythonRunConfiguration::currentInterpreterChanged() +{ + const FilePath python = aspect()->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()->currentInterpreter().command; + if (auto pySideBuildStep = buildSteps->firstOfType()) + pySideBuildStep->updatePySideProjectPath(pySideProjectPath); - BuildStepList *buildSteps = target()->activeBuildConfiguration()->buildSteps(); - if (auto pySideBuildStep = buildSteps->firstOfType()) - pySideBuildStep->updateInterpreter(python); - - for (FilePath &file : project()->files(Project::AllFiles)) { - if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) { - if (document->mimeType() == Constants::C_PY_MIMETYPE) { - PyLSConfigureAssistant::openDocumentWithPython(python, document); - PySideInstaller::checkPySideInstallation(python, document); - } + for (FilePath &file : project()->files(Project::AllFiles)) { + if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) { + if (document->mimeType() == Constants::C_PY_MIMETYPE) { + PyLSConfigureAssistant::openDocumentWithPython(python, document); + PySideInstaller::checkPySideInstallation(python, document); } } } -}; +} PythonRunConfigurationFactory::PythonRunConfigurationFactory() {