Fork me on GitHub
#babashka
<
2021-01-15
>
Sergio10:01:40

hello!, is there a guide on how to create a Pod? for example, it’s not clear to me why some pods are written in other languages and how to get one simple “hello-pod” program up and running with Babashka

borkdude10:01:09

@sdmoralesma The docs are available at https://github.com/babashka/pods A hello world pod would be nice to add to the docs. Feel free to create an issue about this. But there are already many clojure examples available, see.: https://github.com/babashka/pod-registry The buddy pod may be the simplest one to look at, since it's just data back and forth, and no real state

❤️ 1
borkdude10:01:35

Some pods are written in other languages, because low level stuff like file system events are better done in golang or Rust. Some things simply didn't work with GraalVM, like sqlite, so that's why its in golang.

borkdude10:01:40

One dev tip: you can test the pod first on the JVM using the pod library and/or starting it via ["clojure" "-M" "-m" ...]

borkdude10:01:50

and if it works, then you can try compiling it to native

Sergio10:01:37

great!, thank you @borkdude

Marco Pas11:01:05

Being fairly new to Clojure and Babashka i was wondering how to manage external dependencies. For example if i want to use the environ package i now have this line in my script.

(babashka.deps/add-deps '{:deps {environ/environ {:mvn/version "1.2.0"}}})
(require '[environ.core :refer [env]])
I have another script that also needs this dependency then i need to copy and paste these lines. I read something about a deps.edn file but i am not sure how i can use this to download and use dependencies in my scripts and also being able to use them in my nrepl-server from babashka. Any pointers would be helpfull!!

borkdude11:01:31

Oh wow, environ works with bb :)

(require '[babashka.deps :as deps])

(babashka.deps/add-deps '{:deps {environ/environ {:mvn/version "1.2.0"}}})

(require '[environ.core :refer [env]])

(prn (:path env))
Nice find @marco.pasopas :)

Marco Pas11:01:10

Not making fun of me 🙂 🙂

borkdude11:01:22

No, I am serious

borkdude11:01:36

haven't tried that lib with bb before :)

Marco Pas11:01:52

Just added it yesterday and sofar no problems..

borkdude11:01:41

@marco.pasopas So what you can do is add some namespaces to the classpath:

(babashka.deps/add-classpath "script")
(require 'script.deps)
and then move your common deps to script/deps.clj

borkdude11:01:19

There is no deps.edn or config.edn like file for bb yet. This is something I'm considering, but not there yet.

Marco Pas11:01:42

Thanks for the pointer! Will try it out..

Marco Pas11:01:10

Next thing on my things i want to do with Babashka is unit testing 🙂

borkdude11:01:12

I am not sure if bb should use deps.edn itself (or maybe an alias :org.babashka) or that it should have a separate config file, or maybe even a __bb_setup__.clj script that's always run. Feel free to provide feedback in issue 680.

borkdude12:01:01

babashka_preloads.clj

borkdude12:01:39

It could be nice to have a .clj file for flexibility and not couple it with deps.edn too much. </hammock>

borkdude12:01:26

@marco.pasopas Btw, I don't think environ adds much for bb except that it reads all envs vars in a nice clojure map. Usually I just use (System/getenv "FOO_BAR")

Marco Pas12:01:28

@borkdude I agree! In my way to search for a lib that would enable me to set properties using envrionment variables and files i came across this one

Marco Pas12:01:06

Just am trying to wrap my head around the clojure world and also babashka

borkdude12:01:11

yeah makes sense, if you are not so familiar with the Java APIs etc these libs can really help

Marco Pas13:01:59

@borkdude The code

(babashka.deps/add-classpath "script")
(require 'script.deps)
Does the .deps package has a add-classpath?

borkdude13:01:17

@marco.pasopas no, this is in (babashka.classpath/add-classpath "script")

borkdude13:01:27

sorry, I made a typo earlier

Marco Pas13:01:40

No problem 🙂 thought it was my mistake 🙂

Marco Pas13:01:47

Newbie question 🙂

borkdude13:01:00

but you can also do this in one go with add-deps: {:paths ["script"]} :deps ...}

borkdude13:01:11

it just takes the contents of a deps.edn file basically

borkdude13:01:24

If you scroll back to January 12th there is a discussion about this

Marco Pas13:01:35

So i have created a file called script/deps.clj

(ns deps)

(require '[babashka.deps :as deps])
(babashka.deps/add-deps '{:deps {environ/environ {:mvn/version "1.2.0"}}})
(require '[environ.core :refer [env]])
In my main script…
(babashka.classpath/add-classpath "script")
(require 'script.deps)
Get an error: :message "Could not find namespace: script.deps.

Marco Pas13:01:20

My problem i guess with not getting clojure that good:)

borkdude13:01:04

@marco.pasopas No worries. Does it help when you rename (ns deps) to (ns script.deps) ?

borkdude13:01:36

I will try locally

Marco Pas13:01:09

I am trying to execute it against a repl

borkdude14:01:19

ah sorry, I got it..., script is added to the classpath, so everything inside that should be referred as deps.foo without script

borkdude14:01:25

(require '[babashka.classpath :as cp])
(cp/add-classpath "script")
(require 'deps)

borkdude14:01:48

and (ns deps) should stay that way

borkdude14:01:28

you can also add the current dir "." to the classpath, and then you could require it as (require 'script.deps) with (ns script.deps)

Marco Pas14:01:46

Gonna give a try! Thanksfor the help!!!!!!!