1# SPDX-License-Identifier: GPL-2.0-only 2# This file is part of Scapy 3# See https://scapy.net/ for more information 4# Copyright (C) Gabriel Potter <gabriel[]potter[]fr> 5 6""" 7Generate MyPy deployment stats 8""" 9 10import os 11import io 12import glob 13from collections import defaultdict 14 15# Parse config file 16 17localdir = os.path.split(__file__)[0] 18rootpath = os.path.abspath(os.path.join(localdir, '../../')) 19 20with io.open(os.path.join(localdir, "mypy_enabled.txt")) as fd: 21 FILES = [l.strip() for l in fd.readlines() if l.strip() and l[0] != "#"] 22 23# Scan Scapy 24 25ALL_FILES = [ 26 "".join(x.partition("scapy/")[2:]) for x in 27 glob.iglob(os.path.join(rootpath, 'scapy/**/*.py'), recursive=True) 28] 29 30# Process 31 32REMAINING = defaultdict(list) 33MODULES = defaultdict(lambda: (0, 0, 0, 0)) 34 35for f in ALL_FILES: 36 with open(os.path.join(rootpath, f)) as fd: 37 lines = len(fd.read().split("\n")) 38 parts = f.split("/") 39 if len(parts) > 2: 40 mod = parts[1] 41 else: 42 mod = "[core]" 43 e, l, t, a = MODULES[mod] 44 if f in FILES: 45 e += lines 46 t += 1 47 else: 48 REMAINING[mod].append(f) 49 l += lines 50 a += 1 51 MODULES[mod] = (e, l, t, a) 52 53ENABLED = sum(x[0] for x in MODULES.values()) 54TOTAL = sum(x[1] for x in MODULES.values()) 55 56print("**MyPy Support: %.2f%%**" % (ENABLED / TOTAL * 100)) 57print("| Module | Typed code (lines) | Typed files |") 58print("| --- | --- | --- |") 59for mod, dat in MODULES.items(): 60 print("|`%s` | %.2f%% | %s/%s |" % (mod, dat[0] / dat[1] * 100, dat[2], dat[3])) 61 62print() 63COREMODS = REMAINING["[core]"] 64if COREMODS: 65 print("Core modules still untypes:") 66 for mod in COREMODS: 67 print("- `%s`" % mod) 68 69