MCPcopy Create free account
hub / github.com/catboost/catboost / process_file

Function process_file

tools/ruff_linter/wrapper.py:51–94  ·  view source on GitHub ↗
(
    orig_filename: str, ruff_bin: str, orig_config: Path, source_root: str, check_format: bool, run_in_source_root: bool
)

Source from the content-addressed store, hash-verified

49
50
51def process_file(
52 orig_filename: str, ruff_bin: str, orig_config: Path, source_root: str, check_format: bool, run_in_source_root: bool
53) -> str:
54 logger.debug('Check %s with config %s', orig_filename, orig_config)
55
56 file_path = os.path.relpath(orig_filename, source_root)
57
58 if run_in_source_root:
59 filename = os.path.realpath(orig_filename) if os.path.islink(orig_filename) else orig_filename
60 config = orig_config.resolve() if orig_config.is_symlink() else orig_config
61 else:
62 filename = orig_filename
63 config = orig_config
64
65 if check_format:
66 ruff_format_check_out = run_ruff(ruff_bin, ['format', '--diff'], filename, config)
67 if len(ruff_format_check_out) > FORMAT_SNIPPET_LINES_LIMIT:
68 ruff_format_check_out = ruff_format_check_out[:FORMAT_SNIPPET_LINES_LIMIT]
69 ruff_format_check_out.append('[truncated]...\n')
70 # first two lines are absolute file paths, replace with relative ones
71 if ruff_format_check_out:
72 ruff_format_check_out[0] = f'--- [[imp]]{file_path}[[rst]]\n'
73 ruff_format_check_out[1] = f'+++ [[imp]]{file_path}[[rst]]\n'
74 else:
75 ruff_format_check_out = []
76
77 ruff_check_out = run_ruff(ruff_bin, ['check', '-q'], filename, config)
78 # Every line starts with an absolute path to a file, replace with relative one
79 for idx, line in enumerate(ruff_check_out):
80 ruff_check_out[idx] = f'[[imp]]{file_path}[[rst]]:{line.split(':', 1)[-1]}'
81
82 msg = ''
83 if ruff_format_check_out:
84 msg += '[[bad]]Formatting errors[[rst]]:\n'
85 msg += ''.join(ruff_format_check_out)
86
87 if ruff_format_check_out and ruff_check_out:
88 msg += '\n'
89
90 if ruff_check_out:
91 msg += '[[bad]]Linting errors[[rst]]:\n'
92 msg += ''.join(ruff_check_out)
93
94 return msg
95
96
97def main():

Callers 1

mainFunction · 0.70

Calls 7

run_ruffFunction · 0.85
lenFunction · 0.85
debugMethod · 0.45
resolveMethod · 0.45
appendMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected