summaryrefslogtreecommitdiff
path: root/src/scripts
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2019-10-10 11:06:47 +0200
committerDave Andreoli <dave@gurumeditation.it>2019-10-10 11:06:55 +0200
commitf3dedfe395225f9710a04fd4529920408972df43 (patch)
treecc5b1a71235ccfe66b8060a43a4e95b787bde375 /src/scripts
parent30ddac07581daeeb1184ba366b6e0ac7392e8d79 (diff)
Pyolian: improve api coverage script
it now also check for enums and is smarter with code comments
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/pyolian/eolian.py77
1 files changed, 58 insertions, 19 deletions
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index 3d27fa481e..abb8e17a94 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -1549,34 +1549,57 @@ if __name__ == '__main__':
1549 1549
1550 # prepare the two regexp 1550 # prepare the two regexp
1551 flags = re.S | re.M 1551 flags = re.S | re.M
1552 DEFINED_RE = re.compile('^EAPI[\w\n *]*(eolian_\w*)\([\w *,]*\);', flags) 1552 FUNC_DEFINED_RE = re.compile(r'^\s*EAPI[\w\s*]*(eolian_\w*)\s*\([\w\s*,]*\);', flags)
1553 USED_RE = re.compile('lib\.(eolian_[\w]*)\(', flags) 1553 FUNC_USED_RE = re.compile(r'^[^\n#]*lib\.(eolian_[\w]*)\s*\(', flags)
1554 1554
1555 # extract all EAPI functions from Eolian.h 1555 ENUM_DEFINED_RE = re.compile(r'typedef enum\s*{([^}]*)}\s*(Eolian_[\w]*);', flags)
1556 ENUM_USED_RE = re.compile(r'^class\s([\w]*)\(IntEnum\):', flags)
1557
1558 # ignore some know cases (function or enum)
1559 IGNORED = {
1560 'eolian_implement_documentation_get', # we are using eolian_aux_implement_documentation_get
1561 'eolian_documentation_string_split', # not needed in python
1562 }
1563
1564 # extract functions and enums from Eolian.h
1556 defined_funcs = [] 1565 defined_funcs = []
1566 defined_enums = []
1557 with open(eolian_header, 'r') as fh: 1567 with open(eolian_header, 'r') as fh:
1558 header = fh.read() 1568 header = fh.read()
1559 for match in re.finditer(DEFINED_RE, header): 1569 for match in re.finditer(FUNC_DEFINED_RE, header):
1560 func_name = match.group(1) 1570 func_name = match.group(1)
1571 if func_name not in IGNORED:
1561 defined_funcs.append(func_name) 1572 defined_funcs.append(func_name)
1573 for match in re.finditer(ENUM_DEFINED_RE, header):
1574 enum_name = match.group(2)
1575 if enum_name not in IGNORED:
1576 defined_enums.append(enum_name)
1562 defined_funcs = set(defined_funcs) 1577 defined_funcs = set(defined_funcs)
1578 defined_enums = set(defined_enums)
1563 1579
1564 # extract all called functions in eolian.py (this file) 1580 # extract functions and enums from eolian.py (this file)
1565 used_funcs = [] 1581 used_funcs = []
1582 used_enums = []
1566 with open(__file__, 'r') as fh: 1583 with open(__file__, 'r') as fh:
1567 source = fh.read() 1584 source = fh.read()
1568 for match in re.finditer(USED_RE, source): 1585 for match in re.finditer(FUNC_USED_RE, source):
1569 func_name = match.group(1) 1586 func_name = match.group(1)
1570 used_funcs.append(func_name) 1587 used_funcs.append(func_name)
1588 for match in re.finditer(ENUM_USED_RE, source):
1589 enum_name = match.group(1)
1590 used_enums.append(enum_name)
1571 used_funcs = set(used_funcs) 1591 used_funcs = set(used_funcs)
1592 used_enums = set(used_enums)
1572 1593
1573 # show general info 1594 # show general info
1574 num_def = len(defined_funcs) 1595 num_def, num_usd = len(defined_funcs), len(used_funcs)
1575 num_usd = len(used_funcs) 1596 num_enum_def, num_enum_usd = len(defined_enums), len(used_enums)
1576 print('Pyolian coverage results') 1597 print('Pyolian coverage results')
1577 print('========================') 1598 print('========================')
1578 print('Found %d functions defined in Eolian.h (%s)' % (num_def, eolian_header)) 1599 print('Found %d functions defined in Eolian.h (%s)' % (num_def, eolian_header))
1579 print('Found %d functions used in eolian.py (hopefully not commented out)' % num_usd) 1600 print('Found %d functions used in eolian.py (hopefully not multiline-commented)' % num_usd)
1601 print('Found %d enums defined in Eolian.h' % num_enum_def)
1602 print('Found %d enums defined in eolian.py' % num_enum_usd)
1580 print('Total API coverage %.1f%%' % (num_usd / num_def * 100)) 1603 print('Total API coverage %.1f%%' % (num_usd / num_def * 100))
1581 print() 1604 print()
1582 1605
@@ -1588,15 +1611,31 @@ if __name__ == '__main__':
1588 print('{:02d}. {}'.format(i, func_name)) 1611 print('{:02d}. {}'.format(i, func_name))
1589 print() 1612 print()
1590 1613
1591 # List all functions found in Eolian.h (--all option) 1614 # list all missing enums
1592 if '--all' in sys.argv: 1615 missing = defined_enums - used_enums
1593 print('{} functions found in Eolian.h'.format(num_def)) 1616 if len(missing) > 0:
1594 print('===============================') 1617 print('{} Missing enums in eolian.py'.format(len(missing)))
1595 for i, func_name in enumerate(sorted(defined_funcs), 1): 1618 print('=================================')
1596 print('{:03d}. {}'.format(i, func_name)) 1619 for i, enum_name in enumerate(sorted(missing), 1):
1620 print('{:02d}. {}'.format(i, enum_name))
1597 print() 1621 print()
1622
1623 # List all functions found in C and Py (--all option)
1624 if '--all' in sys.argv:
1625 to_list = (
1626 (defined_funcs, '{} EAPI functions defined in Eolian.h'),
1627 (used_funcs, '{} functions called in eolian.py'),
1628 (defined_enums, '{} Enums defined in Eolian.h'),
1629 (used_enums, '{} Enums defined in eolian.py'),
1630 )
1631 for bag, label in to_list:
1632 print(label.format(len(bag)))
1633 print('==============================')
1634 for i, obj_name in enumerate(sorted(bag), 1):
1635 print('{:03d}. {}'.format(i, obj_name))
1636 print()
1598 else: 1637 else:
1599 print('Additional arguments') 1638 print('Additional arguments')
1600 print('====================') 1639 print('====================')
1601 print(' --all To list all functions found in Eolian.h') 1640 print(' --all To list all functions and enums found')
1602 print() 1641 print()