diff --git a/deps.edn b/deps.edn index 18c47fe..60a9e5e 100644 --- a/deps.edn +++ b/deps.edn @@ -3,7 +3,8 @@ :aliases {:sci {:extra-deps - {borkdude/sci {:mvn/version "0.0.13-alpha.27"}}} + {borkdude/sci {:git/url "https://github.com/borkdude/sci" + :sha "a7f8d05f08ab150621c2403dacdd57c47ea09ff4"}}} :test {:extra-deps {test-runner diff --git a/src/babashka/pods/impl.clj b/src/babashka/pods/impl.clj index ae34f41..116c3ef 100644 --- a/src/babashka/pods/impl.clj +++ b/src/babashka/pods/impl.clj @@ -119,9 +119,11 @@ read-fn) {})]) namespace (when-let [v (get reply "vars")] - (let [name (-> (get reply "name") - bytes->string)] - {:name name :vars (bencode->vars pod name v)})) + (let [name-str (-> (get reply "name") + bytes->string) + name (symbol name-str)] + {:name name + :vars (bencode->vars pod name-str v)})) chan (get @chans id) promise? (instance? clojure.lang.IPending chan) exception (when (and promise? error?) diff --git a/src/babashka/pods/sci.clj b/src/babashka/pods/sci.clj index b9ab964..2aec82d 100644 --- a/src/babashka/pods/sci.clj +++ b/src/babashka/pods/sci.clj @@ -7,6 +7,10 @@ ns-name name sci-ns (sci/create-ns (symbol ns-name))] (sci/binding [sci/ns sci-ns] + ;; ensure ns map in ctx, see #20 + (swap! env update-in [:namespaces ns-name] + (fn [ns-map] + (if ns-map ns-map {:obj sci-ns}))) (doseq [[var-name var-value] vars] (cond (ifn? var-value) (swap! env assoc-in [:namespaces ns-name var-name] diff --git a/test-pod/pod/test_pod.clj b/test-pod/pod/test_pod.clj index 56583bd..219cc86 100644 --- a/test-pod/pod/test_pod.clj +++ b/test-pod/pod/test_pod.clj @@ -86,7 +86,10 @@ {"name" "pod.test-pod.loaded" "defer" "true"} {"name" "pod.test-pod.loaded2" - "defer" "true"}] + "defer" "true"} + {"name" "pod.test-pod.only-code" + "vars" [{"name" "foo" + "code" "(defn foo [] 1)"}]}] "ops" {"shutdown" {}}}) (recur)) :invoke (let [var (-> (get message "var") diff --git a/test-resources/test_program.clj b/test-resources/test_program.clj index f25bfcd..3ed37db 100644 --- a/test-resources/test_program.clj +++ b/test-resources/test_program.clj @@ -48,6 +48,9 @@ (def fn-called (pod.test-pod/fn-call inc 2)) +(require '[pod.test-pod.only-code :as only-code]) +(def should-be-1 (only-code/foo)) + (require '[pod.test-pod.loaded2 :as loaded2]) (def loaded (loaded2/loaded 1)) @@ -70,4 +73,5 @@ tagged other-tagged loaded - fn-called] + fn-called + should-be-1] diff --git a/test/babashka/pods/test_common.clj b/test/babashka/pods/test_common.clj index f5eabad..1a28e32 100644 --- a/test/babashka/pods/test_common.clj +++ b/test/babashka/pods/test_common.clj @@ -22,7 +22,8 @@ [1 2 3] [[1] [1]] 2 - 3] + 3 + 1] (concat ret (repeat ::nil)))] (if (instance? java.util.regex.Pattern expected) (is (re-find expected actual))