Rigify automatically link UI text file in 2.8
Assoc text with rig via a pointer property.
To test, in a file named &quot;RIG.blend&quot; have asscociated all armatures with an internal  text file &quot;foo.py&quot;. An object using the armature is added to &quot;Rig&quot; collection.
Ran the script below  and saved the file.
import bpy
from bpy.props import PointerProperty
from bpy.types import Text, Armature
context = bpy.context

Armature.ui_text = PointerProperty(
        type=Text
        )
        
if __name__ == &quot;__main__&quot;:
    for arm in bpy.data.armatures:
        arm.ui_text = bpy.data.texts.get(&quot;foo.py&quot;)

Result of linking collection &quot;Rig&quot; from &quot;RIG.blend&quot; to a new file includes the linked text &quot;foo.py&quot;

Note this is a Probable dupe of How to make a Text File dependent of an Armature object so that it appends with it to other projects?
and it is pointed out in accepted answer that this can also be done as a one off single python console code line, via a custom property.
Using a pointer property with a poll, as demonstrated here https://blender.stackexchange.com/a/193608/15543 is a quick way to make a UI.  The example is for a pointer to an object, but same principal applies for texts. eg could choose from any or all texts in blend to assoc with armature depending on poll.
Have linked the object to a bpy.types.Armature object. Could instead link to the object or the collection.