autograder .cli .grading .grade-dir
Grade a submission given an already prepared grading directory (see autograder.cli.testing.setup-grading-dir) and a grader file. Use autograder.cli.grading.grade if you have not already prepared your grading directory.
usage: python3 -m autograder.cli.grading.grade-dir [-h] -g GRADER -d DIR
[-o OUTPATH]
Grade a submission given an already prepared grading directory (see
autograder.cli.testing.setup-grading-dir) and a grader file. Use
autograder.cli.grading.grade if you have not already prepared your grading
directory.
options:
-h, --help show this help message and exit
-g GRADER, --grader GRADER
The path to a Python file containing a single
assignment class.
-d DIR, --dir DIR The path to the grading directory.
-o OUTPATH, --outpath OUTPATH
The path to a output the JSON result.
1# pylint: disable=invalid-name 2 3""" 4Grade a submission given an already prepared grading directory (see autograder.cli.testing.setup-grading-dir) and a grader file. 5Use autograder.cli.grading.grade if you have not already prepared your grading directory. 6""" 7 8import argparse 9import os 10import sys 11 12import edq.util.dirent 13import edq.util.json 14 15import autograder.submission 16 17def run_cli(args: argparse.Namespace) -> int: 18 """ Run the CLI. """ 19 20 grader_path = os.path.abspath(args.grader) 21 grading_dir = os.path.abspath(args.dir) 22 23 result = autograder.submission.run_submission(grading_dir, grader_path = grader_path) 24 if (result is None): 25 return 1 26 27 print(result.report()) 28 29 if (args.outpath is not None): 30 out_path = os.path.abspath(args.outpath) 31 edq.util.dirent.mkdir(os.path.dirname(os.path.abspath(out_path))) 32 edq.util.json.dump_path(result.to_dict(), out_path, indent = 4) 33 34 return 0 35 36def main() -> int: 37 """ Get a parser, parse the args, and call run. """ 38 39 args, _ = _get_parser().parse_known_args() 40 return run_cli(args) 41 42def _get_parser() -> argparse.ArgumentParser: 43 """ Get a parser for this operation. """ 44 45 parser = argparse.ArgumentParser(description = __doc__.strip()) 46 47 parser.add_argument('-g', '--grader', 48 action = 'store', type = str, required = True, 49 help = 'The path to a Python file containing a single assignment class.') 50 51 parser.add_argument('-d', '--dir', 52 action = 'store', type = str, required = True, 53 help = 'The path to the grading directory.') 54 55 parser.add_argument('-o', '--outpath', 56 action = 'store', type = str, required = False, default = None, 57 help = 'The path to a output the JSON result.') 58 59 return parser 60 61if (__name__ == '__main__'): 62 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
18def run_cli(args: argparse.Namespace) -> int: 19 """ Run the CLI. """ 20 21 grader_path = os.path.abspath(args.grader) 22 grading_dir = os.path.abspath(args.dir) 23 24 result = autograder.submission.run_submission(grading_dir, grader_path = grader_path) 25 if (result is None): 26 return 1 27 28 print(result.report()) 29 30 if (args.outpath is not None): 31 out_path = os.path.abspath(args.outpath) 32 edq.util.dirent.mkdir(os.path.dirname(os.path.abspath(out_path))) 33 edq.util.json.dump_path(result.to_dict(), out_path, indent = 4) 34 35 return 0
Run the CLI.
def
main() -> int:
37def main() -> int: 38 """ Get a parser, parse the args, and call run. """ 39 40 args, _ = _get_parser().parse_known_args() 41 return run_cli(args)
Get a parser, parse the args, and call run.