Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you determine the current leiningen profiles from a running repl?

The current set of active profiles is not clear when your IDE has started the REPL for you. In this case, can you query Leiningen somehow to figure out what they may be?

like image 831
Ian Tegebo Avatar asked Jun 16 '16 20:06

Ian Tegebo


2 Answers

Usually I define various profiles on my project.clj pointing to different config files for each one of them like

  :profiles {:release {:resource-paths ["config/release"]
                          :source-paths ["src"]
                          }
             :test {:resource-paths ["config/test"]
                       :source-paths ["src" "test"]
                       }
             :dev {:resource-paths ["config/dev"]
                   :source-paths ["src" "dev"]}}

So, for every folder inside "config" has a config.edn in it containing the needed info for every profile that I have, you could add a :profile keyword in each config.edn with a different value for each one to show which profile is active at that moment. I use yogthos config to load the config files.

Besides that, I really don't the idea of the IDE controlling the nrepl, normally it kills the repl when the IDE is closed and they can be very restrictive on the options you pass to lein. I prefer to start the repl in a different terminal than my editor with lein with-profile dev repl and then connecting that nrepl session on my editor, that way you'll be sure of which profile you are using.

like image 77
lsevero Avatar answered Dec 08 '22 21:12

lsevero


To my knowledge there is no way to see which profiles are loaded as part of a running REPL. Just like any program wouldn't know which terminal window it was started from. That said, profiles and how they work is documented.

Also it isn't always enough to just know which are "active". Sometimes it is also relevant to know in which order.

To play around with this add the following to your project.clj:

  :profiles {
             :dev {:injections [(prn "including dev profile")]}
             :test {:injections [(prn "including test profile")]}
             :repl {:injections [(prn "including repl profile")]}
             :my-profile {:injections [(prn "including my-profile profile")]}

Now run the following and look for the output "including ...:

lein repl
lein test
lein with-profile my-profile test
lein with-profile +my-profile test

Note that :injections is not executed in jars or uberjars (lein jar and lein uberjar). Which is why I excluded this from the above playground.

like image 37
Jacob Avatar answered Dec 08 '22 21:12

Jacob