Skip to content
Snippets Groups Projects
Commit ac164b4d authored by Adrian Ciu's avatar Adrian Ciu
Browse files

added compatibility for not existing bashrc path

parent 014c9eae
No related branches found
No related tags found
No related merge requests found
Pipeline #60629 passed with stages
in 35 minutes and 53 seconds
...@@ -389,20 +389,21 @@ class SpackOperation: ...@@ -389,20 +389,21 @@ class SpackOperation:
else: else:
self.logger.debug("Spack already cloned.") self.logger.debug("Spack already cloned.")
# ensure the file exists before opening it if bashrc_path:
if not os.path.exists(bashrc_path): # ensure the file exists before opening it
open(bashrc_path, "w").close() if not os.path.exists(bashrc_path):
# add spack setup commands to .bashrc open(bashrc_path, "w").close()
with open(bashrc_path, "a") as bashrc: # add spack setup commands to .bashrc
bashrc.write(f'export PATH="{self.spack_dir}/bin:$PATH"\n') with open(bashrc_path, "a") as bashrc:
spack_setup_script = f"source {self.spack_dir / 'share' / 'spack' / 'setup-env.sh'}" bashrc.write(f'export PATH="{self.spack_dir}/bin:$PATH"\n')
bashrc.write(f"{spack_setup_script}\n") spack_setup_script = f"source {self.spack_dir / 'share' / 'spack' / 'setup-env.sh'}"
self.logger.info("Added Spack PATH to .bashrc") bashrc.write(f"{spack_setup_script}\n")
self.logger.info("Added Spack PATH to .bashrc")
if user: if user:
run_command("chown", "-R", f"{user}:{user}", self.spack_dir, check=True, logger=self.logger, run_command("chown", "-R", f"{user}:{user}", self.spack_dir, check=True, logger=self.logger,
info_msg='Adding permissions to the logged in user') info_msg='Adding permissions to the logged in user')
self.logger.info("Spack install completed") 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 # Restart the bash only of the spack is used globally
self.logger.info('Restarting bash') self.logger.info('Restarting bash')
run_command("bash", "-c", f"source {bashrc_path}", check=True, logger=self.logger, info_msg='Restart bash') run_command("bash", "-c", f"source {bashrc_path}", check=True, logger=self.logger, info_msg='Restart bash')
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment