mirror of
https://github.com/nicolargo/glances.git
synced 2024-08-17 00:10:48 +03:00
chg: ruff - flake8-comprehensions
This commit is contained in:
parent
108ffcdfb6
commit
28e7e5b74a
@ -115,7 +115,7 @@ class Export(GlancesExport):
|
||||
sensor_values = dict(zip(columns, points))
|
||||
|
||||
# Build the value to output
|
||||
output_value = dict()
|
||||
output_value = {}
|
||||
for key in sensor_values:
|
||||
split_key = key.split('.')
|
||||
|
||||
@ -123,7 +123,7 @@ class Export(GlancesExport):
|
||||
current_level = output_value
|
||||
for depth in range(len(split_key) - 1):
|
||||
if split_key[depth] not in current_level:
|
||||
current_level[split_key[depth]] = dict()
|
||||
current_level[split_key[depth]] = {}
|
||||
current_level = current_level[split_key[depth]]
|
||||
|
||||
# Add the value
|
||||
|
@ -299,7 +299,7 @@ class PluginModel(GlancesPluginModel):
|
||||
show_pod_name = True
|
||||
self.views['show_pod_name'] = show_pod_name
|
||||
show_engine_name = False
|
||||
if len(set(ct["engine"] for ct in self.stats)) > 1:
|
||||
if len({ct["engine"] for ct in self.stats}) > 1:
|
||||
show_engine_name = True
|
||||
self.views['show_engine_name'] = show_engine_name
|
||||
|
||||
|
@ -267,7 +267,7 @@ class DockerContainersExtension:
|
||||
self.stats_fetchers[container.id] = DockerStatsFetcher(container)
|
||||
|
||||
# Stop threads for non-existing containers
|
||||
absent_containers = set(iterkeys(self.stats_fetchers)) - set(c.id for c in containers)
|
||||
absent_containers = set(iterkeys(self.stats_fetchers)) - {c.id for c in containers}
|
||||
for container_id in absent_containers:
|
||||
# Stop the StatsFetcher
|
||||
logger.debug(f"{self.ext_name} plugin - Stop thread for old container {container_id[:12]}")
|
||||
|
@ -278,7 +278,7 @@ class PodmanContainersExtension:
|
||||
self.container_stats_fetchers[container.id] = PodmanContainerStatsFetcher(container)
|
||||
|
||||
# Stop threads for non-existing containers
|
||||
absent_containers = set(iterkeys(self.container_stats_fetchers)) - set(c.id for c in containers)
|
||||
absent_containers = set(iterkeys(self.container_stats_fetchers)) - {c.id for c in containers}
|
||||
for container_id in absent_containers:
|
||||
# Stop the StatsFetcher
|
||||
logger.debug(f"{self.ext_name} plugin - Stop thread for old container {container_id[:12]}")
|
||||
|
@ -188,7 +188,7 @@ class PluginModel(GlancesPluginModel):
|
||||
# Disk list (sorted by name)
|
||||
for i in self.sorted_stats():
|
||||
# Hide stats if never be different from 0 (issue #1787)
|
||||
if all([self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields]):
|
||||
if all(self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields):
|
||||
continue
|
||||
# Is there an alias for the disk name ?
|
||||
disk_name = i['alias'] if 'alias' in i else i['disk_name']
|
||||
|
@ -139,7 +139,7 @@ class PluginModel(GlancesPluginModel):
|
||||
logger.debug("Plugin - fs: PsUtil extended fetch failed")
|
||||
else:
|
||||
# Discard duplicates (#2299) and add entries matching allowed fs types
|
||||
tracked_mnt_points = set(f.mountpoint for f in fs_stat)
|
||||
tracked_mnt_points = {f.mountpoint for f in fs_stat}
|
||||
for f in all_mounted_fs:
|
||||
if (
|
||||
any(f.fstype.find(fs_type) >= 0 for fs_type in allowed_fs_types)
|
||||
|
@ -64,7 +64,7 @@ class AmdGPU:
|
||||
stats = []
|
||||
|
||||
for index, device in enumerate(self.device_folders):
|
||||
device_stats = dict()
|
||||
device_stats = {}
|
||||
# Dictionary key is the GPU_ID
|
||||
device_stats['key'] = 'gpu_id'
|
||||
# GPU id (for multiple GPU, start at 0)
|
||||
|
@ -49,7 +49,7 @@ class NvidiaGPU:
|
||||
stats = []
|
||||
|
||||
for index, device_handle in enumerate(self.device_handles):
|
||||
device_stats = dict()
|
||||
device_stats = {}
|
||||
# Dictionary key is the GPU_ID
|
||||
device_stats['key'] = 'gpu_id'
|
||||
# GPU id (for multiple GPU, start at 0)
|
||||
|
@ -259,7 +259,7 @@ class PluginModel(GlancesPluginModel):
|
||||
if ('is_up' in i) and (i['is_up'] is False):
|
||||
continue
|
||||
# Hide stats if never be different from 0 (issue #1787)
|
||||
if all([self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields]):
|
||||
if all(self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields):
|
||||
continue
|
||||
# Format stats
|
||||
# Is there an alias for the interface name ?
|
||||
|
@ -93,7 +93,7 @@ class GlancesPluginModel:
|
||||
self.stats_history = self.init_stats_history()
|
||||
|
||||
# Init the limits (configuration keys) dictionary
|
||||
self._limits = dict()
|
||||
self._limits = {}
|
||||
if config is not None:
|
||||
logger.debug(f'Load section {self.plugin_name} in {config.config_file_paths()}')
|
||||
self.load_limits(config=config)
|
||||
@ -105,7 +105,7 @@ class GlancesPluginModel:
|
||||
self.actions = GlancesActions(args=args)
|
||||
|
||||
# Init the views
|
||||
self.views = dict()
|
||||
self.views = {}
|
||||
|
||||
# Hide stats if all the hide_zero_fields has never been != 0
|
||||
# Default is False, always display stats
|
||||
@ -284,10 +284,8 @@ class GlancesPluginModel:
|
||||
return sorted(
|
||||
self.stats,
|
||||
key=lambda stat: tuple(
|
||||
map(
|
||||
lambda part: int(part) if part.isdigit() else part.lower(),
|
||||
re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key]),
|
||||
)
|
||||
int(part) if part.isdigit() else part.lower()
|
||||
for part in re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key])
|
||||
),
|
||||
)
|
||||
except TypeError:
|
||||
@ -295,7 +293,7 @@ class GlancesPluginModel:
|
||||
return sorted(
|
||||
self.stats,
|
||||
key=lambda stat: tuple(
|
||||
map(lambda part: part.lower(), re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key]))
|
||||
part.lower() for part in re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key])
|
||||
),
|
||||
)
|
||||
|
||||
@ -453,7 +451,7 @@ class GlancesPluginModel:
|
||||
if isinstance(self.get_raw(), list) and self.get_raw() is not None and self.get_key() is not None:
|
||||
# Stats are stored in a list of dict (ex: NETWORK, FS...)
|
||||
for i in self.get_raw():
|
||||
if any([i[f] for f in self.hide_zero_fields]):
|
||||
if any(i[f] for f in self.hide_zero_fields):
|
||||
for f in self.hide_zero_fields:
|
||||
self.views[i[self.get_key()]][f]['_zero'] = self.views[i[self.get_key()]][f]['hidden']
|
||||
for f in self.hide_zero_fields:
|
||||
@ -465,7 +463,7 @@ class GlancesPluginModel:
|
||||
#
|
||||
# Stats are stored in a dict (ex: CPU, LOAD...)
|
||||
for key in listkeys(self.get_raw()):
|
||||
if any([self.get_raw()[f] for f in self.hide_zero_fields]):
|
||||
if any(self.get_raw()[f] for f in self.hide_zero_fields):
|
||||
for f in self.hide_zero_fields:
|
||||
self.views[f]['_zero'] = self.views[f]['hidden']
|
||||
for f in self.hide_zero_fields:
|
||||
@ -530,7 +528,7 @@ class GlancesPluginModel:
|
||||
|
||||
def reset_views(self):
|
||||
"""Reset the views to input_views."""
|
||||
self.views = dict()
|
||||
self.views = {}
|
||||
|
||||
def get_views(self, item=None, key=None, option=None):
|
||||
"""Return the views object.
|
||||
@ -888,7 +886,7 @@ class GlancesPluginModel:
|
||||
def read_alias(self):
|
||||
if self.plugin_name + '_' + 'alias' in self._limits:
|
||||
return {i.split(':')[0].lower(): i.split(':')[1] for i in self._limits[self.plugin_name + '_' + 'alias']}
|
||||
return dict()
|
||||
return {}
|
||||
|
||||
def has_alias(self, header):
|
||||
"""Return the alias name for the relative header it it exists otherwise None."""
|
||||
|
@ -179,7 +179,7 @@ class PluginModel(GlancesPluginModel):
|
||||
return ret
|
||||
|
||||
# Define the data: Bar (default behavior) or Sparkline
|
||||
data = dict()
|
||||
data = {}
|
||||
for key in self.stats_list:
|
||||
if self.args.sparkline and self.history_enable() and not self.args.client:
|
||||
data[key] = Sparkline(max_width)
|
||||
|
@ -233,7 +233,7 @@ class GlancesStats:
|
||||
"""
|
||||
if enable:
|
||||
return [p for p in self._plugins if self._plugins[p].is_enabled()]
|
||||
return [p for p in self._plugins]
|
||||
return list(self._plugins)
|
||||
|
||||
def getExportsList(self, enable=True):
|
||||
"""Return the exports list.
|
||||
@ -244,8 +244,8 @@ class GlancesStats:
|
||||
:return: list of export module names
|
||||
"""
|
||||
if enable:
|
||||
return [e for e in self._exports]
|
||||
return [e for e in self._exports_all]
|
||||
return list(self._exports)
|
||||
return list(self._exports_all)
|
||||
|
||||
def load_limits(self, config=None):
|
||||
"""Load the stats limits (except the one in the exclude list)."""
|
||||
|
@ -20,7 +20,7 @@ select = [
|
||||
# "N", # pep8-naming
|
||||
"W", # pycodestyle
|
||||
"UP", # pyupgrde
|
||||
# "C4", # flake8-comprehensions
|
||||
"C4", # flake8-comprehensions
|
||||
"RET", # flake8-return
|
||||
# "FBT", # flake8-boolean-trap
|
||||
# "RUF", # Ruff-specific rules
|
||||
|
@ -74,10 +74,8 @@ class TestGlances(unittest.TestCase):
|
||||
self.assertEqual(plugin_instance.get_key(), None)
|
||||
self.assertTrue(
|
||||
all(
|
||||
[
|
||||
f in [h['name'] for h in plugin_instance.items_history_list]
|
||||
for f in plugin_instance.get_raw_history()
|
||||
]
|
||||
f in [h['name'] for h in plugin_instance.items_history_list]
|
||||
for f in plugin_instance.get_raw_history()
|
||||
)
|
||||
)
|
||||
elif plugin_instance.history_enable() and isinstance(plugin_instance.get_raw(), list):
|
||||
|
Loading…
Reference in New Issue
Block a user