MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / run_plugin_command

Function run_plugin_command

src/python/plugin_runner.cpp:56–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54 } // anonymous namespace
55
56 int run_plugin_command(const lfs::core::args::PluginMode& mode) {
57 ensure_initialized();
58
59 int result = 0;
60 {
61 const GilAcquire gil;
62
63 switch (mode.command) {
64 case lfs::core::args::PluginMode::Command::CREATE: {
65 PyObjectGuard setup(PyImport_ImportModule("lfs_plugins.dev_setup"));
66 if (!setup) {
67 print_python_error();
68 result = 1;
69 break;
70 }
71
72 PyObjectGuard func(PyObject_GetAttrString(setup.get(), "create_plugin_with_venv"));
73 if (!func) {
74 print_python_error();
75 result = 1;
76 break;
77 }
78
79 const auto& pm = PackageManager::instance();
80 const std::string uv_path = lfs::core::path_to_utf8(pm.uv_path());
81 const std::string site_packages = lfs::core::path_to_utf8(pm.site_packages_dir());
82 const std::string typings_dir = lfs::core::path_to_utf8(lfs::core::getTypingsDir());
83 const std::string python_path = lfs::core::path_to_utf8(lfs::core::getEmbeddedPython());
84 if (uv_path.empty()) {
85 std::println(stderr, "Error: UV not found");
86 result = 1;
87 break;
88 }
89 if (python_path.empty()) {
90 std::println(stderr, "Error: Python executable not configured");
91 result = 1;
92 break;
93 }
94
95 PyObjectGuard args(PyTuple_Pack(1, PyUnicode_FromString(mode.name.c_str())));
96 PyObjectGuard kwargs(PyDict_New());
97 PyDict_SetItemString(kwargs.get(), "uv_path", PyUnicode_FromString(uv_path.c_str()));
98 PyDict_SetItemString(
99 kwargs.get(), "python_path", PyUnicode_FromString(python_path.c_str()));
100 PyDict_SetItemString(
101 kwargs.get(), "typings_dir", PyUnicode_FromString(typings_dir.c_str()));
102 PyDict_SetItemString(
103 kwargs.get(), "site_packages_dir", PyUnicode_FromString(site_packages.c_str()));
104
105 PyObjectGuard path(PyObject_Call(func.get(), args.get(), kwargs.get()));
106 if (!path) {
107 print_python_error();
108 result = 1;
109 break;
110 }
111
112 const char* path_str = PyUnicode_AsUTF8(path.get());
113 if (path_str) {

Callers 1

mainFunction · 0.85

Calls 12

ensure_initializedFunction · 0.85
print_python_errorFunction · 0.85
instanceFunction · 0.85
path_to_utf8Function · 0.85
getTypingsDirFunction · 0.85
getEmbeddedPythonFunction · 0.85
uv_pathMethod · 0.80
site_packages_dirMethod · 0.80
c_strMethod · 0.80
root_dirMethod · 0.80
getMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected