The start of a prototyping unit test for settings

25 views
Skip to first unread message

Edward K. Ream

unread,
Sep 5, 2019, 8:39:00 AM9/5/19
to leo-e...@googlegroups.com
The recent advances in dumping settings allows us to get a quick snapshot of the present settings:

d = c.config.settingsDictsources = list(set([
    gs
.path for gs in d.d.values() if gs.path is not None]))
       
# Yes, gs.path can be None.
# Compute the summary dict.
summary
= {}
for path in sources:
    inner_d
= g.TypedDict(
        name
=g.shortFileName(path),
        keyType
=str,
        valType
=g.GeneralSetting)
    summary
[path] = inner_d
   
for key, val in d.items():
       
if val.path == path:
            inner_d
[key] = val
# Show the summary dict.
if 1:
   
# Brief: good for quick checks.
    g
.printObj([str(z) for z in summary.values()])
else:
   
# Complete. Good for deep debugging.
    g
.printObj(summary)

For my test file, this prints:

[
   
'<TypedDict name:leoSettings.leo keys:str values:GeneralSetting len(keys): 433>',
   
'<TypedDict name:myLeoSettings.leo keys:str values:GeneralSetting len(keys): 83>',
   
'<TypedDict name:ekr.leo keys:str values:GeneralSetting len(keys): 77>',
   
'<TypedDict name:EKRWindowsDark.leo keys:str values:GeneralSetting len(keys): 114>'
]

This reveals the four sources of settings, and the number of settings defined in each. Unless I am mistaken, it does not tell which settings are overridden in each. Code in the settings branch suggests how to compute that.

So this is the start of the "before" snapshot of any proposed overhaul of the settings code.  Something similar will likely suffice for the "after" snapshot.

Edward

P.S.  Use the latest code, in any branch.  Doh!, g.TypedDict must have values and items methods!

EKR

Edward K. Ream

unread,
Sep 5, 2019, 9:09:28 AM9/5/19
to leo-editor
On Thursday, September 5, 2019 at 7:39:00 AM UTC-5, Edward K. Ream wrote:

> Unless I am mistaken, [the script] does not tell which settings are overridden in each.
> Code in the settings branch suggests how to compute that.

The c.config class should have a method that tells the actual source of each setting. Clearly, this is possible.  I'll do this next.

Work can be done in devel, because the new method is only for debugging.

Edward

Edward K. Ream

unread,
Sep 5, 2019, 9:20:01 AM9/5/19
to leo-editor
On Thursday, September 5, 2019 at 8:09:28 AM UTC-5, Edward K. Ream wrote:

> The c.config class should have a method that tells the actual source of each setting.

The new method, say, c.config.settingIsActiveInPath, would be used like this:

# Compute the summary dict.

is_active
= c.config.settingIsActiveInPath
summary
= {}

for path in sources:
    inner_d
= g.TypedDict(
        name
=g.shortFileName(path),
        keyType
=str,
        valType
=g.GeneralSetting)
    summary
[path] = inner_d
   
for key, val in d.items():

       
if val.path == path and is_active(val, path):
            inner_d
[key] = val

Edward

Edward K. Ream

unread,
Sep 5, 2019, 12:28:37 PM9/5/19
to leo-editor
On Thursday, September 5, 2019 at 8:20:01 AM UTC-5, Edward K. Ream wrote:

> The c.config class should have a method that tells the actual source of each setting.

Heh.  gs.path apparently already is the file that actually defines the setting.  So, c.config.settingIsActiveInPath is just:

def settingIsActiveInPath(self, gs, target_path):
   
"""Return True if settings file given by path actually defines the setting, gs."""
   
assert isinstance(gs, g.GeneralSetting), repr(gs)
   
return gs.path == target_path

That is, Leo's startup logic honors the precedence of settings and updates c.config.settingsDict accordingly.

We can regard c.config.settingIsActiveInPath as a template that might have to be updated in any grand reorg of Leo's startup code.

Edward
Reply all
Reply to author
Forward
0 new messages