13
13
# arg name is positional is not prefixed with - or --
14
14
15
15
parser = argparse .ArgumentParser (description = 'Program description.' )
16
- parser .add_argument ('-p' , '--path' , metavar = 'PATH' , type = str ,required = False ,
16
+ parser .add_argument ('-p' , '--path' , metavar = 'PATH' , type = str , required = False ,
17
17
default = None ,
18
18
help = 'full path relative to which paths wills be reported' ,action = 'store' )
19
19
parser .add_argument ('-m' , '--module' , metavar = 'MODULE' , type = str ,required = True ,
20
20
help = 'name of package to import and examine' ,action = 'store' )
21
+ parser .add_argument ('-G' , '--github_repo' , metavar = 'REPO' , type = str ,required = False ,
22
+ help = 'github project where the the coe lives, e.g. "pydata/pandas"' ,
23
+ default = None ,action = 'store' )
21
24
22
25
args = parser .parse_args ()
23
26
24
- Entry = namedtuple ("Entry" ,"func loc undoc_names missing_args nsig_names ndoc_names" )
27
+ Entry = namedtuple ("Entry" ,"func path lnum undoc_names missing_args nsig_names ndoc_names" )
25
28
26
29
def entry_gen (root_ns ,module_name ):
27
30
@@ -45,7 +48,8 @@ def entry_gen(root_ns,module_name):
45
48
def cmp_docstring_sig (f ):
46
49
def build_loc (f ):
47
50
path = f .func_code .co_filename .split (args .path ,1 )[- 1 ][1 :]
48
- return "+{} {}" .format (f .func_code .co_firstlineno ,path )
51
+ return dict (path = path ,lnum = f .func_code .co_firstlineno )
52
+
49
53
import inspect
50
54
sig_names = set (inspect .getargspec (f ).args )
51
55
doc = f .func_doc .lower ()
@@ -57,10 +61,49 @@ def build_loc(f):
57
61
doc_names .discard ("kwds" )
58
62
doc_names .discard ("kwargs" )
59
63
doc_names .discard ("args" )
60
- return Entry (func = f ,loc = build_loc (f ),undoc_names = sig_names .difference (doc_names ),
64
+ return Entry (func = f ,path = build_loc (f )['path' ],lnum = build_loc (f )['lnum' ],
65
+ undoc_names = sig_names .difference (doc_names ),
61
66
missing_args = doc_names .difference (sig_names ),nsig_names = len (sig_names ),
62
67
ndoc_names = len (doc_names ))
63
68
69
+ def format_id (i ):
70
+ return i
71
+
72
+ def format_item_as_github_task_list ( i ,item ,repo ):
73
+ tmpl = "- [ ] {id}) [{file}:{lnum} ({func_name}())]({link}) - __Missing__[{nmissing}/{total_args}]: {undoc_names}"
74
+
75
+ link_tmpl = "https://github.com/{repo}/blob/master/{file}#L{lnum}"
76
+
77
+ link = link_tmpl .format (repo = repo ,file = item .path ,lnum = item .lnum )
78
+
79
+ s = tmpl .format (id = i ,file = item .path ,
80
+ lnum = item .lnum ,
81
+ func_name = item .func .__name__ ,
82
+ link = link ,
83
+ nmissing = len (item .undoc_names ),
84
+ total_args = item .nsig_names ,
85
+ undoc_names = list (item .undoc_names ))
86
+
87
+ if item .missing_args :
88
+ s += " __Extra__(?): {missing_args}" .format (missing_args = list (item .missing_args ))
89
+
90
+ return s
91
+
92
+ def format_item_as_plain (i ,item ):
93
+ tmpl = "+{lnum} {path} {func_name}(): Missing[{nmissing}/{total_args}]={undoc_names}"
94
+
95
+ s = tmpl .format (path = item .path ,
96
+ lnum = item .lnum ,
97
+ func_name = item .func .__name__ ,
98
+ nmissing = len (item .undoc_names ),
99
+ total_args = item .nsig_names ,
100
+ undoc_names = list (item .undoc_names ))
101
+
102
+ if item .missing_args :
103
+ s += " Extra(?)={missing_args}" .format (missing_args = list (item .missing_args ))
104
+
105
+ return s
106
+
64
107
def main ():
65
108
module = __import__ (args .module )
66
109
if not args .path :
@@ -70,13 +113,12 @@ def main():
70
113
# and there are at least some documented arguments
71
114
collect = [e for e in collect if e .undoc_names and len (e .undoc_names ) != e .nsig_names ]
72
115
73
- tmpl = "{}:[{}]\t missing[{}/{}]={}"
74
- for x in collect :
75
- s = tmpl .format (x .loc ,x .func .__name__ ,len (x .undoc_names ),
76
- x .nsig_names ,list (x .undoc_names ))
77
- if x .missing_args :
78
- s += " extra(?)={}" .format (list (x .missing_args ))
79
- print (s )
116
+ if args .github_repo :
117
+ for i ,item in enumerate (collect ,1 ):
118
+ print ( format_item_as_github_task_list (i ,item ,args .github_repo ))
119
+ else :
120
+ for i ,item in enumerate (collect ,1 ):
121
+ print ( format_item_as_plain (i , item ))
80
122
81
123
if __name__ == "__main__" :
82
124
import sys
0 commit comments