mirror of
https://github.com/XuehaiPan/nvitop.git
synced 2026-05-15 14:15:55 -06:00
style: apply suggestions from pylint
Signed-off-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
This commit is contained in:
parent
6d431c88eb
commit
13f02f92c8
13 changed files with 42 additions and 50 deletions
10
.pylintrc
10
.pylintrc
|
|
@ -46,8 +46,8 @@ ignore=CVS,.vscode,.history
|
|||
|
||||
# Add files or directories matching the regular expressions patterns to the
|
||||
# ignore-list. The regex matches against paths and can be in Posix or Windows
|
||||
# format. Because '\' represents the directory delimiter on Windows systems, it
|
||||
# can't be used as an escape character.
|
||||
# format. Because '\\' represents the directory delimiter on Windows systems,
|
||||
# it can't be used as an escape character.
|
||||
ignore-paths=
|
||||
|
||||
# Files or directories matching the regular expression patterns are skipped.
|
||||
|
|
@ -270,7 +270,7 @@ exclude-protected=_asdict,
|
|||
valid-classmethod-first-arg=cls
|
||||
|
||||
# List of valid names for the first argument in a metaclass class method.
|
||||
valid-metaclass-classmethod-first-arg=cls
|
||||
valid-metaclass-classmethod-first-arg=mcs
|
||||
|
||||
|
||||
[DESIGN]
|
||||
|
|
@ -317,8 +317,8 @@ min-public-methods=2
|
|||
[EXCEPTIONS]
|
||||
|
||||
# Exceptions that will emit a warning when caught.
|
||||
overgeneral-exceptions=BaseException,
|
||||
Exception
|
||||
overgeneral-exceptions=builtins.BaseException,
|
||||
builtins.Exception
|
||||
|
||||
|
||||
[FORMAT]
|
||||
|
|
|
|||
|
|
@ -540,8 +540,8 @@ class Device: # pylint: disable=too-many-instance-attributes,too-many-public-me
|
|||
"""
|
||||
if (index, uuid, bus_id).count(None) != 2:
|
||||
raise TypeError(
|
||||
'Device(index=None, uuid=None, bus_id=None) takes 1 non-None arguments '
|
||||
'but (index, uuid, bus_id) = {!r} were given'.format((index, uuid, bus_id))
|
||||
f'Device(index=None, uuid=None, bus_id=None) takes 1 non-None arguments '
|
||||
f'but (index, uuid, bus_id) = {(index, uuid, bus_id)!r} were given'
|
||||
)
|
||||
|
||||
if cls is not Device:
|
||||
|
|
@ -784,15 +784,11 @@ class Device: # pylint: disable=too-many-instance-attributes,too-many-public-me
|
|||
if self._cuda_index is None:
|
||||
visible_device_indices = self.parse_cuda_visible_devices()
|
||||
try:
|
||||
cuda_index = visible_device_indices.index(self.index)
|
||||
self._cuda_index = visible_device_indices.index(self.index)
|
||||
except ValueError as ex:
|
||||
raise RuntimeError(
|
||||
'CUDA Error: Device(index={}) is not visible to CUDA applications'.format(
|
||||
self.index
|
||||
)
|
||||
f'CUDA Error: Device(index={self.index}) is not visible to CUDA applications'
|
||||
) from ex
|
||||
else:
|
||||
self._cuda_index = cuda_index
|
||||
|
||||
return self._cuda_index
|
||||
|
||||
|
|
|
|||
|
|
@ -302,10 +302,10 @@ def nvmlInitWithFlags(flags: int) -> None: # pylint: disable=function-redefined
|
|||
|
||||
LOGGER.critical(message)
|
||||
raise
|
||||
else:
|
||||
with __lock:
|
||||
__flags.append(flags)
|
||||
__initialized = True
|
||||
|
||||
with __lock:
|
||||
__flags.append(flags)
|
||||
__initialized = True
|
||||
|
||||
|
||||
def nvmlShutdown() -> None: # pylint: disable=function-redefined
|
||||
|
|
@ -416,10 +416,10 @@ def nvmlQuery(
|
|||
if ignore_errors:
|
||||
return default
|
||||
raise
|
||||
else:
|
||||
if isinstance(retval, bytes):
|
||||
retval = retval.decode('UTF-8')
|
||||
return retval
|
||||
|
||||
if isinstance(retval, bytes):
|
||||
retval = retval.decode('UTF-8')
|
||||
return retval
|
||||
|
||||
|
||||
def nvmlCheckReturn(
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ class GpuStatsLogger(Callback): # pylint: disable=too-many-instance-attributes
|
|||
self._devices = get_devices_by_logical_ids(gpu_ids, unique=True)
|
||||
except (libnvml.NVMLError, RuntimeError) as ex:
|
||||
raise ValueError(
|
||||
'Cannot use GpuStatsLogger callback because devices unavailable. '
|
||||
'Received: `gpus={}`'.format(gpu_ids)
|
||||
f'Cannot use GpuStatsLogger callback because devices unavailable. '
|
||||
f'Received: `gpus={gpu_ids}`'
|
||||
) from ex
|
||||
|
||||
self._memory_utilization = memory_utilization
|
||||
|
|
|
|||
|
|
@ -115,8 +115,8 @@ class GpuStatsLogger(Callback): # pylint: disable=too-many-instance-attributes
|
|||
|
||||
if trainer.strategy.root_device.type != 'cuda':
|
||||
raise MisconfigurationException(
|
||||
'You are using GpuStatsLogger but are not running on GPU. '
|
||||
'The root device type is {}.'.format(trainer.strategy.root_device.type)
|
||||
f'You are using GpuStatsLogger but are not running on GPU. '
|
||||
f'The root device type is {trainer.strategy.root_device.type}.'
|
||||
)
|
||||
|
||||
device_ids = trainer.data_parallel_device_ids
|
||||
|
|
@ -124,8 +124,8 @@ class GpuStatsLogger(Callback): # pylint: disable=too-many-instance-attributes
|
|||
self._devices = get_devices_by_logical_ids(device_ids, unique=True)
|
||||
except (libnvml.NVMLError, RuntimeError) as ex:
|
||||
raise ValueError(
|
||||
'Cannot use GpuStatsLogger callback because devices unavailable. '
|
||||
'Received: `gpus={}`'.format(device_ids)
|
||||
f'Cannot use GpuStatsLogger callback because devices unavailable. '
|
||||
f'Received: `gpus={device_ids}`'
|
||||
) from ex
|
||||
|
||||
def on_train_epoch_start(self, trainer, pl_module) -> None:
|
||||
|
|
|
|||
|
|
@ -172,8 +172,8 @@ def key_to_string(key):
|
|||
if key in range(33, 127):
|
||||
return chr(key)
|
||||
if key in REVERSED_SPECIAL_KEYS:
|
||||
return '<%s>' % REVERSED_SPECIAL_KEYS[key]
|
||||
return '<%s>' % str(key)
|
||||
return f'<{REVERSED_SPECIAL_KEYS[key]}>'
|
||||
return f'<{key}>'
|
||||
|
||||
|
||||
def construct_keybinding(keys):
|
||||
|
|
@ -201,7 +201,7 @@ def construct_keybinding(keys):
|
|||
continue
|
||||
if alt_key_on:
|
||||
try:
|
||||
strings.append('<%s>' % REVERSED_SPECIAL_KEYS[(ALT_KEY, key)])
|
||||
strings.append(f'<{REVERSED_SPECIAL_KEYS[(ALT_KEY, key)]}>')
|
||||
except KeyError:
|
||||
strings.extend(map(key_to_string, (ALT_KEY, key)))
|
||||
else:
|
||||
|
|
@ -276,7 +276,7 @@ class KeyMaps(dict):
|
|||
pointer = pointer[key]
|
||||
except KeyError as ex:
|
||||
raise KeyError(
|
||||
"Tried to copy the keybinding `%s', but it was not found." % source
|
||||
f'Tried to copy the keybinding `{source}`, but it was not found.'
|
||||
) from ex
|
||||
try:
|
||||
self.bind(context, target, copy.deepcopy(pointer))
|
||||
|
|
|
|||
|
|
@ -275,8 +275,7 @@ class CursesShortcuts:
|
|||
self.win.attrset(attr)
|
||||
except curses.error:
|
||||
return 0
|
||||
else:
|
||||
return attr
|
||||
return attr
|
||||
|
||||
def update_size(self, termsize=None):
|
||||
if termsize is None:
|
||||
|
|
|
|||
|
|
@ -277,6 +277,7 @@ def send_signal(signal, panel):
|
|||
processes = [process.ljust(maxlen) for process in processes]
|
||||
message = 'Send signal to the following processes?\n\n{}'.format(' '.join(processes))
|
||||
|
||||
# pylint: disable=use-dict-literal
|
||||
panel.root.messagebox = MessageBox(
|
||||
message=message,
|
||||
options=[
|
||||
|
|
@ -325,3 +326,4 @@ def send_signal(signal, panel):
|
|||
win=panel.win,
|
||||
root=panel.root,
|
||||
)
|
||||
# pylint: enable=use-dict-literal
|
||||
|
|
|
|||
|
|
@ -145,15 +145,13 @@ class EnvironScreen(Displayable): # pylint: disable=too-many-instance-attribute
|
|||
self.color_reset()
|
||||
|
||||
if isinstance(self.process, GpuProcess):
|
||||
process_type = 'GPU: {}'.format(
|
||||
self.process.type.replace('C', 'Compute').replace('G', 'Graphics')
|
||||
process_type = 'GPU: ' + self.process.type.replace('C', 'Compute').replace(
|
||||
'G', 'Graphics'
|
||||
)
|
||||
else:
|
||||
process_type = 'Host'
|
||||
header_prefix = WideString(
|
||||
'Environment of process {} ({}@{}): '.format(
|
||||
self.process.pid, self.username, process_type
|
||||
)
|
||||
f'Environment of process {self.process.pid} ({self.username}@{process_type}): '
|
||||
)
|
||||
offset = max(0, min(self.x_offset, len(self.command) + len(header_prefix) - self.width))
|
||||
header = str((header_prefix + self.command[offset:]).ljust(self.width)[: self.width])
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ class MainScreen(DisplayableContainer): # pylint: disable=too-many-instance-att
|
|||
sort_by(order=ProcessPanel.ORDERS[self.process_panel.order].next, reverse=False)
|
||||
|
||||
def order_reverse():
|
||||
sort_by(order=self.process_panel.order, reverse=(not self.process_panel.reverse))
|
||||
sort_by(order=self.process_panel.order, reverse=not self.process_panel.reverse)
|
||||
|
||||
keymaps = self.root.keymaps
|
||||
|
||||
|
|
|
|||
|
|
@ -138,9 +138,7 @@ class DevicePanel(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
if device.bar1_memory_percent >= 100:
|
||||
device.bar1_memory_percent_string = 'MAX'
|
||||
else:
|
||||
device.bar1_memory_percent_string = '{}%'.format(
|
||||
round(device.bar1_memory_percent)
|
||||
)
|
||||
device.bar1_memory_percent_string = f'{round(device.bar1_memory_percent)}%'
|
||||
else:
|
||||
device.name = cut_string(device.name, maxlen=18, padstr='..', align='right')
|
||||
device.current_driver_model = device.current_driver_model.replace('WDM', 'TCC')
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class HostPanel(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
baseline=0.0,
|
||||
upperbound=100.0,
|
||||
dynamic_bound=False,
|
||||
format=lambda x: ('GPU {} MEM: {}').format(device.display_index, percentage(x)),
|
||||
format=lambda x: f'GPU {device.display_index} MEM: {percentage(x)}',
|
||||
)(device.memory_percent)
|
||||
device.gpu_utilization = BufferedHistoryGraph(
|
||||
interval=1.0,
|
||||
|
|
@ -132,7 +132,7 @@ class HostPanel(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
baseline=0.0,
|
||||
upperbound=100.0,
|
||||
dynamic_bound=False,
|
||||
format=lambda x: ('GPU {} UTL: {}').format(device.display_index, percentage(x)),
|
||||
format=lambda x: f'GPU {device.display_index} UTL: {percentage(x)}',
|
||||
)(device.gpu_utilization)
|
||||
|
||||
for device in self.devices:
|
||||
|
|
@ -147,7 +147,7 @@ class HostPanel(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
baseline=0.0,
|
||||
upperbound=100.0,
|
||||
dynamic_bound=False,
|
||||
format=lambda x: ('{}GPU MEM: {}').format(prefix, percentage(x)),
|
||||
format=lambda x: f'{prefix}GPU MEM: {percentage(x)}',
|
||||
)
|
||||
self.average_gpu_utilization = BufferedHistoryGraph(
|
||||
interval=1.0,
|
||||
|
|
@ -157,7 +157,7 @@ class HostPanel(Displayable): # pylint: disable=too-many-instance-attributes
|
|||
baseline=0.0,
|
||||
upperbound=100.0,
|
||||
dynamic_bound=False,
|
||||
format=lambda x: ('{}GPU UTL: {}').format(prefix, percentage(x)),
|
||||
format=lambda x: f'{prefix}GPU UTL: {percentage(x)}',
|
||||
)
|
||||
|
||||
def take_snapshots(self):
|
||||
|
|
|
|||
|
|
@ -141,8 +141,8 @@ class UI(DisplayableContainer): # pylint: disable=too-many-instance-attributes
|
|||
return
|
||||
|
||||
n_term_lines, n_term_cols = self.termsize
|
||||
message = 'nvitop needs at least a width of 79 to render, the current width is {}.'.format(
|
||||
self.width
|
||||
message = (
|
||||
f'nvitop needs at least a width of 79 to render, the current width is {self.width}.'
|
||||
)
|
||||
words = iter(message.split())
|
||||
width = min(max(n_term_cols, 40), n_term_cols, 60) - 10
|
||||
|
|
@ -199,8 +199,7 @@ class UI(DisplayableContainer): # pylint: disable=too-many-instance-attributes
|
|||
event = MouseEvent(curses.getmouse())
|
||||
except curses.error:
|
||||
return
|
||||
else:
|
||||
super().click(event)
|
||||
super().click(event)
|
||||
|
||||
def handle_key(self, key):
|
||||
"""Handles key input"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue