MCPcopy Create free account
hub / github.com/DFHack/dfhack / main

Function main

ci/lint.py:128–176  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

126 raise RuntimeError('git exited with %r' % p.returncode)
127
128def main(args):
129 root_path = os.path.abspath(args.path)
130 if not os.path.exists(args.path):
131 print('Nonexistent path: %s' % root_path)
132 sys.exit(2)
133
134 check_patterns = load_pattern_files(args.check_patterns)
135 ignore_patterns = load_pattern_files(args.ignore_patterns)
136
137 walk_iter = walk_all
138 if args.git_only:
139 walk_iter = walk_git_files
140
141 for full_path in walk_iter(root_path):
142 rel_path = full_path.replace(root_path, '').replace('\\', '/').lstrip('/')
143 if not valid_file(rel_path, check_patterns, ignore_patterns):
144 continue
145 if args.verbose:
146 print('Checking:', rel_path)
147 lines = []
148 with open(full_path, 'rb') as f:
149 lines = f.read().split(b'\n')
150 for i, line in enumerate(lines):
151 try:
152 lines[i] = line.decode('utf-8')
153 except UnicodeDecodeError:
154 msg_params = (rel_path, i + 1, 'Invalid UTF-8 (other errors will be ignored)')
155 error('%s:%i: %s' % msg_params)
156 if args.github_actions:
157 print('::error file=%s,line=%i::%s' % msg_params)
158 lines[i] = ''
159 for linter in linters:
160 try:
161 linter.check(lines)
162 except LinterError as e:
163 error('%s: %s' % (rel_path, e))
164 if args.github_actions:
165 print(e.github_actions_workflow_command(rel_path))
166 if args.fix:
167 linter.fix(lines)
168 contents = '\n'.join(lines)
169 with open(full_path, 'wb') as f:
170 f.write(contents.encode('utf-8'))
171
172 if success:
173 print('All linters completed successfully')
174 sys.exit(0)
175 else:
176 sys.exit(1)
177
178if __name__ == '__main__':
179 parser = argparse.ArgumentParser()

Callers 1

lint.pyFile · 0.70

Calls 11

load_pattern_filesFunction · 0.85
valid_fileFunction · 0.85
checkMethod · 0.80
fixMethod · 0.80
errorFunction · 0.70
printFunction · 0.50
existsMethod · 0.45
readMethod · 0.45
decodeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected