From 6f81a7ab01b8426b21f38f876da2a5665cdd236d Mon Sep 17 00:00:00 2001 From: Umesh Timalsina Date: Sat, 14 Oct 2023 18:58:28 -0500 Subject: [PATCH] Remove entrypoint cp-worker. Closes #281 (#282) --- chimerapy/engine/entry/__init__.py | 0 chimerapy/engine/entry/worker.py | 67 ------------------------- pyproject.toml | 4 -- test/test_entrypoint.py | 78 ------------------------------ 4 files changed, 149 deletions(-) delete mode 100644 chimerapy/engine/entry/__init__.py delete mode 100644 chimerapy/engine/entry/worker.py delete mode 100644 test/test_entrypoint.py diff --git a/chimerapy/engine/entry/__init__.py b/chimerapy/engine/entry/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/chimerapy/engine/entry/worker.py b/chimerapy/engine/entry/worker.py deleted file mode 100644 index df007040..00000000 --- a/chimerapy/engine/entry/worker.py +++ /dev/null @@ -1,67 +0,0 @@ -# Built-in Imports -import argparse - -from chimerapy.engine import _logger - -logger = _logger.getLogger("chimerapy-engine") - - -def routine(worker, d_args): - if d_args["zeroconf"]: - worker.connect(method="zeroconf") - else: - if d_args["ip"] == "" or d_args["port"] == -1: - logger.info("IP or Port not provided. Worker not connected") - else: - worker.connect(method="ip", host=d_args["ip"], port=d_args["port"]) - worker.idle() - - -def main(): - - # Internal Imports - from chimerapy.engine.worker import Worker - - # Create the arguments for Worker CI - parser = argparse.ArgumentParser(description="ChimeraPy-Engine Worker CI") - - # Adding the arguments - parser.add_argument("--name", type=str, help="Name of the Worker", required=True) - parser.add_argument( - "--zeroconf", type=bool, help="Use Zeroconf to find Manager", default=False - ) - parser.add_argument("--ip", type=str, help="Manager's IP Address", default="") - parser.add_argument("--port", type=int, help="Manager's Port", default=-1) - parser.add_argument("--id", type=str, help="ID of the Worker", default=None) - parser.add_argument("--wport", type=int, help="Worker's Port", default=0) - parser.add_argument( - "--delete", - type=bool, - help="Delete Worker's data after transfer to Manager's computer", - default=True, - ) - - args = parser.parse_args() - - # Convert the Namespace to a dictionary - d_args = vars(args) - - # Create Worker and execute connect - worker = Worker( - name=d_args["name"], - delete_temp=d_args["delete"], - id=d_args["id"], - port=d_args["wport"], - ) - worker.serve() - - try: - routine(worker, d_args) - except KeyboardInterrupt: - ... - finally: - worker.shutdown() - - -if __name__ == "__main__": - main() diff --git a/pyproject.toml b/pyproject.toml index 1d3716d1..710f9174 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,10 +87,6 @@ homepath = "https://github.com/ChimeraPy" documentation = "https://chimerapy-engine.readthedocs.io/en/latest/index.html" repository = "https://github.com/ChimeraPy/Engine" -# Entrypoint -[project.scripts] -cp-worker = "chimerapy.engine.entry.worker:main" - [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" diff --git a/test/test_entrypoint.py b/test/test_entrypoint.py deleted file mode 100644 index eb286ca6..00000000 --- a/test/test_entrypoint.py +++ /dev/null @@ -1,78 +0,0 @@ -# Test Import - -# Built-in Imports -import subprocess -import time - -# Third-party Imports -import chimerapy.engine as cpe - -from .conftest import TEST_DATA_DIR - -logger = cpe._logger.getLogger("chimerapy-engine") -cpe.debug() - - -def test_worker_entrypoint_connect_wport(): - - manager = cpe.Manager(name="test", port=0, logdir=TEST_DATA_DIR) - manager.serve() - - # Connect to manager from subprocess - worker_process = subprocess.Popen( - [ - "cp-worker", - "--name", - "test", - "--id", - "test", - "--ip", - manager.host, - "--port", - str(manager.port), - "--wport", - str(9980), - ] - ) - logger.info("Executed cmd to connect Worker to Manager.") - - time.sleep(2) - assert "test" in manager.workers - assert manager.workers["test"].port == 9980 - - logger.info("Killing worker subprocess") - worker_process.kill() - - logger.info("Manager shutting down") - manager.shutdown() - - -def test_worker_entrypoint_zeroconf_connect(): - - manager = cpe.Manager(name="test", port=0, logdir=TEST_DATA_DIR) - manager.serve() - - manager.zeroconf(enable=True) - - # Connect to manager from subprocess - worker_process = subprocess.Popen( - [ - "cp-worker", - "--name", - "test", - "--id", - "test", - "--zeroconf", - "true", - ] - ) - logger.info("Executed cmd to connect Worker to Manager.") - - time.sleep(5) - assert "test" in manager.workers - - logger.info("Killing worker subprocess") - worker_process.kill() - - logger.info("Disable Zeroconf") - manager.zeroconf(enable=False)