Fix: enable re-import .ipynb when error ocurred #191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I’m a Korean student taking some classes with Prof. DongSun Kim.
Executing GreyboxFuzzer.ipynb, we found an error when importing generate_maze_code from ControlFlow. First, we got an error that is "ModuleNotFoundError: No module named 'graphviz'". And then we got an another error that is "ImportError: cannot import name 'generate_maze_code' from 'Controlflow' (Controlflow.ipynb)". The second problem has some issues.
At the time, I had solved the problem with just changing the name of module:from 'ControlFlow' to 'Controlflow'. I was confused because I couldn't understand why this solution works.
Here is how to invoke same error
fixed code
In python, the same module cannot be imported twice(
unless importlib.reload()is used).If the first import fails, the imported module remains in
sys.modules, preventing it from being re-imported successfully.So, I changed some code in
load_module()in bookutils.import_notebooks.py. It delete module if the error occured.Problem in .ipynb import code (bookutils.import_notebooks.py)
executing exec() function, load_module() does not control an error that is occured when importing othre files. Other errors are controled as exception by some code(I don't know actual lines) like assert, function not found error, and so on.
The reason problem was solved with changing capital F to small f.
Using function os.path checks file with case insensitive, but load_module function uses user input (import "Controlflow") string as a key value of sys.modules dict. The string is case sensitive and treat "Controlflow" as new module, and it makes importing success.