gemini-code-assist[bot] commented on code in PR #19726: URL: https://github.com/apache/tvm/pull/19726#discussion_r3391625393
########## python/tvm/contrib/hexagon/pytest_plugin.py: ########## @@ -19,24 +19,25 @@ """Hexagon testing fixtures used to deduce testing argument values from testing parameters""" +from __future__ import annotations + import os import random +import socket import pytest import tvm import tvm.rpc import tvm.testing Review Comment:  Since `HexagonLauncherRPC` and `Session` are no longer imported at the module level, using them as type annotations will cause static analysis/linter errors (e.g., `F821 undefined name`) and type-checking failures. Since `from __future__ import annotations` is used, we can import these types under a `TYPE_CHECKING` block to satisfy type checkers and linters without importing them at runtime. ```suggestion from __future__ import annotations import os import random from typing import TYPE_CHECKING import pytest import tvm import tvm.rpc import tvm.testing if TYPE_CHECKING: from tvm.contrib.hexagon.build import HexagonLauncherRPC from tvm.contrib.hexagon.session import Session ``` ########## python/tvm/contrib/hexagon/pytest_plugin.py: ########## @@ -106,13 +107,18 @@ def get_free_port() -> int: if port > LISTEN_PORT_MAX: port = LISTEN_PORT_MIN - while tvm.contrib.hexagon.build._is_port_in_use(port): + while _is_port_in_use(port): port = port + 1 if port < LISTEN_PORT_MAX else LISTEN_PORT_MIN PREVIOUS_PORT = port return port +def _is_port_in_use(port: int) -> bool: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + return sock.connect_ex(("localhost", port)) == 0 Review Comment:  Instead of duplicating the `_is_port_in_use` helper function from `tvm.contrib.hexagon.build`, we can lazily import it inside `get_free_port()`. This avoids code duplication and keeps the module-level imports clean. ```suggestion from tvm.contrib.hexagon.build import _is_port_in_use while _is_port_in_use(port): port = port + 1 if port < LISTEN_PORT_MAX else LISTEN_PORT_MIN PREVIOUS_PORT = port return port ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
