MCPcopy Create free account
hub / github.com/Prograda/Skybolt / isPythonOnPath

Function isPythonOnPath

src/Skybolt/SkyboltEngine/FindPython.cpp:22–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21
22bool isPythonOnPath(unsigned int majorVersion, unsigned int minorVersion)
23{
24 namespace bp = boost::process;
25 // Python executable names on windows and linux.
26 // Note that we don't include "py" as it only redirects to python - finding py does not mean Python is on the PATH.
27 std::string majorVersionString = std::to_string(majorVersion);
28 std::string majorMinorVersionString = majorVersionString + "." + std::to_string(minorVersion);
29 std::vector<std::string> commands = {"python", "python" + majorVersionString, "python" + majorMinorVersionString};
30
31 for (const auto& command : commands)
32 {
33 std::string result;
34 bp::ipstream output;
35 try
36 {
37 // Execute command and capture standard output
38 bp::child c(command + " --version", bp::std_out > output, bp::std_err > bp::null);
39 std::getline(output, result);
40 c.wait(); // wait for process to exit
41
42 if (result.find("Python " + majorMinorVersionString) != std::string::npos)
43 {
44 return true; // Found Python
45 }
46 } catch (const std::exception& e)
47 {
48 }
49 }
50
51 return false;
52}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected