Skip to content

Commit

Permalink
Merge pull request #8410 from khoaguin/optional-description-DockerWor…
Browse files Browse the repository at this point in the history
…kerConfig

Allow optional description for DockerWorkerConfig
  • Loading branch information
shubham3121 authored Jan 22, 2024
2 parents ef696c8 + 5aa9ca3 commit df8dbd3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/syft/src/syft/custom_worker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ def get_signature(self) -> str:
class DockerWorkerConfig(WorkerConfig):
dockerfile: str
file_name: Optional[str]
description: Optional[str]

@classmethod
def from_path(cls, path: Union[Path, str]) -> Self:
def from_path(cls, path: Union[Path, str], description: Optional[str] = "") -> Self:
with open(path) as f:
return cls(dockerfile=f.read(), file_name=Path(path).name)
return cls(
dockerfile=f.read(), file_name=Path(path).name, description=description
)

def __eq__(self, __value: object) -> bool:
if not isinstance(__value, DockerWorkerConfig):
Expand All @@ -140,3 +143,6 @@ def test_image_build(self, tag: str, **kwargs) -> Tuple[Image, SyftSuccess]:
return SyftSuccess(message=parse_output(logs))
except Exception as e:
return SyftError(message=f"Failed to build image !! Error: {str(e)}.")

def set_description(self, description_text: str) -> None:
self.description = description_text
41 changes: 41 additions & 0 deletions packages/syft/tests/syft/custom_worker/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# syft absolute
from syft.custom_worker.config import CustomBuildConfig
from syft.custom_worker.config import CustomWorkerConfig
from syft.custom_worker.config import DockerWorkerConfig


# in Pydantic v2 this would just be model.model_dump(mode='json')
Expand Down Expand Up @@ -163,3 +164,43 @@ def test_load_custom_worker_config(
)

assert to_json_like_dict(parsed_worker_config_obj) == expected


DOCKER_METHODS = ["from_str", "from_path"]
DOCKER_CONFIG = """
FROM openmined/grid-backend:0.8.4-beta.12
RUN pip install opendp
"""


@pytest.fixture
def dockerfile_path(tmp_path: Path) -> Path:
file_name = f"{uuid4().hex}.Dockerfile"
file_path = tmp_path / file_name

with open(file_path, "w") as f:
f.write(DOCKER_CONFIG)

yield file_path
file_path.unlink()


@pytest.mark.parametrize("method", DOCKER_METHODS)
def test_docker_worker_config(dockerfile_path: Path, method: str) -> None:
description = "I want to do some cool DS stuff with Syft and OpenDP"
if method == "from_str":
docker_config = DockerWorkerConfig(
dockerfile=dockerfile_path.read_text(), description=description
)
elif method == "from_path":
docker_config = DockerWorkerConfig.from_path(
path=dockerfile_path, description=description
)
else:
raise ValueError(f"method must be one of {METHODS}")

assert docker_config.dockerfile == dockerfile_path.read_text()
assert docker_config.description == description
new_description = description + " (syft version is 0.8.4-beta.12)"
docker_config.set_description(description_text=new_description)
assert docker_config.description == new_description

0 comments on commit df8dbd3

Please sign in to comment.