Fork me on GitHub
#babashka
<
2023-08-16
>
mmer08:08:08

Is it possible to use libpython with babashka? I want to be able to use the ruamel yaml parser?

borkdude08:08:24

no. babashka has clj-yaml built-in. you can shell out to python, but that's about it

mmer08:08:31

As you know I am trying to get comments from Yaml, and that parser supports it.

Ingy döt Net13:08:14

@U4C3ZU6KX fyi In my experience I have found ruamel to be a lot buggier than pyyaml, which is odd as it is a fork of pyyaml.

Ingy döt Net13:08:41

You might want to try https://www.npmjs.com/package/yaml (JS) which also has comment support and is very solid.

borkdude13:08:56

You can use that package from #C029PTWD3HR as well

borkdude13:08:50

This works with nbb but I don't see any comments:

(ns yaml.example
  (:require ["yaml" :as yaml]))

(prn (yaml/parse "- foo # this is a comment" #js {:keepSourceTokens true :commentString prn}))
The comment option isn't listed under the parse options. (https://eemeli.org/yaml/#options)

pesterhazy11:08:06

Show 'n Tell: wait for a local dynamodb instance to come up for unit tests – all with babashka family tools

🎉 4
pesterhazy11:08:11

(ns mytest.core-test
  (:require [babashka.fs :as fs]
            [babashka.process :refer [process]]
            [clojure.test :refer [deftest is]]
            [babashka.wait :as wait]))

(def project-root (-> *file* fs/absolutize fs/normalize fs/parent fs/parent))
(def !ddb-local
  (delay
    (let [p (process {:inherit true, :shutdown babashka.process/destroy-tree}
                     (str project-root "/scripts/get-ddb-local") "run")]
      (wait/wait-for-port "localhost" 8044))))
(deftest mytest
  (deref !ddb-local)
  ...)

🙌 6
🎉 2
pesterhazy11:08:37

Note the babashka libs it uses • babashka.fs for easily find the folder • babashka.process for handling a subprocess (note the beautiful shutdown hook, which is exactly what I needed) • basbshka.wait to wait until the process is ready Thanks for the great libs @U04V15CAJ

❤️ 2
2
pesterhazy11:08:14

(In fact, this test is written in Clojure, not bb, and just uses babashka.* as deps)

👍 2
til 2
pesterhazy11:08:08

It would be nicer still if clojure.test supported global fixtures (one for all tests), but delay+shutdown hook is good enough