MCPcopy Create free account
hub / github.com/NatLabRockies/SAM / WritePythonConfig

Function WritePythonConfig

src/pythonhandler.cpp:116–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116void WritePythonConfig(const std::string& configPath, const PythonConfig& config){
117 std::ofstream configFile;
118 configFile.open(configPath);
119
120 rapidjson::Document configObj;
121 configObj.SetObject();
122 configObj.AddMember(rapidjson::Value("python_version", configObj.GetAllocator()).Move(), rapidjson::Value(config.pythonVersion.c_str(), configObj.GetAllocator()).Move(), configObj.GetAllocator());
123 configObj.AddMember(rapidjson::Value("miniconda_version", configObj.GetAllocator()).Move(), rapidjson::Value(config.minicondaVersion.c_str(), configObj.GetAllocator()).Move(), configObj.GetAllocator());
124 configObj.AddMember(rapidjson::Value("exec_path", configObj.GetAllocator()).Move(), rapidjson::Value(config.execPath.c_str(), configObj.GetAllocator()).Move(), configObj.GetAllocator());
125 configObj.AddMember(rapidjson::Value("pip_path", configObj.GetAllocator()).Move(), rapidjson::Value(config.pipPath.c_str(), configObj.GetAllocator()).Move(), configObj.GetAllocator());
126 // array
127 rapidjson::Value json_arr;
128 json_arr.SetArray();
129 for (auto& i : config.packages) {
130 json_arr.PushBack(rapidjson::Value(i.c_str(), configObj.GetAllocator()), configObj.GetAllocator());
131 }
132 configObj.AddMember(rapidjson::Value("packages", configObj.GetAllocator()).Move(), json_arr.Move(), configObj.GetAllocator());
133 // object
134 rapidjson::Value json_obj;
135 json_obj.SetObject();
136 for (auto& i : config.options) {
137 json_obj.AddMember(rapidjson::Value(i.first.c_str(), configObj.GetAllocator()).Move(), rapidjson::Value(i.second.c_str(), configObj.GetAllocator()).Move(), configObj.GetAllocator());
138 }
139 configObj.AddMember(rapidjson::Value("options", configObj.GetAllocator()).Move(), json_obj.Move(), configObj.GetAllocator());
140
141 rapidjson::StringBuffer buffer;
142 buffer.Clear();
143 rapidjson::PrettyWriter<rapidjson::StringBuffer, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator, rapidjson::kWriteNanAndInfFlag> writer(buffer);
144
145 configObj.Accept(writer);
146 configFile << buffer.GetString();
147 configFile.close();
148}
149
150bool CheckPythonInstalled(const PythonConfig& config){
151 return !config.execPath.empty() && !config.pipPath.empty();

Callers 1

InstallPythonPackageMethod · 0.85

Calls 4

SetObjectMethod · 0.80
SetArrayMethod · 0.45
ClearMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected