Skip to content

Commit

Permalink
tweak exe
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshKarpel committed Jun 29, 2024
1 parent 69c075b commit e18d3ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion synthesize/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Target(Model):
args: Args = {}
envs: Envs = {}

executable: str = "sh -u"
executable: str = "sh -eu"

@field_validator("commands")
@classmethod
Expand Down
9 changes: 3 additions & 6 deletions synthesize/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,44 @@ 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"),
Args(),
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",
),
),
)
Expand Down

0 comments on commit e18d3ce

Please sign in to comment.