From 7cb90e5de7404836324230d99f210812a4f0f545 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Sun, 24 Jul 2022 21:55:33 +0800 Subject: [PATCH] style: update pylint magic comments Signed-off-by: Xuehai Pan --- nvitop/core/collector.py | 2 +- nvitop/core/device.py | 5 ++--- nvitop/core/libcuda.py | 5 +++-- nvitop/core/libnvml.py | 15 ++++++++++----- nvitop/core/process.py | 10 +++++----- nvitop/gui/library/history.py | 4 ++-- nvitop/gui/screens/main/__init__.py | 2 +- nvitop/gui/screens/main/device.py | 2 +- nvitop/gui/top.py | 2 +- nvitop/select.py | 2 +- 10 files changed, 27 insertions(+), 22 deletions(-) diff --git a/nvitop/core/collector.py b/nvitop/core/collector.py index d95d748..1f948ba 100644 --- a/nvitop/core/collector.py +++ b/nvitop/core/collector.py @@ -481,7 +481,7 @@ class ResourceMetricCollector: # pylint: disable=too-many-instance-attributes def __del__(self) -> None: self._daemon_running.clear() - # pylint: disable=missing-function-docstring,too-many-branches,too-many-locals,too-many-statements + # pylint: disable-next=missing-function-docstring,too-many-branches,too-many-locals,too-many-statements def take_snapshots(self) -> SnapshotResult: if len(self.root_pids) > 0: all_gpu_processes = [] diff --git a/nvitop/core/device.py b/nvitop/core/device.py index 3bce9ac..49fcf47 100644 --- a/nvitop/core/device.py +++ b/nvitop/core/device.py @@ -378,10 +378,9 @@ class Device: # pylint: disable=too-many-instance-attributes,too-many-public-me return Device._parse_cuda_visible_devices(cuda_visible_devices) - # pylint: disable=too-many-branches @staticmethod @ttl_cache(ttl=300.0) - def _parse_cuda_visible_devices( + def _parse_cuda_visible_devices( # pylint: disable=too-many-branches cuda_visible_devices: Optional[str] = None, ) -> Union[List['PhysicalDevice'], List['MigDevice']]: """The underlining implementation for :meth:`parse_cuda_visible_devices`. The result will be cached.""" @@ -1831,7 +1830,7 @@ class MigDevice(Device): # pylint: disable=too-many-instance-attributes return list(map(cls, indices)) - # pylint: disable=super-init-not-called + # pylint: disable-next=super-init-not-called def __init__( self, index: Optional[Union[Tuple[int, int], str]] = None, *, uuid: Optional[str] = None ) -> None: diff --git a/nvitop/core/libcuda.py b/nvitop/core/libcuda.py index 0428e42..4ada9f2 100644 --- a/nvitop/core/libcuda.py +++ b/nvitop/core/libcuda.py @@ -15,7 +15,7 @@ from typing import Tuple as _Tuple from typing import Type as _Type -# pylint: disable=missing-class-docstring,too-few-public-methods +# pylint: disable-next=missing-class-docstring,too-few-public-methods class struct_c_CUdevice_t(_ctypes.Structure): pass # opaque handle @@ -194,6 +194,7 @@ CUDA_ERROR_EXTERNAL_DEVICE = 911 """This indicates that an async error has occurred in a device outside of CUDA. If CUDA was waiting for an external device's signal before consuming shared data, the external device signaled an error indicating that the data is not valid for consumption. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched.""" CUDA_ERROR_UNKNOWN = 999 """This indicates that an unknown internal error has occurred.""" +# pylint: enable=line-too-long ## Error Checking ## @@ -218,7 +219,7 @@ class CUDAError(Exception): """Maps value to a proper subclass of :class:`CUDAError`.""" if cls is CUDAError: - # pylint: disable=self-cls-assignment + # pylint: disable-next=self-cls-assignment cls = CUDAError._value_class_mapping.get(value, cls) obj = Exception.__new__(cls) obj.value = value diff --git a/nvitop/core/libnvml.py b/nvitop/core/libnvml.py index b79851c..f189514 100644 --- a/nvitop/core/libnvml.py +++ b/nvitop/core/libnvml.py @@ -139,12 +139,17 @@ del ( ) # 5. Add explicit references to appease linters +# pylint: disable=no-member c_nvmlDevice_t = _pynvml.c_nvmlDevice_t -NVMLError_LibraryNotFound = _pynvml.NVMLError_LibraryNotFound # pylint: disable=no-member -NVMLError_FunctionNotFound = _pynvml.NVMLError_FunctionNotFound # pylint: disable=no-member -NVMLError_NotSupported = _pynvml.NVMLError_NotSupported # pylint: disable=no-member -NVMLError_NotFound = _pynvml.NVMLError_NotFound # pylint: disable=no-member -NVMLError_GpuIsLost = _pynvml.NVMLError_GpuIsLost # pylint: disable=no-member +NVMLError_FunctionNotFound = _pynvml.NVMLError_FunctionNotFound +NVMLError_GpuIsLost = _pynvml.NVMLError_GpuIsLost +NVMLError_InvalidArgument = _pynvml.NVMLError_InvalidArgument +NVMLError_LibraryNotFound = _pynvml.NVMLError_LibraryNotFound +NVMLError_NoPermission = _pynvml.NVMLError_NoPermission +NVMLError_NotFound = _pynvml.NVMLError_NotFound +NVMLError_NotSupported = _pynvml.NVMLError_NotSupported +NVMLError_Unknown = _pynvml.NVMLError_Unknown +# pylint: enable=no-member # New members in `libnvml` ############################################################################################# diff --git a/nvitop/core/process.py b/nvitop/core/process.py index a3ab4b7..13d8d7c 100644 --- a/nvitop/core/process.py +++ b/nvitop/core/process.py @@ -200,7 +200,7 @@ class HostProcess(host.Process, metaclass=ABCMeta): return instance - # pylint: disable=unused-argument,super-init-not-called + # pylint: disable-next=unused-argument,super-init-not-called def __init__(self, pid: Optional[int] = None) -> None: pass @@ -441,7 +441,7 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi INSTANCE_LOCK = threading.RLock() INSTANCES = WeakValueDictionary() - # pylint: disable=too-many-arguments,unused-argument + # pylint: disable-next=too-many-arguments,unused-argument def __new__( cls, pid: int, @@ -478,7 +478,7 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi return instance - # pylint: disable=too-many-arguments,unused-argument + # pylint: disable-next=too-many-arguments,unused-argument def __init__( self, pid: int, @@ -630,10 +630,10 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi return self._gpu_decoder_utilization - # pylint: disable=attribute-defined-outside-init def set_gpu_memory(self, value: Union[int, NaType]) -> None: """Sets the used GPU memory in bytes.""" + # pylint: disable=attribute-defined-outside-init self._gpu_memory = memory_used = value self._gpu_memory_human = bytes2human(self.gpu_memory()) memory_total = self.device.memory_total() @@ -642,7 +642,6 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi gpu_memory_percent = round(100.0 * memory_used / memory_total, 1) self._gpu_memory_percent = gpu_memory_percent - # pylint: disable=attribute-defined-outside-init def set_gpu_utilization( self, gpu_sm_utilization: Optional[int] = None, @@ -652,6 +651,7 @@ class GpuProcess: # pylint: disable=too-many-instance-attributes,too-many-publi ) -> None: """Sets the GPU utilization rates.""" + # pylint: disable=attribute-defined-outside-init if gpu_sm_utilization is not None: self._gpu_sm_utilization = gpu_sm_utilization if gpu_memory_utilization is not None: diff --git a/nvitop/gui/library/history.py b/nvitop/gui/library/history.py index 1bf868e..42fb2ea 100644 --- a/nvitop/gui/library/history.py +++ b/nvitop/gui/library/history.py @@ -49,7 +49,7 @@ def grouped(iterable, size, fillvalue=None): class HistoryGraph: # pylint: disable=too-many-instance-attributes MAX_WIDTH = 1024 - # pylint: disable=too-many-arguments + # pylint: disable-next=too-many-arguments def __init__( self, upperbound, @@ -254,7 +254,7 @@ class HistoryGraph: # pylint: disable=too-many-instance-attributes class BufferedHistoryGraph(HistoryGraph): - # pylint: disable=too-many-arguments + # pylint: disable-next=too-many-arguments def __init__( self, upperbound, diff --git a/nvitop/gui/screens/main/__init__.py b/nvitop/gui/screens/main/__init__.py index 3ac3c47..3f9b89f 100644 --- a/nvitop/gui/screens/main/__init__.py +++ b/nvitop/gui/screens/main/__init__.py @@ -19,7 +19,7 @@ class BreakLoop(Exception): class MainScreen(DisplayableContainer): # pylint: disable=too-many-instance-attributes NAME = 'main' - # pylint: disable=redefined-builtin,too-many-arguments,too-many-locals,too-many-statements + # pylint: disable-next=redefined-builtin,too-many-arguments,too-many-locals,too-many-statements def __init__(self, devices, filters, ascii, mode, win, root): super().__init__(win, root) diff --git a/nvitop/gui/screens/main/device.py b/nvitop/gui/screens/main/device.py index ec2ad86..241f851 100644 --- a/nvitop/gui/screens/main/device.py +++ b/nvitop/gui/screens/main/device.py @@ -392,7 +392,7 @@ class DevicePanel(Displayable): # pylint: disable=too-many-instance-attributes def colorize(s): if len(s) > 0: - # pylint: disable=cell-var-from-loop + # pylint: disable-next=cell-var-from-loop return colored(s, device.display_color) return '' diff --git a/nvitop/gui/top.py b/nvitop/gui/top.py index f83e86d..1adcdb9 100644 --- a/nvitop/gui/top.py +++ b/nvitop/gui/top.py @@ -12,7 +12,7 @@ from nvitop.gui.screens import BreakLoop, EnvironScreen, HelpScreen, MainScreen, class Top(DisplayableContainer): # pylint: disable=too-many-instance-attributes - # pylint: disable=too-many-arguments + # pylint: disable-next=too-many-arguments def __init__( self, devices, diff --git a/nvitop/select.py b/nvitop/select.py index e7846a5..5802ea1 100644 --- a/nvitop/select.py +++ b/nvitop/select.py @@ -54,7 +54,7 @@ from nvitop.version import __version__ TTY = sys.stdout.isatty() -# pylint: disable=too-many-branches,too-many-statements,too-many-locals +# pylint: disable-next=too-many-branches,too-many-statements,too-many-locals def select_devices( devices: Iterable[Device] = None, *,