Fork me on GitHub
#tools-deps
<
2020-07-01
>
practicalli-john11:07:56

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 🙂

practicalli-john11:07:58

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).

borkdude11:07:44

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

borkdude11:07:59

I imagine something similar is happening here

practicalli-john12:07:36

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.

borkdude12:07:54

@jr0cket This seems to work:

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

borkdude12:07:02

@jr0cket or even:

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

practicalli-john12:07:41

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

borkdude12:07:31

@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-john12:07:57

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

drewverlee19:07:49

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?

borkdude19:07:40

@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}}}}

borkdude19:07:37

This only works in an alias