clojure

Don Waldhalm 2026-02-13T22:08:01.628059Z

I'm working on a pandoc filter that executes clojure within Code and CodeBlock ASTs (gated and in-line "verbatim" parts of the pandoc markdown). Its going pretty OK, but now I'd like to load any dependencies from the 'deps.edn' (should it exist) in the directory from which pandoc was called. I'm struggling to take contextless, repl-less clojure code and load-up deps.edn. any advice?

teodorlu 2026-02-14T08:30:12.549319Z

Carsten is right, the clojure cli tool loads the deps.edn file from the folder it's executed in. You'll control the deps.edn file by controlling that folder. If you want to change it, you'll need a script as your pandoc filter, which then calls the clojure clifrom your folder of choice.

2026-02-13T22:44:46.182309Z

I assume that "pandoc" calls "clojure xxx", correct ? If so it need to so setting the working directory to the dir where "deps.edn" is. Is it like that ?

Don Waldhalm 2026-02-13T22:45:28.247789Z

that's right

Don Waldhalm 2026-02-13T22:46:27.674489Z

in my examples, I can have deps.edn and the pandoc call in the same directory, so I don't think the problem is that I can't find deps.edn, but that I don't know what to do with deps.edn if/when I have it

2026-02-13T22:47:55.172459Z

"you" do nothing with deps.edn, the clojure CLI uses it to construc teh classpath (if exiting in 'current dir', which at the end he "caller of 'clojure' controls)

2026-02-14T00:24:23.641939Z

I wonder if clj-mcp-light might be of help here. I have used it with success before with pandoc filter system. https://github.com/bhauman/clojure-mcp-light

Don Waldhalm 2026-02-13T22:11:17.754579Z

I can run these in my CodeBlocks (require '[clojure.repl :refer :all] '[clojure.string :as str] ) but not this: (require '[some.randomthingfromdeps :as harder])

p-himik 2026-02-14T12:31:50.972639Z

What exactly did you do and what was the error?

p-himik 2026-02-13T22:45:40.383599Z

Never worked with Pandoc, so no idea. But what does (-> (System/getProperty "java.class.path") (clojure.string/split #":")) output?

Don Waldhalm 2026-02-13T22:49:43.750719Z

["../ clojure_pandoc_filter/projects/rcf/target/rcf.jar"]

p-himik 2026-02-13T23:00:15.948219Z

And (System/getProperty "user.dir")?

Don Waldhalm 2026-02-13T23:01:59.799459Z

/home/don/Desktop/git/delivery_kick_v_brooksher

Don Waldhalm 2026-02-13T23:02:17.246979Z

this is the directory containing the deps.edn I'd like to recognize and sync

p-himik 2026-02-13T23:03:21.329069Z

Oh, wait, brain farts - 1 AM here. Looking up deps.edn is separate from the classpath. When you launch a REPL via clj and there's no cache, it's done in two steps: 1. Find deps.edn and compute the classpath 2. Launch the actual process with that classpath So unless there's that step (1), nothing will compute the classpath. So either you have to wrap pandoc with something that does (1) and then launches pandoc with the right classpath (assuming it's even possible), or you have to inject things into the classpath dynamically.

p-himik 2026-02-13T23:05:13.733429Z

You might have some luck with clojure.repl.deps/sync-deps, but I don't know how it looks up deps.edn. I'd guess that it will work just as is, without you having to do anything. Just try calling (clojure.rep.deps/sync-deps).

Don Waldhalm 2026-02-13T23:06:18.231309Z

thanks, I'll try sync-deps

Don Waldhalm 2026-02-13T23:31:02.332679Z

I get a macro expanding error with sync-deps. I was hacking at the https://github.com/clojure/tools.deps/blob/master/src/main/clojure/clojure/tools/deps.clj earlier, but don't understand it well enough to get it working. I recognize "compute the classpath" from that. I was able to find a deps.edn, resolve the dependencies, get a map that looks like all the right stuff (maven paths, ect), but I don't know what to do with it...what's the end-game for making a dependency "here"

Don Waldhalm 2026-02-15T15:46:34.386459Z

Thanks for the help. I did finally figure this out, I think. This lets me send arbitrary code to my pandoc filter (a jar file, who's ClassLoader is not dynamic).

(ns com.raw-digital.transformer.dynamic-deps
  (:require
    [clojure.tools.deps :as deps]
    [clojure.tools.deps.edn :as dedn]
    [ :as io]
    [clojure.repl :refer [dir doc]] 
    [clojure.tools.deps.util.maven :as mvn]))

(defn resolve-arbitrary-deps!
  "use standard maven repos to fetch any deps we don't already have"
  [deps-edn-path]
  (let [my-deps (dedn/read-deps  deps-edn-path)]
    (deps/resolve-deps (assoc my-deps :mvn/repos mvn/standard-repos) nil)))

(defn get-loader []
  (let [current-loader (.. Thread currentThread getContextClassLoader)]
    (if (instance? clojure.lang.DynamicClassLoader current-loader)
      current-loader
      (let [dyn (clojure.lang.DynamicClassLoader. )] 
        (.setContextClassLoader (Thread/currentThread) dyn)
        dyn))))

(defn load-arbitrary-deps! 
  "load any deps.edn file into the current thread's classpath, as if it had been launched with that deps.edn"
  [deps-edn-path]
  (let [cp-roots (:classpath-roots (deps/calc-basis (dedn/read-deps deps-edn-path))) 
        loader (get-loader)] 
    (doseq [path cp-roots]
      (.addURL loader (-> path io/as-file .toURI .toURL)))))

(defn use-deps! [deps-edn-path]
  (do (resolve-arbitrary-deps! deps-edn-path)
      (load-arbitrary-deps! deps-edn-path)))