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

Add Binder, simplify hook #2

Merged
merged 7 commits into from
Feb 22, 2024
Merged
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
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