diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..cdb5941 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,6 @@ +Controller (master) + +Worker (minion) + +API + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..98abdb7 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +run-controller: + venv/bin/mypy --strict phasmplatform + venv/bin/pyflakes phasmplatform + venv/bin/pycodestyle phasmplatform +# venv/bin/python + +init: + docker compose up -d + +redis-sh: + docker compose exec -it redis redis-cli + +setup: + python3.10 -m venv venv + venv/bin/pip install --upgrade pip wheel setuptools + venv/bin/pip install -r requirements.txt -r requirements-dev.txt + +update: + venv/bin/pip install -r requirements.txt -r requirements-dev.txt diff --git a/README.md b/README.md index 7235d9f..c046fbd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # phasm-platform +## Steps +```sh +make setup +make init +make run-controller +``` \ No newline at end of file diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..9b4bded --- /dev/null +++ b/config.toml @@ -0,0 +1,7 @@ +[controller.redis.write] +host = 'localhost' +port = 17859 + +[controller.redis.read] +host = 'localhost' +port = 17859 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..da2080a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,5 @@ +services: + redis: + image: 'redis:7.0-alpine' + ports: + - '17859:6379' diff --git a/phasmplatform/__init__.py b/phasmplatform/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/phasmplatform/common/__init__.py b/phasmplatform/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/phasmplatform/common/config.py b/phasmplatform/common/config.py new file mode 100644 index 0000000..e3eead9 --- /dev/null +++ b/phasmplatform/common/config.py @@ -0,0 +1,58 @@ +from typing import TYPE_CHECKING, BinaryIO + +import redis + +if TYPE_CHECKING: + import tomli as tomllib +else: + try: + import tomllib + except ImportError: + import tomli as tomllib + + +class ControllerConfig: + __slots__ = ('redis_read', 'redis_write', ) + + redis_read: 'redis.Redis[bytes]' # Set decode_responses to False + redis_write: 'redis.Redis[bytes]' # Set decode_responses to False + + def __init__( + self, + redis_read: 'redis.Redis[bytes]', + redis_write: 'redis.Redis[bytes]', + ) -> None: + self.redis_read = redis_read + self.redis_write = redis_write + + +class Config: + __slots__ = ('controller_config', ) + + controller_config: ControllerConfig + + def __init__(self, controller_config: ControllerConfig) -> None: + self.controller_config = controller_config + + +def from_toml(toml: BinaryIO) -> Config: + """ + Loads the given toml and builds a config instance out of it + """ + toml_dict = tomllib.load(toml) + + redis_read = redis.Redis( + host=toml_dict['redis_read_host'], + port=toml_dict['redis_read_port'], + decode_responses=False, + ) + + redis_write = redis.Redis( + host=toml_dict['redis_write_host'], + port=toml_dict['redis_write_port'], + decode_responses=False, + ) + + controller_config = ControllerConfig(redis_read, redis_write) + + return Config(controller_config) diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..8cc549a --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,4 @@ +mypy==1.2.0 +pycodestyle==2.10.0 +pyflakes==3.0.1 +types-redis==4.5.4.1 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7f60c54 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +redis==4.5.4 +tomli==2.0.1 ; python_version < '3.11'