Fork me on GitHub
#leiningen
<
2023-09-12
>
Ingy döt Net16:09:38

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.

emilaasa18:09:03

I think it normally does yes

Ingy döt Net18:09:50

It does't seem to here

emilaasa18:09:15

What lein version are you running?

emilaasa18:09:19

lein --version

emilaasa18:09:06

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 Net18:09:41

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 Net18:09:20

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

Ingy döt Net18:09:45

which logs do you mean?

Ingy döt Net18:09:05

the commands do print that to /dev/tty

nREPL server started on port 38097 on host 127.0.0.1 - 

pez18:09:26

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 Net18:09:45

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

Ingy döt Net18:09:21

I can do what I need now...

pez18:09:57

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 Net18:09:26

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 Net18:09:32

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

Ingy döt Net18:09:00

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

lread18:09:59

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 Net19:09:31

I can see it being useful. :)

Ingy döt Net19:09:59

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 @U04V70XH6’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.

pez19:09:57

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

lread19:09:13

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

hifumi12320:09:18

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
hifumi12320:09:19

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
lread13:09:11

> 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