babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Karol Wójcik 2021-04-26T06:56:02.084800Z

Thank you so much! Will give it a spin.

borkdude 2021-04-26T09:42:36.091Z

@karol.wojcik Perhaps I will remove the logging stuff which I pretty much butchered together and will just expose *task-name*. So you can do:

(println ">>>" *task-name*)
in your tasks, if you want to print the task name

pithyless 2021-04-26T10:02:03.091600Z

Can we use some kind of middleware/interceptor pattern for tasks (similar to :init)? That way we could globally define and customize things like printing task names, logging responses, etc.

borkdude 2021-04-26T10:04:54.092100Z

hmm, interesting!

borkdude 2021-04-26T10:05:25.092300Z

:pre-task (fn [...] ...) :post-task (fn [...] ...) ?

borkdude 2021-04-26T10:07:48.092500Z

I guess if you want to save some state, you can accumulate it in some atom you define in :init

borkdude 2021-04-26T10:08:09.092700Z

nice idea

pithyless 2021-04-26T10:08:20.092900Z

:interceptors [{:name "optional"
                :pre-task (fn [..] ...)
                :post-task (fn [..] ...)}]

👍 1
pithyless 2021-04-26T10:08:56.093300Z

^ perhaps something like that, and you can probably ship with a couple default interceptors built-in

pithyless 2021-04-26T10:11:20.093500Z

so the previous discussions would boil down to:

:interceptors [log-task-names, log-task-outputs]

borkdude 2021-04-26T10:14:12.093700Z

https://github.com/babashka/babashka/issues/805

👍 1
Karol Wójcik 2021-04-26T10:15:37.094200Z

Please allow binding interceptors from task script as well.

borkdude 2021-04-26T10:17:48.094400Z

What do you mean exactly?

Karol Wójcik 2021-04-26T10:22:52.094600Z

I want to add interceptors from script not via bb.edn:

