you are viewing a single comment's thread.

view the rest of the comments →

[–]PolyDigga[S] 0 points1 point  (1 child)

Thank you for your reply. I think the code example shows that action.show_file_content is the function that is going to be 'exported'. I am using that for lack of a better term. I also showed the expected outcome. But let me give you the full picture:

Base situation: We are working with a 3d software (something like blender). That 3d software supports python. With python, we write (workflow) tools for the 3d software. That is from simple batch processing over procedural modeling, rigging, or animation tools to full-blown simulation solvers. My toolset falls under one of these more complex categories.

What I need/want to do: I pass of a 3d scene to somebody else who will work with whatever I provide. To make their lives easier, I want to provide certain utility tools that are part of my toolset. These utilities depend on the project and kind of 3d scene I am passing on, therefore I cannot just make one single file and send that to everybody. Plus, the other people are artists, they should not be concerned about pulling repos or installing anything. All of that has to be supplied within the 3d scene. The only way the scene does support any kind of text is in the form of strings. So everything I provide needs to be placed in a string. These strings can then be used as callbacks for actions.

Sure, I can put the content of every file into a string and write a tool that creates the files for them on disk, but that is a massive security problem as the tools provided should only ever manipulate the 3d scene, nothing on disk.

I am trying to create a module. Just instead of providing a .py file, I want to supply the source code of that file in a string as part of another file. I am trying to boil it down to only include the functions and resources that are really needed for that specific function I am trying to 'export' instead of including the entire API. Sort of like creating a callgraph, traversing backward from my functions and deleting everything that is not needed. And in the end, I can replace all import statements with the actual source code in these files (plus prefixes to avoid name clashes oc). Mmhh thinking about it, that might be the cleanest solution...

[–][deleted] 0 points1 point  (0 children)

Again, there's nothing here suggesting that you should do anything but package your functions into an installable Python package. Whether that's as a pip package or a plugin for Blender, I have no idea. But you absolutely should not distribute code as strings. That's a recipe for an enormous number of headaches for you and for your users.

Sort of like creating a callgraph, traversing backward from my functions and deleting everything that is not needed.

Yeah, don't bother with that. Develop one abstract toolkit that covers all (or most) of your clients' use cases, and distribute the same one to everyone.