From a0387867fbd269bec0cf0b5dbd2fe04f790dc258 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Tue, 12 Mar 2024 13:21:54 +0000 Subject: [PATCH 1/3] chore(pre-commit): update pre-commit hooks --- .pre-commit-config.yaml | 2 +- nvitop/api/device.py | 4 ++-- nvitop/api/libcuda.py | 14 ++++++-------- nvitop/api/libcudart.py | 14 ++++++-------- nvitop/api/process.py | 2 +- nvitop/gui/screens/metrics.py | 8 ++++---- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1fcb2cba..5e0fd66d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: - id: debug-statements - id: double-quote-string-fixer - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 + rev: v0.3.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/nvitop/api/device.py b/nvitop/api/device.py index 7e45182d..417e2274 100644 --- a/nvitop/api/device.py +++ b/nvitop/api/device.py @@ -710,7 +710,7 @@ def __init__( def __repr__(self) -> str: """Return a string representation of the device.""" - return '{}(index={}, name="{}", total_memory={})'.format( + return '{}(index={}, name={!r}, total_memory={})'.format( # noqa: UP032 self.__class__.__name__, self.index, self.name(), @@ -2741,7 +2741,7 @@ def __init__( def __repr__(self) -> str: """Return a string representation of the CUDA device.""" - return '{}(cuda_index={}, nvml_index={}, name="{}", total_memory={})'.format( + return '{}(cuda_index={}, nvml_index={}, name="{}", total_memory={})'.format( # noqa: UP032 self.__class__.__name__, self.cuda_index, self.index, diff --git a/nvitop/api/libcuda.py b/nvitop/api/libcuda.py index 53f85a5b..50a5a130 100644 --- a/nvitop/api/libcuda.py +++ b/nvitop/api/libcuda.py @@ -259,10 +259,9 @@ def __repr__(self) -> str: ) if self.value not in CUDAError._errcode_to_name: CUDAError._errcode_to_name[self.value] = cuGetErrorName(self.value) - return '{} Code: {} ({}).'.format( - CUDAError._errcode_to_string[self.value], - CUDAError._errcode_to_name[self.value], - self.value, + return ( + f'{CUDAError._errcode_to_string[self.value]} ' + f'Code: {CUDAError._errcode_to_name[self.value]} ({self.value}).' ) except CUDAError: return f'CUDA Error with code {self.value}.' @@ -316,10 +315,9 @@ def new(cls: type[CUDAError]) -> CUDAError: new_error_class = type(class_name, (CUDAError,), {'__new__': gen_new(err_val)}) new_error_class.__module__ = __name__ if err_val in CUDAError._errcode_to_string: - new_error_class.__doc__ = 'CUDA Error: {} Code: :data:`{}` ({}).'.format( - CUDAError._errcode_to_string[err_val], - err_name, - err_val, + new_error_class.__doc__ = ( + f'CUDA Error: {CUDAError._errcode_to_string[err_val]} ' + f'Code: :data:`{err_name}` ({err_val}).' ) else: new_error_class.__doc__ = f'CUDA Error with code :data:`{err_name}` ({err_val})' diff --git a/nvitop/api/libcudart.py b/nvitop/api/libcudart.py index 56238962..5ef7aa21 100644 --- a/nvitop/api/libcudart.py +++ b/nvitop/api/libcudart.py @@ -307,10 +307,9 @@ def __repr__(self) -> str: ) if self.value not in cudaError._errcode_to_name: cudaError._errcode_to_name[self.value] = cudaGetErrorName(self.value) - return '{} Code: {} ({}).'.format( - cudaError._errcode_to_string[self.value], - cudaError._errcode_to_name[self.value], - self.value, + return ( + f'{cudaError._errcode_to_string[self.value]} ' + f'Code: {cudaError._errcode_to_name[self.value]} ({self.value}).' ) except cudaError: return f'CUDA Error with code {self.value}.' @@ -367,10 +366,9 @@ def new(cls: type[cudaError]) -> cudaError: new_error_class = type(class_name, (cudaError,), {'__new__': gen_new(err_val)}) new_error_class.__module__ = __name__ if err_val in cudaError._errcode_to_string: - new_error_class.__doc__ = 'cudaError: {} Code: :data:`{}` ({}).'.format( - cudaError._errcode_to_string[err_val], - err_name, - err_val, + new_error_class.__doc__ = ( + f'cudaError: {cudaError._errcode_to_string[err_val]} ' + f'Code: :data:`{err_name}` ({err_val}).' ) else: new_error_class.__doc__ = f'CUDA Error with code :data:`{err_name}` ({err_val})' diff --git a/nvitop/api/process.py b/nvitop/api/process.py index d26b1296..ea086b76 100644 --- a/nvitop/api/process.py +++ b/nvitop/api/process.py @@ -535,7 +535,7 @@ def __init__( def __repr__(self) -> str: """Return a string representation of the GPU process.""" - return '{}(pid={}, gpu_memory={}, type={}, device={}, host={})'.format( + return '{}(pid={}, gpu_memory={}, type={}, device={}, host={})'.format( # noqa: UP032 self.__class__.__name__, self.pid, self.gpu_memory_human(), diff --git a/nvitop/gui/screens/metrics.py b/nvitop/gui/screens/metrics.py index 0588ddf7..92282505 100644 --- a/nvitop/gui/screens/metrics.py +++ b/nvitop/gui/screens/metrics.py @@ -148,7 +148,7 @@ def format_max_cpu_percent(value): def format_host_memory(value): if value is NA: return f'HOST-MEM: {value}' - return 'HOST-MEM: {} ({:.1f}%)'.format( + return 'HOST-MEM: {} ({:.1f}%)'.format( # noqa: UP032 bytes2human(value), round(100.0 * value / total_host_memory, 1), ) @@ -156,7 +156,7 @@ def format_host_memory(value): def format_max_host_memory(value): if value is NA: return f'MAX HOST-MEM: {value}' - return 'MAX HOST-MEM: {} ({:.1f}%) / {}'.format( + return 'MAX HOST-MEM: {} ({:.1f}%) / {}'.format( # noqa: UP032 bytes2human(value), round(100.0 * value / total_host_memory, 1), total_host_memory_human, @@ -164,7 +164,7 @@ def format_max_host_memory(value): def format_gpu_memory(value): if value is not NA and total_gpu_memory is not NA: - return 'GPU-MEM: {} ({:.1f}%)'.format( + return 'GPU-MEM: {} ({:.1f}%)'.format( # noqa: UP032 bytes2human(value), round(100.0 * value / total_gpu_memory, 1), ) @@ -172,7 +172,7 @@ def format_gpu_memory(value): def format_max_gpu_memory(value): if value is not NA and total_gpu_memory is not NA: - return 'MAX GPU-MEM: {} ({:.1f}%) / {}'.format( + return 'MAX GPU-MEM: {} ({:.1f}%) / {}'.format( # noqa: UP032 bytes2human(value), round(100.0 * value / total_gpu_memory, 1), total_gpu_memory_human, From c2f7af490145c3effafaf856e6b9976eab466ca4 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Tue, 12 Mar 2024 13:23:03 +0000 Subject: [PATCH 2/3] docs(.readthedocs.yaml): update read the docs config --- .readthedocs.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 047a70a5..fdf5d40f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -7,9 +7,9 @@ version: 2 # Set the version of Python and other tools you might need build: - os: ubuntu-22.04 + os: ubuntu-lts-latest tools: - python: "3.8" + python: "3" jobs: post_install: - bash docs/source/fix-psutil-docstring.sh From 201caef035715a26d79f20b631d53cb68146f004 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Sun, 24 Mar 2024 15:11:00 +0000 Subject: [PATCH 3/3] docs(.readthedocs.yaml): update read the docs config --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index fdf5d40f..afa2dab6 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 build: os: ubuntu-lts-latest tools: - python: "3" + python: "3.8" jobs: post_install: - bash docs/source/fix-psutil-docstring.sh