Fork me on GitHub
#leiningen
<
2023-10-26
>
souenzzo10:10:27

does lein provides an API to parse a project.clj and get name, version, etc?

vemv10:10:28

nope for basic needs, Maven-level xml metadata should answer the basic q's otherwise, your best bet is to make a plugin (that can also simply be inlined as a :middleware) that dumps the value of project (after applying profiles, other plugins, etc) to foo.edn or stdout

hiredman15:10:03

defproject allows for code execution, so you have to read and eval

souenzzo15:10:20

somewhere inside lein's code, it calls (read-string (slurp "project.clj")). Where is it?

hifumi12323:10:13

@U45T93RA6 are you sure? i've used leiningen.core.project/read-raw to parse defproject forms. this is not an internal or private API, as those are marked with ^:internal

hifumi12323:10:38

@U2J4FRT2T does it actually call slurp? last time I had to care about how leiningen loads project, I discovered that a project.clj is read as File or Reader, but no explicit hardcoding of paths via slurp

vemv02:10:43

Depends on what you intend to do. The name read-raw is fairly self-explanatory. "read and eval" or read-raw would probably not give you the same values that a full-blown Lein evaluation would give you. For instance defproject ~(my computation) might depend on 3 things: the eval itself, any plugins present, and any profiles present.

vemv02:10:52

IMO the key thing to keep in mind is that project.clj is not data, is code, and the more accurately you perform that code evaluation, the better Thankfully this is super easy - as mentioned, you don't even need to make a separate plugin https://github.com/nedap/formatting-stack/blob/6fc23a538aea3fd256b39647b412b70973091c9d/project.clj#L87-L104