WIP project run command
This commit is contained in:
parent
5869befecb
commit
f7f457e6c2
4 changed files with 57 additions and 0 deletions
|
@ -4,6 +4,7 @@ import click
|
|||
import daemonize
|
||||
|
||||
from catfish import __version__, worker
|
||||
from catfish.project.cli import project as project_cli
|
||||
from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir
|
||||
|
||||
|
||||
|
@ -48,5 +49,8 @@ def stop(ctx):
|
|||
delete_base_socket_dir()
|
||||
|
||||
|
||||
cli.add_command(project_cli)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
|
26
catfish/project/cli.py
Normal file
26
catfish/project/cli.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
import click
|
||||
|
||||
from . import Project
|
||||
|
||||
|
||||
@click.group()
|
||||
def project():
|
||||
pass
|
||||
|
||||
|
||||
@project.command()
|
||||
@click.argument("command", nargs=-1, type=str)
|
||||
@click.pass_context
|
||||
def run(ctx, command):
|
||||
command = " ".join(command)
|
||||
project = Project(os.getcwd())
|
||||
proc = subprocess.run(
|
||||
shlex.split(command),
|
||||
env={**os.environ, **project.get_environment()},
|
||||
shell=True
|
||||
)
|
||||
return ctx.exit(proc.returncode)
|
|
@ -3,6 +3,7 @@ import os
|
|||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
from contextlib import contextmanager
|
||||
from unittest import TestCase
|
||||
|
||||
import psutil
|
||||
|
@ -31,6 +32,7 @@ class BaseTestCase(TestCase):
|
|||
self.cli_runner = CliRunner()
|
||||
self.cli = cli
|
||||
self.run_cli = functools.partial(self.cli_runner.invoke, self.cli)
|
||||
self.in_example_dir = functools.partial(self.change_dir, self.EXAMPLE_DIR)
|
||||
|
||||
def terminate_dummy_processes(self):
|
||||
dummy_processes = []
|
||||
|
@ -47,6 +49,15 @@ class BaseTestCase(TestCase):
|
|||
self.terminate_dummy_processes()
|
||||
delete_base_socket_dir()
|
||||
|
||||
@contextmanager
|
||||
def change_dir(self, newdir):
|
||||
prevdir = os.getcwd()
|
||||
os.chdir(os.path.expanduser(newdir))
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(prevdir)
|
||||
|
||||
|
||||
class BaseWorkerTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
|
|
16
tests/test_project/test_cli.py
Normal file
16
tests/test_project/test_cli.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from tests import BaseTestCase
|
||||
from catfish.project import Project
|
||||
from dotenv import dotenv_values
|
||||
|
||||
|
||||
class ProjectRunCLITestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.project = Project(self.EXAMPLE_DIR)
|
||||
|
||||
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)
|
Reference in a new issue