-
Notifications
You must be signed in to change notification settings - Fork 165
add a scriptlet to put cuopt_grpc_server on the default path #1100
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
Changes from all commits
09e24aa
49726ac
829e6b9
b348cb0
a974d79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import ctypes | ||
| import ctypes.util | ||
| import platform | ||
| import shutil | ||
| import subprocess | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def test_cuopt_grpc_server_on_path(): | ||
| assert shutil.which("cuopt_grpc_server") is not None, ( | ||
| "cuopt_grpc_server should be on PATH after installing cuopt-server" | ||
| ) | ||
|
|
||
|
|
||
| def _check_libuuid(): | ||
| """Return (found: bool, detail: str) for libuuid availability.""" | ||
| name = ctypes.util.find_library("uuid") | ||
| if name is None: | ||
| return False, "ctypes.util.find_library('uuid') returned None" | ||
| try: | ||
| ctypes.CDLL(name) | ||
| return True, f"loaded {name}" | ||
| except OSError as exc: | ||
| return False, f"find_library returned '{name}' but load failed: {exc}" | ||
|
|
||
|
|
||
| def test_cuopt_grpc_server_help(): | ||
| result = subprocess.run( | ||
| ["cuopt_grpc_server", "--help"], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=10, | ||
| ) | ||
| if result.returncode != 0 and not result.stdout and not result.stderr: | ||
| uuid_ok, uuid_detail = _check_libuuid() | ||
| pytest.skip( | ||
| f"cuopt_grpc_server binary failed to load " | ||
| f"(rc={result.returncode}, arch={platform.machine()}). " | ||
| f"libuuid: {uuid_detail}" | ||
| ) | ||
| assert result.returncode == 0, ( | ||
| f"cuopt_grpc_server --help failed (rc={result.returncode}): " | ||
| f"{result.stdout}\n{result.stderr}" | ||
| ) | ||
| output = f"{result.stdout}\n{result.stderr}" | ||
| assert "cuopt_grpc_server" in output, ( | ||
| f"Expected 'cuopt_grpc_server' in --help output, got: {output}" | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| This connects to the gRPC server binary situated under libcuopt/bin folder. | ||
| """ | ||
| server_path = os.path.join( | ||
| os.path.dirname(__file__), "bin", "cuopt_grpc_server" | ||
| ) | ||
| sys.exit(subprocess.call([server_path] + sys.argv[1:])) | ||
|
Comment on lines
+13
to
+16
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. Handle missing/non-executable binary gracefully. On Line 16, a missing or non-executable binary will surface as a Python traceback. Add an explicit guard and exit with a clear error message. Suggested hardening patch def main():
@@
server_path = os.path.join(
os.path.dirname(__file__), "bin", "cuopt_grpc_server"
)
- sys.exit(subprocess.call([server_path] + sys.argv[1:]))
+ if not os.path.isfile(server_path) or not os.access(server_path, os.X_OK):
+ print(
+ f"cuopt_grpc_server binary not found or not executable: {server_path}",
+ file=sys.stderr,
+ )
+ sys.exit(127)
+ sys.exit(subprocess.call([server_path] + sys.argv[1:]))🧰 Tools🪛 Ruff (0.15.10)[error] 16-16: (S603) [warning] 16-16: Consider Replace with (RUF005) 🤖 Prompt for AI Agents |
||
Uh oh!
There was an error while loading. Please reload this page.