1
- """Script to encourage documentation addition of changes incurred
1
+ #!/usr/bin/env python3
2
+ """Script to encourage documentation addition of changes incurred.
2
3
3
4
Methodology:
4
5
8
9
9
10
This script is to help better document the functionality
10
11
11
- NOTE :
12
+ Other :
12
13
13
14
This script complies with our python3 coding and documentation standards
14
15
and should be used as a reference guide. It complies with:
15
16
16
- 1) Pylint
17
- 2) Pydocstyle
18
- 3) Pycodestyle
19
- 4) Flake8
17
+ 1) Pylint
18
+ 2) Pydocstyle
19
+ 3) Pycodestyle
20
+ 4) Flake8
20
21
21
22
Run these commands from the CLI to ensure the code is compliant for all
22
23
your pull requests.
23
- """
24
24
25
+ """
25
26
# Standard imports
26
27
import argparse
27
28
import os
28
29
import sys
30
+ import enum
29
31
30
32
import git
31
- import enum
32
33
33
34
34
35
class DocumentationStatus (enum .Enum ):
36
+ """Define the documentation status.
37
+
38
+ Args:
39
+ None
40
+
41
+ Returns:
42
+ None
43
+
44
+ """
45
+
35
46
unknown = 0
36
47
updated = 1
37
48
not_updated = 2
@@ -52,44 +63,54 @@ def _arg_parser_resolver():
52
63
parser = argparse .ArgumentParser ()
53
64
# getting merge branch name
54
65
parser .add_argument (
55
- '--merge_branch_name' , type = str , required = True ,
56
- help = 'Name of the merging to branch' )
66
+ "--merge_branch_name" ,
67
+ type = str ,
68
+ required = True ,
69
+ help = "Name of the merging to branch" ,
70
+ )
57
71
# Github repository
58
72
parser .add_argument (
59
- '--repository' , type = str , required = True ,
60
- help = 'Name of the GitHub repository in the format "<USERNAME>/<REPO_NAME>"' )
73
+ "--repository" ,
74
+ type = str ,
75
+ required = True ,
76
+ help = '''\
77
+ Name of the GitHub repository in the format "<USERNAME>/<REPO_NAME>"''' ,
78
+ )
61
79
# getting root directory of repository
62
80
parser .add_argument (
63
- '--directory' , type = str , required = False ,
81
+ "--directory" ,
82
+ type = str ,
83
+ required = False ,
64
84
default = os .getcwd (),
65
- help = 'The parent directory of files to analyze.' )
85
+ help = "The parent directory of files to analyze." ,
86
+ )
66
87
# Return parser
67
88
result = parser .parse_args ()
68
89
return result
69
90
70
91
71
92
def check_for_documentation (diff_item ):
72
- """Determine the documentation status
93
+ """Determine the documentation status.
73
94
74
- Args:
75
- diff_item: Diff to check
95
+ Args:
96
+ diff_item: Diff to check
76
97
77
- Returns:
78
- doc_status: DocumentationStatus
98
+ Returns:
99
+ doc_status: DocumentationStatus
79
100
80
101
"""
81
102
# Extracting the changes made
82
103
file_diffs = diff_item .diff .decode ("utf-8" )
83
104
# Setting documentation status flag to unknown
84
105
doc_status = DocumentationStatus .unknown
85
106
# Splitting the changes for line by line iteration
86
- lines = file_diffs .split (' \n ' )
107
+ lines = file_diffs .split (" \n " )
87
108
# Setting updated doc line count
88
109
edited_doc_line_count = 0
89
110
# Looping over differences
90
111
for line in lines :
91
112
# checking if the line was updated and contains documentation
92
- if line .strip () and line .startswith ('+' ) and line .__contains__ (' ///' ):
113
+ if line .strip () and line .startswith ("+" ) and line .__contains__ (" ///" ):
93
114
# updating the flag by one
94
115
edited_doc_line_count += 1
95
116
# Checking if no doc was changed
@@ -99,15 +120,15 @@ def check_for_documentation(diff_item):
99
120
100
121
# Reading complete file to check if not documentation exist
101
122
# Reading the complete file
102
- file = diff_item .b_blob .data_stream .read ().decode (' utf-8' )
123
+ file = diff_item .b_blob .data_stream .read ().decode (" utf-8" )
103
124
# Splitting the line to check if documentation is present or not
104
- lines = file .split (' \n ' )
125
+ lines = file .split (" \n " )
105
126
# Setting the documentation line count flag
106
127
doc_lines = 0
107
128
# Looping over the file lines
108
129
for line in lines :
109
130
# Checking if the line contains any documentation or not
110
- if line .strip () and line .__contains__ (' ///' ):
131
+ if line .strip () and line .__contains__ (" ///" ):
111
132
# updating the flag by 1
112
133
doc_lines += 1
113
134
# Checking if the documentation lines were present or not
@@ -128,6 +149,9 @@ def main():
128
149
This function finds, and prints the files that exceed the CLI
129
150
defined defaults.
130
151
152
+ Args:
153
+ None
154
+
131
155
Returns:
132
156
None
133
157
@@ -137,12 +161,15 @@ def main():
137
161
# Getting the git repo
138
162
repo_feature = git .Repo (args .directory )
139
163
(_ , repository_directory ) = args .repository .split ("/" )
140
- repo_merge = git .Repo .clone_from ("https://github.com/{}.git" .format (args .repository ), "{}/{}" .format (args .directory , repository_directory ))
164
+ repo_merge = git .Repo .clone_from (
165
+ "https://github.com/{}.git" .format (args .repository ),
166
+ "{}/{}" .format (args .directory , repository_directory ),
167
+ )
141
168
142
169
# Do nothing if the branch has a "/" in it
143
- if '/' in args .merge_branch_name :
170
+ if "/" in args .merge_branch_name :
144
171
return
145
-
172
+
146
173
# Getting latest commit on latest branch
147
174
commit_dev = repo_merge .commit (args .merge_branch_name )
148
175
# Getting latest commit on feature branch
@@ -152,35 +179,44 @@ def main():
152
179
# Setting a flag to keep record of files and their documentation
153
180
lookup = {}
154
181
# Lopping over differences in modified files
155
- for diff_item in diff_index .iter_change_type ('M' ):
182
+ for diff_item in diff_index .iter_change_type ("M" ):
156
183
# Getting file path of difference
157
184
file_path = diff_item .b_path
158
185
# Checking if a file under codebase(lib) directory was modified
159
- if file_path .startswith (' lib' ):
186
+ if file_path .startswith (" lib" ):
160
187
# Getting file documentation status
161
188
lookup [file_path ] = check_for_documentation (diff_item )
162
189
# Lopping over differences in added files
163
- for diff_item in diff_index .iter_change_type ('A' ):
190
+ for diff_item in diff_index .iter_change_type ("A" ):
164
191
# Getting file path of difference
165
192
file_path = diff_item .b_path
166
193
# Checking if a file under codebase(lib) directory was added
167
- if file_path .startswith (' lib' ):
194
+ if file_path .startswith (" lib" ):
168
195
# Getting file documentation status
169
196
lookup [file_path ] = check_for_documentation (diff_item )
170
197
# Filtering files whose documentation status != updated
171
- filtered_lookup = {k : v for (k , v ) in lookup .items () if DocumentationStatus .updated != v }
198
+ filtered_lookup = {
199
+ k : v for (k , v ) in lookup .items () if DocumentationStatus .updated != v
200
+ }
172
201
# Checking if documentation was updated for all changed files
173
202
if len (filtered_lookup ) == 0 :
174
- print ('''🚀 {} Hurrah! documentation was updated in all modified/added files''' .format ('\033 [92m' ))
203
+ print (
204
+ """Hurrah! documentation was updated in all modified/added files"""
205
+ )
175
206
sys .exit (0 )
176
207
else :
177
208
print (
178
- '''🔍 {}DOCUMENTATION NOT UPDATED: Files with missing or not updated DartDoc documentation found''' .format (
179
- '\033 [91m' ))
209
+ """\
210
+ DOCUMENTATION NOT UPDATED: Files with missing or not updated \
211
+ DartDoc documentation found"""
212
+ )
180
213
for failing_file in filtered_lookup :
181
- print ('''>>> File name: {}\n \t {}\n ''' .format (failing_file , filtered_lookup [failing_file ]))
214
+ print (
215
+ f"""\
216
+ >>> File name: { failing_file } \n \t { filtered_lookup [failing_file ]} \n """
217
+ )
182
218
sys .exit (1 )
183
219
184
220
185
- if __name__ == ' __main__' :
221
+ if __name__ == " __main__" :
186
222
main ()
0 commit comments