Sys.path value should be limited to the scope of the python node(CPython3 Engine)#10977
Sys.path value should be limited to the scope of the python node(CPython3 Engine)#10977reddyashish merged 4 commits intoDynamoDS:masterfrom
Conversation
| } | ||
|
|
||
| // 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.
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.
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.
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.
Added it to the same test.
|
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
*.resxfilesReviewers
@mjkkirschner @mmisol
FYIs
@DynamoDS/dynamo