babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Jason 2021-02-26T00:26:43.111400Z

Is there a way to gt bb to report in a way that refactor-nrepl undersands? I RTFM. Sorry about the noise.

borkdude 2021-02-26T10:08:13.113900Z

Made this experimental malli pod. https://github.com/babashka/pod-babashka-malli

(prn (m/validate [:cat 'int? 'int?] [1 1]))
;; => true

(prn (me/humanize [:cat 'int? 'int?] [1 :foo]))
;; => [nil ["should be an int"]]
$ time bb test.clj
true
[nil ["should be an int"]]
bb test.clj   0.01s  user 0.01s system 51% cpu 0.049 total

😎 2
wilkerlucio 2021-02-26T12:01:23.114700Z

@borkdude next one

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: force
Location: /Users/wilkerlucio/Development/guardrails/src/main/com/fulcrologic/guardrails/core.cljc:49:8
Phase:    analysis

----- Context ------------------------------------------------------------------
45:   (let [{:keys [level ?err msg_ ?ns-str ?file hostname_
46:                 timestamp_ ?line]} data]
47:     (str
48:       (string/upper-case (name level)) " "
49:       (force msg_)
           ^--- Could not resolve symbol: force
50:       (when-let [err ?err]
51:         (str "\n" (utils/stacktrace err))))))
52:
53: (defn now-ms [] #?(:clj  (System/currentTimeMillis)
54:                    :cljs (inst-ms (js/Date.))))
That's also a case of juts adding to https://github.com/wilkerlucio/sci/blob/master/src/sci/impl/namespaces.cljc?

borkdude 2021-02-26T12:02:22.115200Z

I'm really surprised that one isn't in there yet. Yes, please add it.

borkdude 2021-02-26T12:59:31.115500Z

@wilkerlucio Already pushed to sci and bb master

wilkerlucio 2021-02-26T13:00:55.115700Z

thanks, was about to make it, but you got there faster 🙂

wilkerlucio 2021-02-26T13:12:05.116500Z

humm, this time I got an error, but that's not pointing to where it happens:

----- Error --------------------------------------------------------------------
Type:     java.lang.UnsupportedOperationException
Message:  nth not supported on this type: Symbol

wilkerlucio 2021-02-26T13:12:13.116800Z

is there a verbose/debug way to run to get more details?

borkdude 2021-02-26T13:13:42.117Z

Can you make a repro repo for me where I can test this out locally? Usually I discover this by bisecting the code

borkdude 2021-02-26T13:14:04.117200Z

I'm not sure why the location is missing here. Could be the result of a macro-expansion that is failing to execute

wilkerlucio 2021-02-26T13:14:31.117400Z

I'm doing that bisect myself, find the file already at least 🙂

wilkerlucio 2021-02-26T13:20:26.117700Z

@borkdude I believe I found in something related to spartan, this code breaks:

(ns demo
  (:require [babashka.deps :as deps]))

(deps/add-deps
  '{:deps {borkdude/spartan.spec {:git/url "<https://github.com/borkdude/spartan.spec>"
                                  :sha     "bf4ace4a857c29cbcbb934f6a4035cfabe173ff1"}}})

