leiningen

souenzzo 2023-10-26T10:46:27.289529Z

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

vemv 2023-10-26T10:53:28.483539Z

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

2023-10-26T15:44:03.239339Z

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

souenzzo 2023-10-26T15:47:20.094969Z

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

hifumi123 2023-10-26T23:03:13.157139Z

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

hifumi123 2023-10-26T23:07:38.354739Z

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

vemv 2023-10-27T02:49:43.412389Z

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.

vemv 2023-10-27T02:51:52.596099Z

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