[#263] add yaml library

This commit is contained in:
Michiel Borkent 2020-04-15 12:22:08 +02:00
parent c9c359e251
commit 5f914cedd1
7 changed files with 29 additions and 6 deletions

View file

@ -225,7 +225,8 @@ enumerated explicitly.
- [`clojure.data.csv`](https://github.com/clojure/data.csv) aliased as `csv` - [`clojure.data.csv`](https://github.com/clojure/data.csv) aliased as `csv`
- [`cheshire.core`](https://github.com/dakrone/cheshire) aliased as `json` - [`cheshire.core`](https://github.com/dakrone/cheshire) aliased as `json`
- [`cognitect.transit`](https://github.com/cognitect/transit-clj) aliased as `transit` - [`cognitect.transit`](https://github.com/cognitect/transit-clj) aliased as `transit`
- [`bencode.core`](https://github.com/nrepl/bencode) aliased as `bencode`: `read-bencode`, `write-bencode`. - [`clj-yaml.core`](https://github.com/clj-commons/clj-yaml) alias as `yaml`
- [`bencode.core`](https://github.com/nrepl/bencode) aliased as `bencode`: `read-bencode`, `write-bencode`
A selection of java classes are available, see `babashka/impl/classes.clj`. A selection of java classes are available, see `babashka/impl/classes.clj`.

View file

@ -9,9 +9,8 @@
org.clojure/data.csv {:mvn/version "1.0.0"}, org.clojure/data.csv {:mvn/version "1.0.0"},
cheshire {:mvn/version "5.10.0"} cheshire {:mvn/version "5.10.0"}
fipp {:mvn/version "0.6.22"} fipp {:mvn/version "0.6.22"}
com.cognitect/transit-clj {:mvn/version "1.0.324"} clj-commons/clj-yaml {:mvn/version "0.7.1"}
;; nrepl/bencode {:mvn/version "1.0.0"} com.cognitect/transit-clj {:mvn/version "1.0.324"}}
}
:aliases {:main :aliases {:main
{:main-opts ["-m" "babashka.main"]} {:main-opts ["-m" "babashka.main"]}
:profile :profile

View file

@ -61,6 +61,9 @@ $ BABASHKA_XMX="-J-Xmx4g" script/compile
Keep notes here about how adding libraries and classes to Babashka affects the binary size. Keep notes here about how adding libraries and classes to Babashka affects the binary size.
2020/03/29 Added clj-yaml for parsing and generating yaml.
45196996 - 42626884 = 2570kb added.
2020/03/28 Added java.nio.file.FileSystem(s) to support extracting zip files 2020/03/28 Added java.nio.file.FileSystem(s) to support extracting zip files
42562284 - 42021244 = 541kb added. 42562284 - 42021244 = 541kb added.

View file

@ -21,8 +21,8 @@
[org.clojure/data.csv "1.0.0"] [org.clojure/data.csv "1.0.0"]
[cheshire "5.10.0"] [cheshire "5.10.0"]
[fipp "0.6.22"] [fipp "0.6.22"]
[com.cognitect/transit-clj "1.0.324"] [clj-commons/clj-yaml "0.7.1"]
#_[nrepl/bencode "1.0.0"]] [com.cognitect/transit-clj "1.0.324"]]
:profiles {:test {:dependencies [[clj-commons/conch "0.9.2"] :profiles {:test {:dependencies [[clj-commons/conch "0.9.2"]
[com.clojure-goes-fast/clj-async-profiler "0.4.0"]]} [com.clojure-goes-fast/clj-async-profiler "0.4.0"]]}
:uberjar {:global-vars {*assert* false} :uberjar {:global-vars {*assert* false}

View file

@ -0,0 +1,11 @@
(ns babashka.impl.yaml
{:no-doc true}
(:require [clj-yaml.core :as yaml]
[sci.impl.namespaces :refer [copy-var]]
[sci.impl.vars :as vars]))
(def yns (vars/->SciNamespace 'clj-yaml.core nil))
(def yaml-namespace
{'generate-string (copy-var yaml/generate-string yns)
'parse-string (copy-var yaml/parse-string yns)})

View file

@ -28,6 +28,7 @@
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.stacktrace :refer [print-stack-trace]] [clojure.stacktrace :refer [print-stack-trace]]
[clojure.string :as str] [clojure.string :as str]
[babashka.impl.yaml :refer [yaml-namespace]]
[sci.addons :as addons] [sci.addons :as addons]
[sci.core :as sci] [sci.core :as sci]
[sci.impl.interpreter :refer [eval-string*]] [sci.impl.interpreter :refer [eval-string*]]
@ -246,6 +247,7 @@ Everything after that is bound to *command-line-args*."))
async clojure.core.async async clojure.core.async
csv clojure.data.csv csv clojure.data.csv
json cheshire.core json cheshire.core
yaml clj-yaml.core
curl babashka.curl curl babashka.curl
transit cognitect.transit transit cognitect.transit
bencode bencode.core}) bencode bencode.core})
@ -279,6 +281,7 @@ Everything after that is bound to *command-line-args*."))
'clojure.repl {'demunge demunge} 'clojure.repl {'demunge demunge}
'clojure.test t/clojure-test-namespace 'clojure.test t/clojure-test-namespace
'babashka.classpath {'add-classpath add-classpath*} 'babashka.classpath {'add-classpath add-classpath*}
'clj-yaml.core yaml-namespace
'clojure.pprint pprint-namespace 'clojure.pprint pprint-namespace
'babashka.curl curl-namespace 'babashka.curl curl-namespace
'cognitect.transit transit-namespace 'cognitect.transit transit-namespace

View file

@ -402,6 +402,12 @@
(bb nil (format "(.deleteOnExit (io/file \"%s\"))" p)) (bb nil (format "(.deleteOnExit (io/file \"%s\"))" p))
(is (false? (.exists f)))))) (is (false? (.exists f))))))
(deftest yaml-test
(is (str/starts-with?
(bb nil "(yaml/generate-string [{:name \"John Smith\", :age 33} {:name \"Mary Smith\", :age 27}])")
"-")))
(deftest statsd-client-test (deftest statsd-client-test
(is (= :success (bb nil " (is (= :success (bb nil "
(load-file (io/file \"test-resources\" \"babashka\" \"statsd.clj\")) (load-file (io/file \"test-resources\" \"babashka\" \"statsd.clj\"))