-
-
Notifications
You must be signed in to change notification settings - Fork 542
v2.15.4 #1449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2.15.4 #1449
Changes from all commits
f713b31
45a0172
7dbad7f
3bf8ec6
47033a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| using StabilityMatrix.Avalonia.ViewModels.Base; | ||
| using StabilityMatrix.Avalonia.Views.Dialogs; | ||
| using StabilityMatrix.Core.Attributes; | ||
| using StabilityMatrix.Core.Helper; | ||
| using StabilityMatrix.Core.Helper.Factory; | ||
| using StabilityMatrix.Core.Models; | ||
| using StabilityMatrix.Core.Models.Database; | ||
|
|
@@ -27,21 +28,22 @@ namespace StabilityMatrix.Avalonia.ViewModels.Dialogs; | |
| [View(typeof(PackageImportDialog))] | ||
| [ManagedService] | ||
| [RegisterTransient<PackageImportViewModel>] | ||
| public partial class PackageImportViewModel : ContentDialogViewModelBase | ||
| public partial class PackageImportViewModel( | ||
| IPackageFactory packageFactory, | ||
| ISettingsManager settingsManager, | ||
| IPyInstallationManager pyInstallationManager | ||
| ) : ContentDialogViewModelBase | ||
| { | ||
| private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); | ||
|
|
||
| private readonly IPackageFactory packageFactory; | ||
| private readonly ISettingsManager settingsManager; | ||
| private bool venvDetected = false; | ||
|
|
||
| [ObservableProperty] | ||
| private DirectoryPath? packagePath; | ||
|
|
||
| [ObservableProperty] | ||
| private BasePackage? selectedBasePackage; | ||
|
|
||
| public IReadOnlyList<BasePackage> AvailablePackages => | ||
| packageFactory.GetAllAvailablePackages().ToImmutableArray(); | ||
| public IReadOnlyList<BasePackage> AvailablePackages => [.. packageFactory.GetAllAvailablePackages()]; | ||
|
|
||
| [ObservableProperty] | ||
| private PackageVersion? selectedVersion; | ||
|
|
@@ -64,6 +66,9 @@ public partial class PackageImportViewModel : ContentDialogViewModelBase | |
| [ObservableProperty] | ||
| private bool showCustomCommitSha; | ||
|
|
||
| [ObservableProperty] | ||
| public partial bool ShowPythonVersionSelection { get; set; } = true; | ||
|
|
||
| // Version types (release or commit) | ||
| [ObservableProperty] | ||
| [NotifyPropertyChangedFor(nameof(ReleaseLabelText), nameof(IsReleaseMode), nameof(SelectedVersion))] | ||
|
|
@@ -73,6 +78,13 @@ public partial class PackageImportViewModel : ContentDialogViewModelBase | |
| [NotifyPropertyChangedFor(nameof(IsReleaseModeAvailable))] | ||
| private PackageVersionType availableVersionTypes = | ||
| PackageVersionType.GithubRelease | PackageVersionType.Commit; | ||
|
|
||
| [ObservableProperty] | ||
| public partial ObservableCollection<UvPythonInfo> AvailablePythonVersions { get; set; } = []; | ||
|
|
||
| [ObservableProperty] | ||
| public partial UvPythonInfo? SelectedPythonVersion { get; set; } | ||
|
|
||
| public string ReleaseLabelText => IsReleaseMode ? "Version" : "Branch"; | ||
| public bool IsReleaseMode | ||
| { | ||
|
|
@@ -82,12 +94,6 @@ public bool IsReleaseMode | |
|
|
||
| public bool IsReleaseModeAvailable => AvailableVersionTypes.HasFlag(PackageVersionType.GithubRelease); | ||
|
|
||
| public PackageImportViewModel(IPackageFactory packageFactory, ISettingsManager settingsManager) | ||
| { | ||
| this.packageFactory = packageFactory; | ||
| this.settingsManager = settingsManager; | ||
| } | ||
|
|
||
| public override async Task OnLoadedAsync() | ||
| { | ||
| SelectedBasePackage ??= AvailablePackages[0]; | ||
|
|
@@ -115,6 +121,24 @@ public override async Task OnLoadedAsync() | |
| ); | ||
| UpdateSelectedVersionToLatestMain(); | ||
| } | ||
|
|
||
| var pythonVersions = await pyInstallationManager.GetAllAvailablePythonsAsync(); | ||
| AvailablePythonVersions = new ObservableCollection<UvPythonInfo>(pythonVersions); | ||
|
|
||
| if ( | ||
| PackagePath is not null | ||
| && Utilities.TryGetPyVenvVersion(PackagePath.FullPath, out var venvPyVersion) | ||
| ) | ||
| { | ||
| var matchingVenvPy = AvailablePythonVersions.FirstOrDefault(x => x.Version == venvPyVersion); | ||
| if (matchingVenvPy != default) | ||
| { | ||
| SelectedPythonVersion = matchingVenvPy; | ||
| venvDetected = true; | ||
| } | ||
| } | ||
|
|
||
| SelectedPythonVersion ??= GetRecommendedPyVersion() ?? AvailablePythonVersions.LastOrDefault(); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
|
|
@@ -155,7 +179,7 @@ partial void OnSelectedVersionChanged(PackageVersion? value) | |
| if (commits is null || commits.Count == 0) | ||
| return; | ||
|
|
||
| commits = [..commits, new GitCommit { Sha = "Custom..." }]; | ||
| commits = [.. commits, new GitCommit { Sha = "Custom..." }]; | ||
|
|
||
| AvailableCommits = new ObservableCollection<GitCommit>(commits); | ||
| SelectedCommit = AvailableCommits[0]; | ||
|
|
@@ -205,12 +229,18 @@ partial void OnSelectedBasePackageChanged(BasePackage? value) | |
| if (commits is null || commits.Count == 0) | ||
| return; | ||
|
|
||
| commits = [..commits, new GitCommit { Sha = "Custom..." }]; | ||
| commits = [.. commits, new GitCommit { Sha = "Custom..." }]; | ||
|
|
||
| AvailableCommits = new ObservableCollection<GitCommit>(commits); | ||
| SelectedCommit = AvailableCommits[0]; | ||
| UpdateSelectedVersionToLatestMain(); | ||
| } | ||
|
|
||
| if (!venvDetected) | ||
| { | ||
| SelectedPythonVersion = | ||
| GetRecommendedPyVersion() ?? AvailablePythonVersions.FirstOrDefault(); | ||
|
Comment on lines
+241
to
+242
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a small inconsistency in the fallback logic for selecting a Python version. Here, SelectedPythonVersion =
GetRecommendedPyVersion() ?? AvailablePythonVersions.LastOrDefault(); |
||
| } | ||
| }) | ||
| .SafeFireAndForget(); | ||
| } | ||
|
|
@@ -267,7 +297,9 @@ public async Task AddPackageWithCurrentInputs() | |
| LastUpdateCheck = DateTimeOffset.Now, | ||
| PreferredTorchIndex = torchVersion, | ||
| PreferredSharedFolderMethod = sharedFolderRecommendation, | ||
| PythonVersion = PyInstallationManager.Python_3_10_11.StringValue | ||
| PythonVersion = | ||
| SelectedPythonVersion?.Version.StringValue | ||
| ?? PyInstallationManager.Python_3_10_17.StringValue, | ||
| }; | ||
|
|
||
| // Recreate venv if it's a BaseGitPackage | ||
|
|
@@ -300,4 +332,10 @@ await gitPackage.SetupVenv( | |
|
|
||
| settingsManager.Transaction(s => s.InstalledPackages.Add(package)); | ||
| } | ||
|
|
||
| private UvPythonInfo? GetRecommendedPyVersion() => | ||
| AvailablePythonVersions.LastOrDefault(x => | ||
| x.Version.Major.Equals(SelectedBasePackage?.RecommendedPythonVersion.Major) | ||
| && x.Version.Minor.Equals(SelectedBasePackage?.RecommendedPythonVersion.Minor) | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a typo in the contributor's username. The pull request description mentions
@NeuralFault, but the changelog has@neural_fault. For consistency and to ensure proper credit, it would be best to use the casing from the PR description.