Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added the start of building the kernel to override IPython #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ python3 setup.py install

## Quick Usage

### Install All 3rd Party Packages

```bash
pip install -e .
```

### Install Any Ape Plugins
Just an example, we install infura here

```bash
ape plugins install infura
```

### Create Your Ape Kernel
NOTE: This will be added to the CLI in the future

```bash
export WEB3_INFURA_PROJECT_ID=<your infura project ID>
ipython kernel install --name "ape" --user
```

### Start Up Your Notebook
```bash
ape notebook
```


## Development
Expand Down
14 changes: 12 additions & 2 deletions ape_notebook/_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import click
from notebook import notebookapp as app
import subprocess

from ape.cli import NetworkBoundCommand, ape_cli_context, network_option

@click.command(short_help="Run a notebook server")
def cli():

@click.command(
cls=NetworkBoundCommand,
short_help="Run a notebook server"
)
@network_option()
@ape_cli_context()
def cli(cli_ctx, network):
args = ["ipython", "kernel", "install", "--name", "ape", "--user"]
subprocess.run(args)
app.launch_new_instance()
29 changes: 29 additions & 0 deletions ape_notebook/apekernel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from ipykernel.kernelbase import Kernel


class ApeKernel(Kernel):
implementation = "Ape"
implementation_version = "1.0"
language = "no-op"
language_version = "0.1"


banner = "Echo kernel - as useful as a parrot"

def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
if not silent:
stream_content = {'name': 'stdout', 'text': code}
self.send_response(self.iopub_socket, 'stream', stream_content)

return {'status': 'ok',
# The base class increments the execution count
'execution_count': self.execution_count,
'payload': [],
'user_expressions': {},
}


if __name__ == '__main__':
from ipykernel.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=ApeKernel)
3 changes: 3 additions & 0 deletions ape_notebook/kernel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"argv":["python","-m","apekernel", "-f", "{connection_file}"],
"display_name":"Ape"
}
Loading