Skip to content

Commit

Permalink
Clean up unused deploy name from handler, cli messages
Browse files Browse the repository at this point in the history
  • Loading branch information
emdoyle committed Jul 23, 2024
1 parent 8b389b0 commit 640d33b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
13 changes: 4 additions & 9 deletions gauge/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import sys
import tempfile
import uuid
import zipfile
from pathlib import Path
from typing import Dict, TypedDict
Expand All @@ -31,11 +30,8 @@ class DeployType(TypedDict):


class DeployHandler:
def __init__(self, file_paths: list[str], deploy_name: str = "") -> None:
def __init__(self, file_paths: list[str]) -> None:
self.file_paths = {Path(file_path) for file_path in file_paths}
if not deploy_name:
deploy_name = str(uuid.uuid4())
self.deploy_name = deploy_name

def validate_file_paths(self) -> None:
errored = False
Expand All @@ -54,7 +50,7 @@ def validate_file_paths(self) -> None:

def bundle(self, temp_dir: str) -> Path:
with log_task(start_message="Bundling...", end_message="Project bundled"):
zip_filename = f"{self.deploy_name}.zip"
zip_filename = "gauge_project_bundle.zip"
zip_path = Path(temp_dir) / zip_filename

with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
Expand Down Expand Up @@ -111,12 +107,11 @@ def register_deployments(self) -> DeployConfigType:
def deploy(self):
console = Console()
console.print(
f"Deploying [bold white]"
f"[bold green] as [bold white]{self.deploy_name}[bold green]...",
f"[bold white]Deploying...[/bold white]",
)
self.validate_file_paths()
deployments = self.register_deployments()
with tempfile.TemporaryDirectory() as temp_dir:
zip_path = self.bundle(temp_dir)
self.upload(zip_path, deployments)
console.print(f"[bold white]{self.deploy_name[:8]} [bold green]deployed!")
console.print("[bold green]Deployed![/bold green]")
2 changes: 1 addition & 1 deletion gauge/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def deploy(file_path_str: str) -> None:
file_paths = [path.strip() for path in file_path_str.split(",")]
DeployHandler(file_paths=file_paths, deploy_name="test").deploy()
DeployHandler(file_paths=file_paths).deploy()


def status() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gauge/cli/tests/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def hello_world():
print("Hello World!")


@endpoint(name="name2", python_version="3.11", dependencies=["pandas"])
@endpoint(name="name2", python_version="3.11", dependencies=["fastapi", "gunicorn"])
def test(echo: str):
return echo
12 changes: 5 additions & 7 deletions gauge/cli/tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@

@pytest.fixture
def deploy_handler() -> DeployHandler:
return DeployHandler(["test_file.py"], "test_deploy")
return DeployHandler(["test_file.py"])


def test_init() -> None:
handler = DeployHandler(["file1.py", "file2.py"], "test_deploy")
handler = DeployHandler(["file1.py", "file2.py"])
assert len(handler.file_paths) == 2
assert handler.deploy_name == "test_deploy"

handler_no_name = DeployHandler(["file1.py"])
assert len(handler_no_name.file_paths) == 1
assert len(handler_no_name.deploy_name) == 36 # UUID4 length
other_handler = DeployHandler(["file1.py"])
assert len(other_handler.file_paths) == 1


def test_validate_file_paths(deploy_handler: DeployHandler) -> None:
Expand Down Expand Up @@ -48,7 +46,7 @@ def test_bundle(deploy_handler: DeployHandler) -> None:
with patch("zipfile.ZipFile") as mock_zipfile:
result = deploy_handler.bundle("/tmp")
assert isinstance(result, Path)
assert result.name == f"{deploy_handler.deploy_name}.zip"
assert result.name.endswith(".zip")
mock_zipfile.assert_called_once()


Expand Down

0 comments on commit 640d33b

Please sign in to comment.