Page MenuHome

LibLink/Append: Port `bpy.data.libraries.load` to new `BKE_blendfile_link_append` module.
ClosedPublic

Authored by Bastien Montagne (mont29) on Nov 23 2021, 12:25 PM.

Details

Summary

Note that this fully replaces the 'PyCapsule' storage of linked/appended items
in the python API code by the generic storage of items in the
BlendfileLinkAppendContext data.

Diff Detail

Repository
rB Blender

Event Timeline

Bastien Montagne (mont29) requested review of this revision.Nov 23 2021, 12:25 PM
Bastien Montagne (mont29) created this revision.

Running into an assert when doing nothing, I expect this can just be removed:

import bpy
with bpy.data.libraries.load("/path/to/untitled_simple.blend", link=True) as (data_from, data_to):
    print(data_from, data_to)

Asserts with:

BLI_assert(lapp_context->num_items && lapp_context->num_libraries);

... commenting for now as it seems harmless.

Previously there was a warning if the ID block couldn't be found.

Could the warning be added back? load: '/path/to/untitled_simple.blend' does not contain objects["Missing"]

While it would be good to support detecting ID's that fail to load as part of the API in a way the script author can inspect, unless this is supported - warning seems reasonable as part of a patch that updates the API usage.

source/blender/python/intern/bpy_library_load.c
361–363

There should be a comment explaining why the ID-codes might not match.

This reads as if it might leave the list index unset which creates a bad/corrupt list which will likely crash on access).

If the list item at py_list_index is guaranteed to be set they should be a comment explaining the conditions under which this would happen.

Campbell Barton (campbellbarton) requested changes to this revision.Nov 30 2021, 10:50 AM
This revision now requires changes to proceed.Nov 30 2021, 10:50 AM

Running into an assert when doing nothing, I expect this can just be removed:

import bpy
with bpy.data.libraries.load("/path/to/untitled_simple.blend", link=True) as (data_from, data_to):
    print(data_from, data_to)

Asserts with:

BLI_assert(lapp_context->num_items && lapp_context->num_libraries);

... commenting for now as it seems harmless.

Changed code in BKE_blendfile_link to better deal with empty items case.

source/blender/python/intern/bpy_library_load.c
361–363

Since the py code loops over ID types and then items in each ID type, the whole list of items in lapp_context is looped over for each ID type, so there will be a lot of items that do not match the current id_code, therefore the early return. Will add a comment about this.

And unless bpy_lib_exit or BKE_blendfile_ code is buggy, there should be no way to get an unset item in py_list_index - worst case it would just keep the id name set by user in python code, right? But even this should not happen.

Previously there was a warning if the ID block couldn't be found.

Could the warning be added back? load: '/path/to/untitled_simple.blend' does not contain objects["Missing"]

While it would be good to support detecting ID's that fail to load as part of the API in a way the script author can inspect, unless this is supported - warning seems reasonable as part of a patch that updates the API usage.

Added back this error message, was less difficult than I thought in the end...

Bastien Montagne (mont29) marked an inline comment as done.Nov 30 2021, 11:31 AM

*Edit* had note about the assert but this was resolved in rB6f460b76fec18da63d5e7ed8f7ee94a08d0f4719

source/blender/python/intern/bpy_library_load.c
363

typo being

This revision is now accepted and ready to land.Nov 30 2021, 1:21 PM
Bastien Montagne (mont29) marked an inline comment as done.Nov 30 2021, 3:03 PM