Commit 63e25bb
authored
Refactor OutputsManager to align with default Jupyter behavior (#163)
* Add safe msg_id handling in kernel_client.
* Contrain to Python 3.13 in dev environment.
* Create _is_stream_output utility function
* Update stream_limit to 500 to avoid triggering too early
* Use set literal
* Update get_outputs to remove stream_limit logic
The stream_limit logic is being moved in this PR to the writing of outputs, so get_outputs can just return all outputs.
* Create _append_to_stream_file utility method.
* Update process_loaded_notebook to handle exclude_outputs
* Modify private _process_loaded methods to handle exclude_outputs
* Update process_saving_notebooks to handle exclude_outputs
* Add comment about placeholder outputs wrt nbformat
* Fix write to better handle stream outputs and stream_limit at write time
* Remove call to clear in saving logic
* Refactor OutputsManager and add experimental OptimizedOutputsManager
This commit introduces a cleaner architecture for handling notebook outputs
and adds an experimental optimized version that supports excluding outputs
from saved notebook files.
Core changes to OutputsManager:
- Extract private utility functions (_create_output_url, _create_output_placeholder)
- Add comprehensive docstrings to all methods
- Simplify write() method by removing stream_limit logic
- Improve error handling in get_outputs() to return empty list instead of raising
- Consolidate output processing logic into _process_outputs_from_cell()
- Add helper methods: _upgrade_notebook_format(), _ensure_cell_id()
- Always write full outputs to notebook files on save (traditional Jupyter behavior)
- Remove stream-specific handling and StreamAPIHandler route
New OptimizedOutputsManager:
- Extends base OutputsManager with exclude_outputs metadata flag support
- When exclude_outputs=True: outputs stored only in runtime, not in saved files
- When exclude_outputs=False/unset: full outputs included in saved files (default)
- Implements stream_limit (500) for large stream outputs with link placeholders
- Provides _append_to_stream_file() for efficient stream handling
- Stream API handler for accessing accumulated stream outputs
Other improvements:
- Add __all__ to outputs/__init__.py for cleaner exports
- Expand test coverage with comprehensive test suite
- Rename private methods for clarity (_process_loaded_excluded_outputs, etc.)
- Update yroom_file_api to use process_saving_notebook correctly
The OptimizedOutputsManager is currently experimental and disabled by default.
StreamAPIHandler route is commented out until the feature is ready for production.1 parent babd48c commit 63e25bb
File tree
8 files changed
+1753
-394
lines changed- jupyter_server_documents
- kernels
- outputs
- rooms
- tests
8 files changed
+1753
-394
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
147 | | - | |
| 150 | + | |
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
| |||
240 | 243 | | |
241 | 244 | | |
242 | 245 | | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
247 | 256 | | |
248 | 257 | | |
249 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
90 | 92 | | |
0 commit comments