tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
practicalli-john 2020-12-06T21:56:44.206600Z

FYI: I noticed that the excellent antq project wasnt check for new library versions when added as a dependency via :replace-deps so I've created a PR (its a very simple change). I've been using :replace-deps specifically for tooling that doesn't need to use the project deps, such as clj-new. https://github.com/liquidz/antq/pull/45

seancorfield 2020-12-06T22:31:38.208Z

@jr0cket That served as a nice reminder that now we've abandoned the CLJ_CONFIG "hack" at work, we can get rid of our weird, custom "outdated deps" script and switch over to antq which works really well on our new setup!

1πŸ‘
practicalli-john 2020-12-06T22:33:43.209200Z

antq has some nice coverage, it even reported a newer version in my github action config for linting my user level configuration. Very impressive.

1☝️
seancorfield 2020-12-06T22:34:50.210600Z

With the custom formatter, I even managed to exactly replicate the output of our custom shell script that it replaces. And it found a few more outdated deps than our script.

practicalli-john 2020-12-06T22:37:04.211800Z

Nice. I've found the local/root config option very handy for hacking on an open source project that I've forked locally. I just added an alias so I could test my code before committing

:hack/antq
  {:replace-deps
   {antq/antq {:local/root "/home/practicalli/projects/clojure/community-tools/antq"}}
   :main-opts ["-m" "antq.core"]}

borkdude 2020-12-06T22:38:55.213300Z

I use that as well (usually :clj-kondo/dev, :babashka/dev, etc) but I have not used or found the need to use :replace-deps with it.

borkdude 2020-12-06T22:40:20.214500Z

:extra-deps works fine for this use case, it will override deps with the same qualified symbol I think, but maybe there's something subtle going on that I'm missing

ghadi 2020-12-06T22:42:05.215400Z

:local/root is super useful in dev mode with multiple repos

ghadi 2020-12-06T22:42:34.216300Z

I've been enjoying all the new knobs (I know that one isn't so new)

borkdude 2020-12-06T22:42:54.216800Z

yeah, it's super useful

practicalli-john 2020-12-06T22:49:40.219300Z

@borkdude :replace-deps was suggested to me for aliases that run tools which do not need the :deps from the project. The project deps wont be loaded, so don't add to execution time (although it probably has to be a large set of deps to notice). Its also in the official docs now https://clojure.org/reference/deps_and_cli#_replace_project_environment_tool

practicalli-john 2020-12-06T22:50:06.220Z

I still used extra deps for project related aliases

borkdude 2020-12-06T22:50:45.220500Z

oh so because you normally use antq as a tool, you just copied that alias and made the local/root hack version?

practicalli-john 2020-12-06T22:51:03.220900Z

Yes,

borkdude 2020-12-06T22:51:03.221Z

that makes sense

practicalli-john 2020-12-06T22:52:23.222500Z

copy paste is a wonderful excuse not to think πŸ™‚ So i didn't really think about how I was pulling in the dependency. Using extra-deps probably is more approapriate for hack/antq

ghadi 2020-12-06T22:53:15.223700Z

:replace-deps also useful for when you do want to read the project deps or construct the runtime basis

ghadi 2020-12-06T22:53:34.224400Z

but not be in the project classpath

borkdude 2020-12-06T22:53:38.224500Z

so what if you are combining multiple aliases for dev, like :clj-kondo/dev:cider-nrepl then I guess :replace-deps would still work in both aliases, combining the deps of both aliases?

practicalli-john 2020-12-06T22:54:32.225200Z

Sound like something interesting to test...

borkdude 2020-12-06T22:55:40.225500Z

@ghadi I need an example to be able to understand what you said

ghadi 2020-12-06T22:56:14.226400Z

tools like depot or antq want to analyze the project dependencies

seancorfield 2020-12-06T22:56:28.227Z

clojure.basis will still be computed from the project deps.edn file (and user deps.edn etc).

