Skip to content
Permalink
Browse files
fix: consider post-deploy script for env hashing (#1363)
* fix: hash post-deploy scripts

* Add testcase

* Remove printing

* removed redundant call

* fix wrapper test

* fix wrapper test

* propper fix

* Refactoring

* limit to env file
  • Loading branch information
FelixMoelder committed Jan 31, 2022
1 parent 86f8619 commit d50efd9d16d029fb0e5b14b182882c71a20552bb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
@@ -62,8 +62,14 @@ def __init__(
):
self.file = None
self.name = None
self.post_deploy_file = None
if env_file is not None:
self.file = infer_source_file(env_file)
deploy_file = Path(self.file.get_path_or_uri()).with_suffix(
".post-deploy.sh"
)
if deploy_file.exists():
self.post_deploy_file = infer_source_file(deploy_file)
if env_name is not None:
assert env_file is None, "bug: both env_file and env_name specified"
self.name = env_name
@@ -101,8 +107,9 @@ 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 self.post_deploy_file:
return self.workflow.sourcecache.open(self.post_deploy_file, "rb").read()
return None

@property
def _env_archive_dir(self):
@@ -139,6 +146,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(content_deploy)
md5hash.update(self.content)
self._hash = md5hash.hexdigest()
return self._hash
@@ -148,6 +158,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

@@ -317,11 +330,7 @@ def create(self, dryrun=False):
tmp.write(self.content)
env_file = tmp.name
tmp_env_file = tmp.name
if (
Path(self.file.get_path_or_uri())
.with_suffix(".post-deploy.sh")
.exists()
):
if self.post_deploy_file:
with tempfile.NamedTemporaryFile(
delete=False, suffix=".post-deploy.sh"
) as tmp:
@@ -331,8 +340,7 @@ def create(self, dryrun=False):
tmp_deploy_file = tmp.name
else:
env_file = env_file.get_path_or_uri()
if Path(env_file).with_suffix(".post-deploy.sh").exists():
deploy_file = Path(env_file).with_suffix(".post-deploy.sh")
deploy_file = self.post_deploy_file

env_path = self.address

@@ -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}"
@@ -0,0 +1,3 @@
#!/bin/bash

echo "test" > $CONDA_PREFIX/a.txt
@@ -0,0 +1,5 @@
channels:
- bioconda
- conda-forge
dependencies:
- python =3.10
@@ -0,0 +1,5 @@
channels:
- bioconda
- conda-forge
dependencies:
- python =3.10
Empty file.
Empty file.
@@ -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"),

0 comments on commit d50efd9

Please sign in to comment.