Fork me on GitHub
#tools-deps
<
2022-09-07
>
Crispin04:09:37

Hi! I want to add a path to the classpath, but only in a deps.edn :aliases. I want to use codox to generate documentation, but it's for a babashka pod. And that code, with the docstrings, is not in the classpath because it can't be compiled by the normal compilation process (it is embedded in the code that is compiled with macros so it can be injected into babashka via it's interface). Any ideas how to extend the classpath in an alias? I have tried a bunch of things with no success.

seancorfield04:09:30

@Crispin use :extra-paths inside your alias to specify the extra directors

seancorfield04:09:01

And perhaps show us exactly what you have tried and exactly how it failed?

Crispin04:09:52

I tried :paths, and :clj-paths, and :main-opts passing extra flags

Crispin04:09:16

it failed with

Could not generate clojure documentation for pod.epiccastle.bbssh.utils - root cause: java.io.FileNotFoundException Could not locate pod/epiccastle/bbssh/utils__init.class, pod/epiccastle/bbssh/utils.clj or pod/epiccastle/bbssh/utils.cljc on classpath.
java.io.FileNotFoundException: Could not locate pod/epiccastle/bbssh/utils__init.class, pod/epiccastle/bbssh/utils.clj or pod/epiccastle/bbssh/utils.cljc on classpath.

Crispin04:09:35

ah bugger, that adds the classpath allright, but now it fails because it cant compile (which is why it's not in the classpath to begin with)

seancorfield04:09:30

If Codox loads the code to generate docs, it is a compiling it.

Crispin04:09:10

it now doesnt load (even though the classpath is added) because the code cant compile:

Caused by: java.lang.ClassNotFoundException: babashka.pods
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
	at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:69)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at clojure.lang.DynamicClassLoader.loadClass(DynamicClassLoader.java:77)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at clojure.lang.RT.classForName(RT.java:2209)
	at clojure.lang.RT.classForNameNonLoading(RT.java:2222)
	at clojure.lang.Compiler$HostExpr.maybeClass(Compiler.java:1041)
	at clojure.lang.Compiler.macroexpand1(Compiler.java:7062)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:7110)
	... 156 more

seancorfield04:09:06

That says Babashka pods isn't on the classpath

seancorfield04:09:50

So I expect you need to add that as :extra-deps in that alias

seancorfield04:09:14

(sorry, on phone)

Crispin04:09:44

babashka.pods only exists inside sci context over in babashka

Crispin04:09:44

and this code that I want codox to run over, is text files that get injected into the babashka context

seancorfield04:09:08

Then you can't use it with Codox

Crispin04:09:14

looks like codox cant do it... as long as its searching for code on the classpath

Crispin04:09:35

thanks anyway

seancorfield04:09:51

Ask in #babashka?

Crispin04:09:36

I also might be able to do something hacky, like preprocess those source files to remove offending vars...

seancorfield04:09:15

Or get Codox to run under bb?😁

borkdude06:09:17

Or use #quickdoc

matthavener20:09:41

this feels like a very simple problem but I'm having trouble googling it. when I run clj -A:myalias it's failing to compile some change I've made, but it doesn't produce an error, it just exits with a 1 error code. Is there some trick to getting the compiler to print the eval error?

hiredman20:09:45

depends, clojure itself (the clojure.main entry point) always produces some kind of error message, possibly just pointing you to a file that contains the full error message

hiredman20:09:58

if you aren't getting any error message at all then you may need to look at whatever that alias is actually launching (assuming it isn't just clojure.main), that might be swallowing any errors

hiredman20:09:21

additionally, when an issue report is vague, it is often good to revisit and verify the underlying assumptions in the report: how do you know it is failing to compile if it just exits without an error message?

matthavener20:09:18

if I remove the namespace I require from the gen-class'd namespace with -main it works fine

matthavener20:09:35

that lets me start a repl and then manually require that same ns

matthavener20:09:40

maybe I'll try to make an actually minimal testcase

hiredman20:09:44

what is the the alias doing?

hiredman20:09:11

what are the main opts?

matthavener20:09:33

it's actually two, both adding :extra-pathsand :extra-deps

hiredman20:09:57

but no :main-opts?

hiredman20:09:54

are you aot compiling your gen-class somehow? (gen-class is a no op without aot)

matthavener20:09:29

I assume I'm doing something weird. I have an alias named nrepl that adds nrepl to the deps and then includes a path with a user.clj

matthavener20:09:40

I don't think I'm doing aot, not for dev

hiredman20:09:52

oh, try it without the user.clj (rename it to foo.clj or something)

matthavener20:09:14

yeah, without that user.clj I don't think it pulls in the offending namespace so it works fine

matthavener20:09:36

what's the accepted way of adding nrepl? I put this in my user.clj and it seemed so.. wrong:

matthavener20:09:54

(ns user (:require [proj.main :as main] [nrepl.server :as nrepl])) (defonce nrepl-server (nrepl/start-server)) (spit "./.nrepl-port" (:port nrepl-server)) (main/-main)

hiredman20:09:43

and what happens if you start your repl without the user.clj and load proj.main and call (proj.main/-main)

matthavener20:09:30

yeah, then I see the compile error when I (require 'proj.main)

hiredman20:09:18

oh, of course, user.clj is loaded so early it doesn't have all the error reporting stuff around it

hiredman20:09:05

I don't know how people launch nrepl these days

matthavener20:09:11

I suppose I should just make my user.clj more simple and have some go function that actually runs my app

matthavener20:09:21

I was used to lein repl doing everything for me

matthavener20:09:22

thank you for your help, that error reporting explanation makes sense

matthavener20:09:41

I just thought I might be missing some glaringly obvious flag on clj or doing something silly