Skip to content

[SofaPython3/Plugin] Restore the automatic reload of modules#182

Merged
guparan merged 2 commits intosofa-framework:masterfrom
CRIStAL-PADR:pr-restore-pythonenvironment-cleaning
Apr 26, 2022
Merged

[SofaPython3/Plugin] Restore the automatic reload of modules#182
guparan merged 2 commits intosofa-framework:masterfrom
CRIStAL-PADR:pr-restore-pythonenvironment-cleaning

Conversation

@damienmarchal
Copy link
Copy Markdown
Contributor

@damienmarchal damienmarchal commented Sep 15, 2021

it is important when reloading a scene to force python to reload all the loaded modules to be sure the context is as clean as possible.

This PR restore this mechanism and clean the duplicated code from between SofaRuntime and Sofa

@damienmarchal
Copy link
Copy Markdown
Contributor Author

damienmarchal commented Sep 17, 2021

It was flaggued ready by @fredroy but it emits a deprecation message from a python library...so i prefer to update the code to remove it before mergin.

EDIT: ok so the warning was about using a python2 library in the embedded code. Now this code is replaced with python3 version.

@guparan guparan modified the milestones: v21.06, v21.12 Oct 26, 2021
@guparan guparan removed this from the v21.12 milestone Dec 15, 2021
…vironment-cleaning

# Conflicts:
#	Plugin/src/SofaPython3/PythonEnvironment.cpp
As they are not operating in the same python namespace.
}
getStaticData()->m_sofamodule = py::module::import("Sofa");

PyRun_SimpleString("import SofaRuntime");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this replacement?

Copy link
Copy Markdown
Contributor Author

@damienmarchal damienmarchal Apr 20, 2022

Choose a reason for hiding this comment

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

Because as far as I can see it is not the same behavior and the existing py::module is not working as expected.
The difference is that the py::module version is importing something in a standalone context, accessible from c++ and not importing a module it into the current interpreter context.
For consistency I used the same function as other part of the code to do that as in

PyRun_SimpleString("from Sofa.livecoding import onReimpAFile");

@guparan guparan merged commit 571e470 into sofa-framework:master Apr 26, 2022
@guparan
Copy link
Copy Markdown
Contributor

guparan commented Apr 27, 2022

@damienmarchal
Copy link
Copy Markdown
Contributor Author

Thanks for reporting, I'm looking at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants