Skip to content
Open
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
44 changes: 41 additions & 3 deletions pyflow/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,25 +939,63 @@ class InLimit(Attribute):

Parameters:
value(str,Limit_): The name of the limit or a limit object.
path(str): The optional path to the limit if the limit is not in the same node as the InLimit attribute.
tokens(int): The number of tokens to consume from the limit when a task is submitted.
limit_this_node_only(bool): Whether the limit should only apply to current node.
limit_submission(bool): Whether the limit should only apply to submissions

Example::

l = pyflow.Limit('l', 3)
pyflow.InLimit(l)
"""

def __init__(self, value):
def __init__(
self,
value: str | Limit,
path: str = "",
tokens: int = 1,
limit_this_node_only: bool = False,
limit_submission: bool = False,
):
super().__init__("_" + str(value), value)
self.path = path
self.tokens = tokens
self.limit_this_node_only = limit_this_node_only
self.limit_submission = limit_submission

def _build(self, ecflow_parent):
value = self.value
if NO_INLIMIT:
return
if isinstance(value, Limit):
value = value.fullname.split(":")
ecflow_parent.add_inlimit(ecflow.InLimit(value[1], value[0]))
if self.path:
if self.path != value[0]:
raise ValueError(
"InLimit path {} does not match limit path {}".format(
self.path, value[0]
)
)
ecflow_parent.add_inlimit(
ecflow.InLimit(
value[1],
value[0],
self.tokens,
self.limit_this_node_only,
self.limit_submission,
)
)
else:
ecflow_parent.add_inlimit(ecflow.InLimit(str(value)))
ecflow_parent.add_inlimit(
ecflow.InLimit(
str(value),
self.path,
self.tokens,
self.limit_this_node_only,
self.limit_submission,
)
)


class Inlimit(InLimit):
Expand Down
27 changes: 26 additions & 1 deletion tests/test_inlimits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from pyflow import Limits, Suite, Tasks
import pytest

from pyflow import InLimit, Limit, Limits, Suite, Tasks


def test_inlimits():
Expand All @@ -14,6 +16,29 @@ def test_inlimits():
s.generate_node()


@pytest.mark.parametrize(
"options",
[
{},
{"path": "/s"},
{"value": "tlimit"},
{"value": "tlimit", "path": "/s"},
{"value": "tlimit", "tokens": 1},
{"value": "tlimit", "limit_this_node_only": True},
{"value": "tlimit", "limit_submission": True},
],
)
def test_options(options):
with Suite("s") as s:
limit = Limit("tlimit", value=3)
if "value" not in options:
options["value"] = limit
Tasks("t", "t2", inlimits=InLimit(**options))

s.check_definition()
s.generate_node()


if __name__ == "__main__":
from os import path

Expand Down
Loading