-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: Use HTML to present warnings of train_test_split when in notebooks #1060
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7490f19
feat: Use HTML to present warnings of train_test_split when in vscode…
rouk1 cb20147
use environement css vars as much as possible
rouk1 c5101dd
Merge branch 'main' into train-test-split-html-warnings
rouk1 9e94136
add warning title
rouk1 2195aad
fix bottom padding in jupyter
rouk1 a7bf2d3
Merge branch 'main' into train-test-split-html-warnings
rouk1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
import sys | ||
|
||
|
||
def get_environment_info(): | ||
"""Detect the current Python execution environment. | ||
|
||
Returns a dictionary with information about the environment. | ||
""" | ||
env_info = { | ||
"is_jupyter": False, | ||
"is_vscode": False, | ||
"is_interactive": False, | ||
"environment_name": "standard_python", | ||
"details": {}, | ||
} | ||
|
||
# Check for interactive mode | ||
env_info["is_interactive"] = hasattr(sys, "ps1") | ||
|
||
# Check for Jupyter | ||
try: | ||
shell = get_ipython().__class__.__name__ # type: ignore | ||
env_info["details"]["ipython_shell"] = shell | ||
|
||
if shell == "ZMQInteractiveShell": # Jupyter notebook/lab | ||
env_info["is_jupyter"] = True | ||
env_info["environment_name"] = "jupyter" | ||
elif shell == "TerminalInteractiveShell": # IPython terminal | ||
env_info["environment_name"] = "ipython_terminal" | ||
except NameError: | ||
pass | ||
|
||
# Check for VSCode | ||
if "VSCODE_PID" in os.environ: | ||
env_info["is_vscode"] = True | ||
if env_info["is_interactive"]: | ||
env_info["environment_name"] = "vscode_interactive" | ||
else: | ||
env_info["environment_name"] = "vscode_script" | ||
|
||
# Add additional environment details | ||
env_info["details"]["python_executable"] = sys.executable | ||
env_info["details"]["python_version"] = sys.version | ||
|
||
return env_info | ||
|
||
|
||
def is_environment_html_capable() -> bool: | ||
"""Return `True` if the execution context dcan render HTML. `False` otherwise.""" | ||
info = get_environment_info() | ||
return info["is_vscode"] or info["is_jupyter"] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative that would work in both HTML and in prompt would be to leverage
rich
:It would provide the following outputs:
And here it is configure such that someone filter the warnings with ignore, then we don't show it.
It might be a bit less invasive than checking for the environment (while this code could be useful for some other stuff along the road).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using rich everywhere does provide coherence (with the EstimatorReport of #997)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can rich display
False
with code style for example?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes rich is capable to display markdown.
I hadn't considered using pure textual, it's cool and lightweight. Only down side is that we cant match hosting styles.
I'm happy to refactor that way. @MarieS-WiMLDS can you please settle this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by matching hosting style? Is it light/dark theme, or is it about the font?
I really don't mind if we don't have the default font of the user, it's more troublesome if it's about the theme, because it might affect readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An note that we have a similar limitation with the logging when creating project, etc. where we use
rich
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your insights, anyway an orange background seems anti-UX, let's move on with rich. Should we close this PR and open a new one for rich? How do you wish to proceed with rich?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Sylvain, very unlikely for a user to have a orange background!
The "we can do it later" stuff tends to be never done, especially when it's about having clean code, so I'd prefer that we go for rich before merging, if it's compatible with your deadline of tuesday evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cf. #1086
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're the best ⚡️