scala-steward icon indicating copy to clipboard operation
scala-steward copied to clipboard

Is it possible to switch the order of execution between the ScalaFix and the Hook executor

Open alifirat opened this issue 3 years ago • 6 comments

I would like to know if it's possible to switch in the execution of the EditAlg the steps that did the ScalaFix migration and the Hook executor.

My use case is that when I'm running ScalaFix, it needs some Protobuf files that I need to fetch before the rules migration and with the current state it's going to work since the migration is run before the hook executor (see here)

I don't see a constraint to swap the both in the current code there is no link between them but maybe a better solution is to add a pre hook execution instead to swap them ?

alifirat avatar Jan 06 '22 14:01 alifirat

Since the impact of this seems to go beyond steward, did you consider redefining the scalafixAll input task key (called by Steward) in your build to materialize your dependency to the protobuf fetching?

    scalafixAll := scalafixAll.dependsOn(Def.task {
      // fetch protos
    }).evaluated

bjaglin avatar Feb 09 '22 14:02 bjaglin

Hey @bjaglin I didn't consider that at all, this is something that I need to define in the build.sbt of my projects I guess ?

alifirat avatar Feb 09 '22 14:02 alifirat

Hey @bjaglin I didn't consider that at all, this is something that I need to define in the build.sbt of my projects I guess ?

Indeed, in the project scope since that's where the input task is defined.

bjaglin avatar Feb 09 '22 14:02 bjaglin

Ok thanks @bjaglin for the tip, I will try that let you know :)

alifirat avatar Feb 09 '22 14:02 alifirat

Hey @bjaglin @fthomas I would like to give a feedback around this topic and for any person that needs to fetch external resources of a project. I've decided to follow an another direction based on this sbt documentation.

The idea is to override the onLoad hook when running sbt and basically I'm calling a script that fetch the external resources allowing to run successfully run ScalaFix. I've tested on a real project and what a success! We're able to bump the scalatest version resulting with a PR of +700 lines of code changes.

Maybe in the same idea than the postHook available after every update, we think to implement a preHook but that should be execute before ScalaFix. Any glue on that ?

alifirat avatar Apr 14 '22 13:04 alifirat

The idea is to override the onLoad hook when running sbt and basically I'm calling a script that fetch the external resources allowing to run successfully run ScalaFix

onLoad works, but it obviously has the downside of requiring a sbt restart to get newer resources. What about the suggestion above? I assume scalafix is not the only task needing these protos though... I feel like https://www.scala-sbt.org/1.x/docs/Howto-Generating-Files.html#Generate+resources would better cover your use-case actually. You might have to add some caching/TTL to avoid hitting the network each time though.

Maybe in the same idea than the postHook available after every update, we think to implement a preHook but that should be execute before ScalaFix. Any glue on that ?

Since anyone using your project (human or bot) needs the external resources to be fetched, why would you do that in steward instead of doing it in your build? I am not a steward maintainer but I don't see a strong use-case for your particular scenario.

bjaglin avatar Apr 14 '22 13:04 bjaglin

I agree with @bjaglin's assessment. The build should make sure that all files are available for compilation and if it does, there is no need for a PreUpdateHook in Scala Steward.

I'm not against such hook in principle, but if we add it, there should be strong use-case for it.

fthomas avatar Jan 23 '23 16:01 fthomas