[Bf-committers] Python RNA Type Registration
ideasman42 at gmail.com
Mon Aug 2 16:52:25 CEST 2010
On Mon, Aug 2, 2010 at 12:38 PM, Campbell Barton <ideasman42 at gmail.com> wrote:
> On Mon, Aug 2, 2010 at 2:14 AM, Martin Poirier <theeth at yahoo.com> wrote:
>> As mentioned during meeting, now that most of the bugs with rna types are fixed, I really think it's time to revisit my earlier proposal for metaclass based automatic registration.
>> Here was the proposal: http://lists.blender.org/pipermail/bf-committers/2010-February/026328.html
>> And here's the updated patch: http://blenderartists.org/~theeth/bf/register.patch
>> Previous criticism was that it didn't handle running stuff from the text window (that's fixed now) and that it made debugging harder (during development, I added debug code that would spit out a list of all registered type, the module they came from (with complete back trace to declaration path), the order they were loaded in and so forth).
>> Any other questions or objections, I'd be happy to discuss.
> Looks good, give useful backtraces and removes class list cruft,
> you'll probably want to commit this patch yourself.
> * would prefer not to have to subclass 2 types, but guess we cant get
> around this, no big deal. eg.
> class PHYSICS_PT_domain_particles(PhysicButtonsPanel, bpy.types.Panel):
> * addons will need LoadModule() called from WM_OT_addon_enable, at the
> moment they use the old style register.
> * many addons will need updating, (heads up for Luca and Brendon!)
> * perhaps we could make register/unregister optional class methods and
> remove from the module, have to think about this, it would be annoying
> if you didn't want to register a class but DID want to run
> register/unregister functions though currently we don't do this AFAIK.
> - Campbell
Updated addons, they should all register/unregister without problems now.
it ended up being very difficult to load a module (to inspect it), but
not register its classes, in a way that let you register them later.
I did manage to get register and unregister to work but it was quite
messy involving overrides in bpy_types.py
So rather then loading the scripts at all, python has an 'ast' module
which can extract variables from a python script without running it.
Parsing whole file is slow but it only needs to extract a single
dictionary variable in this case so it can just scan the header for
This now has the benifit that we can...
1) list addons with description etc online without the security risk
of executing a script.
2) only download the header of a file (first ~100 lines would do), to
quickly list an online repo.
Luca is looking into getting scripts from an online repo.
More information about the Bf-committers