Skip to content

Commit

Permalink
fix: put IPython import in separate cell
Browse files Browse the repository at this point in the history
sphinx-codeautolink does not detect display function if there is cell
magic in the cell
  • Loading branch information
redeboer committed Feb 6, 2022
1 parent b6478ec commit bc49e11
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/repoma/set_nb_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,26 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
)
cell_id += 1
if not args.no_config_cell:
config_cell_content = __CONFIG_CELL_CONTENT
if "ipython" in args.additional_packages.lower():
config_cell_content = config_cell_content.replace(
"import os",
"import os\n\nfrom IPython.display import display # noqa:"
" F401",
)
_update_cell(
filename,
new_content=config_cell_content.strip("\n"),
new_content=__CONFIG_CELL_CONTENT.strip("\n"),
new_metadata=__CONFIG_CELL_METADATA,
cell_id=cell_id,
)
cell_id += 1
if "ipython" in args.additional_packages.lower():
_update_cell(
filename,
new_content=(
"from IPython.display import display # noqa: F401"
),
new_metadata={
**__CONFIG_CELL_METADATA,
"tags": ["hide-cell"],
},
cell_id=cell_id,
)
cell_id += 1
_insert_autolink_concat(filename)
return 0

Expand Down

0 comments on commit bc49e11

Please sign in to comment.