babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
kwrooijen 2020-12-05T12:17:21.093900Z

Any way to get the contents of a jar in bb?

borkdude 2020-12-05T12:19:01.094300Z

@kevin.van.rooijen yes, look at examples/ls_jar.clj

👍 1
kwrooijen 2020-12-05T12:19:24.094500Z

Amazing

kwrooijen 2020-12-05T12:24:32.094700Z

Works as a little sun. Thanks

👍 1
kwrooijen 2020-12-05T13:35:06.095600Z

I could use edamame.core/parse-string in bb. Any chance we can include this in the clojure.edn NS? Or is there another way to include this?

kwrooijen 2020-12-05T13:35:33.096100Z

Currently tripping over the #() reader with clojure.edn. Which was fixed in edamame

borkdude 2020-12-05T13:35:50.096500Z

@kevin.van.rooijen you can use read-string in bb as well

borkdude 2020-12-05T13:35:59.096700Z

which is basically edamame

borkdude 2020-12-05T13:36:32.096900Z

$ bb -e '(read-string "#()")'
(fn* [] ())

kwrooijen 2020-12-05T13:36:54.097100Z

Let me try that 🙂

kwrooijen 2020-12-05T13:39:46.097300Z

hmm

kwrooijen 2020-12-05T13:39:49.097500Z

clojure.lang.ExceptionInfo: Read-eval not allowed. Use the :read-eval` option`

kwrooijen 2020-12-05T13:40:34.097900Z

but read-string in bb doesn't accept 3 args?

kwrooijen 2020-12-05T13:40:46.098100Z

*read-eval* is also undefined

borkdude 2020-12-05T13:41:40.099Z

currently read-string is a bit under-developed. but read-eval is turned off by default in edamame

borkdude 2020-12-05T13:41:57.099500Z

you could post an issue about what you expect to work, but I expect read-string to be safe by default in bb currently

kwrooijen 2020-12-05T13:42:04.099700Z

Yeah I don't actually want to eval anything. I just want the form

kwrooijen 2020-12-05T13:45:09.100200Z

I guess it makes sense for this to crash (read-string "#=(+ 1 2 3))")

kwrooijen 2020-12-05T13:46:02.100800Z

Actually I think I'd expect (eval '(+ 1 2 3))

borkdude 2020-12-05T13:47:48.101700Z

edamame currently doesn't even support this, nobody has ever asked for this before. edamame just returns (read-eval (+ 1 2 3)) when you pass :read-eval true but doesn't have a callback for evaluating it, which we of course can include

borkdude 2020-12-05T13:48:25.102100Z

so currently bb crashes when you try to do this

borkdude 2020-12-05T13:49:10.102500Z

So maybe the sane behavior would be to do it exactly as clojure. PR welcome

borkdude 2020-12-05T13:49:39.103Z

1) The first step would be to fix edamame to support a read-eval function which gets the expression and then can eval it

borkdude 2020-12-05T13:50:43.104300Z

2) Fix read-string in bb or sci (not sure where it is currently). I think in the case of sci it could make sense to disallow it by default unless someone passes a setting. In bb we can enable this setting by default.

borkdude 2020-12-05T13:51:07.104500Z

Does it hurt anyone if we allow it in sci by default?

borkdude 2020-12-05T13:51:10.104700Z

security-wise

borkdude 2020-12-05T13:51:20.104900Z

you're evaluating already anyway, so maybe not

kwrooijen 2020-12-05T13:52:31.105Z

For my use case I don't actually want anything evalled though

borkdude 2020-12-05T13:52:52.105300Z

Yes, so you can set *read-eval* to false, like in clj.

borkdude 2020-12-05T13:53:04.105600Z

3) Include *read-eval* in sci

kwrooijen 2020-12-05T13:53:27.105900Z

But doesn't it just crash, like in clj? https://clojuredocs.org/clojure.core/*read-eval*#example-542692d1c026201cdc326f3a

borkdude 2020-12-05T13:54:10.106200Z

yes. so you want to parse code which contains it but not eval it? why?

kwrooijen 2020-12-05T13:55:22.106800Z

Currently I just want to get all the functions in a namespace, without having to require it

