Fork me on GitHub
#tools-deps
<
2020-10-22
>
practicalli-johnny10:10:12

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.

borkdude10:10:59

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

borkdude10:10:36

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*] )

borkdude10:10:13

(I've made the same mistake before)

practicalli-johnny10:10:57

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

borkdude10:10:43

the same rules apply for -A

borkdude10:10:11

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

practicalli-johnny10:10:11

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

borkdude10:10:35

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

👍 3
practicalli-johnny10:10:17

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.

dominicm11:10:11

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-johnny11:10:00

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

practicalli-johnny11:10:51

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

dominicm11:10:35

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

borkdude12:10:28

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

😢 9
dominicm13:10:32

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

borkdude13:10:17

Having less magic to understand is also useful ;)

dpsutton13:10:25

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

👍 6
dominicm13:10:24

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

borkdude13:10:57

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

dominicm17:10:52

implementation detail, subproc part could change :)

dpsutton13:10:56

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

Alex Miller (Clojure team)14:10:38

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)

bananadance 3
👀 6
rschmukler17:10:42

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

rschmukler17:10:12

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

rschmukler17:10:19

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

borkdude17:10:57

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

borkdude17:10:54

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

rschmukler17:10:16

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

borkdude17:10:39

-I is for reading multiple EDN values from stdin

seancorfield17:10:06

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

rschmukler17:10:40

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

seancorfield17:10:06

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

rschmukler17:10:36

Then clearly my clj must be outdated lol!

rschmukler17:10:47

Right'o - thank you for the help!

seancorfield17:10:57

(! 652)-> clojure -Sdescribe
{:version "1.10.1.727"
 :config-files ["/usr/local/Cellar/[email protected]/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/[email protected]/1.10.1.727"
 :config-dir "/Users/sean/.clojure"
 :cache-dir ".cpcache"
 :force false
 :repro false
 :main-aliases ""
 :repl-aliases ""}

rschmukler17:10:15

:version "1.10.1.645

rschmukler17:10:21

There we are

seancorfield17:10:03

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

rschmukler17:10:10

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

rschmukler18:10:04

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

3
practicalli-johnny18:10:35

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)

seancorfield18:10:54

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

seancorfield18:10:18

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

Alex Miller (Clojure team)18:10:10

I expect that to be ~months

3
practicalli-johnny18:10:44

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

6
seancorfield22:10:29

@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?)

seancorfield22:10:36

Also, you have

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

practicalli-johnny09:10:04

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.

3
Drew Verlee22:10:41

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.

dpsutton22:10:27

#: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?

dpsutton22:10:06

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

Drew Verlee22:10:25

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

Alex Miller (Clojure team)22:10:50

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

Alex Miller (Clojure team)22:10:16

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

seancorfield22:10:44

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

seancorfield22:10:29

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

Alex Miller (Clojure team)22:10:29

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