Coverage for /home/ubuntu/Documents/Research/mut_p6/sacred/sacred/config/config_summary.py: 73%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

37 statements  

1#!/usr/bin/env python 

2# coding=utf-8 

3 

4from sacred.utils import iter_prefixes, join_paths 

5 

6 

7class ConfigSummary(dict): 

8 def __init__( 

9 self, added=(), modified=(), typechanged=(), ignored_fallbacks=(), docs=() 

10 ): 

11 super().__init__() 

12 self.added = set(added) 

13 self.modified = set(modified) # TODO: test for this member 

14 self.typechanged = dict(typechanged) 

15 self.ignored_fallbacks = set(ignored_fallbacks) # TODO: test 

16 self.docs = dict(docs) 

17 self.ensure_coherence() 

18 

19 def update_from(self, config_mod, path=""): 

20 added = config_mod.added 

21 updated = config_mod.modified 

22 typechanged = config_mod.typechanged 

23 self.added &= {join_paths(path, a) for a in added} 

24 self.modified |= {join_paths(path, u) for u in updated} 

25 self.typechanged.update( 

26 {join_paths(path, k): v for k, v in typechanged.items()} 

27 ) 

28 self.ensure_coherence() 

29 for k, v in config_mod.docs.items(): 

30 if not self.docs.get(k, ""): 

31 self.docs[k] = v 

32 

33 def update_add(self, config_mod, path=""): 

34 added = config_mod.added 

35 updated = config_mod.modified 

36 typechanged = config_mod.typechanged 

37 self.added |= {join_paths(path, a) for a in added} 

38 self.modified |= {join_paths(path, u) for u in updated} 

39 self.typechanged.update( 

40 {join_paths(path, k): v for k, v in typechanged.items()} 

41 ) 

42 self.docs.update( 

43 { 

44 join_paths(path, k): v 

45 for k, v in config_mod.docs.items() 

46 if path == "" or k != "seed" 

47 } 

48 ) 

49 self.ensure_coherence() 

50 

51 def ensure_coherence(self): 

52 # make sure parent paths show up as updated appropriately 

53 self.modified |= {p for a in self.added for p in iter_prefixes(a)} 

54 self.modified |= {p for u in self.modified for p in iter_prefixes(u)} 

55 self.modified |= {p for t in self.typechanged for p in iter_prefixes(t)} 

56 

57 # make sure there is no overlap 

58 self.added -= set(self.typechanged.keys()) 

59 self.modified -= set(self.typechanged.keys()) 

60 self.modified -= self.added