tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
onetom 2021-07-02T03:56:10.455400Z

https://clojure.org/reference/deps_and_cli#_paths mentions that I can use aliases to assemble a value from aliases for the value for :paths. is that possible to do something like this for :extra-deps and similar hash-maps, within aliases?

onetom 2021-07-02T10:45:36.457700Z

thank you! i will have a look how you did it.

onetom 2021-07-02T03:57:00.455500Z

my motivation for doing this is to reduce some repetition in dependency definitions.

seancorfield 2021-07-02T04:39:36.455700Z

Not at the moment. Only :paths can accept keywords and treat them as aliases I believe. Some tools support this, such as depstar and deps-deploy, for some of their exec args. I'd like to see this be more widespread.

šŸ‘ 1
dharrigan 2021-07-02T10:38:52.456800Z

Is it possible to mix, say a function execution that does something, i.e., -X:foo with a set of aliases -M:bar:baz, i.e., clj -X:foo -M:bar:baz

dharrigan 2021-07-02T10:39:17.457300Z

so that foo would run first, then aliases next? Or perhaps I'm going about this the wrong way?

alexmiller 2021-07-02T14:39:00.459300Z

If Iā€™m guessing what you want, no

alexmiller 2021-07-02T14:39:16.459800Z

Each clj call runs a single program

alexmiller 2021-07-02T14:40:20.462700Z

One new capability in latest release is that you can chain multiple functions together, but they run serially which I suspect is not what you want

dharrigan 2021-07-02T14:41:41.465500Z

A bit of background, I'm porting a lein project.clj to deps. Part of our system uses a local docker stack, with random external ports. There's in-house lein plugin that introspects the docker stack running and spits out the ports for injection into the environment for development. I've ported that plugin to a little program that I can invoke using clj -X:foo. It's tedious to write out the ports each time (as the stack can bepulled up and down several times a day). So I wasn hoping to have something that ran a function (this one) then fired off the aliases that would then start up my repl etc...

alexmiller 2021-07-02T14:41:43.465700Z

You can use whatever you like to make two calls around clj, or you could write a program that did two things and call that

alexmiller 2021-07-02T14:42:27.466400Z

Chaining might work well for this

dharrigan 2021-07-02T14:43:20.467Z

serial execution is fine, but I wonder would it work with the repl programs, such as rebel-readline that uses a main method to start up

dharrigan 2021-07-02T14:44:16.467700Z

so, it's like I want to run a function before then handing off to the -M aliases, perhaps that function, like in this case, is a pre-start bit of work

borkdude 2021-07-02T14:45:41.468100Z

@dharrigan Is there a need for the first script to run inside the Clojure JVM environment?

dharrigan 2021-07-02T14:46:20.469Z

no (in fact, all it does is shell out to docker to get a list of runnig services, then use a bit of clojure code to write them out neatly into edn format)

alexmiller 2021-07-02T14:46:49.470100Z

this won't work with clojure.main programs so you'd need a wrapper -X style entry point to get to the repl (which would maybe be something we could provide)

dharrigan 2021-07-02T14:47:27.470800Z

Interesting!

alexmiller 2021-07-02T14:48:44.471800Z

the actual repl entry point function inside clojure.main is actually a vararg method so it would actually work as an entry point automatically IF you are using Clojure 1.11.0 alphas with trailing map support for kvarg functions

alexmiller 2021-07-02T14:49:09.472300Z

but you'd probably want a set of default supplied anyways, needing a wrapper

dharrigan 2021-07-02T14:50:39.472900Z

good point. I'll have a ponder over the weekend (I mean, I could always just do clj -X:foo && clj -M...... šŸ™‚

dharrigan 2021-07-02T14:51:05.473300Z

but maybe babashka, with it's tasks may help out as well šŸ™‚

dharrigan 2021-07-02T14:51:14.473700Z

thank you @alexmiller and @borkdude!

alexmiller 2021-07-02T14:51:29.474Z

yeah, there are many ways to skin this cat (which is why I don't see a need to add another one :)

dharrigan 2021-07-02T14:52:17.474200Z

meow!

Chase 2021-07-02T19:02:32.478900Z

so tools.deps.alpha is for dynamically adding a library without restarting the repl right? How are folks using this universally in all their projects? I'm assuming putting it somewhere in their /clojure/deps.edn config? I'm thinking of putting it in my repl alias as I'm always using that to start a cider nrepl anyways

alexmiller 2021-07-02T19:08:14.479600Z

no, that feature is not available in the mainline code (it is available on an experimental branch and may be merged in some form at a future time)

Chase 2021-07-02T19:13:43.482400Z

no worries, thanks

seancorfield 2021-07-02T20:00:30.483300Z

@chase-lambert I use that experimental branch all the time. My dot-clojure repo has that and a bunch of other aliases in it: see the usage notes here https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn#L202-L224

seancorfield 2021-07-02T20:02:18.485400Z

I did a REPL-Driven Development talk about six months ago -- for both the London Clojurians and Provo Clojure -- and in that talk/demo I show how to use it with deps.edn to load new dependencies into the REPL while I'm working.

Chase 2021-07-02T20:02:45.485800Z

Does this mean if I add that in to my deps.edn I could do something like clj -M:add-libs:repl to run both aliases? I am still confused on how to call multiple aliases because I thought I read only the "last" alias allows for :main-opts or something

Chase 2021-07-02T20:03:20.486500Z

I'll rewatch that talk, I think that is where I originally saw this possibility

seancorfield 2021-07-02T20:03:52.487100Z

With :main-opts only the last one wins, so it depends what is in your :repl alias?

seancorfield 2021-07-02T20:05:25.488400Z

But, yeah, in this case :add-libs only loads extra (git) deps, so it would combine with your :repl alias too.

Chase 2021-07-02T20:06:23.488900Z

the repl main opts are basically nrepl middleware and "-i" to get a prompt

Chase 2021-07-02T20:07:16.489600Z

it looks like your :add-libs alias needs some Dynamic Class Loader options going on or something though

seancorfield 2021-07-02T20:10:25.490200Z

That's really for Socket REPLs which don't currently have a DCL. Pretty sure your nREPL setup will have a DCL.

Chase 2021-07-02T20:10:52.490600Z

sounds good, I'll give this a shot, thank you

seancorfield 2021-07-02T20:14:21.491400Z

Feel free to DM me with Qs if you have problems. There aren't many of using add-libs...

Chase 2021-07-02T20:16:38.492200Z

thanks! It seems to be working great in the repl. I was thinking it would add the dependency to my project's deps.edn for me though.

seancorfield 2021-07-02T20:20:14.493100Z

Nope, just in-memory. Which is why, in my demo, I do that weird dance with #_ and code actually in my deps.edn file šŸ™‚

seancorfield 2021-07-02T20:20:45.494200Z

So I edit deps.edn to add the dep, then run add-libs on it in-situ to actually load the new dep into the running REPL.

Chase 2021-07-02T20:21:19.494600Z

Awesome, I'll go check it out again soon. My lazy self also wants to find a way to auto load the (require '[clojure.tools.deps.alpha ...) at repl start too but I'll leave you fine folks alone on that (for now) haha

seancorfield 2021-07-02T20:22:24.494800Z

Put it in user.clj

seancorfield 2021-07-02T20:22:36.495100Z

Clojure loads that when it starts up.

Chase 2021-07-02T20:22:59.495500Z

I was thinking that's how it is done. So it just runs all the code found in that file automatically? It has to be on a certain path?

seancorfield 2021-07-02T20:23:59.496700Z

Yeah, so it's usually best to have a :dev alias that adds the path containing user.clj so it doesn't get into your production code. It just needs to be on the classpath.

seancorfield 2021-07-02T20:24:34.497400Z

(so you might have dev/user.clj and then :dev {:extra-paths ["dev"]})

Chase 2021-07-02T20:25:11.498100Z

yep, just saw that here: https://github.com/prestancedesign/usermanager-reitit-example which is based on your own example repo. Thanks again

Chase 2021-07-02T20:26:37.499400Z

I feel like the more I learn these tools.deps the more I'm going to keep wanting to run multiple aliases depending on what I'm doing but then this only one alias's main opts thing will be tripping me up constantly. That's not accurate though?

seancorfield 2021-07-02T20:27:50.000100Z

These days I run most stuff via -X, even if that means writing a little wrapper around someone else's actual -main function šŸ™‚

seancorfield 2021-07-02T20:28:11.000500Z

:exec-args composes across multiple -X aliases.

Chase 2021-07-02T20:34:53.001100Z

yeah it's time to sit down and really grok this official deps and cli reference docs I think

seancorfield 2021-07-02T20:41:42.002400Z

If you have the :new alias (from clj-new) and run clojure -X:new :template app :name chase/example you'll get a small, simple project that uses -X for most stuff.

seancorfield 2021-07-02T20:42:27.003100Z

(and soon these tools will be even easier to install and use -- see Alex's clojureD talk that was just released to YouTube today)

Chase 2021-07-02T20:46:57.004Z

Ironically I decided not to use clj-new this time to force myself to learn these things myself. haha. Yeah I have all those clojureD talks lined up to watch, they all look interesting.

seancorfield 2021-07-02T21:12:43.004100Z

It was a great conference! I attended "live" and the virtual environment was really good.

seancorfield 2021-07-02T21:13:02.004300Z

Kind of brutal, time-wise, since I'm in California šŸ™‚

seancorfield 2021-07-02T21:14:42.004500Z

At work, we're preparing for tools.build -- and we've been using deps.edn since 2018. Just recently we replaced our ad hoc bash-based build scripts with a short build.clj program (which my colleague is refactoring today), and we use -X invocation for a lot of tasks already.

seancorfield 2021-07-02T21:16:28.004700Z

I've been updating depstar so it has multiple "tasks" that can be run individually via -X or together, but I'm waiting for tools.build to become available so I can finish that work off in a way that is compatible (with tools.build) so you should be able to swap out some of the built-in tasks for depstars version of them (sync pom.xml, compile Clojure, build a JAR or uberjar).