tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
practicalli-john 2020-07-01T11:38:56.175300Z

Does the clojure or clj command from Clojure CLI tools read a user.clj file if it contains (ns user) expression when starting the REPL? With Leiningen projets using a user or dev/user.clj file was one way to start component services. For a Clojure CLI project, if the dev directory was added as an extra path under a :dev alias and clj -A:dev used to start the REPL, should the dev/user.clj file be automatically evaluate on REPL start? I though I had this working the other week, but not sure if I imagined this now 🙂

borkdude 2020-07-01T11:47:57.175700Z

@jr0cket I think the answer is yes, it's not tooling dependent: https://github.com/clojure/clojure/blob/d07ef175c700329f7afbef8770332b6247a34a49/src/jvm/clojure/lang/RT.java#L486

practicalli-john 2020-07-01T11:54:58.178400Z

Ah, I have it working in terms of requiring a namespace and evaluating a funtion call. However, using (in-ns main-project-namespace) does not seem to switch to the namespace (or if it does, then maybe it been switched back to user afterward).

borkdude 2020-07-01T11:57:44.179200Z

@jr0cket load-file also switches back to the original namespace afterwards, because it uses binding + *ns*

borkdude 2020-07-01T11:57:59.179400Z

I imagine something similar is happening here

practicalli-john 2020-07-01T12:13:36.181600Z

Okay, I dont have to change the namespace, I can require the relevant libraries and use fully qualified namespace function calls. http://practicalli.github.io/clojure/clojure-tools/configure-repl-startup.html If there is a way in Clojure CLI tools to change the namespace using a user.clj file, I would be interested to know, but not essential. I can use the --eval option to run the relevant expressions.

borkdude 2020-07-01T12:15:54.181900Z

@jr0cket This seems to work:

$ clj -e "(ns foo.bar) (alter-var-root #'*ns* (constantly 'foo.bar))" -r

borkdude 2020-07-01T12:17:02.182400Z

@jr0cket or even:

$ clj -e "(ns foo.bar) (alter-var-root #'*ns* (constantly 'foo.bar)) (clojure.main/repl)"
foo.bar
foo.bar=>

practicalli-john 2020-07-01T12:18:41.183500Z

I can set the namespace easily using --eval option on the command line. Unfortunately the above do not work from within user.clj. Ideally I'd like use it with rebel readline, which is the REPL UI I use if I am just using the REPL directly rather than an editor. --eval doesnt work when using the :rebel alias

borkdude 2020-07-01T12:22:31.184100Z

@jr0cket Very well.

$ clj -R:rebel -e "(ns foo.bar) (alter-var-root #'*ns* (constantly (find-ns 'foo.bar)))" -m rebel-readline.main
#object[clojure.lang.Namespace 0x46cf05f7 "foo.bar"]
[Rebel readline] Type :repl/help for online help info
foo.bar=>

practicalli-john 2020-07-01T12:23:57.184400Z

Success 🙂 I have learnt many things today, thank you.

2020-07-01T19:52:49.185700Z

Is there a way to do a universal exlucions? i see you can attach exluded to individual deps, but what if i wont want this lib from any dep?

borkdude 2020-07-01T19:55:40.186100Z

@drewverlee you can use :classpath-overrides:

{:aliases {:babashka {:classpath-overrides {org.clojure/clojure nil
                                            org.clojure/spec.alpha nil
                                            org.clojure/core.specs.alpha nil}}}}

borkdude 2020-07-01T19:57:37.186300Z

This only works in an alias

2020-07-01T19:58:15.186500Z

gotcha.