Fork me on GitHub
#babashka
<
2023-01-04
>
grav07:01:19

Hi! Any reason why clojure.data.json isn't included in Babashka?

tatut07:01:02

cheshire is, you can parse JSON with that

grav07:01:24

👍 Was just about to guess that 🙂

grav07:01:24

What determines what goes in to Babashka? In the case of clojure.data.json, it "sounds" more standard than cheshire, but maybe the usage isn't high enough to warrent including it?

borkdude08:01:34

3 years ago Cheshire was imo still the dominant JSON library which, by including it, enabled running a plethora of libraries from source. Meanwhile data.json caught up in performance, three years ago it was relatively much slower. You can add data.json to bb in bb.edn - it works from source but because it’s interpreted, it’s not fast to parse a megabyte of JSON. In the future, if data.json might become the defacto JSON lib, perhaps it’s a good idea to include it.

grav08:01:13

Cool, thanks for the explanation @borkdude

borkdude09:01:38

I have considered offering an API to which libraries can program, rather than a specific JSON library so this implementation can be abstracted away, https://github.com/clj-easy/tools.misc

👍 2
Alexander Kaiser11:01:51

Hello, am i doing something wrong? I cannot use malli in babashka.

(ns bb-malli
  (:require [babashka.deps :as deps]))

