-
Notifications
You must be signed in to change notification settings - Fork 39
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
Imported modules aren't re-imported when script is re-run #102
Comments
@fragmuffin Can you try the latest master, using show_object() uses the new CadQuery Gateway Interface (CQGI). I'm curious if it handles the imports correctly. |
@jmwright done, and the same issue. for example, if import os
def foo():
locally_scoped_str = 'testing 123'
with open(os.path.join(os.environ['HOME'], 'temp', 'test.txt')) as fh:
fh.write(locally_scoped_str) the same error can be observed when changing the value of |
CQGI does the execution environment much differently than the module does. I was hoping that the issue was in the environment setup and tear down. I'll look into this issue. Thanks for reporting it. |
@jmwright this may be the culprit # We import this way because using execfile() causes non-standard script execution in some situations
imp.load_source('temp_module', tempFile.name) where yep, I just used that method manually, same issue. |
That section of code is bypassed when you use show_object() though. Did you try show_object after a fresh start of FreeCAD? CQGI sets up a separate environment each time it runs so I had expected that would fix this issue. If you ran the script with show and then immediately with show_object, the section of code you linked might still cause problems. |
oh!, I see how that works now, so sorry. |
with the from contextlib import contextmanager
import sys
@contextmanager
def revert_sys_modules():
modules_before = set(sys.modules.keys())
yield
for mod_name in sys.modules.keys():
if mod_name not in modules_before:
del sys.modules[mod_name]
with revert_sys_modules():
imp.load_source('temp_module', tempFile.name) I haven't tested it yet, but I've reeealy got to get to sleep right now 💤 |
That would be awesome, thanks for all your work on this. |
My pleasure @jmwright ! |
@fragmuffin We're really glad that you've gotten involved. You've brought a lot to the project, and your enthusiasm is greatly appreciated. @dcowden and I are really busy with day jobs, so if we're slow to respond or miss things once in awhile, please don't take it as a sign of disinterest. We're very excited about where CadQuery is headed, and it's very encouraging when other people believe in it too and jump in with us. |
@fragmuffin @jmwright not to just ditto Jeremy, but.. ditto! It's so cool to have other people helping. |
I haven't closed this because there might have been a bug introduced with this code change. |
When importing a module, FreeCAD needs to be re-started to successfully re-import
Steps to re-create
~/temp/my_module/__init__.py
with contents...my_module/__init__.py
fileF2
) in FreeCADExpectation
The box should show the new dimensions
Actual Results
The box is still in the old dimensions
Work-around
Close FreeCAD, then re-open it
The text was updated successfully, but these errors were encountered: