tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
practicalli-john 2020-10-22T10:05:12.448200Z

Should the -M flag for Clojure CLI tools have an issue when also supplying -Sdeps options? (the -A flag works without issue for the same command)

/usr/local/bin/clojure -M:env/test -Sdeps '{:deps {}}' 
This gives an error, whether or not the :deps contains any dependencies.
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
-Sdeps (No such file or directory)
I first experienced this issue when running Clojure CLI tools with Cider (Emacs) and using the -M flag, specifically with cider-jack-in which injects the relevant dependencies for cider-nrepl using `-Sdeps argument. I can disable the actual dependencies, but not yet Testing the same command on the terminal, gives the same error. Using the command without the -M:env/test alias, only the -deps arguments works Using the -A flag works with S-deps argument Starting a repl with that command, minus the -Sdeps argument works via the command line and I can connect I have tried this with several versions of Clojure CLI tools installed, from 1.10.1.697 onwards, including the latest pre-release. All seem to have the same issue.

borkdude 2020-10-22T10:14:59.449600Z

@jr0cket The -S... options should go before -M

borkdude 2020-10-22T10:16:36.450700Z

clj-opts before exec-opts (although they are mentioned in the other order in the help text, that order is documented as Run main clojure [clj-opt*] -M[:aliases] [init-opt*] [main-opt] [arg*] )

borkdude 2020-10-22T10:19:13.453200Z

(I've made the same mistake before)

practicalli-john 2020-10-22T10:20:57.454800Z

Yes, putting the -M after -Sdeps does seem to work on the terminal. That ordering is not the case with -A flag and so sounds like a change is required for Cider to work correctly with jack-in. The ordering can be changed by editing the the command line each time, but using .dir-locals.el config to set the alias, the -M and -A flags are put before the -Sdeps option I assume -A will also work after -Sdeps option, to support those who havent upgraded to Clojure CLI tools

borkdude 2020-10-22T10:21:43.455Z

the same rules apply for -A

borkdude 2020-10-22T10:22:11.455200Z

Start a REPL   clj     [clj-opt*] [-A:aliases] [init-opt*]

practicalli-john 2020-10-22T10:23:11.455800Z

Except -A doesnt uphold that rule in practice...

borkdude 2020-10-22T10:23:35.456300Z

It's a case of Hyrum's law, but I guess the tools doing it wrong should be changed.

1👍
practicalli-john 2020-10-22T10:27:17.458400Z

Confirmed that editing the cider command line and putting -M flag in the correct place does work :)

/usr/local/bin/clojure -Sdeps '{:deps {nrepl {:mvn/version "0.8.2"} refactor-nrepl {:mvn/version "2.5.0"} cider/cider-nrepl {:mvn/version "0.25.3"}}}' -M:env/test -m nrepl.cmdline --middleware '["refactor-nrepl.middleware/wrap-refactor", "cider.nrepl/cider-middleware"]'
I'll raise an issue with Cider to see if they can fix this. Thanks.

dominicm 2020-10-22T11:47:11.459800Z

That's annoying. It looks like we'll need to write a parser for the arguments or something and split on it? Not too terrible, but it is if you want to be backwards compatible.

practicalli-john 2020-10-22T11:50:00.460300Z

@dominicm I just submitted an issue for this on the cider repository https://github.com/clojure-emacs/cider/issues/2916

practicalli-john 2020-10-23T11:10:51.002400Z

And there is a pull request that fixes this issue https://github.com/clojure-emacs/cider/pull/2917

dominicm 2020-10-22T11:51:35.461400Z

Hmm, I guess I'll have to check if my scripts use prefix or suffix form. That pattern is used in other tools too.

borkdude 2020-10-22T12:09:28.461700Z

or just don't use cider-jack-in. I never use it.

3😢
dominicm 2020-10-22T13:22:32.462600Z

I do. It's a useful tool, especially for beginners. Having less pieces to understand is very useful.

borkdude 2020-10-22T13:24:17.463Z

Having less magic to understand is also useful ;)

dpsutton 2020-10-22T13:26:25.465100Z

I also really like that CIDER can start up almost any project for you automatically without thought. It displays its startup command in the repl so you know there actually isn’t any magic. It’s just an extra dep and a main so you can run from the clj easily

2👍
dominicm 2020-10-22T13:54:24.466500Z

There's no magic, just trying to build on top of simple tools underneath. It's more like an abstraction.

borkdude 2020-10-22T13:54:57.466900Z

It feels like too much magic to me. Also I don't want the REPL to be a subprocess of my editor..

dpsutton 2020-10-22T13:55:56.467500Z

the subprocess part is fair 🙂 If there's a problem in your lisp interpreter from 1970 your repl goes down ...

alexmiller 2020-10-22T14:12:38.467800Z

Clojure tools (clj) https://clojure.org/releases/tools#v1.10.1.727 is now available: • Fix clj -X:deps tree adding tools.deps.alpha to tree • Fix clj -X:deps mvn-pom adding tools.deps.alpha to pom deps • Fix clj -X:deps git-resolve-tags not working • https://clojure.atlassian.net/browse/TDEPS-152 - Fix clj -X:deps mvn-install on jar to also install embedded pom • Fix clj -Spom not respecting dep modifications from -A (regression)

12👀
rschmukler 2020-10-22T17:32:42.469Z

Is there any way to install dependencies from a given alias without running an associated :main-opts in the alias? Essentially I want a -e "" that ignores the main-opts

rschmukler 2020-10-22T17:33:12.469400Z

(specifically from the CLI, I realize its very doable via the clj package)

dominicm 2020-10-22T17:33:52.469500Z

implementation detail, subproc part could change :)

rschmukler 2020-10-22T17:42:19.470500Z

Right now my best shot is using babashka to construct a new deps.edn and invoking clj -Sdeps

clj -Sdeps "`cat deps.edn | bb -I -e "{:deps (merge (:deps (first *input*)) (get-in (first *input*) [:aliases :native-image :extra-deps]))}"`" -e ""
But this feels like quite the hack

borkdude 2020-10-22T17:48:57.471300Z

@rschmukler (I don't think you need -I here, since you're reading only one EDN value)

borkdude 2020-10-22T17:49:54.471500Z

cat deps.edn | bb -e "{:deps (merge (:deps *input*) (get-in *input* [:aliases :native-image :extra-deps]))}"

rschmukler 2020-10-22T17:50:16.472Z

Right on! I misunderstood the CLI. I thought -I coerced to EDN from string literal

borkdude 2020-10-22T17:50:39.472400Z

-I is for reading multiple EDN values from stdin

seancorfield 2020-10-22T17:50:46.472700Z

The official way is to use the -P option: https://clojure.org/reference/deps_and_cli#_prepare_for_execution

seancorfield 2020-10-22T17:52:06.473300Z

So clojure -P -M:my:aliases:here assuming you're using a recent release of the CLI.

rschmukler 2020-10-22T17:52:40.474200Z

@seancorfield perfection! Sorry that I missed that. Might be worth adding that to the clj --help docs too

seancorfield 2020-10-22T17:53:06.474400Z

It's in that help

exec-opts:
 -A:aliases     Use aliases to modify classpath
 -X[:aliases]   Use aliases to modify classpath or supply exec fn/args
 -M[:aliases]   Use aliases to modify classpath or supply main opts
 -P             Prepare deps - download libs, cache classpath, but don't exec

rschmukler 2020-10-22T17:53:36.474700Z

Then clearly my clj must be outdated lol!

rschmukler 2020-10-22T17:53:47.475Z

Right'o - thank you for the help!

seancorfield 2020-10-22T17:53:57.475200Z

(! 652)-> clojure -Sdescribe
{:version "1.10.1.727"
 :config-files ["/usr/local/Cellar/clojure@1.10.1.727/1.10.1.727/deps.edn" "/Users/sean/.clojure/deps.edn" "deps.edn" ]
 :config-user "/Users/sean/.clojure/deps.edn"
 :config-project "deps.edn"
 :install-dir "/usr/local/Cellar/clojure@1.10.1.727/1.10.1.727"
 :config-dir "/Users/sean/.clojure"
 :cache-dir ".cpcache"
 :force false
 :repro false
 :main-aliases ""
 :repl-aliases ""}

rschmukler 2020-10-22T17:54:15.475600Z

:version "1.10.1.645

rschmukler 2020-10-22T17:54:21.475800Z

There we are

seancorfield 2020-10-22T17:56:03.476800Z

Yeah, 645 was one of the prerelease builds while a lot was changing in the CLI.

rschmukler 2020-10-22T17:59:10.477200Z

Now I've just gotta figure out why Manjaro hasn't kept up

rschmukler 2020-10-22T18:08:04.477600Z

Updated my clojure and sure enough, it's all there for me. Thanks again @seancorfield

1
practicalli-john 2020-10-22T18:18:35.479300Z

Clojure CLI 1.10.1.697 is the minimum version for the -P and new mode for the -M flags. 1.10.1.727 is the latest (officially release today)

alexmiller 2020-10-22T18:19:32.479500Z

https://clojure.org/releases/tools for your version questions

seancorfield 2020-10-22T18:19:54.479900Z

I'll be glad when -A changes to no longer run :main-opts 🙂

practicalli-john 2020-10-22T18:21:44.480300Z

I did a little cheat sheet of command line flags to help me remember https://github.com/practicalli/clojure-deps-edn#clojure-cli-main-flag-options

2
practicalli-john 2020-10-23T09:35:04.000800Z

Thanks for the review, those issues are now fixed, along with further explanation. Using a :project/run alias seems to make most sense as a project level deps.edn, so the specific namespace and function names are in the config. I'm adding this to the templates I'm creating with clj-new.

1
seancorfield 2020-10-22T18:26:18.480600Z

@alexmiller This is still the plan, at some point, right?

alexmiller 2020-10-22T18:31:53.480800Z

yes

alexmiller 2020-10-22T18:32:10.481Z

I expect that to be ~months

1
2020-10-22T22:03:41.483100Z

When I run clj i get an exception about building the class path. I tried deleting my cpcache. If you can think of something else i can try please chime in. gist file is my deps.edn. the comment contains the command run and output (error): https://gist.github.com/drewverlee/893a150c780a86fbf73cd789b48d9b40 Thanks in advance. ill post in this thread if i figure it out.

dpsutton 2020-10-22T22:05:27.483700Z

#:com.datomic{ion-dev #:mvn{:version "0.9.276"}} the ion-dev does not begin with a colon but in #:mvn{:version it does. can you try fixing that?

dpsutton 2020-10-22T22:10:06.484300Z

scratch that. namespaced symbols look strange to me in that fashion 🙂

seancorfield 2020-10-22T22:11:29.484400Z

@jr0cket I see

Run the project	clojure -X:project/run -m domain.main-namespace
but there's no :project/run alias in your deps.edn so I'm not sure what this is meant to do? (and it seems weird to have -X and then have -m domain.main-namespace as well?)

2020-10-22T22:12:25.485700Z

It is strange, I'll clean it up. But I'm guessing that's not it. That's from copy pasting

seancorfield 2020-10-22T22:12:36.485900Z

Also, you have

Package library	clojure -X:project/jars
That should be -X:project/jar singular, yes?

alexmiller 2020-10-22T22:12:50.486300Z

I don't think that's it - this look like maybe a bad version range in some transitive dep?

alexmiller 2020-10-22T22:13:16.486700Z

although I know all those deps so not sure what you'd find there :)

seancorfield 2020-10-22T22:14:44.487300Z

{:deps      #:com.datomic{ion-dev #:mvn{:version "0.9.276"}}
under an alias, that should be :extra-deps, not :deps (or :override-deps)

alexmiller 2020-10-22T22:15:02.487500Z

typo: mvn/verison

seancorfield 2020-10-22T22:15:29.488Z

Ah yes, on com.datomic/ion {:mvn/verison "0.9.48"}

alexmiller 2020-10-22T22:15:29.488100Z

newest version of clj will give you a better error message there