led-control icon indicating copy to clipboard operation
led-control copied to clipboard

Optionally run patterns unrestricted

Open nils opened this issue 4 years ago • 2 comments

Hi @jackw01,

I'd like to write complex patterns with classes and everything Python provides, so this PR proposes a new command line flag --run-unsafe which does run the pattern code in an unrestricted way.

However, I have to admit that I'm not very experienced with Python, so I'd welcome every feedback you have concerning the code quality.

Best Regards, Nils

nils avatar Mar 24 '21 18:03 nils

Hi @jackw01, could you provide some feedback on this?

Any chances to get it merged? If not, I'd be happy to learn why :-)

  • [ ] because you don't see it in scope of this project
  • [ ] because the code quality needs to be improved
  • [ ] ... or let me know any other reason

nils avatar Oct 13 '21 11:10 nils

I understand the motivation for having this feature to be able to use classes, helper functions, and global variables in patterns, but I would rather it be implemented using RestrictedPython instead of using the unsafe compile and executing the pattern with access to all existing global variables. If I were to implement this, I would allow each pattern to have a separate setup function that gets called once after the code is compiled to set up any classes or global variables that can then be used by the pattern function. I am not sure about the exact implementation details for this, but I will look into it when I have some free time.

The one use case I can see that this approach wouldn't cover is being able to read data from a file from within animation code, which could be solved by adding a command line flag like you have that would (unsafely) add open and other file-related functionality to the list of allowed globals.

jackw01 avatar Oct 15 '21 20:10 jackw01