is it possible to print out the project version with lein? project.clj has (defproject my.package/foo "0.1.2-SNAPSHOT" ...) and i'd like to be able to say lein X and print out 0.1.2-SNAPSHOT
Per the Leiningen FAQ, you can do this:
(!2006)-> lein repl
...
user=> (require '[ :as io])
nil
user=> (with-open [pom-properties-reader (io/reader (io/resource "META-INF/maven/slingshot/slingshot/pom.properties"))]
#_=> (doto (java.util.Properties.)
#_=> (.load pom-properties-reader)))
{"groupId" "slingshot", "artifactId" "slingshot", "version" "0.12.2", "revision" "b0875f5caee1ebb069d4d799b71af976e04f21d8"}
user=>
(I ran this in an old Slingshot repo -- adjust the group/artifact as needed)i saw that, was hoping for an easier command. thanks
something i can call from the command line in a bash script
Unfortunately, you can't -e eval arbitrary code with lein run
There may be a plugin you can add to your user profile...? I've hardly used lein since 2015 so I'm a bit hazy.
> lein update-in :version println "!"
0.1.0-SNAPSHOT !
the extra arg seems to be necessary, and it's completely not what update-in was meant to do, but hey, I've got more cursed stuff than this running in prod, so 🤷look at that!
Haha... that's wild! Slick...
Hello 👋 I'd like to record every call to a certain function, eg: datomic.api/q. So I was thinking of wrapping it via with-redefs-fn, something like this
Nice 😄 works beautiful!!
ðŸ¤
(let [f @#'clojure.core/first]
(with-redefs-fn {#'clojure.core/first
(fn [coll]
;; My custom code
(println "Hi")
(f coll))}
(fn []
(first [1 2]))))
Which is giving me a StackOverflowError errorIs it possible to reference the old var definition from the replacement?
clojure.core is AOT compiled and direct-linked, so you can't reliably redefine its functions.
(and I strongly suspect with-redefs-fn is not thread-safe -- just like with-redefs -- and should not be used in any production code, and should only be used with great care in tests)
hi! If it is for debugging purposes in dev there is https://www.flow-storm.org/, which doesn't require any modification to your codebase and can record/inspect everything.
If it's your code that's doing the calling, you could also just write a helper/wrapper function and call that instead.
Oh, that's unfortunate. Yep, the function is not mine and I'm not running this on prod 😅
Maybe I'll take a peek at flowstorm, I was expecting to do this just from the REPL
Thanks!!
(the function I want to redefine is datomic.api/q, which I assume is probably AOT compiled too)
You can do what you want, hang on...
Haha no rush!
Handle with care...
user> (defn do-some-query!
[]
(-> (d/q '[:find ?e
:where [?e :db/txInstant]]
db)
(first)))
#'user/do-some-query!
user> (do-some-query!)
[13194143730722]
user> (let [old-q @#'datomic.query/q]
(with-redefs [datomic.query/q (fn [& args]
(println "we in there...")
(let [res (apply old-q args)]
(println "we outta there...")
res))]
(do-some-query!)))
we in there...
we outta there...
[13194143730722]
Something similar could be done with alter-var-root! as well, if one were in the mood for a more permanent change.
We were just discussing today how delightful it is that so little of datomic is direct linked. ðŸ¤