Text datablocks don't self-register when getting a .00x suffix #89532

Closed
opened 2021-06-29 15:57:44 +02:00 by Demeter Dzadik · 11 comments
Member

Problem
Although all text blocks that don't have an extension use script highlighting, only those which end in exactly .py allow for the "Register" checkbox's functionality to work. I think this design forgot to take into account that Blender will slap a .001 suffix after duplicates datablocks, which can cause scripts to fail to register themselves pretty easily, and in a way that is very hard to troubleshoot for a user who is not in the know.

Example cases
For example, someone might rig two characters in two files, and create rig UI scripts for them, both named rig_ui.py. Then, since they're working on a small hobby level production, they will append the characters into the same scene, resulting in the appended script getting a .001 suffix and failing to execute.

In another case, one might want to append multiple of the same character, resulting in the same issue, and in this case naming the rig script in a unique way won't even help.

Even in a real production where linking allows these datablocks to have their own namespaces, sometimes there's small flaws in pipeline tools, or somebody makes a small mistake, and a script can end up with a .001 suffix in a plethora of ways.

Solutions
I would propose allowing scripts to use the Register feature not only if their names end in exactly .py but also .py.### (I think there's already naming util functions to check for this)

Alternative would be to put the .001 before the .py when a duplicate appears but I think that would require adding a special case to much deeper code which probably nobody wants to do ;).

This was also mentioned in an Animation Module meeting once upon a time and according to my memory there was general agreement toward the first solution, but my memories are faded and I'm biased.

CC @dr.sybren @BassamKurdali @LucianoMunoz @icappiello @jpbouza-4 Thoughts? :)

