diff --git a/controller/Dockerfile b/controller/Dockerfile index e6a384a..da31dd7 100644 --- a/controller/Dockerfile +++ b/controller/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /app ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 -RUN pip install --no-cache-dir pdm==2.10.3 +RUN pip install --no-cache-dir pdm==2.10.4 ENV PYTHONPATH "${PYTHONPATH}:/app/src" diff --git a/controller/pyproject.toml b/controller/pyproject.toml index add956c..9b9540b 100644 --- a/controller/pyproject.toml +++ b/controller/pyproject.toml @@ -48,7 +48,9 @@ isort = "isort src" black = "black src" pure_lint = "flake8 src" type_check = "mypy src" -test = "python -m unittest discover -s src/ribot/tests -p 'test_*.py' -v" +test_no_sleep = "python -m unittest discover -s src/ribot/tests -p 'test_*.py' -v" +sleep = "sleep 3" +test = {composite = ["test_no_sleep", "sleep"]} format = {composite = ["isort", "black"]} lint = {composite = ["pure_lint", "type_check"]} main = "python src/ribot/sample_main.py" diff --git a/controller/src/ribot/tests/test_controller.py b/controller/src/ribot/tests/test_controller.py index 2fd3ff1..d1e4f16 100644 --- a/controller/src/ribot/tests/test_controller.py +++ b/controller/src/ribot/tests/test_controller.py @@ -53,6 +53,7 @@ def setUpClass(cls) -> None: @classmethod def tearDownClass(cls) -> None: cls.controller.stop() + time.sleep(3) def tearDown(self) -> None: self.controller.move_joints_to([0, 0, 0, 0, 0, 0]) @@ -271,3 +272,6 @@ def test_move_queue_size(self) -> None: self.controller.stop_movement() time.sleep(0.5) self.assertEqual(self.controller.move_queue_size, 0) + + if __name__ == "__main__": + unittest.main() diff --git a/manage.py b/manage.py index ec157ad..3bdf174 100755 --- a/manage.py +++ b/manage.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from logging import captureWarnings from sys import stdout import time import argparse @@ -73,7 +74,7 @@ def get_file_list(self, services: List[str]) -> List[str]: file_list.extend(['-f', self.get_service_from_name(service).full_path]) return file_list - def dc_run(self, service_name: str, command: str, env={}, service_ports_and_aliases=False, exec=False, mute=False): + def dc_run(self, service_name: str, command: str, env={}, service_ports_and_aliases=False, exec=False): command_list = command.split(' ') service = self.get_service_from_name(service_name) @@ -88,15 +89,11 @@ def dc_run(self, service_name: str, command: str, env={}, service_ports_and_alia new_command.extend(command_list) - try: - result = subprocess.run(new_command, env={**os.environ, **env}, check=True, - stderr=subprocess.PIPE) - print(result.stderr.decode('utf-8')) - return result.returncode - except subprocess.CalledProcessError as e: - print("Command failed with the following output:") - print(e.output.decode('utf-8')) # Output includes both stdout and stderr - return e.returncode + result = subprocess.run(new_command, env={**os.environ, **env}) + # repalce with os.system to get output + # result = os.system(' '.join(new_command)) + + return result.returncode def dc_up(self, files: List[str], env: dict = {}, detached=False): @@ -123,7 +120,13 @@ def dc_logs(self, files: List[str]): def dc_command(self, files: List[str], command: str): file_list = self.get_file_list(files) - command_list = command.split(' ') + command_list = [] + + if "run" in command: + command_list += ["run", "--service-ports", "--use-aliases"] + command_list += command.split(' ')[1:] + else: + command_list += command.split(' ') return subprocess.check_call(['docker', 'compose', *file_list] + command_list, env={**os.environ}) @@ -151,7 +154,10 @@ def source_settings(self, file_path): settings = toml.load(f) for field, value_dict in settings.items(): for sub_key, value in value_dict.items(): - os.environ[f"{field}_{sub_key}".upper()] = str(value) + if "no_pref" in field.lower(): + os.environ[sub_key.upper()] = str(value) + else: + os.environ[f"{field}_{sub_key}".upper()] = str(value) def source_env(self, file_path): pattern = re.compile(r'^(?:export\s+)?([\w\.]+)\s*=\s*(.*)$') @@ -339,7 +345,7 @@ def build_esp(self, **kwargs): def run_command(self, args): container, cmd = args try: - self.docker_manager.dc_run(container, cmd, mute=True) + self.docker_manager.dc_run(container, cmd, service_ports_and_aliases=True) except subprocess.CalledProcessError as e: print(f"Error running command: {e}")