| | | 1 | | using System.Text; |
| | | 2 | | using JetBrains.Annotations; |
| | | 3 | | using Python.Runtime; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Expressions.Python.Options; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Options for the Python expression evaluator. |
| | | 9 | | /// </summary> |
| | | 10 | | [PublicAPI] |
| | | 11 | | public class PythonOptions |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Gets or sets whether workflow-authored Python.NET host-code execution is allowed. |
| | | 15 | | /// Python.NET is not a sandbox and can access host process capabilities. |
| | | 16 | | /// </summary> |
| | 45 | 17 | | public bool AllowHostCodeExecution { get; set; } |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets or sets the path to the Python DLL. Alternatively, you can set the PYTHON_DLL environment variable, which i |
| | | 21 | | /// </summary> |
| | 4 | 22 | | public string? PythonDllPath { get; set; } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets or sets the Python script files to load. |
| | | 26 | | /// </summary> |
| | 9 | 27 | | public ICollection<string> Scripts { get; } = new List<string>(); |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets or sets a list of callbacks that are invoked when the Python engine is being configured. |
| | | 31 | | /// </summary> |
| | 3 | 32 | | public ICollection<Action<PyModule>> Scopes { get; } = new List<Action<PyModule>>(); |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Appends a script to the Python engine. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="builder">A builder that builds the script to append.</param> |
| | | 38 | | public void AddScript(Action<StringBuilder> builder) |
| | | 39 | | { |
| | 3 | 40 | | var sb = new StringBuilder(); |
| | 3 | 41 | | builder(sb); |
| | 3 | 42 | | AddScript(sb.ToString()); |
| | 3 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Appends a script to the Python engine. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <param name="script">The script to append.</param> |
| | | 49 | | public void AddScript(string script) |
| | | 50 | | { |
| | 3 | 51 | | Scripts.Add(script); |
| | 3 | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Registers a callback that is invoked when the Python engine is being configured. |
| | | 56 | | /// </summary> |
| | | 57 | | public void ConfigureScriptScope(Action<PyModule> configure) |
| | | 58 | | { |
| | 0 | 59 | | Scopes.Add(configure); |
| | 0 | 60 | | } |
| | | 61 | | } |