Fork me on GitHub
#babashka
<
2021-02-26
>
Jason00:02:43

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

borkdude10:02:13

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

😎 6
wilkerlucio12:02:23

@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?

borkdude12:02:22

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

borkdude12:02:31

@wilkerlucio Already pushed to sci and bb master

wilkerlucio13:02:55

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

wilkerlucio13:02:05

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

borkdude13:02:42

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

borkdude13:02:04

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

wilkerlucio13:02:31

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

wilkerlucio13:02:26

@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 ""
                                  :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/&
    (s/cat :args ::arg-list)
    (fn arg-specs-match-param-count? [{:keys [args gspec]}]
      true)))

wilkerlucio13:02:42

something about using s/& with a pred

borkdude13:02:54

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

borkdude13:02:15

ok, cool, minimum repro at spartan.spec welcome

borkdude13:02:07

What is ::arg-list in this example?

borkdude13:02:16

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

borkdude13:02:20

I'll take a look

borkdude14:02:42

Issue fixed.

borkdude16:02:47

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

wilkerlucio13:02:13

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

nha13:02:36

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

borkdude14:02:36

@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

nha14:02:07

Thanks! I’ll have a look at parcera 🙂

borkdude14:02:50

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

nha14:02:38

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

borkdude14:02:30

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

nha15:02:07

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]
  ;; 
  (let [parsed (parcera/ast (slurp file-path))
        zloc (zip/zipper (fn [obj]
                           (and (seq? obj)
                                (some-> 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