forked from qt-creator/qt-creator
Python: move python name cache to utils
Change-Id: I7f6d13a465be6de90aea64e7f19c92bca3ee6c19 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -77,25 +77,6 @@ struct PythonLanguageServerState
|
|||||||
FilePath pylsModulePath;
|
FilePath pylsModulePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
static QString pythonName(const FilePath &pythonPath)
|
|
||||||
{
|
|
||||||
static QHash<FilePath, QString> nameForPython;
|
|
||||||
if (!pythonPath.exists())
|
|
||||||
return {};
|
|
||||||
QString name = nameForPython.value(pythonPath);
|
|
||||||
if (name.isEmpty()) {
|
|
||||||
QtcProcess pythonProcess;
|
|
||||||
pythonProcess.setTimeoutS(2);
|
|
||||||
pythonProcess.setCommand({pythonPath, {"--version"}});
|
|
||||||
pythonProcess.runBlocking();
|
|
||||||
if (pythonProcess.result() != ProcessResult::FinishedWithSuccess)
|
|
||||||
return {};
|
|
||||||
name = pythonProcess.allOutput().trimmed();
|
|
||||||
nameForPython[pythonPath] = name;
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePath getPylsModulePath(CommandLine pylsCommand)
|
FilePath getPylsModulePath(CommandLine pylsCommand)
|
||||||
{
|
{
|
||||||
static QMutex mutex; // protect the access to the cache
|
static QMutex mutex; // protect the access to the cache
|
||||||
|
@@ -127,5 +127,24 @@ void openPythonRepl(QObject *parent, const FilePath &file, ReplType type)
|
|||||||
process->start();
|
process->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString pythonName(const FilePath &pythonPath)
|
||||||
|
{
|
||||||
|
static QHash<FilePath, QString> nameForPython;
|
||||||
|
if (!pythonPath.exists())
|
||||||
|
return {};
|
||||||
|
QString name = nameForPython.value(pythonPath);
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
QtcProcess pythonProcess;
|
||||||
|
pythonProcess.setTimeoutS(2);
|
||||||
|
pythonProcess.setCommand({pythonPath, {"--version"}});
|
||||||
|
pythonProcess.runBlocking();
|
||||||
|
if (pythonProcess.result() != ProcessResult::FinishedWithSuccess)
|
||||||
|
return {};
|
||||||
|
name = pythonProcess.allOutput().trimmed();
|
||||||
|
nameForPython[pythonPath] = name;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Python
|
} // namespace Python
|
||||||
|
@@ -33,6 +33,7 @@ namespace Internal {
|
|||||||
enum class ReplType { Unmodified, Import, ImportToplevel };
|
enum class ReplType { Unmodified, Import, ImportToplevel };
|
||||||
void openPythonRepl(QObject *parent, const Utils::FilePath &file, ReplType type);
|
void openPythonRepl(QObject *parent, const Utils::FilePath &file, ReplType type);
|
||||||
Utils::FilePath detectPython(const Utils::FilePath &documentPath);
|
Utils::FilePath detectPython(const Utils::FilePath &documentPath);
|
||||||
|
QString pythonName(const Utils::FilePath &pythonPath);
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Python
|
} // namespace Python
|
||||||
|
Reference in New Issue
Block a user