Skip to content

Commit

Permalink
first run of the tutorial with spack!
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed May 14, 2021
1 parent ee3ede5 commit a529fad
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions snakemake/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,10 @@ def write_script(self, preamble, fd):
fd.write(self.source)

def _is_python_env(self):
print("IS PYTHON ENV in script.py")
import IPython
IPython.embed()
if self.conda_env is not None:
prefix = os.path.join(self.conda_env, "bin")
elif self.spack_env is not None:
prefix = os.path.join(self.spack_env, ".spack-env", "view", "bin")
elif self.env_modules is not None:
prefix = self._execute_cmd("echo $PATH", read=True).split(":")[0]
else:
Expand All @@ -487,16 +486,15 @@ def _get_python_version(self):
return tuple(map(int, out.strip().split(".")))

def execute_script(self, fname, edit=False):
# Are we operating in a spack or conda environment?
is_env = self.conda_env is not None or self.spack_env is not None

py_exec = sys.executable
if self.container_img is not None:
# use python from image
py_exec = "python"

# TODO stopped here, need to add spack_env command.
print("SCRIPT.PY EXECUTE")
import IPython
IPython.embed()
elif self.conda_env is not None or self.env_modules is not None:
elif is_env or self.env_modules is not None:
if self._is_python_env():
py_version = self._get_python_version()
# If version is None, all fine, because host python usage is intended.
Expand All @@ -520,6 +518,7 @@ def execute_script(self, fname, edit=False):
# use forward slashes so script command still works even if
# bash is configured as executable on Windows
py_exec = py_exec.replace("\\", "/")

# use the same Python as the running process or the one from the environment
self._execute_cmd("{py_exec} {fname:q}", py_exec=py_exec, fname=fname)

Expand Down

0 comments on commit a529fad

Please sign in to comment.