**Problem** Although all text blocks that don't have an extension use script highlighting, only those which end in exactly `.py` allow for the "Register" checkbox's functionality to work. I think this design forgot to take into account that Blender will slap a .001 suffix after duplicates datablocks, which can cause scripts to fail to register themselves pretty easily, and in a way that is very hard to troubleshoot for a user who is not in the know. **Example cases** For example, [someone](https://gitlab.com/blender/CloudRig) might rig two characters in two files, and create rig UI scripts for them, both named `rig_ui.py`. Then, since they're working on a small hobby level production, they will append the characters into the same scene, resulting in the appended script getting a .001 suffix and failing to execute. In another case, one might want to append multiple of the same character, resulting in the same issue, and in this case naming the rig script in a unique way won't even help. Even in a real production where linking allows these datablocks to have their own namespaces, sometimes there's [small flaws](https://dev-files.blender.org/file/data/z3cc7hh2vepxxybjiz72/PHID-FILE-dhmjgabyiqk2rl4l45w2/image.png) in pipeline tools, or somebody makes a small mistake, and a script can end up with a .001 suffix in a plethora of ways. **Solutions** I would propose allowing scripts to use the Register feature not only if their names end in exactly `.py` but also `.py.###` (I think there's already naming util functions to check for this) Alternative would be to put the .001 before the .py when a duplicate appears but I think that would require adding a special case to much deeper code which probably nobody wants to do ;). This was also mentioned in an Animation Module meeting once upon a time and according to my memory there was general agreement toward the first solution, but my memories are faded and I'm biased. CC @dr.sybren @BassamKurdali @LucianoMunoz @icappiello @jpbouza-4 Thoughts? :)
Author
Member

Added subscribers: @icappiello, @Bassam, @LucianoMunoz, @jpbouza-4, @dr.sybren, @Mets

Added subscribers: @icappiello, @Bassam, @LucianoMunoz, @jpbouza-4, @dr.sybren, @Mets
Author
Member

Added subscriber: @BassamKurdali

Added subscriber: @BassamKurdali
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'
Member

can confirm the issue, will leave classification up to module devs

can confirm the issue, will leave classification up to module devs

+1 for the first solution. The exact datablock name is less important now that they cannot be directly imported any more; import rig_ui used to work for importing a text datablock rig_ui.py; now you need rig_ui = bpy.data.texts['rig_ui'].as_module() for this.

This might require changing the logic in ED_text_is_syntax_highlight_supported() a bit. Currently it always returns true for any datablock ending in a .### numerical suffix. If we say that blabla.xxx.### should be treated the same as blablabla.xxx, the current logic in that function is not suitable any more.

Furthermore, TEXT_MT_text should be adjusted. Currently it's the menu's Python code that determines whether the "Register" checkbox is enabled or not. IMO this is a bad design -- the ability to register a text datablock should be handled in RNA and not in UI code.

+1 for the first solution. The exact datablock name is less important now that they cannot be directly imported any more; `import rig_ui` used to work for importing a text datablock `rig_ui.py`; now you need `rig_ui = bpy.data.texts['rig_ui'].as_module()` for this. This might require changing the logic in `ED_text_is_syntax_highlight_supported()` a bit. Currently it always returns `true` for any datablock ending in a `.###` numerical suffix. If we say that `blabla.xxx.###` should be treated the same as `blablabla.xxx`, the current logic in that function is not suitable any more. Furthermore, `TEXT_MT_text` should be adjusted. Currently it's the menu's Python code that determines whether the "Register" checkbox is enabled or not. IMO this is a bad design -- the ability to register a text datablock should be handled in RNA and not in UI code.

Added subscriber: @ideasman42

Added subscriber: @ideasman42

In #89532#1185872, @dr.sybren wrote:
+1 for the first solution. The exact datablock name is less important now that they cannot be directly imported any more; import rig_ui used to work for importing a text datablock rig_ui.py; now you need rig_ui = bpy.data.texts['rig_ui'].as_module() for this.

Since the scripts are executed instead of loading as a module there is no longer a need to have any constraint on the naming.

This might require changing the logic in ED_text_is_syntax_highlight_supported() a bit. Currently it always returns true for any datablock ending in a .### numerical suffix. If we say that blabla.xxx.### should be treated the same as blablabla.xxx, the current logic in that function is not suitable any more.

Seems reasonable this can be handled separately.

Furthermore, TEXT_MT_text should be adjusted. Currently it's the menu's Python code that determines whether the "Register" checkbox is enabled or not. IMO this is a bad design -- the ability to register a text datablock should be handled in RNA and not in UI code.

This can't be done in RNA, it's only possible to conditionally be read-only, where as for this we would only want to grey it out.

> In #89532#1185872, @dr.sybren wrote: > +1 for the first solution. The exact datablock name is less important now that they cannot be directly imported any more; `import rig_ui` used to work for importing a text datablock `rig_ui.py`; now you need `rig_ui = bpy.data.texts['rig_ui'].as_module()` for this. Since the scripts are executed instead of loading as a module there is no longer a need to have any constraint on the naming. > This might require changing the logic in `ED_text_is_syntax_highlight_supported()` a bit. Currently it always returns `true` for any datablock ending in a `.###` numerical suffix. If we say that `blabla.xxx.###` should be treated the same as `blablabla.xxx`, the current logic in that function is not suitable any more. Seems reasonable this can be handled separately. > Furthermore, `TEXT_MT_text` should be adjusted. Currently it's the menu's Python code that determines whether the "Register" checkbox is enabled or not. IMO this is a bad design -- the ability to register a text datablock should be handled in RNA and not in UI code. This can't be done in RNA, it's only possible to conditionally be read-only, where as for this we would only want to grey it out.

Submitted D12181, this removes the check for the extension entirely.

Submitted [D12181](https://archive.blender.org/developer/D12181), this removes the check for the extension entirely.

This issue was referenced by 3e775a4fc5

This issue was referenced by 3e775a4fc57cfd48954adcf284354312f34d5412

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'
Campbell Barton self-assigned this 2021-08-13 07:55:00 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#89532
No description provided.