Fork me on GitHub
#leiningen
<
2020-05-04
>
Marco Nicolodi13:05:20

Hi folks. Is it possible to update two values that are not in the same tree branch of a defproject using lein update-in? Im creating codox related settings at pipeline time to generate docs. I need to update both the :codox and the :profiles :dev :dependencies values. I tried to use multiple update-in (as seen in the code below) but I couldnt make it work.

lein update-in :codox assoc :themes "[\"rdash\"]" :metadata "{:doc/format :markdown}" \
      -- update-in :profiles:dev:dependencies conj "[codox-theme-rdash \"0.1.2\"]" \
      -- update-in :plugins conj "[lein-codox \"0.10.7\"]" \
      -- codox

mikerod13:05:09

To chain tasks you use do

mikerod13:05:12

Does that work?

mikerod13:05:29

Now that I say it. Thinking it doesnt

Marco Nicolodi13:05:09

lol so simple! gonna try. it would be awesome. thank you friend!

mikerod13:05:32

Looks like you were doing it right. Sure it doesn’t work? Ha

Marco Nicolodi14:05:25

im not using the single : as the defproject root, maybe its related to that. Im going to try multiple calls with do.

mikerod14:05:30

I don’t think do was a good suggestion

mikerod14:05:35

It doesn’t “chain”

Chase15:05:00

So I have cider/cider-nrepl in my Lein profiles.clj just so I can quickly get a nrepl going with lein repl in random projects that I am exploring. In my official projects though I usually throw it in my project.clj because I think things like shadow-cljs will inject required middleware once it sees that dependency.

noisesmith16:05:19

wouldn't they see cider/cider-nrepl once it's injected by profiles.clj? that should haappen before their code runs

Chase16:05:28

Good question. I am not sure. Let me go test that real quick.

Chase16:05:11

Oh wait, I might have been super dumb with this question as it pertains to shadow-cljs because calling shadow-cljs watch app has nothing to do with lein.

Chase16:05:00

As in, I am not even using lein in that project. shadow-cljs calls the nrepl itself but that might not be necessarily the case always so I was still curious

Chase15:05:13

Can these two things conflict or will the project.clj take precedence?

mikerod16:05:59

@chase-lambert think you end up with both

mikerod16:05:02

but only one wins

mikerod16:05:10

I believe the last one declared wins - going through :dependencies or :plugins order (they are sequentials (eg. vectors))

Marco Nicolodi18:05:04

using pprint for debugging both of these generate valid projects:

lein update-in :codox assoc :themes "[\"rdash\"]" :metadata "{:doc/format :markdown}" -- \
      update-in :profiles:dev:dependencies conj "[codox-theme-rdash \"0.1.2\"]" -- \
      codox
and
lein update-in :codox assoc :themes "[\"rdash\"]" :metadata "{:doc/format :markdown}" -- \
      update-in : assoc :profiles "{:dev {:dependencies  [[codox-theme-rdash \"0.1.2\"]]}}" -- \
      codox
I think the problem is that im adding a new dependency, and therefore I would need to build the classpath again. Does it make sense @mikerod ?

Marco Nicolodi19:05:27

actually i dont think it makes sense, since codox does build the classpath

Marco Nicolodi19:05:38

but its still failing with Could not find Codox theme: :rdash

Marco Nicolodi19:05:49