(ns holy-lambda.tasks
  "This namespace contains tasks!"
  (:require
   [clojure.string :as s]
   [clojure.pprint :as pprint]
   [clojure.java.shell :as csh]
   [clojure.edn :as edn]
   [babashka.tasks :as tasks]
   [babashka.deps :as deps]
   [babashka.fs :as fs]
   [babashka.curl :as curl]
   [babashka.process :as p]
   [<http://clojure.java.io|clojure.java.io> :as io]))

(tasks/add-interceptors [{:name "Wrap task"
                          :enter (fn [task-name] (println task-name))
                          :leave (fn [task-name] (println task-name))}])

borkdude 2021-04-26T10:24:14.094800Z

What is the reason you want this in addition to declaring them in bb.edn?

borkdude 2021-04-26T10:32:31.095Z

Hmm, we could add the value of each task execution into the middleware map as it executes

borkdude 2021-04-26T10:32:42.095200Z

and then each middleware fn gets to see the middleware map

borkdude 2021-04-26T10:32:50.095400Z

and can add/remove to it

borkdude 2021-04-26T10:34:25.095600Z

> Hmm, we could add the value of each task execution into the middleware map as it executes hmm, but this is already supported by :depends as well, but perhaps it doesn't hurt to have some more flexibility

borkdude 2021-04-26T10:39:26.095900Z

baz {:enter (fn [m1] (assoc m :foobar 2)) :task 66 :leave (fn [m2] ...)}
where m1 = {foo 1 bar 2 :task-name baz} and m2 = {foo 1 bar 2 baz 66 :foobar 2 :task-name baz}

Karol Wójcik 2021-04-26T11:22:45.096600Z

Interceptors is an implementation detail for me. I don't want the user to change them.

borkdude 2021-04-26T11:23:31.096800Z

What is "the user"

Karol Wójcik 2021-04-26T11:26:08.097Z

The one who interacts with holy-lambda via executing provided bb tasks.

borkdude 2021-04-26T11:27:41.097200Z

Is holy lambda generating a template project for the user with a bb.edn in it?

borkdude 2021-04-26T11:27:55.097400Z

or how does it work?

Karol Wójcik 2021-04-26T11:30:07.097600Z

When I'll be done with tasks I will just reference to holy-lambda-babashka-tasks/bb.edn from template. Running

lein new holy-lambda &lt;some-project&gt;
will scaffold a project with bb.edn.
bb version
will check for new version of tasks if found a new version then will ask the user to update the sha in bb.edn https://github.com/FieryCod/holy-lambda/blob/master/modules/holy-lambda-babashka-tasks/bb.edn

borkdude 2021-04-26T11:31:35.098100Z

ok but note that a user of the template is as much a "power" user of the bb.edn as you are, a template is only a starting point of a project after which you make your own modifications

borkdude 2021-04-26T11:32:15.098300Z

so whatever changes they want to make to the bb.edn, that should be allowed

Karol Wójcik 2021-04-26T11:32:26.098500Z

Actually that's a good point

borkdude 2021-04-26T11:32:32.098700Z

and btw, version is also a subcommand of babashka which you are overriding

borkdude 2021-04-26T11:32:42.098900Z

but that shouldn't be a problem

Karol Wójcik 2021-04-26T11:32:52.099100Z

I will use tasks:version then

Karol Wójcik 2021-04-26T11:32:53.099300Z

Thanks!

borkdude 2021-04-26T11:44:25.099500Z

Instead of calling it interceptors maybe a more basic "hook" system works better (also in combination with parallel tasks). You can define a global :enter and :leave hook (which gets to mutate the global context map) and you can override those per task. If you want to call the global hook, just call it manually in the override.

borkdude 2021-04-26T11:44:59.099700Z

This way you don't get any weird API edge cases with interceptor ordering/insertion/appending.

borkdude 2021-04-26T11:47:36.100Z

Pretty much the same as (sync) Ring but two hooks, one before and one after

borkdude 2021-04-26T11:48:17.100200Z

or can we get away with just one?

borkdude 2021-04-26T11:51:50.101700Z

I think it's more flexible to have one before and one after hook probably

borkdude 2021-04-26T11:52:17.102300Z

possibly you can also decide to abort/skip the task in the :enter hook based on some condition

sh54 2021-04-26T11:56:01.103600Z

Is there a built in way to stream out a processes output whilst the process is running? Right now I am just doing it myself which is fine. Just checking if I was missing out on some included batteries?

(defn attach-out-printer
  [proc]
  (thread
    (with-open [rdr (<http://clojure.java.io/reader|clojure.java.io/reader> (:out proc))]
      (let [lines (line-seq rdr)]
        (doseq [line lines]
          (println line)))))
  proc)

(-&gt; (process ["./gradlew" "jvmFatJar"] {:dir kgpu-dir})
        (attach-out-printer))

pithyless 2021-04-26T11:56:24.103800Z

yeah, even logic like should a "failing" task continue quietly or Sys/exit could be customized by a :leave hook

borkdude 2021-04-26T11:56:45.104400Z

@slack1003 {:out :inherit :err :inherit :in :inherit} or {:inherit true} for short

sh54 2021-04-26T11:56:58.104600Z

nice! i’ll try that

sh54 2021-04-26T11:57:23.104900Z

ah missed that. just started using your lib

sh54 2021-04-26T11:59:34.105100Z

yup that works great

sh54 2021-04-26T12:03:25.106200Z

in the process of converting the few little helper build scripts in my project over to your tasks system. Very smooth sailing so far!

borkdude 2021-04-26T12:04:35.107500Z

@slack1003 cool. The tasks system also has a shell function which you can use like:

(shell {:dir kgpu-dir} "./gradlew jvmFatJar")
and it will do the same as above with :inherit true set by default

sh54 2021-04-26T12:11:37.111100Z

alright. good to know. right now tasks has just been calling my prexisting bb scripts but I guess I may just do some shell stuff directly

borkdude 2021-04-26T12:12:23.111800Z

both approaches are totally fine. in bb 0.3.6 I just added a new :continue option so shell won't automatically exit with a non-zero exit code

sh54 2021-04-26T12:13:58.112500Z

that will be a nice addition. though all my stuff so far is happy to bail on non-zeroes

borkdude 2021-04-26T12:14:48.112800Z

yeah, that's the default in shell

dangercoder 2021-04-26T12:26:21.114Z

is cheshire.factory included in babashka.json? I have a need of customizing the underlying object-mapper object. This is kind of nice in e.g. jsonista since you can pass it your own object-mapper.

✅ 1
dangercoder 2021-04-26T12:27:44.114500Z

the answer is no

dangercoder 2021-04-26T12:28:20.114800Z

😅

borkdude 2021-04-26T12:29:00.115Z

indeed. I'm not planning to since I'm not certain if cheshire is the right json tool in 2021 now that jsonista and clojure.data.json are also gaining popularity

borkdude 2021-04-26T12:29:45.115200Z

so I'd like to keep the surface area somewhat minimal so it might be easier to port to some other solution in the future

borkdude 2021-04-26T12:30:51.115600Z

could you convince me of the usefulness of providing your own object-mapper? examples?

dangercoder 2021-04-26T12:33:00.115800Z

Options when parsing json. Right now I'm getting: ; clojure.lang.ExceptionInfo: [line 1, col 51] Unsupported escape character: \U. This would not be a problem if I configure the underlying object-mapper. e.g with jsonista:

(def object-mapper
  (-&gt; jsonista/keyword-keys-object-mapper
      (.configure (.mappedFeature JsonReadFeature/ALLOW_UNESCAPED_CONTROL_CHARS) true)))

dangercoder 2021-04-26T12:33:56.116Z

so now, when using jsonista I can do: (jsonista/read-value json-string my-object-mapper)

dangercoder 2021-04-26T12:35:22.116200Z

so basically this blocks me from using babashka from our ci-pipeline, but im going to figure out if I can use jsonista some way.

borkdude 2021-04-26T12:37:44.116400Z

you can't currently use jsonista in babashka. Is there a way to fix the json first with str/replace?

dangercoder 2021-04-26T12:40:16.116600Z

Gonna see, the json we receive is malformed from a system which we do not control. This option is kind of hacky indeed 🙂, I'll check it out. We still use BB for other parts of our CI and it's a pleasure to work with!

dangercoder 2021-04-26T12:43:06.116800Z

its basically a nested json structure containing a json string as a value of a key which we do not want to parse directly.

borkdude 2021-04-26T12:45:17.117100Z

Perhaps you can use a tool like jq to fix the JSON (if that tool supports it...)

borkdude 2021-04-26T12:45:40.117300Z

Can you give a small example of such JSON?

Karol Wójcik 2021-04-26T13:31:42.117900Z

How can I change in docker where .deps.clj/ClojureTools are downloaded? Here is what I tried:

ENV _JAVA_OPTIONS=-Duser.home=/project/.holy-lambda/
ENV XDG_CACHE_HOME=/project/.holy-lambda/
ENV XDG_CONFIG_HOME=/project/.holy-lambda/
ENV CLJ_CACHE=/project/.holy-lambda/
ENV CLOJURE_TOOLS_CP=/project/.holy-lambda/
ENV HOME=/project/.holy-lambda/

RUN curl <https://raw.githubusercontent.com/borkdude/deps.clj/master/install> | bash
RUN bash -c "cd project/.holy-lambda &amp;&amp; deps -P"
But it still downloads to /root/.deps.clj

borkdude 2021-04-27T11:52:57.154Z

@karol.wojcik Btw, have you tested if the aws pod works in your docker container / lambda? If it's a musl based container (alpine, busybox) often pods don't work (because they depend on libc++) and have to be compiled statically, so that would be good to test.

Karol Wójcik 2021-04-27T11:53:30.154300Z

aws pod?

borkdude 2021-04-27T11:54:06.154500Z

org.babashka/aws "0.0.5"

Karol Wójcik 2021-04-27T12:11:07.154800Z

I will not run babashka/pod on my docker image. 😄

borkdude 2021-04-27T12:12:38.155Z

but will it work in your target environment?

borkdude 2021-04-27T12:12:44.155200Z

that is the question right

borkdude 2021-04-27T12:12:59.155400Z

oh I guess it's the same for bb itself, if the normal bb works then the pod will also work

👍 1
Karol Wójcik 2021-04-27T12:14:16.155700Z

Yep exactly.

borkdude 2021-04-27T12:16:41.155900Z

:thumbsup:

Karol Wójcik 2021-04-27T14:50:25.162300Z

https://clojurians.slack.com/archives/CLX41ASCS/p1619463021130800?thread_ts=1619443902.117900&amp;cid=CLX41ASCS This was super helpful. Thank you so much @borkdude!

👍 1
Karol Wójcik 2021-04-27T15:00:09.163Z

Can I set a system property for clojure command as well? Don't see anything such option

borkdude 2021-04-27T15:00:41.163200Z

@karol.wojcik How are you invoking Clojure?

Karol Wójcik 2021-04-27T15:01:15.163400Z

clojure -P

borkdude 2021-04-27T15:01:53.163900Z

without bb that is, right?

Karol Wójcik 2021-04-27T15:01:57.164100Z

Yep

borkdude 2021-04-27T15:02:16.164300Z

clojure -J-Duser.home=/foo

Karol Wójcik 2021-04-27T15:02:29.164500Z

Ahh..

Karol Wójcik 2021-04-27T15:02:31.164700Z

Checking

Karol Wójcik 2021-04-27T15:02:45.165300Z

May I set it for deps.clj which babashka uses as well?

borkdude 2021-04-27T15:03:08.165600Z

> without bb that is, right? > yes ?

borkdude 2021-04-27T15:04:11.165800Z

so are you or are you not using bb to invoke clojure?

borkdude 2021-04-27T15:05:21.166300Z

if not, where does deps.clj come in?

Karol Wójcik 2021-04-27T15:12:05.166800Z

Ok. You're right. I think bb tasks needs deps.clj since I'm using a :deps keyword in bb.edn. To conclude I use both.

borkdude 2021-04-27T15:14:06.167100Z

bb.edn doesn't forward any Java properties to its call to deps.clj

borkdude 2021-04-27T15:22:04.167300Z

Maybe we should support this, but currently it doesn't

borkdude 2021-04-27T15:22:37.167500Z

is this about setting the local .m2 folder?

Karol Wójcik 2021-04-27T15:24:45.167700Z

Yes

borkdude 2021-04-27T15:26:54.167900Z

you can put :mvn/local-repo "/tmp/.m3" in your bb.edn

borkdude 2021-04-27T15:27:33.168100Z

it's a bit of a workaround probably

Karol Wójcik 2021-04-27T15:27:55.168300Z

It's a little bit complicated, but what I want to achieve is to run clojure -P in docker container and sync it with .holy-lambda directory on host. Now I cannot set user.home for Clojure. I just tried what you've sent and user.home is not set.

Karol Wójcik 2021-04-27T15:28:32.168500Z

With _JAVA_OPTIONS it kinda worked, but it prints a low of "Picked _JAVA_OPTIONS etc.

borkdude 2021-04-27T15:29:22.169Z

> but it prints a low of "Picked JAVAOPTIONS etc. I have no idea what this means, sorry =)

borkdude 2021-04-27T15:29:34.169200Z

what is _JAVA_OPTIONS even?

Karol Wójcik 2021-04-27T15:31:06.169400Z

https://unix.stackexchange.com/questions/495469/how-to-fix-picked-up-java-options-no-options-listed-on-linux It's environment variable to which you can pass some java options.

Karol Wójcik 2021-04-27T15:31:10.169700Z

😄

Karol Wójcik 2021-04-27T15:32:29.170100Z

Hmm. Ok it seems that I messed something with my docker again 😄

clojure -J-Duser.home=/foo -e "(println (System/getProperty \"user.home\"))"
You were right. It works.

Karol Wójcik 2021-04-27T15:40:51.172100Z

@borkdude You're some sort of wizard. :mvn/local-repo works like a charm! Thank you so much! You rock man!

borkdude 2021-04-27T15:43:44.172400Z

cool. Perhaps bb should have a separate argument to pass through to deps.clj.

bb --deps-args '-J-Duser.home=/foo'
or so

Karol Wójcik 2021-04-27T15:53:43.174500Z

Yep. It would be useful

Karol Wójcik 2021-04-26T13:42:02.118200Z

CLOJURE_TOOLS_DIR is the thing! 🙂

borkdude 2021-04-26T14:01:44.118400Z

Should the :enter hook be executed before or after dependencies... :thinking_face:

borkdude 2021-04-26T14:09:48.118600Z

What is CLOJURE_TOOLS_CP ?

Karol Wójcik 2021-04-26T14:13:17.118800Z

Before I started reading deps.clj source code I tried my luck with this env var 😄

Karol Wójcik 2021-04-26T14:14:54.119Z

Have you ever seen babashka load/pod to write to '?' folder?

borkdude 2021-04-26T14:15:36.119200Z

This environment variable is also documented in the README

borkdude 2021-04-26T14:15:41.119400Z

no

Karol Wójcik 2021-04-26T14:20:20.119600Z

Ok. It's really weird. Here is repro: https://github.com/FieryCod/holy-lambda/commit/22e18f5f434cfff484db5dd019a541ac04705062 git clone git@github.com:FieryCod/holy-lambda.git && make build-docker && cd modules/holy-lambda-babashka-tasks && bb stack:sync After command finishes you will see '?' folder 😮

borkdude 2021-04-26T14:22:01.119800Z

could it be related about the order of these commands?

RUN mkdir -p /.babashka
RUN chmod -R 777 /clojure
RUN chmod -R 777 /.m2
RUN chmod -R 777 /.babashka

WORKDIR /project

borkdude 2021-04-26T14:22:09.120Z

shouldn't WORKDIR go before mkdir?

borkdude 2021-04-26T14:23:36.120200Z

I'm just guessing, I don't know your project well enough

Karol Wójcik 2021-04-26T14:26:42.120800Z

Nope. It's something with resolver. I got folder .holy-lambda/.babashka/pods/repository/org.babashka/aws/0.0.5/, but bin is downloaded to '?' ?/.babashka/pods/repository/org.babashka/aws/0.0.5/

borkdude 2021-04-26T14:26:53.121200Z

$ bb stack:sync
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  File does not exist: stack:sync

Karol Wójcik 2021-04-26T14:27:37.121400Z

In which folder are you?

borkdude 2021-04-26T14:28:16.121600Z

oh right

borkdude 2021-04-26T14:29:23.121800Z

> After command finishes you will see '?' folder how do I see this folder?

borkdude 2021-04-26T14:29:33.122Z

oh yes, I see it

👍 1
Karol Wójcik 2021-04-26T14:30:52.122200Z

Uff. It's good that I'm not crazy 😄

borkdude 2021-04-26T14:32:41.122500Z

I don't have time to debug your program, so can you make a small repro?

Karol Wójcik 2021-04-26T14:33:42.122800Z

Sure

Karol Wójcik 2021-04-26T14:51:59.123Z

@borkdude Here it is: https://github.com/FieryCod/babashka-docker-path-repro

Karol Wójcik 2021-04-26T14:52:02.123300Z

Just run make

borkdude 2021-04-26T14:54:03.123500Z

Do you have a more minimal one? There is a lot happening in this Dockerfile

borkdude 2021-04-26T14:57:11.123700Z

Oh I see you have stripped it already

Karol Wójcik 2021-04-26T14:57:17.123900Z

It's stripped.

Karol Wójcik 2021-04-26T14:57:29.124100Z

I can use alpine if you want me to to make it even more minimal

Karol Wójcik 2021-04-26T14:57:50.124300Z

But I guess you have graalvm-ce in cache so build should not take long

borkdude 2021-04-26T14:58:25.124500Z

I don't use docker locally for graalvm, but I'm going to try. I do see the question mark dir, but how do I know this is not an issue with your docker config vs pods?

Karol Wójcik 2021-04-26T15:02:16.124700Z

😄 I'm already using the same strategy for mountig .aws directory no question mark there

borkdude 2021-04-26T15:02:27.124900Z

FWIW when I make a .babashka directory inside your repo, then I don't get the question mark dir

Karol Wójcik 2021-04-26T15:05:08.125100Z

Hmm isn't it proof that it's something wrong with babashka resolver then?

borkdude 2021-04-26T15:07:35.125300Z

I don't say there isn't but right now I'm debugging your docker issues while I have another job to do, so I'd say this is not a clear repro yet

Karol Wójcik 2021-04-26T15:25:44.125500Z

Sure. I fixed the repro. It should be very minimal right now. You can spot '?' in error:

----- Context ------------------------------------------------------------------
 7: 
 8: (def PODS {'org.babashka/aws "0.0.5"})
 9: 
10: (doseq [[s v] PODS]
11:   (pods/load-pod s v))
      ^--- ?/.babashka/pods/repository/org.babashka/aws/0.0.5/manifest.edn (No such file or directory)

----- Locals -------------------------------------------------------------------
seq_2:   ([org.babashka/aws "0.0.5"])
chunk_3: nil
count_4: 0
i_5:     0
vec__9:  [org.babashka/aws "0.0.5"]
s:       org.babashka/aws
v:       "0.0.5"

----- Stack trace --------------------------------------------------------------
user - /usr/bin/download_pods:11:3

borkdude 2021-04-26T15:31:53.125800Z

@karol.wojcik When I print in the script:

(prn (or
            (System/getenv "XDG_CACHE_HOME")
            (System/getProperty "user.home")))
I see "?".

Karol Wójcik 2021-04-26T15:32:16.126Z

When you run make you will see "?"

borkdude 2021-04-26T15:33:19.126200Z

yes. it seems your XDG_CACHE_HOME env variable isn't properly set in the script. so it picks the value of user.home which is a question mark.

borkdude 2021-04-26T15:33:49.126400Z

so it turns out I have been debugging your Docker issues instead of pods. :/

Karol Wójcik 2021-04-26T15:34:51.126600Z

Hmm.. With this it still outputs question mark:

FROM <http://ghcr.io/graalvm/graalvm-ce:ol8-java8-21.1.0|ghcr.io/graalvm/graalvm-ce:ol8-java8-21.1.0>
MAINTAINER Karol Wójcik &lt;Karol Wójcik&gt;

WORKDIR /

RUN microdnf install wget

RUN mkdir -p /project
ENV _JAVA_OPTIONS=-Duser.home=/project
ENV XDG_CACHE_HOME=/project
ENV XDG_CONFIG_HOME=/project
ENV CLJ_CACHE=/project
ENV CLOJURE_TOOLS_DIR=/project
ENV HOME=/project
ARG BABASHKA_VERSION=0.3.6

RUN wget -c <https://github.com/babashka/babashka/releases/download/v$BABASHKA_VERSION/babashka-$BABASHKA_VERSION-linux-amd64.tar.gz> -O - | tar -xz
RUN chmod +x bb
RUN mv bb /bin/bb

COPY download_pods .
RUN chmod +x download_pods
RUN mv download_pods /bin/download_pods

borkdude 2021-04-26T15:35:59.126800Z

I think I have provided you with enough debugging now. I won't look at this anymore unless you can provide a repro without Docker, etc.

Karol Wójcik 2021-04-26T15:36:42.127Z

😕

borkdude 2021-04-26T15:42:20.127200Z

I don't want to sound like an asshole, but I what I mean is: this is a contextual problem between your Docker setup and bb. You can do more diagnosis before you poke me about it. E.g. bash into the container and inspect:

bash-4.4$ bb
Babashka v0.3.6 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=&gt; (System/getProperty "user.home")
"?"
user=&gt; (System/getenv "XDG_CACHE_HOME")
nil

Karol Wójcik 2021-04-26T15:48:39.127500Z

My first repro lacked one env variable which is: XDG_DATA_HOME

Karol Wójcik 2021-04-26T15:49:01.127700Z

It sounded like you being asshole, but no worries I deserved it 😄

Karol Wójcik 2021-04-26T15:49:59.127900Z

I should have studied resolver code more. I did not spot XDG_DATA_HOME I'm really sorry!

borkdude 2021-04-26T15:50:34.128100Z

no worries ;)

Karol Wójcik 2021-04-26T16:14:35.128400Z

I'm deeply sorry. I will spend more time on reading babashka code! 🙂 No more pokes today 🙂 Have a great day!

borkdude 2021-04-26T16:16:08.128700Z

I don't mind the pokes, I think you're making a very interesting project. It's just that in case the bugs aren't directly related to bb a more clear cut repro could be made. Feel free to poke me anytime after you've done your part of the research, so it will save me time.

borkdude 2021-04-26T16:17:17.129Z

and if I think you should make it more clear cut, I will just say so (hopefully without sounding like an asshole :-D)

borkdude 2021-04-26T16:18:10.129300Z

I also enjoy your feedback on the tasks, so thanks for that

viesti 2021-04-26T18:35:45.130300Z

at least if you run as a user, which doesn't have a /etc/passwdentry, then you get ? for (System/getProperty "user.home") (just came to my mind from some previous docker adventure)

Karol Wójcik 2021-04-26T18:43:43.130600Z

Huh. I didn't know that. Thanks @viesti

borkdude 2021-04-26T18:50:21.130800Z

You can force this property in bb by doing bb -Duser.home=/foobar

👍 1
❤️ 1
kokada 2021-04-26T21:09:03.132700Z

Hi I am trying to use babashka.process to run a subprocess, but I don't want to capture its stdin/stdout/stderr (like subprocess.run from Python by default). Is there anyway to do this :thinking_face: ? I did not found anything in the documentation.

borkdude 2021-04-26T21:10:25.133600Z

if you didn't find that in the documentation, then the docs need improving

kokada 2021-04-26T21:10:27.133700Z

Huh... Did try this but it isn't printing anything on REPL

kokada 2021-04-26T21:10:30.134Z

Ah, of course

kokada 2021-04-26T21:10:39.134300Z

It will not print anything on REPL 😛 (since it is not redirecting the output)

kokada 2021-04-26T21:11:36.134900Z

I did find the :inherit option, but it wasn't really clear what it does by the explanation But looking at the examples it seems ok

borkdude 2021-04-26T21:12:06.135300Z

cool

kokada 2021-04-26T21:12:27.135700Z

It is working fine, thanks @borkdude

🎉 1
borkdude 2021-04-26T21:13:51.136Z

I think I'll keep it more basic, in the same fashion :tasks are just expressions:

Re-considering, I think this is all that's needed to support logging of task names:

add *task-name* dynamic var
global :enter (println :&gt; *task-name*)
global :leave (println :&lt; *task-name*)
able to replace :enter and :leave on the task level
This is all that's needed, even to support some kind of middleware pattern, since you can define an atom in :init where :enter and :leave can mutate something to.

kokada 2021-04-26T21:20:13.136800Z

Have to say, porting some internal tools from my company from Bash/Python to Babashka

kokada 2021-04-26T21:20:15.137Z

It is awesome!

🎉 3
kokada 2021-04-26T21:45:18.137600Z

Is there any logging library available in babashka :thinking_face: ?

borkdude 2021-04-26T21:47:46.138Z

@thiagokokada At the moment, no. But here is a tiny useful snippet perhaps: https://gist.github.com/borkdude/c97da85da67c7bcc5671765aef5a89ad

🙌 1
kokada 2021-04-26T22:06:29.138400Z

It is printing the correct line but it always print the namespace user

borkdude 2021-04-26T22:09:16.138600Z

Weird, the gist still seems to work for me where it prints the ns bar

kokada 2021-04-26T22:11:13.138800Z

I am using the -m flag

kokada 2021-04-26T22:11:26.139Z

Since it is a full Clojure project (with src, etc)

borkdude 2021-04-26T22:12:11.139200Z

ah!

kokada 2021-04-26T22:13:35.139400Z

Maybe because of this :thinking_face:?

(ns user (:require [foo.core])) (apply foo.core/-main *command-line-args*)

kokada 2021-04-26T22:13:53.139600Z

I was trying to create a new project to demonstrate, but this got to my attention

kokada 2021-04-26T22:14:00.139800Z

(It is an exception btw)

borkdude 2021-04-26T22:15:07.140Z

Can you try this instead?

(defmacro log [&amp; msgs]
  (let [m (meta &amp;form)
        file *file*]
    `(binding [*out* *err*] ;; or bind to (io/writer log-file)
       (println (str ~file ":"
                     ~(:line m) ":"
                     ~(:column m))
                ~@msgs))))

borkdude 2021-04-26T22:15:39.140200Z

pulling *ns* outside of the macro body might also work

kokada 2021-04-26T22:17:07.140400Z

Yep, the one with *file* works

kokada 2021-04-26T22:17:37.140600Z

BTW, if you want to reproduce it

kokada 2021-04-26T22:17:45.141Z

Run bb -m foo.core

kokada 2021-04-26T22:18:26.141200Z

But this alternative with *file* seems even more useful to me

kokada 2021-04-26T22:18:37.141400Z

:thanks:

borkdude 2021-04-26T22:19:33.141600Z

ok, you like file better than ns?

(ns logger)

(defmacro log [&amp; msgs]
  (let [m (meta &amp;form)
        ns *ns*]
    `(binding [*out* *err*] ;; or bind to (io/writer log-file)
       (println (str ~ns ":"
                     ~(:line m) ":"
                     ~(:column m))
                ~@msgs))))
this one also works, but let's go with the *file* one

kokada 2021-04-26T22:20:17.141900Z

Yeah, now that I think about it maybe ns is better (the printed line is smaller)

kokada 2021-04-26T22:20:31.142100Z

Don't know yet, I will do a experiment here

kokada 2021-04-26T22:20:35.142300Z

But thanks anyway

borkdude 2021-04-26T22:23:07.142500Z

ok, adapted the gist

kokada 2021-04-26T23:14:40.143500Z

From my search I don't think there is a way, but asking anyway (since I didn't found anything for neither Clojure nor Java) Is there anyway to set an environment variable from Babashka?

👀 2
borkdude 2021-04-27T07:32:47.149300Z

AFAIK you cannot change env vars in a Java runtime

borkdude 2021-04-27T07:52:30.149600Z

Here is another hack: https://stackoverflow.com/a/64804398/6264