-
Notifications
You must be signed in to change notification settings - Fork 18
feat(files): migrate filesets package to NemoClient typed HTTP client #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matthewgrossman
merged 39 commits into
main
from
mgrossman/aircore-827-migrate-first-plugin-to-nemoclient-typed-http-client-files
Jul 6, 2026
Merged
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
82fb001
squash
matthewgrossman 4c69439
reduce diff
matthewgrossman 113160c
make more concise
matthewgrossman 05a8140
query params
matthewgrossman 3eb4961
lint
matthewgrossman f10ea57
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 4af5133
fix: compare SecretRef.root instead of SecretRef object against string
matthewgrossman c4b9e5e
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 567ecac
vendor
matthewgrossman 8ea1d2c
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 8966a96
fixes
matthewgrossman 2e9991e
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 60083cc
clenaup
matthewgrossman 4025935
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 1a6f8ca
self code review
matthewgrossman 9ff20bb
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 038c583
improve perf of stream
matthewgrossman 9caa76b
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman a413ac8
add new client.py for files
matthewgrossman 201d06a
merge
matthewgrossman a333f20
update sync/async handling
matthewgrossman 945006b
add comments
matthewgrossman be8fbf2
self code review
matthewgrossman b9f7c6c
cleanup
matthewgrossman 3de2f54
vendor
matthewgrossman 7cb16ce
self review
matthewgrossman d389a46
update tests
matthewgrossman 0ad1329
lint
matthewgrossman 528f209
fix openapi
matthewgrossman ea717b9
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 53b77aa
fix: resolve ty lint errors for FilesetsSubResource migration
matthewgrossman 83887a8
fix: remap NemoClient errors to Stainless SDK errors for backward compat
matthewgrossman 4869d05
fix: remap NemoClient errors to Stainless SDK errors for backward compat
matthewgrossman 11a9a2d
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 2c063af
fix: update callers for NemoPaginatedResponse interface
matthewgrossman 76c16dc
feat: replace __iter__/__aiter__ with explicit items()/pages() on pag…
matthewgrossman 0a6416d
self code review
matthewgrossman b1fe7de
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman b0e6f05
self code review
matthewgrossman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
193 changes: 112 additions & 81 deletions
193
packages/filesets/src/filesets/filesystem/filesystem.py
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
packages/nemo_platform_plugin/src/nemo_platform_plugin/client/errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """HTTP error hierarchy for the NemoClient. | ||
|
|
||
| Status-code-specific subclasses also inherit from the corresponding | ||
| Stainless SDK exception so that existing ``except ConflictError`` | ||
| (imported from ``nemo_platform``) catches our exceptions too. | ||
|
|
||
| TODO: Once all consumers import from ``nemo_platform_plugin.client.errors``, | ||
| remove the Stainless base classes. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import httpx | ||
|
|
||
|
|
||
| class NemoHTTPError(Exception): | ||
| """Raised on non-2xx HTTP responses. | ||
|
|
||
| Attributes: | ||
| http_response: The raw httpx response. | ||
| status_code: The HTTP status code. | ||
| detail: A human-readable error message extracted from the response | ||
| body (``{"detail": "..."}`` convention used by FastAPI / NeMo | ||
| Platform), or the raw response text as a fallback. | ||
| body: The parsed JSON response body, or None. | ||
| """ | ||
|
|
||
| def __init__(self, http_response: httpx.Response) -> None: | ||
| self.http_response = http_response | ||
| self.status_code = http_response.status_code | ||
| self.detail = self._extract_detail(http_response) | ||
| self.body = self._extract_body(http_response) | ||
| # Call Exception.__init__ directly to avoid Stainless APIStatusError.__init__ | ||
| # which expects different arguments. Our subclasses inherit from both | ||
| # NemoHTTPError and the Stainless exception for isinstance() compatibility. | ||
| Exception.__init__(self, f"HTTP {self.status_code}: {self.detail}") | ||
|
|
||
| @staticmethod | ||
| def _extract_body(resp: httpx.Response) -> object | None: | ||
| try: | ||
| return resp.json() | ||
| except Exception: | ||
| return None | ||
|
|
||
| @staticmethod | ||
| def _extract_detail(resp: httpx.Response) -> str: | ||
| try: | ||
| body = resp.json() | ||
| if isinstance(body, dict) and isinstance(body.get("detail"), str): | ||
| return body["detail"] | ||
| except Exception: | ||
| pass | ||
| return resp.text | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Status-code-specific errors | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def _stainless_base(name: str) -> type: | ||
| """Import a Stainless SDK exception by name, falling back to NemoHTTPError.""" | ||
| try: | ||
| import nemo_platform._exceptions as exc | ||
|
|
||
| return getattr(exc, name) | ||
| except (ImportError, AttributeError): | ||
| return NemoHTTPError | ||
|
|
||
|
|
||
| class BadRequestError(NemoHTTPError, _stainless_base("BadRequestError")): # type: ignore[misc] | ||
| """HTTP 400""" | ||
|
|
||
|
|
||
| class AuthenticationError(NemoHTTPError, _stainless_base("AuthenticationError")): # type: ignore[misc] | ||
| """HTTP 401""" | ||
|
|
||
|
|
||
| class PermissionDeniedError(NemoHTTPError, _stainless_base("PermissionDeniedError")): # type: ignore[misc] | ||
| """HTTP 403""" | ||
|
|
||
|
|
||
| class NotFoundError(NemoHTTPError, _stainless_base("NotFoundError")): # type: ignore[misc] | ||
| """HTTP 404""" | ||
|
|
||
|
|
||
| class ConflictError(NemoHTTPError, _stainless_base("ConflictError")): # type: ignore[misc] | ||
| """HTTP 409""" | ||
|
|
||
|
|
||
| class UnprocessableEntityError(NemoHTTPError, _stainless_base("UnprocessableEntityError")): # type: ignore[misc] | ||
| """HTTP 422""" | ||
|
|
||
|
|
||
| class RateLimitError(NemoHTTPError, _stainless_base("RateLimitError")): # type: ignore[misc] | ||
| """HTTP 429""" | ||
|
|
||
|
|
||
| class InternalServerError(NemoHTTPError, _stainless_base("InternalServerError")): # type: ignore[misc] | ||
| """HTTP 500+""" | ||
|
|
||
|
|
||
| _STATUS_CODE_TO_ERROR: dict[int, type[NemoHTTPError]] = { | ||
| 400: BadRequestError, | ||
| 401: AuthenticationError, | ||
| 403: PermissionDeniedError, | ||
| 404: NotFoundError, | ||
| 409: ConflictError, | ||
| 422: UnprocessableEntityError, | ||
| 429: RateLimitError, | ||
| 500: InternalServerError, | ||
| } | ||
|
|
||
|
|
||
| def raise_for_status(http_response: httpx.Response) -> None: | ||
| """Raise status-code-specific NemoHTTPError subclass for non-2xx responses.""" | ||
| if 200 <= http_response.status_code < 300: | ||
| return | ||
| error_cls = _STATUS_CODE_TO_ERROR.get(http_response.status_code, NemoHTTPError) | ||
| if error_cls is NemoHTTPError and http_response.status_code >= 500: | ||
| error_cls = InternalServerError | ||
| raise error_cls(http_response) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.