ghadi 2020-12-06T22:56:42.227300Z

those are good candidates for :replace-deps

ghadi 2020-12-06T22:57:37.228700Z

without revealing much, I'm working on a tool right now that is installed as a :replace-deps tool. It need to read the project's deps.edn and produce a bunch of data derived from it

borkdude 2020-12-06T22:58:06.229800Z

Where is clojure.basis documented, I haven't looked into it (I probably encountered it while porting the new clojure bash to clojure). I can't see it here: https://clojure.org/guides/deps_and_cli

ghadi 2020-12-06T22:58:13.230Z

within my tool I remember :project-dir as (io/file ".") and call tools.deps as an API

ghadi 2020-12-06T22:58:26.230300Z

loading in the deps.edn from the project and shredding it

borkdude 2020-12-06T22:59:52.231Z

shredding = rewriting?

ghadi 2020-12-06T23:00:09.231400Z

deriving info from it for the purposes of my tool

ghadi 2020-12-06T23:00:30.231900Z

(i need to produce several zip files with different partitions of the classpath)

seancorfield 2020-12-06T23:01:01.232500Z

@borkdude https://insideclojure.org/2020/07/28/clj-exec/ -- explains the "runtime basis"

borkdude 2020-12-06T23:01:53.233100Z

it sounds like you're working on some caching tool?

ghadi 2020-12-06T23:02:08.233300Z

sort of

seancorfield 2020-12-06T23:03:16.234300Z

https://clojure.org/reference/deps_and_cli#_basis_and_classpath talks about the "runtime basis" but doesn't seem to clarify that you can read it via the JVM property 😐

ghadi 2020-12-06T23:03:28.234600Z

you shouldn't actually rely on the JVM property

ghadi 2020-12-06T23:04:05.235300Z

use tools.deps programmatically.

ghadi 2020-12-06T23:04:47.236100Z

I assume there will eventually be some stable API for an application to discover its own runtime basis

borkdude 2020-12-06T23:07:53.236700Z

Thanks, I missed that because I only searched for clojure.basis

seancorfield 2020-12-06T23:10:59.238500Z

A stable API would be nice. I wrote a few questions on http://ask.clojure.org recently about providing easier ways to use t.d.a with higher-level APIs to avoid the boilerplate. A nicer API than (-> (System/getProperty "clojure.basis") (slurp) (edn/read-string)) would be appreciated πŸ™‚

seancorfield 2020-12-06T23:12:04.240200Z

Although right now it doesn't require you to depend on t.d.a so there's that small bonus (but I get the impression that Clojure itself will start to depend on t.d.a soon, or parts of it perhaps, maybe for the add-libs style functionality?).

ghadi 2020-12-06T23:13:05.241200Z

most tools people write do not need to be within the project classpath

ghadi 2020-12-06T23:13:12.241500Z

the depstar approach was wrong

ghadi 2020-12-06T23:13:35.242Z

most tools want access to the application's basis to analyze it

ghadi 2020-12-06T23:13:41.242300Z

e.g. see what libs are outdated

ghadi 2020-12-06T23:14:07.243400Z

I don't think clojure will ever depend on t.d.a., but I'm curious to know why you said that

seancorfield 2020-12-06T23:14:48.244700Z

Well, now we've abandoned the CLJ_CONFIG hack at work, I'd be happy with a version of depstar that constructed the project basis instead of relying on the runtime classpath environment.

seancorfield 2020-12-06T23:15:30.246500Z

But I don't want to break anyone's projects that are already depending on how depstar works today, so I'll have to give that some careful thought.

ghadi 2020-12-06T23:16:47.249200Z

one advantage of running as a -X tool with :replace-deps is that you don't have to be frugal about which dependencies you allow yourself to use

ghadi 2020-12-06T23:17:08.250200Z

you can access the application basis to produce an uberjar with whatever nice deps you want to use

seancorfield 2020-12-06T23:17:09.250400Z

