Skip to content

Commit

Permalink
Fix environment-modules hashing to support dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasjacobsen committed Oct 16, 2024
1 parent 035f1da commit 2807327
Showing 1 changed file with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,43 @@ class EnvironmentModules(PackageManagerBase):
run_before=["make_experiments"],
)

def _generate_loads_content(self, workspace):
if not hasattr(self, "_load_string"):
app_context = self.app_inst.expander.expand_var_name(
self.keywords.env_name
)

require_env = self.environment_required()

software_envs = workspace.software_environments
software_env = software_envs.render_environment(
app_context, self.app_inst.expander, self, require=require_env
)

load_content = []

if software_env is not None:
for spec in software_envs.package_specs_for_environment(
software_env
):
load_content.append(f"module load {spec}")

self._load_string = "\n".join(load_content)

return self._load_string

def populate_inventory(
self, workspace, force_compute=False, require_exist=False
):
env_path = self.app_inst.expander.env_path

self.app_inst.hash_inventory["package_manager"].append(
{
"name": self.name,
}
)

env_hash = ramble.util.hashing.hash_file(
os.path.join(env_path, "module_loads")
env_path = self.app_inst.expander.env_path
env_hash = ramble.util.hashing.hash_string(
self._generate_loads_content(workspace)
)

self.app_inst.hash_inventory["software"].append(
Expand All @@ -58,32 +82,16 @@ def populate_inventory(
)

def _write_module_commands(self, workspace, app_inst=None):

app_context = self.app_inst.expander.expand_var_name(
self.keywords.env_name
)

require_env = self.environment_required()

software_envs = workspace.software_environments
software_env = software_envs.render_environment(
app_context, self.app_inst.expander, self, require=require_env
)

env_path = self.app_inst.expander.env_path

module_file_path = os.path.join(env_path, "module_loads")

fs.mkdirp(env_path)

module_file = open(module_file_path, "w+")
loads_content = self._generate_loads_content(workspace)

if software_env is not None:
for spec in software_envs.package_specs_for_environment(
software_env
):
module_file.write(f"module load {spec}\n")
module_file.close()
with open(module_file_path, "w+") as f:
f.write(loads_content)

register_builtin("module_load", required=True)

Expand Down

0 comments on commit 2807327

Please sign in to comment.