Skip to content

Commit

Permalink
Feat: separate IPython from import hook installation
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Aug 12, 2021
1 parent 02e868a commit fd08c02
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
literary~=1.8.2
literary~=2.0.1
pytest
jupyterlab
black
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = literary
version = 2.1.0
version = 2.2.0
description = Literate package development with Jupyter
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
5 changes: 3 additions & 2 deletions src/literary/notebook/__init__.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"\n",
" # Install the import hook\n",
" importer = ProjectImporter(config=config)\n",
" importer.install(ipython)"
" importer.install_hook()\n",
" importer.update_namespace(ipython.user_ns)"
]
}
],
Expand Down Expand Up @@ -114,4 +115,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
23 changes: 19 additions & 4 deletions src/literary/notebook/importer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"outputs": [],
"source": [
"@patch(ProjectImporter)\n",
"def install(self, ipython):\n",
"def install_hook(self):\n",
" \"\"\"Install notebook import hook\n",
"\n",
" Don't allow the user to specify a custom search path, because we also need this to\n",
Expand Down Expand Up @@ -178,10 +178,25 @@
" # Python's C-level traceback reporting doesn't call `linecache`, and so retrieves\n",
" # the underlying notebook source instead of the generated Python code\n",
" if self.set_except_hook:\n",
" sys.excepthook = traceback.print_exception\n",
" sys.excepthook = traceback.print_exception"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"export"
]
},
"outputs": [],
"source": [
"@patch(ProjectImporter)\n",
"def update_namespace(self, namespace):\n",
" cwd = Path.cwd()\n",
"\n",
" # Update user namespace\n",
" ipython.user_ns.update(\n",
" namespace.update(\n",
" {\n",
" \"__package__\": self.determine_package_name(cwd),\n",
" \"patch\": patch,\n",
Expand Down Expand Up @@ -216,4 +231,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit fd08c02

Please sign in to comment.