Browse Source

fix pyrunner stuff

pull/55/head
Ionite 1 year ago
parent
commit
d362000571
No known key found for this signature in database
  1. 8
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 10
      StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs
  3. 2
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml
  4. 5
      StabilityMatrix.Core/Python/PyRunner.cs

8
StabilityMatrix.Avalonia/App.axaml.cs

@ -222,8 +222,12 @@ public sealed class App : Application
services.AddSingleton<INotificationService, NotificationService>();
services.AddSingleton<IPyRunner, PyRunner>();
services.AddSingleton<IUpdateHelper, UpdateHelper>();
if (Compat.IsLinux)
if (Compat.IsWindows)
{
services.AddSingleton<IPrerequisiteHelper, PrerequisiteHelper>();
}
else if (Compat.IsLinux)
{
services.AddSingleton<IPrerequisiteHelper, UnixPrerequisiteHelper>();
}

10
StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs

@ -9,6 +9,7 @@ using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
using NLog;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.Views;
using StabilityMatrix.Core.Attributes;
@ -24,6 +25,8 @@ namespace StabilityMatrix.Avalonia.ViewModels;
[View(typeof(SettingsPage))]
public partial class SettingsViewModel : PageViewModelBase
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly INotificationService notificationService;
private readonly ISettingsManager settingsManager;
private readonly IPrerequisiteHelper prerequisiteHelper;
@ -141,13 +144,18 @@ public partial class SettingsViewModel : PageViewModelBase
$"Result: {result}"));
}
public async Task ShowPythonVersion()
[RelayCommand]
private async Task CheckPythonVersion()
{
var isInstalled = prerequisiteHelper.IsPythonInstalled;
Logger.Debug($"Check python installed: {isInstalled}");
// Ensure python installed
if (!prerequisiteHelper.IsPythonInstalled)
{
// Need 7z as well for site packages repack
Logger.Debug("Python not installed, unpacking resources...");
await prerequisiteHelper.UnpackResourcesIfNecessary();
Logger.Debug("Unpacked resources, installing python...");
await prerequisiteHelper.InstallPythonIfNecessary();
}

2
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -63,7 +63,7 @@
<controls:FASymbolIconSource Symbol="fa-brands fa-python"/>
</ui:SettingsExpander.IconSource>
<ui:SettingsExpander.Footer>
<Button Content="Check Version" Command="{Binding ShowPythonVersion}"/>
<Button Content="Check Version" Command="{Binding CheckPythonVersionCommand}"/>
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
</StackPanel>

5
StabilityMatrix.Core/Python/PyRunner.cs

@ -2,6 +2,7 @@
using NLog;
using Python.Runtime;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Processes;
using StabilityMatrix.Core.Python.Interop;
@ -17,12 +18,12 @@ public class PyRunner : IPyRunner
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
// Set by ISettingsManager.TryFindLibrary()
public static DirectoryPath HomeDir { get; set; } = new();
public static DirectoryPath HomeDir { get; set; } = string.Empty;
// This is same for all platforms
public const string PythonDirName = "Python310";
public static string PythonDir => Path.Combine(HomeDir, "Assets", PythonDirName);
public static string PythonDir => Path.Combine(GlobalConfig.LibraryDir, "Assets", PythonDirName);
public static string PythonDllPath { get; }
public static string PythonExePath { get; }
public static string PipExePath { get; }

Loading…
Cancel
Save