Skip to content

Commit f30eb4d

Browse files
committed
Make python upgrade dialog more generic
1 parent f8ca290 commit f30eb4d

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public async Task Update()
442442
return;
443443
}
444444

445-
if (!await ShowForgeVenvRecreationDialogIfNeeded(basePackage, Package))
445+
if (!await ShowPythonUpgradeDialogIfNeeded(basePackage, Package))
446446
return;
447447

448448
var packageName = Package.DisplayName ?? Package.PackageName ?? "";
@@ -594,7 +594,7 @@ private async Task ChangeVersion()
594594
return;
595595
}
596596

597-
if (!await ShowForgeVenvRecreationDialogIfNeeded(basePackage, Package))
597+
if (!await ShowPythonUpgradeDialogIfNeeded(basePackage, Package))
598598
return;
599599

600600
var packageName = Package.DisplayName ?? Package.PackageName ?? "";
@@ -1031,32 +1031,32 @@ private async Task<bool> HasUpdate()
10311031
}
10321032
}
10331033

1034-
private static bool RequiresForgeVenvRecreationNotice(
1034+
private static bool RequiresPythonUpgradeNotice(
10351035
BasePackage basePackage,
10361036
InstalledPackage installedPackage
10371037
)
10381038
{
1039-
if (basePackage is not ForgeClassic)
1039+
if (basePackage.MinimumPythonVersion is not { } minimumVersion)
10401040
return false;
10411041

10421042
return PyVersion.TryParse(installedPackage.PythonVersion, out var currentVersion)
1043-
&& currentVersion < PyInstallationManager.Python_3_13_12;
1043+
&& currentVersion < minimumVersion;
10441044
}
10451045

1046-
private async Task<bool> ShowForgeVenvRecreationDialogIfNeeded(
1046+
private async Task<bool> ShowPythonUpgradeDialogIfNeeded(
10471047
BasePackage basePackage,
10481048
InstalledPackage installedPackage
10491049
)
10501050
{
1051-
if (!RequiresForgeVenvRecreationNotice(basePackage, installedPackage))
1051+
if (!RequiresPythonUpgradeNotice(basePackage, installedPackage))
10521052
return true;
10531053

10541054
var dialog = new BetterContentDialog
10551055
{
10561056
Title = "Python Upgrade Required",
10571057
Content =
10581058
"This update will recreate the package venv to migrate from Python "
1059-
+ $"{installedPackage.PythonVersion} to {PyInstallationManager.Python_3_13_12}.\n\n"
1059+
+ $"{installedPackage.PythonVersion} to {basePackage.MinimumPythonVersion}.\n\n"
10601060
+ "Any custom pip packages manually installed into the current venv may need to be reinstalled. "
10611061
+ "Your launch options, extensions, and generated files are not affected.\n\n"
10621062
+ "You can also install a fresh copy and migrate manually.\n\n"

StabilityMatrix.Core/Models/Packages/BasePackage.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public abstract class BasePackage(ISettingsManager settingsManager)
6262
public virtual string? AdminRequiredReason => null;
6363
public virtual PyVersion RecommendedPythonVersion => PyInstallationManager.Python_3_10_17;
6464

65+
/// <summary>
66+
/// Minimum Python version required for updates. When set, updating a package with a lower
67+
/// installed Python version will prompt for venv recreation. Null means no minimum enforced.
68+
/// </summary>
69+
public virtual PyVersion? MinimumPythonVersion => null;
70+
6571
/// <summary>
6672
/// Returns a list of extra commands that can be executed for this package.
6773
/// The function takes an InstalledPackage parameter to operate on a specific installation.

StabilityMatrix.Core/Models/Packages/ForgeClassic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ IPipWheelService pipWheelService
3333
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
3434
private const string LegacyUpgradeAlert = "You are updating from an old version";
3535
private const string ContinuePrompt = "Press Enter to Continue";
36-
private static readonly PyVersion MinimumPythonVersion = Python.PyInstallationManager.Python_3_13_12;
36+
public override PyVersion? MinimumPythonVersion => Python.PyInstallationManager.Python_3_13_12;
3737

3838
public override string Name => "forge-classic";
3939
public override string Author => "Haoming02";
@@ -198,7 +198,7 @@ public override async Task InstallPackage(
198198
);
199199

200200
var shouldUpgradePython = options.IsUpdate && requestedPythonVersion < MinimumPythonVersion;
201-
var targetPythonVersion = shouldUpgradePython ? MinimumPythonVersion : requestedPythonVersion;
201+
var targetPythonVersion = shouldUpgradePython ? MinimumPythonVersion!.Value : requestedPythonVersion;
202202

203203
if (shouldUpgradePython)
204204
{

0 commit comments

Comments
 (0)