Skip to content
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

DM-39325: Revert cell numbering to only count code cells #261

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/20230522_085712_rra_DM_39325.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug fixes

- Revert change in 5.0.0 to number all cells, and go back to counting only code cells for numbering purposes. This matches the way cell numbers are displayed in the Jupyter lab UI.
10 changes: 6 additions & 4 deletions src/mobu/services/business/notebookrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ def read_notebook(self, notebook: Path) -> list[dict[str, Any]]:
msg = f"Invalid notebook {notebook.name}: {e!s}"
raise NotebookRepositoryError(msg, self.user.username) from e

# Strip non-code cells.
cells = [c for c in cells if c["cell_type"] == "code"]

# Add cell numbers to all the cells, which we'll use in exception
# reporting and to annotate timing events so that we can find cells
# that take an excessively long time to run.
# that take an excessively long time to run. This should be done after
# stripping non-code cells, since the UI for notebooks displays cell
# numbers only counting code cells.
for i, cell in enumerate(cells, start=1):
cell["_index"] = str(i)

# Strip non-code cells.
cells = [c for c in cells if c["cell_type"] == "code"]

return cells

@asynccontextmanager
Expand Down
2 changes: 1 addition & 1 deletion tests/business/notebookrunner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async def test_alert(
"text": {
"type": "mrkdwn",
"text": (
"*Cell*\n`exception.ipynb` cell `ed399c0a` (#2)"
"*Cell*\n`exception.ipynb` cell `ed399c0a` (#1)"
),
"verbatim": True,
},
Expand Down