driazati commented on a change in pull request #9752:
URL: https://github.com/apache/tvm/pull/9752#discussion_r777801877



##########
File path: tests/scripts/ci.py
##########
@@ -44,48 +47,107 @@ class col:
     UNDERLINE = "\033[4m"
 
 
-def print_color(color: str, msg: str, **kwargs: Any) -> None:
+def print_color(color: str, msg: str, bold: bool, **kwargs: Any) -> None:
     if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
-        print(col.BOLD + color + msg + col.RESET, **kwargs)
+        bold_code = col.BOLD if bold else ""
+        print(bold_code + color + msg + col.RESET, **kwargs)
     else:
         print(msg, **kwargs)
 
 
+warnings = []
+
+
 def clean_exit(msg: str) -> None:
-    print_color(col.RED, msg, file=sys.stderr)
+    print_color(col.RED, msg, bold=True, file=sys.stderr)
+
+    for warning in warnings:
+        print_color(col.YELLOW, warning, bold=False, file=sys.stderr)
+
     exit(1)
 
 
 def cmd(commands: List[Any], **kwargs: Any):
     commands = [str(s) for s in commands]
     command_str = " ".join(commands)
-    print_color(col.BLUE, command_str)
+    print_color(col.BLUE, command_str, bold=True)
     proc = subprocess.run(commands, **kwargs)
     if proc.returncode != 0:
         raise RuntimeError(f"Command failed: '{command_str}'")
+    return proc
 
 
-def docker(name: str, image: str, scripts: List[str], env: Dict[str, str]):
-    """
-    Invoke a set of bash scripts through docker/bash.sh
-    """
+def check_docker():
+    executable = shutil.which("docker")
+    if executable is None:
+        clean_exit("'docker' executable not found, install it first (e.g. 'apt 
install docker.io')")
+
     if sys.platform == "linux":
         # Check that the user is in the docker group before running
         try:
             group = grp.getgrnam("docker")
             if getpass.getuser() not in group.gr_mem:
-                print_color(
-                    col.YELLOW, f"Note: User '{getpass.getuser()}' is not in 
the 'docker' group"
+                warnings.append(
+                    f"Note: User '{getpass.getuser()}' is not in the 'docker' 
group, either:\n"
+                    " * run with 'sudo'\n"
+                    " * add user to 'docker': sudo usermod -aG docker 
$(whoami), then log out and back in",
                 )
-        except KeyError:
-            print_color(col.YELLOW, f"Note: 'docker' group does not exist")
+        except KeyError as e:
+            warnings.append(f"Note: 'docker' group does not exist")
+
+
+def check_gpu():
+    if sys.platform == "linux" and shutil.which("lshw"):
+        # See if we can check if a GPU is present in case of later failures,
+        # but don't block on execution since this isn't critical
+        try:
+            proc = cmd(
+                ["lshw", "-json", "-C", "display"],
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                encoding="utf-8",
+            )
+            stdout = proc.stdout.strip().strip(",")
+            stdout = json.loads(stdout)
+            if isinstance(stdout, dict):

Review comment:
       the `lshw` output I saw wasn't consistent across machines (sometimes a 
list of items, sometimes just a single item), so this fixes that




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


Reply via email to