Browse Source

Move Python310 to be extracted to appdata

pull/5/head
Ionite 1 year ago
parent
commit
31a3a4f387
No known key found for this signature in database
  1. 37
      StabilityMatrix/Python/PyRunner.cs
  2. 2
      StabilityMatrix/Python/PyVenvRunner.cs
  3. 5
      StabilityMatrix/StabilityMatrix.csproj
  4. 3
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  5. 3
      StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

37
StabilityMatrix/Python/PyRunner.cs

@ -15,18 +15,15 @@ public class PyRunner : IPyRunner
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private const string RelativeHomePath = @"Assets\Python310";
private const string RelativeDllPath = @"Assets\Python310\python310.dll";
private const string RelativeExePath = @"Assets\Python310\python.exe";
private const string RelativePipExePath = @"Assets\Python310\Scripts\pip.exe";
private const string RelativeGetPipPath = @"Assets\Python310\get-pip.pyc";
private const string RelativeVenvPath = @"Assets\Python310\Scripts\virtualenv.exe";
public static string HomePath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativeHomePath);
public static string DllPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativeDllPath);
public static string ExePath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativeExePath);
public static string PipExePath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativePipExePath);
public static string GetPipPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativeGetPipPath);
public static string VenvPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativeVenvPath);
private static readonly string AppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
private static readonly string HomeDir = Path.Combine(AppDataDir, "StabilityMatrix");
public static string PythonDir => Path.Combine(HomeDir, "Python310");
public static string PythonDllPath => Path.Combine(PythonDir, "python310.dll");
public static string PythonExePath => Path.Combine(PythonDir, "python.exe");
public static string GetPipPath => Path.Combine(PythonDir, "get-pip.pyc");
public static string PipExePath => Path.Combine(PythonDir, "Scripts", "pip.exe");
public static string VenvPath => Path.Combine(PythonDir, "Scripts", "virtualenv.exe");
public static bool PipInstalled => File.Exists(PipExePath);
public static bool VenvInstalled => File.Exists(VenvPath);
@ -45,22 +42,22 @@ public class PyRunner : IPyRunner
{
if (PythonEngine.IsInitialized) return;
Logger.Info("Setting PYTHONHOME and PATH to {HomePath}", HomePath);
Environment.SetEnvironmentVariable("PYTHONHOME", HomePath, EnvironmentVariableTarget.Process);
Logger.Info("Setting PYTHONHOME and PATH to {HomePath}", PythonDir);
Environment.SetEnvironmentVariable("PYTHONHOME", PythonDir, EnvironmentVariableTarget.Process);
// Get existing PATH
var currentEnvPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
// Append Python path to PATH
Environment.SetEnvironmentVariable("PATH", $"{HomePath};{currentEnvPath}", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PATH", $"{PythonDir};{currentEnvPath}", EnvironmentVariableTarget.Process);
Logger.Info("Initializing Python runtime with DLL: {DllPath}", DllPath);
Logger.Info("Initializing Python runtime with DLL: {DllPath}", PythonDllPath);
// Check PythonDLL exists
if (!File.Exists(DllPath))
if (!File.Exists(PythonDllPath))
{
Logger.Error("Python DLL not found");
throw new FileNotFoundException("Python DLL not found", DllPath);
throw new FileNotFoundException("Python DLL not found", PythonDllPath);
}
Runtime.PythonDLL = DllPath;
Runtime.PythonDLL = PythonDllPath;
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
@ -84,7 +81,7 @@ public class PyRunner : IPyRunner
{
throw new FileNotFoundException("get-pip not found", GetPipPath);
}
var p = ProcessRunner.StartProcess(ExePath, "-m get-pip");
var p = ProcessRunner.StartProcess(PythonExePath, "-m get-pip");
await ProcessRunner.WaitForExitConditionAsync(p);
}

2
StabilityMatrix/Python/PyVenvRunner.cs

@ -68,7 +68,7 @@ public class PyVenvRunner : IDisposable
}
// Create venv
var venvProc = ProcessRunner.StartProcess(PyRunner.ExePath, $"-m virtualenv \"{RootPath}\"");
var venvProc = ProcessRunner.StartProcess(PyRunner.PythonExePath, $"-m virtualenv \"{RootPath}\"");
await venvProc.WaitForExitAsync();
// Check return code

5
StabilityMatrix/StabilityMatrix.csproj

@ -10,6 +10,7 @@
<ApplicationIcon>Assets\Icon.ico</ApplicationIcon>
<LangVersion>11</LangVersion>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<DefaultItemExcludes>Assets\Python310\**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
@ -81,9 +82,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Assets\Python310\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Resource Include="Assets\Python310\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>

3
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -409,8 +409,7 @@ public partial class InstallerViewModel : ObservableObject
ProgressValue = Convert.ToInt32(progress.Percentage);
});
await prerequisiteHelper.InstallVcRedistIfNecessary(progressHandler);
await prerequisiteHelper.InstallGitIfNecessary(progressHandler);
await prerequisiteHelper.InstallAllIfNecessary(progressHandler);
}
private void OnPackageInstalled() => PackageInstalled?.Invoke(this, EventArgs.Empty);

3
StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

@ -93,8 +93,7 @@ public partial class OneClickInstallViewModel : ObservableObject
OneClickInstallProgress = Convert.ToInt32(progress.Percentage);
});
await prerequisiteHelper.InstallGitIfNecessary(progressHandler);
await prerequisiteHelper.InstallVcRedistIfNecessary(progressHandler);
await prerequisiteHelper.InstallAllIfNecessary(progressHandler);
SubHeaderText = "Installing prerequisites...";
IsIndeterminate = true;

Loading…
Cancel
Save