Skip to content

Fix IPython detection routine #237

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

Merged
merged 1 commit into from
Jan 12, 2022
Merged

Fix IPython detection routine #237

merged 1 commit into from
Jan 12, 2022

Conversation

gigony
Copy link
Collaborator

@gigony gigony commented Jan 12, 2022

To detect if the code is run inside Jupyter notebook (IPython) or not, it tried to find whether the class's file name starts with <ipython- or not.

Meanwhile the approach worked on Google Colab and some Jupyter Notebook versions. There were some cases where the class's file name is like /tmp/ipykernel_xxxxx/xxxxxxxxx.py causing the failure described in #206.

This patch uses a different approach.

If the file path is not available, it tries to see each frame information in the stack to check whether the file name ends with "interactiveshell.py" and the function name is "run_code".

If so, it returns Path("ipython") to notify that the class is defined inside IPython.

Fixes #206
Signed-off-by: Gigon Bae gbae@nvidia.com

@gigony gigony added the bug Something isn't working label Jan 12, 2022
@gigony gigony added this to the v0.3.0 milestone Jan 12, 2022
@gigony gigony requested a review from MMelQin January 12, 2022 22:02
@gigony gigony self-assigned this Jan 12, 2022
Signed-off-by: Gigon Bae <gbae@nvidia.com>
@MMelQin
Copy link
Collaborator

MMelQin commented Jan 12, 2022

This discussion on StackOverflow also agrees with your approach.

Copy link
Collaborator

@MMelQin MMelQin 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 and the approach is also regarded as the most robust per stack overflow discussion.

@gigony gigony merged commit 0e9ca43 into main Jan 12, 2022
@gigony gigony mentioned this pull request Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Tutorial Notebook Code Not Working With inspect
2 participants