chore(pre-commit): update pre-commit hooks

This commit is contained in:
Xuehai Pan 2024-03-12 13:21:54 +00:00
parent 470245dc3d
commit a0387867fb
6 changed files with 20 additions and 24 deletions

View file

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

View file

@ -710,7 +710,7 @@ class Device: # pylint: disable=too-many-instance-attributes,too-many-public-me
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 @@ class CudaDevice(Device):
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,

View file

@ -259,10 +259,9 @@ class CUDAError(Exception):
)
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 _extract_cuda_errors_as_classes() -> None:
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})'

View file

@ -307,10 +307,9 @@ class cudaError(Exception):
)
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 _extract_cuda_errors_as_classes() -> None:
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})'

View file

@ -535,7 +535,7 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi
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(),

View file

@ -148,7 +148,7 @@ class ProcessMetricsScreen(Displayable): # pylint: disable=too-many-instance-at
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 @@ class ProcessMetricsScreen(Displayable): # pylint: disable=too-many-instance-at
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 @@ class ProcessMetricsScreen(Displayable): # pylint: disable=too-many-instance-at
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 @@ class ProcessMetricsScreen(Displayable): # pylint: disable=too-many-instance-at
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,