gemini-code-assist[bot] commented on code in PR #489:
URL: https://github.com/apache/tvm-ffi/pull/489#discussion_r2868028073
##########
python/tvm_ffi/__init__.py:
##########
@@ -19,78 +19,100 @@
# order matters here so we need to skip isort here
# isort: skip_file
-# HACK: try importing torch first, to avoid a potential
-# symbol conflict when both torch and tvm_ffi are imported.
-# This conflict can be reproduced in a very narrow scenario:
-# 1. GitHub action on Windows X64
-# 2. Python 3.12
-# 3. torch 2.9.0
-try:
- import torch
-except ImportError:
- pass
+import sys
+from typing import TYPE_CHECKING
+
+
+def _is_config_mode() -> bool:
+ """Check user is invoking the config CLI entry."""
+ if sys.argv[0].endswith("tvm-ffi-config"):
+ return True
+ # sys.orig_argv is available only after python 3.10
+ if hasattr(sys, "orig_argv"):
+ # Use orig_argv because Python strips the `tvm_ffi.config` from
sys.argv when using -m.
+ try:
+ index = sys.orig_argv.index("-m")
+ except ValueError:
+ return False
+ if index + 1 < len(sys.orig_argv) and sys.orig_argv[index + 1] ==
"tvm_ffi.config":
+ return True
Review Comment:

The logic for checking `sys.orig_argv` can be simplified to avoid using a
`try...except` block for control flow. Iterating through the arguments is more
explicit and improves readability by not having an early `return` in the
`except` block.
```suggestion
if hasattr(sys, "orig_argv"):
# Use orig_argv because Python strips the `tvm_ffi.config` from
sys.argv when using -m.
argv = sys.orig_argv
for i, arg in enumerate(argv):
if arg == "-m" and i + 1 < len(argv) and argv[i + 1] ==
"tvm_ffi.config":
return True
```
--
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]