sci: record file metadata on var
This commit is contained in:
parent
ef7a75be5b
commit
d1aaa97df6
4 changed files with 8 additions and 6 deletions
2
sci
2
sci
|
|
@ -1 +1 @@
|
||||||
Subproject commit 35ed8cced594f2733ca02d9b7c0b2e7a984adfb3
|
Subproject commit c84dbaa110cf01b56be38f58c5a7f14cc030f90d
|
||||||
|
|
@ -191,7 +191,7 @@ Everything after that is bound to *command-line-args*."))
|
||||||
(defn load-file* [sci-ctx f]
|
(defn load-file* [sci-ctx f]
|
||||||
(let [f (io/file f)
|
(let [f (io/file f)
|
||||||
s (slurp f)]
|
s (slurp f)]
|
||||||
(sci/with-bindings {vars/file-var (.getCanonicalPath f)}
|
(sci/with-bindings {vars/current-file (.getCanonicalPath f)}
|
||||||
(eval-string* sci-ctx s))))
|
(eval-string* sci-ctx s))))
|
||||||
|
|
||||||
(defn eval* [sci-ctx form]
|
(defn eval* [sci-ctx form]
|
||||||
|
|
@ -303,14 +303,13 @@ Everything after that is bound to *command-line-args*."))
|
||||||
(let [res (cp/source-for-namespace loader namespace nil)]
|
(let [res (cp/source-for-namespace loader namespace nil)]
|
||||||
(when uberscript (swap! uberscript-sources conj (:source res)))
|
(when uberscript (swap! uberscript-sources conj (:source res)))
|
||||||
res)))
|
res)))
|
||||||
_ (when file (vars/bindRoot vars/file-var (.getCanonicalPath (io/file file))))
|
_ (when file (vars/bindRoot vars/current-file (.getCanonicalPath (io/file file))))
|
||||||
ctx {:aliases aliases
|
ctx {:aliases aliases
|
||||||
:namespaces (-> namespaces
|
:namespaces (-> namespaces
|
||||||
(assoc 'clojure.core
|
(assoc 'clojure.core
|
||||||
(assoc core-extras
|
(assoc core-extras
|
||||||
'*command-line-args*
|
'*command-line-args*
|
||||||
(sci/new-dynamic-var '*command-line-args* command-line-args)
|
(sci/new-dynamic-var '*command-line-args* command-line-args)
|
||||||
'*file* vars/file-var
|
|
||||||
'*warn-on-reflection* reflection-var))
|
'*warn-on-reflection* reflection-var))
|
||||||
(assoc-in ['clojure.java.io 'resource]
|
(assoc-in ['clojure.java.io 'resource]
|
||||||
#(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true}))))
|
#(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true}))))
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,11 @@
|
||||||
(apply tu/bb (when (some? input) (str input)) (map str args)))
|
(apply tu/bb (when (some? input) (str input)) (map str args)))
|
||||||
|
|
||||||
(deftest file-var-test
|
(deftest file-var-test
|
||||||
(let [[f1 f2 f3]
|
(let [[f1 f2 f3 f4]
|
||||||
(str/split (bb nil "--classpath" "test/babashka/scripts"
|
(str/split (bb nil "--classpath" "test/babashka/scripts"
|
||||||
"test/babashka/scripts/file_var.bb")
|
"test/babashka/scripts/file_var.bb")
|
||||||
#"\n")]
|
#"\n")]
|
||||||
(is (str/ends-with? f1 "file_var_classpath.bb"))
|
(is (str/ends-with? f1 "file_var_classpath.bb"))
|
||||||
(is (str/ends-with? f2 "loaded_by_file_var.bb"))
|
(is (str/ends-with? f2 "loaded_by_file_var.bb"))
|
||||||
(is (str/ends-with? f3 "file_var.bb"))))
|
(is (str/ends-with? f3 "file_var.bb"))
|
||||||
|
(is (str/ends-with? f4 "file_var.bb"))))
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,5 @@
|
||||||
(require '[file-var-classpath])
|
(require '[file-var-classpath])
|
||||||
(load-file (io/file "test" "babashka" "scripts" "loaded_by_file_var.bb"))
|
(load-file (io/file "test" "babashka" "scripts" "loaded_by_file_var.bb"))
|
||||||
(println *file*)
|
(println *file*)
|
||||||
|
(defn foo [])
|
||||||
|
(println (:file (meta #'foo)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue