MCPcopy Index your code
hub / github.com/python/cpython / check

Function check

Tools/patchcheck/reindent.py:104–157  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

102
103
104def check(file):
105 if os.path.isdir(file) and not os.path.islink(file):
106 if verbose:
107 print("listing directory", file)
108 names = os.listdir(file)
109 for name in names:
110 fullname = os.path.join(file, name)
111 if ((recurse and os.path.isdir(fullname) and
112 not os.path.islink(fullname) and
113 not os.path.split(fullname)[1].startswith("."))
114 or name.lower().endswith(".py")):
115 check(fullname)
116 return
117
118 if verbose:
119 print("checking", file, "...", end=' ')
120 with open(file, 'rb') as f:
121 try:
122 encoding, _ = tokenize.detect_encoding(f.readline)
123 except SyntaxError as se:
124 errprint("%s: SyntaxError: %s" % (file, str(se)))
125 return
126 try:
127 with open(file, encoding=encoding) as f:
128 r = Reindenter(f)
129 except IOError as msg:
130 errprint("%s: I/O Error: %s" % (file, str(msg)))
131 return
132
133 newline = spec_newline if spec_newline else r.newlines
134 if isinstance(newline, tuple):
135 errprint("%s: mixed newlines detected; cannot continue without --newline" % file)
136 return
137
138 if r.run():
139 if verbose:
140 print("changed.")
141 if dryrun:
142 print("But this is a dry run, so leaving it alone.")
143 if not dryrun:
144 bak = file + ".bak"
145 if makebackup:
146 shutil.copyfile(file, bak)
147 if verbose:
148 print("backed up", file, "to", bak)
149 with open(file, "w", encoding=encoding, newline=newline) as f:
150 r.write(f)
151 if verbose:
152 print("wrote new", file)
153 return True
154 else:
155 if verbose:
156 print("unchanged.")
157 return False
158
159
160def _rstrip(line, JUNK='\n \t'):

Callers 2

main.pyFile · 0.90
mainFunction · 0.70

Calls 15

runMethod · 0.95
writeMethod · 0.95
strFunction · 0.85
ReindenterClass · 0.85
islinkMethod · 0.80
listdirMethod · 0.80
copyfileMethod · 0.80
errprintFunction · 0.70
openFunction · 0.50
isdirMethod · 0.45
joinMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…