Trim the comments and drop a test that guarded nothing

One rationale in one place instead of three, and the class attribute no longer
describes the per-key build that is gone. test_unknown_key_raises only exercised
dict lookup and passed unchanged on develop.
This commit is contained in:
dipetm committed 2026-08-07 15:29:24 +03:00
1 parent 397ec8dec6
commit e6f3145ef5
3 files changed
+9 -17

No files matched your search

+7 -9
View File
@@ -56,8 +56,8 @@ fields_unit_type = {
class GlancesPluginModel:
"""Main class for Glances plugin model."""
# Build the per-item views on demand instead of up front. Only worth it for plugins whose
# item count is large and unrelated to how many rows the UI shows.
# Defer building the views until something reads them. Worth it for a plugin holding far
# more items than the UI draws, whose own rendering does not consult them.
lazy_views = False
def __init__(self, args=None, config=None, items_history_list=None, stats_init_value={}, fields_description=None):
@@ -121,7 +121,7 @@ class GlancesPluginModel:
# Init the views
self.views = {}
# Stats whose views have not been built yet (see update_views)
# Set by update_views() when the build is deferred; consumed by get_views()
self._views_source = None
# Hide stats if all the hide_zero_fields has never been != 0
@@ -673,10 +673,8 @@ class GlancesPluginModel:
'splittable': False, >>> Is the stat can be cut (like process lon name)
'hidden': False} >>> Is the stats should be hidden in the UI
"""
# A lazy plugin holds far more items than the UI shows and nothing reads its views
# while drawing, so remember the stats and let get_views() do the work if it is ever
# asked for. hide_zero is excluded: it carries the hidden flag over from the previous
# views, which are gone by the time a deferred build runs.
# hide_zero is excluded: it carries the hidden flag over from the previous views,
# which a deferred build no longer has.
if self.lazy_views and not self.hide_zero and isinstance(self.get_raw(), list) and self.get_key() is not None:
self._views_source = self.get_raw()
self.views = {}
@@ -687,8 +685,8 @@ class GlancesPluginModel:
return self.views
def _build_views(self, raw):
"""Build the views for raw stats. Reads self.views, which still holds the previous
views at this point; hide_zero relies on that to keep a field hidden."""
"""self.views still holds the previous views here; hide_zero reads them to keep a
field hidden once it has been hidden."""
ret = {}
if raw is not None and isinstance(raw, list) and self.get_key() is not None:
+2 -2
View File
@@ -122,8 +122,8 @@ class ProcesslistPlugin(GlancesPluginModel):
stats is a list
"""
# The list holds every process on the machine while the UI shows a few dozen rows, and
# the curses output never reads the views at all. Build them on demand.
# Every process on the machine, against a few dozen rows on screen; msg_curse() builds its
# own decorations and never looks at the views.
lazy_views = True
# Default list of processes stats to be grabbed / displayed
-6
View File
@@ -46,12 +46,6 @@ def test_first_read_builds_the_views(plugin):
assert len(views) == 10
def test_unknown_key_raises(plugin):
plugin.update_views()
with pytest.raises(KeyError):
plugin.get_views(item=999999)
def test_second_read_reuses_the_built_views(plugin):
plugin.update_views()
first = plugin.get_views()