diff --git a/synthesize/config.py b/synthesize/config.py index f30354a..04b36b4 100644 --- a/synthesize/config.py +++ b/synthesize/config.py @@ -55,7 +55,7 @@ class Target(Model): args: Args = {} envs: Envs = {} - executable: str = "sh -u" + executable: str = "sh -eu" @field_validator("commands") @classmethod diff --git a/synthesize/execution.py b/synthesize/execution.py index 6e6373f..bc21fd3 100644 --- a/synthesize/execution.py +++ b/synthesize/execution.py @@ -102,18 +102,15 @@ def has_exited(self) -> bool: return self.exit_code is not None def _send_signal(self, signal: int) -> None: - os.killpg(os.getpgid(self.process.pid), signal) - - def terminate(self) -> None: if self.has_exited: return None + os.killpg(os.getpgid(self.process.pid), signal) + + def terminate(self) -> None: self._send_signal(SIGTERM) def kill(self) -> None: - if self.has_exited: - return None - self._send_signal(SIGKILL) async def wait(self) -> Execution: diff --git a/tests/test_config.py b/tests/test_config.py index b294923..7fc1bf1 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -57,29 +57,29 @@ def test_target_commands_dedenting(raw: str, expected: str) -> None: ("target", "args", "expected"), ( ( - Target(commands=""), + Target(commands="", executable="sh"), Args(), - f"#!{shutil.which('sh')} -u\n", + f"#!{shutil.which('sh')}\n", ), ( - Target(commands="echo 'hello'"), + Target(commands="echo 'hello'", executable="sh"), Args(), - f"#!{shutil.which('sh')} -u\n\necho 'hello'", + f"#!{shutil.which('sh')}\n\necho 'hello'", ), ( - Target(commands="echo '{{foo}}'"), + Target(commands="echo '{{foo}}'", executable="sh"), Args({"foo": "bar"}), - f"#!{shutil.which('sh')} -u\n\necho 'bar'", + f"#!{shutil.which('sh')}\n\necho 'bar'", ), ( # unused values are ok - Target(commands="echo '{{foo}}'"), + Target(commands="echo '{{foo}}'", executable="sh"), Args({"foo": "bar", "baz": "qux"}), - f"#!{shutil.which('sh')} -u\n\necho 'bar'", + f"#!{shutil.which('sh')}\n\necho 'bar'", ), ( - Target(commands="echo {{foo}} {{baz}}"), + Target(commands="echo {{foo}} {{baz}}", executable="sh"), Args({"foo": "bar", "baz": "qux"}), - f"#!{shutil.which('sh')} -u\n\necho bar qux", + f"#!{shutil.which('sh')}\n\necho bar qux", ), ( Target(commands="echo", executable="bash"), @@ -87,14 +87,14 @@ def test_target_commands_dedenting(raw: str, expected: str) -> None: f"#!{shutil.which('bash')}\n\necho", ), ( - Target(commands="{{ 'yes' if choice else 'no' }}"), + Target(commands="{{ 'yes' if choice else 'no' }}", executable="sh"), Args({"choice": True}), - f"#!{shutil.which('sh')} -u\n\nyes", + f"#!{shutil.which('sh')}\n\nyes", ), ( - Target(commands="{{ 'yes' if choice else 'no' }}"), + Target(commands="{{ 'yes' if choice else 'no' }}", executable="sh"), Args({"choice": False}), - f"#!{shutil.which('sh')} -u\n\nno", + f"#!{shutil.which('sh')}\n\nno", ), ), )