| 735 | } |
| 736 | |
| 737 | void BPy_init_modules(bContext *C) |
| 738 | { |
| 739 | PyObject *mod; |
| 740 | |
| 741 | /* Needs to be first since this dir is needed for future modules */ |
| 742 | const std::optional<std::string> modpath = BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, |
| 743 | "modules"); |
| 744 | if (modpath.has_value()) { |
| 745 | // printf("bpy: found module path '%s'.\n", modpath); |
| 746 | PyObject *sys_path = PySys_GetObject("path"); /* borrow */ |
| 747 | PyObject *py_modpath = PyC_UnicodeFromStdStr(modpath.value()); |
| 748 | PyList_Insert(sys_path, 0, py_modpath); /* add first */ |
| 749 | Py_DECREF(py_modpath); |
| 750 | } |
| 751 | else { |
| 752 | printf("bpy: couldn't find 'scripts/modules', blender probably won't start.\n"); |
| 753 | } |
| 754 | /* stand alone utility modules not related to blender directly */ |
| 755 | IDProp_Init_Types(); /* not actually a submodule, just types */ |
| 756 | IDPropertyUIData_Init_Types(); |
| 757 | #ifdef WITH_FREESTYLE |
| 758 | Freestyle_Init(); |
| 759 | #endif |
| 760 | |
| 761 | mod = PyModule_New("_bpy"); |
| 762 | |
| 763 | /* add the module so we can import it */ |
| 764 | PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod); |
| 765 | Py_DECREF(mod); |
| 766 | |
| 767 | /* Needs to be first so `_bpy_types` can run. */ |
| 768 | PyObject *bpy_types = BPY_rna_types(); |
| 769 | PyModule_AddObject(bpy_types, "GeometrySet", BPyInit_geometry_set_type()); |
| 770 | PyModule_AddObject(bpy_types, "InlineShaderNodes", BPyInit_inline_shader_nodes_type()); |
| 771 | PyModule_AddObject(mod, "types", bpy_types); |
| 772 | |
| 773 | /* Needs to be first so `_bpy_types` can run. */ |
| 774 | BPY_library_load_type_ready(); |
| 775 | |
| 776 | BPY_rna_data_context_type_ready(); |
| 777 | |
| 778 | BPY_rna_gizmo_module(mod); |
| 779 | |
| 780 | /* Important to internalizes `_bpy_types` before creating RNA instances. */ |
| 781 | { |
| 782 | /* Set a dummy module so the `_bpy_types.py` can access `bpy.types.ID` |
| 783 | * without a null pointer dereference when instancing types. */ |
| 784 | PyObject *bpy_types_dict_dummy = PyDict_New(); |
| 785 | BPY_rna_types_dict_set(bpy_types_dict_dummy); |
| 786 | PyObject *bpy_types_module_py = bpy_import_test("_bpy_types"); |
| 787 | /* Something has gone wrong if this is ever populated. */ |
| 788 | BLI_assert(PyDict_GET_SIZE(bpy_types_dict_dummy) == 0); |
| 789 | Py_DECREF(bpy_types_dict_dummy); |
| 790 | |
| 791 | PyObject *bpy_types_module_py_dict = PyModule_GetDict(bpy_types_module_py); |
| 792 | BPY_rna_types_dict_set(bpy_types_module_py_dict); |
| 793 | } |
| 794 | PyModule_AddObject(mod, "data", BPY_rna_module()); |
no test coverage detected