babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2021-05-26T04:44:21.180600Z

I moved to selmer instead for templating...it's amazingly quick with bb! 40 files in 150ms https://github.com/typedclojure/typedclojure/blob/fd7e00a134425e0ee6b13adbc418c0991dd97608/dev/src/typed/dev/selmer.clj#L77-L117 Totally changed my workflow, thanks @borkdude!

🎉 3
2021-05-26T10:50:47.181700Z

Is it possible to use a different encoding in slurp than utf-8?

lispyclouds 2021-05-26T10:56:19.182Z

(slurp "/path/to/file" :encoding "ISO-8859-1")

2021-05-26T11:18:35.182200Z

which means that my encoding is not included

lispyclouds 2021-05-26T11:19:21.182400Z

what are you trying with?

borkdude 2021-05-26T12:12:07.183800Z

Not sure if I mentioned it here already, but: Maybe you need just a little bit of CLJS in your babashka httpkit app and you don't want to set up a whole new CLJS project for it. Performance and bundle size may not be that important. Then scittle may be suited for you: https://borkdude.github.io/scittle/

❤️ 6
2021-05-26T12:19:39.184Z

"cp1250"

lispyclouds 2021-05-26T12:41:40.184300Z

Yeah can confirm bb raises the java.io.UnsupportedEncodingException with both cp1250 and Windows-1250 @borkdude any ideas?

borkdude 2021-05-26T12:43:38.184500Z

Seems we need to add -H:+AddAllCharsets, https://github.com/oracle/graal/issues/1370

borkdude 2021-05-26T12:44:34.184900Z

PR welcome in a branch. First let's see what it does to the binary size :)

lispyclouds 2021-05-26T16:18:14.185500Z

https://github.com/babashka/babashka/pull/868

cfleming 2021-05-26T21:16:33.187700Z

Is there any way to introspect the classes that are available to bb?

borkdude 2021-05-26T21:17:23.188100Z

@cfleming I can give you a full list as JSON, if that is useful?

borkdude 2021-05-26T21:17:59.188900Z

It's basically this list: https://github.com/babashka/babashka/releases/download/v0.4.3/babashka-0.4.3-reflection.json which is published at every release

cfleming 2021-05-26T21:18:00.189Z

Can that be obtained at runtime, or is that hardcoded somehow? I assume that classes are added to that from time to time?

borkdude 2021-05-26T21:19:10.189400Z

I'm not sure how to do this at runtime, how would you do that in Clojure?

borkdude 2021-05-26T21:19:37.190Z

The churn in classes isn't that high though, so it would probably be ok if you updated this every so often

cfleming 2021-05-26T21:20:09.190500Z

Ok, or I’ll download it from github based on the version of the bb runtime. Thanks!

cfleming 2021-05-26T21:20:53.191400Z

Having looked at it, it looks like all the namespaces available to the bb runtime are available immediately, i.e. I can see them being returned by all-ns. Is that correct?

borkdude 2021-05-26T21:21:06.191800Z

correct

borkdude 2021-05-26T21:21:30.192600Z

except for libraries from the "classpath"

borkdude 2021-05-26T21:21:47.193100Z

so all-ns does return all the built-in ones

cfleming 2021-05-26T21:21:57.193300Z

Great. I’m trying to figure out how to best support bb in Cursive, and the problem is the built-in libs. But if I can introspect those that will probably work well.

cfleming 2021-05-26T21:23:22.193900Z

Users will still have to mark specific files as being bb rather than normal Clojure in some way, but I think that’s ok.

lispyclouds 2021-05-26T21:23:39.194100Z

@huxley please have a look at the PR above, let us know of your use case, we can consider adding it 🙂

borkdude 2021-05-26T21:24:23.195200Z

yeah. babashka does have a bb.edn now which is similar to deps.edn but this isn't mandatory, so it's still useful to have an option to flag a file as "bb"

borkdude 2021-05-26T21:24:55.195500Z

for Clojure-LSP we have a similar problem: https://github.com/babashka/babashka/issues/733#issue-811939787

