diff --git a/assignment_submission_checker/assignment.py b/assignment_submission_checker/assignment.py index 0263e1d..017c721 100644 --- a/assignment_submission_checker/assignment.py +++ b/assignment_submission_checker/assignment.py @@ -166,7 +166,7 @@ def parse_into_output( "Information reported here does not invalidate the submission, " "though you may wish to check you expect everything here to apply " "to your submission.\n\t" - ) + "\n".join(s.replace("\n", "\n\t") for s in information) + ) + "\n\t".join(s.replace("\n", "\n\t") for s in information) if (not fatal_str) and (not warnings_str) and (not information_str): return f"{heading_str}\nSubmission format matches specifications, nothing further to report." diff --git a/assignment_submission_checker/cli_main.py b/assignment_submission_checker/cli_main.py index 65b2807..7785974 100644 --- a/assignment_submission_checker/cli_main.py +++ b/assignment_submission_checker/cli_main.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path from tempfile import mkdtemp from typing import Optional @@ -31,6 +32,13 @@ def fetch_spec(assignment_spec: str) -> None: return r.text +def infer_repo_name(repo: Repo) -> str: + """ + Attempt to infer the name of a repository cloned from GitHub. + """ + return repo.remotes.origin.url.split(".git")[0].split("/")[-1] + + def main( assignment_lookup: Optional[str] = None, github_clone_url: Optional[str] = None, @@ -51,10 +59,20 @@ def main( if github_clone_url is not None: # Attempt to clone GH repo and place into temp folder # then set that as the submission directory - submission_dir = Path(mkdtemp("safe_clone")) + tmp_dir = Path(mkdtemp("safe_clone")) + clone_dir = tmp_dir / "cloned" + clone_dir.mkdir(exist_ok=True) + # Actually clone the repo from GH so it is available on the filesystem - r = Repo.clone_from(github_clone_url, to_path=submission_dir) + r = Repo.clone_from(github_clone_url, to_path=clone_dir) + repo_name = infer_repo_name(r) r.close() + + # Relocate the cloned repository deeper inside another temporary folder, so that + # names match up with those expected. + submission_dir = tmp_dir / repo_name + shutil.move(clone_dir, submission_dir) + elif submission is not None: submission_dir = Path(submission) else: diff --git a/assignment_submission_checker/directory.py b/assignment_submission_checker/directory.py index a60945f..b107800 100644 --- a/assignment_submission_checker/directory.py +++ b/assignment_submission_checker/directory.py @@ -530,12 +530,14 @@ def investigate_subdir( if not path_to_subdir.is_dir(): if subdir.is_optional: - information.append(f"Optional subfolder {subdir.name} of {self.name} not found.") + information.append( + f"Optional subfolder '{subdir.name}' of '{self.name}' not found." + ) return None, warning, information else: return ( AssignmentCheckerError( - f"Expected subdirectory {subdir.name} to be present in {self.name}, but it is not." + f"Expected subdirectory '{subdir.name}' to be present in '{self.name}', but it is not." ), warning, information,