This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-28
Channels
- # announcements (1)
- # babashka (40)
- # beginners (228)
- # cider (9)
- # clara (6)
- # clojure (68)
- # clojure-uk (13)
- # clojuredesign-podcast (5)
- # clojurescript (9)
- # core-typed (1)
- # cursive (1)
- # duct (2)
- # emacs (9)
- # fulcro (18)
- # graalvm (11)
- # hyperfiddle (1)
- # malli (2)
- # off-topic (33)
- # re-frame (9)
- # reagent (3)
- # reitit (15)
- # shadow-cljs (6)
- # tools-deps (1)
so this is useful
with a deps.edn like this:
{:paths []
:deps {clj-http-lite {:git/url ""
:sha "64530ded30d107b1834c3a704f2e087c3324bff9"}}
:aliases {:depstar
{:extra-deps
{seancorfield/depstar {:mvn/version "0.3.4"}}}}}
you can run:
clojure -A:depstar -m hf.depstar.jar deps.jar
to build a thin jar with just clj-http-lite in it
$ unzip -l deps.jar
Archive: deps.jar
Length Date Time Name
--------- ---------- ----- ----
0 12-27-2019 22:13 clj_http/
0 12-27-2019 22:13 clj_http/lite/
2397 12-27-2019 19:00 clj_http/lite/util.clj
2068 12-27-2019 19:00 clj_http/lite/links.clj
3651 12-27-2019 19:00 clj_http/lite/core.clj
9608 12-27-2019 19:00 clj_http/lite/client.clj
--------- -------
17724 6 files
and then you can set the classpath for babashka accordingly:
BABASHKA_CLASSPATH=`pwd`/deps.jar bb "(require '[clj-http.lite.client :as client]) (:status (client/get \"\"))"
which will return 200
I'm betting there's some clever way to include the jar in a babashka script but I haven't figured it out yet
like maybe uuencode/decode to a tmp directory and then set the classpath
ok I made it work but wow is it ugly https://gist.github.com/nate/4ed220b2438b338c4a2e1c0186a1f90e
@nate_clojurians as an alternative you can probably build a script which inlines all namespaces into a single file
@nate_clojurians I've got an experimental thing here: Mac: https://2917-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-macos-amd64.zip Linux: https://2915-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-linux-amd64.zip
$ export BABASHKA_CLASSPATH="$(clojure -Sdeps '{:deps {clj-http-lite {:git/url "" :sha "f44ebe45446f0f44f2b73761d102af3da6d0a13e"}}}' -Spath)"
$ lein bb --uberscript "(require '[clj-http.lite.client :as client]) (:status (client/get \"\"))"
200
This will put all the required namespaces into one single file in /tmp/uberscript.clj
. Now you can:
$ bb /tmp/uberscript.clj
200
ooooh very cool
How do I truncate a number e.g. 52.51029159197582
to two decimal places e.g. 52.51
in babashka?
e.g. (clojure.pprint/cl-format nil "~,2f" 52.51029159197582)
won't work
@slack.jcpsantiago I think you can do this with format
@nate_clojurians New version:
$ bb --classpath test-resources/babashka/src_for_classpath_test -m my.main --uberscript /tmp/script.clj
$ bb /tmp/script.clj 1 2 3
("1" "2" "3")
Linux: https://2921-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-linux-amd64.zip
Mac: https://2923-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-macos-amd64.zipDemo:
$ # create project sources
$ mkdir -p project/src
$ echo "(ns project-impl) (defn foo [] ::foo)" > project/src/project_impl.clj
$ echo "(ns project-main (:require [project-impl])) (defn -main [& args] (project-impl/foo))\n" > project/src/project_main.clj
$ #
$ # run with bb using classpath
$ bb --classpath project/src -m project-main
:project-impl/foo
$ #
$ # create uberscript
$ bb --classpath project/src -m project-main --uberscript uberscript.clj
$ cat uberscript.clj
(ns project-impl) (defn foo [] ::foo)
(ns project-main (:require [project-impl])) (defn -main [& args] (project-impl/foo))
(ns user (:require [project-main])) (apply project-main/-main *command-line-args*)% $ #
$ # run uberscript
$ bb uberscript.clj
:project-impl/foo
Using deps.clj (https://github.com/borkdude/deps.clj/):
deps.edn: {:aliases {:script {:main-opts ["-m project-main"]}}}
$ deps.exe -A:script -Scommand "bb --classpath {{classpath}} {{main-opts}} --uberscript uberscript.clj"
$ bb uberscript.clj
:project-impl/foo
ooooh very cool
Note that when you already have babashka on your system, installing deps.clj is trivial:
$ curl -sL -o /tmp/deps.clj && chmod +x /tmp/deps.clj
$ /tmp/deps.clj
Clojure 1.10.1
It only assumes a working java
installation, nothing else.Updated the quickstart, rationale and install sections for deps.clj: https://github.com/borkdude/deps.clj/blob/master/README.md#quickstart
Babashka v0.0.51 released, which adds the --uberscript
option: https://github.com/borkdude/babashka/blob/master/README.md#uberscript
I made this of it:
(require '[clojure.string :as str])
(defn get-path []
(System/getenv "PATH"))
(defn report-dups
[coll]
(reduce
(fn [acc next]
(if (contains? acc next)
(do
(println "Duplicate PATH entry" next )
acc)
(conj acc next)))
#{}
coll)
nil)
(as-> (get-path) $
(str/split $ (re-pattern (System/getProperty "path.separator")))
(report-dups $))
and it helped me find that have accidentally doubled my entire PATH string somewherenice!