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

[Draft] Defer loading of workspace referenced packages until workspace open #11502

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,8 @@ private bool OpenJsonFileFromPath(string fileContents, string filePath, bool for
OnComputeModelDeserialized();

SetPeriodicEvaluation(ws);

CurrentWorkspace = ws;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the current workspace here, after the VM is re-initialized and all libs/packages are reloaded. This will trigger the property changed event for CurrentWorkspace at the right time for the DynamoPackages extension to react to it and load packages for that new workspace.

}
}
}
Expand Down Expand Up @@ -1771,7 +1773,7 @@ private void OpenWorkspace(WorkspaceModel ws)
}

AddWorkspace(ws);
CurrentWorkspace = ws;
//CurrentWorkspace = ws;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope this doesn't cause any side-effects. As noted above I have moved this so that it happens a little later in the workspace opening sequence.

OnWorkspaceOpened(ws);
}

Expand Down
33 changes: 32 additions & 1 deletion src/DynamoPackages/PackageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Dynamo.Core;
using Dynamo.Exceptions;
using Dynamo.Extensions;
using Dynamo.Graph.Workspaces;
using Dynamo.Interfaces;
using Dynamo.Logging;
using Dynamo.Utilities;
Expand Down Expand Up @@ -91,7 +92,7 @@ public PackageLoader(IEnumerable<string> packagesDirectories)
if (packagesDirectories == null)
throw new ArgumentNullException("packagesDirectories");

this.packagesDirectories.AddRange(packagesDirectories);
//this.packagesDirectories.AddRange(packagesDirectories);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't load all packages, just the ones in the standard lib.

this.packagesDirectories.Add(StandardLibraryDirectory);

var error = PathHelper.CreateFolderIfNotExist(DefaultPackagesDirectory);
Expand All @@ -102,6 +103,36 @@ public PackageLoader(IEnumerable<string> packagesDirectories)
packagesDirectoriesToVerifyCertificates.Add(StandardLibraryDirectory);
}

internal void OnWorkspaceOpened(IEnumerable<INodeLibraryDependencyInfo> packageDependencies,
IEnumerable<string> packageDirectories)
{
var pkgs = new List<Package>();
foreach (var root in packageDirectories)
{
foreach (var dir in
Directory.EnumerateDirectories(root, "*", SearchOption.TopDirectoryOnly))
{
var headerPath = Path.Combine(dir, "pkg.json");
if (PathHelper.IsValidPath(headerPath))
{
var discoveredPkg = Package.FromJson(headerPath, AsLogger());
if(discoveredPkg == null) continue;

foreach (var info in packageDependencies)
{
// if workspace package dependency is present in downloaded packages, load it.
if (info.Name == discoveredPkg.Name && info.Version.ToString() == discoveredPkg.VersionName)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collect all downloaded packages that match with the ones referenced in the workspace.

{
pkgs.Add(discoveredPkg);
break;
}
}
}
}
}
LoadPackages(pkgs);
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
/// Initialize a new instance of PackageLoader class
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoPackages/PackageManagerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ private void OnCurrentWorkspaceChanged(IWorkspaceModel ws)
(ws as WorkspaceModel).CollectingCustomNodePackageDependencies += GetCustomNodePackageFromID;
(ws as WorkspaceModel).CollectingNodePackageDependencies += GetNodePackageFromAssemblyName;
currentWorkspace = ws;

if (PackageLoader != null && ws is HomeWorkspaceModel model)
{
PackageLoader.OnWorkspaceOpened(model.NodeLibraryDependencies,
ReadyParams.StartupParams.PathManager.PackagesDirectories);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Called once a new workspace is opened.

}
}
}

Expand Down