Skip to content

Commit 940dbc7

Browse files
chore: fix format (#37)
Signed-off-by: Ivan Pedrazas <ipedrazas@gmail.com> Co-authored-by: Sergey Ivanov <sergey@shuttle.dev>
1 parent 7795a67 commit 940dbc7

5 files changed

Lines changed: 38 additions & 15 deletions

File tree

src/neptune_cli/cli.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import os
2-
31
import click
4-
from loguru import logger as log
52

63
from neptune_cli.auth import serve_callback_handler
7-
from neptune_cli.client import Client
84
from neptune_cli.config import SETTINGS
95
from neptune_cli.mcp import mcp as mcp_server
106

src/neptune_cli/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,25 @@ def get_project(self, project_name: str) -> GetProjectResponse | None:
4949
response = requests.get(self._mk_url(f"/project/{project_name}"), headers=self._get_headers())
5050
if response.status_code == 404:
5151
return None
52+
response.raise_for_status()
5253
return GetProjectResponse.model_validate(response.json())
5354

5455
def create_deployment(self, project_name: str) -> PostDeploymentResponse:
5556
response = requests.post(self._mk_url(f"/project/{project_name}/deploy"), headers=self._get_headers())
57+
response.raise_for_status()
5658
return PostDeploymentResponse.model_validate(response.json())
5759

5860
def get_deployment(self, project_name: str, revision: str | int = "latest") -> PostDeploymentResponse:
5961
response = requests.get(
6062
self._mk_url(f"/project/{project_name}/deploy/{revision}"),
6163
headers=self._get_headers(),
6264
)
65+
response.raise_for_status()
6366
return PostDeploymentResponse.model_validate(response.json())
6467

6568
def get_logs(self, project_name: str) -> GetLogsResponse:
6669
response = requests.get(self._mk_url(f"/project/{project_name}/logs"), headers=self._get_headers())
70+
response.raise_for_status()
6771
return GetLogsResponse.model_validate(response.json())
6872

6973
def set_secret_value(self, project_name: str, key: str, value: str) -> None:
@@ -78,13 +82,15 @@ def list_bucket_keys(self, project_name: str, bucket_name: str) -> list[str]:
7882
self._mk_url(f"/project/{project_name}/bucket/{bucket_name}"),
7983
headers=self._get_headers(),
8084
)
85+
response.raise_for_status()
8186
return ListBucketKeysResponse.model_validate(response.json()).keys
8287

8388
def get_bucket_object(self, project_name: str, bucket_name: str, key: str) -> bytes:
8489
response = requests.get(
8590
self._mk_url(f"/project/{project_name}/bucket/{bucket_name}/object/{key}"),
8691
headers=self._get_headers(),
8792
)
93+
response.raise_for_status()
8894
return response.content
8995

9096
def get_project_schema(self) -> dict[str, Any]:
@@ -97,4 +103,5 @@ def get_project_schema(self) -> dict[str, Any]:
97103
self._mk_url("/schema/project"),
98104
headers=self._get_headers(),
99105
)
106+
response.raise_for_status()
100107
return response.json()

src/neptune_cli/mcp.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from neptune_common import PutProjectRequest
99

1010
from neptune_cli.client import Client
11+
from neptune_cli.config import SETTINGS
1112
from neptune_cli.utils import run_command
1213

1314

@@ -217,10 +218,12 @@ def provision_resources(neptune_json_path: str) -> dict[str, Any]:
217218

218219
# while loop to retrieve project status, wait until ready
219220
project = client.get_project(project_request.name)
220-
while project.provisioning_state != "Ready":
221-
log.info(
222-
f"Project '{project_request.name}' status: {project.provisioning_state}. Waiting for resources to be provisioned..."
223-
)
221+
222+
while project is None or project.provisioning_state != "Ready":
223+
if project is not None:
224+
log.info(
225+
f"Project '{project_request.name}' status: {project.provisioning_state}. Waiting for resources to be provisioned..."
226+
)
224227
time.sleep(2)
225228
project = client.get_project(project_request.name)
226229

