| 499 | } |
| 500 | |
| 501 | std::vector<std::string> discover_enabled_plugins_locked() { |
| 502 | std::vector<std::string> names; |
| 503 | |
| 504 | PyObject* lf = import_lichtfeld_module("Failed to import lichtfeld for plugin discovery"); |
| 505 | if (!lf) { |
| 506 | return names; |
| 507 | } |
| 508 | |
| 509 | PyObject* plugins = PyObject_GetAttrString(lf, "plugins"); |
| 510 | if (!plugins) { |
| 511 | Py_DECREF(lf); |
| 512 | return names; |
| 513 | } |
| 514 | |
| 515 | PyObject* discover = PyObject_GetAttrString(plugins, "discover"); |
| 516 | if (!discover) { |
| 517 | Py_DECREF(plugins); |
| 518 | Py_DECREF(lf); |
| 519 | return names; |
| 520 | } |
| 521 | |
| 522 | PyObject* discovered = PyObject_CallNoArgs(discover); |
| 523 | if (!discovered) { |
| 524 | PyErr_Print(); |
| 525 | Py_DECREF(discover); |
| 526 | Py_DECREF(plugins); |
| 527 | Py_DECREF(lf); |
| 528 | return names; |
| 529 | } |
| 530 | |
| 531 | // Pre-register all discovered plugins so load() skips re-discovery |
| 532 | PyObject* mgr_mod = PyImport_ImportModule("lfs_plugins.manager"); |
| 533 | if (mgr_mod) { |
| 534 | PyObject* mgr_cls = PyObject_GetAttrString(mgr_mod, "PluginManager"); |
| 535 | if (mgr_cls) { |
| 536 | PyObject* mgr = PyObject_CallMethod(mgr_cls, "instance", nullptr); |
| 537 | if (mgr) { |
| 538 | PyObject* result = PyObject_CallMethod(mgr, "pre_register", "O", discovered); |
| 539 | Py_XDECREF(result); |
| 540 | Py_DECREF(mgr); |
| 541 | } |
| 542 | Py_DECREF(mgr_cls); |
| 543 | } |
| 544 | Py_DECREF(mgr_mod); |
| 545 | } |
| 546 | |
| 547 | PyObject* settings_mod = PyImport_ImportModule("lfs_plugins.settings"); |
| 548 | PyObject* settings_mgr = nullptr; |
| 549 | if (settings_mod) { |
| 550 | PyObject* cls = PyObject_GetAttrString(settings_mod, "SettingsManager"); |
| 551 | if (cls) { |
| 552 | PyObject* instance = PyObject_CallMethod(cls, "instance", nullptr); |
| 553 | if (instance) { |
| 554 | settings_mgr = instance; |
| 555 | } |
| 556 | Py_DECREF(cls); |
| 557 | } |
| 558 | Py_DECREF(settings_mod); |
no test coverage detected