4
$\begingroup$

I have noticed that when creating addon, if the bl_info is create with variable. The script will break the addon system. Causing disappear tab after restarting blender:

desc = 'Run script in any space with given name of script'
import bpy

bl_info = {
    "name": "Run specified script in all context",
    "description": desc,  # Here, a variable. (And WTF is this code highlight?)
    "author": "hikariTW",
    "version": (0, 1, 0),
    "blender": (2, 80, 0),
    "location": "TextEditor",
    "support": "TESTING",
    "category": "Interface",
}

enter image description here

Is there any workaround or this is normal when dealing with static examine of script when Blender try to list them out?

The test is done in Blender 2.83.4


Further testing which also break addon:

  • f-string and str.format
  • formatting with const-like 15 'foobar' without variable.
  • Conditional Expression: "foo" if True else "bar"
$\endgroup$
4
  • $\begingroup$ Have you tried "description" : f"{desc}", ? $\endgroup$
    – Gorgious
    Sep 25, 2020 at 7:44
  • $\begingroup$ Nope, any string format with any kind of variable even pure int or str. Including f"{desc}" and "{}".format(150). It seems that it need to be pure text formatting without any statement. $\endgroup$
    – HikariTW
    Sep 25, 2020 at 7:53
  • $\begingroup$ Oh, alright. Are you dynamically pulling the description from another file / module or is it for a translation ? $\endgroup$
    – Gorgious
    Sep 25, 2020 at 7:55
  • $\begingroup$ Just simply want to separate code into different part for better formatting. $\endgroup$
    – HikariTW
    Sep 25, 2020 at 8:00

2 Answers 2

4
$\begingroup$

No

Sure this is a dupe, have searched and searched,

For want of a better reference

https://developer.blender.org/T53617

bl_info must be declared in the module.

This is because bl_info is extracted without executing code.

ie the bl_info dictionary is grepped out of the addon module top level file (foo.py or foo/__init__.py) as a string where the locals will not be available.

$\endgroup$
3
  • $\begingroup$ Thanks for the link, but shouldn't Blender handle the exception carefully and indicate that there is some invalid bl_info rather that just failed to fetch data and make whole addon panel failed? $\endgroup$
    – HikariTW
    Sep 25, 2020 at 8:29
  • 1
    $\begingroup$ Wish I could find when this was previously asked as IIRC it was well explained, on how the dictionaries are used to build the fake modules list. Yep could add some exception handling for this..... yet again the addons panel can already be a ponderously slow beast. Adding an exception test for something that as demonstrated doesn't work, is fixed by not doing it. $\endgroup$
    – batFINGER
    Sep 25, 2020 at 8:34
  • $\begingroup$ .. have my nose in dynamically creating addons. The concept of having a single tools umbrella addon has kinda taken a big hit with the association of addons with workspaces, and currently end up with all or nothing. Might write a q re this one day. $\endgroup$
    – batFINGER
    Sep 25, 2020 at 8:44
3
$\begingroup$

So it seems like Blender is using ast.literal_eval() for finding bl_info without execute whole addon content.

As the references said, using eval to evaluate arbitrary addon would be extremely dangerous. And the potential corrupt code will also make Blender vulnerable to malware.

Reference

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .