diff --git a/requirements-dev.txt b/requirements-dev.txt index 0e89da9e83..5cd6193c43 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,7 +9,7 @@ sphinx-autoapi sphinx-autodoc-typehints sphinxcontrib-autoprogram cwltest>=2.2.20211116163652 -mypy==1.2.0 +mypy==1.4.1 types-requests types-setuptools types-boto diff --git a/src/toil/lib/accelerators.py b/src/toil/lib/accelerators.py index eab1d7f630..2c7f50c9c2 100644 --- a/src/toil/lib/accelerators.py +++ b/src/toil/lib/accelerators.py @@ -16,7 +16,7 @@ import os import subprocess -from typing import Dict, List, Optional, Set, Union +from typing import Dict, List, Optional, Set, Union, cast from xml.dom import minidom from toil.job import AcceleratorRequirement @@ -92,10 +92,21 @@ def count_nvidia_gpus() -> int: # # Some example output is here: try: - return int(minidom.parseString( - subprocess.check_output(["nvidia-smi", "-q", "-x"]) - ).getElementsByTagName("attached_gpus")[0].firstChild.data) - except (FileNotFoundError, subprocess.CalledProcessError, IndexError, ValueError, PermissionError): + return int( + cast( + minidom.Text, + minidom.parseString(subprocess.check_output(["nvidia-smi", "-q", "-x"])) + .getElementsByTagName("attached_gpus")[0] + .firstChild, + ).data + ) + except ( + FileNotFoundError, + subprocess.CalledProcessError, + IndexError, + ValueError, + PermissionError, + ): return 0 # TODO: Parse each gpu > product_name > text content and convert to some