Skip to content

Commit 83f9b94

Browse files
committed
abandon trying to support other upload file types for devbox file uploads (sticks to base api FileType)
1 parent a487061 commit 83f9b94

3 files changed

Lines changed: 9 additions & 40 deletions

File tree

src/runloop_api_client/sdk/_helpers.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
import io
44
import os
5-
from typing import IO, Dict, Union, Literal, Callable, cast
5+
from typing import Dict, Union, Literal, Callable
66
from pathlib import Path
77

8-
from .._types import FileTypes
9-
from .._utils import file_from_path
10-
118
LogCallback = Callable[[str], None]
12-
UploadInput = Union[FileTypes, str, os.PathLike[str], Path, bytes, bytearray, io.IOBase]
139

1410
ContentType = Literal["unspecified", "text", "binary", "gzip", "tar", "tgz"]
1511
UploadData = Union[str, bytes, bytearray, Path, os.PathLike[str], io.IOBase]
@@ -59,28 +55,3 @@ def read_upload_data(data: UploadData) -> bytes:
5955
return result.encode("utf-8")
6056
return result
6157
raise TypeError("Unsupported upload data type. Provide str, bytes, path, or file-like object.")
62-
63-
64-
def normalize_upload_input(file: UploadInput) -> FileTypes:
65-
"""
66-
Normalize a variety of Python file representations into the generated client's FileTypes.
67-
"""
68-
if isinstance(file, tuple):
69-
return file
70-
if isinstance(file, bytes):
71-
return file
72-
if isinstance(file, bytearray):
73-
return bytes(file)
74-
if isinstance(file, (str, Path, os.PathLike)):
75-
path_str = str(file)
76-
return file_from_path(path_str)
77-
if isinstance(file, io.TextIOBase):
78-
return file.read().encode("utf-8")
79-
if isinstance(file, io.BufferedIOBase) or isinstance(file, io.RawIOBase):
80-
return cast(IO[bytes], file)
81-
if isinstance(file, io.IOBase) and hasattr(file, "read"):
82-
data = file.read()
83-
if isinstance(data, str):
84-
return data.encode("utf-8")
85-
return data
86-
raise TypeError("Unsupported file type for upload. Provide path, bytes, or file-like object.")

src/runloop_api_client/sdk/async_devbox.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
DevboxExecutionDetailView,
1212
DevboxCreateSSHKeyResponse,
1313
)
14-
from .._types import Body, Omit, Query, Headers, Timeout, NotGiven, omit, not_given
14+
from .._types import Body, Omit, Query, Headers, Timeout, NotGiven, FileTypes, omit, not_given
1515
from .._client import AsyncRunloop
16-
from ._helpers import LogCallback, UploadInput, normalize_upload_input
16+
from ._helpers import LogCallback
1717
from .._streaming import AsyncStream
1818
from ..lib.polling import PollingConfig
1919
from .async_execution import AsyncExecution, _AsyncStreamingGroup
@@ -505,19 +505,18 @@ async def download(
505505
async def upload(
506506
self,
507507
path: str,
508-
file: UploadInput,
508+
file: FileTypes,
509509
*,
510510
extra_headers: Headers | None = None,
511511
extra_query: Query | None = None,
512512
extra_body: Body | None = None,
513513
timeout: float | Timeout | None | NotGiven = not_given,
514514
idempotency_key: str | None = None,
515515
) -> object:
516-
file_param = normalize_upload_input(file)
517516
return await self._devbox._client.devboxes.upload_file(
518517
self._devbox.id,
519518
path=path,
520-
file=file_param,
519+
file=file,
521520
extra_headers=extra_headers,
522521
extra_query=extra_query,
523522
extra_body=extra_body,

src/runloop_api_client/sdk/devbox.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
DevboxExecutionDetailView,
1212
DevboxCreateSSHKeyResponse,
1313
)
14-
from .._types import Body, Omit, Query, Headers, Timeout, NotGiven, omit, not_given
14+
from .._types import Body, Omit, Query, Headers, Timeout, NotGiven, FileTypes, omit, not_given
1515
from .._client import Runloop
16-
from ._helpers import LogCallback, UploadInput, normalize_upload_input
16+
from ._helpers import LogCallback
1717
from .execution import Execution, _StreamingGroup
1818
from .._streaming import Stream
1919
from ..lib.polling import PollingConfig
@@ -498,19 +498,18 @@ def download(
498498
def upload(
499499
self,
500500
path: str,
501-
file: UploadInput,
501+
file: FileTypes,
502502
*,
503503
extra_headers: Headers | None = None,
504504
extra_query: Query | None = None,
505505
extra_body: Body | None = None,
506506
timeout: float | Timeout | None | NotGiven = not_given,
507507
idempotency_key: str | None = None,
508508
) -> object:
509-
file_param = normalize_upload_input(file)
510509
return self._devbox._client.devboxes.upload_file(
511510
self._devbox.id,
512511
path=path,
513-
file=file_param,
512+
file=file,
514513
extra_headers=extra_headers,
515514
extra_query=extra_query,
516515
extra_body=extra_body,

0 commit comments

Comments
 (0)