babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2021-06-01T09:47:39.333300Z

@nicolas.estrada938 Decided to add support to bb for this trailing map and StackTraceElement. I'm building a new bb version now

โค๏ธ 1
borkdude 2021-06-01T09:47:48.333600Z

I also tested omniconf and it worked after those fixes

Nicolas Estrada 2021-06-01T09:49:21.333800Z

You my friend are a saint! ๐Ÿ™‚

borkdude 2021-06-01T10:09:36.334400Z

Babashka 0.4.4 is released. Changes: https://github.com/babashka/babashka/blob/master/CHANGELOG.md#044

๐Ÿ‘ 2
1
borkdude 2021-06-01T10:53:26.335300Z

Fun side effect of including StackTraceElement in bb is that you can inspect some of bb/sci's runtime ;)

$ bb -e '(->> (try (/ 1 0) (catch Exception e (.getStackTrace e))) (map bean) clojure.pprint/print-table)'

| :classLoaderName |        :fileName | :moduleVersion | :nativeMethod |                              :className | :moduleName |                            :class | :lineNumber |  :methodName |
|------------------+------------------+----------------+---------------+-----------------------------------------+-------------+-----------------------------------+-------------+--------------|
|                  |     Numbers.java |                |         false |                    clojure.lang.Numbers |             | class java.lang.StackTraceElement |         188 |       divide |
|                  |         core.clj |                |         false |                    clojure.core$_SLASH_ |             | class java.lang.StackTraceElement |        1029 | invokeStatic |
|                  |         core.clj |                |         false |                    clojure.core$_SLASH_ |             | class java.lang.StackTraceElement |        1022 |       invoke |

๐Ÿ™Œ 1
borkdude 2021-06-01T11:18:27.336Z

This is pretty cool too. Get info about another process:

$ bb -e '(.info (.get (java.lang.ProcessHandle/of 39045)))'
#object[java.lang.ProcessHandleImpl$Info 0x6bd723ed "[user: Optional[borkdude], cmd: /Applications/Emacs.app/Contents/MacOS/Emacs-x86_64-10_14, startTime: Optional[2021-05-28T08:59:27.973Z]]"]

borkdude 2021-06-01T11:20:53.336700Z

so with this you can get command line arguments, the exact binary location of what the process was started with, arguments, etc

Nom Nom Mousse 2021-06-01T12:03:09.337500Z

There is supposed to be an alternative to clojure.java.shell/sh in babashka. What is it called?

Nom Nom Mousse 2021-06-01T12:04:25.338800Z

And can I do (bb/sh "ecco my command is just a string") with it? (clojure.java.shell/sh "echo hi") fails with

Execution error (IOException) at java.lang.ProcessImpl/forkAndExec (ProcessImpl.java:-2).
error=2, No such file or directory

Nom Nom Mousse 2021-06-01T12:08:20.339900Z

I do not want to split my command string into whitespace as that might not be easy "ecco 'hi there'":

(clojure.java.shell/sh (clojure.string/split "echo 'hi there'" #" "))
Execution error (IllegalArgumentException) at clojure.java.shell/parse-args (shell.clj:47).
No value supplied for key: ["echo" "'hi" "there'"]

Nom Nom Mousse 2021-06-01T12:11:01.340Z

With apply it works. But I wonder whether this might ever break a command line string.

borkdude 2021-06-01T12:17:59.340600Z

@endrebak The alternative in babashka is babashka.process/process

borkdude 2021-06-01T12:18:22.340900Z

The same library has a function called tokenize to split shell functions for you

borkdude 2021-06-01T12:19:19.341900Z

If you want to invoke a shell command just like how you could do it in the shell, streaming output directly to stdout/stderr, then you could also use (babashka.tasks/shell "echo 'hi there'")

borkdude 2021-06-01T12:20:20.342100Z

user=> (do @(babashka.tasks/shell "echo 'hi there'") nil)
hi there
nil

borkdude 2021-06-01T12:49:03.342600Z

2000+ stars! https://github.com/babashka/babashka/stargazers :star-struck:

๐Ÿ‘ 1
โค๏ธ 6
๐Ÿ™ 4
๐ŸŒŸ 5
Karol Wรณjcik 2021-06-01T12:50:37.342800Z

Well deserved! Congrats!

Nom Nom Mousse 2021-06-01T13:04:53.343400Z

Syntax error (ClassNotFoundException) compiling at (*cider-repl code/myapp:localhost:56301(clj)*:32:12).
babashka.tasks
My lein coords are:
[babashka/babashka "0.4.4"]

Nom Nom Mousse 2021-06-01T13:05:22.343600Z

Also tried:

(require '[babashka.impl.tasks :as tasks])

Syntax error (IllegalArgumentException) compiling . at (borkdude/deps.clj:196:12).
More than one matching method found: newFileSystem

borkdude 2021-06-01T13:06:05.343800Z

Hmm, babashka isn't really supposed to be used as a JVM project. I was assuming you were using babashka as a tool

borkdude 2021-06-01T13:06:22.344Z

But the libraries contained in there, such as babashka.process, are available on the JVM

Nom Nom Mousse 2021-06-01T13:08:15.344200Z

Cool! It seems like clojure.java.shell/sh does not support many simple commands like:

(clojure.java.shell/sh "sleep" "1" ";" "echo" "2")
;; => {:exit 1, :out "", :err "usage: sleep seconds\n"}
So I'll be looking into babashka :thumbsup:

borkdude 2021-06-01T13:08:56.344400Z

The problem there is that ";" is bash syntax

borkdude 2021-06-01T13:09:03.344600Z

if you want to invoke bash, you could invoke bash

borkdude 2021-06-01T13:09:17.344800Z

with e.g. bash -c "echo hello"

Nom Nom Mousse 2021-06-01T13:09:40.345200Z

Thanks ๐Ÿ™‚

borkdude 2021-06-01T16:33:39.346600Z

So this now works @ben.sless

{:tasks
 {:init (do (def ^:dynamic *java*)
            (def ^:dynamic *browser*))
  test-front-end (println :browser *browser*)
  test-back-end (println :java *java*)
  test-app {:depends [test-front-end test-back-end]}
  run-matrix (doseq [java [8 11]
                     browser ["Safari" "Chrome" "Firefox"]]
               (binding [*java* java
                         *browser* browser]
                 (run 'test-app)))}}
The previous issues are fixed.

๐Ÿ‘ 1
๐Ÿ’ช 2
Ben Sless 2021-06-01T16:39:32.347100Z

First, that's pretty cool, ngl, going to try it out Second, have you had a chance to give some thought to my suggestion regarding adding a :matrix key to tasks? I'm willing to donate a hammock ๐Ÿ™‚

borkdude 2021-06-01T16:40:05.347300Z

Haven't thought through the matrix yet ;)

Ben Sless 2021-06-01T16:42:53.347500Z