MCPcopy Create free account
hub / github.com/ImageEngine/cortex / fixFile

Function fixFile

contrib/scripts/fixIncludes.py:197–303  ·  view source on GitHub ↗
( filename )

Source from the content-addressed store, hash-verified

195 )
196
197def fixFile( filename ) :
198
199 lines = open( filename ).readlines()
200
201 includes = collections.defaultdict( set )
202 defaultVisibility = False
203 firstInclude, lastInclude = None, None
204 nonBlankLines = set()
205 for lineNumber, line in enumerate( lines ) :
206
207 line = line.rstrip()
208
209 if line == "IECORE_PUSH_DEFAULT_VISIBILITY" :
210
211 if defaultVisibility :
212 warning( filename, lineNumber, "Bad default visibility nesting detected" )
213 defaultVisibility = True
214
215 elif line == "IECORE_POP_DEFAULT_VISIBILITY" :
216
217 if not defaultVisibility :
218 warning( filename, lineNumber, "Bad default visibility nesting detected" )
219 defaultVisibility = False
220
221 elif line.startswith( "#include" ) :
222
223 includeFile = line.split()[1].strip( '"' ).lstrip( "<" ).rstrip( ">" )
224
225 if includeFile in requiresDefaultVisibility :
226 includes["IECore"].add( "IECore/Export.h" )
227 if not defaultVisibility :
228 info( filename, lineNumber, "Include {0} will have default visibility added".format( includeFile ) )
229 else :
230 if defaultVisibility :
231 warning( filename, lineNumber, "Include {0} will have default visibility removed".format( includeFile ) )
232
233 if line.endswith( '.inl"' ) and os.path.splitext( filename )[1] != ".cpp" :
234 continue
235
236 c = category( includeFile, filename )
237 if c == "unknown" :
238 warning( filename, lineNumber, "Include {0} is uncategorised".format( includeFile ) )
239
240 if c == "self" and len( includes[c] ) :
241 warning( filename, lineNumber, "Found multiple self includes - not making any changes" )
242 return
243
244 includes[c].add( includeFile )
245
246 elif line != "" :
247
248 nonBlankLines.add( lineNumber )
249 continue
250
251 else :
252
253 continue
254

Callers 1

fixIncludes.pyFile · 0.85

Calls 8

formattedIncludeFunction · 0.85
appendMethod · 0.80
warningFunction · 0.70
infoFunction · 0.70
categoryFunction · 0.70
lenFunction · 0.50
addMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected