Skip to content

Commit

Permalink
Merge branch 'master' into GetCustomDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
QilongTang committed Jan 23, 2025
2 parents 37c9015 + e14e089 commit 1735055
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 350 deletions.
1 change: 0 additions & 1 deletion src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@
<Compile Include="ViewModels\Preview\ConnectorAnchorViewModel.cs" />
<Compile Include="ViewModels\Preview\ConnectorContextMenuViewModel.cs" />
<Compile Include="ViewModels\RunSettingsViewModel.cs" />
<Compile Include="Utilities\ActionDebouncer.cs" />
<Compile Include="ViewModels\Search\BrowserInternalElementViewModel.cs" />
<Compile Include="ViewModels\Search\BrowserItemViewModel.cs" />
<Compile Include="ViewModels\Search\NodeAutoCompleteSearchViewModel.cs" />
Expand Down
61 changes: 0 additions & 61 deletions src/DynamoCoreWpf/Utilities/ActionDebouncer.cs

This file was deleted.

15 changes: 10 additions & 5 deletions src/DynamoCoreWpf/Utilities/CrashUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
using Dynamo.Configuration;
using Dynamo.Configuration;
using Dynamo.PackageManager;
using Dynamo.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dynamo.Wpf.Utilities
{
static class CrashUtilities
{
internal static string GithubNewIssueUrlFromCrashContent(object crashContent)
internal enum ReportType
{
Bug,
Crash
}

internal static string GithubNewIssueUrlFromCrashContent(object crashContent, ReportType reportType = ReportType.Crash)
{
var baseUri = new UriBuilder(Configurations.GitHubBugReportingLink);

var issueTitle = "Crash report from Dynamo {0}";
var issueTitle = "{0} report from Dynamo {1}";
var dynamoVersion = AssemblyHelper.GetDynamoVersion().ToString() ?? "2.1.0+";

// append the title and body to the URL as query parameters
// making sure we properly escape content since stack traces may contain characters not suitable
// for use in URLs
var title = "title=" + Uri.EscapeDataString(string.Format(issueTitle, dynamoVersion));
var title = "title=" + Uri.EscapeDataString(string.Format(issueTitle, reportType, dynamoVersion));
var template = "template=issue.yml";
var fields = "dynamo_version=" + Uri.EscapeDataString(dynamoVersion)
+ "&os=" + Uri.EscapeDataString(Environment.OSVersion.ToString())
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ internal bool CanDisplayFunction(object parameters)
/// <param name="bodyContent">Crash details body. If null, nothing will be filled-in.</param>
public static void ReportABug(object bodyContent)
{
var urlWithParameters = Wpf.Utilities.CrashUtilities.GithubNewIssueUrlFromCrashContent(bodyContent);
var urlWithParameters = Wpf.Utilities.CrashUtilities.GithubNewIssueUrlFromCrashContent(bodyContent, CrashUtilities.ReportType.Bug);

// launching the process using explorer.exe will format the URL incorrectly
// and Github will not recognise the query parameters in the URL
Expand Down
44 changes: 2 additions & 42 deletions src/DynamoCoreWpf/ViewModels/Search/SearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
using Dynamo.UI;
using Dynamo.Utilities;
using Dynamo.Wpf.Services;
using Dynamo.Wpf.Utilities;
using Dynamo.Wpf.ViewModels;
using DynamoUtilities;

namespace Dynamo.ViewModels
{
Expand Down Expand Up @@ -75,11 +73,7 @@ public bool BrowserVisibility
set { browserVisibility = value; RaisePropertyChanged("BrowserVisibility"); }
}

internal int searchDelayTimeout = 150;
// Feature flags activated debouncer for the search UI.
internal ActionDebouncer searchDebouncer = null;

private string searchText = string.Empty;
private string searchText;
/// <summary>
/// SearchText property
/// </summary>
Expand All @@ -92,28 +86,10 @@ public string SearchText
set
{
searchText = value;

OnSearchTextChanged(this, EventArgs.Empty);
RaisePropertyChanged("SearchText");
RaisePropertyChanged("BrowserRootCategories");
RaisePropertyChanged("CurrentMode");

// The searchText is set multiple times before the control becomes visible and interactable.
// To prevent any debounces from triggering at some unexpected point before or after the control
// becomes visible, this flag is only set once the searchText value is set by the user
// (unless it somehow gets set somewhere else)
//
// pinzart: The search text is set multiple times with an empty value. Seems sufficient to only use the debouncer
// if we get a non-empty value.
if (!string.IsNullOrEmpty(searchText) && searchDebouncer != null)
{
searchDebouncer.Debounce(searchDelayTimeout, () => OnSearchTextChanged(this, EventArgs.Empty));
}
else
{
// Make sure any previously scheduled debounces are cancelled
searchDebouncer?.Cancel();
OnSearchTextChanged(this, EventArgs.Empty);
}
}
}

Expand Down Expand Up @@ -398,19 +374,9 @@ internal SearchViewModel(DynamoViewModel dynamoViewModel)

iconServices = new IconServices(pathManager);

DynamoFeatureFlagsManager.FlagsRetrieved += TryInitializeDebouncer;

InitializeCore();
}

private void TryInitializeDebouncer()
{
if (DynamoModel.FeatureFlags?.CheckFeatureFlag("searchbar_debounce", false) ?? false)
{
searchDebouncer ??= new ActionDebouncer(dynamoViewModel?.Model?.Logger);
}
}

// Just for tests. Please refer to LibraryTests.cs
internal SearchViewModel(NodeSearchModel model)
{
Expand Down Expand Up @@ -441,9 +407,6 @@ public override void Dispose()
Model.EntryUpdated -= UpdateEntry;
Model.EntryRemoved -= RemoveEntry;

searchDebouncer?.Dispose();
DynamoFeatureFlagsManager.FlagsRetrieved -= TryInitializeDebouncer;

base.Dispose();
}

Expand Down Expand Up @@ -471,9 +434,6 @@ private void InitializeCore()

DefineFullCategoryNames(LibraryRootCategories, "");
InsertClassesIntoTree(LibraryRootCategories);

// If feature flags are already cached, try to initialize the debouncer
TryInitializeDebouncer();
}

private void AddEntry(NodeSearchElement entry)
Expand Down
90 changes: 53 additions & 37 deletions src/Libraries/DSCPython/CPythonEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Autodesk.DesignScript.Runtime;
Expand Down Expand Up @@ -145,6 +146,8 @@ public class CPythonEvaluator : Dynamo.PythonServices.PythonEngine

private static PyScope globalScope;
private static DynamoLogger dynamoLogger;
private static string path;

internal static DynamoLogger DynamoLogger {
get
{ // Session is null when running unit tests.
Expand Down Expand Up @@ -261,60 +264,66 @@ public override object Evaluate(
{
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();

}

using (Py.GIL())
using (PyScope scope = Py.CreateScope())
{
if (globalScope == null)
{
globalScope = CreateGlobalScope();
}
scope.Exec("import sys" + Environment.NewLine + "path = str(sys.path)");
path = scope.Get<string>("path");
}
}

using (PyScope scope = Py.CreateScope())
using (Py.GIL())
{
globalScope ??= CreateGlobalScope();
using (PyScope scope = Py.CreateScope())
{
if (path is not null)
{
// Reset the 'sys.path' value to the default python paths on node evaluation.
var pythonNodeSetupCode = "import sys" + Environment.NewLine + "sys.path = sys.path[0:3]";
// Reset the 'sys.path' value to the default python paths on node evaluation. See https://github.com/DynamoDS/Dynamo/pull/10977.
var pythonNodeSetupCode = "import sys" + Environment.NewLine + $"sys.path = {path}";
scope.Exec(pythonNodeSetupCode);
}

ProcessAdditionalBindings(scope, bindingNames, bindingValues);
ProcessAdditionalBindings(scope, bindingNames, bindingValues);

int amt = Math.Min(bindingNames.Count, bindingValues.Count);
int amt = Math.Min(bindingNames.Count, bindingValues.Count);

for (int i = 0; i < amt; i++)
{
scope.Set((string)bindingNames[i], InputMarshaler.Marshal(bindingValues[i]).ToPython());
}
for (int i = 0; i < amt; i++)
{
scope.Set((string)bindingNames[i], InputMarshaler.Marshal(bindingValues[i]).ToPython());
}

try
{
OnEvaluationBegin(scope, code, bindingValues);
scope.Exec(code);
var result = scope.Contains("OUT") ? scope.Get("OUT") : null;
try
{
OnEvaluationBegin(scope, code, bindingValues);
scope.Exec(code);
var result = scope.Contains("OUT") ? scope.Get("OUT") : null;

return OutputMarshaler.Marshal(result);
return OutputMarshaler.Marshal(result);
}
catch (Exception e)
{
evaluationSuccess = false;
var traceBack = GetTraceBack(e);
if (!string.IsNullOrEmpty(traceBack))
{
// Throw a new error including trace back info added to the message
throw new InvalidOperationException($"{e.Message} {traceBack}", e);
}
catch (Exception e)
else
{
evaluationSuccess = false;
var traceBack = GetTraceBack(e);
if (!string.IsNullOrEmpty(traceBack))
{
// Throw a new error including trace back info added to the message
throw new InvalidOperationException($"{e.Message} {traceBack}", e);
}
else
{
#pragma warning disable CA2200 // Rethrow to preserve stack details
throw e;
throw e;
#pragma warning restore CA2200 // Rethrow to preserve stack details
}
}
finally
{
OnEvaluationEnd(evaluationSuccess, scope, code, bindingValues);
}
}
finally
{
OnEvaluationEnd(evaluationSuccess, scope, code, bindingValues);
}
}
}
}

public static object EvaluatePythonScript(
Expand Down Expand Up @@ -476,6 +485,13 @@ internal override void RegisterHostDataMarshalers()
}
}
var unmarshalled = pyObj.AsManagedObject(typeof(object));

// Avoid calling this marshaler infinitely.
if (unmarshalled is PyObject)
{
return unmarshalled;
}

return dataMarshalerToUse.Marshal(unmarshalled);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/NodeServices/PythonServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ internal abstract class PythonCodeCompletionProviderCommon : IExternalCodeComple
internal static readonly Regex MATCH_FROM_IMPORT_STATEMENTS = new Regex(@"from\s+?([\w.]+)\s+?import\s+?([\w, *]+)", RegexOptions.Compiled | RegexOptions.Multiline);
internal static readonly Regex MATCH_VARIABLE_ASSIGNMENTS = new Regex(@"^[ \t]*?(\w+(\s*?,\s*?\w+)*)\s*?=\s*(.+)", RegexOptions.Compiled | RegexOptions.Multiline);

internal static readonly Regex STRING_VARIABLE = new Regex("[\"']([^\"']*)[\"']", RegexOptions.Compiled);
internal static readonly Regex DOUBLE_VARIABLE = new Regex("^-?\\d+\\.\\d+", RegexOptions.Compiled);
internal static readonly Regex INT_VARIABLE = new Regex("^-?\\d+", RegexOptions.Compiled);
internal static readonly Regex LIST_VARIABLE = new Regex("\\[.*\\]", RegexOptions.Compiled);
internal static readonly Regex DICT_VARIABLE = new Regex("{.*}", RegexOptions.Compiled);
internal static readonly Regex STRING_VARIABLE = new Regex("^[\"']([^\"']*)[\"']$", RegexOptions.Compiled);
internal static readonly Regex DOUBLE_VARIABLE = new Regex("^-?\\d+\\.\\d+$", RegexOptions.Compiled);
internal static readonly Regex INT_VARIABLE = new Regex("^-?\\d+$", RegexOptions.Compiled);
internal static readonly Regex LIST_VARIABLE = new Regex("^\\[.*\\]$", RegexOptions.Compiled);
internal static readonly Regex DICT_VARIABLE = new Regex("^{.*}$", RegexOptions.Compiled);

internal static readonly string BAD_ASSIGNEMNT_ENDS = ",([{";

Expand Down
4 changes: 1 addition & 3 deletions src/Tools/DynamoFeatureFlags/FeatureFlagsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ internal FeatureFlagsClient(string userkey, string mobileKey = null, bool testMo
AllFlags = LdValue.ObjectFrom(new Dictionary<string,LdValue> { { "TestFlag1",LdValue.Of(true) },
{ "TestFlag2", LdValue.Of("I am a string") },
//in tests we want instancing on so we can test it.
{ "graphics-primitive-instancing", LdValue.Of(true) },
//in tests we want search debouncing on so we can test it.
{ "searchbar_debounce", LdValue.Of(true) } });
{ "graphics-primitive-instancing", LdValue.Of(true) } });
return;
}

Expand Down
Loading

0 comments on commit 1735055

Please sign in to comment.