Fork me on GitHub
#tools-deps
<
2019-12-11
>
borkdude13:12:40

it is possible to generate a classpath without clojure and spec itself on it?

borkdude13:12:23

e.g. here:

$ clojure -Srepro -Sdeps '{:deps {myscript {:git/url "" :sha "89f66ba2101180a98acf88441693840875288ec9"}}}' -Spath
I want only the git dep to be on the classpath

borkdude13:12:42

but I'm getting:

src:/Users/borkdude/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar:/Users/borkdude/.gitlibs/libs/myscript/myscript/89f66ba2101180a98acf88441693840875288ec9:/Users/borkdude/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/Users/borkdude/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar

borkdude13:12:31

I want to use tools.deps to create a classpath and download deps for a clojure interpreter tool I'm writing

alexmiller13:12:40

Via clj, no (due to the install deps.edn). Via tools.deps, yes.

borkdude13:12:04

so I'd have to write my own tool that uses tools.deps as a lib? ah

alexmiller13:12:31

clj is a Clojure runner

alexmiller13:12:48

It assumes you’re using Clojure

borkdude13:12:34

btw I could see this feature be useful for other environments like self-hosted Clojure / planck, which is already using the clojure like this

borkdude13:12:50

I'll ask in their channel how they solve this "problem" (more of an optimization really)

alexmiller13:12:51

You can run tools.deps from clj btw - there is a built in alias for it -A:deps

alexmiller13:12:00

It’s not exactly a 1 liner but the tools are there (really depends precisely on what you want to do)

borkdude14:12:38

I'll figure something out. Btw, dirty hack: {:deps {org.clojure/clojure {:local/root "."}}}

alexmiller14:12:20

really ugly 1-liner:

alexmiller14:12:24

clj -A:deps -e "(println ((requiring-resolve 'clojure.tools.deps.alpha/make-classpath) ((requiring-resolve 'clojure.tools.deps.alpha/resolve-deps) {:deps {'org.ow2.asm/asm {:mvn/version \"7.2\"}} :mvn/repos @(requiring-resolve 'clojure.tools.deps.alpha.util.maven/standard-repos)} nil) nil nil))"

alexmiller14:12:44

prints to stdout /Users/alex/.m2/repository/org/ow2/asm/asm/7.2/asm-7.2.jar

alexmiller14:12:03

asm just used as an example

alexmiller14:12:09

you could also slurp from deps.edn or whatever (some tools for that stuff in clojure.tools.deps.alpha.reader)

borkdude15:12:22

nice, thanks!

borkdude15:12:18

I think I'll just use the existing tools though, the entire tooling is already there, caching and all, it'd be a lot of work and error-prone to replicate this. I'll just skip over some known deps that aren't interesting for the interpreter

borkdude15:12:15

The idea is that the interpreter is a drop-in replacement for a program you can otherwise run with normal Clojure (give or take some reader conditionals)

borkdude15:12:41

so re-using most of what's there makes also sense from that perspective

alexmiller15:12:30

gotcha - to some degree the :classpath-overrides alias option is a good match for this

alexmiller15:12:48

you could just override the classpath part for org.clojure/clojure to nothing

alexmiller15:12:28

I guess you'd need to also do clojure's deps though

alexmiller15:12:32

clj -Sdeps '{:aliases {:bye {:classpath-overrides {org.clojure/clojure "" org.clojure/spec.alpha "" org.clojure/core.specs.alpha ""}}}}' -A:bye -Spath

borkdude15:12:59

{:aliases {:babashka {:classpath-overrides {org.clojure/clojure nil
                                            org.clojure/spec.alpha nil
                                            org.clojure/core.specs.alpha nil}}}}
$ clj -C:babashka -Spath
src:::

alexmiller15:12:08

I should probably be killing the nils in there :)

alexmiller15:12:09

committed that fix for whenever I do next release

borkdude15:12:15

maybe remove empty?

borkdude15:12:23

instead of remove nil? so empty strings are also "killed"

alexmiller15:12:40

well, would use str/blank? for that case

alexmiller15:12:52

imo it's bad form to seq-ize strings with empty? vs using a string-specific predicate

borkdude16:12:43

awesome 🙂

borkdude16:12:46

Not that I need it right now, but it is possible to override the tools.deps version for the clojure tool to a git dep on master?

alexmiller16:12:48

no, not without hacking the script

alexmiller16:12:10

hacking works fine though, I test stuff that way all the time :)

alexmiller16:12:18

I guess maybe for this use of -A:deps, you might be able to use :override-deps or :classpath-overrides to make that work

alexmiller16:12:40

that is, there is no hook to affect the classpath of the jvm run that uses tools.deps.alpha to make the classpath, but you could use the existing alias modifiers to change the classpath of the program you're running if it uses tools.deps.alpha