feat: add environment files support and scotty file download helper - #2861
feat: add environment files support and scotty file download helper#2861copybara-service[bot] wants to merge 1 commit into
Conversation
a22fc12 to
8c2fa18
Compare
b482e89 to
92535be
Compare
f7be0ce to
cff0c08
Compare
PiperOrigin-RevId: 962222280
cff0c08 to
ea4e04f
Compare
| @property | ||
| def with_raw_response(self): | ||
| return _RawResponseAccessorProxy(super().with_raw_response) | ||
|
|
||
| @property | ||
| def with_streaming_response(self): | ||
| return _RawResponseAccessorProxy(super().with_streaming_response) | ||
|
|
||
| @property | ||
| def files(self) -> GeminiNextGenEnvironmentFiles: | ||
| return getattr(self, '_files_wrapper', None) | ||
|
|
||
| @files.setter | ||
| def files(self, value: Any) -> None: | ||
| self._sdk_files = value | ||
|
|
There was a problem hiding this comment.
IIUC client.environments.with_raw_response.files does the following:
GeminiNextGenEnvironments.with_raw_responseproxies toEnvironments.with_raw_response->EnvironmentWithRawResponse- calls
__getattr__('files')onEnvironmentWithRawResponse->self._sdk.files.with_raw_response self._sdk.filesis the wrapper'sfilesproperty so returns_files_wrapper= plainGeminiNextGenEnvironmentFileswith nowith_raw_response->AttributeError: 'GeminiNextGenEnvironmentFiles' object has no attribute 'with_raw_response'
Same thing expected for client.environments.with_streaming_response.files
I think it would be wise to add tests for with_raw/streaming_response helpers
| @property | ||
| def files(self) -> GeminiNextGenEnvironmentFiles: | ||
| return getattr(self, '_files_wrapper', None) | ||
|
|
||
| @files.setter | ||
| def files(self, value: Any) -> None: | ||
| self._sdk_files = value | ||
|
|
There was a problem hiding this comment.
I don't think these should be nested under if not TYPE_CHECKING. By doing so mypy could raise a "Files" has no attribute "download" for client.environments.files.download(...)` for example
| @property | |
| def files(self) -> GeminiNextGenEnvironmentFiles: | |
| return getattr(self, '_files_wrapper', None) | |
| @files.setter | |
| def files(self, value: Any) -> None: | |
| self._sdk_files = value | |
| @property | |
| def files(self) -> GeminiNextGenEnvironmentFiles: | |
| return getattr(self, '_files_wrapper', None) | |
| @files.setter | |
| def files(self, value: Any) -> None: | |
| self._sdk_files = value |
|
|
||
| @property | ||
| def files(self) -> AsyncGeminiNextGenEnvironmentFiles: | ||
| return getattr(self, '_files_wrapper', None) | ||
|
|
||
| @files.setter | ||
| def files(self, value: Any) -> None: | ||
| self._sdk_files = value | ||
|
|
There was a problem hiding this comment.
Could streamline by initializing files: GeminiNextGenEnvironmentFiles instead of self._files_wrapper:
class GeminiNextGenEnvironments(GeneratedEnvironments):
"""Public environments resource backed by the NextGen client."""
files: GeminiNextGenEnvironmentFiles
def __init__(self, api_client: Any):
self._api_client = api_client
sdk = build_google_genai_client(api_client)
super().__init__(sdk.sdk_configuration, parent_ref=sdk)
def _init_sdks(self) -> None:
self.files = GeminiNextGenEnvironmentFiles(
self.sdk_configuration,
parent_ref=self.parent_ref,
api_client=self._api_client,
)
| @property | |
| def files(self) -> AsyncGeminiNextGenEnvironmentFiles: | |
| return getattr(self, '_files_wrapper', None) | |
| @files.setter | |
| def files(self, value: Any) -> None: | |
| self._sdk_files = value |
|
|
||
| def __init__(self, api_client: Any): | ||
| self._api_client = api_client | ||
| self._files_wrapper = AsyncGeminiNextGenEnvironmentFiles(self) |
There was a problem hiding this comment.
| env_name = ( | ||
| environment | ||
| if environment.startswith('environments/') | ||
| else f'environments/{environment}' | ||
| ) | ||
| clean_path = path.lstrip('/') | ||
| download_path = f'{env_name}/files/{clean_path}?alt=media' |
There was a problem hiding this comment.
It seems inconsistent to normalize the environment path in download() but not list() (where we pass args directly to async_wrap_sdk_call(files_sdk.list, *args, **kwargs))
feat: add environment files support and scotty file download helper