| | | 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 the path to the Python DLL. Alternatively, you can set the PYTHON_DLL environment variable, which i |
| | | 15 | | /// </summary> |
| | 2 | 16 | | public string? PythonDllPath { get; set; } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets or sets the Python script files to load. |
| | | 20 | | /// </summary> |
| | 3 | 21 | | public ICollection<string> Scripts { get; } = new List<string>(); |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets or sets a list of callbacks that are invoked when the Python engine is being configured. |
| | | 25 | | /// </summary> |
| | 1 | 26 | | public ICollection<Action<PyModule>> Scopes { get; } = new List<Action<PyModule>>(); |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Appends a script to the Python engine. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="builder">A builder that builds the script to append.</param> |
| | | 32 | | public void AddScript(Action<StringBuilder> builder) |
| | | 33 | | { |
| | 1 | 34 | | var sb = new StringBuilder(); |
| | 1 | 35 | | builder(sb); |
| | 1 | 36 | | AddScript(sb.ToString()); |
| | 1 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Appends a script to the Python engine. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <param name="script">The script to append.</param> |
| | | 43 | | public void AddScript(string script) |
| | | 44 | | { |
| | 1 | 45 | | Scripts.Add(script); |
| | 1 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Registers a callback that is invoked when the Python engine is being configured. |
| | | 50 | | /// </summary> |
| | | 51 | | public void ConfigureScriptScope(Action<PyModule> configure) |
| | | 52 | | { |
| | 0 | 53 | | Scopes.Add(configure); |
| | 0 | 54 | | } |
| | | 55 | | } |