| 4238 | } |
| 4239 | |
| 4240 | void |
| 4241 | NATRON_PYTHON_NAMESPACE::getFunctionArguments(const std::string& pyFunc, |
| 4242 | std::string* error, |
| 4243 | std::vector<std::string>* args) |
| 4244 | { |
| 4245 | #ifdef NATRON_RUN_WITHOUT_PYTHON |
| 4246 | |
| 4247 | return; |
| 4248 | #endif |
| 4249 | std::stringstream ss; |
| 4250 | ss << "import inspect\n"; |
| 4251 | ss << "args_spec = inspect.getargspec(" << pyFunc << ")\n"; |
| 4252 | std::string script = ss.str(); |
| 4253 | std::string output; |
| 4254 | bool ok = NATRON_PYTHON_NAMESPACE::interpretPythonScript(script, error, &output); |
| 4255 | if (!ok) { |
| 4256 | throw std::runtime_error("NATRON_PYTHON_NAMESPACE::getFunctionArguments(): interpretPythonScript(" + script + " failed!"); |
| 4257 | } |
| 4258 | PyObject* mainModule = NATRON_PYTHON_NAMESPACE::getMainModule(); |
| 4259 | PyObject* args_specObj = 0; |
| 4260 | PythonGILLocker pgl; |
| 4261 | |
| 4262 | if ( PyObject_HasAttrString(mainModule, "args_spec") ) { |
| 4263 | args_specObj = PyObject_GetAttrString(mainModule, "args_spec"); |
| 4264 | } |
| 4265 | assert(args_specObj); |
| 4266 | PyObject* argListObj = 0; |
| 4267 | |
| 4268 | if (args_specObj) { |
| 4269 | argListObj = PyTuple_GetItem(args_specObj, 0); |
| 4270 | assert(argListObj); |
| 4271 | if (argListObj) { |
| 4272 | // size = PyObject_Size(argListObj) |
| 4273 | assert( PyList_Check(argListObj) ); |
| 4274 | Py_ssize_t size = PyList_Size(argListObj); |
| 4275 | for (Py_ssize_t i = 0; i < size; ++i) { |
| 4276 | PyObject* itemObj = PyList_GetItem(argListObj, i); |
| 4277 | assert(itemObj); |
| 4278 | if (itemObj) { |
| 4279 | std::string itemName = PyStringToStdString(itemObj); |
| 4280 | assert( !itemName.empty() ); |
| 4281 | if ( !itemName.empty() ) { |
| 4282 | args->push_back(itemName); |
| 4283 | } |
| 4284 | } |
| 4285 | } |
| 4286 | if ( (PyTuple_GetItem(args_specObj, 1) != Py_None) || (PyTuple_GetItem(args_specObj, 2) != Py_None) ) { |
| 4287 | error->append("Function contains variadic arguments which is unsupported."); |
| 4288 | |
| 4289 | return; |
| 4290 | } |
| 4291 | } |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | /** |
| 4296 | * @brief Given a fullyQualifiedName, e.g: app1.Group1.Blur1 |
nothing calls this directly
no test coverage detected