diff --git a/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py b/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py index de01258f..6a5ac7cd 100644 --- a/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py +++ b/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py @@ -90,20 +90,25 @@ class DistroContext(FilesContext): ret: list[str] = [] failed: list[str] = [] missing = 0 - targets = await self.list_compilation_targets(pkg_names) - for target in targets: - try: - ok = await self.compile_template_file(target, default_attrs) - except Exception as e: - if not keep_going: - raise - log(ERR, f'{target}: {e}') - failed.append(target) - continue - if ok: - ret.append(target) - else: - missing += 1 + # -- Keep the exec context and the store open across the whole + # compile, so the run() calls in the per-target operations + # bump the reference counter instead of opening and closing + # the connection for every remote command. + async with self.ctx, self.store: + targets = await self.list_compilation_targets(pkg_names) + for target in targets: + try: + ok = await self.compile_template_file(target, default_attrs) + except Exception as e: + if not keep_going: + raise + log(ERR, f'{target}: {e}') + failed.append(target) + continue + if ok: + ret.append(target) + else: + missing += 1 if missing > 0: from ....lib.util import pretty_cmd