Created
September 30, 2020 07:07
-
-
Save deusmachinea/6de71a8fbabdb40f4229f2295d1e9660 to your computer and use it in GitHub Desktop.
Count number of function in a python directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import inspect | |
| import importlib | |
| import ast | |
| import glob | |
| files = glob.glob("/Users/dot/Programs/python_programs/dgm-web-app/backend" + '/**/*.py', recursive=True) | |
| class CountFunc(ast.NodeVisitor): | |
| func_count = 0 | |
| def visit_FunctionDef(self, node): | |
| self.func_count += 1 | |
| functions_count = [] | |
| for _file in files: | |
| p = ast.parse(open(_file).read()) | |
| f = CountFunc() | |
| f.visit(p) | |
| functions_count.append(f.func_count) | |
| print (f'Number of functions are {sum(functions_count)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment