(base_path=".")
| 15 | def is_js_token(s): return len(s) and not s.startswith('//') |
| 16 | |
| 17 | def gen_stats(base_path="."): |
| 18 | table = [] |
| 19 | for path, _, files in os.walk(os.path.join(base_path, "tinygrad")): |
| 20 | for name in files: |
| 21 | if not (name.endswith(".py") or name.endswith(".js")): continue |
| 22 | if any(s in path.replace('\\', '/') for s in ['tinygrad/runtime/autogen', 'tinygrad/viz/assets']): continue |
| 23 | filepath = os.path.join(path, name) |
| 24 | relfilepath = os.path.relpath(filepath, base_path).replace('\\', '/') |
| 25 | if name.endswith(".js"): |
| 26 | with open(filepath) as file_: lines = [line.strip() for line in file_.readlines()] |
| 27 | token_count, line_count = sum(len(line.split()) for line in lines if is_js_token(line)), sum(1 for line in lines if is_js_token(line)) |
| 28 | else: |
| 29 | with tokenize.open(filepath) as file_: |
| 30 | tokens = [t for t in tokenize.generate_tokens(file_.readline) if t.type in TOKEN_WHITELIST and not is_docstring(t)] |
| 31 | token_count, line_count = len(tokens), len(set([x for t in tokens for x in range(t.start[0], t.end[0]+1)])) |
| 32 | if line_count > 0: table.append([relfilepath, line_count, token_count/line_count]) |
| 33 | return table |
| 34 | |
| 35 | def gen_diff(table_old, table_new): |
| 36 | table = [] |
no test coverage detected
searching dependent graphs…