Complete project run command
This commit is contained in:
parent
f7f457e6c2
commit
84bc0bbbd9
3 changed files with 25 additions and 9 deletions
|
@ -4,6 +4,8 @@ import subprocess
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
from catfish.utils.sockets import socket_has_data
|
||||||
|
|
||||||
from . import Project
|
from . import Project
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,9 +20,15 @@ def project():
|
||||||
def run(ctx, command):
|
def run(ctx, command):
|
||||||
command = " ".join(command)
|
command = " ".join(command)
|
||||||
project = Project(os.getcwd())
|
project = Project(os.getcwd())
|
||||||
proc = subprocess.run(
|
proc = subprocess.Popen(
|
||||||
shlex.split(command),
|
shlex.split(command),
|
||||||
env={**os.environ, **project.get_environment()},
|
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)
|
return ctx.exit(proc.returncode)
|
||||||
|
|
|
@ -2,8 +2,8 @@ import functools
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from tests import BaseTestCase
|
from io import StringIO
|
||||||
from catfish.project import Project
|
|
||||||
from dotenv import dotenv_values
|
from dotenv import dotenv_values
|
||||||
|
|
||||||
|
from catfish.project import Project
|
||||||
|
from tests import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
class ProjectRunCLITestCase(BaseTestCase):
|
class ProjectRunCLITestCase(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -10,7 +13,12 @@ class ProjectRunCLITestCase(BaseTestCase):
|
||||||
|
|
||||||
def test_sets_environment(self):
|
def test_sets_environment(self):
|
||||||
with self.in_example_dir():
|
with self.in_example_dir():
|
||||||
result = self.run_cli(["project", "run", "env"])
|
result = self.run_cli(["project", "run", "env"], catch_exceptions=False)
|
||||||
print(result)
|
self.assertEqual(result.exit_code, 0)
|
||||||
self.assertEqual(result.exit_code, 0)
|
env = dotenv_values(stream=StringIO(result.stdout))
|
||||||
environment = dotenv_values(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"])
|
||||||
|
|
Reference in a new issue