Refactor BKE_bpath module.

The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.

Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
   topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
  callback that belongs in `lib_id.c` user code.

NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).

NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D13381
This commit is contained in:
Bastien Montagne
2021-11-29 14:20:58 +01:00
committed by Bastien Montagne
parent 6ae34bb071
commit e5e8db73df
49 changed files with 946 additions and 721 deletions

View File

@@ -94,10 +94,13 @@ static PyObject *bpy_script_paths(PyObject *UNUSED(self))
return ret;
}
static bool bpy_blend_paths_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src)
static bool bpy_blend_foreach_path_cb(BPathForeachPathData *bpath_data,
char *UNUSED(path_dst),
const char *path_src)
{
PyList_APPEND((PyObject *)userdata, PyC_UnicodeFromByte(path_src));
return false; /* never edits the path */
PyObject *py_list = bpath_data->user_data;
PyList_APPEND(py_list, PyC_UnicodeFromByte(path_src));
return false; /* Never edits the path. */
}
PyDoc_STRVAR(bpy_blend_paths_doc,
@@ -115,7 +118,7 @@ PyDoc_STRVAR(bpy_blend_paths_doc,
" :rtype: list of strings\n");
static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
int flag = 0;
eBPathForeachFlag flag = 0;
PyObject *list;
bool absolute = false;
@@ -137,18 +140,21 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
}
if (absolute) {
flag |= BKE_BPATH_TRAVERSE_ABS;
flag |= BKE_BPATH_FOREACH_PATH_ABSOLUTE;
}
if (!packed) {
flag |= BKE_BPATH_TRAVERSE_SKIP_PACKED;
flag |= BKE_BPATH_FOREACH_PATH_SKIP_PACKED;
}
if (local) {
flag |= BKE_BPATH_TRAVERSE_SKIP_LIBRARY;
flag |= BKE_BPATH_FOREACH_PATH_SKIP_LINKED;
}
list = PyList_New(0);
BKE_bpath_traverse_main(G_MAIN, bpy_blend_paths_visit_cb, flag, (void *)list);
BKE_bpath_foreach_path_main(&(BPathForeachPathData){.bmain = G_MAIN,
.callback_function = bpy_blend_foreach_path_cb,
.flag = flag,
.user_data = list});
return list;
}