Skip to content

Commit

Permalink
fix(cloud client): various type error (#4680)
Browse files Browse the repository at this point in the history
* fix(cloud client): various type error

* ci: auto fixes from pre-commit.ci

For more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
bojiang and pre-commit-ci[bot] authored Apr 19, 2024
1 parent 74936ed commit 606c975
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
22 changes: 13 additions & 9 deletions src/bentoml/_internal/cloud/bentocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def filter_(
)
return
finish_req = FinishUploadBentoSchema(
status=BentoUploadStatus.SUCCESS,
status=BentoUploadStatus.SUCCESS.value,
reason="",
)
try:
Expand All @@ -279,7 +279,7 @@ def filter_(
)
if resp.status_code != 200:
finish_req = FinishUploadBentoSchema(
status=BentoUploadStatus.FAILED,
status=BentoUploadStatus.FAILED.value,
reason=resp.text,
)
else:
Expand Down Expand Up @@ -339,7 +339,7 @@ def chunk_upload(
)
if resp.status_code != 200:
return FinishUploadBentoSchema(
status=BentoUploadStatus.FAILED,
status=BentoUploadStatus.FAILED.value,
reason=resp.text,
)
return resp.headers["ETag"], chunk_number
Expand Down Expand Up @@ -391,7 +391,7 @@ def chunk_upload(

except Exception as e: # pylint: disable=broad-except
finish_req = FinishUploadBentoSchema(
status=BentoUploadStatus.FAILED,
status=BentoUploadStatus.FAILED.value,
reason=str(e),
)
if finish_req.status == BentoUploadStatus.FAILED.value:
Expand Down Expand Up @@ -475,14 +475,17 @@ def _do_pull_bento(
with tempfile.TemporaryDirectory() as temp_dir:
# Download models to a temporary directory
model_store = ModelStore(temp_dir)
assert remote_bento.manifest is not None
with ThreadPoolExecutor(
max_workers=max(len(remote_bento.manifest.models), 1)
) as executor:

def pull_model(model_tag: Tag):
model_download_task_id = (
self.spinner.transmission_progress.add_task(
f'Pulling model "{model_tag}"', start=False, visible=False
f'Pulling model "{model_tag}"',
start=False,
visible=False,
)
)
self._do_pull_model(
Expand Down Expand Up @@ -567,6 +570,7 @@ def pull_model(model_tag: Tag):
temp_fs.makedirs(p.parent.as_posix(), recreate=True)
temp_fs.writebytes(member.name, f.read())
bento = Bento.from_fs(temp_fs)
assert remote_bento.manifest is not None
for model_tag in remote_bento.manifest.models:
with self.spinner.spin(
text=f'Copying model "{model_tag}" to model store'
Expand Down Expand Up @@ -725,7 +729,7 @@ def io_cb(x: int):
)
return
finish_req = FinishUploadModelSchema(
status=ModelUploadStatus.SUCCESS,
status=ModelUploadStatus.SUCCESS.value,
reason="",
)
try:
Expand All @@ -735,7 +739,7 @@ def io_cb(x: int):
)
if resp.status_code != 200:
finish_req = FinishUploadModelSchema(
status=ModelUploadStatus.FAILED,
status=ModelUploadStatus.FAILED.value,
reason=resp.text,
)
else:
Expand Down Expand Up @@ -796,7 +800,7 @@ def chunk_upload(
)
if resp.status_code != 200:
return FinishUploadModelSchema(
status=ModelUploadStatus.FAILED,
status=ModelUploadStatus.FAILED.value,
reason=resp.text,
)
return resp.headers["ETag"], chunk_number
Expand Down Expand Up @@ -848,7 +852,7 @@ def chunk_upload(

except Exception as e: # pylint: disable=broad-except
finish_req = FinishUploadModelSchema(
status=ModelUploadStatus.FAILED,
status=ModelUploadStatus.FAILED.value,
reason=str(e),
)
if finish_req.status == ModelUploadStatus.FAILED.value:
Expand Down
16 changes: 8 additions & 8 deletions src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,12 @@ def get_bento_info(
except NotFound:
bento_schema = None

if bento_obj is None and bento_schema is None:
raise NotFound(f"bento {bento} not found in both local and cloud")
elif bento_obj is not None and bento_schema is None:
if bento_obj is not None:
# push to bentocloud
_cloud_client.push_bento(bento=bento_obj, context=context)
return bento_obj.info
else:
if bento_schema is not None:
assert bento_schema.manifest is not None
with Live(_cloud_client.spinner.progress_group):
_cloud_client.spinner.log_progress.add_task(
f"[bold blue]Using bento {bento.name}:{bento.version} from bentocloud to deploy"
Expand All @@ -324,6 +323,7 @@ def get_bento_info(
entry_service=bento_schema.manifest.entry_service,
service=bento_schema.manifest.service,
)
raise NotFound(f"bento {bento} not found in both local and cloud")
else:
raise BentoMLException(
"Create a deployment needs a target; project path or bento is necessary"
Expand Down Expand Up @@ -379,8 +379,8 @@ def to_dict(self) -> dict[str, t.Any]:
"created_at": self.created_at,
"created_by": self.created_by,
"config": (
self.get_config(refetch=False).to_dict(with_meta=False)
if self.get_config(refetch=False) is not None
config.to_dict(with_meta=False)
if (config := self.get_config(refetch=False)) is not None
else None
),
"status": self.get_status(refetch=False).to_dict(),
Expand Down Expand Up @@ -458,7 +458,7 @@ def get_client(
if self._urls is None or len(self._urls) != 1:
raise BentoMLException("Deployment url is not ready")

return SyncHTTPClient(self._urls[0], media_type=media_type, token=token)
return SyncHTTPClient(self._urls[0], token=token)

def get_async_client(
self,
Expand All @@ -472,7 +472,7 @@ def get_async_client(
raise BentoMLException(f"Deployment status is {self._schema.status}")
if self._urls is None or len(self._urls) != 1:
raise BentoMLException("Deployment url is not ready")
return AsyncHTTPClient(self._urls[0], media_type=media_type, token=token)
return AsyncHTTPClient(self._urls[0], token=token)

def wait_until_ready(
self,
Expand Down

0 comments on commit 606c975

Please sign in to comment.