MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / detectPython

Function detectPython

lib/cppcheck.cpp:408–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408static std::string detectPython(const CppCheck::ExecuteCmdFn &executeCommand)
409{
410#ifdef _WIN32
411 const char *py_exes[] = { "python3.exe", "python.exe" };
412#else
413 const char *py_exes[] = { "python3", "python" };
414#endif
415 for (const char* py_exe : py_exes) {
416 std::string out;
417#ifdef _MSC_VER
418 // FIXME: hack to avoid debug assertion with _popen() in executeCommand() for non-existing commands
419 const std::string cmd = std::string(py_exe) + " --version >NUL 2>&1";
420 if (system(cmd.c_str()) != 0) {
421 // TODO: get more detailed error?
422 continue;
423 }
424#endif
425 if (executeCommand(py_exe, split("--version"), "2>&1", out) == EXIT_SUCCESS && startsWith(out, "Python ") && std::isdigit(out[7])) {
426 return py_exe;
427 }
428 }
429 return "";
430}
431
432/**
433 * @throws InternalError thrown when execution fails

Callers 1

executeAddonFunction · 0.85

Calls 2

splitFunction · 0.85
startsWithFunction · 0.70

Tested by

no test coverage detected