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

Add support for snakemake > 8.0 #406

Merged
merged 3 commits into from
Apr 18, 2024
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
2 changes: 1 addition & 1 deletion docs/bids_app/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The value of `filters` should be a dictionary where each key corresponds to a BI
```
The above example selects all paths in the `func/` datatype folder that have a `_desc-` entity but do not have the `_acq-` entity.

* [`list`](#list): Specify multiple string or boolean filters. Any path matching any one of the filters will be selected. Using `False` as one of the filters allows the entity to optionally be absent in addition to matching one of the string filters. Using `True` along with text is redundant, as `True` will cause any value to be selected. Using `True` with `False` is equivalent to not providing the filter at all.
* [`list`](inv:*:py#list): Specify multiple string or boolean filters. Any path matching any one of the filters will be selected. Using `False` as one of the filters allows the entity to optionally be absent in addition to matching one of the string filters. Using `True` along with text is redundant, as `True` will cause any value to be selected. Using `True` with `False` is equivalent to not providing the filter at all.

These filters:

Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Snakemake Command line interface

```{argparse}
:module: snakemake
:module: snakebids.snakemake_compat
:func: get_argument_parser
:prog: snakemake
```
24 changes: 24 additions & 0 deletions snakebids/snakemake_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# type: ignore

try:
from snakemake.cli import get_argument_parser, main
from snakemake.common import configfile
from snakemake.common.configfile import load_configfile
except ImportError:
import snakemake.io as configfile
from snakemake import get_argument_parser, 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",
"get_argument_parser",
]
Loading