Skip to content

Commit

Permalink
Add support for snakemake > 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pvandyken committed Apr 18, 2024
1 parent d79a2a1 commit b4b23f0
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 830 deletions.
192 changes: 190 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ python = ">=3.8,<4.0"
# keep upper limit
pybids = ">=0.16.0,<0.17"
snakemake = [
{ version = ">=5.28.0,<8", python = ">=3.8" },
{ version = ">=7.18.2,<8", python = ">=3.11" },
{ version = ">=5.28.0,<8", python = "<3.11" },
{ version = ">=7.18.2", python = ">=3.11" },
]
typing-extensions = ">=3.10.0"
# minimum 22.2 to get "alias" parameter on attrs.field
Expand Down
2 changes: 1 addition & 1 deletion snakebids/core/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import more_itertools as itx
from bids import BIDSLayout
from pvandyken.deprecated import deprecated
from snakemake.io import expand as sn_expand
from typing_extensions import Self, TypedDict

import snakebids.utils.sb_itertools as sb_it
from snakebids.core.filtering import filter_list
from snakebids.exceptions import DuplicateComponentError
from snakebids.io.console import get_console_size
from snakebids.io.printing import format_zip_lists, quote_wrap
from snakebids.snakemake_compat import expand as sn_expand
from snakebids.types import ZipList
from snakebids.utils.containers import ImmutableList, MultiSelectDict, UserDictPy38
from snakebids.utils.utils import get_wildcard_dict, property_alias, zip_list_eq
Expand Down
2 changes: 1 addition & 1 deletion snakebids/core/input_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import more_itertools as itx
from bids import BIDSLayout, BIDSLayoutIndexer
from snakemake.script import Snakemake

from snakebids.core._querying import (
FilterSpecError,
Expand All @@ -32,6 +31,7 @@
DuplicateComponentError,
RunError,
)
from snakebids.snakemake_compat import Snakemake
from snakebids.types import InputConfig, InputsConfig, ZipList
from snakebids.utils.snakemake_io import glob_wildcards
from snakebids.utils.utils import (
Expand Down
8 changes: 4 additions & 4 deletions snakebids/plugins/snakemake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import attrs
import more_itertools as itx
import snakemake
from snakemake.io import load_configfile
from typing_extensions import overload, override

from snakebids import bidsapp
Expand All @@ -20,6 +18,8 @@
from snakebids.plugins.cli_config import CliConfig
from snakebids.plugins.component_edit import ComponentEdit
from snakebids.plugins.pybidsdb import Pybidsdb
from snakebids.snakemake_compat import load_configfile
from snakebids.snakemake_compat import main as snakemake_main
from snakebids.utils.output import (
prepare_bidsapp_output,
write_output_mode,
Expand Down Expand Up @@ -66,7 +66,7 @@ def __call__(
values: str | Sequence[Any] | None,
option_string: str | None = None,
):
snakemake.main(["-h"]) # type: ignore
snakemake_main(["-h"]) # type: ignore


def _get_file_paths(
Expand Down Expand Up @@ -330,7 +330,7 @@ def finalize_config(self, config: dict[str, Any]):
@bidsapp.hookimpl
def run(self, config: dict[str, Any]):
"""Run snakemake with the given config, after applying plugins."""
snakemake.main( # type: ignore
snakemake_main( # type: ignore
[
*filter(
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ classifiers = [

requires-python = "{{ python_version }}"
dependencies = [
"snakemake >= {{ snakemake_version }},<8",
"snakebids {{ snakebids_version | toml_encode }}",
"snakemake>={{ snakemake_version }},<8; python_version < \"3.11\"",
"snakemake>=8.1.2; python_version >= \"3.11\"",
{#- newer pulps are incompatible with old snakemakes, and we need to support
old snakemakes for python versions <3.11. So cap pulp to the last working
version
#}
"pulp < 2.8.0",
"pulp < 2.8.0; python_version < \"3.11\"",
]

[project.scripts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ classifiers = [

[tool.poetry.dependencies]
python = "{{ python_version }}"
snakemake = ">={{ snakemake_version }},<8"
snakemake = [
{ version=">={{ snakemake_version }},<8", python = "<3.11" },
{ version=">=8.1.2", python = ">=3.11" },
]
snakebids = {{ snakebids_version | format_poetry }}
{#- newer pulps are incompatible with old snakemakes, and we need to support
old snakemakes for python versions <3.11. So cap pulp to the last working
version
#}
pulp = "<2.8.0"
pulp = { version="<2.8.0", python = "<3.11" }
pandas = [
{ version = "<=2.0.3", python = "<3.9" },
{ version = ">=2.1.1", python = ">=3.12" },
Expand Down
23 changes: 23 additions & 0 deletions snakebids/snakemake_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# type: ignore

try:
from snakemake.cli import main
from snakemake.common import configfile
from snakemake.common.configfile import load_configfile
except ImportError:
import snakemake.io as configfile
from snakemake import main
from snakemake.io import load_configfile

from snakemake.exceptions import WildcardError
from snakemake.io import expand
from snakemake.script import Snakemake

__all__ = [
"load_configfile",
"main",
"expand",
"Snakemake",
"WildcardError",
"configfile",
]
Loading

0 comments on commit b4b23f0

Please sign in to comment.