This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-24
Channels
- # adventofcode (2)
- # anglican (1)
- # announcements (4)
- # aws (2)
- # babashka (28)
- # beginners (18)
- # brompton (3)
- # calva (22)
- # clj-kondo (2)
- # cljdoc (29)
- # clojure (41)
- # clojure-europe (28)
- # clojure-gamedev (14)
- # clojure-nl (2)
- # clojure-spec (2)
- # clojure-sweden (1)
- # clojure-uk (6)
- # clojurescript (53)
- # css (3)
- # cursive (6)
- # duct (3)
- # emacs (5)
- # fulcro (29)
- # introduce-yourself (1)
- # liberator (5)
- # lsp (1)
- # malli (11)
- # meander (4)
- # nbb (11)
- # off-topic (17)
- # pathom (2)
- # polylith (8)
- # practicalli (1)
- # react (6)
- # reagent (11)
- # releases (2)
- # rewrite-clj (11)
- # shadow-cljs (59)
- # tools-deps (21)
- # vim (11)
Humm... Is there a simple (easy) way to execute babashka scripts off of github? aka something like
#!/usr/bin/env bb
(add-classpath "") ;; has project "myutility" with src/mynamespace.clj
(require '[mynamespace])
(mynamspace/main *command-line-args* )
perhaps using bb.edn so I can pull in dependencies as needed too...
sort of like clojure's
clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.8.0"}}}' -m cljfmt.main myInputFile
but for bb.... and github...The short(ish) answer is yes, assuming you have a deps.edn file in your repo. In the same way that you can specify git deps for clj, you can do it either in bb.edn or using babashka.deps
:
(ns something
(:require [babashka.deps :as deps]))
(deps/add-deps '{:deps {io.github.bobisageek/bb-test-thing
{:git/url ""
:sha "5a7eb8fb71665cbee2c6d5c90c38ea9fda48f7a6"}}})
(require '[io.github.bobisageek.stuff :as s])
(s/do-a-thing)
... please ignore the ugliness of the code - I just threw the repo up there for a really simple repro
☝️ you can also look at the repos I posted three messages above that used git deps in a bb.edn file
I followed this recipe but the dependency resolution either didn't work or I didn't use it properly:
#!/usr/bin/env bb
(ns fmt-check
(:require [babashka.deps :as deps]))
(deps/add-deps '{:deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}})
(require '[cljfmt.main :as cljfmt])
(apply cljfmt/-main *command-line-args*)
% ./fmt-check
----- Error --------------------------------------------------------------------
Type: java.lang.Exception
Message: Unable to resolve classname: difflib.DiffUtils
Location: cljfmt/diff.clj:2:3
----- Context ------------------------------------------------------------------
1: (ns cljfmt.diff
2: (:import [difflib DiffUtils]
^--- Unable to resolve classname: difflib.DiffUtils
3: [ File]
4: [java.util.regex Pattern])
5: (:require [ :as io]
6: [clojure.string :as str]))
7:
----- Stack trace --------------------------------------------------------------
cljfmt.diff - cljfmt/diff.clj:2:3
cljfmt.main - cljfmt/main.clj:3:3
fmt-check - /Users/jconti/code/reifyhealth/fine-grained-authorization/./fmt-check:5:1
But Clojure resolves the deps and is able to run:
% clojure -Sdeps '{:deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}}' -m cljfmt.main
WARNING: Implicit use of clojure.main with options is deprecated, use -M
cljfmt [OPTIONS] COMMAND [PATHS ...]
--help
--file-pattern FILE_PATTERN \.clj[csx]?$
--indents INDENTS_PATH
--alias-map ALIAS_MAP_PATH
--project-root PROJECT_ROOT .
--[no-]ansi
--[no-]indentation
--[no-]remove-multiple-non-indenting-spaces
--[no-]remove-surrounding-whitespace
--[no-]remove-trailing-whitespace
--[no-]insert-missing-whitespace
--[no-]remove-consecutive-blank-lines
Can I make the bb repl share the same environment with current shell? eg When I export AWS_SECRET_ACCESS_KEY="5beQdsugRmMy1"
I'd like the bb repl to be aware of it.
This'd mean I have to restart the repl every time I change the variables. I am looking for a more scalable option @borkdude
Unfortunately the JVM doesn't let you change environment variables within the same process, this also applies to bb
Is there a way to 'persist' the process environment, so that i can issue repl functions calls outside of the process form?
Ok. How can I do this correctly, it fails ?
(-> (process ["export" "FOO" "1"] {:out :string}) check :out str/split-lines first)
you can find the process docs over here: https://github.com/babashka/process
Example:
$ bb -e '(keys (edn/read-string (:out @(babashka.process/process ["bb" "-e" "(System/getenv)"] {:out :string :err :string :env (assoc (select-keys (System/getenv) ["PATH"]) "FOO" "bar")}))))'
("__CF_USER_TEXT_ENCODING" "PATH" "FOO")
There is :env
which replaces the environment variables and :extra-env
which only adds environment variables (or replaces existing ones)
@borkdude are you worried that nbb would take away from adoption of babashka?
I wonder if making babashka support pluggable backends would be helpful
bb --provider=nodejs or something similar
@adam.stokes I'm not worried about that at all. bb is to Clojure JVM what nbb is to CLJS on Node.JS. A convenient fast starting environment for scripting without needed to build anything. For most things bb is sufficient, but there are sometimes situations in which a library e.g. for Excel or whatever is needed which isn't in bb, in those cases you can perhaps consider nbb.
Also bb still remains as the only true multithreaded scripting environment across any language!