(deps/add-deps '{:deps {metosin/malli {:mvn/version "0.9.0"}}})
(require '[malli.core :as malli])
clojure.lang.ExceptionInfo: Can't set!: clojure.core/*unchecked-math* from non-binding thread
{:type :sci/error, :line 4, :column 3, :message "Can't set!: clojure.core/*unchecked-math* from non-binding thread", :sci.impl/callstack #object[clojure.lang.Volatile 0x1a52cc09 {:status :ready, :val ({:line 1, :column 1, :file "/home/alex/workspace/bb/malli_test.clj", :ns #object[sci.lang.Namespace 0x4e4be0f8 "bb-malli"]} {:line 4, :column 3, :file "malli/core.cljc", :ns #object[sci.lang.Namespace 0x531c22fa "malli.core"]})}], :file "malli/core.cljc"}
babashka v1.0.169, via nrepl-server Same error for malli versions 0.8.9 - 0.9.2.

borkdude12:01:07

This is probably an nrepl problem. can you try:

(binding [*unchecked-math* *unchecked-math*]
  (require '[malli.core :as malli]))

2
borkdude12:01:30

Please post an issue about it

Alexander Kaiser13:01:46

(binding [*unchecked-math* *unchecked-math*]
  (require '[malli.core :as malli]))
This works! The problem also only arises when i use nrepl-server. I will post an issue. Thank you very much!

👍 2
Alexander Kaiser13:01:26

Should i post the issue for nrepl or for bb? I am not sure if it is a problem in nrepl or bb

borkdude13:01:29

Similar, but not same, but I added your problem to this issue now

borkdude14:01:45

That one was solved, and the solution to your problem is similar

borkdude14:01:50

so feel free to make a PR if you want

Alexander Kaiser14:01:21

i will try, thank you!

borkdude16:01:16

why isn't that the right place?

Alexander Kaiser16:01:18

If i add unchecked-math to the place you proposed, the added test still fails. When if remove babashka.impl.clojure.core/warn-on-reflection from :thread-bind [babashka.impl.clojure.core/warn-on-reflection] then the warn-on-reflection dynamic var test still succeeds https://github.com/babashka/babashka/commit/4c0d34b7c8de78c3b54d3d21b41d980da9f41fc3#diff-8afee3c27290022a97944edbbf6ccc957df49cb30cdd41af6cd13f205ddf3138R16 . So I thought that the tests in babashka.nrepl are not related to this.

borkdude16:01:01

@U01169S0E0N Ah, this is probably because babashka.nrepl and babashka are separate projects and the tests of babashka.nrepl have a specific configuration, that is decoupled from babashka

borkdude16:01:04

I think you should only make changes to babashka, not babashka.nrepl

borkdude16:01:29

and also the test should only live in babashka, not in the babashka.nrepl project

Alexander Kaiser16:01:39

could you point me to a place where the test should be in the babashka project?

borkdude16:01:42

I'll have a look. We have a copy of those nrepl tests in babashka, but at some point babashka.nrepl was made a library that can be used in babashka-like projects

Alexander Kaiser16:01:28

perfect! Thank you

borkdude17:01:17

I'll take a look after dinner :)

borkdude19:01:38

It was a little more complex so I went ahead and solved some issues. Next time it should be easier. https://github.com/babashka/babashka/commit/3aca5057909ba3b81da594eaa66fd94435484cbb

clojure-spin 4
grazfather13:01:45

how would one best play with a bb.edn file in the repl. Specifically, if I use :requires, how do I get the repl to load the deps? e.g. should I just manually write (require ...) and evaluate that form?

borkdude13:01:18

I think it's best to add a directory, e.g. bb to your :paths and then just put normal code in there for REPL usage and then hook that up to tasks

grazfather13:01:40

unless I am misunderstanding, then I need to split up my tasks across multiple files, when I want it all self-contained in just bb.edn, that's half the beauty of it

borkdude13:01:57

You can also spin up an nREPL server as a task: https://book.babashka.org/#_repl_2

grazfather13:01:15

Will that repl have the :requires loaded?

borkdude13:01:57

if that REPL depends on the other tasks you want to use in the REPL, then yes

grazfather13:01:04

All I want to do is work on my tasks in the repl, not actually have the repl as a task, this is strictly for debugging my tasks. I'd like to avoid having to convert my :requires to a form the nrepl understands, but I can live with it

grazfather13:01:18

so my tasks don't need the repl to work normally

borkdude13:01:33

you make the REPL task depend on the other tasks you want to debug

grazfather13:01:40

I'm using conjure which knows to spawn a bb nrepl server when I open bb.edn

grazfather13:01:46

ah, ok that might work

borkdude13:01:08

you can spawn an nREPL server programmatically using (babashka.nrepl.server/start-server! {:port 1337})

grazfather14:01:53

Yep, but would be nice to let conjure handle it

borkdude14:01:01

A little bike-shedding about babashka.http-client We already have babashka.nrepl.server and perhaps there will be a babashka.nrepl.client Perhaps it would be better to rename http-client to babashka.http.client ? Or am I overthinking this? :thinking_face:

grav14:01:39

Oooh, bike-shedding ❤️ I personally prefer as little nesting as possible.

borkdude14:01:34

So you prefer babashka.http-client right?

👍 4
pithyless14:01:28

think_beret 1. What are the odds you will have a future <thing> that will be competing? e.g. a different http-server, but this time also supporting ring, etc. 2. I think nesting is nice, but the question is are we subdividing via domain or library? (e.g. imagine babashka added support aleph, which offers both client and server; would that be babashka.http-client-aleph babashka.aleph.client or babashka.http.aleph-client? 3. In a similar vein, why is it babashka.nrepl.client instead of babashka.repl.client or babashka.repl.nrepl-client? What if we want a different repl implementation?

🚲 6
borkdude14:01:59

I think it's babashka.nrepl.server because the original one was called nrepl.server https://github.com/nrepl/nrepl/blob/8c431a07e071e87176942a53f3ed9e2f62a2587a/src/clojure/nrepl/server.clj#L1

pithyless14:01:37

Fair enough, but I thought we were bike-shedding about naming conventions. My what-if questions assume you would not be beholden to past decisions :]

borkdude14:01:32

I've also considered renaming babashka.http-server to babashka.file-server since it serves static files... but it's not an FTP server, it's still an http server... and it's called like that in other projects like Python too thinking-face... Ah well, I think babashka.http-client is just fine then.

borkdude14:01:38

OK, another bike-shed for you:

babashka.http-client.interceptors (plural)
babashka.http-client.interceptor (single)
I saw lib.websocket instead of lib.websockets somewhere and eventually I'll add babashka.http-client.websocket(s) too

borkdude14:01:41

(or perhaps the socket stuff can just live in the main namespace really)

pithyless14:01:26

I like singular, but it assumes you agree with this reasoning:

(:require [babashka.http-client.interceptor :as interceptor])

(interceptor/sanitize-request)
^ I like to use full names in my NS aliases and assume that it actually provides much needed context.

borkdude14:01:52

interceptor/default-interceptors

pithyless14:01:34

(interceptor/defaults) ?

pithyless14:01:03

or if you insist:

interceptor/foo
interceptor/bar

;; separae ns:
interceptors/super-secret
interceptors/permissive

borkdude14:01:06

speaking about context, defaults tells me less

borkdude14:01:32

I might just mash everyhing into the http-client namespace

pithyless14:01:59

> speaking about context, defaults tells me less My point was I like to choose names that may not convey enough information without the namespace; so interceptor/sanitize-request vs http/sanitize-request-interceptors It’s just a convention I like to use, but adding the suffix at the end hints that maybe this is a different context (hence namespace)

pithyless14:01:09

But the argument “everything goes in http” also works :]

borkdude14:01:55

ah you're right, I think I went with the interceptors namespace because I didn't like to suffix every interceptor

pithyless14:01:02

Gotta go afk, thanks for the 🚲 think_beret @borkdude

grazfather14:01:19

makes sense to me

grazfather14:01:38

do you have http-server?

borkdude14:01:31

Let's discuss in a thread. Yes, but this is a library which serves static files https://github.com/babashka/http-server

grav14:01:44

@borkdude Btw, related to the http-client; did you consider building on top of https://github.com/funcool/httpurr? It supports clj+cljs already, and is quite modular

grav14:01:34

One nice thing about its api is that you can pick whether you want to use functions or data, eg (client/send! {:method :get} ... vs (client/get ... I think this is different than your current approach

borkdude14:01:55

bb http-client has (request {:method :get :uri ...})

grav14:01:02

Oh, cool! 🙂

grav14:01:06

Missed that

borkdude14:01:12

bb http-client builds on the java.net.http client (which is already part of bb), and with the :async option you get back a future. Probably supporting a callback will be sufficient to deal with async stuff, rather than pulling in more dependencies

👍 2
lispyclouds15:01:35

Or with Project Loom bb, no one cares about call backs anymore 😄 at least that my hope for contajners

👍 4
awesome 2
2