borkdude 2021-05-26T21:25:45.196300Z

so there currently we have a script to obtain the latest deps in babashka and lsp does analysis on those deps

cfleming 2021-05-26T21:25:48.196500Z

Ok so there you’re actually getting the deps.edn from github for the built-in deps, correct?

cfleming 2021-05-26T21:26:22.197300Z

Interesting, that might work well for Cursive too.

borkdude 2021-05-26T21:26:22.197400Z

correct. not sure how well it works, it hasn't seen a lot of usage yet I think, but that's the idea

2021-05-26T21:26:30.197500Z

thx!

cfleming 2021-05-26T21:26:52.197900Z

Is the deps.edn published as part of a release?

2021-05-26T21:26:54.198Z

I will check as soon as I have some time

cfleming 2021-05-26T21:27:16.198500Z

Hmm, looks like not.

borkdude 2021-05-26T21:27:22.198700Z

no, but we tag every release, so maybe that helps somehow

cfleming 2021-05-26T21:28:49.200100Z

Unfortunately https://raw.githubusercontent.com/babashka/babashka/blob/v0.4.3/deps.edn doesn’t work.

cfleming 2021-05-26T21:28:59.200400Z

I think for tags you have to know the sha

borkdude 2021-05-26T21:29:15.200800Z

This does work :) https://raw.githubusercontent.com/babashka/babashka/v0.4.3/deps.edn

cfleming 2021-05-26T21:29:35.201100Z

Yes, I just tried clicking the link 🙂

cfleming 2021-05-26T21:29:42.201400Z

Ok, great, that will help.

cfleming 2021-05-26T21:31:34.201700Z

I’ll try that and see how far I get, thanks.

đź‘Ť 1
borkdude 2021-05-26T21:33:41.203200Z

I suggested to ericdallo that bb could spit out a deps.edn-like structure with its built-in deps and also the deps and paths from bb.edn combined. Maybe that would help too, but he would rather see a complete classpath with all deps downloaded, which is basically what that script does. Feel free to post in that issue as well, if you have some new insights.

cfleming 2021-05-26T21:34:04.203500Z

I’ll read through it all after breakfast.

cfleming 2021-05-26T21:34:28.204Z

Is there only one bb.edn in the root of a project, normally?

borkdude 2021-05-26T21:34:55.204500Z

typically yes. but it's relatively new and not mandatory for say, single one-off scripts

borkdude 2021-05-26T21:46:21.205Z

I'm afk now as it's almost midnight here, have a great day

cfleming 2021-05-26T21:50:07.205200Z

Thanks for the help!

bherrmann 2021-05-26T22:08:45.207Z

Is there an xpath like thing for babashka? I'm trying to read the version of a pom file... I want to say something like short and sweet like

(xpath "...pom.xml" "/version[0]" ) 
but instead, I'm doing
(def pom-file  ".../pom.xml")
(def pom (xml/parse (io/input-stream pom-file)))
(def element-type (class pom)) ;; instanceof didnt like class literal
(def children-of-toplevel-pom (filter #(instance? element-type %) (:content pom)))
(def version-element (first (filter #(= "version" (name (:tag %))) children-of-toplevel-pom)))
(def current-version (first (:content version-element)))

borkdude 2021-05-26T22:11:06.207300Z

Maybe this example helps? https://github.com/babashka/babashka/blob/master/examples/pom_version_get.clj

bherrmann 2021-05-26T22:16:02.207800Z

That is way better.

borkdude 2021-05-26T22:19:03.208100Z

I think zippers could also help: https://ravi.pckl.me/short/functional-xml-editing-using-zippers-in-clojure/

isak 2021-05-26T22:51:19.208800Z

I think I had this problem before and solved it in like 5 lines of specter. Haven't tried it with babashka, though.

isak 2021-05-26T22:53:11.209Z

https://www.reddit.com/r/Clojure/comments/6tod7e/xmlin_your_friendly_xml_navigator/ See the first comment here (not mine)