tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
alexmiller 2021-06-10T20:17:25.168100Z

New prerelease of Clojure CLI 1.10.3.875: • New: support for specifying multiple functions with -X with -> semantics • https://clojure.atlassian.net/browse/TDEPS-182 - Improve deprecation message to be more accurate • https://clojure.atlassian.net/browse/TDEPS-183 - Fix -Sdescribe output to be valid edn on Windows • https://clojure.atlassian.net/browse/TDEPS-179 - Fix incorrect classpath when :classpath-overrides removes path

1
1
🚀 4
2
seancorfield 2021-06-10T20:21:36.169100Z

Awesome! Can you point me to an example of how that new -X stuff works? Is it literally just -X:myalias foo.bar/fn1 foo.bar/fn2 some.other/thing and each should take a hash map and return a hash map?

alexmiller 2021-06-10T20:22:06.169900Z

yes

seancorfield 2021-06-10T20:22:19.170400Z

What happens if any of them return nil? Does exec just pass the original input hash map into the next function, or does it end up passing nil?

alexmiller 2021-06-10T20:22:26.170600Z

well importantly, the first function gets the kvs from the exec-args/ cli

alexmiller 2021-06-10T20:22:50.171100Z

it's like ->, so if one function returns nil, the next gets nil

seancorfield 2021-06-10T20:24:27.171900Z

Ah, so that also means that the functions in the 2nd pos on don’t need to take hash maps, right? It could be any data produced from the earlier fns?

alexmiller 2021-06-10T20:25:10.172100Z

I suppose :)

alexmiller 2021-06-10T20:25:42.173Z

I will not claim that this is fully baked yet, so I reserve the right to change my answer before it becomes a stable release :)

seancorfield 2021-06-10T20:25:43.173100Z

(I’m already imagining how folks like @borkdude might think of abusing this 🙂 )

1
👀 1
seancorfield 2021-06-10T20:25:58.173300Z

evil chuckle

😈 2
dpsutton 2021-06-10T20:32:11.173500Z

that seems really interesting

dpsutton 2021-06-10T20:32:44.174Z

with low startup time that makes bash very close to a useable repl

alexmiller 2021-06-10T20:33:05.174400Z

repls are also very usable repls :)

dpsutton 2021-06-10T20:33:28.175200Z

haha very true 🙂

vlaaad 2021-06-10T20:35:00.176500Z

> -X:myalias foo.bar/fn1 foo.bar/fn2 some.other/thing how does it know that it's (-> {} foo.bar/fn1 foo.bar/fn2 some.other/thing) and not (foo.bar/fn1 {'foo.bar/fn2 'some.other/thing}) ?

borkdude 2021-06-10T20:35:42.177200Z

@seancorfield could you help me understand how I could abuse this? ;)

alexmiller 2021-06-10T20:35:45.177300Z

symbols at the front are functions

borkdude 2021-06-10T20:36:04.178100Z

and @dpsutton about startup time: how does this solve startup time?

alexmiller 2021-06-10T20:36:35.179200Z

fn* [kpath v]* map?

dpsutton 2021-06-10T20:36:39.179400Z

i was thinking about sci/bb but at that point you could just pass in forms to be evaled

vlaaad 2021-06-10T20:36:54.179800Z

ah, so clj-exec first consumes all symbol args as fn chain, and then rest args as map arg?

alexmiller 2021-06-10T20:37:15.180100Z

well we now have trailing map support ala 1.11 too

vlaaad 2021-06-10T20:37:53.180700Z

> fn* [kpath v]* map? this is great explanation 😄

alexmiller 2021-06-10T20:38:20.181200Z

to be more precise

alexmiller 2021-06-10T20:38:56.181600Z

parsing is done with that spec

vlaaad 2021-06-10T20:48:00.182500Z

Just tried it out on pwsh, it works

alexmiller 2021-06-10T20:48:15.182800Z

but of course :)

vlaaad 2021-06-10T20:48:34.183200Z

not sure how I feel about the -X threading

alexmiller 2021-06-10T20:48:37.183400Z

thanks :)

vlaaad 2021-06-10T20:50:18.185600Z

I tried this:

clj -X clojure.core/pr-str clojure.core/read-string clojure.pprint/pprint :a 1
but when I was playing with it I felt the order is somewhat hard to follow, because arg-map is in the end, unlike in real ->

2021-06-11T16:01:28.203900Z

(defmacro <- [,,,],,,) :grinning_face_with_one_large_and_one_small_eye:

