Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conda python interpreter path on Windows #1711

Merged
merged 6 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions snakemake/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,18 @@ def write_script(self, preamble, fd):
fd.write(self.source.encode())

def _is_python_env(self):
if self.conda_env is not None:
if self.conda_env is not None and ON_WINDOWS:
prefix = self.conda_env
elif self.conda_env is not None:
prefix = os.path.join(self.conda_env, "bin")
elif self.env_modules is not None:
prefix = self._execute_cmd("echo $PATH", read=True).split(":")[0]
else:
raise NotImplementedError()
return os.path.exists(os.path.join(prefix, "python"))
if not ON_WINDOWS:
return os.path.exists(os.path.join(prefix, "python"))
else:
return os.path.exists(os.path.join(prefix, "python.exe"))

def _get_python_version(self):
out = self._execute_cmd(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_conda_python_script/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rule random_python_conda_script:
output:
"version.txt"
conda:
"test_python_env.yaml"
script:
"test_script.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.21.4
6 changes: 6 additions & 0 deletions tests/test_conda_python_script/test_python_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
channels:
- conda-forge
- defaults
dependencies:
- numpy ==1.21.4
- python <3.10
4 changes: 4 additions & 0 deletions tests/test_conda_python_script/test_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import numpy

with open('version.txt', 'w') as f:
f.write(numpy.__version__)
4 changes: 4 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,3 +1659,7 @@ def test_conda_pin_file():
@skip_on_windows # sufficient to test this on linux
def test_github_issue1618():
run(dpath("test_github_issue1618"), cores=5)


def test_conda_python_script():
run(dpath("test_conda_python_script"), use_conda=True)