pygrade package

Submodules

pygrade.cheat module

Check for cheating. Output file in format: distance file1 file2

usage:
pygrade cheat –test <file> [–students <file>] [–output <file>] [–workdir <file>]
Options
-h, –help -o, –output <file> Output file [default: cheats.tsv] -s, –students <file> Students TSV file [default: students.tsv] -t, –test <file> File containing python tests for grading -w, –workdir <file> Temporary directory for storing assignments [default: students]
pygrade.cheat.compare_assignments(students, test_path, path)[source]
pygrade.cheat.main()[source]
pygrade.cheat.parse_assignments(students, test_path, path)[source]
pygrade.cheat.strip_comments(src)[source]
pygrade.cheat.write_output(results, out_path)[source]

pygrade.clone module

Clone student GitHub repositories.

usage:
pygrade clone [–students <file>] [–workdir <file>]
Options
-h, –help -s, –students <file> Students TSV file [default: students.tsv] -w, –workdir <file> Temporary directory for storing assignments [default: students]
pygrade.clone.main()[source]

pygrade.grade module

Grade a Python assignment, writing results to a .json file.

usage:
pygrade grade –test <file> [–students <file>] [–output <file>] [–workdir <file>] [–pull] [–extra <file>]
Options
-h, –help -e, –extra <file> File containing extra deductions, in tab-separated format: github_id points_off reason -o, –output <file> Output file [default: grades.json] -p, –pull Pull latest code from student repository. -s, –students <file> Students TSV file [default: students.tsv] -t, –test <file> File containing python tests for grading -w, –workdir <file> Temporary directory for storing assignments [default: students]
pygrade.grade.deduct_failures(test_results)[source]

Accumulate each failed tests and the points lost.

pygrade.grade.import_file_as_module(path)[source]

Return a python file as a module.

pygrade.grade.load_assignment_modules(repo, assignment_subpaths, metadata, result, results)[source]
pygrade.grade.main()[source]
pygrade.grade.read_extra_deductions(args)[source]

Read a file containing additional deductions for a student. E.g. for late points; or if there is a small compiler error that the grader fixes in order to run the rest of the tests.

pygrade.grade.run_tests(students, test_path, path, do_pull, student2extra)[source]

Run unit tests and deduct points for each failed test. Return a dictionary of results for each student. FIXME: check for errors?

pygrade.grade.unload_assignment_modules(repo, assignment_subpaths)[source]

Unload assignment modules, so that another student’s module doesn’t stay loaded when grading the next student.

pygrade.grade.write_grades(grades, out_path)[source]

pygrade.init module

Initialize student repositories. Create one repo per student. Also create one team per student consisting of that student. Each repo is made private to that team.

usage:
pygrade init –org <name> –user <username> –pass <passwd> –remote <uri> [–students <file>] [–workdir <file>]
Options
-h, –help -o, –org <string> Name of the GitHub Organization for the course. -p, –pass <file> GitHub password -r, –remote <uri> URL of remote github repo used for starter code. -s, –students <file> Students TSV file [default: students.tsv] -u, –user <file> GitHub username -w, –workdir <file> Temporary directory for storing assignments [default: students]
pygrade.init.add_remote(local_repo, remote_repo)[source]
pygrade.init.add_to_org(user, org)[source]
pygrade.init.create_repos_and_teams(students, org_name, github, path, remote_repo)[source]
pygrade.init.get_repo(repo_name, existing_repos, org, team)[source]
pygrade.init.get_team(team_name, existing_teams, org, user)[source]
pygrade.init.lookup_repo(existing_repos, name)[source]
pygrade.init.lookup_team(existing_teams, name)[source]
pygrade.init.main()[source]
pygrade.init.push_readme(repo)[source]
pygrade.init.search_for_user(github, userid)[source]
pygrade.init.write_readme(student, local_repo)[source]

pygrade.push module

Push grades to student repositories.

usage:
pygrade push [–grades <file>] [–workdir <file>]
Options
-h, –help -g, –grades <file> JSON grades output by the grade command [default: grades.json] -w, –workdir <file> Temporary directory for storing assignments [default: students]
pygrade.push.main()[source]
pygrade.push.push_file(repo, grade, grade_path)[source]
pygrade.push.push_grades(grades, path)[source]
pygrade.push.write_grade_file(grade, grade_path)[source]

pygrade.pygrade module

A command-line tool to auto-grade python assignments.

usage:
pygrade [–help] <command> [<args>…]
The most commonly used pygrade commands are:
cheat Detect plagiarism. clone Clone all student GitHub repositories. delete Delete student accounts. grade Grade assignments. init Initialize repositories. push Push grades to student repositories.

See ‘pygrade help <command>’ for more information on a specific command.

pygrade.pygrade.main()[source]

Module contents

pygrade.check_students(students)[source]

Make sure we have requisite fields for each student.

pygrade.clone_repo(student, path)[source]
pygrade.clone_repos(students, path)[source]

Clone all student repos.

pygrade.extract_metadata(text, result)[source]
>>> extract_metadata('@name=a0/foo.py', {})['files_to_test']
['a0/foo.py']
>>> extract_metadata('@name=a0/foo.py,a0/bar.py', {})['files_to_test']
['a0/foo.py', 'a0/bar.py']
>>> extract_metadata('@possible_points=12.4', {})['possible_points']
12.4
pygrade.get_local_repo(s, path)[source]

Return the path to the local copy of this student’s repository.

pygrade.mktmpdir(subdir)[source]

Make a unique, temporary directory for student repos.

pygrade.path2name(path)[source]

Get the basename of a file, minus any extensions. >>> path2name(‘foo/bar/baz.py’) ‘baz’

pygrade.pull_repo(local_repo)[source]
pygrade.read_assignment_metadata(test_file)[source]

Extracts metadata in the comments of the unit test file. E.g.: @name=a0/boolean_search.py,a0/run.py @possible_points=50

pygrade.read_students(path)[source]

Read a tab-separated file of students. The only required field is ‘github_repo’, which is this student’s github repository.