Skip to content

Commit 1619cb6

Browse files
committed
Let service pass env vars to worker processes
1 parent c65cc16 commit 1619cb6

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/appose/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,4 @@ def service(self, exes: list[str], *args) -> Service:
271271
all_args.append(exe_path)
272272
all_args.extend(args)
273273

274-
return Service(self.base(), all_args)
274+
return Service(self.base(), self.env_vars(), *all_args)

src/appose/service.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from uuid import uuid4
1818

1919
from .syntax import ScriptSyntax, get as syntax_from_name
20+
from .util import process
2021
from .util.message import Args, decode, encode
2122

2223

@@ -43,9 +44,12 @@ class Service:
4344

4445
_service_count: int = 0
4546

46-
def __init__(self, cwd: str | Path, args: list[str]) -> None:
47+
def __init__(
48+
self, cwd: str | Path, env_vars: dict[str, str] | None = None, *args: str
49+
) -> None:
4750
self._cwd: Path = Path(cwd)
48-
self._args: list[str] = args[:]
51+
self._env_vars: dict[str, str] = env_vars.copy() if env_vars is not None else {}
52+
self._args: list[str] = list(args)
4953
self._tasks: dict[str, "Task"] = {}
5054
self._service_id: int = Service._service_count
5155
Service._service_count += 1
@@ -54,6 +58,7 @@ def __init__(self, cwd: str | Path, args: list[str]) -> None:
5458
self._stderr_thread: threading.Thread | None = None
5559
self._monitor_thread: threading.Thread | None = None
5660
self._debug_callback: Callable[[Any], Any] | None = None
61+
self._syntax: ScriptSyntax | None = None
5762

5863
def debug(self, debug_callback: Callable[[Any], Any]) -> None:
5964
"""
@@ -80,13 +85,8 @@ def start(self) -> None:
8085
return
8186

8287
prefix = f"Appose-Service-{self._service_id}"
83-
self._process = subprocess.Popen(
84-
self._args,
85-
stdin=subprocess.PIPE,
86-
stdout=subprocess.PIPE,
87-
cwd=self._cwd,
88-
text=True,
89-
)
88+
89+
self._process = process.builder(self._cwd, self._env_vars, *self._args)
9090
self._stdout_thread = threading.Thread(
9191
target=self._stdout_loop, name=f"{prefix}-Stdout"
9292
)

src/appose/util/process.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def builder(
2929
command: Command and arguments to execute.
3030
3131
Returns:
32-
Configured Popen object ready to start.
32+
Configured Popen object with stdin, stdout, and stderr piped.
3333
"""
3434
env = os.environ.copy()
3535
if env_vars:
@@ -41,6 +41,7 @@ def builder(
4141
command,
4242
cwd=cwd,
4343
env=env,
44+
stdin=subprocess.PIPE,
4445
stdout=subprocess.PIPE,
4546
stderr=subprocess.PIPE,
4647
text=True,

0 commit comments

Comments
 (0)