PyAPI: move bpy_types.py to a private module
Use an underscore prefix as this module should not be accessed directly.
This commit is contained in:
@@ -791,7 +791,7 @@ def pyfunc2sphinx(ident, fw, module_name, type_name, identifier, py_func, is_cla
|
||||
# would be listed in documentation which isn't useful.
|
||||
#
|
||||
# However, excluding all of them is also incorrect as it means class methods defined
|
||||
# in `bpy_types.py` for example are excluded, making some utility functions entirely hidden.
|
||||
# in `_bpy_types.py` for example are excluded, making some utility functions entirely hidden.
|
||||
if (bl_rna := getattr(py_func.__self__, "bl_rna", None)) is not None:
|
||||
if bl_rna.functions.get(identifier) is not None:
|
||||
return
|
||||
|
||||
@@ -405,7 +405,7 @@ def dump_rna_messages(msgs, reports, settings, verbose=False):
|
||||
return cls.__name__
|
||||
cls_id = ""
|
||||
bl_rna = getattr(cls, "bl_rna", None)
|
||||
# It seems that py-defined 'wrappers' RNA classes (like `MeshEdge` in `bpy_types.py`) need to be accessed
|
||||
# It seems that py-defined 'wrappers' RNA classes (like `MeshEdge` in `_bpy_types.py`) need to be accessed
|
||||
# once from `bpy.types` before they have a valid `bl_rna` member.
|
||||
# Weirdly enough, this is only triggered on release builds, debug builds somehow do not have that issue.
|
||||
if bl_rna is None:
|
||||
|
||||
@@ -649,7 +649,7 @@ CUSTOM_PY_UI_FILES = [
|
||||
os.path.join("scripts", "startup", "bl_operators"),
|
||||
os.path.join("scripts", "modules", "rna_prop_ui.py"),
|
||||
os.path.join("scripts", "modules", "rna_keymap_ui.py"),
|
||||
os.path.join("scripts", "modules", "bpy_types.py"),
|
||||
os.path.join("scripts", "modules", "_bpy_types.py"),
|
||||
os.path.join("scripts", "presets", "keyconfig"),
|
||||
]
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ def modules_from_path(path, loaded_modules):
|
||||
# Currently used for "startup" modules.
|
||||
_registered_module_names = []
|
||||
# Keep for comparisons, never ever reload this.
|
||||
import bpy_types as _bpy_types
|
||||
import _bpy_types
|
||||
|
||||
|
||||
def _register_module_call(mod):
|
||||
|
||||
@@ -144,7 +144,7 @@ class InfoStructRNA:
|
||||
if (self.py_class and not hasattr(bpy.types, self.identifier)) else
|
||||
"bpy.types"
|
||||
)
|
||||
if self.module_name == "bpy_types":
|
||||
if self.module_name == "_bpy_types":
|
||||
self.module_name = "bpy.types"
|
||||
|
||||
def build(self):
|
||||
|
||||
@@ -745,21 +745,21 @@ void BPy_init_modules(bContext *C)
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod);
|
||||
Py_DECREF(mod);
|
||||
|
||||
/* needs to be first so bpy_types can run */
|
||||
/* Needs to be first so `_bpy_types` can run. */
|
||||
PyObject *bpy_types = BPY_rna_types();
|
||||
PyModule_AddObject(bpy_types, "GeometrySet", BPyInit_geometry_set_type());
|
||||
PyModule_AddObject(mod, "types", bpy_types);
|
||||
|
||||
/* needs to be first so bpy_types can run */
|
||||
/* Needs to be first so `_bpy_types` can run. */
|
||||
BPY_library_load_type_ready();
|
||||
|
||||
BPY_rna_data_context_type_ready();
|
||||
|
||||
BPY_rna_gizmo_module(mod);
|
||||
|
||||
bpy_import_test("bpy_types");
|
||||
PyModule_AddObject(mod, "data", BPY_rna_module()); /* imports bpy_types by running this */
|
||||
bpy_import_test("bpy_types");
|
||||
bpy_import_test("_bpy_types");
|
||||
PyModule_AddObject(mod, "data", BPY_rna_module()); /* Imports `_bpy_types` by running this. */
|
||||
bpy_import_test("_bpy_types");
|
||||
BPY_rna_types_finalize_external_types(bpy_types);
|
||||
|
||||
PyModule_AddObject(mod, "props", BPY_rna_props());
|
||||
|
||||
@@ -8168,11 +8168,11 @@ static PyObject *pyrna_srna_ExternalType(StructRNA *srna)
|
||||
PyObject *newclass;
|
||||
|
||||
if (bpy_types_dict == nullptr) {
|
||||
PyObject *bpy_types = PyImport_ImportModuleLevel("bpy_types", nullptr, nullptr, nullptr, 0);
|
||||
PyObject *bpy_types = PyImport_ImportModuleLevel("_bpy_types", nullptr, nullptr, nullptr, 0);
|
||||
|
||||
if (bpy_types == nullptr) {
|
||||
PyErr_Print();
|
||||
CLOG_ERROR(BPY_LOG_RNA, "failed to find 'bpy_types' module");
|
||||
CLOG_ERROR(BPY_LOG_RNA, "failed to find '_bpy_types' module");
|
||||
return nullptr;
|
||||
}
|
||||
bpy_types_dict = PyModule_GetDict(bpy_types); /* Borrow. */
|
||||
@@ -8194,7 +8194,7 @@ static PyObject *pyrna_srna_ExternalType(StructRNA *srna)
|
||||
|
||||
if (tp_slots == nullptr) {
|
||||
CLOG_ERROR(
|
||||
BPY_LOG_RNA, "expected class '%s' to have __slots__ defined, see bpy_types.py", idname);
|
||||
BPY_LOG_RNA, "expected class '%s' to have __slots__ defined, see _bpy_types.py", idname);
|
||||
newclass = nullptr;
|
||||
}
|
||||
else if (PyTuple_GET_SIZE(tp_bases)) {
|
||||
@@ -8204,7 +8204,7 @@ static PyObject *pyrna_srna_ExternalType(StructRNA *srna)
|
||||
char pyob_info[256];
|
||||
PyC_ObSpitStr(pyob_info, sizeof(pyob_info), base_compare);
|
||||
CLOG_ERROR(BPY_LOG_RNA,
|
||||
"incorrect subclassing of SRNA '%s', expected '%s', see bpy_types.py",
|
||||
"incorrect subclassing of SRNA '%s', expected '%s', see _bpy_types.py",
|
||||
idname,
|
||||
pyob_info);
|
||||
newclass = nullptr;
|
||||
@@ -8234,7 +8234,7 @@ static PyObject *pyrna_srna_Subtype(StructRNA *srna)
|
||||
else if ((newclass = static_cast<PyObject *>(RNA_struct_py_type_get(srna)))) {
|
||||
/* Add a reference for the return value. */
|
||||
Py_INCREF(newclass);
|
||||
} /* Check if `bpy_types.py` module has the class defined in it. */
|
||||
} /* Check if `_bpy_types.py` module has the class defined in it. */
|
||||
else if ((newclass = pyrna_srna_ExternalType(srna))) {
|
||||
pyrna_subtype_set_rna(newclass, srna);
|
||||
/* Add a reference for the return value. */
|
||||
@@ -8851,13 +8851,13 @@ void BPY_rna_types_finalize_external_types(PyObject *submodule)
|
||||
|
||||
BLI_assert_msg(
|
||||
PyObject_IsSubclass(arg_value, (PyObject *)&pyrna_struct_Type),
|
||||
"Members of bpy_types.py which are not StructRNA sub-classes must use a \"_\" prefix!");
|
||||
"Members of _bpy_types.py which are not StructRNA sub-classes must use a \"_\" prefix!");
|
||||
|
||||
PointerRNA newptr;
|
||||
if (RNA_property_collection_lookup_string(&state->ptr.value(), state->prop, key_str, &newptr))
|
||||
{
|
||||
StructRNA *srna = srna_from_ptr(&newptr);
|
||||
/* Within the Python logic of `./scripts/modules/bpy_types.py`
|
||||
/* Within the Python logic of `./scripts/modules/_bpy_types.py`
|
||||
* it's possible this was already initialized. */
|
||||
if (RNA_struct_py_type_get(srna) == nullptr) {
|
||||
pyrna_subtype_set_rna(arg_value, srna);
|
||||
@@ -8872,7 +8872,7 @@ void BPY_rna_types_finalize_external_types(PyObject *submodule)
|
||||
}
|
||||
# endif
|
||||
CLOG_WARN(
|
||||
BPY_LOG_RNA, "bpy_types.py defines \"%.200s\" which is not a known RNA type!", key_str);
|
||||
BPY_LOG_RNA, "_bpy_types.py defines \"%.200s\" which is not a known RNA type!", key_str);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -9977,7 +9977,7 @@ void pyrna_alloc_types()
|
||||
{
|
||||
/* NOTE: This isn't essential to run on startup, since sub-types will lazy initialize.
|
||||
* But keep running in debug mode so we get immediate notification of bad class hierarchy
|
||||
* or any errors in "bpy_types.py" at load time, so errors don't go unnoticed. */
|
||||
* or any errors in `_bpy_types.py` at load time, so errors don't go unnoticed. */
|
||||
|
||||
#ifndef NDEBUG
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
* We should avoid adding code here, and prefer:
|
||||
* - `source/blender/makesrna/intern/rna_context.cc` using the RNA C API.
|
||||
* - `scripts/modules/bpy_types.py` when additions c an be written in Python.
|
||||
* - `scripts/modules/_bpy_types.py` when additions c an be written in Python.
|
||||
*
|
||||
* Otherwise functions can be added here as a last resort.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user