-
Notifications
You must be signed in to change notification settings - Fork 668
Python Engine Switcher for internal testing #10565
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
Conversation
|
Self serve is a pass, the failing test is a sporadic failure |
| /// </summary> | ||
| private void UpdateToPython2Engine() | ||
| { | ||
| pythonNodeModel.Engine = PythonNodeBase.DefaultPythonEngine; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to rely on PythonNodeBase.DefaultPythonEngine pointing to version 2, as we should eventually make version 3 the default, and then this code would break. Is there some other constant/enum that we can use that's explicitly about Python 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmisol If we change the value for PythonNodeBase.DefaultPythonEngine, we should update the code here. Let me add a TODO, this is the only new flag we added, there is no other indication. Also I think this alpha test code will be removed later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @mmisol, this should check for 2 directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked out the branch to take a look at the code. Renaming the DefaultPythonEngine constant to PythonNet2Engine (or something with a 2 in it :) ) would be good to me.
Edit: Copying relevant code for reference
public static readonly string DefaultPythonEngine = "IronPython2";
public static readonly string PythonNet3Engine = "CPython3";
private string engine = DefaultPythonEngine;
public string Engine
{
get { return engine; }
set
{
if (engine != value)
{
engine = value;
RaisePropertyChanged("Engine");
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order should not be a problem if they were serialized as strings, but I agree that you lose the flexibility of maybe having other python engines loaded dynamically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree enums would be superior here. What we really would like is a type-checked enum that can be dynamically populated by what assemblies you have loaded (so the enum only contains CPython3 if DSCPython.dll is loaded and DSIronPython.dll is not.)
This sort of fancy, module-spanning dynamic enum has been built in C++ for other products. I'm not sure there's an easy technical solution in C#, but it seems possible. I think this is a good area to investigate further in the tasks to make the engines optional; it doesn't need to gate merging this feature.
It might be a good idea to make the property non-public so we preserve the ability to change the API before the Python 3 features are finalized. The property will have to be serialized to a string in .dyn files regardless, so a move to enums won't have to break graphs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see the source of the confusion now. The DefaultPythonEngine static property was not intended to be "the name of Python 2 engine" it was intended to mean "which of the possible values of this string-faked enumeration should be assigned to nodes that do not have a value of the Engine property at deserialization time." The idea was it would be set once here, and referenced wherever we needed to, and in the future when we make the default 3, we can change it in one place.
Ideally, the NodeModel code wouldn't know about the details of either of these engines. We could create a RegisteredPythonEngines data structure and each engine DLL could call a RegisterPythonEngine method during initialization, providing a serialization name and an entry point.
We should also separate the concept of "the default value of this property on new nodes" from "the value we attach for graphs from 2.6 and earlier." We will want to change the default engine from 2 to 3 in the future, but pre-2.6 graphs should always be set to 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are important point's Mike - thanks for clarifying them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm I think contractor's work especially the UI part and editor switch will need the whole series of the values somewhere. Do you have a preference between Enums with display name or set of strings? I think we need them available anyway. We can implement the dynamic list later but probably need a static list to solve the immediate needs.
|
Hi @DynamoDS/dynamo and @Dewb I have added Enums with display value instead of static string from our discussion to remove the whole confusion around version checking. Currently it is as Maybe for the enum values we can move to use the actual version number so they are still identical plus we reserve more information? What do you think. I am supportive of getting version info loading time as a future improvement as well. Notice after the change, the graph schema is still consistent with before. |
|
I don't think we need to maintain both a string and an enum version of the property for compatibility. The enum alone should be sufficient. On the other hand, it might be a good idea to go ahead and build the engine registration data structure now. Something like: public class PythonEngine
{
public string Name;
public string Version;
public Func<string, IList, IList, object> Evaluator;
public bool IsDeprecated;
}
Dictionary<String, PythonEngine> RegisteredPythonEngines;
RegisterPythonEngine(PythonEngine engine)
{
RegisteredPythonEngines.Add(engine.Name, engine);
}and then call RegisterPythonEngine inside a static constructor in each engine assembly. |
|
Addressed some comments, please let me know. @Dewb The string property is there so that serialization can happen without a dedicated converter, the default serialization logic for enum is its number value. Due to the impact of this work to what @SHKnudsen is doing, I would like to wrap up and sync with the UI work potentially building on top of it. Plus this should give @SHKnudsen an easier way to test the engine switch. I would like to address the good points raised by @Dewb here in the follow up Jira task. |
|
@QilongTang How about having a single property called Also, is there a reason to keep the |
|
@mmisol Thank you for pointing out. Addressed your comments and cleaned up changes |
mmisol
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me but please address that last comment
|
@mmisol Removed. Merging |
Please Note:
DynamoRevitrepo will need to be cherry-picked into all the DynamoRevit Release branches that Dynamo supports. Contributors will be responsible for cherry-picking their reviewed commits to the other branches after aLGTMlabel is added to the PR.Purpose
Team agreed that we are not going to introduce any setting in Debug Menu. Instead, simply use context menu options under TestMode and to hook up with the work @reddyashish and @Dewb are working on.
With this setting, Python nodes can switch Engine anytime in debug mode.

The example below distinguish the case that print statement got changed in Python3 so that same statement in left (python3 node) will throw a warning instead of execute.
Declarations
Check these if you believe they are true
*.resxfilesReviewers
@DynamoDS/dynamo
FYIs