diff --git a/debugger/debugjob.h b/debugger/debugjob.h --- a/debugger/debugjob.h +++ b/debugger/debugjob.h @@ -43,6 +43,7 @@ QString m_interpreter; QStringList m_args; QUrl m_workingDirectory; + QString m_envProfileName; private slots: void standardOutputReceived(QStringList lines); diff --git a/debugger/debugjob.cpp b/debugger/debugjob.cpp --- a/debugger/debugjob.cpp +++ b/debugger/debugjob.cpp @@ -39,7 +39,8 @@ QStringList program; QString debuggerUrl = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdevpythonsupport/debugger", QStandardPaths::LocateDirectory) + "/kdevpdb.py"; program << m_interpreter << "-u" << debuggerUrl << m_scriptUrl.toLocalFile() << m_args; - m_session = new DebugSession(program, m_workingDirectory); + // Inject environment + m_session = new DebugSession(program, m_workingDirectory, m_envProfileName); setStandardToolView(KDevelop::IOutputView::DebugView); setBehaviours(KDevelop::IOutputView::Behaviours(KDevelop::IOutputView::AllowUserClose) | KDevelop::IOutputView::AutoScroll); diff --git a/debugger/debugsession.h b/debugger/debugsession.h --- a/debugger/debugsession.h +++ b/debugger/debugsession.h @@ -42,7 +42,8 @@ { Q_OBJECT public: - DebugSession(QStringList program, const QUrl& workingDirectory); + DebugSession(QStringList program, const QUrl& workingDirectory, + const QString& envProfileName); ~DebugSession() override; IBreakpointController* breakpointController() const override; @@ -220,6 +221,7 @@ QStringList m_program; QList m_commandQueue; const QUrl& m_workingDirectory; + const QString m_envProfileName; private: /// objects to notify next QPointer m_nextNotifyObject; diff --git a/debugger/debugsession.cpp b/debugger/debugsession.cpp --- a/debugger/debugsession.cpp +++ b/debugger/debugsession.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "debugsession.h" #include "pdbframestackmodel.h" @@ -52,12 +53,14 @@ namespace Python { -DebugSession::DebugSession(QStringList program, const QUrl &workingDirectory) : +DebugSession::DebugSession(QStringList program, const QUrl &workingDirectory, + const QString& envProfileName) : IDebugSession() , m_breakpointController(nullptr) , m_variableController(nullptr) , m_frameStackModel(nullptr) , m_workingDirectory(workingDirectory) + , m_envProfileName(envProfileName) , m_nextNotifyMethod(nullptr) , m_inDebuggerData(0) { @@ -91,6 +94,17 @@ m_debuggerProcess->setOutputChannelMode(KProcess::SeparateChannels); m_debuggerProcess->blockSignals(true); m_debuggerProcess->setWorkingDirectory(m_workingDirectory.path()); + + const KDevelop::EnvironmentProfileList environmentProfiles(KSharedConfig::openConfig()); + const auto environment = environmentProfiles.variables(m_envProfileName); + + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + for(auto i = environment.cbegin(); i != environment.cend(); i++ ) + { + env.insert(i.key(), i.value()); + } + m_debuggerProcess->setProcessEnvironment(env); + connect(m_debuggerProcess, &QProcess::readyReadStandardOutput, this, &DebugSession::dataAvailable); connect(m_debuggerProcess, SIGNAL(finished(int)), this, SLOT(debuggerQuit(int))); connect(this, &DebugSession::debuggerReady, this, &DebugSession::checkCommandQueue); diff --git a/debugger/pdblauncher.cpp b/debugger/pdblauncher.cpp --- a/debugger/pdblauncher.cpp +++ b/debugger/pdblauncher.cpp @@ -38,6 +38,7 @@ #include #include "debuggerdebug.h" +#include namespace Python { @@ -115,6 +116,18 @@ job->m_interpreter = interpreter; job->m_args = iface->arguments(cfg, err); job->m_workingDirectory = wd; + + const KDevelop::EnvironmentProfileList environmentProfiles(KSharedConfig::openConfig()); + QString envProfileName = iface->environmentProfileName(cfg); + + if (envProfileName.isEmpty()) { + qCWarning(KDEV_PYTHON_DEBUGGER) << "No environment profile specified, looks like a broken " + "configuration, please check run configuration " << cfg->name() << + ". Using default environment profile."; + envProfileName = environmentProfiles.defaultProfileName(); + } + job->m_envProfileName = envProfileName; + QList l; l << job; return new KDevelop::ExecuteCompositeJob( KDevelop::ICore::self()->runController(), l );