;; Loading spartan.spec will create a namespace clojure.spec.alpha for compatibility:
(require 'spartan.spec)
(alias 's 'clojure.spec.alpha)

(s/def ::args+gspec+body
  (s/&amp;
    (s/cat :args ::arg-list)
    (fn arg-specs-match-param-count? [{:keys [args gspec]}]
      true)))

wilkerlucio 2021-02-26T13:20:42.117900Z

something about using s/&amp; with a pred

borkdude 2021-02-26T13:21:54.118100Z

I can reproduce this with:

$ bb -e "(defmacro foo [] \`(do [(nth (symbol :dude) 0)])) (foo)"
----- Error --------------------------------------------------------------------
Type:     java.lang.UnsupportedOperationException
Message:  nth not supported on this type: Symbol
I mean, the location issue. This is a general problem with macro generated code, there are no locs

borkdude 2021-02-26T13:22:15.118300Z

ok, cool, minimum repro at spartan.spec welcome

wilkerlucio 2021-02-26T13:25:10.118500Z

https://github.com/borkdude/spartan.spec/issues/19

borkdude 2021-02-26T13:28:07.118800Z

What is ::arg-list in this example?

borkdude 2021-02-26T13:33:16.119Z

btw, the bug seems related to the name in the function predicate

borkdude 2021-02-26T13:33:20.119200Z

I'll take a look

2021-02-26T13:59:36.120400Z

Should rewrite-clj work in babshka?

(deps/add-deps '{:deps {borkdude/rewrite-edn {:mvn/version "0.0.1-alpha.2"}}})
(require '[borkdude.rewrite-edn :as r])
results in an error - seems like .cljc files are not supported?
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Could not find namespace: rewrite-cljc.node.
Location: borkdude/rewrite_edn/impl.cljc:3:3

----- Context ------------------------------------------------------------------
1: (ns borkdude.rewrite-edn.impl
2:   (:refer-clojure :exclude [assoc update assoc-in update-in])
3:   (:require [rewrite-cljc.node :as node]
     ^--- Could not find namespace: rewrite-cljc.node.
4:             [rewrite-cljc.zip :as z]))
5:
6: (defn maybe-right [zloc]
7:   (if (z/rightmost? zloc)
8:     zloc

borkdude 2021-02-26T14:00:42.120500Z

Issue fixed.

borkdude 2021-02-26T14:02:36.121400Z

@nha - rewrite-clj itself doesn't work with babashka. - .cljc files are supported To manipulate code with babashka I recommend using: - https://github.com/babashka/pod-registry/blob/master/examples/parcera.clj

2021-02-26T14:03:07.121900Z

Thanks! I’ll have a look at parcera 🙂

borkdude 2021-02-26T14:10:50.122500Z

rewrite-clj is quite convenient, maybe one day we could have a sci-based CLI dedicated to it :)

2021-02-26T14:13:38.123300Z

it is 🙂 parcera looks overkill for me as I am just doing some light editing of deps.edn files

borkdude 2021-02-26T14:15:30.123800Z

just use rewrite-edn from the JVM I'd say then

2021-02-26T15:09:07.124500Z

I ended up hacking something with parcera btw:

(defn replace-version
  "for deps.edn files
  ex.
  (replace-version \"com.turtlequeue/java-sdk\" \"(str root-dir \"/quickstart/clj/deps.edn\")\" \"1.0.0\")"
  [artefact file-path version]
  ;; <https://github.com/babashka/pod-babashka-parcera/blob/master/examples/zipper.clj>
  (let [parsed (parcera/ast (slurp file-path))
        zloc (zip/zipper (fn [obj]
                           (and (seq? obj)
                                (some-&gt; obj second first keyword?)))
                         rest
                         (fn [node children]
                           (list* (first node) children))
                         (second parsed))

        res (loop [zloc zloc
                   st {:name-found? false
                       :mvn-version-found? false}]
              (if-not (zip/end? zloc)
                (let [node (zip/node zloc)]
                  #_(when-not (= :whitespace (first node))
                      (prn node)
                      (prn (parcera/code node))
                      (println "STATE " st))
                  (cond
                    (= (list :symbol artefact) node)
                    (recur (zip/next zloc)
                           (assoc st :name-found? true))

                    (and
                      (:name-found? st)
                      (= '(:keyword ":mvn/version") node))
                    (recur (zip/next zloc)
                           (assoc st :mvn-version-found? true))

                    (and (:name-found? st)
                         (:mvn-version-found? st)
                         (seq node)
                         (= :string (first node))
                         (string? (second node))
                         (= 2 (count node)))
                    (parcera/code (zip/root (zip/replace zloc (list :string (str "\"" version "\"")))))

                    :default
                    (recur (zip/next zloc) st)))
                (do
                  (warn "Version not found for " artefact " " file-path " " version)
                  (parcera/code (zip/root zloc)))))]
    (spit file-path res)))
good enough for what I’m doing

borkdude 2021-02-26T15:11:07.124700Z

cool!

1
wilkerlucio 2021-02-26T15:58:11.124900Z

😄

borkdude 2021-02-26T16:09:47.125100Z

Fixed by removing an old hack and replacing it with spec's original code because things have been improving ;)

wilkerlucio 2021-02-26T23:16:38.126300Z

can I do this with babashka? https://github.com/wilkerlucio/cljc-misc/blob/73844cee606e5fe22f7ab24b7100415090bd5a1d/src/main/com/wsscode/misc/refs.cljc#L29-L44 if I can, how can I reference the Atom class to extend it?