@@ -303,7 +306,7 @@ def deploy_project(neptune_json_path: str) -> dict[str, Any]:
303306
304307
This only works after the project has been provisioned using 'provision_resources'.
305308
306-
UNDER THE HOOD: deployments are ECS tasks running on Fargate, with images stored in ECR. In particular, this tool builds an image using the Dockerfile in the current directory.
309+
UNDER THE HOOD: this tool builds an image using the Dockerfile in the current directory.
307310
308311
Note: running tasks are *not* persistent; if the task stops or is redeployed, all data stored in the container is lost. Use provisioned resources (storage buckets, etc.) for persistent data storage.
309312
"""
@@ -319,6 +322,13 @@ def deploy_project(neptune_json_path: str) -> dict[str, Any]:
319322

320323
project_request = PutProjectRequest.model_validate_json(project_data)
321324

325+
if client.get_project(project_request.name) is None:
326+
log.info(f"Creating project '{project_request.name}'...")
327+
client.create_project(project_request)
328+
else:
329+
log.info(f"Updating project '{project_request.name}'...")
330+
client.update_project(project_request)
331+
322332
log.info(f"Deploying project '{project_request.name}'...")
323333

324334
try:
@@ -426,6 +436,7 @@ def get_deployment_status(neptune_json_path: str) -> dict[str, Any]:
426436
427437
This will tell you about running resources the project is using, as well as the state of the service.
428438
"""
439+
log.info("Getting deployment status for project ")
429440
client = Client()
430441

431442
if validation_result := validate_neptune_json(neptune_json_path):
@@ -681,6 +692,7 @@ def get_logs(neptune_json_path: str) -> dict[str, Any]:
681692
"next_step": "use these logs to debug your application or monitor its behavior; fix any issues and redeploy as necessary",
682693
}
683694

695+
684696
@mcp.tool("info")
685697
async def info() -> dict[str, Any]:
686698
"""Get information about Neptune and available tools for cloud deployment management."""
@@ -697,21 +709,26 @@ async def info() -> dict[str, Any]:
697709

698710
return {
699711
"status": "success",
700-
"platform": "Neptune (neptune.dev)",
712+
"platform": f"Neptune (neptune.dev) - API Base URL: {SETTINGS.api_base_url.rstrip('/')}",
701713
"description": "Neptune is a cloud deployment platform that simplifies deploying and managing containerized applications with provisioned cloud resources.",
702714
"available_tools": {
703715
"setup": {
704716
"login": tools_by_name.get("login", "Authenticate with Neptune"),
705717
"get_project_schema": tools_by_name.get("get_project_schema", "Get the JSON schema for neptune.json"),
706718
},
707719
"configuration": {
708-
"add_new_resource": tools_by_name.get("add_new_resource", "Get info about resource types (StorageBucket, Secret, etc.) and how to configure these resources in neptune.json"),
720+
"add_new_resource": tools_by_name.get(
721+
"add_new_resource",
722+
"Get info about resource types (StorageBucket, Secret, etc.) and how to configure these resources in neptune.json",
723+
),
709724
},
710725
"deployment": {
711726
"provision_resources": tools_by_name.get("provision_resources", "Provision cloud infrastructure"),
712727
"deploy_project": tools_by_name.get("deploy_project", "Build and deploy the application"),
713728
"wait_for_deployment": tools_by_name.get("wait_for_deployment", "Wait for deployment to complete"),
714-
"get_deployment_status": tools_by_name.get("get_deployment_status", "Check deployment and resource status"),
729+
"get_deployment_status": tools_by_name.get(
730+
"get_deployment_status", "Check deployment and resource status"
731+
),
715732
"delete_project": tools_by_name.get("delete_project", "Delete project and all resources"),
716733
},
717734
"resources": {
@@ -743,6 +760,7 @@ async def info() -> dict[str, Any]:
743760
"next_step": "Use 'login' to authenticate with Neptune, then 'get_project_schema' to understand how to configure your project.",
744761
}
745762

763+
746764
async def list_tools() -> list[dict[str, Any]]:
747765
"""Function to return all tools provided by this MCP."""
748766
tools = await mcp.get_tools()
@@ -754,15 +772,17 @@ async def list_tools() -> list[dict[str, Any]]:
754772
for tool in tools.values()
755773
]
756774

775+
757776
def check_docker_installed() -> bool:
758777
"""Check if docker is installed and running."""
759778
import subprocess
779+
760780
try:
761781
result = subprocess.Popen(["docker", "info"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
762782
result.communicate()
763783
if result.returncode != 0:
764784
return False
765-
return True
785+
return True
766786
except Exception as e:
767787
log.error(f"Failed to check if docker is installed and running: {e}")
768788
return False

src/neptune_cli/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
2-
from typing import List, Union
32
import subprocess
3+
from typing import List, Union
44

55

66
@dataclass

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)