Skip to content

Commit

Permalink
Use concrete step data class when injecting requires
Browse files Browse the repository at this point in the history
Besides raw data, `Step.delegate()` can accept data class instance too.
Converting `prepare` step to use this method to provide better type
safety.
  • Loading branch information
happz authored and psss committed Aug 13, 2024
1 parent efa026f commit cea09fe
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions tmt/steps/prepare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def as_key(self) -> frozenset['tmt.base.DependencySimple']:
#
# 1. make the list of requirements unique,
# 2. group guests with same requirements.
from tmt.steps.prepare.install import _RawPrepareInstallStepData
from tmt.steps.prepare.install import PrepareInstallData

pruned_requires: dict[frozenset[tmt.base.DependencySimple], DependencyCollection] = {}
pruned_recommends: dict[frozenset[tmt.base.DependencySimple], DependencyCollection] = {}
Expand All @@ -294,34 +294,31 @@ def as_key(self) -> frozenset['tmt.base.DependencySimple']:
if not collection.dependencies:
continue

data: _RawPrepareInstallStepData = {
'how': 'install',
'name': 'requires',
'summary': 'Install required packages',
'order': tmt.utils.DEFAULT_PLUGIN_ORDER_REQUIRES,
'where': [guest.name for guest in collection.guests],
'package': [
dependency.to_spec()
for dependency in collection.dependencies
]}
self._phases.append(PreparePlugin.delegate(self, raw_data=data))
data = PrepareInstallData(
name='requires',
how='install',
summary='Install required packages',
order=tmt.utils.DEFAULT_PLUGIN_ORDER_REQUIRES,
where=[guest.name for guest in collection.guests],
package=collection.dependencies
)

self._phases.append(PreparePlugin.delegate(self, data=data))

for collection in pruned_recommends.values():
if not collection.dependencies:
continue

data = {
'how': 'install',
'name': 'recommends',
'summary': 'Install recommended packages',
'order': tmt.utils.DEFAULT_PLUGIN_ORDER_RECOMMENDS,
'where': [guest.name for guest in collection.guests],
'package': [
dependency.to_spec()
for dependency in collection.dependencies
],
'missing': 'skip'}
self._phases.append(PreparePlugin.delegate(self, raw_data=data))
data = PrepareInstallData(
how='install',
name='recommends',
summary='Install recommended packages',
order=tmt.utils.DEFAULT_PLUGIN_ORDER_RECOMMENDS,
where=[guest.name for guest in collection.guests],
package=collection.dependencies,
missing='skip')

self._phases.append(PreparePlugin.delegate(self, data=data))

# Prepare guests (including workdir sync)
guest_copies: list[Guest] = []
Expand Down

0 comments on commit cea09fe

Please sign in to comment.