tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
tianshu 2021-03-08T13:38:22.183Z

Looks like there are more and more wonderful libraries in Clojure, most of them provide a main function that can start with -M . I wonder whether it's possible to start multiple main functions in a single repl, or I have to write a .clj script to combine them.

teodorlu 2021-03-08T13:46:24.183700Z

Could you call the -main function directly? I guess the main function might be private, but there are ways around that.

alexmiller 2021-03-08T13:59:35.184100Z

the -main function can't be private (if you want Java to be able to call it)

alexmiller 2021-03-08T14:00:03.184200Z

no, the Clojure runner runs one program, so if you want to start multiple you need to wrap them in something else

tianshu 2021-03-08T14:15:14.184400Z

@alexmiller Thank you for the quick answer!

tianshu 2021-03-08T14:16:18.184900Z

I can call main functions in a script.

seancorfield 2021-03-08T16:59:31.187Z

@doglooksgood More and more libraries intended for use with the CLI are getting functions that you can call via -X these days, and those are also more amenable to calling directly from Clojure code, making it easier to write a short Clojure script that calls those functions one after the other. I wouldn't be surprised if we adopted a standardized approach for such pipelines of functions fairly soon...

borkdude 2021-03-08T19:16:55.187700Z

I'm running with the latest clojure CLI and I've had several occasions now that there's something weird with gitlibs.

borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka/babashka.curl (master*) $ clojure -M:test
Execution error (FileNotFoundException) at clojure.main/main (main.java:40).
Could not locate cognitect/test_runner__init.class, cognitect/test_runner.clj or cognitect/test_runner.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

Full report at:
/var/folders/2m/h3cvrr1x4296p315vbk7m32c0000gp/T/clojure-11182883341768341391.edn
borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka/babashka.curl (master*) $ ls -la  ~/.gitlibs/libs/cognitect-labs/test-runner
total 0
drwxr-xr-x  4 borkdude  staff  128 Mar  8 20:14 .
drwxr-xr-x  3 borkdude  staff   96 Mar  8 10:48 ..
drwxr-xr-x  4 borkdude  staff  128 Mar  8 20:14 b6b3193fcc42659d7e46ecd1884a228993441182
drwxr-xr-x  8 borkdude  staff  256 Mar  8 10:48 cb96e80f6f3d3b307c59cbeb49bb0dcb3a2a780b
borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka/babashka.curl (master*) $ ls -la  ~/.gitlibs/libs/cognitect-labs/test-runner/b6b3193fcc42659d7e46ecd1884a228993441182
total 16
drwxr-xr-x  4 borkdude  staff   128 Mar  8 20:14 .
drwxr-xr-x  4 borkdude  staff   128 Mar  8 20:14 ..
-rw-r--r--  1 borkdude  staff   368 Mar  8 20:14 deps.edn
-rw-r--r--  1 borkdude  staff  3491 Mar  8 20:14 readme.md

borkdude 2021-03-08T19:18:45.188Z

moving ~/.gitlibs aside fixes it once again

alexmiller 2021-03-08T19:24:26.188300Z

so it's a partial checkout?

borkdude 2021-03-08T19:24:43.188800Z

seems like it yes

alexmiller 2021-03-08T19:25:24.189300Z

can you share the deps.edn you're using?

borkdude 2021-03-08T19:25:38.189600Z

sure:

{:aliases {:json {:extra-deps {cheshire/cheshire {:mvn/version "5.10.0"}}}
           :test {:extra-paths ["test"]
                  :extra-deps {cheshire./cheshire {:mvn/version "5.10.0"}
                               cognitect-labs/test-runner
                               {:git/url "<https://github.com/cognitect-labs/test-runner>"
                                :sha "b6b3193fcc42659d7e46ecd1884a228993441182"}}
                  :main-opts ["-m" "cognitect.test-runner"]}}}

borkdude 2021-03-08T19:25:58.189900Z

(oh I see a typo in the cheshire name, but that wasn't the partial checkout)

alexmiller 2021-03-08T19:26:05.190300Z

so just the one git lib

borkdude 2021-03-08T19:26:11.190500Z

yes

borkdude 2021-03-08T19:28:08.190800Z

it is a gitlib of which I have two different checkouts as you can see

alexmiller 2021-03-08T19:28:14.191Z

sure

alexmiller 2021-03-08T19:28:55.191300Z

I assume you didn't like ctrl-c a previous test run

borkdude 2021-03-08T19:30:20.191600Z

I can't rule that out necessarily

borkdude 2021-03-08T19:30:30.191800Z

don't remember

borkdude 2021-03-08T19:30:58.192100Z

maybe a shutdown hook should do some clean up if that is the case?

alexmiller 2021-03-08T19:32:59.193400Z

what clean up could it do?

mkvlr 2021-03-08T19:34:53.195500Z

I ran into a similar issue today, the symptom was it couldn’t find a namespace. I removed offending folder from ~/.gitlibs but it would only refetch it after running clojure with -Sforce

alexmiller 2021-03-08T19:35:28.195900Z

I think it's probably better to think about it from perspective of only making it visible when it's done

👍 1
alexmiller 2021-03-08T19:37:12.197300Z

git itself is using some locking protocols so there is some benefits from cloning into the same dir so I will need to look at this more closely

alexmiller 2021-03-08T19:37:29.197600Z

(cloning re git dir, not checking out re working trees)

borkdude 2021-03-08T19:38:48.197900Z

yes, my problem was also fixed using -Sforce

borkdude 2021-03-08T19:39:19.198300Z

I meant cleaning like removing the entire folder if the checking out was interrupted

borkdude 2021-03-08T19:39:41.198600Z

maybe some atomic move like construct could also work

alexmiller 2021-03-08T19:39:45.198800Z

yes, that makes sense

alexmiller 2021-03-08T19:40:00.199100Z

same as corrupted maven downloads