babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
onetom 2021-03-10T11:31:58.092400Z

I'm trying to work on a babashka script using CIDER. I've manually added a src directory to the classpath. How can I reload changed namespaces which are defined under src? none of cider-load-file, cider-load-buffer, cider-ns-refresh, cider-ns-reload, cider-eval-ns-form seem to reload the ns.under.src.dir namespace.

(require '[babashka.classpath :refer [add-classpath]])
(add-classpath "src")

(ns user
  (:require [ns.under.src.dir]))

ns.under.src.dir/some-new-symbol

borkdude 2021-03-10T11:32:46.092900Z

(require ns.under.src.dir :reload)

onetom 2021-03-10T11:33:12.093400Z

sure, but that's not something u would want in production code, no?

borkdude 2021-03-10T11:33:24.093600Z

you can do this from the REPL

borkdude 2021-03-10T11:33:39.093800Z

or from a comment form

onetom 2021-03-10T11:34:07.094300Z

so currently i can only manually control reloading the dependent namespaces?

borkdude 2021-03-10T11:34:34.094500Z

do you have many dependents?

borkdude 2021-03-10T11:35:06.095100Z

in normal Clojure :reload-all also works, not sure if that is currently supported as well in babashka. this will cause all dependent namespaces to be reloaded

borkdude 2021-03-10T11:35:28.095400Z

Not hard to support but might not be supported yet

onetom 2021-03-10T11:38:23.097200Z

we don't have a lot of code yet, but some of the code is used from both babashka and jvm clojure. it's just confusing to have different workflows and different dependency specification conventions, depending on the execution environment. im not the only one on the team, so we would need to explain this to 4 other ppl too.

borkdude 2021-03-10T11:40:15.097700Z

feel free to create an issue about this, if this is something that can be improved in babashka(.nrepl)

1๐Ÿ‘
pez 2021-03-10T12:11:09.099100Z

No idea if this is babashka related, Admin can remove if it doesnโ€™t belong. ๐Ÿ˜ƒ

(.format (java.time.LocalDateTime/now)
         java.time.format.DateTimeFormatter/ISO_OFFSET_DATE_TIME)
=> clojure.lang.ExceptionInfo: Unsupported field: OffsetSeconds

2021-03-10T12:18:03.099200Z

not bb problem ๐Ÿ˜‰

1โค๏ธ
2021-03-10T12:19:38.099400Z

same would happen on jvm, but that format would work for e.g. `(.format (java.time.OffsetDateTime/now) java.time.format.DateTimeFormatter/ISO_OFFSET_DATE_TIME)`

2021-03-10T12:20:13.099600Z

or a ZonedDateTime

2021-03-10T12:20:22.099800Z

just those two afaik

pez 2021-03-10T12:22:56.100100Z

I should have tried on JVM, but was in hurry. Thanks for helping me anyway!

2021-03-10T12:25:40.100300Z

:thumbsup:

lukasz 2021-03-10T15:01:26.101300Z

My Google-foo is failing me - does bb include nrepl client? I know that there's a server implementation, but I can't find any reliable info about client support. I'd like to replace lein repl :connect ... with bb in some way.

borkdude 2021-03-10T15:02:58.101900Z

@lukaszkorecki There is not a client, but there is a library which allows you to implement a basic one fairly quicky. https://book.babashka.org/#_interacting_with_an_nrepl_server

borkdude 2021-03-10T15:03:09.102300Z

I am using the above in CI to execute commands against production ;)

borkdude 2021-03-10T15:04:11.102900Z

I do have a natively compiled version of reply too, but this is just an experimental project.

lukasz 2021-03-10T15:04:14.103Z

securely, I hope ๐Ÿ˜‰

lukasz 2021-03-10T15:04:29.103200Z

Gotcha, let me check out the book link

borkdude 2021-03-10T15:04:55.103900Z

yes, securely, it's within the same network let's say

borkdude 2021-03-10T15:05:11.104500Z

and this script can be kicked off from TeamCity (CI)

lukasz 2021-03-10T15:05:53.105400Z

Good! I'm prepping us for a security audit, so I'm a bit too paranoid these days. Re nrepl - most of the times we need to run a single command, but in some cases we need a full on connection to debug something in the live system, so I want to standarize our tooling and reduce its footprint (pulling a whole docker image with lein for this works, but is.... excessive)

borkdude 2021-03-10T15:07:08.105800Z

I will invite you to my native reply repo as well, just in case

borkdude 2021-03-10T15:08:21.106Z

You should have an invite now

borkdude 2021-03-10T15:08:55.106300Z

I think adding a basic nrepl client to babashka itself might be nice

borkdude 2021-03-10T15:09:04.106500Z

for this purpose

borkdude 2021-03-10T15:09:43.107100Z

