in linux/install_gpu_driver.py [0:0]
def detect_gpu_device() -> Optional[str]:
"""
Check if there is an NVIDIA GPU device attached and return its device code.
"""
lspci = run("lspci -n")
output = lspci.stdout.decode()
dev_re = re.compile(r"10de:[\w\d]{4}")
for line in output.splitlines():
dev_code = dev_re.findall(line)
if dev_code:
return dev_code[0]
else:
return None