Add additional environment variables to processes
This commit is contained in:
parent
76b02ed5f9
commit
9870342567
3 changed files with 39 additions and 10 deletions
|
@ -53,6 +53,9 @@ class Project:
|
|||
except StopIteration:
|
||||
return None
|
||||
|
||||
def get_extra_path(self):
|
||||
return [self.root.joinpath("node_modules/.bin"), self.root.joinpath("env/bin")]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Process:
|
||||
|
|
|
@ -68,7 +68,14 @@ async def run_process_command(project: Project, process: Process):
|
|||
*command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
env={**os.environ, "PYTHONUNBUFFERED": "1"},
|
||||
env={
|
||||
**os.environ,
|
||||
"PYTHONUNBUFFERED": "1",
|
||||
"CATFISH_IDENT": process.ident,
|
||||
"PATH": "{}:{}".format(
|
||||
":".join(map(str, project.get_extra_path())), os.environ["PATH"]
|
||||
),
|
||||
},
|
||||
cwd=project.root
|
||||
)
|
||||
asyncio.ensure_future(publish_stdout_for(proc, process))
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import psutil
|
||||
|
||||
from catfish.project import Project
|
||||
from catfish.utils.processes import is_process_running
|
||||
from catfish.worker import BASE_SOCKET_DIR
|
||||
|
@ -6,20 +8,37 @@ from tests import BaseWorkerTestCase
|
|||
|
||||
|
||||
class WorkerServerTestCase(BaseWorkerTestCase):
|
||||
def test_server_creates_process(self):
|
||||
project = Project(self.EXAMPLE_DIR)
|
||||
process = project.get_process("bg")
|
||||
response = send_to_server(
|
||||
PayloadType.PROCESS,
|
||||
{"path": str(project.root), "process": str(process.name)},
|
||||
)
|
||||
self.assertTrue(is_process_running(response["pid"]))
|
||||
|
||||
def test_ping(self):
|
||||
response = send_to_server(PayloadType.PING, {})
|
||||
self.assertEqual(response, {"ping": "pong"})
|
||||
|
||||
|
||||
class ProcessWorkerTestCase(BaseWorkerTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.project = Project(self.EXAMPLE_DIR)
|
||||
self.process = self.project.get_process("bg")
|
||||
|
||||
def test_server_creates_process(self):
|
||||
response = send_to_server(
|
||||
PayloadType.PROCESS,
|
||||
{"path": str(self.project.root), "process": str(self.process.name)},
|
||||
)
|
||||
self.assertTrue(is_process_running(response["pid"]))
|
||||
|
||||
def test_additional_environment(self):
|
||||
response = send_to_server(
|
||||
PayloadType.PROCESS,
|
||||
{"path": str(self.project.root), "process": str(self.process.name)},
|
||||
)
|
||||
env = psutil.Process(response["pid"]).environ()
|
||||
self.assertEqual(env["PYTHONUNBUFFERED"], "1")
|
||||
self.assertEqual(env["CATFISH_IDENT"], self.process.ident)
|
||||
path_dirs = env["PATH"].split(":")
|
||||
for path in self.project.get_extra_path():
|
||||
self.assertIn(str(path), path_dirs)
|
||||
|
||||
|
||||
class ProcessLogsTestCase(BaseWorkerTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
|
Reference in a new issue