diff --git a/catfish/project/cli.py b/catfish/project/cli.py index 6ee46dc..f065268 100644 --- a/catfish/project/cli.py +++ b/catfish/project/cli.py @@ -4,6 +4,8 @@ import subprocess import click +from catfish.utils.sockets import socket_has_data + from . import Project @@ -18,9 +20,15 @@ def project(): def run(ctx, command): command = " ".join(command) project = Project(os.getcwd()) - proc = subprocess.run( + proc = subprocess.Popen( shlex.split(command), env={**os.environ, **project.get_environment()}, - shell=True + stdout=subprocess.PIPE, ) + while proc.poll() is None: + while socket_has_data(proc.stdout): + line = proc.stdout.readline() + if not line: + break + click.echo(line, nl=False) return ctx.exit(proc.returncode) diff --git a/tests/__init__.py b/tests/__init__.py index bfbe8df..20d37cc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,8 +2,8 @@ import functools import os import subprocess import time -from pathlib import Path from contextlib import contextmanager +from pathlib import Path from unittest import TestCase import psutil diff --git a/tests/test_project/test_cli.py b/tests/test_project/test_cli.py index 874e729..ae66f98 100644 --- a/tests/test_project/test_cli.py +++ b/tests/test_project/test_cli.py @@ -1,7 +1,10 @@ -from tests import BaseTestCase -from catfish.project import Project +from io import StringIO + from dotenv import dotenv_values +from catfish.project import Project +from tests import BaseTestCase + class ProjectRunCLITestCase(BaseTestCase): def setUp(self): @@ -10,7 +13,12 @@ class ProjectRunCLITestCase(BaseTestCase): def test_sets_environment(self): with self.in_example_dir(): - result = self.run_cli(["project", "run", "env"]) - print(result) - self.assertEqual(result.exit_code, 0) - environment = dotenv_values(result.stdout) + result = self.run_cli(["project", "run", "env"], catch_exceptions=False) + self.assertEqual(result.exit_code, 0) + env = dotenv_values(stream=StringIO(result.stdout)) + self.assertEqual(env["FOO"], "bar") + self.assertEqual(env["PYTHONUNBUFFERED"], "1") + self.assertIsNone(env.get("CATFISH_IDENT")) + self.assertIn(str(self.project.root), env["PATH"]) + for path in self.project.get_extra_path(): + self.assertIn(str(path), env["PATH"])