Skip to content
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

T1.3 save python2 backup file #10928

Merged
merged 58 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9e29adc
T1.1 Code Migration (#4)
SHKnudsen Jul 3, 2020
0fbd696
Update PythonMigrationViewExtension.csproj
SHKnudsen Jul 3, 2020
c0ab018
T1.2 accept/reject code changes (#5)
SHKnudsen Jul 3, 2020
1684a49
update engine version when migrating code
SHKnudsen Jul 6, 2020
e52d617
Merge remote-tracking branch 'upstream/master' into T1.1-CodeMigration
SHKnudsen Jul 6, 2020
b7fe228
extension and test updates
SHKnudsen Jul 6, 2020
f168751
Merge branch 'T1.1-CodeMigration' into T1.2-AcceptReject-CodeChanges
SHKnudsen Jul 6, 2020
831946e
T1.3 save python2 backup file on migration (#6)
SHKnudsen Jul 6, 2020
7229746
Merge branch 'T1.3-SavePython2BackupFile' of https://github.com/SHKnu…
SHKnudsen Jul 6, 2020
6caa0db
add 2to3 icon
SHKnudsen Jul 6, 2020
451a980
Merge branch 'T1.1-CodeMigration' into T1.2-AcceptReject-CodeChanges
SHKnudsen Jul 6, 2020
9542bf8
Merge branch 'T1.2-AcceptReject-CodeChanges' into T1.3-SavePython2Bac…
SHKnudsen Jul 6, 2020
8a70055
comment updates
SHKnudsen Jul 14, 2020
f9ab1d5
GraphPythonDependencies changes
SHKnudsen Jul 14, 2020
8d2f36b
Merge branch 'master' into T1.1-CodeMigration
SHKnudsen Jul 14, 2020
f3edb0f
make event internal
SHKnudsen Jul 14, 2020
3f264dd
fix build failure
SHKnudsen Jul 14, 2020
c34f729
update license files, MigrationAssitantClicked event and PythonMigrat…
SHKnudsen Jul 20, 2020
fdf7fe6
Merge branch 'master' into T1.1-CodeMigration
SHKnudsen Jul 20, 2020
904dee5
Merge branch 'T1.1-CodeMigration' into T1.2-AcceptReject-CodeChanges
SHKnudsen Jul 20, 2020
d497eb4
clean up
SHKnudsen Jul 20, 2020
33f5aad
Merge branch 'T1.2-AcceptReject-CodeChanges' into T1.3-SavePython2Bac…
SHKnudsen Jul 20, 2020
235851d
clean up
SHKnudsen Jul 20, 2020
cfb0a98
update licence files
SHKnudsen Jul 21, 2020
6912267
Merge branch 'T1.1-CodeMigration' into T1.2-AcceptReject-CodeChanges
SHKnudsen Jul 21, 2020
acbe079
Merge branch 'T1.2-AcceptReject-CodeChanges' into T1.3-SavePython2Bac…
SHKnudsen Jul 21, 2020
9bec448
Merge remote-tracking branch 'upstream/master' into T1.2-AcceptReject…
SHKnudsen Jul 21, 2020
f06d7a2
make MigrateCode internal
SHKnudsen Jul 21, 2020
088e008
comments update
SHKnudsen Jul 22, 2020
303c644
unsubscribe from ScriptEditorWindow closed
SHKnudsen Jul 23, 2020
0ae75be
Merge branch 'T1.2-AcceptReject-CodeChanges' into T1.3-SavePython2Bac…
SHKnudsen Jul 23, 2020
27d53b2
Add 'Before' and 'After' properties (for some reason they where gone)
SHKnudsen Jul 23, 2020
50453fd
Merge remote-tracking branch 'upstream/master' into T1.3-SavePython2B…
SHKnudsen Jul 23, 2020
340e96e
Merge branch 'master' into T1.3-SavePython2BackupFile
SHKnudsen Jul 23, 2020
677d04c
refactor internal methods to bail early
radumg Jul 29, 2020
14706b5
rename IronPython dependency method
radumg Jul 29, 2020
c50b1e1
switch custom node python deps eval to short-circuit and add xml comment
radumg Jul 29, 2020
3416492
rename & move CPython deps method around
radumg Jul 29, 2020
142e10c
prep support for handling dyn and dyf in migration backup
radumg Jul 29, 2020
19a58a6
Merge branch 'master' into pr/10928
radumg Jul 29, 2020
e9c4d55
handle dyf vs dyn difference in migration backup
radumg Jul 29, 2020
01c637a
notify user that a backup file is created on Python migration
radumg Jul 29, 2020
4012e14
fix tests
radumg Jul 29, 2020
b2797f3
move CustomNodeItem class as private to the warning dialog that needs it
radumg Jul 29, 2020
0c1262a
mark the PythonNode script setter for migration as Obsolet
radumg Jul 29, 2020
174206d
change migration assistant viewmodel to depend on workspace and pathm…
radumg Jul 29, 2020
971abb1
DYN-2990 address accessing null reference
radumg Jul 29, 2020
f517b6d
remove prism reference
radumg Jul 29, 2020
02b9e7d
add note to obsolete MigrateCode method
radumg Jul 29, 2020
7b411c4
move migration assistant viewmodel to its namesake namespace
radumg Jul 29, 2020
b7abd75
make GraphPythonDependencies depend on interfaces instead of general …
radumg Jul 29, 2020
d7aec9a
revert graph python dependency evaluation logic to not be short-circu…
radumg Jul 29, 2020
4fc5919
update comment
radumg Jul 29, 2020
dbedf37
fix botched namespace change
radumg Jul 29, 2020
9913c8b
move 'More info' button on script editor window
SHKnudsen Aug 4, 2020
f0145b4
comment updates + add automated test for backup functionality
SHKnudsen Aug 4, 2020
2d0e17a
Update migrate_2to3.py
SHKnudsen Aug 4, 2020
6f592a5
Update PythonMigrationAssistantViewModel.cs
SHKnudsen Aug 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Libraries/PythonNodeModels/PythonNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
return base.UpdateValueCore(updateValueParams);
}

[Obsolete("This method is part of the temporary IronPython to CPython3 migration feature and will be removed in future versions of Dynamo.")]
/// <summary>
/// Updates the Script property of the node.
/// Updates the Script property of the node and raise the migration event notifications.
/// NOTE: This is a temporary method used during the Python 2 to Python 3 transistion period,
/// it will be removed when the transistion period is over.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Libraries/PythonNodeModelsWpf/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5df40db3-627c-43fb-9a0e-0ee422d92485")]

[assembly:InternalsVisibleTo("DynamoPythonTests")]
[assembly:InternalsVisibleTo("DynamoPythonTests")]
[assembly: InternalsVisibleTo("DynamoCoreWpfTests")]
8 changes: 4 additions & 4 deletions src/Libraries/PythonNodeModelsWpf/ScriptEditorWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@
Source="/PythonNodeModelsWpf;component/Resources/2to3Icon.png" />
</Button.Resources>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right"
Grid.Column="1">
<Button Style="{StaticResource IconButton}"
Name="MoreInfoButton"
Click="OnMoreInfoClicked"
Expand All @@ -139,6 +135,10 @@
Icon="QuestionCircleOutline" />
</Button.Resources>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right"
Grid.Column="1">
<Button Style="{StaticResource IconButton}"
Name="SaveScriptChangesButton"
Click="OnSaveClicked"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows;
using DiffPlex.Wpf.Controls;
using Dynamo.PythonMigration.MigrationAssistant;

namespace Dynamo.PythonMigration.Controls
{
Expand Down
124 changes: 68 additions & 56 deletions src/PythonMigrationViewExtension/GraphPythonDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Wpf.Extensions;
using PythonNodeModels;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dynamo.PythonMigration
{
/// <summary>
/// Class that helps with determining if a graph has specific Python dependecies and identifying them.
/// </summary>
public class GraphPythonDependencies
{
private ViewLoadedParams ViewLoaded { get; set; }
internal static readonly string PythonPackage = "DSIronPython_Test";
internal static readonly Version PythonPackageVersion = new Version(1, 0, 8);
private IWorkspaceModel workspace;
private readonly ICustomNodeManager customNodeManager;


// A dictionary to mark Custom Nodes if they have a IronPython dependency or not.
/// <summary>
/// A dictionary to mark Custom Nodes if they have a IronPython dependency or not.
/// Data in this dictionary is required to display all the affected nodes in the IronPython warning modal.
/// </summary>
internal static Dictionary<Guid, CNPythonDependencyType> CustomNodePythonDependencyMap = new Dictionary<Guid, CNPythonDependencyType>();

internal enum CNPythonDependencyType
Expand All @@ -26,50 +31,63 @@ internal enum CNPythonDependencyType
DirectDependency
}

internal GraphPythonDependencies(ViewLoadedParams viewLoadedParams)
internal GraphPythonDependencies(IWorkspaceModel workspaceModel, ICustomNodeManager customNodeManager)
{
ViewLoaded = viewLoadedParams;
this.workspace = workspaceModel;
this.customNodeManager = customNodeManager;
}

private static bool IsIronPythonPackageLoaded()
internal void UpdateWorkspace(IWorkspaceModel workspaceModel)
{
PythonEngineSelector.Instance.GetEvaluatorInfo(PythonEngineVersion.IronPython2,
out string evaluatorClass, out string evaluationMethod);
if (evaluatorClass == PythonEngineSelector.Instance.IronPythonEvaluatorClass &&
evaluationMethod == PythonEngineSelector.Instance.IronPythonEvaluationMethod)
{
return true;
}
return false;
this.workspace = workspaceModel;
}

internal bool ContainsIronPythonDependencyInCurrentWS()
private static bool IsIronPythonPackageLoaded()
{
var containsIronPythonDependency = false;
PythonEngineSelector.Instance.GetEvaluatorInfo(
PythonEngineVersion.IronPython2,
out string evaluatorClass,
out string evaluationMethod);

var workspace = ViewLoaded.CurrentWorkspaceModel as WorkspaceModel;
return evaluatorClass == PythonEngineSelector.Instance.IronPythonEvaluatorClass
&& evaluationMethod == PythonEngineSelector.Instance.IronPythonEvaluationMethod;
}

var customNodeManager = ViewLoaded.StartupParams.CustomNodeManager;
/// <summary>
/// Determines if the current workspace has any dependencies on IronPython engine.
/// </summary>
/// <returns>True if depencies are found, false otherwise.</returns>
internal bool CurrentWorkspaceHasIronPythonDependency()
{
var hasIronPythonDependency = false;

if (workspace.Nodes.Any(IsIronPythonNode))
{
containsIronPythonDependency = true;
}
// Check if any Python nodes in graph are using the IronPython engine
if (this.workspace.Nodes.Any(IsIronPythonNode))
hasIronPythonDependency = true;

// Check if any of the custom nodes has IronPython dependencies in it.
var customNodes = workspace.Nodes.OfType<Function>();
// Check if any of the custom nodes have IronPython dependencies
var customNodes = this.workspace.Nodes.OfType<Function>();
if (CustomNodesHaveIronPythonDependency(customNodes, this.customNodeManager))
hasIronPythonDependency = true;

if (CustomNodesContainIronPythonDependency(customNodes, customNodeManager))
{
containsIronPythonDependency = true;
}
return hasIronPythonDependency;
}

/// <summary>
/// Determines if the current workspace has any dependencies on CPython engine.
/// </summary>
/// <returns>True if depencies are found, false otherwise.</returns>
internal bool CurrentWorkspaceHasCPythonDependencies()
{
if (this.workspace == null)
throw new ArgumentNullException(nameof(this.workspace));

return containsIronPythonDependency;
return this.workspace.Nodes.Any(IsCPythonNode);
}

internal IEnumerable<INodeLibraryDependencyInfo> AddPythonPackageDependency()
{
if (!ContainsIronPythonDependencyInCurrentWS())
if (!CurrentWorkspaceHasIronPythonDependency())
return null;

var packageInfo = new PackageInfo(PythonPackage, PythonPackageVersion);
Expand All @@ -81,12 +99,17 @@ internal IEnumerable<INodeLibraryDependencyInfo> AddPythonPackageDependency()
return new[] { packageDependencyInfo };
}

// This function returns true, if any of the custom nodes in the input list has an IronPython dependency.
// It traverses all CN's in the given list of customNodes and marks them as true in CustomNodePythonDependency,
// if the prarent custom node or any of its child custom nodes contain an IronPython dependency.
private static bool CustomNodesContainIronPythonDependency(IEnumerable<Function> customNodes, ICustomNodeManager customNodeManager)
/// <summary>
/// This recursive function returns true if any of the custom nodes in the input list has an IronPython dependency.
radumg marked this conversation as resolved.
Show resolved Hide resolved
/// Any custom nodes in the input list traversed during evalution have their dependencies cached in <see cref="CustomNodePythonDependencyMap"/>.
/// Custom nodes are found to depend on IronPython if the parent custom node or any of its child custom nodes contain an IronPython dependency.
/// </summary>
/// <param name="customNodes">The custom nodes to evaluate.</param>
/// <param name="customNodeManager">The custom node manager.</param>
/// <returns>True if any IronPython depencies are found, false otherwise.</returns>
private static bool CustomNodesHaveIronPythonDependency(IEnumerable<Function> customNodes, ICustomNodeManager customNodeManager)
{
var containIronPythonDependency = false;
var hasIronPythonDependency = false;

foreach (var customNode in customNodes)
{
Expand All @@ -99,9 +122,7 @@ private static bool CustomNodesContainIronPythonDependency(IEnumerable<Function>
if (CustomNodePythonDependencyMap.TryGetValue(customNodeWS.CustomNodeId, out CNPythonDependencyType dependency))
{
if (dependency == CNPythonDependencyType.DirectDependency || dependency == CNPythonDependencyType.NestedDependency)
{
containIronPythonDependency = true;
}
hasIronPythonDependency = true;
continue;
}

Expand All @@ -110,7 +131,7 @@ private static bool CustomNodesContainIronPythonDependency(IEnumerable<Function>
if (hasPythonNodesInCustomNodeWorkspace)
{
CustomNodePythonDependencyMap.Add(customNodeWS.CustomNodeId, CNPythonDependencyType.DirectDependency);
containIronPythonDependency = true;
hasIronPythonDependency = true;
}
else
{
Expand All @@ -122,28 +143,19 @@ private static bool CustomNodesContainIronPythonDependency(IEnumerable<Function>

if (nestedCustomNodes.Any())
{
hasPythonNodesInCustomNodeWorkspace = CustomNodesContainIronPythonDependency(nestedCustomNodes, customNodeManager);
hasPythonNodesInCustomNodeWorkspace = CustomNodesHaveIronPythonDependency(nestedCustomNodes, customNodeManager);

// If a custom node contains an IronPython dependency in its sub-tree,
// update its corresponding value to 'NestedDependency' in CustomNodePythonDependency.
if (hasPythonNodesInCustomNodeWorkspace && CustomNodePythonDependencyMap[customNodeWS.CustomNodeId] != CNPythonDependencyType.DirectDependency)
{
CustomNodePythonDependencyMap[customNodeWS.CustomNodeId] = CNPythonDependencyType.NestedDependency;
containIronPythonDependency = true;
hasIronPythonDependency = true;
}
}
}

return containIronPythonDependency;
}

internal bool ContainsCPythonDependencies()
{
var workspace = ViewLoaded.CurrentWorkspaceModel;
if (workspace == null)
throw new ArgumentNullException(nameof(workspace));

return workspace.Nodes.Any(n => IsCPythonNode(n));
return hasIronPythonDependency;
}

internal static bool IsIronPythonNode(NodeModel obj)
Expand Down
Loading