From 99871eedf2e00b0bf24c354aad2a49e166c0cf12 Mon Sep 17 00:00:00 2001 From: Giuseppe Steduto Date: Mon, 18 Dec 2023 17:23:35 +0100 Subject: [PATCH] fix: bump Snakemake to v7.32.4 for compatibility with new clients (#435) Update Snakemake version to v7.32.4 (latest one before v8 refactoring), to support newer features and resolve problems for clients using Python 3.11. Other than updating the dependency and Snakemake base image, change `reana_commons/snakemake.py` to switch from the `first_rule` Snakemake workflow directive to the `default_target` one, to adhere to the changes made in snakemake/snakemake!638ec1a. Closes: reanahub/reana-client#655. Closes: reanahub/reana-workflow-engine-snakemake#31. --- reana_commons/config.py | 2 +- reana_commons/snakemake.py | 12 +++++++++--- setup.py | 8 ++++---- tests/conftest.py | 1 + tests/test_snakemake.py | 4 ---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/reana_commons/config.py b/reana_commons/config.py index 57f413c7..1a031f1f 100644 --- a/reana_commons/config.py +++ b/reana_commons/config.py @@ -440,7 +440,7 @@ def default_workspace(): REANA_WORKFLOW_ENGINES = ["yadage", "cwl", "serial", "snakemake"] """Available workflow engines.""" -REANA_DEFAULT_SNAKEMAKE_ENV_IMAGE = "docker.io/snakemake/snakemake:v6.8.0" +REANA_DEFAULT_SNAKEMAKE_ENV_IMAGE = "docker.io/snakemake/snakemake:v7.32.4" """Snakemake default job environment image.""" REANA_JOB_CONTROLLER_CONNECTION_CHECK_SLEEP = float( diff --git a/reana_commons/snakemake.py b/reana_commons/snakemake.py index f942853b..0fbe3dae 100644 --- a/reana_commons/snakemake.py +++ b/reana_commons/snakemake.py @@ -93,7 +93,7 @@ def _create_snakemake_dag( if workdir: workflow.workdir(workdir) - workflow.include(snakefile=snakefile, overwrite_first_rule=True) + workflow.include(snakefile=snakefile, overwrite_default_target=True) workflow.check() # code copied and adapted from `snakemake.workflow.Workflow.execute()` @@ -122,7 +122,9 @@ def files(items): if not kwargs.get("targets"): targets = ( - [workflow.first_rule] if workflow.first_rule is not None else list() + [workflow.default_target] + if workflow.default_target is not None + else list() ) prioritytargets = kwargs.get("prioritytargets", []) @@ -157,7 +159,11 @@ def files(items): omitrules=omitrules, ) - workflow.persistence = Persistence(dag=dag) + if hasattr(workflow, "_persistence"): + workflow._persistence = Persistence(dag=dag) + else: + # for backwards compatibility (Snakemake < 7 for Python 3.6) + workflow.persistence = Persistence(dag=dag) dag.init() dag.update_checkpoint_dependencies() dag.check_dynamic() diff --git a/setup.py b/setup.py index 935e575b..73b1cdd7 100755 --- a/setup.py +++ b/setup.py @@ -35,13 +35,13 @@ "yadage": ["adage~=0.10.1", "yadage~=0.20.1", "yadage-schemas~=0.10.6"], "cwl": ["cwltool==3.1.20210628163208"], "snakemake": [ - "snakemake==6.8.0 ; python_version<'3.12'", - "snakemake==7.9.0 ; python_version>='3.12'", + "snakemake==6.15.5 ; python_version<'3.7'", # Snakemake v7 requires Python 3.7+ + "snakemake==7.32.4 ; python_version>='3.7'", "tabulate<0.9", ], "snakemake_reports": [ - "snakemake[reports]==6.8.0 ; python_version<'3.12'", - "snakemake[reports]==7.9.0 ; python_version>='3.12'", + "snakemake==6.15.5 ; python_version<'3.7'", + "snakemake==7.32.4 ; python_version>='3.7'", "pygraphviz<1.8", "tabulate<0.9", # tabulate 0.9 crashes snakemake, more info: https://github.com/snakemake/snakemake/issues/1899 ], diff --git a/tests/conftest.py b/tests/conftest.py index 87454803..b14231b1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,6 +20,7 @@ def dummy_snakefile(): "results/foo.txt", "results/bar.txt", "results/baz.txt" + default_target: True rule foo: input: diff --git a/tests/test_snakemake.py b/tests/test_snakemake.py index 314b8a59..f7c48b7a 100644 --- a/tests/test_snakemake.py +++ b/tests/test_snakemake.py @@ -17,10 +17,6 @@ def test_snakemake_load(tmpdir, dummy_snakefile): """Test that Snakemake metadata is loaded properly.""" - if sys.version_info.major == 3 and sys.version_info.minor in (11, 12): - pytest.xfail( - "Snakemake features of reana-client are not supported on Python 3.11" - ) workdir = tmpdir.mkdir("sub") # write Snakefile p = workdir.join("Snakefile")