From ac164b4de65f0c9714ef4d04e1e47f76d89edd6d Mon Sep 17 00:00:00 2001
From: adrianciu <adrian.ciu@codemart.ro>
Date: Wed, 26 Mar 2025 14:14:39 +0200
Subject: [PATCH] added compatibility for not existing bashrc path
---
dedal/spack_factory/SpackOperation.py | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/dedal/spack_factory/SpackOperation.py b/dedal/spack_factory/SpackOperation.py
index ca717572..8eaf3ef5 100644
--- a/dedal/spack_factory/SpackOperation.py
+++ b/dedal/spack_factory/SpackOperation.py
@@ -389,20 +389,21 @@ class SpackOperation:
else:
self.logger.debug("Spack already cloned.")
- # ensure the file exists before opening it
- if not os.path.exists(bashrc_path):
- open(bashrc_path, "w").close()
- # add spack setup commands to .bashrc
- with open(bashrc_path, "a") as bashrc:
- bashrc.write(f'export PATH="{self.spack_dir}/bin:$PATH"\n')
- spack_setup_script = f"source {self.spack_dir / 'share' / 'spack' / 'setup-env.sh'}"
- bashrc.write(f"{spack_setup_script}\n")
- self.logger.info("Added Spack PATH to .bashrc")
+ if bashrc_path:
+ # ensure the file exists before opening it
+ if not os.path.exists(bashrc_path):
+ open(bashrc_path, "w").close()
+ # add spack setup commands to .bashrc
+ with open(bashrc_path, "a") as bashrc:
+ bashrc.write(f'export PATH="{self.spack_dir}/bin:$PATH"\n')
+ spack_setup_script = f"source {self.spack_dir / 'share' / 'spack' / 'setup-env.sh'}"
+ bashrc.write(f"{spack_setup_script}\n")
+ self.logger.info("Added Spack PATH to .bashrc")
if user:
run_command("chown", "-R", f"{user}:{user}", self.spack_dir, check=True, logger=self.logger,
info_msg='Adding permissions to the logged in user')
self.logger.info("Spack install completed")
- if self.spack_config.use_spack_global is True:
+ if self.spack_config.use_spack_global is True and bashrc_path is not None:
# Restart the bash only of the spack is used globally
self.logger.info('Restarting bash')
run_command("bash", "-c", f"source {bashrc_path}", check=True, logger=self.logger, info_msg='Restart bash')
--
GitLab