Skip to content

Commit

Permalink
Merge pull request LykosAI#500 from ionite34/fix-onetrainer
Browse files Browse the repository at this point in the history
Add Tkinter prerequisite and handle it
  • Loading branch information
mohnjiles committed Feb 5, 2024
2 parents 8c8a167 + e6c329a commit 3ca62b1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
- Fixed failing InvokeAI install on macOS due to missing nodejs
- Increased timeout on Recommended Models call to prevent potential timeout errors on slow connections
- Fixed SynchronizationLockException when saving settings
- Fixed missing tkinter dependency for OneTrainer on Windows

## v2.8.0
### Added
Expand Down
21 changes: 5 additions & 16 deletions StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs
Expand Up @@ -23,14 +23,14 @@ namespace StabilityMatrix.Avalonia.Helpers;

[SupportedOSPlatform("macos")]
[SupportedOSPlatform("linux")]
public class UnixPrerequisiteHelper : IPrerequisiteHelper
public class UnixPrerequisiteHelper(
IDownloadService downloadService,
ISettingsManager settingsManager,
IPyRunner pyRunner
) : IPrerequisiteHelper
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private readonly IDownloadService downloadService;
private readonly ISettingsManager settingsManager;
private readonly IPyRunner pyRunner;

private DirectoryPath HomeDir => settingsManager.LibraryDir;
private DirectoryPath AssetsDir => HomeDir.JoinDir("Assets");

Expand All @@ -46,17 +46,6 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
// Cached store of whether or not git is installed
private bool? isGitInstalled;

public UnixPrerequisiteHelper(
IDownloadService downloadService,
ISettingsManager settingsManager,
IPyRunner pyRunner
)
{
this.downloadService = downloadService;
this.settingsManager = settingsManager;
this.pyRunner = pyRunner;
}

private async Task<bool> CheckIsGitInstalled()
{
var result = await ProcessRunner.RunBashCommand("git --version");
Expand Down
29 changes: 10 additions & 19 deletions StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs
Expand Up @@ -20,15 +20,14 @@
namespace StabilityMatrix.Avalonia.Helpers;

[SupportedOSPlatform("windows")]
public class WindowsPrerequisiteHelper : IPrerequisiteHelper
public class WindowsPrerequisiteHelper(
IDownloadService downloadService,
ISettingsManager settingsManager,
IPyRunner pyRunner
) : IPrerequisiteHelper
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private readonly IGitHubClient gitHubClient;
private readonly IDownloadService downloadService;
private readonly ISettingsManager settingsManager;
private readonly IPyRunner pyRunner;

private const string VcRedistDownloadUrl = "https://aka.ms/vs/16/release/vc_redist.x64.exe";
private const string TkinterDownloadUrl =
"https://cdn.lykos.ai/tkinter-cpython-embedded-3.10.11-win-x64.zip";
Expand Down Expand Up @@ -62,19 +61,6 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
public string GitBinPath => Path.Combine(PortableGitInstallDir, "bin");
public bool IsPythonInstalled => File.Exists(PythonDllPath);

public WindowsPrerequisiteHelper(
IGitHubClient gitHubClient,
IDownloadService downloadService,
ISettingsManager settingsManager,
IPyRunner pyRunner
)
{
this.gitHubClient = gitHubClient;
this.downloadService = downloadService;
this.settingsManager = settingsManager;
this.pyRunner = pyRunner;
}

public async Task RunGit(
ProcessArgs args,
Action<ProcessOutput>? onProcessOutput,
Expand Down Expand Up @@ -166,6 +152,11 @@ public Task<ProcessResult> GetGitOutput(ProcessArgs args, string? workingDirecto
{
await InstallNodeIfNecessary(progress);
}

if (prerequisites.Contains(PackagePrerequisite.Tkinter))
{
await InstallTkinterIfNecessary(progress);
}
}

public async Task InstallAllIfNecessary(IProgress<ProgressReport>? progress = null)
Expand Down
3 changes: 2 additions & 1 deletion StabilityMatrix.Core/Models/PackagePrerequisite.cs
Expand Up @@ -7,5 +7,6 @@ public enum PackagePrerequisite
Git,
Node,
Dotnet7,
Dotnet8
Dotnet8,
Tkinter,
}
8 changes: 2 additions & 6 deletions StabilityMatrix.Core/Models/Packages/KohyaSs.cs
Expand Up @@ -50,6 +50,8 @@ IPyRunner runner
public override IEnumerable<TorchVersion> AvailableTorchVersions => [TorchVersion.Cuda];
public override IEnumerable<SharedFolderMethod> AvailableSharedFolderMethods =>
new[] { SharedFolderMethod.None };
public override IEnumerable<PackagePrerequisite> Prerequisites =>
base.Prerequisites.Concat([PackagePrerequisite.Tkinter]);

public override List<LaunchOptionDefinition> LaunchOptions =>
[
Expand Down Expand Up @@ -114,12 +116,6 @@ IPyRunner runner
Action<ProcessOutput>? onConsoleOutput = null
)
{
if (Compat.IsWindows)
{
progress?.Report(new ProgressReport(-1f, "Installing prerequisites...", isIndeterminate: true));
await PrerequisiteHelper.InstallTkinterIfNecessary(progress).ConfigureAwait(false);
}

progress?.Report(new ProgressReport(-1f, "Setting up venv", isIndeterminate: true));
// Setup venv
await using var venvRunner = new PyVenvRunner(Path.Combine(installLocation, "venv"));
Expand Down
2 changes: 2 additions & 0 deletions StabilityMatrix.Core/Models/Packages/OneTrainer.cs
Expand Up @@ -41,6 +41,8 @@ IPrerequisiteHelper prerequisiteHelper
public override PackageDifficulty InstallerSortOrder => PackageDifficulty.Nightmare;
public override bool OfferInOneClickInstaller => false;
public override bool ShouldIgnoreReleases => true;
public override IEnumerable<PackagePrerequisite> Prerequisites =>
base.Prerequisites.Concat([PackagePrerequisite.Tkinter]);

public override async Task InstallPackage(
string installLocation,
Expand Down

0 comments on commit 3ca62b1

Please sign in to comment.