Skip to content

Commit

Permalink
Add references to new DSIronPython package version (#14752)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjkkirschner authored Dec 15, 2023
1 parent 34d4787 commit 72492c6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,10 @@ public int NodeSearchTagSizeLimit

/// <summary>
/// The Version of the IronPython package that Dynamo will download when it is found as missing in graphs.
/// This static property is not serialized and is assigned IronPythonResolveTargetVersion's value
/// This property is not serialized and is assigned IronPythonResolveTargetVersion's value
/// if found at deserialize time.
/// </summary>
internal static Version ironPythonResolveTargetVersion = new Version(2, 4, 0);
internal Version ironPythonResolveTargetVersion = new Version(3, 0, 0);

/// <summary>
/// The Version of the IronPython package that Dynamo will download when it is found as missing in graphs.
Expand Down
5 changes: 5 additions & 0 deletions src/DynamoCore/Core/DynamoMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ protected virtual PreferenceSettings ReadPreferences()
/// <returns>new migrator instance after migration</returns>
protected virtual DynamoMigratorBase MigrateFrom(DynamoMigratorBase sourceMigrator)
{
//allows us to access some default pref values of current version before prefs are
//actually written to disk(firstRun).
var currentVersionTempPrefs = new PreferenceSettings();

PreferenceSettings = sourceMigrator.PreferenceSettings;
if (PreferenceSettings == null) return this;

Expand All @@ -171,6 +175,7 @@ protected virtual DynamoMigratorBase MigrateFrom(DynamoMigratorBase sourceMigrat
// Also exclude SelectedPackagePathForInstall or it may point to previous
// Dynamo version folders. When set to string.empty or null - will default to UserDataFolder.
PreferenceSettings.SelectedPackagePathForInstall = string.Empty;
PreferenceSettings.IronPythonResolveTargetVersion = currentVersionTempPrefs.IronPythonResolveTargetVersion;

return this;
}
Expand Down
9 changes: 5 additions & 4 deletions src/PythonMigrationViewExtension/GraphPythonDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dynamo.Configuration;
using Dynamo.Configuration;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
Expand All @@ -16,7 +16,7 @@ namespace Dynamo.PythonMigration
public class GraphPythonDependencies
{
internal static readonly string PythonPackage = "DynamoIronPython2.7";
internal static readonly Version PythonPackageVersion = PreferenceSettings.ironPythonResolveTargetVersion;
internal readonly Version PythonPackageVersion;
private IWorkspaceModel workspace;
private readonly ICustomNodeManager customNodeManager;

Expand All @@ -33,10 +33,11 @@ internal enum CNPythonDependencyType
DirectDependency
}

internal GraphPythonDependencies(IWorkspaceModel workspaceModel, ICustomNodeManager customNodeManager)
internal GraphPythonDependencies(IWorkspaceModel workspaceModel, ICustomNodeManager customNodeManager, Version ironPythonTargetVersion)
{
this.workspace = workspaceModel;
workspace = workspaceModel;
this.customNodeManager = customNodeManager;
PythonPackageVersion = ironPythonTargetVersion;
}

internal void UpdateWorkspace(IWorkspaceModel workspaceModel)
Expand Down
11 changes: 10 additions & 1 deletion src/PythonMigrationViewExtension/PythonMigrationViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Linq;
using System.Windows;
using System.Windows.Threading;
using Dynamo.Configuration;
using Dynamo.Core;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.PackageManager;
using Dynamo.PythonMigration.Controls;
using Dynamo.PythonMigration.MigrationAssistant;
using Dynamo.PythonMigration.Properties;
Expand Down Expand Up @@ -59,7 +61,14 @@ public void Dispose()
public void Loaded(ViewLoadedParams p)
{
LoadedParams = p;
PythonDependencies = new GraphPythonDependencies(LoadedParams.CurrentWorkspaceModel, LoadedParams.StartupParams.CustomNodeManager);

var ironPythonVersion = new Version(3, 0, 0);
if(LoadedParams.StartupParams.Preferences is PreferenceSettings prefs)
{
Version.TryParse(prefs.IronPythonResolveTargetVersion,out ironPythonVersion);
}

PythonDependencies = new GraphPythonDependencies(LoadedParams.CurrentWorkspaceModel, LoadedParams.StartupParams.CustomNodeManager,ironPythonVersion );
DynamoViewModel = LoadedParams.DynamoWindow.DataContext as DynamoViewModel;
CurrentWorkspace = LoadedParams.CurrentWorkspaceModel as WorkspaceModel;
CustomNodeManager = (CustomNodeManager)LoadedParams.StartupParams.CustomNodeManager;
Expand Down
36 changes: 34 additions & 2 deletions test/DynamoCoreTests/UserDataMigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ private static void CreateMockPreferenceSettingsFile(string filePath, string pac
{
var settings = new PreferenceSettings
{
CustomPackageFolders = new List<string>{packageDir},
CustomPackageFolders = new List<string> { packageDir },
//need to mock this because PreferenceSettings.SelectedPackagePathForInstall uses an event to get UserDataFolder from PathManager
SelectedPackagePathForInstall = packageDir
SelectedPackagePathForInstall = packageDir,
IronPythonResolveTargetVersion = new Version(2,4,0).ToString(),
};
settings.Save(filePath);
}
Expand Down Expand Up @@ -383,5 +384,36 @@ public void TestSelectedDownloadPathIsNotMigrated()
Assert.AreNotEqual(sourcePrefs.SelectedPackagePathForInstall,
targetMigrator.PreferenceSettings.SelectedPackagePathForInstall);
}
[Test]
[Category("UnitTests")]
public void IronPythonVersionIsNotMigrated()
{
// Create some mock user data folders
string userDataDir;
CreateMockDirectoriesAndFiles(out userDataDir);

var sourceVersionDir = Path.Combine(userDataDir, "1.3");
var settingsFilePath = Path.Combine(sourceVersionDir, "DynamoSettings.xml");

CreateMockPreferenceSettingsFile(settingsFilePath, sourceVersionDir);

// Create mock objects for IPathManager and IPathResolver
var mockPathManager = new Mock<IPathManager>();

var currentVersionDir = Path.Combine(userDataDir, "2.0");

mockPathManager.Setup(x => x.UserDataDirectory).Returns(() => currentVersionDir);


// Test MigrateBetweenDynamoVersions
var targetMigrator = DynamoMigratorBase.MigrateBetweenDynamoVersions(
mockPathManager.Object);

var sourcePrefs = PreferenceSettings.Load(settingsFilePath);
Assert.AreEqual(sourceVersionDir, sourcePrefs.SelectedPackagePathForInstall);

// Assert that new ironPythonTargetVersion is not equal to the old version.
Assert.That(targetMigrator.PreferenceSettings.IronPythonResolveTargetVersion, Is.Not.EqualTo(sourcePrefs.IronPythonResolveTargetVersion));
}
}
}
2 changes: 1 addition & 1 deletion test/settings/DynamoSettings-NewSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
</GroupStyleItem>
</GroupStyleItemsList>
<NodeSearchTagSizeLimit>500</NodeSearchTagSizeLimit>
<IronPythonResolveTargetVersion>2.1.X</IronPythonResolveTargetVersion>
<IronPythonResolveTargetVersion>2.1.0</IronPythonResolveTargetVersion>
<ReadNotificationIds>
<string>1</string>
</ReadNotificationIds>
Expand Down

0 comments on commit 72492c6

Please sign in to comment.