"{:clojure.main/message \"Syntax error (IllegalArgumentException) compiling at (/private/var/folders/vd/nd1wrjqx4p5bxvsx38gr9n440000gn/T/form-init1582674147706229508.clj:1:125).\ Could not find Codox theme: :rdash\ \", :clojure.main/triage {:clojure.error/phase :compile-syntax-check, :clojure.error/line 1, :clojure.error/column 125, :clojure.error/source \"form-init1582674147706229508.clj\", :clojure.error/path \"/private/var/folders/vd/nd1wrjqx4p5bxvsx38gr9n440000gn/T/form-init1582674147706229508.clj\", :clojure.error/class java.lang.IllegalArgumentException, :clojure.error/cause \"Could not find Codox theme: :rdash\"}, :clojure.main/trace {:via [{:type clojure.lang.Compiler$CompilerException, :message \"Syntax error compiling at (/private/var/folders/vd/nd1wrjqx4p5bxvsx38gr9n440000gn/T/form-init1582674147706229508.clj:1:125).\", :data {:clojure.error/phase :compile-syntax-check, :clojure.error/line 1, :clojure.error/column 125, :clojure.error/source \"/private/var/folders/vd/nd1wrjqx4p5bxvsx38gr9n440000gn/T/form-init1582674147706229508.clj\"}, :at [clojure.lang.Compiler load \"Compiler.java\" 7648]} {:type java.lang.IllegalArgumentException, :message \"Could not find Codox theme: :rdash\", :at [codox.writer.html$apply_one_theme invokeStatic \"html.clj\" 499]}], :trace [[codox.writer.html$apply_one_theme invokeStatic \"html.clj\" 499] [codox.writer.html$apply_one_theme invoke \"html.clj\" 496] [clojure.lang.PersistentVector reduce \"PersistentVector.java\" 343] [clojure.core$reduce invokeStatic \"core.clj\" 6827] [clojure.core$reduce invoke \"core.clj\" 6810] [codox.writer.html$apply_theme_transforms invokeStatic \"html.clj\" 502] [codox.writer.html$apply_theme_transforms invoke \"html.clj\" 501] [codox.writer.html$write_docs invokeStatic \"html.clj\" 507] [codox.writer.html$write_docs invoke \"html.clj\" 504] [clojure.lang.Var invoke \"Var.java\" 384] [codox.main$generate_docs invokeStatic \"main.clj\" 125] [codox.main$generate_docs invoke \"main.clj\" 116] [user$eval11272 invokeStatic \"form-init1582674147706229508.clj\" 1] [user$eval11272 invoke \"form-init1582674147706229508.clj\" 1] [clojure.lang.Compiler eval \"Compiler.java\" 7177] [clojure.lang.Compiler eval \"Compiler.java\" 7166] [clojure.lang.Compiler eval \"Compiler.java\" 7167] [clojure.lang.Compiler load \"Compiler.java\" 7636] [clojure.lang.Compiler loadFile \"Compiler.java\" 7574] [clojure.main$load_script invokeStatic \"main.clj\" 475] [clojure.main$init_opt invokeStatic \"main.clj\" 477] [clojure.main$init_opt invoke \"main.clj\" 477] [clojure.main$initialize invokeStatic \"main.clj\" 508] [clojure.main$null_opt invokeStatic \"main.clj\" 542] [clojure.main$null_opt invoke \"main.clj\" 539] [clojure.main$main invokeStatic \"main.clj\" 664] [clojure.main$main doInvoke \"main.clj\" 616] [clojure.lang.RestFn applyTo \"RestFn.java\" 137] [clojure.lang.Var applyTo \"Var.java\" 705] [clojure.main main \"main.java\" 40]], :cause \"Could not find Codox theme: :rdash\", :phase :compile-syntax-check}} "

Marco Nicolodi19:05:11

adding to :dependencies instead of :profiles:dev:dependencies seem to work. Good enough. But I didnt got what happened.

mikerod13:05:24

@marcocontatopro sorry, didn’t get to look at this. not familiar with the plugin and it sounds like the solution was related to how it works

mikerod13:05:47

if you put it in :dev it may not have been merged in in time for when you were calling the task

mikerod13:05:13

:dev profile is a default that is merged in in most tasks, bbut that’s not always true and also depends on what you are doing if profiles are merged implicitly ahead of time or not

Marco Nicolodi17:05:18

thanks for clarifying

Marco Nicolodi17:05:01

you certainly helped pointing that my script should work and linking that github PR 🙂

mikerod17:05:15

nice, yeah pprint can be helpful in many cases