Skip to content

Commit

Permalink
fix(scripts): function name is a substring of other function
Browse files Browse the repository at this point in the history
  • Loading branch information
ezavod authored and Luthaf committed Jun 16, 2020
1 parent adaaf6a commit 11fd576
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions scripts/check-used-functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import os
import sys
import re

IGNORED = ["chfl_version", "chfl_trajectory_open"]
ERROR = False
Expand All @@ -28,26 +29,27 @@ def functions_list():
return functions


def read_all_source():
source = ""
def read_all_binding_functions():
binding_functions = set()
for (dirpath, _, paths) in os.walk(os.path.join(ROOT, "chemfiles")):
for path in paths:
if path != "ffi.py" and path.endswith(".py"):
with open(os.path.join(ROOT, dirpath, path)) as fd:
source += fd.read()
return source
file_functions = re.findall(r"(chfl_[a-z A-Z 0-9 _]*)\(", fd.read())
binding_functions.update(file_functions)
return binding_functions


def check_functions(functions, source):
def check_functions(functions, binding_functions):
for function in functions:
if function not in source and function not in IGNORED:
if function not in binding_functions and function not in IGNORED:
error("Missing: " + function)


if __name__ == '__main__':
functions = functions_list()
source = read_all_source()
check_functions(functions, source)
binding_functions = read_all_binding_functions()
check_functions(functions, binding_functions)

if ERROR:
sys.exit(1)

0 comments on commit 11fd576

Please sign in to comment.