sicmutils icon indicating copy to clipboard operation
sicmutils copied to clipboard

add a "version" variable that the API can query from the REPL

Open sritchie opened this issue 4 years ago • 0 comments

It would be lovely if Nextjournal and friends had some sicmutils-version variable inside env that they could query to figure out what is actually running! I'm not sure of the best pattern here. Does anyone have any pointers?

Clojure

Here is how to do it on the JVM, modeled after *clojure.core/clojure-version*:

(let [version-string (slurp (.getResourceAsStream
                             (clojure.lang.RT/baseLoader)
                             "SICMUTILS_VERSION"))
      [_ major minor incremental qualifier snapshot]
      (re-matches
       #"(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9_]+))?(?:-(SNAPSHOT))?"
       version-string)
      version {:major       (Integer/valueOf ^String major)
               :minor       (Integer/valueOf ^String minor)
               :incremental (Integer/valueOf ^String incremental)
               :qualifier   (if (= qualifier "SNAPSHOT") nil qualifier)}]
  (def ^:dynamic *sicmutils-version*
    (if (.contains version-string "SNAPSHOT")
      (assoc version :interim true)
      version)))

sritchie avatar Feb 18 '21 18:02 sritchie