alexmiller 2021-06-10T20:50:50.186300Z

interested in feedback, so do more , and come back

vlaaad 2021-06-10T20:52:11.188300Z

intuitively I wanted to write this:

clj -X clojure.pprint/pprint clojure.core/read-string clojure.core/pr-str :a 1
because arg-map is closer to fn that will receive it. e.g.
(clojure.pprint/pprint (clojure.core/read-string (clojure.core/pr-str {:a 1})))

alexmiller 2021-06-10T20:52:13.188400Z

I don't know that this is something you're going to want to use all the time, but it is another dimension of composition available

alexmiller 2021-06-10T20:52:36.188800Z

the goal is not to replicate the repl. if you want that, use a repl

vlaaad 2021-06-10T20:52:54.189Z

mm yeah...

seancorfield 2021-06-10T21:00:58.190600Z

I guess my big test is going to be breaking depstar up into multiple -X-compatible functions so you can run parts of it or all of it in a pipeline 🙂

alexmiller 2021-06-10T21:02:11.191800Z

if you do do that, I would be very interested in hearing your questions/feedback. if I may be so bold, that might be a better thing to do in design space before actually cutting the code :)

vlaaad 2021-06-10T21:05:22.194600Z

Okay, another argument why (fn1 (fn2 argmap)) might make sense:

PS C:\Users\Vlaaad\Projects\deps-test\lib> Get-Content .\deps.edn
{:aliases {:deploy {:ns-default deploy}}}
PS C:\Users\Vlaaad\Projects\deps-test\lib> Get-Content .\src\deploy.clj
(ns deploy)

(defn dev [args]
  (merge
   {:env :dev
    :url "dev-cluster"}
   args))

(defn prod [args]
  (merge
   {:env :prod
    :url "prod-cluster"}
   args))

(defn deploy [env]
  (prn :deploy env))
Suppose I want to deploy my app. Currently I have to use this order: dev deploy
PS C:\Users\Vlaaad\Projects\deps-test\lib> clj -X:deploy dev deploy :a 1
:deploy {:env :dev, :url "dev-cluster", :a 1}
But this is unintuitive, as I would expect the at the command line first specify an "action" and then "env"
PS C:\Users\Vlaaad\Projects\deps-test\lib> clj -X:deploy deploy dev :a 1
:deploy {:a 1}
but with -> style the main action goes last instead of being first

seancorfield 2021-06-10T21:06:18.194900Z

Oh, definitely. I need to tease apart the various useful processes that depstar performs and figure out exactly what inputs and outputs each of them have.

seancorfield 2021-06-10T21:06:34.195100Z

I have smaller things to test it on before that 🙂

seancorfield 2021-06-10T21:08:09.195300Z

I don’t understand this at all. -> says “do things in this order” and that’s exactly what I would expect: setup the env, run the command.

alexmiller 2021-06-10T21:09:13.195500Z

the key thing is that inputs/outputs need to align, which harkens to namespaced keys ... but those fight with conciseness of what you want at the CLI

alexmiller 2021-06-10T21:10:37.195800Z

agreed, the order is the most important thing here

vlaaad 2021-06-10T21:11:36.196Z

so it's more like clj -X:build clean jar than clj -X:build deploy dev ?

alexmiller 2021-06-10T21:12:44.196200Z

yes

seancorfield 2021-06-10T21:21:28.196400Z

clojure -X:depstar sync-pom compile jar for example 🙂

💡 1
vlaaad 2021-06-10T21:31:26.196600Z

mm yeah, that makes a lot of sense

seancorfield 2021-06-10T22:15:50.198600Z

@alexmiller What’s the thinking around -X functions that would require (shutdown-agents) calls at the end to avoid the 60 second “hang”? That’s been a long-standing issue with -main functions. I didn’t check the latest exec source but does it handle that? (since you clearly cannot chain exec functions that call shutdown-agents)

alexmiller 2021-06-10T22:21:40.198900Z

Haven’t thought about it

seancorfield 2021-06-10T22:25:30.199100Z

I just looked at the exec.clj code and it does not call (*exit* 0) or (shutdown-agents) in the “happy” case…

seancorfield 2021-06-10T22:34:46.199500Z

Yeah, my first test of chaining tasks leads to a 60 second hang at the end because of that.

seancorfield 2021-06-10T22:35:59.199700Z

(I used to run the tasks individually and they had calls to (shutdown-agents) at the end — which I removed so I could chain them — and I can’t just call clojure.core/shutdown-agents via -X because it takes no arguments 😞