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

feat: add function to get unnamed arguments from input output files #2509

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
17 changes: 16 additions & 1 deletion snakemake/io.py
Expand Up @@ -28,7 +28,7 @@
from inspect import isfunction, ismethod
from itertools import chain, product
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Set, Union
from typing import Any, Callable, Dict, List, Optional, Set, Union, Sequence

from snakemake_interface_common.utils import not_iterable, lchmod
from snakemake_interface_common.utils import lutime as lutime_raw
Expand Down Expand Up @@ -1656,6 +1656,21 @@ def _insert_items(self, index, items):
elif i == index:
self._set_name(name, i, end=i + len(items))

def get_positional_items(self) -> Sequence[str]:
"""
Get arguments without name and return them as a list.
"""

keys_with_positions = self._names
if len(keys_with_positions) == 0:
# all arguments are unnamed
return list(self)

first_key = next(iter(keys_with_positions.items()))
n_unnamed_arguments = first_key[1][0]

return [self[i] for i in range(n_unnamed_arguments)]

def keys(self):
return self._names.keys()

Expand Down