diff options
author | David Schulz <david.schulz@qt.io> | 2019-10-25 09:15:59 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-10-30 08:46:12 +0000 |
commit | 6664d78ded334264c3486c0b9472b23f8f3fc2e0 (patch) | |
tree | 88954987cd04285e4c94d3e74e75573387ff1a51 /src/plugins/python/pythonutils.cpp | |
parent | 519fc4ec72b1c59b2485bde0e02191b21506d4af (diff) | |
download | qt-creator-6664d78ded334264c3486c0b9472b23f8f3fc2e0.tar.gz |
Python: detect virtual environments for documents and projects
After opening a document or project the directory hierarchy is looked up
for a Scripts/(activate && python.exe) on windows or bin/(activate &&
python) on unix. This is the usual structure of python virtual
environments. If such a folder is found add the python from that folder
to the list of configured interpreters in the settings, set it as the
current interpreter for the project and try to open the corresponding
language server.
Change-Id: I038c309ea2988f9370194330d250d1515beac0a0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r-- | src/plugins/python/pythonutils.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index 86ee34e922..aa7051b396 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -175,6 +175,11 @@ static FilePath detectPython(const FilePath &documentPath) } } + // check whether this file is inside a python virtual environment + QList<Interpreter> venvInterpreters = PythonSettings::detectPythonVenvs(documentPath); + if (!python.exists()) + python = venvInterpreters.value(0).command; + if (!python.exists()) python = PythonSettings::defaultInterpreter().command; @@ -248,7 +253,13 @@ public: ? QString{"python-language-server[pyflakes]"} : QString{"python-language-server[all]"}; - m_process.start(m_python.toString(), {"-m", "pip", "install", "--user", pylsVersion}); + QStringList arguments = {"-m", "pip", "install", pylsVersion}; + + // add --user to global pythons, but skip it for venv pythons + if (!QDir(m_python.parentDir().toString()).exists("activate")) + arguments << "--user"; + + m_process.start(m_python.toString(), arguments); Core::MessageManager::write(tr("Running \"%1 %2\" to install Python language server") .arg(m_process.program(), m_process.arguments().join(' '))); |