scicloj / notespace

using your namespace as a notebook
Eclipse Public License 2.0
148 stars 10 forks source link

use render-current-state via code creates html with failiing images #40

Open behrica opened 3 years ago

behrica commented 3 years ago

Running this evaluates the notespace and generates html, but the plots fail with

(ns notespace.cli
  (:require [notespace.actions :as actions]
            [notespace.api :as api]
            [gorilla-notes.core :as gn]
            [notespace.kinds :as k]
            )
  )
(require '[notespace.v3-experiment1-test])
(defn eval-and-realize-a-notespace []
  (let  [anamespace (find-ns 'notespace.v3-experiment1-test)
         ]
    (api/init)
    (actions/act-on-notes! anamespace [actions/eval-note!])
    (gn/render-current-state! "/tmp/out.html")
    )

    (System/exit 0)
  )
behrica commented 3 years ago

Thre is somethinh weired going on. The above code only produces the non-working html, while started from leiningen:

lein exec -ep "(use 'notespace.cli)(eval-and-realize-a-notespace \"notespace.v3-experiment1-test\")"

Running the same in repl works:

 (require '[notespace.actions :as actions]
           '[notespace.api :as api]
           '[gorilla-notes.core :as gn]
           '[notespace.kinds :as k]
           )

  (require '[notespace.v3-experiment1-test])
  (let  [anamespace (find-ns 'notespace.v3-experiment1-test)
         ]
    (api/init)
    (actions/act-on-notes! anamespace [actions/eval-note!])
    (gn/render-current-state! "/tmp/out.html")
    )
behrica commented 3 years ago

I diffed the produced html, and it differs in size. But I could not really see anything in the diff, due to huge lines.

behrica commented 3 years ago

I think the "leiningen" run code does not interpret the kind metadata. All notes gets rendered as native:

image

vs.

image

I have not seen this before, only the missing plots were obvious.

daslu commented 3 years ago

Interesting.

It looks like the problem with the first time is that it renders the code when it is not supposed to render. The markdown-rendered output ("text: ...") seems to appear in both cases. Right?

behrica commented 3 years ago

I don't know, my screenshot wa maybe not good... The most visible issue is this:

image

And there is no plot

behrica commented 3 years ago

I tried to a lot of variations of the code, with "sleeps and prints" eveywhere, and the only working workaround is to run evaluation twice:

(require '[notespace.v3-experiment1-test])
(defn eval-and-realize-a-notespace [& args]
  (let  [anamespace (find-ns 'notespace.v3-experiment1-test)]
    (api/init)
    (actions/act-on-notes! anamespace [actions/eval-note!])
    (actions/act-on-notes! anamespace [actions/eval-note!])
    (gn/render-current-state! "/tmp/out.html") )
   (System/exit 0) )

This works reliably.

behrica commented 3 years ago

This test case is even better, as it produces 2 different html files, one bad, one good:

(let  [anamespace (find-ns 'notespace.v3-experiment1-test)]
    (api/init)
    (actions/act-on-notes! anamespace [actions/eval-note!])
    (gn/render-current-state! "/tmp/out_bad.html")
    (actions/act-on-notes! anamespace [actions/eval-note!])
    (gn/render-current-state! "/tmp/out_good.html")
    )