Skip to content
Merged

V4 #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "git-autograder"
version = "3.0.0"
version = "4.0.0"
authors = [{ name = "Jiahao, Woo", email = "[email protected]" }]
description = "Library for autograding Git repositories"
readme = "README.md"
Expand All @@ -16,7 +16,13 @@ classifiers = [
"Programming Language :: Python :: 3.13",
]
license.file = "LICENSE"
dependencies = ["pytz", "types-pytz", "difflib_parser", "GitPython"]
dependencies = [
"pytz",
"types-pytz",
"difflib_parser",
"GitPython",
"repo-smith",
]

[project.urls]
Homepage = "https://github.com/git-mastery/git-autograder.git"
Expand Down
10 changes: 8 additions & 2 deletions src/git_autograder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
__all__ = [
"autograder",
"setup_autograder",
"set_env",
"assert_output",
"GitAutograderException",
"GitAutograderInvalidStateException",
"GitAutograderWrongAnswerException",
"GitAutograderTestLoader",
"GitAutograderRepo",
"GitAutograderStatus",
Expand All @@ -14,11 +16,15 @@

from .status import GitAutograderStatus
from .output import GitAutograderOutput
from .exception import (
GitAutograderException,
GitAutograderInvalidStateException,
GitAutograderWrongAnswerException,
)
from .repo import GitAutograderRepo
from .commit import GitAutograderCommit
from .branch import GitAutograderBranch
from .remote import GitAutograderRemote
from .decorators import autograder
from .test_utils import (
setup_autograder,
set_env,
Expand Down
2 changes: 1 addition & 1 deletion src/git_autograder/answers/rules/not_empty_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class NotEmptyRule(AnswerRule):
EMPTY = "Answer for {question} is empty."

def apply(self, answer: GitAutograderAnswersRecord) -> None:
if answer.answer.strip() != "":
if answer.answer.strip() == "":
raise Exception(self.EMPTY.format(question=answer.question))
88 changes: 0 additions & 88 deletions src/git_autograder/decorators.py

This file was deleted.

1 change: 0 additions & 1 deletion src/git_autograder/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class GitAutograderOutput:

started_at: Optional[datetime]
completed_at: Optional[datetime]
is_local: Optional[bool]
comments: Optional[List[str]] = None
exercise_name: Optional[str] = None

Expand Down
13 changes: 2 additions & 11 deletions src/git_autograder/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,14 @@
class GitAutograderRepo:
def __init__(
self,
is_local: bool,
exercise_name: str,
repo_path: Optional[str | os.PathLike] = None,
repo_path: str | os.PathLike,
) -> None:
# TODO: We should not be starting the grading at the point of initializing, but
# we're keeping this because of the exception system
self.started_at = self.__now()
self.is_local: bool = is_local
self.exercise_name = exercise_name
self.repo_path = (
repo_path
if repo_path is not None
else Path.cwd().parent / "main"
if not is_local
else Path.cwd().parent / "exercises" / exercise_name
)
self.repo_path = repo_path

self.repo: Repo = Repo(self.repo_path)

Expand Down Expand Up @@ -85,7 +77,6 @@ def to_output(
exercise_name=self.exercise_name,
started_at=self.started_at,
completed_at=self.__now(),
is_local=self.is_local,
comments=comments,
status=(
GitAutograderStatus.SUCCESSFUL
Expand Down
17 changes: 11 additions & 6 deletions src/git_autograder/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def set_env(**kwargs) -> mock._patch_dict:
class GitAutograderTestLoader:
def __init__(
self,
test_path: str,
exercise_name: str,
grade_func: Callable[[GitAutograderRepo], GitAutograderOutput],
) -> None:
self.test_path = test_path
self.exercise_name = exercise_name
self.grade_func = grade_func

Expand All @@ -48,6 +50,10 @@ def load(
step_id: str,
setup: Optional[Callable[[Repo], None]] = None,
) -> Iterator[GitAutograderOutput]:
# This is done to work around the limitation of running tests not within the exercise/tests/ folder
test_dir = os.path.dirname(self.test_path)
spec_path = os.path.join(test_dir, spec_path)

repo_initializer = initialize_repo(spec_path)
attach_start_tag(repo_initializer, step_id)
with repo_initializer.initialize() as r:
Expand All @@ -57,7 +63,6 @@ def load(
started_at = datetime.now(tz=pytz.UTC)
try:
autograder = GitAutograderRepo(
is_local=True,
exercise_name=self.exercise_name,
repo_path=r.working_dir,
)
Expand All @@ -70,7 +75,6 @@ def load(
exercise_name=self.exercise_name,
started_at=started_at,
completed_at=datetime.now(tz=pytz.UTC),
is_local=True,
comments=[e.message] if isinstance(e.message, str) else e.message,
status=(
GitAutograderStatus.ERROR
Expand All @@ -84,7 +88,6 @@ def load(
exercise_name=self.exercise_name,
started_at=None,
completed_at=None,
is_local=True,
comments=[str(e)],
status=GitAutograderStatus.ERROR,
)
Expand All @@ -101,6 +104,10 @@ def setup_autograder(
grade_func: Callable[[GitAutograderRepo], GitAutograderOutput],
setup: Optional[Callable[[Repo], None]] = None,
) -> Iterator[GitAutograderOutput]:
# This is done to work around the limitation of running tests not within the exercise/tests/ folder
cur_dir = os.path.dirname(__file__)
spec_path = os.path.join(cur_dir, spec_path)

repo_initializer = initialize_repo(spec_path)
attach_start_tag(repo_initializer, step_id)
with repo_initializer.initialize() as r:
Expand All @@ -110,7 +117,7 @@ def setup_autograder(
started_at = datetime.now(tz=pytz.UTC)
try:
autograder = GitAutograderRepo(
is_local=True, exercise_name=exercise_name, repo_path=r.working_dir
exercise_name=exercise_name, repo_path=r.working_dir
)
output = grade_func(autograder)
except (
Expand All @@ -121,7 +128,6 @@ def setup_autograder(
exercise_name=exercise_name,
started_at=started_at,
completed_at=datetime.now(tz=pytz.UTC),
is_local=True,
comments=[e.message] if isinstance(e.message, str) else e.message,
status=(
GitAutograderStatus.ERROR
Expand All @@ -135,7 +141,6 @@ def setup_autograder(
exercise_name=exercise_name,
started_at=None,
completed_at=None,
is_local=True,
comments=[str(e)],
status=GitAutograderStatus.ERROR,
)
Expand Down