but I guess you could also connect to the production repl from your local emacs / other via an ssh tunnel?

lukasz 2021-03-10T15:18:28.107600Z

Technically yes, in practice - the company policy prohibits that (did I mention audits?)

lukasz 2021-03-10T15:18:52.108Z

Just got the invite, thanks!

borkdude 2021-03-10T15:19:09.108500Z

yes. so the same developer can have access to this prisoned nREPL client box somewhere else? how is that more secure?

lukasz 2021-03-10T15:20:10.109500Z

You have to jump through a couple of hoops to get to the machines which can start nrepl sessions. Now that I think about it - connecting from your local computer wouldn't work because we cannot open reverse tunnels in the first place.

lukasz 2021-03-10T15:20:33.109800Z

(All of that is protected via AWS IAM and a bunch of other things)

borkdude 2021-03-10T15:21:23.110400Z

ok. I am open to adding a basic nREPL client to bb if this would help.

borkdude 2021-03-10T15:21:55.111400Z

assuming bb doesn't have to carry a ton of extra deps for this, it will be more like the above script, but better executed and built in

lukasz 2021-03-10T15:23:03.112500Z

Let me check out reply-cli - if it can do both interactive sessions and one-off evaluations it might be better than bundling the client with bb

borkdude 2021-03-10T15:23:17.112800Z

ok

borkdude 2021-03-10T15:23:37.113300Z

I haven't published reply-cli publically because I hacked the code as quickly as I could to a working state

lukasz 2021-03-10T15:23:45.113600Z

Makes sense!

borkdude 2021-03-10T15:23:53.113900Z

most notably I changed futures into delays in the completion code

borkdude 2021-03-10T15:24:12.114200Z

because spawning futures at compile time isn't something GraalVM likes

lukasz 2021-03-10T15:28:18.114700Z

I'll check it out and report back :thumbsup:

borkdude 2021-03-10T16:11:13.115700Z

A new version of sql pods is out. This release adds better support for inserting and retrieving arrays. https://github.com/babashka/babashka-sql-pods/blob/master/CHANGELOG.md#v003 Babashka sql pods allow you to interact with databases like PostgreSQL, Oracle and MS SQL

2021-03-10T16:18:02.116400Z

What is a pod in the babashka context?

borkdude 2021-03-10T16:19:12.116900Z

@anders152 Pods are binaries that expose library functionality to babashka via RPC

borkdude 2021-03-10T16:19:37.117300Z

It is like shelling out but more integrated, so you can just do function calls without having to do de/serialization yourself

borkdude 2021-03-10T16:20:09.117700Z

See https://github.com/babashka/pod-registry for a list of available pods and examples

2021-03-10T16:39:32.118600Z

Interesting concept! How did you land on this type of design?

borkdude 2021-03-10T16:45:40.121400Z

I want to be able to add features to babashka without bloating the binary too much with stuff that isn't used widely. You can either do this via libraries (I might implement the nREPL idea using a library instead), but bb libraries have the limitation that you can not access Java classes that aren't available in the bb image. You can also shell out to other binaries via clojure.java.shell or babashka.process, which works well, but is sometimes cumbersome. Also I had some ideas about FFI but this is not very extensible from the Java side (yet). So babashka pods are a kind of higher level FFI (with more overhead, e.g. we serialize args via json or transit, RPC-style) but it works well and performance is generally fast enough for scripting tasks.

NoahTheDuke 2021-03-10T16:54:00.121900Z

is it possible to use pods in clojure code? or are they bb only?

NoahTheDuke 2021-03-10T16:54:06.122100Z

i really like bb/fs

borkdude 2021-03-10T16:56:57.122600Z

bb/fs is not a pod, but just a library. you can use that in Clojure as well. But pods are also runnable in Clojure using the pods library (https://github.com/babashka/pods)

2๐ŸŽ‰
NoahTheDuke 2021-03-10T17:01:25.123500Z

thank you!

2021-03-10T17:12:50.124800Z

Thanks a lot for the explanation @borkdude! As always Clojure culture seems to favour real-world pragmatism. I love it!

grazfather 2021-03-10T17:18:05.125200Z

I found this one easy to read and understand (though thatโ€™s probably because I mostly write Go) https://github.com/babashka/pod-babashka-go-sqlite3/blob/main/main.go

grazfather 2021-03-10T17:18:43.125700Z

very simple: Read from stdin, process the message, switch on the Op

wilkerlucio 2021-03-10T23:48:59.126900Z

22
borkdude 2021-03-11T11:30:14.127400Z

Cool! Although https://github.com/borkdude/sci/issues/549 made me wonder if we should continue supporting this as is, or that we should only support some pre-selected combination of interfaces. Which will then break if we add one more interface to it. ๐Ÿคฆ I'm starting to think it would be safer to not support reify at all anymore... :(