Complete project run command

This commit is contained in:
Jake Howard 2018-12-21 13:00:20 +00:00
parent f7f457e6c2
commit 84bc0bbbd9
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 25 additions and 9 deletions

View file

@ -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)

View file

@ -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

View file

@ -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"])