forked from qt-creator/qt-creator
Python: move pyside detection to runconfig
Change-Id: I781c4d005ced0c884081616696eae7f738f38c6f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -89,24 +89,9 @@ 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;
|
m_pysideProject->setFilePath(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PySideBuildStep::doRun()
|
void PySideBuildStep::doRun()
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -140,85 +140,99 @@ private:
|
|||||||
class PythonRunConfiguration : public RunConfiguration
|
class PythonRunConfiguration : public RunConfiguration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PythonRunConfiguration(Target *target, Id id)
|
PythonRunConfiguration(Target *target, Id id);
|
||||||
: RunConfiguration(target, id)
|
void currentInterpreterChanged();
|
||||||
{
|
};
|
||||||
auto interpreterAspect = addAspect<InterpreterAspect>();
|
|
||||||
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
|
|
||||||
interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID);
|
|
||||||
|
|
||||||
connect(interpreterAspect, &InterpreterAspect::changed,
|
PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
|
||||||
this, &PythonRunConfiguration::currentInterpreterChanged);
|
: RunConfiguration(target, id)
|
||||||
|
{
|
||||||
|
auto interpreterAspect = addAspect<InterpreterAspect>();
|
||||||
|
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
|
||||||
|
interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID);
|
||||||
|
|
||||||
connect(PythonSettings::instance(), &PythonSettings::interpretersChanged,
|
connect(interpreterAspect, &InterpreterAspect::changed,
|
||||||
interpreterAspect, &InterpreterAspect::updateInterpreters);
|
this, &PythonRunConfiguration::currentInterpreterChanged);
|
||||||
|
|
||||||
QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(
|
connect(PythonSettings::instance(), &PythonSettings::interpretersChanged,
|
||||||
project()->projectDirectory());
|
interpreterAspect, &InterpreterAspect::updateInterpreters);
|
||||||
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 bufferedAspect = addAspect<BoolAspect>();
|
QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(
|
||||||
bufferedAspect->setSettingsKey("PythonEditor.RunConfiguation.Buffered");
|
project()->projectDirectory());
|
||||||
bufferedAspect->setLabel(tr("Buffered output"), BoolAspect::LabelPlacement::AtCheckBox);
|
interpreterAspect->updateInterpreters(PythonSettings::interpreters());
|
||||||
bufferedAspect->setToolTip(tr("Enabling improves output performance, "
|
Interpreter defaultInterpreter = interpreters.isEmpty() ? PythonSettings::defaultInterpreter()
|
||||||
"but results in delayed output."));
|
: interpreters.first();
|
||||||
|
if (!defaultInterpreter.command.isExecutableFile())
|
||||||
|
defaultInterpreter = PythonSettings::interpreters().value(0);
|
||||||
|
interpreterAspect->setDefaultInterpreter(defaultInterpreter);
|
||||||
|
|
||||||
auto scriptAspect = addAspect<MainScriptAspect>();
|
auto bufferedAspect = addAspect<BoolAspect>();
|
||||||
scriptAspect->setSettingsKey("PythonEditor.RunConfiguation.Script");
|
bufferedAspect->setSettingsKey("PythonEditor.RunConfiguation.Buffered");
|
||||||
scriptAspect->setLabelText(tr("Script:"));
|
bufferedAspect->setLabel(tr("Buffered output"), BoolAspect::LabelPlacement::AtCheckBox);
|
||||||
scriptAspect->setDisplayStyle(StringAspect::LabelDisplay);
|
bufferedAspect->setToolTip(tr("Enabling improves output performance, "
|
||||||
|
"but results in delayed output."));
|
||||||
|
|
||||||
addAspect<LocalEnvironmentAspect>(target);
|
auto scriptAspect = addAspect<MainScriptAspect>();
|
||||||
|
scriptAspect->setSettingsKey("PythonEditor.RunConfiguation.Script");
|
||||||
|
scriptAspect->setLabelText(tr("Script:"));
|
||||||
|
scriptAspect->setDisplayStyle(StringAspect::LabelDisplay);
|
||||||
|
|
||||||
auto argumentsAspect = addAspect<ArgumentsAspect>(macroExpander());
|
addAspect<LocalEnvironmentAspect>(target);
|
||||||
|
|
||||||
addAspect<WorkingDirectoryAspect>(macroExpander(), nullptr);
|
auto argumentsAspect = addAspect<ArgumentsAspect>(macroExpander());
|
||||||
addAspect<TerminalAspect>();
|
|
||||||
|
|
||||||
setCommandLineGetter([bufferedAspect, interpreterAspect, argumentsAspect, scriptAspect] {
|
addAspect<WorkingDirectoryAspect>(macroExpander(), nullptr);
|
||||||
CommandLine cmd{interpreterAspect->currentInterpreter().command};
|
addAspect<TerminalAspect>();
|
||||||
if (!bufferedAspect->value())
|
|
||||||
cmd.addArg("-u");
|
|
||||||
cmd.addArg(scriptAspect->filePath().fileName());
|
|
||||||
cmd.addArgs(argumentsAspect->arguments(), CommandLine::Raw);
|
|
||||||
return cmd;
|
|
||||||
});
|
|
||||||
|
|
||||||
setUpdater([this, scriptAspect] {
|
setCommandLineGetter([bufferedAspect, interpreterAspect, argumentsAspect, scriptAspect] {
|
||||||
const BuildTargetInfo bti = buildTargetInfo();
|
CommandLine cmd{interpreterAspect->currentInterpreter().command};
|
||||||
const QString script = bti.targetFilePath.toUserOutput();
|
if (!bufferedAspect->value())
|
||||||
setDefaultDisplayName(tr("Run %1").arg(script));
|
cmd.addArg("-u");
|
||||||
scriptAspect->setValue(script);
|
cmd.addArg(scriptAspect->filePath().fileName());
|
||||||
aspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.targetFilePath.parentDir());
|
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<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.targetFilePath.parentDir());
|
||||||
|
});
|
||||||
|
|
||||||
|
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()
|
if (auto pySideBuildStep = buildSteps->firstOfType<PySideBuildStep>())
|
||||||
{
|
pySideBuildStep->updatePySideProjectPath(pySideProjectPath);
|
||||||
const FilePath python = aspect<InterpreterAspect>()->currentInterpreter().command;
|
|
||||||
|
|
||||||
BuildStepList *buildSteps = target()->activeBuildConfiguration()->buildSteps();
|
for (FilePath &file : project()->files(Project::AllFiles)) {
|
||||||
if (auto pySideBuildStep = buildSteps->firstOfType<PySideBuildStep>())
|
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
|
||||||
pySideBuildStep->updateInterpreter(python);
|
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
|
||||||
|
PyLSConfigureAssistant::openDocumentWithPython(python, document);
|
||||||
for (FilePath &file : project()->files(Project::AllFiles)) {
|
PySideInstaller::checkPySideInstallation(python, document);
|
||||||
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
|
|
||||||
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
|
|
||||||
PyLSConfigureAssistant::openDocumentWithPython(python, document);
|
|
||||||
PySideInstaller::checkPySideInstallation(python, document);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
PythonRunConfigurationFactory::PythonRunConfigurationFactory()
|
PythonRunConfigurationFactory::PythonRunConfigurationFactory()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user