kenenet 0.4.8__py3-none-any.whl → 0.4.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kenenet/__init__.py +46 -28
- {kenenet-0.4.8.dist-info → kenenet-0.4.9.dist-info}/METADATA +1 -1
- kenenet-0.4.9.dist-info/RECORD +5 -0
- kenenet-0.4.8.dist-info/RECORD +0 -5
- {kenenet-0.4.8.dist-info → kenenet-0.4.9.dist-info}/WHEEL +0 -0
- {kenenet-0.4.8.dist-info → kenenet-0.4.9.dist-info}/top_level.txt +0 -0
    
        kenenet/__init__.py
    CHANGED
    
    | @@ -49,7 +49,7 @@ def timer(clock=1): | |
| 49 49 | 
             
                    timings[clock] = time.time()
         | 
| 50 50 |  | 
| 51 51 |  | 
| 52 | 
            -
            class  | 
| 52 | 
            +
            class Config:
         | 
| 53 53 | 
             
                EXCLUDED_NAMES = {'Config', 'VariableTracker', 'track_variables', 'stop_tracking',
         | 
| 54 54 | 
             
                                  'track_frame', 'sys', 'inspect', 'types', 'datetime',
         | 
| 55 55 | 
             
                                  'self', 'cls', 'args', 'kwargs', '__class__'}
         | 
| @@ -57,66 +57,82 @@ class _Config: | |
| 57 57 | 
             
                SHOW_TIMESTAMPS = True
         | 
| 58 58 | 
             
                EXCLUDE_INTERNALS = True
         | 
| 59 59 |  | 
| 60 | 
            -
             | 
| 60 | 
            +
             | 
| 61 | 
            +
            class VariableTracker:
         | 
| 61 62 | 
             
                _instance = None
         | 
| 63 | 
            +
                
         | 
| 62 64 | 
             
                @classmethod
         | 
| 63 | 
            -
                def  | 
| 64 | 
            -
                    if cls._instance is None: cls._instance =  | 
| 65 | 
            +
                def get_instance(cls):
         | 
| 66 | 
            +
                    if cls._instance is None: cls._instance = VariableTracker()
         | 
| 65 67 | 
             
                    return cls._instance
         | 
| 68 | 
            +
                
         | 
| 66 69 | 
             
                def __init__(self):
         | 
| 67 70 | 
             
                    self.active = False
         | 
| 68 71 | 
             
                    self.tracked_module = None
         | 
| 69 72 | 
             
                    self.frame_locals = {}
         | 
| 70 73 | 
             
                    self.global_vars = {}
         | 
| 74 | 
            +
                
         | 
| 71 75 | 
             
                def fmt(self, v):
         | 
| 72 | 
            -
                    try: | 
| 73 | 
            -
             | 
| 76 | 
            +
                    try:
         | 
| 77 | 
            +
                        return repr(v)
         | 
| 78 | 
            +
                    except:
         | 
| 79 | 
            +
                        return f"<{type(v).__name__} object>"
         | 
| 80 | 
            +
                
         | 
| 74 81 | 
             
                def print_change(self, name, old, new, scope="Global"):
         | 
| 75 | 
            -
                    ts = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if  | 
| 82 | 
            +
                    ts = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if Config.SHOW_TIMESTAMPS else ""
         | 
| 76 83 | 
             
                    print(f"{ts}{scope} '{name}' changed from {self.fmt(old)} to {self.fmt(new)}")
         | 
| 84 | 
            +
                
         | 
| 77 85 | 
             
                def _should_track_name(self, n):
         | 
| 78 | 
            -
                    return not (n.startswith('_') and n not in ('__name__','__file__')) and n not in  | 
| 86 | 
            +
                    return not (n.startswith('_') and n not in ('__name__', '__file__')) and n not in Config.EXCLUDED_NAMES
         | 
| 87 | 
            +
                
         | 
| 79 88 | 
             
                def _should_track_frame(self, f):
         | 
| 80 | 
            -
                    if not  | 
| 89 | 
            +
                    if not Config.EXCLUDE_INTERNALS:
         | 
| 81 90 | 
             
                        return True
         | 
| 82 91 | 
             
                    fn = f.f_code.co_filename
         | 
