Skip to content

Commit 50c91c4

Browse files
author
Leah Wasser
authoredSep 26, 2020
Move cloned student directories into assignment subdirectory (#288)
* syntax cleanup * fix docstring * black * black * update changelog and fix manifest issue
1 parent 64c12fe commit 50c91c4

File tree

5 files changed

+51
-23
lines changed

5 files changed

+51
-23
lines changed
 

‎CHANGELOG.rst

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`
99

1010
[Unreleased]
1111
------------
12+
- Clone dir copies assignments into an assignment-name dir rather than cloned
13+
dir root (@lwasser, #276)
14+
- Fix manifest file to bundle example-data not example-files dir (@lwasser, #272 take two)
1215

1316
[0.1.5]
1417
------------

‎MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
graft abcclassroom/example-files
1+
graft abcclassroom/example-data
22
include README.md
33
include LICENSE.rst

‎abcclassroom/clone.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ def clone_or_update_repo(organization, repo, clone_dir, skip_existing):
1717
Tries to clone the single repository 'repo' from the organization. If the
1818
local repository already exists, pulls instead of cloning (unless the
1919
skip flag is set, in which case it does nothing).
20+
21+
Parameters
22+
----------
23+
organization : string
24+
Organization where your GitHub classroom lives.
25+
repo : string
26+
Name of the student's GitHub repo.
27+
clone_dir : string
28+
Name of the clone directory.
29+
skip_existing : boolean
30+
True if you wish to skip copying files to existing repos.
2031
"""
2132
destination_dir = Path(clone_dir, repo)
2233
if destination_dir.is_dir():
@@ -56,7 +67,8 @@ def clone_student_repos(args):
5667
"repositories but will not copy any assignment files."
5768
)
5869
try:
59-
Path(course_dir, clone_dir).mkdir(exist_ok=True)
70+
# Create the assignment subdirectory path and ensure it exists
71+
Path(course_dir, clone_dir, assignment).mkdir(exist_ok=True)
6072
missing = []
6173
with open(roster_filename, newline="") as csvfile:
6274
reader = csv.DictReader(csvfile)
@@ -66,7 +78,10 @@ def clone_student_repos(args):
6678
repo = "{}-{}".format(assignment, student)
6779
try:
6880
clone_or_update_repo(
69-
organization, repo, clone_dir, skip_existing
81+
organization,
82+
repo,
83+
Path(clone_dir, assignment),
84+
skip_existing,
7085
)
7186
if materials_dir is not None:
7287
copy_assignment_files(config, student, assignment)
@@ -80,7 +95,7 @@ def clone_student_repos(args):
8095
print(" {}".format(r))
8196

8297
except FileNotFoundError as err:
83-
print("Cannot find roster file".format(roster_filename))
98+
print("Cannot find roster file: {}".format(roster_filename))
8499
print(err)
85100

86101

@@ -91,7 +106,11 @@ def copy_assignment_files(config, student, assignment):
91106
materials_dir = cf.get_config_option(config, "course_materials", False)
92107
clone_dir = cf.get_config_option(config, "clone_dir", True)
93108
repo = "{}-{}".format(assignment, student)
94-
files = Path(course_dir, clone_dir, repo).glob("*.ipynb")
109+
110+
# Copy files from the cloned_dirs/assignment name directory
111+
# TODO - right now this ONLY copies notebooks but we may want to copy
112+
# other file types like .py files as well.
113+
files = Path(course_dir, clone_dir, assignment, repo).glob("*.ipynb")
95114
destination = Path(
96115
course_dir, materials_dir, "submitted", student, assignment
97116
)

‎abcclassroom/feedback.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414

1515
def copy_feedback(args):
1616
"""
17-
Copies feedback reports to local student repositories, commits the changes, and (optionally) pushes to github. Assumes files are in the directory course_materials/feedback/student/assignment. Copies all files in the source directory.
17+
Copies feedback reports to local student repositories and commits the
18+
changes. If the --github flag is used, it also will push the changes to
19+
GitHub.
20+
21+
Assumes feedback files are in the directory
22+
course_materials/feedback/student/assignment-name following a typical
23+
nbgrader structure. Copies all files in the source directory.
1824
"""
19-
assignment = args.assignment
25+
assignment_name = args.assignment
2026
do_github = args.github
2127

2228
print("Loading configuration from config.yml")
@@ -26,7 +32,6 @@ def copy_feedback(args):
2632
roster_filename = cf.get_config_option(config, "roster", True)
2733
course_dir = cf.get_config_option(config, "course_directory", True)
2834
clone_dir = cf.get_config_option(config, "clone_dir", True)
29-
organization = cf.get_config_option(config, "organization", True)
3035
materials_dir = cf.get_config_option(config, "course_materials", True)
3136

3237
try:
@@ -35,16 +40,16 @@ def copy_feedback(args):
3540
reader = csv.DictReader(csvfile)
3641
for row in reader:
3742
student = row["github_username"]
38-
source_files = Path(feedback_dir, student, assignment).glob(
39-
"*"
40-
)
41-
repo = "{}-{}".format(assignment, student)
42-
destination_dir = Path(clone_dir, repo)
43+
source_files = Path(
44+
feedback_dir, student, assignment_name
45+
).glob("*")
46+
repo_name = "{}-{}".format(assignment_name, student)
47+
# The repos now live in clone_dir/assignment-name/repo-name
48+
destination_dir = Path(clone_dir, assignment_name, repo_name)
4349
if not destination_dir.is_dir():
4450
print(
45-
"Local student repository {} does not exist; skipping student".format(
46-
destination_dir
47-
)
51+
"Local student repository {} does not exist; skipping "
52+
"student".format(destination_dir)
4853
)
4954
continue
5055
for f in source_files:
@@ -56,7 +61,9 @@ def copy_feedback(args):
5661
shutil.copy(f, destination_dir)
5762
github.commit_all_changes(
5863
destination_dir,
59-
msg="Adding feedback for assignment {}".format(assignment),
64+
msg="Adding feedback for assignment {}".format(
65+
assignment_name
66+
),
6067
)
6168
if do_github:
6269
github.push_to_github(destination_dir)

‎abcclassroom/tests/test_clone.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# Tests for clone script
22

33
import pytest
4-
import os
54
from pathlib import Path
65

76
import abcclassroom.clone as abcclone
8-
import abcclassroom.github as github
97

8+
# TODO - this should be a fixture
109
test_data = {
1110
"assignment": "assignment1",
12-
"students": ["bert"],
11+
"students": ["bert", "alana"],
1312
"files": ["nb1.ipynb", "nb2.ipynb", "junk.csv"],
1413
}
1514

@@ -27,8 +26,8 @@ def test_files(default_config, tmp_path):
2726
files = test_data["files"]
2827
for s in students:
2928
repo_name = "{}-{}".format(assignment, s)
30-
assignment_path = Path(tmp_path, clone_dir, repo_name)
31-
assignment_path.mkdir(parents=True)
29+
assignment_path = Path(tmp_path, clone_dir, assignment, repo_name)
30+
assignment_path.mkdir(parents=True, exist_ok=True)
3231
for f in files:
3332
Path(assignment_path, f).touch()
3433

@@ -58,5 +57,5 @@ def test_copy_assignment_files(default_config, test_files):
5857
Path(
5958
materials_dir, "submitted", s, assignment, "junk.csv"
6059
).exists()
61-
== False
60+
is False
6261
)

0 commit comments

Comments
 (0)
Please sign in to comment.