MCPcopy Create free account
hub / github.com/espnet/espnet / fix_file

Function fix_file

utils/apply_code_fixes.py:334–382  ·  view source on GitHub ↗

Fix flake8 issues in a single file. Args: file_path: Path to the Python file to fix. use_black: Whether to use black for formatting. use_isort: Whether to use isort for import sorting. use_autopep8: Whether to use autopep8 for PEP 8 compliance. verbose: W

(
    file_path: str,
    use_black: bool = True,
    use_isort: bool = True,
    use_autopep8: bool = True,
    verbose: bool = False,
)

Source from the content-addressed store, hash-verified

332
333
334def fix_file(
335 file_path: str,
336 use_black: bool = True,
337 use_isort: bool = True,
338 use_autopep8: bool = True,
339 verbose: bool = False,
340) -> bool:
341 """Fix flake8 issues in a single file.
342
343 Args:
344 file_path: Path to the Python file to fix.
345 use_black: Whether to use black for formatting.
346 use_isort: Whether to use isort for import sorting.
347 use_autopep8: Whether to use autopep8 for PEP 8 compliance.
348 verbose: Whether to print verbose output.
349
350 Returns:
351 True if all fixes were applied successfully, False otherwise.
352 """
353 success = True
354
355 if verbose:
356 print(f"Processing {file_path}...")
357
358 # Run isort to fix import order issues (H301, H306)
359 if use_isort:
360 if verbose:
361 print(f" Running isort on {file_path}")
362 cmd = ["isort", file_path]
363 if not run_command(cmd, file_path):
364 success = False
365
366 # Run autopep8 to fix spacing and line issues (E231, etc.)
367 if use_autopep8:
368 if verbose:
369 print(f" Running autopep8 on {file_path}")
370 cmd = ["autopep8", "--in-place", "--aggressive", "--aggressive", file_path]
371 if not run_command(cmd, file_path):
372 success = False
373
374 # Run black as a final formatter (also handles E203, W503)
375 if use_black:
376 if verbose:
377 print(f" Running black on {file_path}")
378 cmd = ["black", "--line-length", "88", file_path]
379 if not run_command(cmd, file_path):
380 success = False
381
382 return success
383
384
385def main():

Callers 1

mainFunction · 0.85

Calls 1

run_commandFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…