leiningen

Ingy döt Net 2023-09-12T16:43:38.802569Z

Does/can lein repl write ./.nrepl-port file? This seems like it would be easy to find info on but I'm struggling. It's not creating that file for me by default.

emilaasa 2023-09-12T18:19:03.646139Z

I think it normally does yes

Ingy döt Net 2023-09-12T18:19:50.107929Z

It does't seem to here

Ingy döt Net 2023-09-12T18:20:52.902349Z

wonder what https://codeberg.org/leiningen/leiningen/src/branch/main/src/leiningen/repl.clj#L252 is about

emilaasa 2023-09-12T18:22:15.383429Z

What lein version are you running?

emilaasa 2023-09-12T18:23:19.247959Z

lein --version

emilaasa 2023-09-12T18:24:06.271499Z

Do you get any nREPL output in your logs? Something like:

nREPL server started on port 34603 on host 127.0.0.1 - 
REPL-y 0.5.1, nREPL 1.0.0
Clojure 1.11.1
OpenJDK 64-Bit Server VM 17.0.8+7-jvmci-23.0-b15

Ingy döt Net 2023-09-12T18:24:41.761799Z

Leiningen 2.10.0 on Java 17.0.8.1 OpenJDK 64-Bit Server VM
on my linux box and
Leiningen 2.10.0 on Java 20.0.1 OpenJDK 64-Bit Server VM
on my mac

Ingy döt Net 2023-09-12T18:25:20.198809Z

lein repl and lein repl :headless do not write a ./.nrepl-port file

Ingy döt Net 2023-09-12T18:25:45.354219Z

which logs do you mean?

Ingy döt Net 2023-09-12T18:27:05.265269Z

the commands do print that to /dev/tty

nREPL server started on port 38097 on host 127.0.0.1 - 

pez 2023-09-12T18:47:26.953189Z

I think it might only write that file in a project.

/tmp
❯ mkdir foo

/tmp
❯ cd foo

/tmp/foo
❯ lein repl
nREPL server started on port 58193 on host 127.0.0.1 - 
REPL-y 0.5.1, nREPL 1.0.0
Clojure 1.11.1
OpenJDK 64-Bit Server VM 18.0.2.1+1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=>
zsh: suspended  lein repl

/tmp/foo
❯ ls -a
.	..

/tmp/foo
❯ fg
[1]  + continued  lein repl
Welcome back!
Bye for now!

/tmp/foo
❯ cd ..

/tmp
❯ rmdir foo

/tmp
❯ lein new foo
Generating a project called foo based on the 'default' template.
The default template is intended for library projects, not applications.
To see other templates (app, plugin, etc), try `lein help new`.

/tmp
❯ cd foo

/tmp/foo
❯ ls
CHANGELOG.md	README.md	project.clj	src
LICENSE		doc		resources	test

/tmp/foo
❯ lein repl
nREPL server started on port 58535 on host 127.0.0.1 - 
REPL-y 0.5.1, nREPL 1.0.0
Clojure 1.11.1
OpenJDK 64-Bit Server VM 18.0.2.1+1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

foo.core=>
zsh: suspended  lein repl

/tmp/foo
❯ ls -a
.			.nrepl-port		project.clj
..			CHANGELOG.md		resources
.gitignore		LICENSE			src
.hgignore		README.md		target
.lein-repl-history	doc			test

/tmp/foo

Ingy döt Net 2023-09-12T18:49:45.528669Z

Thanks @pez. It does seem to write it in a project. @lee++ helped figured out that it writes to ~/.lein/repl-port otherwise.

Ingy döt Net 2023-09-12T18:50:21.226039Z

I can do what I need now...

pez 2023-09-12T18:50:57.396679Z

Ah, well, that might or might not be what one wants. 😃 But as long as it is deterministic, I guess it’s fine.

Ingy döt Net 2023-09-12T18:54:26.920969Z

I'm writing a shell function called nrepl for me personally that will start a lein repl server in a background process in any directory, and then write .nrepl-port and .nrepl-pid files. If they already exist it will just report the port and pid.

Ingy döt Net 2023-09-12T18:55:32.098259Z

So I can just mv ~/.lein/repl-port ./.nrepl-port if needed after starting the lein repl server.

Ingy döt Net 2023-09-12T18:56:00.886599Z

Using lein repl for now because my current projects all use lein

lread 2023-09-12T18:59:59.790509Z

I don't know leiningen very well, but wouldn't it be abnormal to run lein repl in a dir without a project.clj?

Ingy döt Net 2023-09-12T19:01:31.595699Z

I can see it being useful. :)

Ingy döt Net 2023-09-12T19:06:59.214999Z

fwiw, I'm trying to get my REPL/nREPL fu solidified and only use REPL servers from various clients from now on. It's not super easy to learn all the right things to do on this but it's important that I figure it all out. I did watch @seancorfield’s talk on REPL DD https://www.youtube.com/watch?v=gIoadGfm5T8 but that doesn't instantly make me a expert by any stretch. Also... advice welcome.

pez 2023-09-12T19:14:57.665779Z

Shouldn’t be abnormal? Isn’t that what a lot of Clojure at a glance guides tell you to do?

lread 2023-09-12T19:36:13.609179Z

Oh yeah, right, for a wee experiment at the terminal, of course.

hifumi123 2023-09-12T20:09:18.041759Z

Running lein repl outside of a project is fine. If it werent then the task would signal an error (like e.g. running lein uberjar in an empty folder)

🙏 1
hifumi123 2023-09-12T20:10:19.064159Z

In fact Leiningen looks for a :no-project-needed metadata in tasks. If that is set to true, then the task will run even in the absence of a project file. Otherwise the user will see an error like

Couldn't find project.clj, which is needed for [task]

💡 1
lread 2023-09-13T13:11:11.745899Z

> I don't know leiningen very well, but wouldn't it be abnormal to run lein repl in a dir without a project.clj? My brain was obviously not working well yesterday! facepalm