kwrooijen 2020-12-05T13:55:32.107Z

Not sure if edamame has any magic for that

borkdude 2020-12-05T13:55:53.107200Z

you are parsing defn etc manually?

borkdude 2020-12-05T13:57:22.107600Z

I think clj-kondo is a much better tool for this.

$ clj-kondo --config '{:output {:analysis true :format :edn}}' --lint - <<< '(defn foo [])' | puget
{:analysis {:namespace-definitions [],
            :namespace-usages [],
            :var-definitions [{:col 1,
                               :filename "<stdin>",
                               :fixed-arities #{0},
                               :name foo,
                               :ns user,
                               :row 1}],
            :var-usages [{:arity 2,
                          :col 2,
                          :filename "<stdin>",
                          :from user,
                          :macro true,
                          :name defn,
                          :row 1,
                          :to clojure.core,
                          :varargs-min-arity 2}]},
 :findings [],
 :summary {:duration 35,
           :error 0,
           :files 1,
           :info 0,
           :type :summary,
           :warning 0}}

kwrooijen 2020-12-05T13:57:45.107800Z

Ahh, that might be exactly what I need

borkdude 2020-12-05T13:58:02.108100Z

you can use clj-kondo as a babashka pod as well, for scripting

borkdude 2020-12-05T13:58:33.108300Z

https://github.com/borkdude/clj-kondo/#babashka-pod

kwrooijen 2020-12-05T13:59:53.108500Z

Very cool, I'll try that. Thanks

borkdude 2020-12-05T14:22:33.109Z

@kevin.van.rooijen if you're using this from emacs, you might also want to look at anakondo: https://github.com/didibus/anakondo

kwrooijen 2020-12-05T14:25:28.109400Z

oh wow

kwrooijen 2020-12-05T14:25:38.109600Z

I did not know about this

2020-12-05T15:45:46.109900Z

https://twitter.com/MMz_/status/1335248650193285120

😎 1
kwrooijen 2020-12-05T17:29:53.110900Z

Private functions can't be called in bb? Trying to figure out what this function results in (#'babashka.curl/curl-command {})

borkdude 2020-12-05T17:33:54.111500Z

that function just isn't exposed in the bb sci config (if you have watched the internals talk, you will know what I mean)

borkdude 2020-12-05T17:34:19.111900Z

but if you run babashka.curl from source, you should be able to do that

kwrooijen 2020-12-05T17:34:19.112Z

Haven't watched that yet 😛

kwrooijen 2020-12-05T17:34:29.112200Z

Yeah I'll just clone it

kwrooijen 2020-12-05T17:34:45.112800Z

Trying to pass in a cookie but not sure how / if it's possible

borkdude 2020-12-05T17:35:00.113200Z

@kevin.van.rooijen if you want to see the command, you can also do (:command (curl/get "foobar" {:debug true}))

borkdude 2020-12-05T17:35:48.113400Z

$ bb -e "(:command (curl/get \"<https://babashka.org>\" {:debug true}))"
["curl" "--silent" "--show-error" "--location" "--dump-header" "/var/folders/2m/h3cvrr1x4296p315vbk7m32c0000gp/T/babashka.curl8448783184890828476.headers" "--compressed" "<https://babashka.org>"]

borkdude 2020-12-05T17:35:55.113700Z

Cookies are passed using :headers

borkdude 2020-12-05T17:36:00.113900Z

they are just that

kwrooijen 2020-12-05T17:40:28.114200Z

Ahh ok, I assumed I have to use the --cookie arg in curl

borkdude 2020-12-05T17:42:33.114800Z

That might be better, I haven't used it that way yet. But Cookie is just an HTTP header, so something like this should also work:

$ bb -e '(org.httpkit.server/run-server (fn [req] (clojure.pprint/pprint req) {:body "hello"}) {:port 3000}) (curl/post "<http://localhost:3000>" {:headers {"Cookie" "name=dude; foo=bar"}}) nil'
{:remote-addr "0:0:0:0:0:0:0:1",
 :headers
 {"accept" "*/*",
  "accept-encoding" "deflate, gzip",
  "cookie" "name=dude; foo=bar",
  "host" "localhost:3000",

👍 1