bash_kernel icon indicating copy to clipboard operation
bash_kernel copied to clipboard

including hml ?

Open parmentelat opened this issue 5 years ago • 12 comments

Hi

I am trying to write a tutorial notebook on git, and would like o find a way to somehow include some html/svg that depicts the current repo

coming from mostly python notebooks, I was expecting to find a way to inject some html, but realized this requires python, of course

how would you go about doing that ?

regardless, it's so cool to be able to write bash notebooks, thanks for putting this together :)

ps. i is a piy ha my keyboard can' seem o oupu t's oday ;)

parmentelat avatar Apr 29 '19 18:04 parmentelat

I don't think there's any way to display HTML from bash_kernel at present. I'd be open to some generalisation of the mechanism to display images, but I don't know what would be idiomatic for this kind of thing.

takluyver avatar Apr 29 '19 19:04 takluyver

I'm not sure either; it's hard to pick a character sequence that is not meaningful to bash already :)

my first thought was to refer to IPython's magics; but their regular magic syntax in % and %% seems out, as in bash it refers to jobs control (although my understanding of the current limitations is that job control may be out of reach in a notebook; but still)

although it is technically legal to have command names that include and even start with minuses, it seems unlikely that anyone in their own mind would write a command named -% or -%%; so maybe these 2 could be used to define magics ?

that would give us something like

 -%html <img src="foo.svg"> </img>

unless we'd rather expect the command stdout to be the html code

-%html-stdout echo '<img src="foo.svg"> </img>'

just thinking aloud here though; I'm not even sure the notion of magic is the right one, as in IPython this specific feature is exposed as an imported function..

parmentelat avatar Apr 30 '19 06:04 parmentelat

I wouldn't try to come up with new syntax for it - rather I'd expose a command, as is already done for images, so you could do e.g. jupyter-display --html. It could take a filename or even data piped on stdin.

takluyver avatar Apr 30 '19 07:04 takluyver

Yes and that was my suggestion too; but as I said I was trying to mimick the magics that IPython has; which probably, you’re right, is just an entirely different matter

Whichever way is fine by me :)

parmentelat avatar Apr 30 '19 07:04 parmentelat

Following up then, we could imagine convenience variants like —svg or —png so as to be able to pipe directly out of tools like dot

parmentelat avatar Apr 30 '19 07:04 parmentelat

Yup, I think if we had a generic way to display things, it should support all the formats commonly use in Jupyter. And it should probably also have a way to specify an arbitrary mime-type for less common formats.

takluyver avatar Apr 30 '19 07:04 takluyver

We have a version of a bash kernel in metakernel that supports the %%html magic if you'd like to use that instead, @parmentelat.

pip install git+git://github.com/calysto/metakernel.git#subdirectory=metakernel_bash
python -m metakernel_bash install --user

image

blink1073 avatar Apr 30 '19 09:04 blink1073

I was not aware of that, thanks for pointing it out
Is there any piece of background that can be relevant when deciding between these 2 ?
I'm mostly thinking in terms of maturity / support, of course

parmentelat avatar Apr 30 '19 12:04 parmentelat

We just hadn't gone through the trouble of making it a separate package or advertising it. We use it for unit tests primarily. However, its sibling kernels, that share a lot of the same logic, are quite mature and widely used. If there were demand, we could make it published package.

blink1073 avatar Apr 30 '19 12:04 blink1073

Ok thanks
I’ll start with using them alongside one another :)
I take it the same sort of limitation applies in terms of running interactive tools that expect stdin to be a terminal?

parmentelat avatar Apr 30 '19 13:04 parmentelat

That is correct, we are using the same underlying mechanism to communicate with bash.

blink1073 avatar May 01 '19 07:05 blink1073

@parmentelat, I completely forgot we had already created a separate bash kernel with magics. You can install it as pip install calysto_bash.

blink1073 avatar May 15 '19 10:05 blink1073

I missed the thread before because of the mispelling, so I never saw calysto_bash ...

But I did put together a PR to add support to HTML, if anyone is interested. It also include other goodies (progress-bar output support, a trivial environment variable to tell programs it is in a bash_kernel and it can output rich content, etc.)

https://github.com/takluyver/bash_kernel/pull/122

janpfeifer avatar Oct 22 '22 17:10 janpfeifer

implemented by @janpfeifer in #122

kdm9 avatar Dec 13 '22 07:12 kdm9