jackw01 / led-control

Advanced WS2812/SK6812 RGB/RGBW LED controller with on-the-fly Python animation programming, web code editor/control interface, 1D, 2D, and 3D display support, and E1.31 sACN support
https://jackw01.github.io/led-control/
MIT License
162 stars 35 forks source link

Optionally run patterns unrestricted #13

Open nils opened 3 years ago

nils commented 3 years ago

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 commented 2 years ago

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

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

jackw01 commented 2 years ago

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.