Fork me on GitHub
#tools-deps
<
2022-06-11
>
pyr07:06:51

I couldn't find whether this was discussed before, but it feels a bit odd that aliases cannot hint at their preferred call structure and that is a peculiarity the caller has to know about (i.e: -M vs. -X). I suppose this stems from the fact that there's only so much the large bash wrapper can figure out, right? Or let me rephrase: if there was a way for tools to hint at their preferred calling convention, would a clojure cli flag honoring that be considered?

Alex Miller (Clojure team)13:06:37

Not sure I understand what the request is at the end

borkdude14:06:42

@U06V097TP The usual solution to this is to use a task manager thing like Makefile, or https://book.babashka.org/#tasks`bb.edn`

seancorfield20:06:43

@U06V097TP An alias can contain both :main-opts and :exec-fn so its behavior depends on whether you use -X or -M. Generally tho', looking at the alias in deps.edn tells you which usage it expects: :main-opts implies -M, :exec-fn or :exec-args or :ns-default implies -X. Given my first point, usage could not be inferred however.

seancorfield20:06:44

If an alias contains :extra-deps and :exec-fn, you can still use it with -M and it will bring in those deps but then expect you to provide main opts somewhere else, either via other aliases in combination or on the command-line.

seancorfield20:06:37

Similarly, if an alias contains :extra-deps and :main-opts, you can still use it with -X and it will bring in those deps but then expect you to provide exec opts somewhere else, either via other aliases in combination or on the command-line.

seancorfield20:06:25

For a long time, my dot-clojure deps.edn file had aliases with both :exec-fn and :main-opts so you could invoke certain tools with either -X or -M (and so you got to choose how to provide command-line arguments). And that's another reason why the tool can't decide for you: clojure -[X or M]:some-alias :arg '{:value 42}' -- those arguments will be read as EDN and put into a hash map if you use -X but they'll be treated as strings if you use -M.

Sam Ritchie16:06:27

question - when I use create-basis in tools.build to create a basis and pass it to pom, it looks like that command adds org.clojure/clojure to the pom. i THINK I don’t want to do this, but instead let the user specify their Clojure version — so 1. is that correct? and 2. what is the best way to prevent tools.build from adding this dep?

Alex Miller (Clojure team)16:06:35

Clojure is defined as a dep in the root deps.edn. If you want to not include the root, you can pass :root nil to create-basis

Alex Miller (Clojure team)16:06:04

Whether you want to do that is hard for me to answer :)

Alex Miller (Clojure team)16:06:24

You do need something to declare a dep on Clojure or you can't run Clojure programs

Sam Ritchie17:06:14

@U064X3EF3 I had been browsing and seen many library that didn’t declare the dep at all, which made me think folks have settled on providing clj and cljs scoped as "provided"

Sam Ritchie17:06:55

which is eminently reasonable (that is how it should be done ALWAYS for cljs I’d say). but an explicit Clojure dep makes sense too obviously, at the lowest version you can support

Alex Miller (Clojure team)17:06:25

I think not specifying is a reasonable choice for libraries

Alex Miller (Clojure team)17:06:05

but I understand the many reasons libs do specify one

Alex Miller (Clojure team)17:06:23

the important thing is that ultimately some app is going to make the choice anyways

Sam Ritchie16:06:11

etaoin for example https://clojars.org/etaoin does not declare org.clojure/clojure as a dependency, but I don’t see an obvious spot where this is excluded: https://github.com/clj-commons/etaoin/blob/master/build.clj

lread16:06:05

Warning @sritchie09 that build.clj is pretty new and has not been used for a real release yet! As far as I understand it, I think the best practice is for a library to explicitly depend on the minimum Clojure version required for the lib. https://clojars.org/rewrite-clj/versions/1.1.45.

lread16:06:40

(If that’s what you are wondering about?)

lread16:06:18

An app writer will typically specify clojure as a dep overriding any library clojure deps.

Sam Ritchie17:06:22

@lee okay that makes sense! and in that case that is easy to manage

lread17:06:26

I find it especially nice in deps.edn because dep resolution seems simple, clean and intuitive to me when compared to lein deps resolution (which maybe I really just haven’t taken the time to understand).