2025-05-20 11:38:24 +00:00
|
|
|
using Elsa.Common.Features;
|
2026-05-20 12:19:47 +00:00
|
|
|
using Elsa.Expressions.Python.ActivityDescriptorModifiers;
|
2025-05-20 11:38:24 +00:00
|
|
|
using Elsa.Expressions.Features;
|
|
|
|
|
using Elsa.Extensions;
|
|
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Attributes;
|
|
|
|
|
using Elsa.Features.Services;
|
2025-05-20 11:52:19 +00:00
|
|
|
using Elsa.Expressions.Python.Activities;
|
|
|
|
|
using Elsa.Expressions.Python.Contracts;
|
|
|
|
|
using Elsa.Expressions.Python.HostedServices;
|
|
|
|
|
using Elsa.Expressions.Python.Options;
|
|
|
|
|
using Elsa.Expressions.Python.Providers;
|
|
|
|
|
using Elsa.Expressions.Python.Services;
|
2025-05-20 11:38:24 +00:00
|
|
|
using Elsa.Workflows;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
2025-05-20 11:52:19 +00:00
|
|
|
namespace Elsa.Expressions.Python.Features;
|
2025-05-20 11:38:24 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Installs Python integration.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DependsOn(typeof(MediatorFeature))]
|
|
|
|
|
[DependsOn(typeof(ExpressionsFeature))]
|
|
|
|
|
public class PythonFeature : FeatureBase
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public PythonFeature(IModule module) : base(module)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the <see cref="Options.PythonOptions"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<PythonOptions> PythonOptions { get; set; } = _ => { };
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void ConfigureHostedServices()
|
|
|
|
|
{
|
|
|
|
|
Module.ConfigureHostedService<PythonGlobalInterpreterManager>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Apply()
|
|
|
|
|
{
|
|
|
|
|
Services.Configure(PythonOptions);
|
|
|
|
|
|
|
|
|
|
// Python services.
|
|
|
|
|
Services
|
|
|
|
|
.AddScoped<IPythonEvaluator, PythonNetPythonEvaluator>()
|
|
|
|
|
.AddExpressionDescriptorProvider<PythonExpressionDescriptorProvider>()
|
2026-05-20 12:19:47 +00:00
|
|
|
.AddSingleton<IActivityDescriptorModifier, PythonActivityDescriptorModifier>()
|
2025-05-20 11:38:24 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
// Handlers.
|
|
|
|
|
Services.AddNotificationHandlersFrom<PythonFeature>();
|
|
|
|
|
|
|
|
|
|
// Activities.
|
|
|
|
|
Module.AddActivitiesFrom<PythonFeature>();
|
|
|
|
|
|
|
|
|
|
// UI property handlers.
|
|
|
|
|
Services.AddScoped<IPropertyUIHandler, RunPythonOptionsProvider>();
|
|
|
|
|
}
|
2026-05-20 12:19:47 +00:00
|
|
|
}
|