Skip to content

Commit

Permalink
preview checkit pull requests (#482)
Browse files Browse the repository at this point in the history
* factor out some functionality of preview_outcome's main function

* first swing at checkit preview

* fix import

* try running as a module

* create directory to move build into

* test change in a generator file

* typo

* build the viewer

* fix
  • Loading branch information
StevenClontz authored Dec 18, 2024
1 parent 73e5731 commit 2af1c43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pretext-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:

- name: build previews of all changed files
id: changes
run: python scripts/quickbuild_changes.py
run: python -m scripts.quickbuild_changes

- name: stage deployment
run: pretext deploy --stage-only
Expand Down
8 changes: 7 additions & 1 deletion scripts/preview_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from checkit.bank import Bank
from checkit import static

def main(book:str, outcome:str, amount:int = 20):
def build_preview(book:str, outcome:str, amount:int = 20):
# check that this outcome exists
exercise_path = Path("source", book, "exercises")
sage_library_path = Path("source", book, "sage")
Expand Down Expand Up @@ -89,9 +89,15 @@ def main(book:str, outcome:str, amount:int = 20):
# copy assets
shutil.copytree(b.build_path(), os.path.join(docs_path, "assets"), dirs_exist_ok=True)

return sandbox_bank_path


def main(book:str, outcome:str, amount:int = 20):
sandbox_bank_path = build_preview(book, outcome, amount)

subprocess.run(['python', '-m', 'http.server', '-d', str(sandbox_bank_path/'docs')])


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Preview a CheckIt outcome.')
parser.add_argument('book', choices=['precalculus', 'calculus', 'linear-algebra'])
Expand Down
22 changes: 22 additions & 0 deletions scripts/quickbuild_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pathlib import Path
from lxml import etree
import os
import shutil
from . import preview_outcome

def main():
repo = Repo()
Expand Down Expand Up @@ -41,6 +43,26 @@ def main():
"file": f,
"path": path
})
# for each CheckIt file, build its preview
for b in BOOKS:
EXERCISE_FILES = [f for f in changed_files if Path("source", b, "exercises", "outcomes") in f.parents]
# collect changed outcomes
changed_outcomes = []
for f in EXERCISE_FILES:
if f.parent.name not in changed_outcomes:
changed_outcomes.append(f.parent.name)
# build changed outcomes
for o in changed_outcomes:
sandbox_bank_path = preview_outcome.build_preview(b, o)
output_path = Path("output", f"{b}-web-instructor", "exercises", o)
output_path.mkdir(parents=True)
shutil.copytree(sandbox_bank_path / "docs", output_path, dirs_exist_ok=True)
preview_links.append({
"file": f,
"path": f"/preview/{b}/instructor/exercises/{o}/"
})



# create Javascript template for markdown output
markdown = f"## 🚀 Preview available 🚀\n\n<${{cf_url}}>\n\n"
Expand Down
4 changes: 3 additions & 1 deletion source/precalculus/exercises/outcomes/FN/FN1/generator.sage
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@ class Generator(BaseGenerator):
"plot0": plot(q[0]),
"plot1": plot(q[1]),
"plot2": plot(q[2]),
}
}

# trigger preview build...

0 comments on commit 2af1c43

Please sign in to comment.