Skip to content

Commit 790f840

Browse files
Merge pull request #942 from linsword13/pkg-prov-cache
Cache package list to reduce hitting the pkgman runner
2 parents fb1eeeb + 3c553e7 commit 790f840

File tree

5 files changed

+40
-49
lines changed

5 files changed

+40
-49
lines changed

lib/ramble/ramble/package_manager.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,22 @@ def _add_software_to_results(self, workspace, app_inst=None):
220220
owns the results.
221221
222222
"""
223-
pass
223+
if app_inst.result is None:
224+
return
225+
prov_cache = workspace.pkg_prov_cache
226+
env_name = self.app_inst.expander.expand_var_name(self.keywords.env_name)
227+
if env_name in prov_cache[self.name]:
228+
# No copy done as this shouldn't be modified once written
229+
pkg_list = prov_cache[self.name][env_name]
230+
else:
231+
pkg_list = self.get_package_list(workspace)
232+
prov_cache[self.name][env_name] = pkg_list
233+
self.app_inst.result.software[self._spec_prefix] = pkg_list
234+
235+
def get_package_list(self, workspace):
236+
"""Method used by add_software_to_results phase to get software provenance info"""
237+
del workspace
238+
return []
224239

225240

226241
class PackageManagerError(RambleError):

lib/ramble/ramble/workspace/workspace.py

+4
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ def __init__(self, root, dry_run=False, read_default_template=True):
468468

469469
self.results = self.default_results()
470470

471+
# A cache structured as {pkg_man: {env_name: pkg_list}}.
472+
# It's used to cache package provenance info from different package managers.
473+
self.pkg_prov_cache = defaultdict(dict)
474+
471475
self.success_list = ramble.success_criteria.ScopedCriteriaList()
472476

473477
# Key for each application config should be it's filepath

var/ramble/repos/builtin/package_managers/environment-modules/package_manager.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,18 @@ def module_list(self):
111111
f"module list &> {list_file}",
112112
]
113113

114-
def _add_software_to_results(self, workspace, app_inst=None):
114+
def get_package_list(self, workspace):
115+
del workspace
116+
app_inst = self.app_inst
115117
list_file = app_inst.expander.expand_var(
116118
f"{{experiment_run_dir}}/{self._list_file}"
117119
)
118120

119-
if app_inst.result is None:
120-
return
121-
122121
if not os.path.exists(list_file):
123-
return
124-
125-
if self._spec_prefix not in app_inst.result.software:
126-
app_inst.result.software[self._spec_prefix] = []
127-
128-
package_list = app_inst.result.software[self._spec_prefix]
122+
return []
129123

124+
pkg_list = []
130125
pkg_regex = re.compile(r"\S+$")
131-
132126
with open(list_file) as f:
133127
packages = re.split(r"[0-9]*\)", f.read())
134128
for spec in packages:
@@ -138,6 +132,7 @@ def _add_software_to_results(self, workspace, app_inst=None):
138132
parts = cleaned.split("/")
139133
name = parts[0]
140134
version = "/".join(parts[1:]) if len(parts) > 1 else ""
141-
package_list.append(
135+
pkg_list.append(
142136
{"name": name, "version": version, "variants": ""}
143137
)
138+
return pkg_list

var/ramble/repos/builtin/package_managers/pip/package_manager.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -213,30 +213,20 @@ def _warn_mirror_support(self, workspace, app_inst=None):
213213
"If a software mirror is required, it needs to be set up outside of Ramble"
214214
)
215215

216-
def _add_software_to_results(self, workspace, app_inst=None):
216+
def get_package_list(self, workspace):
217217
"""Augment the owning experiment's results with software stack information
218218
219-
This is a registered phase by the base package manager class, so here
220-
we only override its base definition.
221-
222-
Args:
223-
workspace (Workspace): A reference to the workspace that owns the
224-
current pipeline
225-
app_inst (Application): A reference to the application instance for
226-
the current experiment
219+
This is called by the `add_software_to_results` phase registered in the base
220+
package manager class.
227221
"""
228-
229222
env_path = self.app_inst.expander.env_path
230223
self.runner.set_dry_run(workspace.dry_run)
231224
self.runner.configure_env(env_path)
232225

233-
if self._spec_prefix not in app_inst.result.software:
234-
app_inst.result.software[self._spec_prefix] = []
235-
236-
package_list = app_inst.result.software[self._spec_prefix]
237-
226+
pkg_list = []
238227
for info in self.runner.package_provenance():
239-
package_list.append(info)
228+
pkg_list.append(info)
229+
return pkg_list
240230

241231

242232
package_name_regex = re.compile(

var/ramble/repos/builtin/package_managers/spack-lightweight/package_manager.py

+7-20
Original file line numberDiff line numberDiff line change
@@ -493,32 +493,19 @@ def get_spec_str(self, pkg, all_pkgs, compiler):
493493
out_str += f" (built with {pkg.compiler})"
494494
return out_str
495495

496-
def _add_software_to_results(self, workspace, app_inst=None):
496+
def get_package_list(self, workspace):
497497
"""Augment the owning experiment's results with software stack information
498498
499-
This is a registered phase by the base package manager class, so here
500-
we only override its base definition.
501-
502-
Args:
503-
workspace (Workspace): A reference to the workspace that owns the
504-
current pipeline
505-
app_inst (Application): A reference to the application instance for
506-
the current experiment
499+
This is called by the `add_software_to_results` phase registered in the base
500+
package manager class.
507501
"""
508-
509-
# Do not manipulate null results
510-
if app_inst.result is None:
511-
return
512-
513-
if self._spec_prefix not in app_inst.result.software:
514-
app_inst.result.software[self._spec_prefix] = []
515-
516-
package_list = app_inst.result.software[self._spec_prefix]
517-
502+
del workspace
503+
pkg_list = []
518504
self.runner.activate()
519505
for info in self.runner.package_provenance():
520-
package_list.append(info)
506+
pkg_list.append(info)
521507
self.runner.deactivate()
508+
return pkg_list
522509

523510

524511
spack_namespace = "spack"

0 commit comments

Comments
 (0)