Skip to content

Commit

Permalink
Merged.
Browse files Browse the repository at this point in the history
  • Loading branch information
janpfeifer committed Jul 10, 2024
2 parents a92bb7d + f23c806 commit 95c158d
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 105 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ RUN apt-get install --yes --no-install-recommends git
#######################################################################################################
# Go and GoNB Libraries
#######################################################################################################
ENV GO_VERSION=1.22.2
ENV GONB_VERSION="v0.10.1"
ENV GO_VERSION=1.22.5
ENV GONB_VERSION="v0.10.2"
ENV GOROOT=/usr/local/go
ENV GOPATH=/opt/go
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

<img align="right" width="480px" src="https://repository-images.githubusercontent.com/599714179/38d0328a-abdb-4f69-9617-6ef136390708">

* **NEW**: Now supported by [Jupytext](https://github.com/mwouts/jupytext): it allows one to write the notebook as a normal.
Go file, and use [Jupytext](https://github.com/mwouts/jupytext) to convert to a notebook (with markdown support, etc).
See [example](https://github.com/mwouts/jupytext/issues/1244#issuecomment-2202097837).
* Auto-complete and contextual help while coding.
* Rich content display: HTML, markdown (with latex), images, javascript, svg, videos, etc.
* Widgets (sliders, buttons) support: interact using HTML elements. Create your own widgets!
Expand All @@ -26,6 +29,7 @@
start up, since each cell is compiled.
* Run cell's `Test*` and `Benchmark*` functions with `go test`, simply adding `%test` to cell.
* Support for `go.mod` and `go.work`, to allow local development. Including importing specific versions of libraries.
* Debug using [gdlv](https://github.com/aarzilli/gdlv), a GUI for the [delve](https://github.com/go-delve/delve) debugger (see %help).
* Shell command executions with `!` -- handy at times, for instance to install packages.
* Reported to work with Github Codespace, [VSCode](docs/VSCode.md), Binder, Google's Colab, etc.
* Very well documented and supported.
Expand Down
13 changes: 11 additions & 2 deletions cmd/nbexec/nbexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/proto"
"github.com/janpfeifer/gonb/common"
"github.com/janpfeifer/must"
Expand Down Expand Up @@ -267,9 +268,17 @@ func startJupyterNotebook() {
}

// Notebook instrumenting using go-rod.

func executeNotebook(url string, inputBoxes []string) {
page := rod.New().MustConnect().MustPage(url)
// Use system's Google Chrome is available, for sandboxing:
var controlURL string
chromePath, err := exec.LookPath("google-chrome")
if err == nil {
controlURL = launcher.New().Bin(chromePath).MustLaunch()
} else {
klog.Warningf("Using rod downloaded chromium, with --no-sandbox")
controlURL = launcher.New().NoSandbox(true).MustLaunch()
}
page := rod.New().ControlURL(controlURL).MustConnect().MustPage(url)
klog.V(1).Infof("Waiting for opening of page %q", url)
page.MustWaitStable()

Expand Down
28 changes: 28 additions & 0 deletions cmd/ndlv/ndlv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# ndlv is a wrapper script that executes gdlv, a delve GUI, from inside a gonb notebook.
# It will fail if not being executed by gonb, or if dlv and gdlv are not installed, or if no cell has
# yet been executed to be debugged.

if [[ "${GONB_TMP_DIR}" == "" ]] ; then
echo "No being executed from a gonb notebook cell, GONB_TMP_DIR not set." 1>&2
exit 1
fi
if [[ "$(which dlv)" == "" ]] ; then
echo "Can't find delve (dlv) debugger. See https://github.com/go-delve/delve/tree/master/Documentation/installation" 1>&2
exit 1
fi
if [[ "$(which gdlv)" == "" ]] ; then
echo "Can't find gdlv GUI for delve debugger. See https://github.com/aarzilli/gdlv" 1>&2
exit 1
fi

go_binary="$(basename "${GONB_TMP_DIR}")"
cd "${GONB_TMP_DIR}" || ( echo "Can't cd to GONB_TMP_DIR=${GONB_TMP_DIR}" ; exit 1 )

if [[ ! -e "${go_binary}" ]] ; then
echo "Cell binary is not available (${GONB_TMP_DIR}/${go_binary}) -- has cell already been executed ?" 1>&2
exit 1
fi

gdlv debug "${go_binary}"
14 changes: 13 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# GoNB Changelog

## Next
## 0.10.2, 2024/07/10 Added Jupytext support and `ndlv` script for debugging cells.

* [Jupytext](https://jupytext.readthedocs.io/en/latest/) integration [#120](https://github.com/janpfeifer/gonb/discussions/120):
* Many thanks for [Marc Wouts](github.com/mwouts) for [adding support in Jupytext](https://github.com/mwouts/jupytext/releases/tag/v1.16.3),
and @HaveF for the help and starting the topic.
* Handle special commands to be prefixed with `//gonb:` -- this allows special commands to be parseable Go code, and makes it easier for IDEs.
* Ignore `package` tag -- as opposed to raising an error: also to make easy on IDEs that may require a `package` tag.
* Added special variation: `%exec <function_name> <args...>` that creates a main function that calls `<function_name>`
and sets the program arguments (flags) to the given values.
* Added `ndlv` wrapper script for starting [gdlv](https://github.com/aarzilli/gdlv) on cell binary.
* Many thanks for @HaveF for the help -- see [#122](https://github.com/janpfeifer/gonb/discussions/122)
* Notebook testing: changed `nbexec` to use system's google-chrome if available (with sandbox), or let Rod download
chromium, but then use with --no-sandbox (since there is no SUID on the binaries).
* Fixed tracking to simply ignore loops, but not interrupt traversal during tracking.

## 0.10.1, 2024/04/14 Added support for Apache ECharts
Expand Down
23 changes: 12 additions & 11 deletions docs/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ github.com/janpfeifer/gonb/main.go SetUpKlog 66.7%
github.com/janpfeifer/gonb/cache/cache.go New 75.0%
github.com/janpfeifer/gonb/cache/cache.go AssertNoError 50.0%
github.com/janpfeifer/gonb/cache/cache.go MustNew 100.0%
github.com/janpfeifer/gonb/cache/cache.go NewInTmp 72.7%
github.com/janpfeifer/gonb/cache/cache.go NewInTmp 68.2%
github.com/janpfeifer/gonb/cache/cache.go MustNewInTmp 100.0%
github.com/janpfeifer/gonb/cache/cache.go NewHidden 80.0%
github.com/janpfeifer/gonb/cache/cache.go MustNewHidden 100.0%
Expand All @@ -28,7 +28,7 @@ github.com/janpfeifer/gonb/cache/cache.go CacheWith 91.7%
github.com/janpfeifer/gonb/cache/cache.go Cache 0.0%
github.com/janpfeifer/gonb/cmd/nbexec/nbexec.go main 72.2%
github.com/janpfeifer/gonb/cmd/nbexec/nbexec.go startJupyterNotebook 73.2%
github.com/janpfeifer/gonb/cmd/nbexec/nbexec.go executeNotebook 81.8%
github.com/janpfeifer/gonb/cmd/nbexec/nbexec.go executeNotebook 78.6%
github.com/janpfeifer/gonb/cmd/nbexec/nbexec.go checkForInputBoxes 95.7%
github.com/janpfeifer/gonb/common/common.go Panicf 0.0%
github.com/janpfeifer/gonb/common/common.go Pause 0.0%
Expand Down Expand Up @@ -165,9 +165,9 @@ github.com/janpfeifer/gonb/internal/comms/namedpipes.go *State.ProgramUnsubscr
github.com/janpfeifer/gonb/internal/comms/namedpipes.go *State.deliverProgramSubscriptionsLocked 62.5%
github.com/janpfeifer/gonb/internal/dispatcher/comms.go handleComms 55.6%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go RunKernel 80.0%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go handleShellMsg 71.0%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go handleShellMsg 78.4%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go handleBusyMessage 47.8%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go handleShutdownRequest 83.3%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go handleShutdownRequest 84.6%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go handleExecuteRequest 87.5%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go HandleInspectRequest 0.0%
github.com/janpfeifer/gonb/internal/dispatcher/dispatcher.go handleCompleteRequest 0.0%
Expand All @@ -185,7 +185,7 @@ github.com/janpfeifer/gonb/internal/goexec/composer.go *Declarations.RenderFun
github.com/janpfeifer/gonb/internal/goexec/composer.go *Declarations.RenderTypes 100.0%
github.com/janpfeifer/gonb/internal/goexec/composer.go *Declarations.RenderConstants 100.0%
github.com/janpfeifer/gonb/internal/goexec/composer.go *Constant.Render 100.0%
github.com/janpfeifer/gonb/internal/goexec/composer.go *State.createGoFileFromLines 85.7%
github.com/janpfeifer/gonb/internal/goexec/composer.go *State.createGoFileFromLines 81.8%
github.com/janpfeifer/gonb/internal/goexec/composer.go *State.createCodeFileFromDecls 58.8%
github.com/janpfeifer/gonb/internal/goexec/composer.go *State.createAlternativeFileFromDecls 0.0%
github.com/janpfeifer/gonb/internal/goexec/composer.go *State.createCodeFromDecls 71.9%
Expand Down Expand Up @@ -258,6 +258,7 @@ github.com/janpfeifer/gonb/internal/goexec/parser.go *State.readMainGo 77.8
github.com/janpfeifer/gonb/internal/goexec/parser.go *State.SetCellTests 100.0%
github.com/janpfeifer/gonb/internal/goexec/parser.go *State.DefaultCellTestArgs 100.0%
github.com/janpfeifer/gonb/internal/goexec/parser.go IsEmptyLines 77.8%
github.com/janpfeifer/gonb/internal/goexec/parser.go TrimGonbCommentPrefix 100.0%
github.com/janpfeifer/gonb/internal/goexec/tracking.go newTrackingInfo 100.0%
github.com/janpfeifer/gonb/internal/goexec/tracking.go *State.Track 100.0%
github.com/janpfeifer/gonb/internal/goexec/tracking.go *State.lockedTrack 54.8%
Expand Down Expand Up @@ -344,10 +345,10 @@ github.com/janpfeifer/gonb/internal/kernel/kernel.go *SyncSocket.RunLocked
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.IsStopped 66.7%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.StoppedChan 100.0%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.Stop 72.2%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.HandleInterrupt 88.2%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.HandleInterrupt 58.8%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.SubscribeInterrupt 80.0%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.UnsubscribeInterrupt 75.0%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.callInterruptSubscribers 42.9%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.CallInterruptSubscribers 42.9%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.ExitWait 100.0%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.Stdin 100.0%
github.com/janpfeifer/gonb/internal/kernel/kernel.go *Kernel.Shell 100.0%
Expand Down Expand Up @@ -395,7 +396,7 @@ github.com/janpfeifer/gonb/internal/nbtests/nbtests.go Sequence 63.2%
github.com/janpfeifer/gonb/internal/nbtests/nbtests.go OutputLine 100.0%
github.com/janpfeifer/gonb/internal/nbtests/nbtests.go InputLine 100.0%
github.com/janpfeifer/gonb/internal/specialcmd/cellmagic.go IsGoCell 0.0%
github.com/janpfeifer/gonb/internal/specialcmd/cellmagic.go ExecuteSpecialCell 80.0%
github.com/janpfeifer/gonb/internal/specialcmd/cellmagic.go ExecuteSpecialCell 81.0%
github.com/janpfeifer/gonb/internal/specialcmd/cellmagic.go cellCmdWritefile 87.5%
github.com/janpfeifer/gonb/internal/specialcmd/cellmagic.go writeLinesToFile 85.7%
github.com/janpfeifer/gonb/internal/specialcmd/cellmagic.go cellCmdScript 50.0%
Expand All @@ -404,9 +405,9 @@ github.com/janpfeifer/gonb/internal/specialcmd/definitions.go displayEnumeratio
github.com/janpfeifer/gonb/internal/specialcmd/definitions.go listDefinitions 100.0%
github.com/janpfeifer/gonb/internal/specialcmd/definitions.go removeDefinitionImpl 87.5%
github.com/janpfeifer/gonb/internal/specialcmd/definitions.go removeDefinitions 75.0%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go Parse 84.0%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go joinLine 85.7%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go execSpecialConfig 54.4%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go Parse 84.6%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go joinLine 87.5%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go execSpecialConfig 55.3%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go execShell 100.0%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go splitCmd 97.0%
github.com/janpfeifer/gonb/internal/specialcmd/track.go execTrack 27.3%
Expand Down
Binary file added docs/gopher_notebook.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions examples/tests/bash_script.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"/tmp/gonb_9dda40ab\n"
"/tmp/gonb_af538290\n"
]
}
],
Expand All @@ -59,7 +59,7 @@
"output_type": "stream",
"text": [
"/home/janpf/Projects/gonb/examples/tests\n",
"/tmp/gonb_9dda40ab\n",
"/tmp/gonb_af538290\n",
"/home/janpf/Projects/gonb\n",
"/home/janpf/Projects/gonb\n"
]
Expand All @@ -86,7 +86,7 @@
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.22.1"
"version": "go1.22.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/comms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.22.1"
"version": "go1.22.4"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions examples/tests/dom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
{
"data": {
"text/html": [
"<div id=\"dom.transient_div_86d0ec90\"></div>"
"<div id=\"dom.transient_div_88e9bcad\"></div>"
]
},
"metadata": {},
Expand Down Expand Up @@ -152,7 +152,7 @@
{
"data": {
"text/html": [
"<div id=\"dom.transient_div_9113427e\"></div>"
"<div id=\"dom.transient_div_33dbca98\"></div>"
]
},
"metadata": {},
Expand Down Expand Up @@ -197,7 +197,7 @@
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.22.0"
"version": "go1.22.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.22.0"
"version": "go1.22.4"
}
},
"nbformat": 4,
Expand Down
18 changes: 9 additions & 9 deletions examples/tests/goflags.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"gonb_bc1385f7/main.go:8:\tA\t\t100.0%\n",
"gonb_bc1385f7/main.go:12:\tB\t\t0.0%\n",
"gonb_bc1385f7/main.go:17:\tmain\t\t100.0%\n",
"gonb_17c43c9d/main.go:8:\tA\t\t100.0%\n",
"gonb_17c43c9d/main.go:12:\tB\t\t0.0%\n",
"gonb_17c43c9d/main.go:17:\tmain\t\t100.0%\n",
"total\t\t\t\t(statements)\t75.0%\n"
]
}
Expand Down Expand Up @@ -238,14 +238,14 @@
"name": "stderr",
"output_type": "stream",
"text": [
"# gonb_bc1385f7\n",
"# gonb_17c43c9d\n",
"./main.go:10:6: can inline (*Point).ManhattanLen\n",
"./main.go:16:12: inlining call to flag.Parse\n",
"./main.go:18:28: inlining call to (*Point).ManhattanLen\n",
"./main.go:18:13: inlining call to fmt.Println\n",
"./main.go:18:27: inlining call to (*Point).ManhattanLen\n",
"./main.go:18:12: inlining call to fmt.Println\n",
"./main.go:10:7: p does not escape\n",
"./main.go:18:13: ... argument does not escape\n",
"./main.go:18:28: ~r0 escapes to heap\n"
"./main.go:18:12: ... argument does not escape\n",
"./main.go:18:27: ~r0 escapes to heap\n"
]
}
],
Expand All @@ -267,7 +267,7 @@
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.22.0"
"version": "go1.22.4"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/gonbui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"output_type": "stream",
"text": [
"%goflags=[\"--cover\" \"--covermode=set\"]\n",
"GOCOVERDIR=/tmp/gonb_test_coverage.4mPvyGK2OJ\n"
"GOCOVERDIR=/tmp/gonb_test_coverage.9v84ceUYUN\n"
]
}
],
Expand Down Expand Up @@ -133,7 +133,7 @@
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.22.0"
"version": "go1.22.4"
}
},
"nbformat": 4,
Expand Down
18 changes: 9 additions & 9 deletions examples/tests/gotest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@
"text": [
"goos: linux\n",
"goarch: amd64\n",
"pkg: gonb_36f3efc5\n",
"cpu: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz\n",
"pkg: gonb_ce57b149\n",
"cpu: 12th Gen Intel(R) Core(TM) i9-12900K\n",
"BenchmarkFibonacciA32\n",
"BenchmarkFibonacciA32-8 \t 50\t 22759741 ns/op\n",
"BenchmarkFibonacciA32-24 \t 177\t 6414568 ns/op\n",
"BenchmarkFibonacciB32\n",
"BenchmarkFibonacciB32-8 \t28774705\t 39.85 ns/op\n",
"BenchmarkFibonacciB32-24 \t107397702\t 12.40 ns/op\n",
"PASS\n",
"coverage: [no statements]\n"
]
Expand Down Expand Up @@ -334,10 +334,10 @@
"text": [
"goos: linux\n",
"goarch: amd64\n",
"pkg: gonb_36f3efc5\n",
"cpu: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz\n",
"BenchmarkFibonacciA32-8 \t 52\t 22831751 ns/op\n",
"BenchmarkFibonacciB32-8 \t31159093\t 40.49 ns/op\n",
"pkg: gonb_ce57b149\n",
"cpu: 12th Gen Intel(R) Core(TM) i9-12900K\n",
"BenchmarkFibonacciA32-24 \t 174\t 6429990 ns/op\n",
"BenchmarkFibonacciB32-24 \t100000000\t 11.82 ns/op\n",
"PASS\n",
"coverage: [no statements]\n"
]
Expand All @@ -361,7 +361,7 @@
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.22.0"
"version": "go1.22.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 95c158d

Please sign in to comment.