diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb95bb6..ca1f57a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: args: [--ignore-case] files: ^docs/source/spelling_wordlist\.txt$ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.14.14 + rev: v0.15.1 hooks: - id: ruff-check args: [--fix, --exit-non-zero-on-fix] diff --git a/nvitop-exporter/nvitop_exporter/version.py b/nvitop-exporter/nvitop_exporter/version.py index aefa01b..07913f8 100644 --- a/nvitop-exporter/nvitop_exporter/version.py +++ b/nvitop-exporter/nvitop_exporter/version.py @@ -25,22 +25,24 @@ __email__ = 'XuehaiPan@pku.edu.cn' __release__ = False if not __release__: - import os import subprocess + from pathlib import Path - root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + root_dir = Path(__file__).absolute().parent.parent.parent try: prefix, sep, suffix = ( subprocess.check_output( # noqa: S603 [ # noqa: S607 'git', - f'--git-dir={os.path.join(root_dir, ".git")}', + f'--git-dir={root_dir / ".git"}', 'describe', '--abbrev=7', ], cwd=root_dir, stderr=subprocess.DEVNULL, text=True, + encoding='utf-8', + timeout=120.0, ) .strip() .lstrip('v') @@ -56,7 +58,7 @@ if not __release__: else: __version__ = prefix del prefix, sep, suffix - except (OSError, subprocess.CalledProcessError): + except (OSError, RuntimeError, subprocess.SubprocessError): pass - del os, subprocess, root_dir + del Path, subprocess, root_dir diff --git a/nvitop/api/device.py b/nvitop/api/device.py index 9b45047..f34338a 100644 --- a/nvitop/api/device.py +++ b/nvitop/api/device.py @@ -3241,12 +3241,15 @@ def _parse_cuda_visible_devices( # pylint: disable=too-many-branches,too-many-s """, ), ], + stderr=subprocess.DEVNULL, + text=True, + encoding='utf-8', + timeout=120.0, ) - .decode('utf-8', errors='replace') .strip() .split(',') ) - except subprocess.CalledProcessError: + except subprocess.SubprocessError: pass else: uuids = [ diff --git a/nvitop/version.py b/nvitop/version.py index cb5c1ed..812e0df 100644 --- a/nvitop/version.py +++ b/nvitop/version.py @@ -25,22 +25,24 @@ __email__ = 'XuehaiPan@pku.edu.cn' __release__ = False if not __release__: - import os import subprocess + from pathlib import Path - root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + root_dir = Path(__file__).absolute().parent.parent try: prefix, sep, suffix = ( subprocess.check_output( # noqa: S603 [ # noqa: S607 'git', - f'--git-dir={os.path.join(root_dir, ".git")}', + f'--git-dir={root_dir / ".git"}', 'describe', '--abbrev=7', ], cwd=root_dir, stderr=subprocess.DEVNULL, text=True, + encoding='utf-8', + timeout=120.0, ) .strip() .lstrip('v') @@ -56,10 +58,10 @@ if not __release__: else: __version__ = prefix del prefix, sep, suffix - except (OSError, subprocess.CalledProcessError): + except (OSError, RuntimeError, subprocess.SubprocessError): pass - del os, subprocess, root_dir + del Path, subprocess, root_dir # The package `nvidia-ml-py` is not backward compatible over releases. This may