예제 #1
0
    def merge_assets(self, assignment: CompilationAssignment, context: Context,
                     result: UnitResult):
        """Combine instruction assets into one folder."""

        run, _ = self.asset_merger.run_if_should(assignment, context)
        log.info(f"""instructions: {"merged" if run else "skipped"} assets""")
        if run:
            result.compiled = True
            result.tags.add(self.ASSETS)
예제 #2
0
    def compile_readme(self, assignment: CompilationAssignment,
                       context: Context, result: UnitResult):
        """Assemble cheat sheet."""

        run, _ = self.readme_builder.run_if_should(assignment, context)
        log.info(f"""solution: {"built" if run else "skipped"} readme""")
        if run:
            result.compiled = True
            result.tags.add(self.README)
예제 #3
0
    def compile_readme(self, assignment: CompilationAssignment,
                       context: Context, result: UnitResult):
        """Combine instructions."""

        run, _ = self.readme_builder.run_if_should(assignment, context)
        log.info(f"""instructions: {"built" if run else "skipped"} readme""")
        if run:
            result.compiled = True
            result.tags.add(self.README)
예제 #4
0
    def compile(self, assignment: CompilationAssignment,
                context: Context) -> UnitResult:
        """Bring the problem resources into one directory."""

        result = UnitResult()
        run, _ = self.content_aggregator.run_if_should(assignment, context)
        log.info(
            f"""resources: {"aggregated" if run else "skipped"} resources""")
        if run:
            result.compiled = True
            result.tags.add(self.RESOURCES)
        return result
예제 #5
0
    def aggregate_contents(self, assignment: CompilationAssignment,
                           context: Context, result: UnitResult):
        """Get all grading scripts."""

        run, copied_paths = self.content_aggregator.run_if_should(
            assignment, context)
        log.info(f"""grading: {"merged" if run else "skipped"} contents""")

        if run:
            # Delete extra READMEs
            for copied_path in copied_paths:
                readme_path = copied_path.joinpath(Files.README)
                if readme_path.exists():
                    files.delete(readme_path)

            result.compiled = True
            result.tags.add(self.CONTENTS)
예제 #6
0
    def compile(self, **context_options) -> TargetResult:
        """Generate context and compile."""

        log.info(
            f"building {self.configuration.assignment_path} to {self.configuration.artifacts_path}"
        )

        # Validate first
        validate(self.configuration.assignment_path)

        # Load the assignment object
        log.debug("loading assignment")
        assignment = CompilationAssignment.read(
            self.configuration.assignment_path)

        # Set up templating
        problem_template_paths = {
            f"problem/{problem.short}": problem.path
            for problem in assignment.problems
        }
        environment = jinja2_create_environment(
            default_template_path=root.joinpath("template"),
            assignment_path=self.configuration.assignment_path,
            problem_paths=problem_template_paths,
            custom_template_path=self.configuration.custom_template_path)
        environment.filters.update(get_readme=get_readme,
                                   has_readme=has_readme)
        environment.globals["configuration"] = self.configuration

        # Define context
        log.debug("setting context")
        context = Context(environment=environment, **context_options)

        # Check if an index file was edited
        if context.paths_modified:
            for item in (assignment, *assignment.problems):
                if item.index_path.resolve() in context.paths_modified:
                    context.indices_modified = True
                    break

        # Create output directory
        self.configuration.artifacts_path.mkdir(exist_ok=True, parents=True)

        # Run units
        return super().compile(assignment, context)
예제 #7
0
    def run(self, assignment: CompilationAssignment, result: TargetResult):
        """Main."""

        if not self.configuration.options.get("site"):
            return

        if not result["instructions"].compiled:
            return

        site_path = Path(self.configuration.options["site"])
        if not site_path.parent.exists():
            log.error("site parent path does not exist, cancelling pipeline")
            return

        log.info(f"pipelining instructions to site {site_path}")
        copy_directory(source=self.configuration.artifacts_path.joinpath(
            Paths.INSTRUCTIONS),
                       destination=site_path,
                       merge=False)
        move(site_path.joinpath(Files.README), site_path.joinpath("index.md"))
예제 #8
0
 def __post_init__(self):
     if self.custom_template_path is not None:
         log.info(f"custom template path is {self.custom_template_path}")