This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-07
Channels
- # adventofcode (114)
- # announcements (3)
- # aws (5)
- # babashka (62)
- # beginners (111)
- # calva (4)
- # cider (20)
- # clara (5)
- # clj-kondo (1)
- # cljs-dev (9)
- # clojure (255)
- # clojure-europe (75)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-norway (5)
- # clojure-uk (6)
- # clojuredesign-podcast (5)
- # clojurescript (34)
- # community-development (28)
- # conjure (1)
- # cursive (3)
- # data-science (1)
- # datavis (1)
- # datomic (4)
- # figwheel-main (1)
- # fulcro (14)
- # graalvm (1)
- # graphql (8)
- # integrant (4)
- # introduce-yourself (2)
- # jobs (2)
- # juxt (4)
- # kaocha (2)
- # malli (6)
- # membrane-term (53)
- # mount (2)
- # nextjournal (2)
- # off-topic (27)
- # pathom (11)
- # polylith (3)
- # portal (11)
- # reagent (4)
- # reitit (4)
- # remote-jobs (1)
- # reveal (14)
- # shadow-cljs (22)
- # tools-deps (24)
- # vim (6)
- # xtdb (19)
Hi, is it possible to use fs/delete
in conjunction with fs/glob
?
OK, just find that we can use run!
on Slack archive: https://clojurians-log.clojureverse.org/babashka/2021-05-09/1620596239.142900
O nice, clojure.core.specs.alpha also works with babashka (via spartan.spec).
user=> (require 'spartan.spec)
nil
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (require '[clojure.core.specs.alpha :as cs])
nil
user=> (s/conform ::cs/defn-args '[foo [x y z]])
{:fn-name foo, :fn-tail [:arity-1 {:params {:params [[:local-symbol x] [:local-symbol y] [:local-symbol z]]}, :body [:body []]}]}
I was discovering this while trying to run better-cond
with babashka which uses these core specs.
Work in progress. I was amazed at how little changes clojure.spec needs nowadays for bb:
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {org.babashka/spec.alpha {:git/url ""
:git/sha "cf136c8e6e83554b4d3077821e76725adc772cff"}}})
(require '[clojure.spec.alpha :as s])
(prn (s/valid? int? 1))
(require '[clojure.spec.gen.alpha :as gen])
(prn (gen/sample (s/gen int?)))
true
(0 0 0 3 2 -1 3 28 14 0)
(s/def ::name (s/and string? (complement str/blank?)))
(s/def ::street (s/and string? (complement str/blank?)))
(s/def ::street-number int?)
(s/def ::address (s/keys :req-un [::street ::street-number]))
(s/def ::contact (s/keys :req-un [::name ::address]))
(prn (gen/sample (s/gen ::contact)))
({:name "4d", :address {:street "k", :street-number 0}} ...)
:-)we're thinking about it: https://github.com/Quantisan/docker-clojure/issues/129 🙂
I don't think this exists. I would just use the base image that is most convenient for you and then install bb during your Dockerfile build. Or use a multi-state and copy from an existing one.
how do I handle situations where I have a function that receives a parameter that's a number, which I want to invoke both from code and command line?
when passing the parameter through command line invocation, I get an error since it's received as a string. If I do Integer/parseInt, then it fails when it's passed a number.
(-> p str Integer/parseInt)
seems to work for both number and strings, but wondering if there's something simpler.
@thomascpendergrast perhaps write a wrapper for the command line which calls the internal function
Now also got instrumentation working:
$ bb -cp src/main/clojure -e "
(require '[clojure.spec.alpha :as s] '[clojure.spec.test.alpha :as st])
(defn foo [x] x)
(s/fdef foo :args (s/cat :x int?))
(st/instrument 'user/foo)
(-> (try (foo :dude) (catch Exception e (ex-data e))) :clojure.spec.alpha/args)
"
(:dude)
Hi. Thanks for pushing on spec compatibility! With your work I was able to bring specmonstah to bb compatibility - https://github.com/reifyhealth/specmonstah/compare/develop...cldwalker:bb-support?expand=1 . I did find an instrument edge case that still fails - https://github.com/cldwalker/specmonstah/blob/d8db0be0259b11d6667dcfe20a94225d361c59b6/test/reifyhealth/specmonstah/core_test.cljc#L13-L17 . You can repro on that branch with bb test
I don’t have an urgency to use instrumentation here but figured I’d share in case you’re interested
@U08ALHZ2N I think I just fixed that one on babashka/spec.alpha master
but it does require the bb from master now - you can download from #babashka-circleci-builds
With master@ef8e4f48b9312226c5e0d200c43b2d72a9b0d187 I still see the same failure e.g.
ERROR in (test-spec-gen) (/Users/me/code/world/specmonstah/test/reifyhealth/specmonstah/spec_gen_test.cljc:43)
Uncaught exception, not in assertion.
expected: nil
actual: java.lang.IllegalArgumentException: No matching method applyTo found taking 1 args for class sci.impl.fns$fun$arity_3__7291
at sci.impl.Reflector.invokeMatchingMethod (Reflector.java:132)
sci.impl.interop$invoke_instance_method.invokeStatic (interop.cljc:28)
sci.impl.evaluator$eval_instance_method_invocation.invokeStatic (evaluator.cljc:209)
sci.impl.analyzer$expand_dot$fn__8708.invoke (analyzer.cljc:723)
sci.impl.evaluator$eval.invokeStatic (evaluator.cljc:334)
sci.impl.evaluator$eval.invoke (evaluator.cljc:328)
sci.impl.evaluator$eval_try.invokeStatic (evaluator.cljc:150)
sci.impl.analyzer$analyze_try$fn__8664.invoke (analyzer.cljc:616)
sci.impl.evaluator$eval.invokeStatic (evaluator.cljc:334)
sci.impl.evaluator$eval.invoke (evaluator.cljc:328)
https://github.com/babashka/spec.alpha/commit/4b76776ca84403555dc03cbf7fc285ebfe3907ec
With this spec.alpha fork, is there a way to fix clojure.lang.ExceptionInfo: Could not find namespace: clojure.core.specs.alpha
? I encountered this while trying to use better-cond with latest masters. I see the remove-clojure hack in https://github.com/babashka/babashka/issues/743 but that seems kinda gross
babashka applies this gross hack itself because the clojure spec alpha wasn't compatible with bb. but the core specs are. you can get those by doing:
bb -cp $(clojure -Spath)
instead. Thanks for reminding me, I will remove this hack for the core specs. Not for spec itself.This is what's in babashka:
(defn add-deps
"Takes deps edn map and optionally a map with :aliases (seq of
keywords) which will used to calculate classpath. The classpath is
then used to resolve dependencies in babashka."
([deps-map] (add-deps deps-map nil))
([deps-map {:keys [:aliases :env :extra-env :force]}]
(when-let [paths (:paths deps-map)]
(cp/add-classpath (str/join cp/path-sep paths)))
(when-let [deps-map (not-empty (dissoc deps-map :paths :tasks :raw :min-bb-version))]
(let [deps-map (assoc-in deps-map [:aliases :org.babashka/defaults]
'{:replace-paths [] ;; babashka sets paths manually
:classpath-overrides {org.clojure/clojure ""
org.clojure/spec.alpha ""
org.clojure/core.specs.alpha ""}})
args (list "-Srepro" ;; do not include deps.edn from user config
"-Spath" "-Sdeps" (str deps-map)
"-Sdeps-file" "") ;; we reset deps file so the local deps.edn isn't used
args (if force (cons "-Sforce" args) args)
args (concat args [(str "-A:" (str/join ":" (cons ":org.babashka/defaults" aliases)))])
cp (with-out-str (binding [deps/*env* env
deps/*extra-env* extra-env]
(apply deps/-main args)))
cp (str/trim cp)
cp (str/replace cp (re-pattern (str cp/path-sep "+$")) "")]
(cp/add-classpath cp)))))
And we probably don't always want the core specs on the classpath, unless it's explicitly provided
With ~/Downloads/bb -cp $(clojure -Spath) test
, I encounter Could not resolve symbol: clojure.lang.Compiler/demunge
. I’m guessing this is because it picks up the original spec.alpha. Is there a way to use the forked spec.alpha with core specs?
like this:
$ rlwrap bb -cp $(clojure -Spath -Sdeps '{:deps {borkdude/spartan.spec {:git/url ""
:sha "12947185b4f8b8ff8ee3bc0f19c98dbde54d4c90"}}}')
but then with babashka/spec.alphaAh gotcha. ~/Downloads/bb -cp $(clojure -Spath -Sdeps '{:deps {org.babashka/spec.alpha {:git/url "
does work. I’ll probably avoid using better-cond for now as it’s not worth making specmonstah folks use this workaround on every bb invocation
clojure.tools.deps.alpha.script.make-classpath2
stubbornly adds clojure itself to the deps
@U08ALHZ2N What I could do is: do not remove these deps if you explicitly mention core.specs
in your deps map
@U08ALHZ2N what do you think?
borkdude@MBP2019 /tmp/test $ clojure -M:babashka/dev -e "(babashka.classpath/get-classpath)"
"/Users/borkdude/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar"
borkdude@MBP2019 /tmp/test $ cat bb.edn
{:deps {org.clojure/core.specs.alpha {:mvn/version "RELEASE"}}}
Great idea. Tried with latest master and org.clojure/core.specs.alpha {:mvn/version "0.2.62"}
and better-cond works great with passing tests. Thanks again!
If there’s somewhere you’d like core.specs.alpha usage documented happy to submit a PR later
I also added a message in the output about using babashka/spec.alpha when you require clojure.spec.alpha and it isn't there
$ bb -e "(require '[clojure.spec.alpha])"
[babashka] WARNING: Use the babashka-compatible version of clojure.spec.alpha, available here:
----- Error --------------------------------------------------------------------
Type: java.lang.Exception
Message: Could not find namespace: clojure.spec.alpha.
Location: 1:1
@U08ALHZ2N When I try to run reifyhealth.specmonstah.core-test
with babashka, I get an error about clojure.lang.Sorted
- does that ring a bell?