Skip to content

Commit

Permalink
add the ability to import ipy files (#110)
Browse files Browse the repository at this point in the history
* add the ability to import ipy files

* add an assertion to the test
  • Loading branch information
tonyfast committed Oct 14, 2020
1 parent 0cd0dda commit e3b5c32
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/importnb/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ class NotebookBaseLoader(ImportLibMixin, FinderContextManager):
"""The simplest implementation of a Notebook Source File Loader.
"""

extensions = (".ipynb",)
extensions = (
".ipy",
".ipynb",
)
__slots__ = "_lazy", "_fuzzy", "_markdown_docstring", "_position"

def __init__(
Expand Down Expand Up @@ -184,7 +187,7 @@ def get_data(self, path):
return LineCacheNotebookDecoder(
code=self.code, raw=self.raw, markdown=self.markdown
).decode(self.decode(), self.path)
return super().get_data(path)
return self.code(super().get_data(path))


class FileModuleSpec(ModuleSpec):
Expand Down
1 change: 1 addition & 0 deletions tests/ascript.ipy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msg = !echo "hello word"
45 changes: 30 additions & 15 deletions tests/test_importnb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -133,7 +133,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -158,7 +158,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -174,7 +174,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -186,7 +186,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -195,7 +195,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -210,7 +210,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -220,7 +220,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -234,7 +234,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -248,7 +248,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -261,7 +261,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -280,7 +280,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -290,6 +290,21 @@
" del __bar"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
" @ipy \n",
" def test_import_ipy():\n",
" \"\"\"import ipy scripts, this won't really work without ipython.\"\"\"\n",
" with Notebook():\n",
" import ascript\n",
" \n",
" assert ascript.msg"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -316,9 +331,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
}

0 comments on commit e3b5c32

Please sign in to comment.