gemini-code-assist[bot] commented on code in PR #19987:
URL: https://github.com/apache/tvm/pull/19987#discussion_r3565844188


##########
python/tvm/libinfo.py:
##########
@@ -39,18 +39,21 @@ def package_lib_paths() -> list[Path]:
 
     Anchored on this file's location (``python/tvm/libinfo.py``), the list
     covers the wheel-install layout (``python/tvm/lib/``) and the in-tree dev
-    build layouts (``<worktree>/build/lib/`` and ``<worktree>/lib/``).
+    build layouts (``<worktree>/build/lib/``,
+    ``<worktree>/build/<wheel-tag>/lib/``, and ``<worktree>/lib/``).
     ``TVM_LIBRARY_PATH`` is prepended when set so it takes priority. Callers
     pick the basenames they want (e.g. ``libtvm_runtime.so``) and the load
     mode; this function only returns the search path.
     """
     pkg = _rel_top_directory()  # python/tvm/
+    build = _dev_top_directory() / "build"
     paths: list[Path] = []
     if os.environ.get("TVM_LIBRARY_PATH"):
         paths.append(Path(os.environ["TVM_LIBRARY_PATH"]))
     paths += [
         pkg / "lib",  # wheel layout
-        _dev_top_directory() / "build" / "lib",  # dev: <worktree>/build/lib
+        build / "lib",  # dev: <worktree>/build/lib
+        *sorted(build.glob("*/lib")),  # dev: <worktree>/build/<wheel-tag>/lib
         _dev_top_directory() / "lib",  # dev: <worktree>/lib
     ]

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Unconditionally calling `build.glob("*/lib")` can be inefficient and 
potentially problematic in non-development environments (e.g., when TVM is 
installed as a wheel and the `build` directory does not exist or refers to an 
unrelated system path). Since `glob` is evaluated immediately when 
`package_lib_paths()` is called (which happens during `import tvm`), we should 
guard this with `build.is_dir()` to avoid unnecessary filesystem scanning. 
Additionally, we can cache the result of `_dev_top_directory()` to avoid 
calling it twice.
   
   ```suggestion
       dev_top = _dev_top_directory()
       build = dev_top / "build"
       paths: list[Path] = []
       if os.environ.get("TVM_LIBRARY_PATH"):
           paths.append(Path(os.environ["TVM_LIBRARY_PATH"]))
       paths += [
           pkg / "lib",  # wheel layout
           build / "lib",  # dev: <worktree>/build/lib
           *(sorted(build.glob("*/lib")) if build.is_dir() else []),  # dev: 
<worktree>/build/<wheel-tag>/lib
           dev_top / "lib",  # dev: <worktree>/lib
       ]
   ```



-- 
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]

Reply via email to