def process_args(self, args): r'''Processes `args`. Returns none. ''' private_classes = [] private_functions = [] public_classes = [] public_functions = [] generator = documentationtools.yield_all_modules( code_root=args.path, visit_private_modules=True, ) for module in generator: module_file_name = module.__file__ if module_file_name.endswith('.pyc'): module_file_name = module_file_name[:-1] with open(module_file_name, 'r') as f: lines = f.readlines() for line in lines: if line.startswith('def '): name = line.split()[1].partition('(')[0] payload = (name, os.path.relpath(module_file_name)) if name.startswith('_'): private_functions.append(payload) else: public_functions.append(payload) elif line.startswith('class '): name = line.split()[1].partition('(')[0] payload = (name, os.path.relpath(module_file_name)) if name.startswith('_'): private_classes.append(payload) else: public_classes.append(payload) print('PUBLIC FUNCTIONS: {}'.format(len(public_functions))) print('PUBLIC CLASSES: {}'.format(len(public_classes))) print('PRIVATE FUNCTIONS: {}'.format(len(private_functions))) if args.verbose: for x in private_functions: name, file_name = x print('\t{}:'.format(file_name)) print('\t\t{}'.format(name)) print('PRIVATE CLASSES: {}'.format(len(private_classes))) if args.verbose: for x in private_classes: name, file_name = x print('\t{}:'.format(file_name)) print('\t\t{}'.format(name))
def process_args(self, args): r'''Processes `args`. Returns none. ''' private_classes = [] private_functions = [] public_classes = [] public_functions = [] generator = documentationtools.yield_all_modules( code_root=args.path, visit_private_modules=True, ) for module in generator: module_file_name = module.__file__ if module_file_name.endswith('.pyc'): module_file_name = module_file_name[:-1] with open(module_file_name, 'r') as f: lines = f.readlines() for line in lines: if line.startswith('def '): name = line.split()[1].partition('(')[0] payload = (name, os.path.relpath(module_file_name)) if name.startswith('_'): private_functions.append(payload) else: public_functions.append(payload) elif line.startswith('class '): name = line.split()[1].partition('(')[0] payload = (name, os.path.relpath(module_file_name)) if name.startswith('_'): private_classes.append(payload) else: public_classes.append(payload) print('PUBLIC FUNCTIONS: {}'.format(len(public_functions))) print('PUBLIC CLASSES: {}'.format(len(public_classes))) print('PRIVATE FUNCTIONS: {}'.format(len(private_functions))) if args.verbose: for x in private_functions: name, file_name = x print('\t{}:'.format(file_name)) print('\t\t{}'.format(name)) print('PRIVATE CLASSES: {}'.format(len(private_classes))) if args.verbose: for x in private_classes: name, file_name = x print('\t{}:'.format(file_name)) print('\t\t{}'.format(name))
def _process_args(self, args): from abjad.tools import documentationtools path = args.path if not os.path.isdir(path): path = os.path.dirname(path) counts = self._setup_counts() for module in documentationtools.yield_all_modules( code_root=path, ignored_file_names=[], ): with open(module.__file__, 'r') as file_pointer: contents = file_pointer.read() counts['source_lines'] += contents.count('\n') for obj in self._iterate_module(module): if isinstance(obj, types.FunctionType): if obj.__name__.startswith('_'): counts['private_functions'] += 1 else: counts['public_functions'] += 1 elif isinstance(obj, type): if obj.__name__.startswith('_'): counts['private_classes'] += 1 else: counts['public_classes'] += 1 for attr in inspect.classify_class_attrs(obj): if attr.defining_class != obj: continue if attr.kind in ('method', 'class method', 'static method'): if attr.name.startswith('_'): counts['unique_private_methods'] += 1 else: counts['unique_public_methods'] += 1 elif attr.kind in ('property,'): if attr.name.startswith('_'): counts['unique_private_properties'] += 1 else: counts['unique_public_properties'] += 1 self._print_results(counts)
def yield_all_functions( code_root=None, include_private_objects=False, root_package_name=None, ): r'''Yields all functions in `code_root`. Returns generator. ''' from abjad.tools import documentationtools for module in documentationtools.yield_all_modules( code_root=code_root, root_package_name=root_package_name, ): name = module.__name__.split('.')[-1] if not include_private_objects and name.startswith('_'): continue if not hasattr(module, name): continue obj = getattr(module, name) if isinstance(obj, types.FunctionType): yield obj
def yield_all_classes( code_root=None, include_private_objects=False, root_package_name=None, ): r'''Yields all classes encountered in `code_root`. Returns generator. ''' from abjad.tools import documentationtools for module in documentationtools.yield_all_modules( code_root=code_root, root_package_name=root_package_name, ): name = module.__name__.split('.')[-1] if not include_private_objects and name.startswith('_'): continue if not hasattr(module, name): continue obj = getattr(module, name) if isinstance(obj, type): yield obj
def _process_args(self, args): from abjad.tools import documentationtools path = args.path if not os.path.isdir(path): path = os.path.dirname(path) counts = self._setup_counts() for module in documentationtools.yield_all_modules( code_root=path, ignored_file_names=[], ): with open(module.__file__, 'r') as file_pointer: contents = file_pointer.read() counts['source_lines'] += contents.count('\n') for obj in self._iterate_module(module): if isinstance(obj, types.FunctionType): if obj.__name__.startswith('_'): counts['private_functions'] += 1 else: counts['public_functions'] += 1 elif isinstance(obj, type): if obj.__name__.startswith('_'): counts['private_classes'] += 1 else: counts['public_classes'] += 1 for attr in inspect.classify_class_attrs(obj): if attr.defining_class != obj: continue if attr.kind in ('method', 'class method', 'static method'): if attr.name.startswith('_'): counts['unique_private_methods'] += 1 else: counts['unique_public_methods'] += 1 elif attr.kind in ('property,'): if attr.name.startswith('_'): counts['unique_private_properties'] += 1 else: counts['unique_public_properties'] += 1 self._print_results(counts)