commit cdb24125a2529d7698fe063ef5d90d69c125d7fa Author: Charles Gray Date: Tue Aug 30 18:16:33 2022 -0700 Add comby timeouts diff --git a/src/comby/binary.py b/src/comby/binary.py index 6147058..69544fc 100644 --- a/src/comby/binary.py +++ b/src/comby/binary.py @@ -37,6 +37,7 @@ class CombyBinary(CombyInterface): """ location = attr.ib(type=str, default='comby') language = attr.ib(type=str, default='.c') + timeout = attr.ib(default=None) @property def version(self) -> str: @@ -101,6 +102,8 @@ class CombyBinary(CombyInterface): cmd = ('-stdin', '-json-lines', '-match-only', '-matcher', shlex.quote(language), shlex.quote(template), 'foo') + if (self.timeout is not None): + cmd = ('-timeout', str(self.timeout)) + cmd cmd_s = ' '.join(cmd) jsn = json.loads(self.call(cmd_s, text=source) or 'null') @@ -135,6 +138,8 @@ class CombyBinary(CombyInterface): cmd = ['-stdin', shlex.quote(match), shlex.quote(rewrite)] cmd += ['-matcher', shlex.quote(language)] cmd += ['-diff' if diff else '-stdout'] + if (self.timeout is not None): + cmd += ['-timeout', str(self.timeout)] cmd_s = ' '.join(cmd) return self.call(cmd_s, text=source) @@ -161,6 +166,8 @@ class CombyBinary(CombyInterface): cmd = ('IGNORE_MATCHED_TEMPLATE', shlex.quote(template), '-matcher', shlex.quote(language), '-substitute-only', encoded_substitutions) + if (self.timeout is not None): + cmd = ('-timeout', str(self.timeout)) + cmd cmd_string = ' '.join(cmd) result = self.call(cmd_string)