Skip to content

Commit

Permalink
Change git branches less frequently
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jul 2, 2023
1 parent 45f4ddb commit 460e01b
Showing 1 changed file with 53 additions and 32 deletions.
85 changes: 53 additions & 32 deletions doc/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def log(msg=''):
output.append(msg)


def iter_branches():
for branch, version in BRANCHES:
git_switch_branch(branch)
os.chdir(GIT_DIR)
yield version


def display_title(title):
log(title)
log('=' * len(title))
Expand All @@ -50,6 +43,32 @@ def paragraph(text):
log()


class Data:
pass


def _get_data():
data = Data()
data.line_numbers = get_line_numbers()
data.file_numbers = get_file_numbers()
data.functions = get_functions()
data.variables = get_variables()
data.macro_static_inline_funcs = get_macros_static_inline_funcs()
data.types = get_types()
return data


def get_data():
result = []
for branch, version in BRANCHES:
print(f"Parse {branch} header files")
git_switch_branch(branch)
os.chdir(GIT_DIR)
data = _get_data()
result.append((version, data))
return result


def main_title():
title = 'Statistics on the Python C API'
log('+' * len(title))
Expand Down Expand Up @@ -123,13 +142,13 @@ def has_include_cpython(name):
return (name not in ('2.7', '3.6', '3.7'))


def line_numbers():
def line_numbers(results):
display_title('Line Numbers')
paragraph('Number of C API line numbers per Python version:')

lines = [COLUMNS]
for name in iter_branches():
limited, cpython, internal = get_line_numbers()
for name, data in results:
limited, cpython, internal = data.line_numbers
total = limited + cpython + internal

line = [name]
Expand All @@ -140,26 +159,26 @@ def line_numbers():
render_table(lines)


def file_numbers():
def file_numbers(results):
display_title('File Numbers')
paragraph('Number of header file numbers per Python version:')
lines = [COLUMNS]
for name in iter_branches():
limited, cpython, internal = get_file_numbers()
for name, data in results:
limited, cpython, internal = data.file_numbers
line = [name, limited, cpython, internal, limited + cpython + internal]
lines.append(line)
table_compute_diff(lines)
render_table(lines)


def list_functions():
def list_functions(results):
display_title('Functions')
paragraph('Functions exported with PyAPI_FUNC():')
lines = [('Python', 'Public', 'Private', 'Internal', 'Total')]
for branch_name in iter_branches():
public, private, internal = get_functions()
for name, data in results:
public, private, internal = data.functions
total = len(public) + len(private) + len(internal)
line = [branch_name, len(public), len(private), len(internal), total]
line = [name, len(public), len(private), len(internal), total]
lines.append(line)

table_compute_diff(lines)
Expand All @@ -175,26 +194,26 @@ def list_functions():
""")


def list_variables():
def list_variables(results):
display_title('Variables')
paragraph('Symbols exported with PyAPI_DATA():')
lines = [('Python', 'Public', 'Private', 'Internal', 'Total')]
for name in iter_branches():
public, private, internal = get_variables()
for name, data in results:
public, private, internal = data.variables
total = len(public) + len(private) + len(internal)
line = [name, len(public), len(private), len(internal), total]
lines.append(line)
table_compute_diff(lines)
render_table(lines)


def static_inline_func():
def static_inline_func(results):
display_title('Functions defined as macros and static inline functions')
paragraph('Functions defined as macros (only public) and static inline functions (public or private):')

lines = [('Python', 'Macro', 'Static inline', 'Total')]
for name in iter_branches():
macros, static_inline = get_macros_static_inline_funcs()
for name, data in results:
macros, static_inline = data.macro_static_inline_funcs

line = [name, len(macros), len(static_inline),
len(macros) + len(static_inline)]
Expand All @@ -203,13 +222,13 @@ def static_inline_func():
render_table(lines)


def structures():
def structures(results):
display_title('Structures')
paragraph('Structures in the Python C API:')

lines = [COLUMNS]
for name in iter_branches():
limited, cpython, internal = get_types()
for name, data in results:
limited, cpython, internal = data.types
total = limited + cpython + internal
line = [name, limited, cpython, internal, total]
lines.append(line)
Expand All @@ -220,13 +239,15 @@ def structures():


def render_page():
results = get_data()

main_title()
line_numbers()
file_numbers()
list_functions()
list_variables()
static_inline_func()
structures()
line_numbers(results)
file_numbers(results)
list_functions(results)
list_variables(results)
static_inline_func(results)
structures(results)


def main():
Expand Down

0 comments on commit 460e01b

Please sign in to comment.