Fork me on GitHub
#babashka
<
2021-03-10
>
onetom11:03:58

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

borkdude11:03:46

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

onetom11:03:12

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

borkdude11:03:24

you can do this from the REPL

borkdude11:03:39

or from a comment form

onetom11:03:07

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

borkdude11:03:34

do you have many dependents?

borkdude11:03:06

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

borkdude11:03:28

Not hard to support but might not be supported yet

onetom11:03:23

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.

borkdude11:03:15

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

👍 3
pez12:03:09

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

henryw37412:03:03

not bb problem 😉

❤️ 3
henryw37412:03:38

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)`

henryw37412:03:13

or a ZonedDateTime

henryw37412:03:22

just those two afaik

pez12:03:56

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

lukasz15:03:26

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.

borkdude15:03:58

@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

borkdude15:03:09

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

borkdude15:03:11

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

lukasz15:03:14

securely, I hope 😉

lukasz15:03:29

Gotcha, let me check out the book link

borkdude15:03:55

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

borkdude15:03:11

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

lukasz15:03:53

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)

borkdude15:03:08

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

borkdude15:03:21

You should have an invite now

borkdude15:03:55

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

borkdude15:03:04

for this purpose

borkdude15:03:43

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

lukasz15:03:28

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

lukasz15:03:52

Just got the invite, thanks!

borkdude15:03:09

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

lukasz15:03:10

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.

lukasz15:03:33

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

borkdude15:03:23

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

borkdude15:03:55

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

lukasz15:03:03

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

borkdude15:03:37

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

lukasz15:03:45

Makes sense!

borkdude15:03:53

most notably I changed futures into delays in the completion code

borkdude15:03:12

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

lukasz15:03:18

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

borkdude16:03:13

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

andarp16:03:02

What is a pod in the babashka context?

borkdude16:03:12

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

borkdude16:03:37

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

borkdude16:03:09

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

andarp16:03:32

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

borkdude16:03:40

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.

Noah Bogart16:03:00

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

Noah Bogart16:03:06

i really like bb/fs

borkdude16:03:57

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)

🎉 6
andarp17:03:50

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

grazfather17:03:05

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

grazfather17:03:43

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

borkdude11:03:14

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. facepalm I'm starting to think it would be safer to not support reify at all anymore... :(