| 83 | 
            -
                    if any(e in fn for e in  | 
| 92 | 
            +
                    if any(e in fn for e in Config.EXCLUDED_FILES):
         | 
| 84 93 | 
             
                        return False
         | 
| 85 94 | 
             
                    # Exclude known internal shutdown and list comprehension functions.
         | 
| 86 95 | 
             
                    if f.f_code.co_name in ('tracked_setattr', 'fmt', 'print_change', 'track_globals', 'get_instance',
         | 
| 87 | 
            -
             | 
| 96 | 
            +
                                            '_maintain_shutdown_locks', '_shutdown', '_stop', '<listcomp>'):
         | 
| 88 97 | 
             
                        return False
         | 
| 89 98 | 
             
                    return True
         | 
| 90 | 
            -
                 | 
| 99 | 
            +
                
         | 
| 100 | 
            +
                def start_tracking(self, mod_name):
         | 
| 91 101 | 
             
                    if self.active: return
         | 
| 92 102 | 
             
                    self.tracked_module = sys.modules[mod_name]
         | 
| 93 103 | 
             
                    for name, value in self.tracked_module.__dict__.items():
         | 
| 94 104 | 
             
                        if self._should_track_name(name):
         | 
| 95 105 | 
             
                            self.global_vars[name] = value
         | 
| 96 | 
            -
                    sys.settrace( | 
| 106 | 
            +
                    sys.settrace(track_frame)
         | 
| 97 107 | 
             
                    self.active = True
         | 
| 98 108 | 
             
                    print(f"Variable tracking started at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
         | 
| 99 | 
            -
                 | 
| 109 | 
            +
                
         | 
| 110 | 
            +
                def stop_tracking(self):
         | 
| 100 111 | 
             
                    if not self.active: return
         | 
| 101 112 | 
             
                    sys.settrace(None)
         | 
| 102 | 
            -
                    self.frame_locals.clear(); | 
| 113 | 
            +
                    self.frame_locals.clear();
         | 
| 114 | 
            +
                    self.global_vars.clear();
         | 
| 115 | 
            +
                    self.active = False
         | 
| 103 116 | 
             
                    print(f"Variable tracking stopped at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
         | 
| 104 117 |  | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 118 | 
            +
             | 
| 119 | 
            +
            def track_frame(frame, event, arg):
         | 
| 120 | 
            +
                tracker = VariableTracker.get_instance()
         | 
| 107 121 | 
             
                if not tracker.active or not tracker._should_track_frame(frame):
         | 
| 108 | 
            -
                    return  | 
| 122 | 
            +
                    return track_frame
         | 
| 109 123 | 
             
                if event != 'line':
         | 
| 110 | 
            -
                    return  | 
| 124 | 
            +
                    return track_frame
         | 
| 111 125 | 
             
                fid, is_mod = id(frame), frame.f_code.co_name == '<module>'
         | 
| 112 126 | 
             
                scope = "Global" if is_mod else f"Local in '{frame.f_code.co_name}'"
         | 
| 113 127 | 
             
                curr = {n: v for n, v in frame.f_locals.items() if tracker._should_track_name(n)}
         | 
| 114 128 | 
             
                if is_mod:
         | 
| 115 129 | 
             
                    for n, v in curr.items():
         | 
| 116 130 | 
             
                        if n not in tracker.global_vars:
         | 
| 117 | 
            -
                            tracker.print_change(n, None, v, scope); | 
| 131 | 
            +
                            tracker.print_change(n, None, v, scope);
         | 
| 132 | 
            +
                            tracker.global_vars[n] = v
         | 
| 118 133 | 
             
                        elif tracker.global_vars[n] != v:
         | 
| 119 | 
            -
                            tracker.print_change(n, tracker.global_vars[n], v, scope); | 
| 134 | 
            +
                            tracker.print_change(n, tracker.global_vars[n], v, scope);
         | 
| 135 | 
            +
                            tracker.global_vars[n] = v
         | 
| 120 136 | 
             
                else:
         | 
| 121 137 | 
             
                    if fid in tracker.frame_locals:
         | 
| 122 138 | 
             
                        for n, v in curr.items():
         | 
| @@ -130,17 +146,19 @@ def _track_frame(frame, event, arg): | |
| 130 146 | 
             
                    tracker.frame_locals[fid] = curr.copy()
         | 
| 131 147 | 
             
                if event == 'return' and not is_mod and fid in tracker.frame_locals:
         | 
| 132 148 | 
             
                    del tracker.frame_locals[fid]
         | 
| 133 | 
            -
                return  | 
| 149 | 
            +
                return track_frame
         | 
| 150 | 
            +
             | 
| 134 151 |  | 
| 135 | 
            -
            def  | 
| 152 | 
            +
            def track_variables():
         | 
| 136 153 | 
             
                cf = inspect.currentframe().f_back
         | 
| 137 154 | 
             
                mod = cf.f_globals['__name__']
         | 
| 138 | 
            -
                 | 
| 139 | 
            -
                cf.f_trace =  | 
| 140 | 
            -
                atexit.register( | 
| 155 | 
            +
                VariableTracker.get_instance().start_tracking(mod)
         | 
| 156 | 
            +
                cf.f_trace = track_frame
         | 
| 157 | 
            +
                atexit.register(stop_tracking)
         | 
| 158 | 
            +
             | 
| 141 159 |  | 
| 142 | 
            -
            def  | 
| 143 | 
            -
                 | 
| 160 | 
            +
            def stop_tracking():
         | 
| 161 | 
            +
                VariableTracker.get_instance().stop_tracking()
         | 
| 144 162 |  | 
| 145 163 | 
             
            def pp(msg='caca', subdir=None, pps=3):
         | 
| 146 164 | 
             
                import os, subprocess
         | 
| @@ -0,0 +1,5 @@ | |
| 1 | 
            +
            kenenet/__init__.py,sha256=lW5HqrpZo8FAxzi1WgSAr4Bo-aweG0S0H-RNQ2OlVn8,8644
         | 
| 2 | 
            +
            kenenet-0.4.9.dist-info/METADATA,sha256=jmh9EbdAn04ICRraoI8tOibDzbuencrMX2vzF0wnxh0,633
         | 
| 3 | 
            +
            kenenet-0.4.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
         | 
| 4 | 
            +
            kenenet-0.4.9.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
         | 
| 5 | 
            +
            kenenet-0.4.9.dist-info/RECORD,,
         | 
    
        kenenet-0.4.8.dist-info/RECORD
    DELETED
    
    | @@ -1,5 +0,0 @@ | |
| 1 | 
            -
            kenenet/__init__.py,sha256=rEHte4thzsgNXDblmcHHQlIEN38OpXalPZ28o9NGrgc,8518
         | 
| 2 | 
            -
            kenenet-0.4.8.dist-info/METADATA,sha256=vYSrchmnsYXGa6Wp9H4UmZZw8OBVaTO8R-fsZPxHxYM,633
         | 
| 3 | 
            -
            kenenet-0.4.8.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
         | 
| 4 | 
            -
            kenenet-0.4.8.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
         | 
| 5 | 
            -
            kenenet-0.4.8.dist-info/RECORD,,
         | 
| 
            File without changes
         | 
| 
            File without changes
         |