plugin: Checking other plugins
I haven't checked that it works, but my understanding is that this is one way to check the plugin type of a particular step:
# Check that there is a prepare CMake step
if not any(
phase
for step in self.step.plan.steps()
if isinstance(step, Prepare)
for phase in step.phases(tmt_cmake.prepare.PrepareCMake)
):
msg = "No CMake prepare step found"
raise tmt.utils.SpecificationError(msg)
Two simplifications that can be done here:
-
tmt.plan.stepsacceptingclassessimilar to thestep.phases - Have a
tmt.plan.phasesthat wraps the generator above. Maybe these should be as mixin since thetmt.base.Planis quite lengthy. Although that would make it less navigable?
Second question for this, where should such a check be. I believe the most appropriate place so far is in wake? It should be in a place that:
- Guarantees all steps and phases are defined
- Is run for lint/show steps as well.
Edit: Tried it out and wake does not affect those cases, so it might need to be spread out different entry points
I have then tried to add it to show, but it seems in the current version show does not error when bogus data is given, so I should not use raise for that case. Right now I am using using try...except and redirecting the output to warning. Thinking of doing the same for wake but redirecting to fail. Technically this should be handled by the schema validation, but it is not portable to external plugins yet.
I think the thing that confuses me here is how one should add messages and raise, so as to not affect the remainder of the execution. E.g. if I raise within show or wake, the execution of the remainder of the tmt show/run fails, i.e. other tmt plans are stopped and do not execute.
Update this does not work :(. The phases are not available at the wake/show stage and not all steps are computed at that point. The closest I could get is to check step.data type
@LecrisUT, what is the main motivation here?
The goal is similar to #3970 to provide a simpler interface for operating with the steps. Here the goal is to get and check the presence of a specific step plugin in different phases, e.g. discover phase CMakeDiscover checks if a CMakePrepare phase is defined as a required step instead of injecting the prepare step itself and cramming the interface.