autograder .cli .util .style
Check the style of all '.py' and '.ipynb' files in the paths specified (recursively).
usage: python3 -m autograder.cli.util.style [-h] [--version] [--testing-mode]
[--ignore-path IGNORE_PATHS]
[--ignore-pattern IGNORE_PATTERNS]
[--style-overrides STYLE_OVERRIDES]
path [path ...]
Check the style of all '.py' and '.ipynb' files in the paths specified (recursively).
positional arguments:
path A path to check for style.
options:
-h, --help show this help message and exit
--version show program's version number and exit
--ignore-path IGNORE_PATHS
Paths to ignore (may be specified multiple times).
--ignore-pattern IGNORE_PATTERNS
Regular expressions to ignore (may be specified
multiple times).
--style-overrides STYLE_OVERRIDES
A JSON object containing style overrides to send to
flake8 (default: {}).
testing options:
--testing-mode Run as if a test is being run (default: False).
1""" 2Check the style of all '.py' and '.ipynb' files in the paths specified (recursively). 3""" 4 5import argparse 6import sys 7 8import edq.util.json 9 10import autograder.cli.parser 11import autograder.style 12 13def run_cli(args: argparse.Namespace) -> int: 14 """ Run the CLI. """ 15 16 style_overrides = edq.util.json.loads(args.style_overrides) 17 18 count, total_lines = autograder.style.check_paths(args.paths, 19 ignore_paths = args.ignore_paths, 20 ignore_patterns = args.ignore_patterns, 21 style_overrides = style_overrides) 22 23 print(f"Found {count} style errors.") 24 25 if (count > 0): 26 for (path, lines) in total_lines: 27 print(f"\nStyle Errors for '{path}':") 28 print('---') 29 print("\n".join(lines)) 30 print("---\n") 31 32 return count 33 34def main() -> int: 35 """ Get a parser, parse the args, and call run. """ 36 return run_cli(_get_parser().parse_args()) 37 38def _get_parser() -> argparse.ArgumentParser: 39 parser = autograder.cli.parser.get_parser(__doc__.strip()) 40 41 parser.add_argument('paths', metavar = 'path', 42 type = str, nargs = '+', 43 help = 'A path to check for style.') 44 45 parser.add_argument('--ignore-path', dest = 'ignore_paths', 46 type = str, action = 'append', default = [], 47 help = 'Paths to ignore (may be specified multiple times).') 48 49 parser.add_argument('--ignore-pattern', dest = 'ignore_patterns', 50 type = str, action = 'append', default = [], 51 help = 'Regular expressions to ignore (may be specified multiple times).') 52 53 parser.add_argument('--style-overrides', dest = 'style_overrides', 54 type = str, action = 'store', default = '{}', 55 help = 'A JSON object containing style overrides to send to flake8 (default: %(default)s).') 56 57 return parser 58 59if (__name__ == '__main__'): 60 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
14def run_cli(args: argparse.Namespace) -> int: 15 """ Run the CLI. """ 16 17 style_overrides = edq.util.json.loads(args.style_overrides) 18 19 count, total_lines = autograder.style.check_paths(args.paths, 20 ignore_paths = args.ignore_paths, 21 ignore_patterns = args.ignore_patterns, 22 style_overrides = style_overrides) 23 24 print(f"Found {count} style errors.") 25 26 if (count > 0): 27 for (path, lines) in total_lines: 28 print(f"\nStyle Errors for '{path}':") 29 print('---') 30 print("\n".join(lines)) 31 print("---\n") 32 33 return count
Run the CLI.
def
main() -> int:
35def main() -> int: 36 """ Get a parser, parse the args, and call run. """ 37 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.