Skip to content

Commit

Permalink
Add Binder, simplify hook (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski authored Feb 22, 2024
1 parent 21b0a76 commit 4ea67a6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# ipython-markdown-inspector

[![tests](https://github.com/krassowski/ipython-markdown-inspector/workflows/tests/badge.svg)](https://github.com/krassowski/ipython-markdown-inspector/actions?query=workflow%3A%22tests%22)
[![tests](https://github.com/krassowski/ipython-markdown-inspector/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/krassowski/ipython-markdown-inspector/actions/workflows/tests.yml)
![CodeQL](https://github.com/krassowski/ipython-markdown-inspector/workflows/CodeQL/badge.svg)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/krassowski/ipython-markdown-inspector/main?urlpath=lab)
[![pypi-version](https://img.shields.io/pypi/v/ipython-markdown-inspector.svg)](https://python.org/pypi/ipython-markdown-inspector)

IPython extension providing inspection results as Markdown, enabling better integration with Jupyter Notebook and JupyterLab.
Expand Down
18 changes: 18 additions & 0 deletions binder/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ipython-markdown-inspector

channels:
- conda-forge
- nodefaults

dependencies:
- python =3.10
- pip
- jupyterlab >=4.1
- hatchling >=1.5.0
- ipykernel >=6.29
- notebook >=7.1
- jupyter_server >=2.12
- wheel
- build
- ipython >=8.22
- traitlets >=5.14.1
1 change: 1 addition & 0 deletions binder/ipython_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c.InteractiveShellApp.extensions = ["ipython_markdown_inspector"] # noqa: F821
8 changes: 8 additions & 0 deletions binder/postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

source activate ${NB_PYTHON_PREFIX}

pip install -v -e . --no-build-isolation

mkdir -p ~/.ipython/profile_default/
cp binder/ipython_config.py ~/.ipython/profile_default/
12 changes: 1 addition & 11 deletions ipython_markdown_inspector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
from functools import partial
from typing import List

from IPython.core.interactiveshell import InteractiveShell
from IPython.core.oinspect import InspectorHookData

from .formatter import as_markdown


def hook(
data: InspectorHookData,
*_,
ipython: InteractiveShell,
) -> str:
return as_markdown(data)


ORIGINAL_HOOK = None


def load_ipython_extension(ipython: InteractiveShell):
global ORIGINAL_HOOK
ORIGINAL_HOOK = ipython.inspector.mime_hooks.get("text/markdown", None)
ipython.inspector.mime_hooks["text/markdown"] = partial(hook, ipython=ipython)
ipython.inspector.mime_hooks["text/markdown"] = as_markdown


def unload_ipython_extension(ipython: InteractiveShell):
Expand Down

0 comments on commit 4ea67a6

Please sign in to comment.