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: consider post-deploy script for env hashing #1363

Merged
merged 9 commits into from Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion snakemake/deployment/conda.py
Expand Up @@ -102,7 +102,11 @@ def _get_content(self):
def _get_content_deploy(self):
self.check_is_file_based()
deploy_file = Path(self.file).with_suffix(".post-deploy.sh")
return self.workflow.sourcecache.open(deploy_file, "rb").read()
if deploy_file.exists():
return self.workflow.sourcecache.open(
infer_source_file(deploy_file), "rb"
).read()
return None

@property
def _env_archive_dir(self):
Expand Down Expand Up @@ -139,6 +143,9 @@ def hash(self):
md5hash.update(env_dir.encode())
if self._container_img:
md5hash.update(self._container_img.url.encode())
content_deploy = self.content_deploy
if content_deploy:
md5hash.update(self.content_deploy)
md5hash.update(self.content)
self._hash = md5hash.hexdigest()
return self._hash
Expand All @@ -148,6 +155,9 @@ def content_hash(self):
if self._content_hash is None:
md5hash = hashlib.md5()
md5hash.update(self.content)
content_deploy = self.content_deploy
if content_deploy:
md5hash.update(content_deploy)
self._content_hash = md5hash.hexdigest()
return self._content_hash

Expand Down
19 changes: 19 additions & 0 deletions tests/test_deploy_hashing/Snakefile
@@ -0,0 +1,19 @@
rule all:
input:
expand("{s}.txt", s=["a", "b"])

rule a:
output:
"a.txt"
conda:
"a.yaml"
shell:
"touch {output}"

rule b:
output:
"b.txt"
conda:
"b.yaml"
shell:
"touch {output}"
3 changes: 3 additions & 0 deletions tests/test_deploy_hashing/a.post-deploy.sh
@@ -0,0 +1,3 @@
#!/bin/bash

echo "test" > $CONDA_PREFIX/a.txt
5 changes: 5 additions & 0 deletions tests/test_deploy_hashing/a.yaml
@@ -0,0 +1,5 @@
channels:
- bioconda
- conda-forge
dependencies:
- python =3.10
5 changes: 5 additions & 0 deletions tests/test_deploy_hashing/b.yaml
@@ -0,0 +1,5 @@
channels:
- bioconda
- conda-forge
dependencies:
- python =3.10
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions tests/tests.py
Expand Up @@ -434,6 +434,12 @@ def test_deploy_script():
run(dpath("test_deploy_script"), use_conda=True)


@skip_on_windows
def test_deploy_hashing():
tmpdir = run(dpath("test_deploy_hashing"), use_conda=True, cleanup=False)
assert len(next(os.walk(os.path.join(tmpdir, ".snakemake/conda")))[1]) == 2


def test_conda_custom_prefix():
run(
dpath("test_conda_custom_prefix"),
Expand Down