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

Redirect python print to Dynamo console #11000

Merged
merged 4 commits into from
Aug 14, 2020

Conversation

SHKnudsen
Copy link
Contributor

Purpose

This PR builds on the work of https://jira.autodesk.com/browse/DYN-2971, to add functionality to redirect Python print to the Dynamo console. It also removes the current DynamoPrint() function.

image

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@mmisol

FYIs

@mjkkirschner
@QilongTang

FYI @mmisol seems like the IronPythonEvaluator does not have a global scope, is that correctly understood? For redirecting prints in IronPython i simply ProcessAdditionalBindings in the local scope. Let me know if you are okay with that.

Copy link
Collaborator

@mmisol mmisol left a comment

Choose a reason for hiding this comment

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

Looks pretty good. Only an issue with escaping ' and a couple of typos.

About Iron Python, you are correct @SHKnudsen , there is no such thing as a global scope, so your solution looks fine.


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());
}

scope.Exec($"sys.stdout.prefix = '{nodeName}'");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this code could run into problems when nodeName contains a ' character. Could you escape it and maybe and an ' to a node name in the test so that we are covering it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i added the nodename as a variable to the PyScope, that seems to work better and works with all special characters.

test/Libraries/DynamoPythonTests/PythonTestsWithLogging.cs Outdated Show resolved Hide resolved
Copy link
Collaborator

@mmisol mmisol left a comment

Choose a reason for hiding this comment

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

Looks good. Just one minor final comment.

src/Libraries/DSCPython/CPythonEvaluator.cs Outdated Show resolved Hide resolved
@mmisol
Copy link
Collaborator

mmisol commented Aug 14, 2020

Thanks @SHKnudsen ! I will just wait for the tests to run and merge this in.

@mmisol mmisol merged commit 7ce97f5 into DynamoDS:master Aug 14, 2020
mmisol pushed a commit to mmisol/Dynamo that referenced this pull request Aug 17, 2020
* redirect print to DynamoConsol + update unit test

* comment updates

* Update CPythonEvaluator.cs
@mmisol mmisol mentioned this pull request Aug 17, 2020
8 tasks
mmisol added a commit that referenced this pull request Aug 17, 2020
* Redirect python print to Dynamo console (#11000)

* redirect print to DynamoConsol + update unit test

* comment updates

* Update CPythonEvaluator.cs

* Move Python print function to local scope (#11007)

This fixes build issues that appeared after merging 'print' function
changes for CPython3. Those changes moved the print function to the
globalScope which caused the 'DynamoPrintLogsToConsole' test to fail.
The reason for this is that Python unit tests, which don't use a model,
still initialize the globalScope but do not provide a logger, making
later logging tests fail.

Co-authored-by: Sylvester Knudsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants