-
Notifications
You must be signed in to change notification settings - Fork 636
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
Sys.path value should be limited to the scope of the python node(CPython3 Engine) #10977
Conversation
@@ -188,6 +189,10 @@ static CPythonEvaluator() | |||
{ | |||
globalScope = CreateGlobalScope(); | |||
} | |||
|
|||
// Reset the 'sys.path' value to the default python paths on node evaluation. | |||
code = "import sys" + Environment.NewLine + "sys.path = sys.path[0:3]" + Environment.NewLine + code; |
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.
This should be done in its own scope. Otherwise the line numbers will be moved, which will affect traceback.
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.
alternatively it can be done from the c# side - without injecting more code into python code string at all.
Modified the code to reset the sys.path in its own scope. Verified that the line numbers in the trace point to the correct line number. |
Self-serve passed with no failures: https://master-15.jenkins.autodesk.com/view/DYN/job/DYN-DevCI_Self_Service/715/ |
[Test] | ||
public void VerifySysPathValueForCPythonEngine() | ||
{ | ||
// open test graph |
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.
Can you also add an assertion or another simple test to make sure the number of paths is 3 before making any changes to it? Given those paths are added by Python.NET by default, and we are assuming they are 3 on our end, this would be useful to catch changes on their end.
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.
Added it to the same test.
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
Merging this. |
Purpose
This PR is to address the task https://jira.autodesk.com/browse/DYN-2956.
Issue: For CPython3 Engine, when you add a custom path to the 'sys.path' variable, its value was persistent for the whole Dynamo session. This wasn't the case with IronPython2. To make this consistent, we have decided to limit the scope of this variable to individual python node.
To fix this, whenever a python node is evaluated, the 'sys.path' value is reset to contain only the default python values. For CPython engine, the first 3 paths correspond to the default python paths.
To test this, I have added a custom path "C:\Program Files\dotnet" in the Python script editor and checked that this path is not reflected in the 2nd python node. I wasn't sure if using such paths in our test could cause any issues. My thought was this dotnot folder should be present on all Windows machines with dotnet installed. Looking for suggestions.
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@mjkkirschner @mmisol
FYIs
@DynamoDS/dynamo