-
Notifications
You must be signed in to change notification settings - Fork 20
fix: keep SDK importable without platform_ext, related automodel image fixes #1510
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1028,16 +1028,41 @@ def test_vendor_entrypoints_writes_to_sdk(tmp_path: Path, monkeypatch) -> None: | |
| assert "entry-points" not in wrapper_updated["project"] | ||
|
|
||
|
|
||
| def test_replace_client_methods_updates_init_and_getattr(tmp_path: Path) -> None: | ||
| def test_replace_client_methods_updates_init_and_getattr(tmp_path: Path, monkeypatch) -> None: | ||
| sdk_path = tmp_path / "sdk/python/nemo-platform" | ||
| client_path = sdk_path / "src/nemo_platform/_client.py" | ||
| source_path = tmp_path / "packages/nemo_platform_ext/src/nemo_platform_ext/client/enhanced.py" | ||
| client_path.parent.mkdir(parents=True, exist_ok=True) | ||
| source_path.parent.mkdir(parents=True, exist_ok=True) | ||
| plugin_client_path = tmp_path / "nemo_platform_plugin/client" | ||
| plugin_client_path.mkdir(parents=True) | ||
| (client_path.parent / "__init__.py").write_text("", encoding="utf-8") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Remove the temporary 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| (client_path.parent / "_base_client.py").write_text( | ||
| """ | ||
| class DefaultAsyncHttpxClient: | ||
| pass | ||
|
|
||
|
|
||
| class DefaultHttpxClient: | ||
| pass | ||
| """.lstrip(), | ||
| encoding="utf-8", | ||
| ) | ||
| (tmp_path / "nemo_platform_plugin/__init__.py").write_text("", encoding="utf-8") | ||
| (plugin_client_path / "__init__.py").write_text("", encoding="utf-8") | ||
| (plugin_client_path / "constants.py").write_text( | ||
| 'WORKLOAD_IDENTITY_TOKEN_FILE_ENVVAR = "NMP_WORKLOAD_IDENTITY_TOKEN_FILE"\n', | ||
| encoding="utf-8", | ||
| ) | ||
| (plugin_client_path / "tls.py").write_text( | ||
| "def client_verify_from_env() -> bool:\n return True\n", | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| client_path.write_text( | ||
| """ | ||
| from typing import Any | ||
| from nemo_platform_ext.client.tls import client_verify_from_env | ||
|
|
||
|
|
||
| def _should_bootstrap_config(config_path: object | None = None) -> bool: | ||
|
|
@@ -1096,8 +1121,9 @@ def __getattr__(self, name: str) -> Any: | |
|
|
||
| assert "from pathlib import Path" in updated | ||
| assert "from nemo_platform._base_client import DefaultAsyncHttpxClient, DefaultHttpxClient" in updated | ||
| assert "from nemo_platform_ext.client.tls import client_verify_from_env" in updated | ||
| assert "from nemo_platform_plugin.client.constants import WORKLOAD_IDENTITY_TOKEN_FILE_ENVVAR" in updated | ||
| assert "from nemo_platform_plugin.client.tls import client_verify_from_env" in updated | ||
| assert "from nemo_platform_ext.client.tls import client_verify_from_env" not in updated | ||
|
mckornfield marked this conversation as resolved.
|
||
| assert "def _should_bootstrap_config(config_path: Path | None = None) -> bool:" in updated | ||
| assert "return config_path is not None" in updated | ||
| assert "return False" not in updated | ||
|
|
@@ -1106,3 +1132,41 @@ def __getattr__(self, name: str) -> Any: | |
| assert updated.count("def __getattr__(self, name: str) -> Any:") == 2 | ||
| assert "self.value = 1" not in updated | ||
| assert "self.value = 2" not in updated | ||
|
|
||
| class BlockNemoPlatformExt: | ||
| def find_spec( | ||
| self, | ||
| fullname: str, | ||
| path: object | None = None, | ||
| target: object | None = None, | ||
| ) -> None: | ||
| del path, target | ||
| if fullname == "nemo_platform_ext" or fullname.startswith("nemo_platform_ext."): | ||
| raise ModuleNotFoundError("nemo_platform_ext must not be imported") | ||
| return None | ||
|
|
||
| blocked_finder = BlockNemoPlatformExt() | ||
| module_names = ( | ||
| "nemo_platform", | ||
| "nemo_platform._base_client", | ||
| "nemo_platform._client", | ||
| "nemo_platform_plugin", | ||
| "nemo_platform_plugin.client", | ||
| "nemo_platform_plugin.client.constants", | ||
| "nemo_platform_plugin.client.tls", | ||
| ) | ||
| monkeypatch.syspath_prepend(str(tmp_path)) | ||
| monkeypatch.syspath_prepend(str(sdk_path / "src")) | ||
| sys.meta_path.insert(0, blocked_finder) | ||
| try: | ||
| for module_name in module_names: | ||
| sys.modules.pop(module_name, None) | ||
|
|
||
| generated_client = import_module("nemo_platform._client") | ||
|
|
||
| assert generated_client.NeMoPlatform(config_path=Path("config.yaml")).should_bootstrap is True | ||
| finally: | ||
| if blocked_finder in sys.meta_path: | ||
| sys.meta_path.remove(blocked_finder) | ||
| for module_name in module_names: | ||
| sys.modules.pop(module_name, None) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Annotate
monkeypatchaspytest.MonkeyPatchand importpytestnormally.🤖 Prompt for AI Agents
Source: Coding guidelines