kenenet 1.0.5__py3-none-any.whl → 1.0.8__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 +40 -27
- {kenenet-1.0.5.dist-info → kenenet-1.0.8.dist-info}/METADATA +1 -1
- kenenet-1.0.8.dist-info/RECORD +5 -0
- kenenet-1.0.5.dist-info/RECORD +0 -5
- {kenenet-1.0.5.dist-info → kenenet-1.0.8.dist-info}/WHEEL +0 -0
- {kenenet-1.0.5.dist-info → kenenet-1.0.8.dist-info}/top_level.txt +0 -0
kenenet/__init__.py
CHANGED
@@ -40,7 +40,7 @@ def get_pos(key='f10', kill=False):
|
|
40
40
|
if kill:
|
41
41
|
quick_print('killing process')
|
42
42
|
zhmiscellany.misc.die()
|
43
|
-
quick_print(f'Press {key} when ever you want the location')
|
43
|
+
quick_print(f'Press {key} when ever you want the location, automatically copies coords/rgb to clipboard')
|
44
44
|
frame = inspect.currentframe().f_back
|
45
45
|
lineno = frame.f_lineno
|
46
46
|
_get_pos(key, kill)
|
@@ -51,9 +51,9 @@ def timer(clock=1):
|
|
51
51
|
frame = inspect.currentframe().f_back
|
52
52
|
lineno = frame.f_lineno
|
53
53
|
if clock == 1:
|
54
|
-
quick_print(f'Timer took \033[97m{elapsed}\033[0m seconds', f'{
|
54
|
+
quick_print(f'Timer took \033[97m{elapsed}\033[0m seconds', f'{timings[clock][1]}-{lineno}')
|
55
55
|
else:
|
56
|
-
quick_print(f'Timer {clock} took \033[97m{elapsed}\033[0m seconds', f'{
|
56
|
+
quick_print(f'Timer {clock} took \033[97m{elapsed}\033[0m seconds', f'{timings[clock][1]}-{lineno}')
|
57
57
|
del timings[clock]
|
58
58
|
return elapsed
|
59
59
|
else:
|
@@ -286,13 +286,31 @@ _block_timings = defaultdict(float)
|
|
286
286
|
_current_context = None
|
287
287
|
_line_start_time = None
|
288
288
|
_stack = []
|
289
|
-
_ignore_line = {'frame = inspect.currentframe().f_back', 'filename = frame.f_code.co_filename', 'if _current_context is None:', 'sys.settrace(None)', 'Function: currentframe', 'return sys._getframe(1) if hasattr(sys, "_getframe") else None'
|
289
|
+
_ignore_line = {'frame = inspect.currentframe().f_back', 'filename = frame.f_code.co_filename', 'if _current_context is None:', 'sys.settrace(None)', 'Function: currentframe', 'return sys._getframe(1) if hasattr(sys, "_getframe") else None'}
|
290
290
|
_seen_lines = set() # Track lines we've already processed
|
291
291
|
_current_function = None
|
292
292
|
_function_lines = defaultdict(set) # Track which lines belong to which function
|
293
293
|
_site_packages_dirs = [] # List to store site-packages directories
|
294
294
|
|
295
|
+
# Patterns for generated code constructs to ignore
|
296
|
+
_ignore_function_patterns = {
|
297
|
+
'<dictcomp>',
|
298
|
+
'<lambda>',
|
299
|
+
'<setcomp>',
|
300
|
+
'<listcomp>',
|
301
|
+
'<genexpr>',
|
302
|
+
'<comprehension>',
|
303
|
+
'<module>'
|
304
|
+
}
|
305
|
+
|
295
306
|
# Initialize site-packages directories
|
307
|
+
import sys
|
308
|
+
import os
|
309
|
+
import inspect
|
310
|
+
import time
|
311
|
+
import re
|
312
|
+
import linecache
|
313
|
+
from collections import defaultdict
|
296
314
|
|
297
315
|
# Get site-packages directories from sys.path
|
298
316
|
for path in sys.path:
|
@@ -319,6 +337,10 @@ def _is_package_code(filename):
|
|
319
337
|
|
320
338
|
return False
|
321
339
|
|
340
|
+
def _is_generated_construct(func_name):
|
341
|
+
"""Check if the function name is a generated construct like <dictcomp>, <lambda>, etc."""
|
342
|
+
return any(pattern in func_name for pattern in _ignore_function_patterns)
|
343
|
+
|
322
344
|
|
323
345
|
def time_code(label=None):
|
324
346
|
global _current_context, _timings, _line_start_time, _block_timings, _stack, _ignore_line, _seen_lines, _current_function, _function_lines
|
@@ -337,17 +359,19 @@ def time_code(label=None):
|
|
337
359
|
_seen_lines.clear() # Reset seen lines
|
338
360
|
_function_lines.clear() # Reset function lines mapping
|
339
361
|
|
340
|
-
# Define the trace function
|
341
362
|
def trace_function(frame, event, arg):
|
342
363
|
global _line_start_time, _stack, _seen_lines, _current_function, _function_lines
|
343
364
|
|
344
|
-
# Skip tracking for package code
|
345
365
|
if _is_package_code(frame.f_code.co_filename):
|
346
366
|
return trace_function
|
347
367
|
|
348
|
-
# Track function calls and returns
|
349
368
|
if event == 'call':
|
350
369
|
func_name = frame.f_code.co_name
|
370
|
+
|
371
|
+
# Skip recording generated constructs
|
372
|
+
if _is_generated_construct(func_name):
|
373
|
+
return trace_function
|
374
|
+
|
351
375
|
if func_name != 'time_code':
|
352
376
|
_stack.append((func_name, time.time()))
|
353
377
|
_current_function = func_name # Track current function
|
@@ -356,10 +380,11 @@ def time_code(label=None):
|
|
356
380
|
elif event == 'return':
|
357
381
|
if _stack:
|
358
382
|
func_name, start_time = _stack.pop()
|
359
|
-
elapsed = time.time() - start_time
|
360
|
-
_block_timings[f"Function: {func_name}"] += elapsed
|
361
383
|
|
362
|
-
|
384
|
+
if not _is_generated_construct(func_name):
|
385
|
+
elapsed = time.time() - start_time
|
386
|
+
_block_timings[f"Function: {func_name}"] += elapsed
|
387
|
+
|
363
388
|
if _current_function == func_name and _stack:
|
364
389
|
_current_function = _stack[-1][0]
|
365
390
|
elif not _stack:
|
@@ -367,33 +392,28 @@ def time_code(label=None):
|
|
367
392
|
return None
|
368
393
|
|
369
394
|
elif event == 'line':
|
370
|
-
# Get current line information
|
371
395
|
lineno = frame.f_lineno
|
372
396
|
line_content = linecache.getline(frame.f_code.co_filename, lineno).strip()
|
373
397
|
line_id = f"{lineno}:{line_content}"
|
374
398
|
|
375
|
-
# Skip empty lines or comments
|
376
399
|
if not line_content or line_content.startswith('#'):
|
377
400
|
return trace_function
|
378
401
|
|
379
|
-
# Check if we should stop tracing
|
380
402
|
if "time_code" in line_content and _current_context is not None:
|
381
|
-
# This might be the ending call, let's continue execution
|
382
403
|
return trace_function
|
383
404
|
|
384
|
-
|
405
|
+
if _current_function and _is_generated_construct(_current_function):
|
406
|
+
return trace_function
|
407
|
+
|
385
408
|
current_time = time.time()
|
386
409
|
if _line_start_time is not None:
|
387
410
|
elapsed = current_time - _line_start_time
|
388
411
|
|
389
|
-
# Track relationship between current function and lines
|
390
412
|
if _current_function:
|
391
413
|
_function_lines[_current_function].add(line_id)
|
392
414
|
|
393
|
-
# For timing, we always record all executions to get accurate timing
|
394
415
|
_timings[_current_context].append((lineno, line_content, elapsed, line_id in _seen_lines))
|
395
416
|
|
396
|
-
# For loop timings, first check if it's a loop
|
397
417
|
if re.match(r'\s*(for|while)\s+', line_content):
|
398
418
|
loop_id = f"Loop at line {lineno}: {line_content[:40]}{'...' if len(line_content) > 40 else ''}"
|
399
419
|
_block_timings[loop_id] += elapsed
|
@@ -401,12 +421,10 @@ def time_code(label=None):
|
|
401
421
|
# Mark this line as seen
|
402
422
|
_seen_lines.add(line_id)
|
403
423
|
|
404
|
-
# Set new start time for next line
|
405
424
|
_line_start_time = current_time
|
406
425
|
|
407
426
|
return trace_function
|
408
427
|
|
409
|
-
# Start tracing
|
410
428
|
sys.settrace(trace_function)
|
411
429
|
|
412
430
|
else:
|
@@ -419,7 +437,6 @@ def time_code(label=None):
|
|
419
437
|
quick_print(f"No times recorded: {context}")
|
420
438
|
return
|
421
439
|
|
422
|
-
# Process timings to aggregate by line but only show first occurrence
|
423
440
|
aggregated_timings = defaultdict(float)
|
424
441
|
first_occurrences = {}
|
425
442
|
|
@@ -427,18 +444,15 @@ def time_code(label=None):
|
|
427
444
|
line_id = f"{lineno}:{line_content}"
|
428
445
|
aggregated_timings[line_id] += elapsed
|
429
446
|
|
430
|
-
# Store the first occurrence information
|
431
447
|
if line_id not in first_occurrences:
|
432
448
|
first_occurrences[line_id] = (lineno, line_content, elapsed)
|
433
449
|
|
434
|
-
# Create sorted list of first occurrences with total time
|
435
450
|
display_timings = [
|
436
451
|
(lineno, line_content, aggregated_timings[f"{lineno}:{line_content}"])
|
437
452
|
for lineno, line_content, _ in first_occurrences.values()
|
438
453
|
if line_content not in _ignore_line
|
439
454
|
]
|
440
455
|
|
441
|
-
# Sort by elapsed time (descending)
|
442
456
|
sorted_timings = sorted(display_timings, key=lambda x: x[2], reverse=True)
|
443
457
|
|
444
458
|
quick_print(f"\nTime spent on each line: {context}")
|
@@ -459,17 +473,16 @@ def time_code(label=None):
|
|
459
473
|
quick_print(f"{'Chunks':^40} | {'Time':>12} | {'% of Time Spent':>10}")
|
460
474
|
quick_print("-" * 80)
|
461
475
|
|
462
|
-
# Sort block timings by time
|
463
476
|
sorted_blocks = sorted(_block_timings.items(), key=lambda x: x[1], reverse=True)
|
464
477
|
|
465
478
|
for block, elapsed in sorted_blocks:
|
466
|
-
if not any(ignore in block for ignore in _ignore_line)
|
479
|
+
if (not any(ignore in block for ignore in _ignore_line) and
|
480
|
+
not any(pattern in block for pattern in _ignore_function_patterns)):
|
467
481
|
percentage = (elapsed / total_time) * 100 if total_time > 0 else 0
|
468
482
|
quick_print(f"{block[:40]:40} | {elapsed:12.6f} | {percentage:10.2f}%")
|
469
483
|
|
470
484
|
quick_print("-" * 80)
|
471
485
|
|
472
|
-
# Clear the timing data for this context
|
473
486
|
del _timings[context]
|
474
487
|
_block_timings.clear()
|
475
488
|
_seen_lines.clear()
|
@@ -0,0 +1,5 @@
|
|
1
|
+
kenenet/__init__.py,sha256=oC4cUSYUIAFkI15eYO98XTFtFWM8-t_2h0mQc4ueG7c,20122
|
2
|
+
kenenet-1.0.8.dist-info/METADATA,sha256=V5C3p7SASz7s7tb9KCyAkwe9b7mUgyqHNVkzPmMDRnM,1693
|
3
|
+
kenenet-1.0.8.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
+
kenenet-1.0.8.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
+
kenenet-1.0.8.dist-info/RECORD,,
|
kenenet-1.0.5.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
kenenet/__init__.py,sha256=p2bl59OmW7OI5L0HPAcDYqDqigIik0Js4djFqRIDaVA,20517
|
2
|
-
kenenet-1.0.5.dist-info/METADATA,sha256=A3rWN_i3R21vkdykLlo_8VryFM497ZF16eS29uiARnQ,1693
|
3
|
-
kenenet-1.0.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
-
kenenet-1.0.5.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
-
kenenet-1.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|