@ghadi Alex has talked several times about add-libs style functionality being part of Clojure itself and that's currently in t.d.a -- so my assumption is that at least part of t.d.a's functionality will be rolled into Clojure directly, or Clojure will come to depend on (a future variant of) t.d.a like it currently depends on Spec etc.

ghadi 2020-12-06T23:17:17.250800Z

πŸ˜•

borkdude 2020-12-06T23:17:38.251400Z

> A nicer API thanΒ (-> (System/getProperty "clojure.basis") (slurp) (edn/read-string))Β would be appreciated It think having a generic way of storing properties in clojure would be nice. Instead of the Java properties String -> String. we could have something like clojure.core/*properties* with keyword -> parsed EDN, without re-inventing a new variable for every new thing we want to store.

ghadi 2020-12-06T23:18:10.251900Z

I use the runtime basis for that borkdude. here is an ex:

borkdude 2020-12-06T23:18:44.252500Z

(I'm also thinking of other use cases than tools.deps)

ghadi 2020-12-06T23:19:39.253300Z

{:paths ["src"]

 :deps {org.clojure/clojure {:mvn/version "1.10.2-alpha4"}
        org.clojure/data.json {:mvn/version "1.0.0"}

        cognitect-labs/secret :local/root "/Users/ghadi/dev/secret"}}

 :aliases {:secret-deploy {:replace-deps {cognitect-labs/deploy {:local/root "/Users/ghadi/dev/deploy"}}
                           :exec-fn cognitect-labs.secret.deploy/magic
                           :exec-args {:compile-nses [hello-clojure
                                                      cognitect-labs.secret.runtime]}}}}

ghadi 2020-12-06T23:20:00.253700Z

then I run clojure -X:secret-deploy

ghadi 2020-12-06T23:20:27.254400Z

the code within cognitect-labs.secret.deploy/magic reads the local project's deps.edn and "does things" with it

ghadi 2020-12-06T23:21:06.255100Z

but you can put arbitrary data in aliases now, like the :compile-nses stuff

borkdude 2020-12-06T23:23:43.257300Z

yeah, you can store data in deps.edn, but it can be handy to have a general *properties* thing with the actual runtime data as well. e.g. instead of *command-line-args* we could have (:command-line-args *properties*) without ever introducing a new dynamic var for environment specific things again

ghadi 2020-12-06T23:23:58.257600Z

yeah, that's the injected basis

ghadi 2020-12-06T23:24:27.258300Z

just need a stable API πŸ™‚ . I am 90% sure the clojure.basis property is going away

ghadi 2020-12-06T23:28:07.259300Z

I see that clojure.basis is mentioned in Alex's blog

borkdude 2020-12-06T23:28:20.260Z

(afk now, sleeping)

1
seancorfield 2020-12-06T23:28:36.260500Z

FWIW, clj-new uses the runtime basis right via the clojure.basis property but switching to a nice API that reads the deps and computes it would be nicer.

seancorfield 2020-12-06T23:31:29.261900Z

Right now it still depends on being introduced via :extra-deps but it would make more sense to use :replace-deps and calc-basis -- but that goes to the "standard way to provide aliases to tools" Q I posted on http://ask.clojure.org @ghadi

ghadi 2020-12-06T23:34:03.262400Z

yeah that's an interesting API design problem

ghadi 2020-12-06T23:34:36.263100Z

how do you talk about the aliases to run the tool and then also about the tool's inputs?

seancorfield 2020-12-06T23:35:15.263700Z

Yeah, and right now every tool does something different and ad hoc 😐

ghadi 2020-12-06T23:35:58.264300Z

in my example above, I'd add :aliases as a parameter within the :exec-args map

ghadi 2020-12-06T23:36:16.264700Z

(but I haven't the need for this tool)

seancorfield 2020-12-06T23:37:48.265600Z

Yeah, maybe as everything catches up with t.d.a and switches over to the -X approach and :replace-deps we can standardize things.