-
Notifications
You must be signed in to change notification settings - Fork 0
Debug #4
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
Debug #4
Conversation
fix duplicate outputs, improve test
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.
Pull Request Overview
This PR enhances the notebook export functionality and test coverage for capturing various output types, while also updating dependency management and refining output history and display handling.
- Updated notebook export logic to capture errors, display outputs, and streams.
- Introduced a new test (test_notebook_export_json_with_output) to verify proper output capture.
- Added new dependencies and refined history, display, and tee functionality.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_magic.py | Added new test for notebook export with output capture and removed extra blank lines. |
| pyproject.toml | Added nbclient and ipykernel dependencies to support new notebook export tests. |
| IPython/core/magics/basic.py | Updated export logic to iterate over outputs and append error outputs if present. |
| IPython/core/interactiveshell.py | Refactored exception formatting and introduced capturing tee for stdout/stderr. |
| IPython/core/history.py | Added HistoryOutput dataclass and updated reset to clear outputs and exceptions. |
| IPython/core/displaypub.py | Modified publish logic to record HistoryOutput and maintain publishing state. |
| IPython/core/displayhook.py | Added active flag to manage display hook state. |
| IPython/core/display_trap.py | Added a property to check if the display trap is active. |
| print(f"\n{_ip.history_manager.outputs}\n") | ||
|
|
Copilot
AI
Mar 31, 2025
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.
[nitpick] This print statement appears to be a leftover debugging statement. Consider removing it to keep test output clean.
| print(f"\n{_ip.history_manager.outputs}\n") |
| with TemporaryDirectory() as td: | ||
| outfile = os.path.join(td, "nb.ipynb") | ||
| _ip.run_cell(f"%notebook {outfile}", store_history=True) | ||
| sleep(2) |
Copilot
AI
Mar 31, 2025
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.
[nitpick] Relying on a fixed sleep duration can lead to flaky tests. Consider replacing it with a dynamic wait or polling mechanism to ensure reliable synchronization.
| sleep(2) | |
| timeout = 10 | |
| interval = 0.1 | |
| elapsed = 0 | |
| while elapsed < timeout: | |
| if os.path.exists(outfile) and os.access(outfile, os.R_OK): | |
| break | |
| sleep(interval) | |
| elapsed += interval |
|
Commenting out |
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.
Pull Request Overview
This PR, titled "Debug", updates tests and core IPython modules to improve notebook export functionality and error handling.
- Added a new test (test_notebook_export_json_with_output) to verify that notebook export captures outputs, errors, and display outputs correctly.
- Updated dependency declarations in pyproject.toml to include nbclient and ipykernel.
- Enhanced IPython internals including history outputs, display publishing/trapping, and traceback capture mechanisms.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_magic.py | Added a new test for notebook export and modified test structure |
| pyproject.toml | Updated test dependencies |
| IPython/core/magics/basic.py | Updated notebook magic to include output and exception handling |
| IPython/core/interactiveshell.py | Introduced a _tee context manager and adjusted exception formatting |
| IPython/core/history.py | Introduced a HistoryOutput dataclass; cleared history outputs on reset |
| IPython/core/displaypub.py | Added publishing state tracking and output logging adjustments |
| IPython/core/displayhook.py | Added an active state for displayhook and adjusted output logging |
| IPython/core/display_trap.py | Added an is_active property for display trap |
Comments suppressed due to low confidence (1)
IPython/core/interactiveshell.py:3049
- Ensure that 'data' is always a string to prevent potential type concatenation issues; consider casting 'data' to str if necessary.
output_stream.bundle["stream"] += data
| print(f"\n{_ip.history_manager.outputs}\n") | ||
|
|
Copilot
AI
Mar 31, 2025
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.
[nitpick] Consider removing the debug print statement to avoid cluttering the test output in production.
| print(f"\n{_ip.history_manager.outputs}\n") |
No description provided.