From be9805435bd69bebaa89ac3028ff061d79a3cac2 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Thu, 12 May 2022 12:01:55 +0100 Subject: [PATCH] Fix: detect IPython and require magic for imports On IPython, the kernel adds $PWD to sys.path before proceeding to import lots of modules. In order to remove the restriction that user submodule notebook names not shadow existing libraries we can remove $PWD from the sys.path under IPython. Once the kernel has started, experienced users *might* expect $PWD to be on sys.path. Literary only restores this for non-__package__ notebooks. This would also work out-of-the-box for top-level notebooks, but not inside e.g. examples/ folders. --- examples/absolute-importing.ipynb | 14 +- examples/src/package_a/__init__.ipynb | 2 +- examples/src/package_a/docstring.ipynb | 4 +- examples/src/package_a/exports.ipynb | 2 +- examples/src/package_a/importer.ipynb | 34 +---- examples/src/package_a/patching.ipynb | 27 +--- pdm.lock | 139 ++++++++++++++++++- pyproject.toml | 5 +- src/literary/commands/__main__.ipynb | 42 +++--- src/literary/commands/app.ipynb | 56 ++++---- src/literary/commands/build.ipynb | 84 ++++++++++-- src/literary/commands/test.ipynb | 66 +++++++-- src/literary/commands/trait.ipynb | 26 ++-- src/literary/config/__init__.ipynb | 35 ++++- src/literary/hook/__init__.ipynb | 84 ++++++++---- src/literary/hook/finder.ipynb | 113 ++++++++++++++-- src/literary/hook/importer.ipynb | 77 ++++++----- src/literary/hook/loader.ipynb | 83 +++++++----- src/literary/module/__init__.ipynb | 128 +++++++++++++----- src/literary/transpile/exporter.ipynb | 22 +-- src/literary/transpile/filter.ipynb | 43 +++--- src/literary/transpile/patch.ipynb | 83 ++++++------ src/literary/transpile/preprocessor.ipynb | 50 +++---- src/literary/transpile/syntax.ipynb | 157 ++++++++++++++++------ 24 files changed, 934 insertions(+), 442 deletions(-) diff --git a/examples/absolute-importing.ipynb b/examples/absolute-importing.ipynb index cb816b0..f48c24e 100644 --- a/examples/absolute-importing.ipynb +++ b/examples/absolute-importing.ipynb @@ -21,18 +21,6 @@ "We are going to use the _notebook_ hook, which adds support for importing other notebooks. This is different to the _module_ hook, which can be seen in [src/package_a/importer.ipynb](src/package_a/importer.ipynb)" ] }, - { - "cell_type": "code", - "execution_count": 1, - "id": "satisfactory-discretion", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "%load_ext literary.notebook" - ] - }, { "cell_type": "markdown", "id": "favorite-questionnaire", @@ -187,7 +175,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.4" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/examples/src/package_a/__init__.ipynb b/examples/src/package_a/__init__.ipynb index 1a8ef96..0163336 100644 --- a/examples/src/package_a/__init__.ipynb +++ b/examples/src/package_a/__init__.ipynb @@ -25,7 +25,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.4" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/examples/src/package_a/docstring.ipynb b/examples/src/package_a/docstring.ipynb index 3ea5826..fdb9d28 100644 --- a/examples/src/package_a/docstring.ipynb +++ b/examples/src/package_a/docstring.ipynb @@ -24,7 +24,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -38,7 +38,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.0" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/examples/src/package_a/exports.ipynb b/examples/src/package_a/exports.ipynb index d989c8f..3d0b7b0 100644 --- a/examples/src/package_a/exports.ipynb +++ b/examples/src/package_a/exports.ipynb @@ -96,7 +96,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.4" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/examples/src/package_a/importer.ipynb b/examples/src/package_a/importer.ipynb index b614826..2ae02fe 100644 --- a/examples/src/package_a/importer.ipynb +++ b/examples/src/package_a/importer.ipynb @@ -23,38 +23,6 @@ "## Loaded modules" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Loading the hook" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First we need to run the shim that installs the import hook and loads the useful globals:" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "%load_ext literary.module" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is **only needed if we wish to execute this notebook directly**, as the import hook performs this step automatically when importing notebooks. Defining `__package__` enables us to perform relative imports. Let's import a function from [exports.ipynb]():" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -408,7 +376,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.4" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/examples/src/package_a/patching.ipynb b/examples/src/package_a/patching.ipynb index fd13b72..3a2399c 100644 --- a/examples/src/package_a/patching.ipynb +++ b/examples/src/package_a/patching.ipynb @@ -226,29 +226,6 @@ "## `@patch` decorator" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The `%load_ext literary.module` magic can be used to load a `patch` decorator from Literary:" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "execution": { - "iopub.execute_input": "2021-05-18T21:00:06.297765Z", - "iopub.status.busy": "2021-05-18T21:00:06.297160Z", - "iopub.status.idle": "2021-05-18T21:00:06.442965Z", - "shell.execute_reply": "2021-05-18T21:00:06.441843Z" - } - }, - "outputs": [], - "source": [ - "%load_ext literary.module" - ] - }, { "cell_type": "code", "execution_count": 10, @@ -376,7 +353,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -390,7 +367,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.0" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/pdm.lock b/pdm.lock index 0f1ad96..2150f73 100644 --- a/pdm.lock +++ b/pdm.lock @@ -77,6 +77,21 @@ dependencies = [ "soupsieve>1.2", ] +[[package]] +name = "black" +version = "22.3.0" +requires_python = ">=3.6.2" +summary = "The uncompromising code formatter." +dependencies = [ + "click>=8.0.0", + "mypy-extensions>=0.4.3", + "pathspec>=0.9.0", + "platformdirs>=2", + "tomli>=1.1.0; python_version < \"3.11\"", + "typed-ast>=1.4.2; python_version < \"3.8\" and implementation_name == \"cpython\"", + "typing-extensions>=3.10.0.0; python_version < \"3.10\"", +] + [[package]] name = "bleach" version = "5.0.0" @@ -106,6 +121,16 @@ version = "2.0.12" requires_python = ">=3.5.0" summary = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +[[package]] +name = "click" +version = "8.1.3" +requires_python = ">=3.7" +summary = "Composable command line interface toolkit" +dependencies = [ + "colorama; platform_system == \"Windows\"", + "importlib-metadata; python_version < \"3.8\"", +] + [[package]] name = "colorama" version = "0.4.4" @@ -214,6 +239,12 @@ name = "ipython-genutils" version = "0.2.0" summary = "Vestigial utilities from IPython" +[[package]] +name = "isort" +version = "5.10.1" +requires_python = ">=3.6.1,<4.0" +summary = "A Python utility / library to sort Python imports." + [[package]] name = "jedi" version = "0.18.1" @@ -315,6 +346,15 @@ dependencies = [ "tornado>=6.1.0", ] +[[package]] +name = "jupyterlab-code-formatter" +version = "1.4.11" +requires_python = ">=3.6" +summary = "Code formatter for JupyterLab" +dependencies = [ + "jupyterlab~=3.0", +] + [[package]] name = "jupyterlab-pygments" version = "0.2.2" @@ -373,6 +413,11 @@ name = "mistune" version = "0.8.4" summary = "The fastest markdown parser in pure Python" +[[package]] +name = "mypy-extensions" +version = "0.4.3" +summary = "Experimental type system extensions for programs checked with the mypy typechecker." + [[package]] name = "nbclassic" version = "0.3.7" @@ -501,6 +546,11 @@ version = "0.8.3" requires_python = ">=3.6" summary = "A Python Parser" +[[package]] +name = "pathspec" +version = "0.9.0" +summary = "Utility library for gitignore style pattern matching of file paths." + [[package]] name = "pexpect" version = "4.8.0" @@ -514,6 +564,12 @@ name = "pickleshare" version = "0.7.5" summary = "Tiny 'shelve'-like database with concurrency support" +[[package]] +name = "platformdirs" +version = "2.5.2" +requires_python = ">=3.7" +summary = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." + [[package]] name = "pluggy" version = "1.0.0" @@ -709,6 +765,12 @@ version = "5.2.0" requires_python = ">=3.7" summary = "Traitlets Python configuration system" +[[package]] +name = "typed-ast" +version = "1.5.3" +requires_python = ">=3.6" +summary = "a fork of Python 2 and 3 ast modules with type comment support" + [[package]] name = "typing-extensions" version = "4.2.0" @@ -751,7 +813,7 @@ summary = "Backport of pathlib-compatible object wrapper for zip files" [metadata] lock_version = "3.1" -content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b71e5a91" +content_hash = "sha256:35395079d616b39c6693fd8613ff11f3374f315af9d304396ed9c7924c83d2ff" [metadata.files] "anyio 3.5.0" = [ @@ -813,6 +875,31 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "beautifulsoup4-4.11.1-py3-none-any.whl", hash = "sha256:58d5c3d29f5a36ffeb94f02f0d786cd53014cf9b3b3951d42e0080d8a9498d30"}, {file = "beautifulsoup4-4.11.1.tar.gz", hash = "sha256:ad9aa55b65ef2808eb405f46cf74df7fcb7044d5cbc26487f96eb2ef2e436693"}, ] +"black 22.3.0" = [ + {file = "black-22.3.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:2497f9c2386572e28921fa8bec7be3e51de6801f7459dffd6e62492531c47e09"}, + {file = "black-22.3.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:5795a0375eb87bfe902e80e0c8cfaedf8af4d49694d69161e5bd3206c18618bb"}, + {file = "black-22.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e3556168e2e5c49629f7b0f377070240bd5511e45e25a4497bb0073d9dda776a"}, + {file = "black-22.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:67c8301ec94e3bcc8906740fe071391bce40a862b7be0b86fb5382beefecd968"}, + {file = "black-22.3.0-cp310-cp310-win_amd64.whl", hash = "sha256:fd57160949179ec517d32ac2ac898b5f20d68ed1a9c977346efbac9c2f1e779d"}, + {file = "black-22.3.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:cc1e1de68c8e5444e8f94c3670bb48a2beef0e91dddfd4fcc29595ebd90bb9ce"}, + {file = "black-22.3.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6d2fc92002d44746d3e7db7cf9313cf4452f43e9ea77a2c939defce3b10b5c82"}, + {file = "black-22.3.0-cp36-cp36m-win_amd64.whl", hash = "sha256:a6342964b43a99dbc72f72812bf88cad8f0217ae9acb47c0d4f141a6416d2d7b"}, + {file = "black-22.3.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:328efc0cc70ccb23429d6be184a15ce613f676bdfc85e5fe8ea2a9354b4e9015"}, + {file = "black-22.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:06f9d8846f2340dfac80ceb20200ea5d1b3f181dd0556b47af4e8e0b24fa0a6b"}, + {file = "black-22.3.0-cp37-cp37m-win_amd64.whl", hash = "sha256:ad4efa5fad66b903b4a5f96d91461d90b9507a812b3c5de657d544215bb7877a"}, + {file = "black-22.3.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:e8477ec6bbfe0312c128e74644ac8a02ca06bcdb8982d4ee06f209be28cdf163"}, + {file = "black-22.3.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:637a4014c63fbf42a692d22b55d8ad6968a946b4a6ebc385c5505d9625b6a464"}, + {file = "black-22.3.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:863714200ada56cbc366dc9ae5291ceb936573155f8bf8e9de92aef51f3ad0f0"}, + {file = "black-22.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:10dbe6e6d2988049b4655b2b739f98785a884d4d6b85bc35133a8fb9a2233176"}, + {file = "black-22.3.0-cp38-cp38-win_amd64.whl", hash = "sha256:cee3e11161dde1b2a33a904b850b0899e0424cc331b7295f2a9698e79f9a69a0"}, + {file = "black-22.3.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:5891ef8abc06576985de8fa88e95ab70641de6c1fca97e2a15820a9b69e51b20"}, + {file = "black-22.3.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:30d78ba6bf080eeaf0b7b875d924b15cd46fec5fd044ddfbad38c8ea9171043a"}, + {file = "black-22.3.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ee8f1f7228cce7dffc2b464f07ce769f478968bfb3dd1254a4c2eeed84928aad"}, + {file = "black-22.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6ee227b696ca60dd1c507be80a6bc849a5a6ab57ac7352aad1ffec9e8b805f21"}, + {file = "black-22.3.0-cp39-cp39-win_amd64.whl", hash = "sha256:9b542ced1ec0ceeff5b37d69838106a6348e60db7b8fdd245294dc1d26136265"}, + {file = "black-22.3.0-py3-none-any.whl", hash = "sha256:bc58025940a896d7e5356952228b68f793cf5fcb342be703c3a2669a1488cb72"}, + {file = "black-22.3.0.tar.gz", hash = "sha256:35020b8886c022ced9282b51b5a875b6d1ab0c387b31a065b84db7c33085ca79"}, +] "bleach 5.0.0" = [ {file = "bleach-5.0.0-py3-none-any.whl", hash = "sha256:08a1fe86d253b5c88c92cc3d810fd8048a16d15762e1e5b74d502256e5926aa1"}, {file = "bleach-5.0.0.tar.gz", hash = "sha256:c6d6cc054bdc9c83b48b8083e236e5f00f238428666d2ce2e083eaa5fd568565"}, @@ -877,6 +964,10 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "charset_normalizer-2.0.12-py3-none-any.whl", hash = "sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"}, {file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"}, ] +"click 8.1.3" = [ + {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, + {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, +] "colorama 0.4.4" = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, @@ -945,6 +1036,10 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "ipython_genutils-0.2.0-py2.py3-none-any.whl", hash = "sha256:72dd37233799e619666c9f639a9da83c34013a73e8bbc79a7a6348d93c61fab8"}, {file = "ipython_genutils-0.2.0.tar.gz", hash = "sha256:eb2e116e75ecef9d4d228fdc66af54269afa26ab4463042e33785b887c628ba8"}, ] +"isort 5.10.1" = [ + {file = "isort-5.10.1-py3-none-any.whl", hash = "sha256:6f62d78e2f89b4500b080fe3a81690850cd254227f27f75c3a0c491a1f351ba7"}, + {file = "isort-5.10.1.tar.gz", hash = "sha256:e8443a5e7a020e9d7f97f1d7d9cd17c88bcb3bc7e218bf9cf5095fe550be2951"}, +] "jedi 0.18.1" = [ {file = "jedi-0.18.1-py2.py3-none-any.whl", hash = "sha256:637c9635fcf47945ceb91cd7f320234a7be540ded6f3e99a50cb6febdfd1ba8d"}, {file = "jedi-0.18.1.tar.gz", hash = "sha256:74137626a64a99c8eb6ae5832d99b3bdd7d29a3850fe2aa80a4126b2a7d949ab"}, @@ -976,6 +1071,10 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "jupyterlab-3.4.0-py3-none-any.whl", hash = "sha256:a50e5f400652def16d8a7edf10dfab177c03cf20427678fac09922de1055cf58"}, {file = "jupyterlab-3.4.0.tar.gz", hash = "sha256:0b504cef99c5eeb4058e554aa90733370d2b4b1ba5a275e267a5a144f43daa55"}, ] +"jupyterlab-code-formatter 1.4.11" = [ + {file = "jupyterlab_code_formatter-1.4.11-py3-none-any.whl", hash = "sha256:4c426bc9bd2b4d270659b70863e8eea7efe39ba75f632f52ebfb587cd1a7e062"}, + {file = "jupyterlab_code_formatter-1.4.11.tar.gz", hash = "sha256:b05f65b4b1499feeccae0d273b8fad8d37f6c8acaa32da10d4fc00dc223d2bde"}, +] "jupyterlab-pygments 0.2.2" = [ {file = "jupyterlab_pygments-0.2.2-py2.py3-none-any.whl", hash = "sha256:2405800db07c9f770863bcf8049a529c3dd4d3e28536638bd7c1c01d2748309f"}, {file = "jupyterlab_pygments-0.2.2.tar.gz", hash = "sha256:7405d7fde60819d905a9fa8ce89e4cd830e318cdad22a0030f7a901da705585d"}, @@ -1038,6 +1137,10 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "mistune-0.8.4-py2.py3-none-any.whl", hash = "sha256:88a1051873018da288eee8538d476dffe1262495144b33ecb586c4ab266bb8d4"}, {file = "mistune-0.8.4.tar.gz", hash = "sha256:59a3429db53c50b5c6bcc8a07f8848cb00d7dc8bdb431a4ab41920d201d4756e"}, ] +"mypy-extensions 0.4.3" = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] "nbclassic 0.3.7" = [ {file = "nbclassic-0.3.7-py3-none-any.whl", hash = "sha256:89184baa2d66b8ac3c8d3df57cbcf16f34148954d410a2fb3e897d7c18f2479d"}, {file = "nbclassic-0.3.7.tar.gz", hash = "sha256:36dbaa88ffaf5dc05d149deb97504b86ba648f4a80a60b8a58ac94acab2daeb5"}, @@ -1078,6 +1181,10 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "parso-0.8.3-py2.py3-none-any.whl", hash = "sha256:c001d4636cd3aecdaf33cbb40aebb59b094be2a74c556778ef5576c175e19e75"}, {file = "parso-0.8.3.tar.gz", hash = "sha256:8c07be290bb59f03588915921e29e8a50002acaf2cdc5fa0e0114f91709fafa0"}, ] +"pathspec 0.9.0" = [ + {file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"}, + {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"}, +] "pexpect 4.8.0" = [ {file = "pexpect-4.8.0-py2.py3-none-any.whl", hash = "sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937"}, {file = "pexpect-4.8.0.tar.gz", hash = "sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c"}, @@ -1086,6 +1193,10 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "pickleshare-0.7.5-py2.py3-none-any.whl", hash = "sha256:9649af414d74d4df115d5d718f82acb59c9d418196b7b4290ed47a12ce62df56"}, {file = "pickleshare-0.7.5.tar.gz", hash = "sha256:87683d47965c1da65cdacaf31c8441d12b8044cdec9aca500cd78fc2c683afca"}, ] +"platformdirs 2.5.2" = [ + {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, + {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"}, +] "pluggy 1.0.0" = [ {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, @@ -1342,6 +1453,32 @@ content_hash = "sha256:b258efddcbd536fc8afce5fef1fc663198349cf48069caf43e224964b {file = "traitlets-5.2.0-py3-none-any.whl", hash = "sha256:9dd4025123fbe018a2092b2ad6984792f53ea3362c698f37473258b1fa97b0bc"}, {file = "traitlets-5.2.0.tar.gz", hash = "sha256:60474f39bf1d39a11e0233090b99af3acee93bbc2281777e61dd8c87da8a0014"}, ] +"typed-ast 1.5.3" = [ + {file = "typed_ast-1.5.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9ad3b48cf2b487be140072fb86feff36801487d4abb7382bb1929aaac80638ea"}, + {file = "typed_ast-1.5.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:542cd732351ba8235f20faa0fc7398946fe1a57f2cdb289e5497e1e7f48cfedb"}, + {file = "typed_ast-1.5.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5dc2c11ae59003d4a26dda637222d9ae924387f96acae9492df663843aefad55"}, + {file = "typed_ast-1.5.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:fd5df1313915dbd70eaaa88c19030b441742e8b05e6103c631c83b75e0435ccc"}, + {file = "typed_ast-1.5.3-cp310-cp310-win_amd64.whl", hash = "sha256:e34f9b9e61333ecb0f7d79c21c28aa5cd63bec15cb7e1310d7d3da6ce886bc9b"}, + {file = "typed_ast-1.5.3-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f818c5b81966d4728fec14caa338e30a70dfc3da577984d38f97816c4b3071ec"}, + {file = "typed_ast-1.5.3-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3042bfc9ca118712c9809201f55355479cfcdc17449f9f8db5e744e9625c6805"}, + {file = "typed_ast-1.5.3-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:4fff9fdcce59dc61ec1b317bdb319f8f4e6b69ebbe61193ae0a60c5f9333dc49"}, + {file = "typed_ast-1.5.3-cp36-cp36m-win_amd64.whl", hash = "sha256:8e0b8528838ffd426fea8d18bde4c73bcb4167218998cc8b9ee0a0f2bfe678a6"}, + {file = "typed_ast-1.5.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8ef1d96ad05a291f5c36895d86d1375c0ee70595b90f6bb5f5fdbee749b146db"}, + {file = "typed_ast-1.5.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed44e81517364cb5ba367e4f68fca01fba42a7a4690d40c07886586ac267d9b9"}, + {file = "typed_ast-1.5.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:f60d9de0d087454c91b3999a296d0c4558c1666771e3460621875021bf899af9"}, + {file = "typed_ast-1.5.3-cp37-cp37m-win_amd64.whl", hash = "sha256:9e237e74fd321a55c90eee9bc5d44be976979ad38a29bbd734148295c1ce7617"}, + {file = "typed_ast-1.5.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:ee852185964744987609b40aee1d2eb81502ae63ee8eef614558f96a56c1902d"}, + {file = "typed_ast-1.5.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:27e46cdd01d6c3a0dd8f728b6a938a6751f7bd324817501c15fb056307f918c6"}, + {file = "typed_ast-1.5.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d64dabc6336ddc10373922a146fa2256043b3b43e61f28961caec2a5207c56d5"}, + {file = "typed_ast-1.5.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8cdf91b0c466a6c43f36c1964772918a2c04cfa83df8001ff32a89e357f8eb06"}, + {file = "typed_ast-1.5.3-cp38-cp38-win_amd64.whl", hash = "sha256:9cc9e1457e1feb06b075c8ef8aeb046a28ec351b1958b42c7c31c989c841403a"}, + {file = "typed_ast-1.5.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:e20d196815eeffb3d76b75223e8ffed124e65ee62097e4e73afb5fec6b993e7a"}, + {file = "typed_ast-1.5.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:37e5349d1d5de2f4763d534ccb26809d1c24b180a477659a12c4bde9dd677d74"}, + {file = "typed_ast-1.5.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c9f1a27592fac87daa4e3f16538713d705599b0a27dfe25518b80b6b017f0a6d"}, + {file = "typed_ast-1.5.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8831479695eadc8b5ffed06fdfb3e424adc37962a75925668deeb503f446c0a3"}, + {file = "typed_ast-1.5.3-cp39-cp39-win_amd64.whl", hash = "sha256:20d5118e494478ef2d3a2702d964dae830aedd7b4d3b626d003eea526be18718"}, + {file = "typed_ast-1.5.3.tar.gz", hash = "sha256:27f25232e2dd0edfe1f019d6bfaaf11e86e657d9bdb7b0956db95f560cceb2b3"}, +] "typing-extensions 4.2.0" = [ {file = "typing_extensions-4.2.0-py3-none-any.whl", hash = "sha256:6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708"}, {file = "typing_extensions-4.2.0.tar.gz", hash = "sha256:f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376"}, diff --git a/pyproject.toml b/pyproject.toml index f4e8fcd..d79bb4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "literary" -version = "4.0.0a1" +version = "4.0.0a2" description = "Literate package development with Jupyter" authors = [ {name = "Angus Hollands", email = "goosey15@gmail.com"}, @@ -56,6 +56,9 @@ dev = [ "jupyterlab>=3.4.0", "pytest>=7.1.2", "literary>=4.0.0a0", + "jupyterlab-code-formatter>=1.4.11", + "black>=22.3.0", + "isort>=5.10.1", ] [tool.hatch.build] diff --git a/src/literary/commands/__main__.ipynb b/src/literary/commands/__main__.ipynb index d4e03c5..f430ff4 100644 --- a/src/literary/commands/__main__.ipynb +++ b/src/literary/commands/__main__.ipynb @@ -14,14 +14,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "informed-raise", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:13.655795Z", - "iopub.status.busy": "2021-05-18T21:00:13.654549Z", - "iopub.status.idle": "2021-05-18T21:00:13.662259Z", - "shell.execute_reply": "2021-05-18T21:00:13.662730Z" + "iopub.execute_input": "2022-05-12T11:23:58.033350Z", + "iopub.status.busy": "2022-05-12T11:23:58.032705Z", + "iopub.status.idle": "2022-05-12T11:23:58.368071Z", + "shell.execute_reply": "2022-05-12T11:23:58.367446Z" }, "tags": [ "export" @@ -40,14 +40,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "imported-thickness", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:13.669139Z", - "iopub.status.busy": "2021-05-18T21:00:13.668540Z", - "iopub.status.idle": "2021-05-18T21:00:13.670479Z", - "shell.execute_reply": "2021-05-18T21:00:13.671128Z" + "iopub.execute_input": "2022-05-12T11:23:58.371025Z", + "iopub.status.busy": "2022-05-12T11:23:58.370746Z", + "iopub.status.idle": "2022-05-12T11:23:58.375871Z", + "shell.execute_reply": "2022-05-12T11:23:58.375171Z" }, "tags": [ "export" @@ -65,7 +65,7 @@ " def start(self):\n", " \"\"\"Perform the App's actions as configured\"\"\"\n", " super().start()\n", - " \n", + "\n", " if self.subapp is None:\n", " sub_commands = \", \".join(sorted(self.subcommands))\n", " sys.exit(\"Please supply at least one subcommand: {}\".format(sub_commands))" @@ -73,14 +73,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "sustainable-archive", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:13.676540Z", - "iopub.status.busy": "2021-05-18T21:00:13.675210Z", - "iopub.status.idle": "2021-05-18T21:00:13.677853Z", - "shell.execute_reply": "2021-05-18T21:00:13.678926Z" + "iopub.execute_input": "2022-05-12T11:23:58.378526Z", + "iopub.status.busy": "2022-05-12T11:23:58.378105Z", + "iopub.status.idle": "2022-05-12T11:23:58.381525Z", + "shell.execute_reply": "2022-05-12T11:23:58.381067Z" }, "tags": [ "export" @@ -93,14 +93,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "7cd5310f-b1a4-4926-b909-b736e37d839c", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:14.973332Z", - "iopub.status.busy": "2021-05-18T21:00:14.971745Z", - "iopub.status.idle": "2021-05-18T21:00:14.974742Z", - "shell.execute_reply": "2021-05-18T21:00:14.975885Z" + "iopub.execute_input": "2022-05-12T11:23:58.383872Z", + "iopub.status.busy": "2022-05-12T11:23:58.383598Z", + "iopub.status.idle": "2022-05-12T11:23:58.387073Z", + "shell.execute_reply": "2022-05-12T11:23:58.386566Z" }, "tags": [ "export" diff --git a/src/literary/commands/app.ipynb b/src/literary/commands/app.ipynb index f5e3a86..b9a2cbc 100644 --- a/src/literary/commands/app.ipynb +++ b/src/literary/commands/app.ipynb @@ -14,14 +14,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "informed-raise", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:07.997672Z", - "iopub.status.busy": "2021-05-18T21:00:07.996449Z", - "iopub.status.idle": "2021-05-18T21:00:08.000077Z", - "shell.execute_reply": "2021-05-18T21:00:07.999029Z" + "iopub.execute_input": "2022-05-12T11:23:59.952283Z", + "iopub.status.busy": "2022-05-12T11:23:59.951856Z", + "iopub.status.idle": "2022-05-12T11:24:00.061456Z", + "shell.execute_reply": "2022-05-12T11:24:00.060887Z" }, "tags": [ "export" @@ -43,14 +43,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "74c77e66-da39-4d89-a52f-8491361d0bcf", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:08.014076Z", - "iopub.status.busy": "2021-05-18T21:00:08.013127Z", - "iopub.status.idle": "2021-05-18T21:00:08.017282Z", - "shell.execute_reply": "2021-05-18T21:00:08.016046Z" + "iopub.execute_input": "2022-05-12T11:24:00.064247Z", + "iopub.status.busy": "2022-05-12T11:24:00.063842Z", + "iopub.status.idle": "2022-05-12T11:24:00.069852Z", + "shell.execute_reply": "2022-05-12T11:24:00.069311Z" }, "tags": [ "export" @@ -63,9 +63,7 @@ " description = \"A Literary application\"\n", " aliases = {**Application.aliases, \"config-file\": \"LiteraryApp.config_file\"}\n", "\n", - " config_file = PathTrait(help=\"Literary project configuration file\").tag(\n", - " config=True\n", - " )\n", + " config_file = PathTrait(help=\"Literary project configuration file\").tag(config=True)\n", "\n", " project_path = PathTrait(help=\"Path to Literary project top-level directory\").tag(\n", " config=True\n", @@ -103,9 +101,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "5b160148-86a4-4828-a616-3a6146a77e29", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:00.072517Z", + "iopub.status.busy": "2022-05-12T11:24:00.072205Z", + "iopub.status.idle": "2022-05-12T11:24:00.076011Z", + "shell.execute_reply": "2022-05-12T11:24:00.075470Z" + }, "tags": [ "export" ] @@ -132,10 +136,10 @@ "id": "0809aef0-26b0-4c62-963d-65a802bf5bb1", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:29.468339Z", - "iopub.status.busy": "2021-05-18T21:00:29.467720Z", - "iopub.status.idle": "2021-05-18T21:00:29.469492Z", - "shell.execute_reply": "2021-05-18T21:00:29.469999Z" + "iopub.execute_input": "2022-05-12T11:24:00.078568Z", + "iopub.status.busy": "2022-05-12T11:24:00.078266Z", + "iopub.status.idle": "2022-05-12T11:24:00.082703Z", + "shell.execute_reply": "2022-05-12T11:24:00.081921Z" }, "tags": [ "export" @@ -163,10 +167,10 @@ "id": "1a9baca9-a61e-440f-9997-5a720fcc2990", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:29.474450Z", - "iopub.status.busy": "2021-05-18T21:00:29.473853Z", - "iopub.status.idle": "2021-05-18T21:00:29.475654Z", - "shell.execute_reply": "2021-05-18T21:00:29.476155Z" + "iopub.execute_input": "2022-05-12T11:24:00.085113Z", + "iopub.status.busy": "2022-05-12T11:24:00.084845Z", + "iopub.status.idle": "2022-05-12T11:24:00.088353Z", + "shell.execute_reply": "2022-05-12T11:24:00.087681Z" }, "tags": [ "export" @@ -193,10 +197,10 @@ "id": "663b69e3-8787-4fd7-a9bb-ec57797dc274", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:29.480607Z", - "iopub.status.busy": "2021-05-18T21:00:29.480011Z", - "iopub.status.idle": "2021-05-18T21:00:29.481813Z", - "shell.execute_reply": "2021-05-18T21:00:29.482318Z" + "iopub.execute_input": "2022-05-12T11:24:00.090885Z", + "iopub.status.busy": "2022-05-12T11:24:00.090613Z", + "iopub.status.idle": "2022-05-12T11:24:00.094473Z", + "shell.execute_reply": "2022-05-12T11:24:00.093790Z" }, "tags": [ "export" diff --git a/src/literary/commands/build.ipynb b/src/literary/commands/build.ipynb index ecba9e0..dc35324 100644 --- a/src/literary/commands/build.ipynb +++ b/src/literary/commands/build.ipynb @@ -14,9 +14,15 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "differential-carolina", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.736997Z", + "iopub.status.busy": "2022-05-12T11:24:01.736430Z", + "iopub.status.idle": "2022-05-12T11:24:01.906166Z", + "shell.execute_reply": "2022-05-12T11:24:01.905475Z" + }, "lines_to_next_cell": 2, "tags": [ "export" @@ -38,9 +44,15 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "integrated-continent", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.908970Z", + "iopub.status.busy": "2022-05-12T11:24:01.908616Z", + "iopub.status.idle": "2022-05-12T11:24:01.912804Z", + "shell.execute_reply": "2022-05-12T11:24:01.911990Z" + }, "tags": [ "export" ] @@ -60,9 +72,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "695f4635-5746-4775-9968-653eebf50fa7", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.917133Z", + "iopub.status.busy": "2022-05-12T11:24:01.916850Z", + "iopub.status.idle": "2022-05-12T11:24:01.922561Z", + "shell.execute_reply": "2022-05-12T11:24:01.921628Z" + }, "tags": [ "export" ] @@ -71,9 +89,9 @@ "source": [ "class LiteraryBuildApp(LiteraryApp):\n", " \"\"\"Project operator which builds a Literary package from a set of notebook directories.\"\"\"\n", - " \n", + "\n", " description = \"Build a pure-Python package from a set of Jupyter notebooks\"\n", - " \n", + "\n", " exporter = Instance(Exporter)\n", " exporter_class = Type(LiteraryExporter).tag(config=True)\n", "\n", @@ -114,9 +132,15 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "1a38f83c-b8c1-4ca2-b5ef-eafd46e842ca", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.926574Z", + "iopub.status.busy": "2022-05-12T11:24:01.926280Z", + "iopub.status.idle": "2022-05-12T11:24:01.929853Z", + "shell.execute_reply": "2022-05-12T11:24:01.929412Z" + }, "tags": [ "export" ] @@ -139,9 +163,15 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "bee90241-7410-448a-8ed6-b5640254f7e5", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.934692Z", + "iopub.status.busy": "2022-05-12T11:24:01.934420Z", + "iopub.status.idle": "2022-05-12T11:24:01.937567Z", + "shell.execute_reply": "2022-05-12T11:24:01.937151Z" + }, "tags": [ "export" ] @@ -164,9 +194,15 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "6a55f4ba-4cf9-4010-8b29-62c7fabb3466", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.942709Z", + "iopub.status.busy": "2022-05-12T11:24:01.942252Z", + "iopub.status.idle": "2022-05-12T11:24:01.945842Z", + "shell.execute_reply": "2022-05-12T11:24:01.945316Z" + }, "tags": [ "export" ] @@ -189,9 +225,15 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "medium-lebanon", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.951738Z", + "iopub.status.busy": "2022-05-12T11:24:01.951493Z", + "iopub.status.idle": "2022-05-12T11:24:01.957847Z", + "shell.execute_reply": "2022-05-12T11:24:01.957352Z" + }, "tags": [ "export" ] @@ -252,9 +294,15 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "4671401e-5f73-4b93-b5cf-484099d3628e", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.962460Z", + "iopub.status.busy": "2022-05-12T11:24:01.962199Z", + "iopub.status.idle": "2022-05-12T11:24:01.966039Z", + "shell.execute_reply": "2022-05-12T11:24:01.965398Z" + }, "tags": [ "export" ] @@ -278,9 +326,15 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "fb39ec21-fb7c-4d15-b64e-78326174ff16", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.970702Z", + "iopub.status.busy": "2022-05-12T11:24:01.970430Z", + "iopub.status.idle": "2022-05-12T11:24:01.974759Z", + "shell.execute_reply": "2022-05-12T11:24:01.973982Z" + }, "tags": [ "export" ] @@ -313,9 +367,15 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "rising-pipeline", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:01.979414Z", + "iopub.status.busy": "2022-05-12T11:24:01.979127Z", + "iopub.status.idle": "2022-05-12T11:24:01.983575Z", + "shell.execute_reply": "2022-05-12T11:24:01.982868Z" + }, "tags": [ "export" ] diff --git a/src/literary/commands/test.ipynb b/src/literary/commands/test.ipynb index cca7fe3..c658e12 100644 --- a/src/literary/commands/test.ipynb +++ b/src/literary/commands/test.ipynb @@ -14,9 +14,15 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "id": "golden-festival", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:03.611524Z", + "iopub.status.busy": "2022-05-12T11:24:03.610659Z", + "iopub.status.idle": "2022-05-12T11:24:03.817177Z", + "shell.execute_reply": "2022-05-12T11:24:03.816623Z" + }, "tags": [ "export" ] @@ -38,9 +44,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "id": "b987c651-2cfa-4a19-b92b-919077449497", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:03.819748Z", + "iopub.status.busy": "2022-05-12T11:24:03.819472Z", + "iopub.status.idle": "2022-05-12T11:24:03.822753Z", + "shell.execute_reply": "2022-05-12T11:24:03.822173Z" + }, "tags": [ "export" ] @@ -52,9 +64,15 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "id": "05afe6ea-e56d-44e9-b968-cb3db577d149", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:03.824881Z", + "iopub.status.busy": "2022-05-12T11:24:03.824642Z", + "iopub.status.idle": "2022-05-12T11:24:03.830372Z", + "shell.execute_reply": "2022-05-12T11:24:03.829737Z" + }, "tags": [ "export" ] @@ -63,7 +81,7 @@ "source": [ "class LiteraryTestApp(LiteraryApp):\n", " \"\"\"Test the current project notebooks, with various failure strategies.\"\"\"\n", - " \n", + "\n", " client_class = Type(\n", " nbclient.NotebookClient, help=\"Class for the notebook client\"\n", " ).tag(config=True)\n", @@ -95,9 +113,15 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "id": "ce05a61f-2c3d-491f-8db1-65ace29330ef", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:03.832947Z", + "iopub.status.busy": "2022-05-12T11:24:03.832635Z", + "iopub.status.idle": "2022-05-12T11:24:03.837351Z", + "shell.execute_reply": "2022-05-12T11:24:03.836557Z" + }, "tags": [ "export" ] @@ -107,7 +131,7 @@ "@patch(LiteraryTestApp)\n", "def _execute_notebook(self, path: Path):\n", " \"\"\"Execute the notebook with the given path.\n", - " \n", + "\n", " :param path: path to notebook\n", " \"\"\"\n", " nb = nbformat.read(path, as_version=nbformat.NO_CONVERT)\n", @@ -119,9 +143,15 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "id": "5bf9c867-b2f0-4ef4-9c00-7fc1ccaf9921", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:03.839813Z", + "iopub.status.busy": "2022-05-12T11:24:03.839546Z", + "iopub.status.idle": "2022-05-12T11:24:03.843874Z", + "shell.execute_reply": "2022-05-12T11:24:03.843375Z" + }, "tags": [ "export" ] @@ -155,9 +185,15 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "id": "be6b8a1b-cd86-45c9-827a-b8ddf9bf97a1", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:03.846221Z", + "iopub.status.busy": "2022-05-12T11:24:03.845972Z", + "iopub.status.idle": "2022-05-12T11:24:03.849732Z", + "shell.execute_reply": "2022-05-12T11:24:03.849149Z" + }, "tags": [ "export" ] @@ -168,7 +204,7 @@ "def _visit_and_flatten_paths(self, paths: tp.Iterable[str]):\n", " \"\"\"Flatten an iterable of directory and file paths into file paths.\n", " Directories will be visited and any notebook paths that are not ignored will be yielded.\n", - " \n", + "\n", " :param paths: iterable of paths\n", " \"\"\"\n", " for p in paths:\n", @@ -181,9 +217,15 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "id": "2b41ace0-8435-4601-a042-4cfaf30d53f2", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:03.851959Z", + "iopub.status.busy": "2022-05-12T11:24:03.851707Z", + "iopub.status.idle": "2022-05-12T11:24:03.856667Z", + "shell.execute_reply": "2022-05-12T11:24:03.856105Z" + }, "tags": [ "export" ] @@ -195,13 +237,13 @@ " \"\"\"Run the tracked notebooks in a process pool.\"\"\"\n", " sources = [Path(p) for p in [self.packages_path] + self.extra_paths]\n", " paths = [*self._visit_and_flatten_paths(sources)]\n", - " \n", + "\n", " return_when = futures.FIRST_EXCEPTION if self.fail_fast else futures.ALL_COMPLETED\n", "\n", " with futures.ProcessPoolExecutor(max_workers=self.jobs) as executor:\n", " tasks = [executor.submit(self._execute_notebook, p) for p in paths]\n", " done, not_done = futures.wait(tasks, return_when=return_when)\n", - " \n", + "\n", " # Raise any exceptions\n", " for path, task in zip(paths, done):\n", " task.result()\n", diff --git a/src/literary/commands/trait.ipynb b/src/literary/commands/trait.ipynb index b8a56ab..416efa1 100644 --- a/src/literary/commands/trait.ipynb +++ b/src/literary/commands/trait.ipynb @@ -10,14 +10,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "8f876794-8f60-4f95-b653-cb4cccaed292", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:32.938393Z", - "iopub.status.busy": "2021-05-18T21:00:32.937795Z", - "iopub.status.idle": "2021-05-18T21:00:32.940663Z", - "shell.execute_reply": "2021-05-18T21:00:32.940054Z" + "iopub.execute_input": "2022-05-12T11:24:05.337756Z", + "iopub.status.busy": "2022-05-12T11:24:05.337135Z", + "iopub.status.idle": "2022-05-12T11:24:05.341976Z", + "shell.execute_reply": "2022-05-12T11:24:05.341229Z" }, "tags": [ "export" @@ -25,20 +25,21 @@ }, "outputs": [], "source": [ - "import traitlets\n", - "import pathlib" + "import pathlib\n", + "\n", + "import traitlets" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "0a98271c-60e6-45ab-a136-06301a9b2244", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:32.946246Z", - "iopub.status.busy": "2021-05-18T21:00:32.945576Z", - "iopub.status.idle": "2021-05-18T21:00:32.948816Z", - "shell.execute_reply": "2021-05-18T21:00:32.948274Z" + "iopub.execute_input": "2022-05-12T11:24:05.344228Z", + "iopub.status.busy": "2022-05-12T11:24:05.344005Z", + "iopub.status.idle": "2022-05-12T11:24:05.348450Z", + "shell.execute_reply": "2022-05-12T11:24:05.347512Z" }, "tags": [ "export" @@ -48,6 +49,7 @@ "source": [ "class Path(traitlets.TraitType):\n", " \"\"\"A pathlib.Path trait class\"\"\"\n", + "\n", " def validate(self, obj, value):\n", " try:\n", " return pathlib.Path(value)\n", diff --git a/src/literary/config/__init__.ipynb b/src/literary/config/__init__.ipynb index 0611cb5..1a02f23 100644 --- a/src/literary/config/__init__.ipynb +++ b/src/literary/config/__init__.ipynb @@ -10,9 +10,15 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 1, "id": "front-notion", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:06.932980Z", + "iopub.status.busy": "2022-05-12T11:24:06.932676Z", + "iopub.status.idle": "2022-05-12T11:24:06.937089Z", + "shell.execute_reply": "2022-05-12T11:24:06.936397Z" + }, "tags": [ "export" ] @@ -41,9 +47,15 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "id": "8ed360c7-eef6-4707-804a-744225ecdd79", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:06.941857Z", + "iopub.status.busy": "2022-05-12T11:24:06.941562Z", + "iopub.status.idle": "2022-05-12T11:24:06.944629Z", + "shell.execute_reply": "2022-05-12T11:24:06.944087Z" + }, "tags": [ "export" ] @@ -63,9 +75,15 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 3, "id": "environmental-cooperation", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:06.950762Z", + "iopub.status.busy": "2022-05-12T11:24:06.949962Z", + "iopub.status.idle": "2022-05-12T11:24:06.956823Z", + "shell.execute_reply": "2022-05-12T11:24:06.955846Z" + }, "tags": [ "export" ] @@ -81,7 +99,7 @@ " # Look for any config file\n", " for p in path.glob(f\"{CONFIG_FILE_STEM}.*\"):\n", " return p\n", - " \n", + "\n", " # Visit parent\n", " if path.parents:\n", " return find_literary_config(path.parent)\n", @@ -99,15 +117,22 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 4, "id": "131149c5-b284-4765-b079-abbd2054b350", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:06.962252Z", + "iopub.status.busy": "2022-05-12T11:24:06.961573Z", + "iopub.status.idle": "2022-05-12T11:24:06.968840Z", + "shell.execute_reply": "2022-05-12T11:24:06.967818Z" + }, "tags": [ "export" ] }, "outputs": [], "source": [ + "@lru_cache()\n", "def load_literary_config(path: Path) -> Config:\n", " \"\"\"Load a project configuration file\n", "\n", diff --git a/src/literary/hook/__init__.ipynb b/src/literary/hook/__init__.ipynb index f39d398..1f5b701 100644 --- a/src/literary/hook/__init__.ipynb +++ b/src/literary/hook/__init__.ipynb @@ -1,37 +1,49 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "f7f38cc5-1baa-4c34-9426-c00bc62f09bd", + "metadata": {}, + "source": [ + "# Import Hook\n", + "\n", + "In order to be able to import on-disk notebooks as Python modules, we need a Python import hook. This hook is lazy, as importing `nbconvert` et al. significantly affects startup time." + ] + }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 1, "id": "74d6c9be-4502-4ec4-8a14-9aa073762ded", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:08.611120Z", + "iopub.status.busy": "2022-05-12T11:24:08.610721Z", + "iopub.status.idle": "2022-05-12T11:24:08.617316Z", + "shell.execute_reply": "2022-05-12T11:24:08.616150Z" + }, "tags": [ "export" ] }, "outputs": [], "source": [ - "from .finder import extend_file_finder\n", - "\n", - "import builtins\n", "import sys\n", "import traceback\n", - "from pathlib import Path" - ] - }, - { - "cell_type": "markdown", - "id": "9bbd720f-f197-48b2-9f7f-908ac9928213", - "metadata": {}, - "source": [ - "Here we implement a no-op implementation of the loader interface:" + "\n", + "from .finder import extend_file_finder, install_ipykernel_restrictor" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 2, "id": "4202e95e-461a-4b69-a86b-c54055647ccb", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:08.622846Z", + "iopub.status.busy": "2022-05-12T11:24:08.622209Z", + "iopub.status.idle": "2022-05-12T11:24:08.628008Z", + "shell.execute_reply": "2022-05-12T11:24:08.626835Z" + }, "tags": [ "export" ] @@ -44,17 +56,31 @@ }, { "cell_type": "markdown", - "id": "b8ad0675-b7c3-41f9-9334-d3daa147f146", + "id": "094d56d7-e70e-44c9-a450-285702c0d3e8", "metadata": {}, "source": [ - "We want to lazily load the notebook loader factory so that the Python startup is not adversely affected by importing nbconvert et al. However, if we do this naively with a relative import that is evaluated per-notebook, we will run into import loops. Here we'll define a lazy proxy that ensures the import hook is fully loaded." + "We want to lazily load the notebook loader factory so that the Python startup is not adversely affected by importing nbconvert et al. " + ] + }, + { + "cell_type": "markdown", + "id": "736733c6-e0aa-4bd5-be33-ced1021fb88b", + "metadata": {}, + "source": [ + "Now we'll define a lazy proxy that ensures the import hook is fully loaded by the time a package needs it:" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 3, "id": "25d57a07-a47e-40d6-80f1-03df6eeb69dd", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:08.632061Z", + "iopub.status.busy": "2022-05-12T11:24:08.630827Z", + "iopub.status.idle": "2022-05-12T11:24:08.637669Z", + "shell.execute_reply": "2022-05-12T11:24:08.636926Z" + }, "tags": [ "export" ] @@ -63,18 +89,17 @@ "source": [ "def notebook_loader_factory(fullname, path):\n", " try:\n", - " factory = notebook_loader_factory.factory\n", + " get_loader = notebook_loader_factory.get_loader\n", " except AttributeError:\n", " # As we're installing the notebook hook, we shouldn't be loading any notebooks yet\n", - " notebook_loader_factory.factory = noop_loader\n", + " notebook_loader_factory.get_loader = noop_loader\n", "\n", " # Realise import of loader\n", " from .importer import get_loader\n", - " notebook_loader_factory.factory = get_loader\n", "\n", - " factory = get_loader\n", + " notebook_loader_factory.get_loader = get_loader\n", "\n", - " return factory(fullname, path)" + " return get_loader(fullname, path)" ] }, { @@ -90,14 +115,25 @@ "execution_count": 4, "id": "f9ee7560-eae0-4694-b74f-8fa2cf232246", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:08.640228Z", + "iopub.status.busy": "2022-05-12T11:24:08.639979Z", + "iopub.status.idle": "2022-05-12T11:24:08.643787Z", + "shell.execute_reply": "2022-05-12T11:24:08.643210Z" + }, "tags": [ "export" ] }, "outputs": [], "source": [ - "def install_import_hook(set_except_hook=True):\n", - " extend_file_finder((notebook_loader_factory, [\".ipynb\"]),)\n", + "def install_import_hook(set_except_hook=True, restrict_ipykernel_path=True):\n", + " if restrict_ipykernel_path:\n", + " install_ipykernel_restrictor()\n", + "\n", + " extend_file_finder(\n", + " (notebook_loader_factory, [\".ipynb\"]),\n", + " )\n", "\n", " if set_except_hook:\n", " sys.excepthook = traceback.print_exception" diff --git a/src/literary/hook/finder.ipynb b/src/literary/hook/finder.ipynb index ecdd4dd..b898e3f 100644 --- a/src/literary/hook/finder.ipynb +++ b/src/literary/hook/finder.ipynb @@ -14,14 +14,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "atomic-restoration", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:38.918763Z", - "iopub.status.busy": "2021-05-18T21:00:38.917571Z", - "iopub.status.idle": "2021-05-18T21:00:38.921501Z", - "shell.execute_reply": "2021-05-18T21:00:38.920415Z" + "iopub.execute_input": "2022-05-12T11:24:10.286561Z", + "iopub.status.busy": "2022-05-12T11:24:10.286092Z", + "iopub.status.idle": "2022-05-12T11:24:10.290890Z", + "shell.execute_reply": "2022-05-12T11:24:10.290345Z" }, "tags": [ "export" @@ -29,21 +29,30 @@ }, "outputs": [], "source": [ + "import os\n", "import sys\n", - "from importlib.machinery import FileFinder\n", + "from importlib.machinery import FileFinder, PathFinder\n", "from inspect import getclosurevars" ] }, + { + "cell_type": "markdown", + "id": "302097d2-ab17-45c6-ade1-e74f417e7d55", + "metadata": {}, + "source": [ + "The notebook loader needs to be installed by modifying the existing `FileFinder`. This is so that packages can be loaded with `__init__.ipynb` or `__init__.py` modules." + ] + }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "id": "908ecbf2-022a-4d18-9d0d-21533c80fe91", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:38.961195Z", - "iopub.status.busy": "2021-05-18T21:00:38.960612Z", - "iopub.status.idle": "2021-05-18T21:00:38.963344Z", - "shell.execute_reply": "2021-05-18T21:00:38.962736Z" + "iopub.execute_input": "2022-05-12T11:24:10.295732Z", + "iopub.status.busy": "2022-05-12T11:24:10.295307Z", + "iopub.status.idle": "2022-05-12T11:24:10.300325Z", + "shell.execute_reply": "2022-05-12T11:24:10.299794Z" }, "tags": [ "export" @@ -51,9 +60,7 @@ }, "outputs": [], "source": [ - "def extend_file_finder(\n", - " *loader_details\n", - "):\n", + "def extend_file_finder(*loader_details):\n", " \"\"\"Inject a set of loaders into a list of path hooks\n", "\n", " :param path_hooks: list of path hooks\n", @@ -80,6 +87,84 @@ " # To fix cached path finders\n", " sys.path_importer_cache.clear()" ] + }, + { + "cell_type": "markdown", + "id": "6dd8802c-5265-4e1e-b520-c1fb5855bf26", + "metadata": {}, + "source": [ + "We will want to lazily load the notebook loader factory so that the Python startup is not adversely affected by importing nbconvert et al. However, IPyKernel puts the working directory on the `sys.path` by default, which causes problems if any notebooks shadow built-in packages. Although this also holds for regular Python files in the working directory, in practice this behaviour is not desirable, so we choose to (opt-out) remove the working directory from the path using a meta path finder." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "2e493732-a88d-43fb-9d03-a291e3d5c1f4", + "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:10.303926Z", + "iopub.status.busy": "2022-05-12T11:24:10.303174Z", + "iopub.status.idle": "2022-05-12T11:24:10.312528Z", + "shell.execute_reply": "2022-05-12T11:24:10.311533Z" + }, + "tags": [ + "export" + ] + }, + "outputs": [], + "source": [ + "class IPyKernelPathRestrictor:\n", + " @classmethod\n", + " def find_spec(cls, fullname, path=None, target=None):\n", + " if \".\" in fullname:\n", + " return None\n", + "\n", + " name = fullname.split(\".\", 1)[0]\n", + "\n", + " # IPython controls the kernel startup including its path\n", + " # The user cannot easily shape this, so instead we ignore notebooks\n", + " # during initialisation, to avoid problems of name shadowing in the cwd\n", + " if name == \"ipykernel\":\n", + " cwd = os.path.realpath(os.getcwd())\n", + " sys.path = [p for p in sys.path if os.path.realpath(p) != cwd]\n", + "\n", + " return None" + ] + }, + { + "cell_type": "markdown", + "id": "24ff552e-f91a-4a96-b870-304e1008e648", + "metadata": {}, + "source": [ + "Let's make a dedicated installer for this" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "731fec98-b411-4676-8975-a407e785d1d8", + "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:10.316594Z", + "iopub.status.busy": "2022-05-12T11:24:10.316045Z", + "iopub.status.idle": "2022-05-12T11:24:10.322488Z", + "shell.execute_reply": "2022-05-12T11:24:10.321739Z" + }, + "tags": [ + "export" + ] + }, + "outputs": [], + "source": [ + "def install_ipykernel_restrictor():\n", + " for i, finder in enumerate(sys.meta_path):\n", + " if finder is PathFinder:\n", + " break\n", + " else:\n", + " return\n", + "\n", + " sys.meta_path.insert(i, IPyKernelPathRestrictor)" + ] } ], "metadata": { diff --git a/src/literary/hook/importer.ipynb b/src/literary/hook/importer.ipynb index f33dc29..7a52a0a 100644 --- a/src/literary/hook/importer.ipynb +++ b/src/literary/hook/importer.ipynb @@ -14,9 +14,15 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "id": "atomic-restoration", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:11.960182Z", + "iopub.status.busy": "2022-05-12T11:24:11.959943Z", + "iopub.status.idle": "2022-05-12T11:24:11.965303Z", + "shell.execute_reply": "2022-05-12T11:24:11.964448Z" + }, "tags": [ "export" ] @@ -25,6 +31,7 @@ "source": [ "from functools import lru_cache\n", "from pathlib import Path\n", + "\n", "from nbconvert import Exporter\n", "from traitlets import Instance, Type, default\n", "from traitlets.config import Configurable\n", @@ -44,9 +51,15 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "id": "4bd4893f-d373-4161-80b3-1ce334492a15", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:11.970100Z", + "iopub.status.busy": "2022-05-12T11:24:11.969063Z", + "iopub.status.idle": "2022-05-12T11:24:11.974074Z", + "shell.execute_reply": "2022-05-12T11:24:11.973511Z" + }, "tags": [ "export" ] @@ -55,7 +68,9 @@ "source": [ "class NotebookImporter(Configurable):\n", " exporter = Instance(Exporter)\n", - " exporter_class = Type(LiteraryExporter).tag(config=True)" + " exporter_class = Type(\n", + " LiteraryExporter, help=\"exporter class used for module source generation\"\n", + " ).tag(config=True)" ] }, { @@ -68,9 +83,15 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "id": "c2b8b55d-8d52-49d4-8c99-97731232187c", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:11.978637Z", + "iopub.status.busy": "2022-05-12T11:24:11.978232Z", + "iopub.status.idle": "2022-05-12T11:24:11.982023Z", + "shell.execute_reply": "2022-05-12T11:24:11.981500Z" + }, "tags": [ "export" ] @@ -93,9 +114,15 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "id": "f8172c3a-00b6-41eb-80f9-bfbe5a67a5ad", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:11.988215Z", + "iopub.status.busy": "2022-05-12T11:24:11.987213Z", + "iopub.status.idle": "2022-05-12T11:24:11.994277Z", + "shell.execute_reply": "2022-05-12T11:24:11.993579Z" + }, "tags": [ "export" ] @@ -103,7 +130,7 @@ "outputs": [], "source": [ "@patch(NotebookImporter)\n", - "def get_loader(self, fullname, path): \n", + "def get_loader(self, fullname, path):\n", " # Create the exporter\n", " exporter = self.exporter_class(parent=self)\n", " return NotebookLoader(fullname, path, exporter=self.exporter)" @@ -111,42 +138,24 @@ }, { "cell_type": "markdown", - "id": "3237d24c-960d-4e31-bc0f-8f911d7a18f1", + "id": "5dc94192-f264-4078-81e9-378ad30d7246", "metadata": {}, "source": [ "## Loader factory\n", - "To avoid a startup penalty, we want this module to be imported lazily. We should also load the configuation lazily" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2e3659fa-dd6c-4f42-897d-49cf75badfc7", - "metadata": { - "tags": [ - "export" - ] - }, - "outputs": [], - "source": [ - "@lru_cache()\n", - "def load_cached_config(path):\n", - " return load_literary_config(path)" - ] - }, - { - "cell_type": "markdown", - "id": "498179f1-f812-4a6c-862c-f8c3c6dcb16f", - "metadata": {}, - "source": [ - "However, we also do not want to have to lookup relative imports once the import hook has been installed. It this were to happen, the import hook itself may start resolving against the local notebooks (and things would break)! So, we provide a factory function here that can be imported once on demand by the hook." + "To avoid a startup penalty, we want this module to be imported lazily. However, we also do not want to have to lookup relative imports once the import hook has been installed. It this were to happen, the import hook itself may start resolving against the local notebooks (and things would break)! So, we provide a factory function here that can be imported once on demand by the hook." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "a1fc2bb1-4d07-40a8-8f31-02e425661eda", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:11.998707Z", + "iopub.status.busy": "2022-05-12T11:24:11.998466Z", + "iopub.status.idle": "2022-05-12T11:24:12.001574Z", + "shell.execute_reply": "2022-05-12T11:24:12.001138Z" + }, "tags": [ "export" ] @@ -158,7 +167,7 @@ " config_path = find_literary_config(Path(path))\n", " except FileNotFoundError:\n", " return None\n", - " importer = NotebookImporter(config=load_cached_config(config_path))\n", + " importer = NotebookImporter(config=load_literary_config(config_path))\n", " return importer.get_loader(fullname, path)" ] } diff --git a/src/literary/hook/loader.ipynb b/src/literary/hook/loader.ipynb index ac9832a..e7732ea 100644 --- a/src/literary/hook/loader.ipynb +++ b/src/literary/hook/loader.ipynb @@ -17,6 +17,12 @@ "execution_count": 1, "id": "a2115a46-2725-45c4-9a9f-75eee74e0869", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:13.637059Z", + "iopub.status.busy": "2022-05-12T11:24:13.636582Z", + "iopub.status.idle": "2022-05-12T11:24:13.641877Z", + "shell.execute_reply": "2022-05-12T11:24:13.640992Z" + }, "tags": [] }, "outputs": [], @@ -31,6 +37,12 @@ "execution_count": 2, "id": "c7ff6b8f-9153-41d9-97c3-90f9c5e055ff", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:13.644503Z", + "iopub.status.busy": "2022-05-12T11:24:13.644221Z", + "iopub.status.idle": "2022-05-12T11:24:13.648240Z", + "shell.execute_reply": "2022-05-12T11:24:13.647463Z" + }, "tags": [ "export" ] @@ -38,8 +50,9 @@ "outputs": [], "source": [ "import linecache\n", - "import nbformat\n", - "from importlib.machinery import SourcelessFileLoader" + "from importlib.machinery import SourcelessFileLoader\n", + "\n", + "import nbformat" ] }, { @@ -47,6 +60,12 @@ "execution_count": 3, "id": "5bcde51b-dda5-4613-afbc-de78ba2232e8", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:13.650835Z", + "iopub.status.busy": "2022-05-12T11:24:13.650474Z", + "iopub.status.idle": "2022-05-12T11:24:13.656540Z", + "shell.execute_reply": "2022-05-12T11:24:13.655986Z" + }, "tags": [ "export" ] @@ -104,10 +123,10 @@ "id": "6f82e3e8-2324-4d4d-9740-a42eea24caab", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:43.809005Z", - "iopub.status.busy": "2021-05-18T21:00:43.808401Z", - "iopub.status.idle": "2021-05-18T21:00:43.814687Z", - "shell.execute_reply": "2021-05-18T21:00:43.814190Z" + "iopub.execute_input": "2022-05-12T11:24:13.659669Z", + "iopub.status.busy": "2022-05-12T11:24:13.659205Z", + "iopub.status.idle": "2022-05-12T11:24:13.669966Z", + "shell.execute_reply": "2022-05-12T11:24:13.668545Z" } }, "outputs": [], @@ -121,10 +140,10 @@ "id": "cf7dd2c1-c39b-4048-ad13-f5074d1eb076", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:43.820525Z", - "iopub.status.busy": "2021-05-18T21:00:43.819185Z", - "iopub.status.idle": "2021-05-18T21:00:43.821963Z", - "shell.execute_reply": "2021-05-18T21:00:43.823173Z" + "iopub.execute_input": "2022-05-12T11:24:13.673782Z", + "iopub.status.busy": "2022-05-12T11:24:13.673012Z", + "iopub.status.idle": "2022-05-12T11:24:13.679034Z", + "shell.execute_reply": "2022-05-12T11:24:13.678018Z" } }, "outputs": [], @@ -147,10 +166,10 @@ "id": "450bd5d4-e0ef-4544-a942-41566c06d14a", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:43.835785Z", - "iopub.status.busy": "2021-05-18T21:00:43.835189Z", - "iopub.status.idle": "2021-05-18T21:00:43.839008Z", - "shell.execute_reply": "2021-05-18T21:00:43.840017Z" + "iopub.execute_input": "2022-05-12T11:24:13.682746Z", + "iopub.status.busy": "2022-05-12T11:24:13.682115Z", + "iopub.status.idle": "2022-05-12T11:24:13.701210Z", + "shell.execute_reply": "2022-05-12T11:24:13.700281Z" } }, "outputs": [ @@ -160,7 +179,7 @@ "b'{\\n \"cells\": [\\n {\\n \"cell_type\": \"markdown\",\\n \"id\": \"b8c9dad6-af40-42b8-a071-2e6ce66c0d9e\",\\n \"m'" ] }, - "execution_count": 1, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -183,10 +202,10 @@ "id": "58853f8a-a2ba-4c6e-b8ea-19f700b47e3b", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:43.845329Z", - "iopub.status.busy": "2021-05-18T21:00:43.844622Z", - "iopub.status.idle": "2021-05-18T21:00:43.912134Z", - "shell.execute_reply": "2021-05-18T21:00:43.910878Z" + "iopub.execute_input": "2022-05-12T11:24:13.704048Z", + "iopub.status.busy": "2022-05-12T11:24:13.703772Z", + "iopub.status.idle": "2022-05-12T11:24:13.758909Z", + "shell.execute_reply": "2022-05-12T11:24:13.757945Z" } }, "outputs": [], @@ -208,10 +227,10 @@ "id": "ecfe5e15-d8d0-4b46-ba1f-9fa7db0b5f9c", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:43.918068Z", - "iopub.status.busy": "2021-05-18T21:00:43.916640Z", - "iopub.status.idle": "2021-05-18T21:00:43.920965Z", - "shell.execute_reply": "2021-05-18T21:00:43.921956Z" + "iopub.execute_input": "2022-05-12T11:24:13.761823Z", + "iopub.status.busy": "2022-05-12T11:24:13.761372Z", + "iopub.status.idle": "2022-05-12T11:24:13.765360Z", + "shell.execute_reply": "2022-05-12T11:24:13.764819Z" } }, "outputs": [ @@ -249,7 +268,7 @@ } ], "source": [ - "source = ''.join(linecache.getlines(file_path))\n", + "source = \"\".join(linecache.getlines(file_path))\n", "print(source)" ] }, @@ -267,10 +286,10 @@ "id": "c51d5457-fe70-42ed-8710-50c88777022b", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:43.927934Z", - "iopub.status.busy": "2021-05-18T21:00:43.927436Z", - "iopub.status.idle": "2021-05-18T21:00:43.930503Z", - "shell.execute_reply": "2021-05-18T21:00:43.929958Z" + "iopub.execute_input": "2022-05-12T11:24:13.768411Z", + "iopub.status.busy": "2022-05-12T11:24:13.768023Z", + "iopub.status.idle": "2022-05-12T11:24:13.771032Z", + "shell.execute_reply": "2022-05-12T11:24:13.770555Z" } }, "outputs": [], @@ -293,10 +312,10 @@ "id": "e1eeacc5-cedb-427e-a1a1-4278b9153941", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:43.934664Z", - "iopub.status.busy": "2021-05-18T21:00:43.933990Z", - "iopub.status.idle": "2021-05-18T21:00:43.938031Z", - "shell.execute_reply": "2021-05-18T21:00:43.936836Z" + "iopub.execute_input": "2022-05-12T11:24:13.773665Z", + "iopub.status.busy": "2022-05-12T11:24:13.773416Z", + "iopub.status.idle": "2022-05-12T11:24:13.776222Z", + "shell.execute_reply": "2022-05-12T11:24:13.775735Z" } }, "outputs": [], diff --git a/src/literary/module/__init__.ipynb b/src/literary/module/__init__.ipynb index a1111a8..575efda 100644 --- a/src/literary/module/__init__.ipynb +++ b/src/literary/module/__init__.ipynb @@ -9,14 +9,22 @@ ] }, "source": [ - "# Notebook Modules" + "# Notebook Modules\n", + "\n", + "Just providing importable notebook modules does not address the full scope of package development. When developing a package, we often want to perform relative imports `from . import x`. This requires that a `__package__` global is set to the name of the current package. Additionally, literary provides tools to make it easier to write literate documents e.g. `patch` which need to be exposed to the end user." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "id": "grave-finding", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:15.347832Z", + "iopub.status.busy": "2022-05-12T11:24:15.347422Z", + "iopub.status.idle": "2022-05-12T11:24:15.353810Z", + "shell.execute_reply": "2022-05-12T11:24:15.352959Z" + }, "tags": [ "export" ] @@ -26,51 +34,94 @@ "import sys\n", "import warnings\n", "from pathlib import Path\n", + "\n", + "from traitlets import Enum\n", + "from traitlets.config import Configurable\n", + "\n", + "from ..config import find_literary_config, load_literary_config\n", "from ..transpile.patch import patch" ] }, + { + "cell_type": "markdown", + "id": "02f2cb7b-357f-45f9-9acc-772470e0af12", + "metadata": {}, + "source": [ + "Let's implement a simple function to determine the name of the current package" + ] + }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "id": "48f56bbb-2398-4bd1-b16b-af6e7ca15c27", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:15.358126Z", + "iopub.status.busy": "2022-05-12T11:24:15.357294Z", + "iopub.status.idle": "2022-05-12T11:24:15.369753Z", + "shell.execute_reply": "2022-05-12T11:24:15.368407Z" + }, "tags": [ "export" ] }, "outputs": [], "source": [ - "def determine_package_name(path: Path) -> str:\n", - " \"\"\"Determine the corresponding importable name for a package directory given by\n", - " a particular file path. Return `None` if path is not contained within `sys.path`.\n", + "class NotebookExtension(Configurable):\n", + " package_name_strategy = Enum(\n", + " [\"shortest\", \"first\"],\n", + " default_value=\"shortest\",\n", + " help=\"strategy for resolving package name\",\n", + " ).tag(config=True)\n", "\n", - " :param path: path to package\n", - " :return:\n", - " \"\"\"\n", - " for p in sys.path:\n", - " # If the cwd is only on `sys.path` exactly, then it can't\n", - " # be a submodule. However, let's first look for parent paths\n", - " if str(path) == p:\n", - " continue\n", - "\n", - " # Resolve path relative to `sys.path`\n", - " try:\n", - " relative_path = path.relative_to(p)\n", - " except ValueError:\n", - " continue\n", - "\n", - " # This might be ambiguous, but let's assume first wins\n", - " return \".\".join(relative_path.parts)\n", - "\n", - " # Nothing was found on `sys.path`, so we abort\n", - " return None" + " def determine_package_name(self, path: Path) -> str:\n", + " \"\"\"Determine the corresponding importable name for a package directory given by\n", + " a particular file path. Return `None` if path is not contained within `sys.path`.\n", + "\n", + " :param path: path to package\n", + " :return:\n", + " \"\"\"\n", + " candidates = []\n", + " for p in sys.path:\n", + " # If the cwd is only on `sys.path` exactly, then it can't\n", + " # be a submodule. However, let's first look for parent paths\n", + " if str(path) == p:\n", + " continue\n", + "\n", + " # Resolve path relative to `sys.path`\n", + " try:\n", + " relative_path = path.relative_to(p)\n", + " except ValueError:\n", + " continue\n", + "\n", + " candidates.append(relative_path)\n", + "\n", + " # Nothing was found on `sys.path`, so we abort\n", + " if not candidates:\n", + " return\n", + "\n", + " # Different strategies for name resolution\n", + " if self.package_name_strategy == \"shortest\":\n", + " # This might be ambiguous (there may be several matches)\n", + " # so let's take the most-direct path\n", + " best_candidate = min(candidates, key=lambda x: len(x.parts))\n", + " else:\n", + " best_candidate = candidates[0]\n", + "\n", + " return \".\".join(best_candidate.parts)" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 3, "id": "classical-shoulder", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:15.374921Z", + "iopub.status.busy": "2022-05-12T11:24:15.374550Z", + "iopub.status.idle": "2022-05-12T11:24:15.379777Z", + "shell.execute_reply": "2022-05-12T11:24:15.379287Z" + }, "tags": [ "export" ] @@ -83,18 +134,27 @@ " added to `sys.path`.\n", "\n", " :param ipython: IPython shell instance\n", - " \"\"\" \n", + " \"\"\"\n", " cwd = Path.cwd()\n", "\n", + " # Load the current project's config\n", + " config = load_literary_config(find_literary_config(cwd))\n", + "\n", + " notebook_extension = NotebookExtension(config=config)\n", + "\n", " # Identify which package this belongs to\n", - " package = determine_package_name(cwd) \n", - " \n", + " package = notebook_extension.determine_package_name(cwd)\n", + "\n", " if package is None:\n", - " warnings.warn(f\"Couldn't determine the package name for the current working directory {cwd}. \"\n", - " f\"This might be because the current project has not been installed in editable mode.\")\n", - " \n", - " # Packages don't have absolute imports\n", + " warnings.warn(\n", + " f\"Couldn't determine the package name for the current working directory {cwd}. \"\n", + " f\"This might be because the current project has not been installed in editable mode.\"\n", + " )\n", + " # Allow local absolute imports\n", + " sys.path.append(str(cwd))\n", " else:\n", + " # Packages don't have absolute imports\n", + " # This should already have been done by the import hook, but let's guarantee\n", " sys.path = [p for p in sys.path if Path(p).resolve() != cwd]\n", "\n", " # Set `__package__` for consumer notebook\n", diff --git a/src/literary/transpile/exporter.ipynb b/src/literary/transpile/exporter.ipynb index 0c34553..da38596 100644 --- a/src/literary/transpile/exporter.ipynb +++ b/src/literary/transpile/exporter.ipynb @@ -14,14 +14,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "congressional-sacrifice", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:20.504388Z", - "iopub.status.busy": "2021-05-18T21:00:20.503141Z", - "iopub.status.idle": "2021-05-18T21:00:20.506583Z", - "shell.execute_reply": "2021-05-18T21:00:20.507551Z" + "iopub.execute_input": "2022-05-12T11:24:18.728417Z", + "iopub.status.busy": "2022-05-12T11:24:18.728017Z", + "iopub.status.idle": "2022-05-12T11:24:18.732955Z", + "shell.execute_reply": "2022-05-12T11:24:18.732448Z" }, "tags": [ "export" @@ -36,21 +36,21 @@ "from traitlets import List, default, import_item\n", "from traitlets.config import Config\n", "\n", - "from .preprocessor import TagAllowListPreprocessor\n", "from .filter import escape_triple_quotes\n", + "from .preprocessor import TagAllowListPreprocessor\n", "from .syntax import unparse_ast" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "deadly-gross", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:20.521232Z", - "iopub.status.busy": "2021-05-18T21:00:20.519982Z", - "iopub.status.idle": "2021-05-18T21:00:20.522516Z", - "shell.execute_reply": "2021-05-18T21:00:20.523504Z" + "iopub.execute_input": "2022-05-12T11:24:18.735714Z", + "iopub.status.busy": "2022-05-12T11:24:18.735432Z", + "iopub.status.idle": "2022-05-12T11:24:18.744658Z", + "shell.execute_reply": "2022-05-12T11:24:18.743851Z" }, "tags": [ "export" diff --git a/src/literary/transpile/filter.ipynb b/src/literary/transpile/filter.ipynb index b61f523..a81c1a6 100644 --- a/src/literary/transpile/filter.ipynb +++ b/src/literary/transpile/filter.ipynb @@ -14,14 +14,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "liberal-weekend", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:37.599010Z", - "iopub.status.busy": "2021-05-18T21:00:37.597842Z", - "iopub.status.idle": "2021-05-18T21:00:37.601461Z", - "shell.execute_reply": "2021-05-18T21:00:37.600272Z" + "iopub.execute_input": "2022-05-12T11:24:20.369774Z", + "iopub.status.busy": "2022-05-12T11:24:20.369048Z", + "iopub.status.idle": "2022-05-12T11:24:20.378168Z", + "shell.execute_reply": "2022-05-12T11:24:20.376678Z" }, "tags": [ "export" @@ -50,14 +50,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "mediterranean-conflict", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:37.610300Z", - "iopub.status.busy": "2021-05-18T21:00:37.609804Z", - "iopub.status.idle": "2021-05-18T21:00:37.613656Z", - "shell.execute_reply": "2021-05-18T21:00:37.612418Z" + "iopub.execute_input": "2022-05-12T11:24:20.382900Z", + "iopub.status.busy": "2022-05-12T11:24:20.382329Z", + "iopub.status.idle": "2022-05-12T11:24:20.389700Z", + "shell.execute_reply": "2022-05-12T11:24:20.388406Z" }, "tags": [ "export" @@ -89,14 +89,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "vocational-catalog", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:37.620434Z", - "iopub.status.busy": "2021-05-18T21:00:37.619236Z", - "iopub.status.idle": "2021-05-18T21:00:37.622281Z", - "shell.execute_reply": "2021-05-18T21:00:37.621662Z" + "iopub.execute_input": "2022-05-12T11:24:20.393646Z", + "iopub.status.busy": "2022-05-12T11:24:20.392918Z", + "iopub.status.idle": "2022-05-12T11:24:20.399234Z", + "shell.execute_reply": "2022-05-12T11:24:20.398147Z" } }, "outputs": [], @@ -117,15 +117,16 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "respective-greene", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:37.627047Z", - "iopub.status.busy": "2021-05-18T21:00:37.626462Z", - "iopub.status.idle": "2021-05-18T21:00:37.629522Z", - "shell.execute_reply": "2021-05-18T21:00:37.628922Z" - } + "iopub.execute_input": "2022-05-12T11:24:20.402373Z", + "iopub.status.busy": "2022-05-12T11:24:20.401968Z", + "iopub.status.idle": "2022-05-12T11:24:20.406121Z", + "shell.execute_reply": "2022-05-12T11:24:20.405240Z" + }, + "tags": [] }, "outputs": [], "source": [ diff --git a/src/literary/transpile/patch.ipynb b/src/literary/transpile/patch.ipynb index 0b50828..6db089a 100644 --- a/src/literary/transpile/patch.ipynb +++ b/src/literary/transpile/patch.ipynb @@ -12,14 +12,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "arabic-words", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.380206Z", - "iopub.status.busy": "2021-05-18T21:00:45.378916Z", - "iopub.status.idle": "2021-05-18T21:00:45.381495Z", - "shell.execute_reply": "2021-05-18T21:00:45.382482Z" + "iopub.execute_input": "2022-05-12T11:24:22.002864Z", + "iopub.status.busy": "2022-05-12T11:24:22.002583Z", + "iopub.status.idle": "2022-05-12T11:24:22.006102Z", + "shell.execute_reply": "2022-05-12T11:24:22.005628Z" }, "tags": [ "export" @@ -32,14 +32,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "unlikely-consent", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.388656Z", - "iopub.status.busy": "2021-05-18T21:00:45.388051Z", - "iopub.status.idle": "2021-05-18T21:00:45.390000Z", - "shell.execute_reply": "2021-05-18T21:00:45.390502Z" + "iopub.execute_input": "2022-05-12T11:24:22.008617Z", + "iopub.status.busy": "2022-05-12T11:24:22.008372Z", + "iopub.status.idle": "2022-05-12T11:24:22.010959Z", + "shell.execute_reply": "2022-05-12T11:24:22.010520Z" }, "tags": [ "export" @@ -60,14 +60,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "4d8d01bc-22f6-4741-b7cd-75c7c66c50dd", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.394677Z", - "iopub.status.busy": "2021-05-18T21:00:45.394086Z", - "iopub.status.idle": "2021-05-18T21:00:45.395935Z", - "shell.execute_reply": "2021-05-18T21:00:45.396445Z" + "iopub.execute_input": "2022-05-12T11:24:22.013113Z", + "iopub.status.busy": "2022-05-12T11:24:22.012905Z", + "iopub.status.idle": "2022-05-12T11:24:22.016063Z", + "shell.execute_reply": "2022-05-12T11:24:22.015574Z" }, "tags": [ "export" @@ -88,14 +88,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "editorial-corrections", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.403216Z", - "iopub.status.busy": "2021-05-18T21:00:45.402607Z", - "iopub.status.idle": "2021-05-18T21:00:45.404903Z", - "shell.execute_reply": "2021-05-18T21:00:45.404345Z" + "iopub.execute_input": "2022-05-12T11:24:22.018404Z", + "iopub.status.busy": "2022-05-12T11:24:22.018136Z", + "iopub.status.idle": "2022-05-12T11:24:22.022867Z", + "shell.execute_reply": "2022-05-12T11:24:22.022371Z" }, "tags": [ "export" @@ -145,14 +145,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "495ec606-4e33-4bd0-8e89-10b2af38c3af", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.408892Z", - "iopub.status.busy": "2021-05-18T21:00:45.408294Z", - "iopub.status.idle": "2021-05-18T21:00:45.410222Z", - "shell.execute_reply": "2021-05-18T21:00:45.410720Z" + "iopub.execute_input": "2022-05-12T11:24:22.026149Z", + "iopub.status.busy": "2022-05-12T11:24:22.025827Z", + "iopub.status.idle": "2022-05-12T11:24:22.028907Z", + "shell.execute_reply": "2022-05-12T11:24:22.028428Z" } }, "outputs": [], @@ -171,14 +171,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "96cd47e6-fe35-4974-9ad6-e494a7d7d2c9", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.414692Z", - "iopub.status.busy": "2021-05-18T21:00:45.414084Z", - "iopub.status.idle": "2021-05-18T21:00:45.415867Z", - "shell.execute_reply": "2021-05-18T21:00:45.416371Z" + "iopub.execute_input": "2022-05-12T11:24:22.031179Z", + "iopub.status.busy": "2022-05-12T11:24:22.030899Z", + "iopub.status.idle": "2022-05-12T11:24:22.035294Z", + "shell.execute_reply": "2022-05-12T11:24:22.034413Z" } }, "outputs": [], @@ -188,14 +188,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "989ffd7d-dee1-4ecc-be02-057dccf09a04", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.420379Z", - "iopub.status.busy": "2021-05-18T21:00:45.419783Z", - "iopub.status.idle": "2021-05-18T21:00:45.421562Z", - "shell.execute_reply": "2021-05-18T21:00:45.422063Z" + "iopub.execute_input": "2022-05-12T11:24:22.038404Z", + "iopub.status.busy": "2022-05-12T11:24:22.038056Z", + "iopub.status.idle": "2022-05-12T11:24:22.041499Z", + "shell.execute_reply": "2022-05-12T11:24:22.040964Z" } }, "outputs": [], @@ -215,15 +215,16 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "86b1122d-3e47-4422-8d9f-276945522472", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:45.426103Z", - "iopub.status.busy": "2021-05-18T21:00:45.425501Z", - "iopub.status.idle": "2021-05-18T21:00:45.427342Z", - "shell.execute_reply": "2021-05-18T21:00:45.427855Z" - } + "iopub.execute_input": "2022-05-12T11:24:22.044350Z", + "iopub.status.busy": "2022-05-12T11:24:22.043869Z", + "iopub.status.idle": "2022-05-12T11:24:22.049625Z", + "shell.execute_reply": "2022-05-12T11:24:22.048533Z" + }, + "tags": [] }, "outputs": [], "source": [ diff --git a/src/literary/transpile/preprocessor.ipynb b/src/literary/transpile/preprocessor.ipynb index c97926b..bf4a6e2 100644 --- a/src/literary/transpile/preprocessor.ipynb +++ b/src/literary/transpile/preprocessor.ipynb @@ -11,14 +11,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "settled-making", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:28.270303Z", - "iopub.status.busy": "2021-05-18T21:00:28.269805Z", - "iopub.status.idle": "2021-05-18T21:00:28.272835Z", - "shell.execute_reply": "2021-05-18T21:00:28.272383Z" + "iopub.execute_input": "2022-05-12T11:24:23.700966Z", + "iopub.status.busy": "2022-05-12T11:24:23.700578Z", + "iopub.status.idle": "2022-05-12T11:24:23.705694Z", + "shell.execute_reply": "2022-05-12T11:24:23.704739Z" }, "tags": [ "export" @@ -40,14 +40,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "a65fe4e0-383c-48f2-8946-f1cc48a3306e", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:28.277032Z", - "iopub.status.busy": "2021-05-18T21:00:28.276539Z", - "iopub.status.idle": "2021-05-18T21:00:28.279440Z", - "shell.execute_reply": "2021-05-18T21:00:28.279900Z" + "iopub.execute_input": "2022-05-12T11:24:23.710564Z", + "iopub.status.busy": "2022-05-12T11:24:23.710223Z", + "iopub.status.idle": "2022-05-12T11:24:23.715061Z", + "shell.execute_reply": "2022-05-12T11:24:23.714197Z" }, "tags": [ "export" @@ -69,14 +69,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "21cdf0c2-1339-4830-b94c-5792ec162d2e", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:28.284801Z", - "iopub.status.busy": "2021-05-18T21:00:28.284185Z", - "iopub.status.idle": "2021-05-18T21:00:28.286716Z", - "shell.execute_reply": "2021-05-18T21:00:28.287236Z" + "iopub.execute_input": "2022-05-12T11:24:23.718889Z", + "iopub.status.busy": "2022-05-12T11:24:23.718231Z", + "iopub.status.idle": "2022-05-12T11:24:23.725564Z", + "shell.execute_reply": "2022-05-12T11:24:23.724516Z" }, "tags": [ "export" @@ -100,14 +100,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "ccafe0b5-e3fb-4509-b190-2918cbfc4f7f", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:28.292464Z", - "iopub.status.busy": "2021-05-18T21:00:28.291839Z", - "iopub.status.idle": "2021-05-18T21:00:28.296265Z", - "shell.execute_reply": "2021-05-18T21:00:28.294909Z" + "iopub.execute_input": "2022-05-12T11:24:23.729097Z", + "iopub.status.busy": "2022-05-12T11:24:23.728646Z", + "iopub.status.idle": "2022-05-12T11:24:23.735487Z", + "shell.execute_reply": "2022-05-12T11:24:23.734615Z" }, "tags": [ "export" @@ -135,14 +135,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "af54c2f2-ff58-42c3-9a90-8a81bbe5e64f", "metadata": { "execution": { - "iopub.execute_input": "2021-05-18T21:00:28.301560Z", - "iopub.status.busy": "2021-05-18T21:00:28.300840Z", - "iopub.status.idle": "2021-05-18T21:00:28.303840Z", - "shell.execute_reply": "2021-05-18T21:00:28.304503Z" + "iopub.execute_input": "2022-05-12T11:24:23.738850Z", + "iopub.status.busy": "2022-05-12T11:24:23.738372Z", + "iopub.status.idle": "2022-05-12T11:24:23.743678Z", + "shell.execute_reply": "2022-05-12T11:24:23.742878Z" }, "tags": [ "export" diff --git a/src/literary/transpile/syntax.ipynb b/src/literary/transpile/syntax.ipynb index 9a22fe2..d0d2773 100644 --- a/src/literary/transpile/syntax.ipynb +++ b/src/literary/transpile/syntax.ipynb @@ -14,30 +14,33 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "id": "eaa04dfe-1007-44a8-ad14-28f16f82f5c5", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.410609Z", + "iopub.status.busy": "2022-05-12T11:24:25.409682Z", + "iopub.status.idle": "2022-05-12T11:24:25.521757Z", + "shell.execute_reply": "2022-05-12T11:24:25.521025Z" + }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The literary.module extension is already loaded. To reload it, use:\n", - " %reload_ext literary.module\n" - ] - } - ], + "outputs": [], "source": [ "import pytest" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "id": "extended-national", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.525512Z", + "iopub.status.busy": "2022-05-12T11:24:25.524902Z", + "iopub.status.idle": "2022-05-12T11:24:25.528803Z", + "shell.execute_reply": "2022-05-12T11:24:25.528262Z" + }, "tags": [ "export" ] @@ -46,8 +49,8 @@ "source": [ "import ast\n", "import logging\n", - "import typing as tp\n", "import sys\n", + "import typing as tp\n", "\n", "from traitlets import Bool, Unicode\n", "from traitlets.config import Configurable" @@ -55,9 +58,15 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "id": "elect-event", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.531497Z", + "iopub.status.busy": "2022-05-12T11:24:25.531128Z", + "iopub.status.idle": "2022-05-12T11:24:25.534792Z", + "shell.execute_reply": "2022-05-12T11:24:25.534077Z" + }, "tags": [ "export" ] @@ -69,9 +78,15 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 4, "id": "opponent-bottle", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.539085Z", + "iopub.status.busy": "2022-05-12T11:24:25.538657Z", + "iopub.status.idle": "2022-05-12T11:24:25.542103Z", + "shell.execute_reply": "2022-05-12T11:24:25.541493Z" + }, "tags": [ "export" ] @@ -93,9 +108,15 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 5, "id": "1b9efeab-cf2b-4f7a-942f-4bf1b98e2609", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.545249Z", + "iopub.status.busy": "2022-05-12T11:24:25.544932Z", + "iopub.status.idle": "2022-05-12T11:24:25.550388Z", + "shell.execute_reply": "2022-05-12T11:24:25.549644Z" + }, "tags": [ "export" ] @@ -136,9 +157,15 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 6, "id": "18f5f1ef-d08c-48b4-af2b-5a91cef05882", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.553610Z", + "iopub.status.busy": "2022-05-12T11:24:25.553243Z", + "iopub.status.idle": "2022-05-12T11:24:25.556999Z", + "shell.execute_reply": "2022-05-12T11:24:25.556246Z" + }, "tags": [] }, "outputs": [], @@ -156,9 +183,15 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 7, "id": "e0aa5f2b-20e4-4ac3-ab6c-f9321315d9d3", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.559726Z", + "iopub.status.busy": "2022-05-12T11:24:25.559433Z", + "iopub.status.idle": "2022-05-12T11:24:25.569643Z", + "shell.execute_reply": "2022-05-12T11:24:25.568984Z" + }, "tags": [] }, "outputs": [ @@ -168,7 +201,7 @@ "\"x = y = f'hello {__name__}'\"" ] }, - "execution_count": 13, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -195,9 +228,15 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 8, "id": "swedish-denial", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.572773Z", + "iopub.status.busy": "2022-05-12T11:24:25.572321Z", + "iopub.status.idle": "2022-05-12T11:24:25.577951Z", + "shell.execute_reply": "2022-05-12T11:24:25.577408Z" + }, "tags": [ "export" ] @@ -247,9 +286,15 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 9, "id": "imperial-character", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.580508Z", + "iopub.status.busy": "2022-05-12T11:24:25.580128Z", + "iopub.status.idle": "2022-05-12T11:24:25.583995Z", + "shell.execute_reply": "2022-05-12T11:24:25.583345Z" + }, "tags": [] }, "outputs": [], @@ -267,9 +312,15 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 10, "id": "transsexual-chart", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.586884Z", + "iopub.status.busy": "2022-05-12T11:24:25.586483Z", + "iopub.status.idle": "2022-05-12T11:24:25.589799Z", + "shell.execute_reply": "2022-05-12T11:24:25.589190Z" + }, "tags": [] }, "outputs": [], @@ -287,24 +338,18 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 11, "id": "guided-planning", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.592406Z", + "iopub.status.busy": "2022-05-12T11:24:25.592075Z", + "iopub.status.idle": "2022-05-12T11:24:25.596038Z", + "shell.execute_reply": "2022-05-12T11:24:25.595352Z" + }, "tags": [] }, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'pytest' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/tmp/ipykernel_2975113/3262995093.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mpytest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mraises\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mValueError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mipython_transformer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvisit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'pytest' is not defined" - ] - } - ], + "outputs": [], "source": [ "with pytest.raises(ValueError):\n", " ipython_transformer.visit(node)" @@ -321,9 +366,15 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 12, "id": "indonesian-prior", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.599648Z", + "iopub.status.busy": "2022-05-12T11:24:25.599110Z", + "iopub.status.idle": "2022-05-12T11:24:25.608745Z", + "shell.execute_reply": "2022-05-12T11:24:25.608017Z" + }, "tags": [ "export" ] @@ -423,9 +474,15 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 13, "id": "rental-ladder", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.613590Z", + "iopub.status.busy": "2022-05-12T11:24:25.610946Z", + "iopub.status.idle": "2022-05-12T11:24:25.616792Z", + "shell.execute_reply": "2022-05-12T11:24:25.615986Z" + }, "tags": [] }, "outputs": [], @@ -435,9 +492,15 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 14, "id": "speaking-yellow", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.619567Z", + "iopub.status.busy": "2022-05-12T11:24:25.619097Z", + "iopub.status.idle": "2022-05-12T11:24:25.622197Z", + "shell.execute_reply": "2022-05-12T11:24:25.621610Z" + }, "tags": [] }, "outputs": [], @@ -460,9 +523,15 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 15, "id": "polyphonic-airfare", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.624779Z", + "iopub.status.busy": "2022-05-12T11:24:25.624209Z", + "iopub.status.idle": "2022-05-12T11:24:25.627990Z", + "shell.execute_reply": "2022-05-12T11:24:25.627425Z" + }, "tags": [] }, "outputs": [], @@ -472,9 +541,15 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 16, "id": "charitable-regular", "metadata": { + "execution": { + "iopub.execute_input": "2022-05-12T11:24:25.630562Z", + "iopub.status.busy": "2022-05-12T11:24:25.630097Z", + "iopub.status.idle": "2022-05-12T11:24:25.633940Z", + "shell.execute_reply": "2022-05-12T11:24:25.633396Z" + }, "tags": [] }, "outputs": [