diff --git a/src/DynamoCore/Configuration/PreferenceSettings.cs b/src/DynamoCore/Configuration/PreferenceSettings.cs index 02b0b183e92..4705daf0c3f 100644 --- a/src/DynamoCore/Configuration/PreferenceSettings.cs +++ b/src/DynamoCore/Configuration/PreferenceSettings.cs @@ -853,10 +853,10 @@ public int NodeSearchTagSizeLimit /// /// 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. /// - internal static Version ironPythonResolveTargetVersion = new Version(2, 4, 0); + internal Version ironPythonResolveTargetVersion = new Version(3, 0, 0); /// /// The Version of the IronPython package that Dynamo will download when it is found as missing in graphs. diff --git a/src/DynamoCore/Core/DynamoMigrator.cs b/src/DynamoCore/Core/DynamoMigrator.cs index 85f87cf4299..8f339ce255c 100644 --- a/src/DynamoCore/Core/DynamoMigrator.cs +++ b/src/DynamoCore/Core/DynamoMigrator.cs @@ -162,6 +162,10 @@ protected virtual PreferenceSettings ReadPreferences() /// new migrator instance after migration 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; @@ -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; } diff --git a/src/PythonMigrationViewExtension/GraphPythonDependencies.cs b/src/PythonMigrationViewExtension/GraphPythonDependencies.cs index c6eec707ea7..6a8f3cf7f64 100644 --- a/src/PythonMigrationViewExtension/GraphPythonDependencies.cs +++ b/src/PythonMigrationViewExtension/GraphPythonDependencies.cs @@ -1,4 +1,4 @@ -using Dynamo.Configuration; +using Dynamo.Configuration; using Dynamo.Graph.Nodes; using Dynamo.Graph.Nodes.CustomNodes; using Dynamo.Graph.Workspaces; @@ -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; @@ -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) diff --git a/src/PythonMigrationViewExtension/PythonMigrationViewExtension.cs b/src/PythonMigrationViewExtension/PythonMigrationViewExtension.cs index 1c28c53381c..df7ab4a3550 100644 --- a/src/PythonMigrationViewExtension/PythonMigrationViewExtension.cs +++ b/src/PythonMigrationViewExtension/PythonMigrationViewExtension.cs @@ -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; @@ -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; diff --git a/test/DynamoCoreTests/UserDataMigrationTests.cs b/test/DynamoCoreTests/UserDataMigrationTests.cs index 9b9ed5776ef..3c00f5d8437 100644 --- a/test/DynamoCoreTests/UserDataMigrationTests.cs +++ b/test/DynamoCoreTests/UserDataMigrationTests.cs @@ -266,9 +266,10 @@ private static void CreateMockPreferenceSettingsFile(string filePath, string pac { var settings = new PreferenceSettings { - CustomPackageFolders = new List{packageDir}, + CustomPackageFolders = new List { 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); } @@ -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(); + + 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)); + } } } diff --git a/test/settings/DynamoSettings-NewSettings.xml b/test/settings/DynamoSettings-NewSettings.xml index 4ae2b3afca4..e3a0977f028 100644 --- a/test/settings/DynamoSettings-NewSettings.xml +++ b/test/settings/DynamoSettings-NewSettings.xml @@ -132,7 +132,7 @@ 500 - 2.1.X + 2.1.0 1