|
|
@ -1,6 +1,7 @@ |
|
|
|
using System.Collections.Immutable; |
|
|
|
using System.Collections.Immutable; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using NLog; |
|
|
|
using NLog; |
|
|
|
using Salaros.Configuration; |
|
|
|
using Salaros.Configuration; |
|
|
|
using StabilityMatrix.Core.Exceptions; |
|
|
|
using StabilityMatrix.Core.Exceptions; |
|
|
@ -15,7 +16,6 @@ namespace StabilityMatrix.Core.Python; |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Python runner using a subprocess, mainly for venv support. |
|
|
|
/// Python runner using a subprocess, mainly for venv support. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] |
|
|
|
|
|
|
|
public class PyVenvRunner : IDisposable, IAsyncDisposable |
|
|
|
public class PyVenvRunner : IDisposable, IAsyncDisposable |
|
|
|
{ |
|
|
|
{ |
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); |
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); |
|
|
@ -248,21 +248,19 @@ public class PyVenvRunner : IDisposable, IAsyncDisposable |
|
|
|
public async Task PipInstallFromRequirements( |
|
|
|
public async Task PipInstallFromRequirements( |
|
|
|
FilePath file, |
|
|
|
FilePath file, |
|
|
|
Action<ProcessOutput>? outputDataReceived = null, |
|
|
|
Action<ProcessOutput>? outputDataReceived = null, |
|
|
|
IEnumerable<string>? excludes = null |
|
|
|
[StringSyntax(StringSyntaxAttribute.Regex)] string? excludes = null |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var requirementsText = await file.ReadAllTextAsync().ConfigureAwait(false); |
|
|
|
var requirementsText = await file.ReadAllTextAsync().ConfigureAwait(false); |
|
|
|
var requirements = requirementsText |
|
|
|
var requirements = requirementsText |
|
|
|
.Split(Environment.NewLine) |
|
|
|
.SplitLines(StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) |
|
|
|
.Where(s => !string.IsNullOrWhiteSpace(s)); |
|
|
|
.AsEnumerable(); |
|
|
|
|
|
|
|
|
|
|
|
if (excludes is not null) |
|
|
|
if (excludes is not null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var excludesFilter = excludes.ToImmutableHashSet( |
|
|
|
var excludeRegex = new Regex(excludes); |
|
|
|
StringComparer.InvariantCultureIgnoreCase |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements = requirements.Where(s => !excludesFilter.Contains(s)); |
|
|
|
requirements = requirements.Where(s => !excludeRegex.IsMatch(s)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var pipArgs = string.Join(' ', requirements); |
|
|
|
var pipArgs = string.Join(' ', requirements); |
|
|
|