Skip to content

Commit

Permalink
Account for source being a string
Browse files Browse the repository at this point in the history
  • Loading branch information
Koncopd committed Oct 16, 2024
1 parent c28c19b commit d200f59
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ repos:
hooks:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports]
additional_dependencies:
["types-pkg-resources", "types-requests", "types-attrs"]
additional_dependencies: ["types-requests", "types-attrs"]
exclude: |
(?x)(
test_notebooks.py
Expand Down
11 changes: 5 additions & 6 deletions nbproject/dev/_check_last_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ def check_last_cell(nb: Notebook, calling_statement: str) -> bool:
nb: Notebook content.
calling_statement: The statement that calls this function.
"""
last_code_cell = None
last_code_cell_source = None
for cell in nb.cells:
if cell["cell_type"] == "code" and cell["source"] != []:
last_code_cell = cell
cell_source = "".join(cell["source"])
if cell["cell_type"] == "code" and cell_source != "":
last_code_cell_source = cell_source

if last_code_cell is not None and calling_statement in "".join(
last_code_cell["source"]
):
if last_code_cell_source is not None and calling_statement in last_code_cell_source:
return True
else:
return False
7 changes: 3 additions & 4 deletions nbproject/dev/_consecutiveness.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ def check_consecutiveness(nb: Notebook, calling_statement: str = None) -> bool:
ccount = 0 # need to initialize because notebook might note have code cells
# and below, we check if ccount is None
for cell in cells:
if cell["cell_type"] != "code" or cell["source"] == []:
cell_source = "".join(cell["source"])
if cell["cell_type"] != "code" or cell_source == "":
continue

if calling_statement is not None and calling_statement in "".join(
cell["source"]
):
if calling_statement is not None and calling_statement in cell_source:
continue

ccount = cell["execution_count"]
Expand Down
2 changes: 1 addition & 1 deletion nbproject/dev/_meta_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_title(nb: Notebook) -> Optional[str]:
# only consider markdown
if cell["cell_type"] == "markdown":
# grab source
text = cell["source"][0]
text = "".join(cell["source"])
# loop through lines
for line in text.split("\n"):
# if finding a level-1 heading, consider it a title
Expand Down
6 changes: 4 additions & 2 deletions nbproject/dev/_meta_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def _set_execution_count(calling_statement: str, notebook: Notebook):

prev = 0
for cell in cells:
if cell["cell_type"] != "code" or cell["source"] == []:
cell_source = "".join(cell["source"])

if cell["cell_type"] != "code" or cell_source == "":
continue

if calling_statement in "".join(cell["source"]):
if calling_statement in cell_source:
cell["execution_count"] = prev + 1

ccount = cell["execution_count"]
Expand Down

0 comments on commit d200f59

Please sign in to comment.