Fork me on GitHub
#leiningen
<
2018-09-14
>
gfredericks20:09:14

so I have a lein plugin that adds a profile in its middleware I expect, after adding that plugin to a project in its top-level :plugins, that I can use that profile, e.g. via :profiles {:dev [:my-profile {...}]}

gfredericks20:09:57

this seems to work, except that leiningen prints a warning saying the profile is not found

gfredericks20:09:03

as far I as can tell it's being used

gfredericks20:09:13

if I add a println to the middleware, I can tell the warning is printed before the middleware is run

gfredericks20:09:42

is there some better way for a plugin to register a profile?

mikerod21:09:15

@gfredericks I think this is common

mikerod21:09:18

and I think it is fine

mikerod21:09:27

This is based on some investigation of the same issue I did a while back

mikerod21:09:49

If you track back through history in lein you can see the change was made to make that “missing profile” thing a warning instead of failing - it used to fail.

mikerod21:09:18

the reason is that plugins may add profiles, but there are earlier “passes” over the project map where those haven’t been added yet. I think there were issues related to this

mikerod21:09:31

I ended up concluding that it was just a false-positive warning though

mikerod21:09:19

wish I had better notes on it though, to not have to re-remember it

gfredericks21:09:30

a false positive is a pretty severe thing to put up with though

gfredericks21:09:49

I guess I should clarify that at this point I'm complaining about having to see the warning; I don't think I have any other issues

gfredericks21:09:16

hmm; seems I can suppress the warning by adding an empty version of the profile to the top-level :profiles map and the provided one still works

gfredericks21:09:34

so that's significantly better

mikerod21:09:19

I guess it never failed, it used to just not report anything

mikerod21:09:44

if you can add a top-level that helps, but that means anyone using your plugin would have to do that

mikerod21:09:59

It’s a non-ideal false positive, I agree

mikerod21:09:15

but the profile lookup logic happens several times throughout the initialization of things

mikerod21:09:19

and one time is prior to plugins being loaded

gfredericks21:09:20

yeah both solutions are annoying, but the extra entry is less annoying than a printed warning on every task

gfredericks21:09:47

do you think this is Fundamentally Unsolvable?

mikerod21:09:03

I was pretty sure I saw discussion on this a long while back, but can’t find anything now

mikerod21:09:09

I don’t see how to solve the problem

gfredericks21:09:23

any chance that warnings could be queued up until all middlewares have been processed?

mikerod21:09:26

I think profiles need to be looked-up prior to plugin loading

mikerod21:09:33

because they may be being used to get plugins

mikerod21:09:46

So it’s a which comes first, the chicken-or-the-egg situation

mikerod21:09:05

that’s my take on it at least

gfredericks21:09:27

at worst there could be a less hacky warning suppression mechanism

:suppress-missing-profile-warnings #{:my-profile}

mikerod21:09:55

still would require people to add that to use the plugin hah

gfredericks21:09:56

this plugin is top-level

mikerod21:09:00

the plugin doesn’t get to “do anything” before this warning

mikerod21:09:03

because it isn’t loaded yet

gfredericks21:09:12

so you should be able to at least run the top-level plugin middlewares before loading any profiles

mikerod21:09:17

Yeah, maybe it could try that

mikerod21:09:29

At least on the surface, that sounds feasible

mikerod21:09:49

but I’m not sure how hard that’d be or if that’d mess up any other initialization steps that are expected prior to plugin loading

mikerod21:09:03

could be an issue I think

mikerod21:09:06

Say you have 2 plugins

mikerod21:09:17

:plugins [A B]

mikerod21:09:32

if plugin B adds the profile, but A goes first in terms of initializing

mikerod21:09:03

then A may need to see the :profiles, so will have to load them before B gets to and then the missing warning would happen right?

gfredericks21:09:18

plugins can see profiles?

mikerod21:09:31

they get the project

mikerod21:09:51

as first arg to the plugin fn

mikerod21:09:00

and that project is “initialized” or whatever you want to call it

gfredericks21:09:47

it seems like there's no good mechanism for a plugin to add non-production things to a project

gfredericks21:09:10

dependencies in particular are what I'm concerned with

mikerod21:09:39

within a profile perhaps, but idk

mikerod21:09:05

lein-modules may do some similar sorts of things https://github.com/jcrossley3/lein-modules

mikerod21:09:19

if looking through that perhaps had any analogies to what you are wanting to do.

mikerod21:09:32

then again, it may be doing “production things” in its cases