| 57 | |
| 58 | |
| 59 | void ZVecPyConfig::Initialize(pybind11::module_ &m) { |
| 60 | m.def("Initialize", [](py::args args, py::kwargs kwargs) -> py::none { |
| 61 | py::dict config_dict; |
| 62 | // parse args |
| 63 | for (auto &arg : args) { |
| 64 | if (py::isinstance<py::dict>(arg)) { |
| 65 | for (auto item : arg.cast<py::dict>()) { |
| 66 | config_dict[item.first] = item.second; |
| 67 | } |
| 68 | } else { |
| 69 | throw py::type_error("Positional argument must be a dict if provided"); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // parser kwargs |
| 74 | if (kwargs) { |
| 75 | for (auto item : kwargs) { |
| 76 | config_dict[item.first] = item.second; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (config_dict.empty()) { |
| 81 | return py::none(); |
| 82 | } |
| 83 | |
| 84 | GlobalConfig::ConfigData data; |
| 85 | // config memory_limit_mb |
| 86 | if (has_key(config_dict, "memory_limit_mb")) { |
| 87 | auto mb = get_if<int64_t>(config_dict, "memory_limit_mb").value(); |
| 88 | if (mb <= 0) throw py::value_error("memory_limit_mb must be positive"); |
| 89 | data.memory_limit_bytes = static_cast<uint64_t>(mb) * 1024 * 1024; |
| 90 | } |
| 91 | |
| 92 | // config log |
| 93 | bool has_log_type = has_key(config_dict, "log_type"); |
| 94 | bool has_log_level = has_key(config_dict, "log_level"); |
| 95 | if (has_log_type || has_log_level) { |
| 96 | std::string log_type = "console"; |
| 97 | std::string log_level_str = "warn"; |
| 98 | |
| 99 | if (has_log_type) { |
| 100 | log_type = config_dict["log_type"].cast<std::string>(); |
| 101 | } |
| 102 | if (has_log_level) { |
| 103 | log_level_str = config_dict["log_level"].cast<std::string>(); |
| 104 | } |
| 105 | auto log_level = str_to_loglevel(log_level_str); |
| 106 | if (iequals(log_type, "file")) { |
| 107 | std::string dir = DEFAULT_LOG_DIR; |
| 108 | std::string basename = DEFAULT_LOG_BASENAME; |
| 109 | uint32_t file_size = DEFAULT_LOG_FILE_SIZE; |
| 110 | uint32_t overdue_days = DEFAULT_LOG_OVERDUE_DAYS; |
| 111 | |
| 112 | if (has_key(config_dict, "log_dir")) { |
| 113 | dir = get_if<std::string>(config_dict, "log_dir").value(); |
| 114 | } |
| 115 | if (has_key(config_dict, "log_basename")) { |
| 116 | basename = get_if<std::string>(config_dict, "log_basename").value(); |
nothing calls this directly
no test coverage detected