Skip to content

Commit

Permalink
Remove docker and stringcase from core dependencies (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter authored Nov 11, 2024
1 parent d4a6e42 commit c720288
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **BREAKING**: Removed `stringcase` and `docker` from core dependencies. `ComputerTool` will now install these on the fly.
- **BREAKING**: Renamed `BaseTask.State.EXECUTING` to `BaseTask.State.RUNNING`.
- **BREAKING**: Renamed `BaseTask.is_executing()` to `BaseTask.is_running()`.
- **BREAKING**: Renamed `Structure.is_executing()` to `Structure.is_running()`.
Expand Down
2 changes: 2 additions & 0 deletions griptape/tools/computer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker
stringcase
12 changes: 9 additions & 3 deletions griptape/tools/computer/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
from typing import TYPE_CHECKING, Optional

import docker
import stringcase
from attrs import Attribute, Factory, define, field
from docker.errors import NotFound
from docker.models.containers import Container
from schema import Literal, Schema

from griptape.artifacts import BaseArtifact, ErrorArtifact, TextArtifact
Expand Down Expand Up @@ -97,6 +94,8 @@ def execute_command(self, params: dict) -> BaseArtifact:
return self.execute_command_in_container(command)

def execute_command_in_container(self, command: str) -> BaseArtifact:
from docker.models.containers import Container

try:
binds = {self.local_workdir: {"bind": self.container_workdir, "mode": "rw"}} if self.local_workdir else None

Expand Down Expand Up @@ -160,12 +159,19 @@ def default_docker_client(self) -> Optional[DockerClient]:
return None

def image_name(self, tool: BaseTool) -> str:
import stringcase # pyright: ignore[reportMissingImports]

return f"{stringcase.snakecase(tool.name)}_image"

def container_name(self, tool: BaseTool) -> str:
import stringcase # pyright: ignore[reportMissingImports]

return f"{stringcase.snakecase(tool.name)}_container"

def remove_existing_container(self, name: str) -> None:
from docker.errors import NotFound
from docker.models.containers import Container

try:
existing_container = self.docker_client.containers.get(name)
if isinstance(existing_container, Container):
Expand Down
12 changes: 1 addition & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ schema = "^0.7.7"
pyyaml = "^6.0.1"
tenacity = "^8.5.0"
numpy = "^1.26.4"
stringcase = "^1.2.0"
docker = "^7.1.0"
requests = "^2.32.0"
filetype = "^1.2"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tools/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class TestComputer:
@pytest.fixture()
def computer(self):
return ComputerTool(docker_client=make_fake_client(), install_dependencies_on_init=False)
return ComputerTool(docker_client=make_fake_client())

def test_execute_code(self, computer):
assert computer.execute_code({"values": {"code": "print(1)", "filename": "foo.py"}}).value == "hello world"
Expand Down

0 comments on commit c720288

Please sign in to comment.