Skip to content

Commit

Permalink
style: update pylint magic comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
  • Loading branch information
XuehaiPan committed Jul 24, 2022
1 parent 587e204 commit 7cb90e5
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion nvitop/core/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def collect(self) -> Dict[str, float]:
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 = []
Expand Down
5 changes: 2 additions & 3 deletions nvitop/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,9 @@ def parse_cuda_visible_devices(

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."""
Expand Down Expand Up @@ -1831,7 +1830,7 @@ def from_indices( # pylint: disable=signature-differs

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:
Expand Down
5 changes: 3 additions & 2 deletions nvitop/core/libcuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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

Expand Down Expand Up @@ -194,6 +194,7 @@ class struct_c_CUdevice_t(_ctypes.Structure):
"""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 ##
Expand All @@ -218,7 +219,7 @@ def __new__(cls, value: int) -> 'CUDAError':
"""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
Expand Down
15 changes: 10 additions & 5 deletions nvitop/core/libnvml.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,17 @@
)

# 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` #############################################################################################

Expand Down
10 changes: 5 additions & 5 deletions nvitop/core/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __new__(cls, pid: Optional[int] = None) -> 'HostProcess':

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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -478,7 +478,7 @@ def __new__(

return instance

# pylint: disable=too-many-arguments,unused-argument
# pylint: disable-next=too-many-arguments,unused-argument
def __init__(
self,
pid: int,
Expand Down Expand Up @@ -630,10 +630,10 @@ def gpu_decoder_utilization(self) -> Union[int, NaType]: # in percentage

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()
Expand All @@ -642,7 +642,6 @@ def set_gpu_memory(self, value: Union[int, NaType]) -> None:
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,
Expand All @@ -652,6 +651,7 @@ def set_gpu_utilization(
) -> 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:
Expand Down
4 changes: 2 additions & 2 deletions nvitop/gui/library/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -254,7 +254,7 @@ def wrapped(*args, **kwargs):


class BufferedHistoryGraph(HistoryGraph):
# pylint: disable=too-many-arguments
# pylint: disable-next=too-many-arguments
def __init__(
self,
upperbound,
Expand Down
2 changes: 1 addition & 1 deletion nvitop/gui/screens/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion nvitop/gui/screens/main/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def print(self): # pylint: disable=too-many-locals,too-many-branches

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 ''

Expand Down
2 changes: 1 addition & 1 deletion nvitop/gui/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class Top(DisplayableContainer): # pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments
# pylint: disable-next=too-many-arguments
def __init__(
self,
devices,
Expand Down
2 changes: 1 addition & 1 deletion nvitop/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
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,
*,
Expand Down

0 comments on commit 7cb90e5

Please sign in to comment.