Skip to content

Instantly share code, notes, and snippets.

@adler-j
Created January 25, 2017 11:03
Show Gist options
  • Save adler-j/e7aeba3a5db65e4d1a3384ceb0ed0630 to your computer and use it in GitHub Desktop.
Save adler-j/e7aeba3a5db65e4d1a3384ceb0ed0630 to your computer and use it in GitHub Desktop.
import fnmatch
import os
matches = []
for root, dirnames, filenames in os.walk('E:/Github/ODL/odl'):
for filename in fnmatch.filter(filenames, '*.py'):
matches.append(os.path.join(root, filename))
for match in matches:
with open(match) as f:
in_args = False
individual_args = []
found_doc = []
found_parameters = False
for line_nr, line in enumerate(f):
if line.strip() == '':
continue
if 'def ' in line:
start = line.find('(')
if start == -1:
continue
# check previous
if found_parameters and not all(found_doc):
missing_docs = [arg for arg, fd in zip(individual_args, found_doc) if not fd]
print('missing doc ', line_nr + 1, missing_docs, match)
#raise Exception
line = line[start+1:]
in_args = True
args = ''
individual_args = []
found_doc = []
found_parameters = False
if in_args:
end = line.find(')')
if end != -1:
args += line[:end]
individual_args = args.split(',')
for i in range(len(individual_args)):
individual_args[i] = individual_args[i].replace(' ', '')
individual_args[i] = individual_args[i].replace('\n', '')
if 'self' in individual_args:
individual_args.remove('self')
if '**kwargs' in individual_args:
individual_args.remove('**kwargs')
is_optional = [False for i in range(len(individual_args))]
found_doc = [False for i in range(len(individual_args))]
for i, arg in enumerate(individual_args):
equals_ind = arg.find('=')
if equals_ind != -1:
individual_args[i] = arg[:equals_ind]
is_optional[i] = True
in_args = False
if args == 'RealNumbers(':
raise Exception
else:
args += line
in_args = True
if 'Returns' in line:
individual_args = []
found_doc = []
if 'Parameters' in line:
found_parameters = True
for i, arg in enumerate(individual_args):
if arg in line.strip().split()[0] and ' :' in line:
found_doc[i] = True
if 'optional' not in line and is_optional[i]:
print('missing optional', line_nr + 1, match, line)
if not all(found_doc[:i]):
print('wrong order ', line_nr + 1, match, line, found_doc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment