Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP do not merge #13

Closed
wants to merge 15 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ nbgrader/docs/source/user_guide/managing_assignment_files_manually.rst
nbgrader/docs/source/user_guide/managing_the_database.rst
nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem1.html
nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem2.html
nbgrader/docs/source/user_guide/autograded/bitdiddle/ps1/problem3.html
nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem1.html
nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem2.html
nbgrader/docs/source/user_guide/autograded/hacker/ps1/problem3.html
nbgrader/docs/source/user_guide/downloaded/ps1/archive/ps1_hacker_attempt_2016-01-30-20-30-10_problem1.html
nbgrader/docs/source/user_guide/release/ps1/problem1.html
nbgrader/docs/source/user_guide/release/ps1/problem2.html
nbgrader/docs/source/user_guide/release/ps1/problem3.html
nbgrader/docs/source/user_guide/source/header.html
nbgrader/docs/source/user_guide/source/ps1/problem1.html
nbgrader/docs/source/user_guide/source/ps1/problem2.html
nbgrader/docs/source/user_guide/source/ps1/problem3.html

# components stuff
node_modules
Expand Down
32 changes: 29 additions & 3 deletions nbgrader/apps/generateassignmentapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import sys

from traitlets import default
from traitlets import default, Bool
from textwrap import dedent

from .baseapp import NbGrader, nbgrader_aliases, nbgrader_flags
from ..converters import BaseConverter, GenerateAssignment, NbGraderException
from ..converters import BaseConverter, GenerateAssignment, NbGraderException, GenerateSourceWithTests
from traitlets.traitlets import MetaHasTraits
from typing import List, Any
from traitlets.config.loader import Config
Expand Down Expand Up @@ -51,6 +52,12 @@
{'BaseConverter': {'force': True}},
"Overwrite an assignment/submission if it already exists."
),
'source_with_tests': (
{'GenerateAssignmentApp': {'source_with_tests': True}},
"Generate intermediate notebooks that contain both the autogenerated test code and the solutions. "
"Results will be saved in the source_with_tests/ folder. "
"This is useful for instructors to debug problematic autogenerated test code."
),
})


Expand All @@ -62,6 +69,17 @@ class GenerateAssignmentApp(NbGrader):
aliases = aliases
flags = flags

source_with_tests = Bool(
False,
help=dedent(
"""
Generate intermediate notebooks that contain both the autogenerated test code and the solutions.
Results will be saved in the source_with_tests/ folder.
This is useful for instructors to debug issues in autogenerated test code.
"""
)
).tag(config=True)

examples = """
Produce the version of the assignment that is intended to be released to
students. This performs several modifications to the original assignment:
Expand Down Expand Up @@ -112,7 +130,7 @@ class GenerateAssignmentApp(NbGrader):
@default("classes")
def _classes_default(self) -> List[MetaHasTraits]:
classes = super(GenerateAssignmentApp, self)._classes_default()
classes.extend([BaseConverter, GenerateAssignment])
classes.extend([BaseConverter, GenerateAssignment, GenerateSourceWithTests])
return classes

def _load_config(self, cfg: Config, **kwargs: Any) -> None:
Expand Down Expand Up @@ -141,6 +159,14 @@ def start(self) -> None:
elif len(self.extra_args) == 1:
self.coursedir.assignment_id = self.extra_args[0]


if self.source_with_tests:
converter = GenerateSourceWithTests(coursedir=self.coursedir, parent=self)
try:
converter.start()
except NbGraderException:
sys.exit(1)

converter = GenerateAssignment(coursedir=self.coursedir, parent=self)
try:
converter.start()
Expand Down
5 changes: 5 additions & 0 deletions nbgrader/apps/quickstartapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def start(self):
ignore_html = shutil.ignore_patterns("*.html")
shutil.copytree(example, os.path.join(course_path, "source"), ignore=ignore_html)

# copying the autotests.yml file to the course directory
tests_file_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', 'docs', 'source', 'user_guide', 'autotests.yml'))
shutil.copyfile(tests_file_path, os.path.join(course_path, 'autotests.yml'))

# create the config file
self.log.info("Generating example config file...")
currdir = os.getcwd()
Expand Down
4 changes: 3 additions & 1 deletion nbgrader/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .feedback import Feedback
from .generate_feedback import GenerateFeedback
from .generate_solution import GenerateSolution
from .generate_source_with_tests import GenerateSourceWithTests

__all__ = [
"BaseConverter",
Expand All @@ -14,5 +15,6 @@
"Autograde",
"Feedback",
"GenerateFeedback",
"GenerateSolution"
"GenerateSolution",
"GenerateSourceWithTests"
]
2 changes: 2 additions & 0 deletions nbgrader/converters/generate_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .base import BaseConverter, NbGraderException
from ..preprocessors import (
IncludeHeaderFooter,
InstantiateTests,
ClearSolutions,
LockCells,
ComputeChecksums,
Expand Down Expand Up @@ -57,6 +58,7 @@ def _output_directory(self) -> str:

preprocessors = List([
IncludeHeaderFooter,
InstantiateTests,
LockCells,
ClearSolutions,
ClearOutput,
Expand Down
49 changes: 49 additions & 0 deletions nbgrader/converters/generate_source_with_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import re

from traitlets import List, default

from .base import BaseConverter
from ..preprocessors import (
InstantiateTests,
ClearOutput,
CheckCellMetadata
)
from traitlets.config.loader import Config
from typing import Any
from ..coursedir import CourseDirectory


class GenerateSourceWithTests(BaseConverter):

@default("permissions")
def _permissions_default(self) -> int:
return 664 if self.coursedir.groupshared else 644

@property
def _input_directory(self) -> str:
return self.coursedir.source_directory

@property
def _output_directory(self) -> str:
return self.coursedir.source_with_tests_directory

preprocessors = List([
InstantiateTests,
ClearOutput,
CheckCellMetadata
]).tag(config=True)

def _load_config(self, cfg: Config, **kwargs: Any) -> None:
super(GenerateSourceWithTests, self)._load_config(cfg, **kwargs)

def __init__(self, coursedir: CourseDirectory = None, **kwargs: Any) -> None:
super(GenerateSourceWithTests, self).__init__(coursedir=coursedir, **kwargs)

def start(self) -> None:
old_student_id = self.coursedir.student_id
self.coursedir.student_id = '.'
try:
super(GenerateSourceWithTests, self).start()
finally:
self.coursedir.student_id = old_student_id
12 changes: 12 additions & 0 deletions nbgrader/coursedir.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ def _validate_notebook_id(self, proposal: Bunch) -> str:
)
).tag(config=True)

source_with_tests_directory = Unicode(
'source_with_tests',
help=dedent(
"""
The name of the directory that contains notebooks with both solutions
and instantiated test code (i.e., all AUTOTEST directives are removed
and replaced by actual test code). This corresponds to the
`nbgrader_step` variable in the `directory_structure` config option.
"""
)
).tag(config=True)

submitted_directory = Unicode(
'submitted',
help=dedent(
Expand Down
Loading
Loading