Skip to content

Commit 166c788

Browse files
committed
PythonCodeCompletion: Allow user to put python setup commands in ~/.codeblocks/share/codeblocks/python/python_completion_config.py (primary purpose is to add directories of cached modules to the python path)
1 parent a9e97ac commit 166c788

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

PythonCodeCompletion/PythonCodeCompletion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ void PythonCodeCompletion::OnAttach()
8888

8989
ConfigManager *mgr=Manager::Get()->GetConfigManager(_T("PythonCC"));
9090

91+
wxString server_config_module = ConfigManager::GetFolder(sdDataUser)+_T("/python/python_completion_config.py");
92+
9193
wxString script = GetExtraFile(_T("/python/python_completion_server.py"));
9294
if(script==wxEmptyString)
9395
{
@@ -96,7 +98,7 @@ void PythonCodeCompletion::OnAttach()
9698
}
9799
#ifndef EMBEDDER_DEBUG
98100
int port = -1; // Port == -1 uses pipe to do RPC over redirected stdin/stdout of the process, otherwise uses a socket
99-
wxString command = wxString::Format(_T("python -u %s %i"),script.c_str(),port);
101+
wxString command = wxString::Format(_T("python -u %s %i %s"),script.c_str(),port, server_config_module.c_str());
100102
#else
101103
int port = 3456;
102104
wxString command = wxString::Format(_T("xterm -e python -u %s %i"),script.c_str(),port);

PythonCodeCompletion/python/python_completion_server.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def cmd_err():
167167
sys.exit()
168168

169169
if __name__=='__main__':
170-
if len(sys.argv)!=2:
170+
if len(sys.argv)<2:
171171
port=8001
172172
else:
173173
try:
@@ -176,6 +176,17 @@ def cmd_err():
176176
cmd_err()
177177
if port<-1:
178178
cmd_err()
179+
if len(sys.argv)>2:
180+
config_module_path = sys.argv[2]
181+
config_path, module_name = os.path.split(config_module_path)
182+
module_name = os.path.splitext(module_name)[0]
183+
import importlib
184+
try:
185+
sys.path.insert(0, config_path)
186+
importlib.import_module(module_name)
187+
except:
188+
#TODO: Do something better than silently failing here
189+
pass
179190

180191
server=PythonCompletionServer(port)
181192
server.run()

0 commit comments

Comments
 (0)