Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: handout URL #126 #136

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ In order to typeset the slides you want, you can simply run
$ ./render --master-tex <tex master document> -c <configfile>
```

Two master slide sets are offered:
Three master slide sets are offered:

- `slides/Snakemake_HPC_Users.tex` - which contains a slide set tailored for users of ready-to use and non-curated workflows, their HPC parameterization and execution
- `slides/Snakemake_HPC_Creators.tex` - which contains a slide set tailored for creators of new workflows.
- `slides/Snakemake_HPC_Admins.tex'' - which contains some slides tailored to administrators to tell them some bits about Snakemake and global configurations.

A lecturer may choose to render a handout version of a slide set with the `--handout` flag. Handouts do not contain some images or slide overlays and are a little bit smaller then full course slide sets.
cmeesters marked this conversation as resolved.
Show resolved Hide resolved

### Customizing Slides

Expand Down
4 changes: 2 additions & 2 deletions handout/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ Please note:

* This handout does not display material to be used as a reference.
* In particular, the recepient has been informed that people new
to Snakemake and HPC should partake this course themselves as (some)
to Snakemake and HPC should follow this course themselves as (some)
material can and will be outdated, eventually.
* This is a handout release: Slides are merged and some (graphical)
content has been dropped.
* Sample scripts and (where applicable) solutions are provided. The above
notice applies.


Please direct suggestion for improvements to https://github.com/cmeesters/snakemake-hpc-teaching-material/issues .
Please direct suggestion for improvements to https://github.com/snakemake/snakemake-hpc-teaching-material/issues .
40 changes: 0 additions & 40 deletions pack_release.py

This file was deleted.

73 changes: 60 additions & 13 deletions render
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import subprocess
import sys
from tempfile import TemporaryDirectory
import yaml
import zipfile

# non standard libraries
from jinja2 import Environment, FileSystemLoader
Expand All @@ -33,6 +34,7 @@ PATH = os.path.split(os.path.realpath(__file__))[0]

jinja_env = Environment(loader=FileSystemLoader(PATH), **options)


def edition_from_tag():
"""
sets the edition from the latests tag
Expand All @@ -41,6 +43,7 @@ def edition_from_tag():
cmd = "git tag -l | tail -1"
return subprocess.getoutput(cmd)


def screen_master(masterdoc, tempdir):
prefix = os.path.join(tempdir, "slides")
fnames = list()
Expand Down Expand Up @@ -122,7 +125,7 @@ def run_pdflatex(fname="out.tex", path=".", handout=False):
cmd += r' "\def\ishandout{1} \input{' + fname + r'}"'
else:
cmd += f" {fname}"
cmd = shlex.split(cmd)
cmd = shlex.split(cmd)
retcode = subprocess.call(cmd, cwd=path)
pdfname = get_pdf_name(fname)
shutil.copy(os.path.join(path, pdfname), os.path.join(outdir, pdfname))
Expand Down Expand Up @@ -182,17 +185,19 @@ def find_and_replace_sections(boundaries, section_estimate, fname):
)
# adapt the two lines with our new boundaries:
elif first_done and second_done:
lines[
first_done
] = " \\tableofcontents[sections={%d-%d},currentsection]\n" % (
boundaries["lower"],
boundaries["first_half_end"],
lines[first_done] = (
" \\tableofcontents[sections={%d-%d},currentsection]\n"
% (
boundaries["lower"],
boundaries["first_half_end"],
)
)
lines[
second_done
] = " \\tableofcontents[sections={%d-%d},currentsection]\n" % (
boundaries["second_half_start"],
boundaries["upper"],
lines[second_done] = (
" \\tableofcontents[sections={%d-%d},currentsection]\n"
% (
boundaries["second_half_start"],
boundaries["upper"],
)
)
else:
logger.error(f"TOC expectations for '{fname}' not met")
Expand All @@ -215,12 +220,22 @@ if __name__ == "__main__":
)
parser.add_argument(
"--handout", default=False, action=argparse.BooleanOptionalAction
)
)
parser.add_argument(
"-n", "--no-rerun", default=False, action=argparse.BooleanOptionalAction
)
parser.add_argument(
"--sample-directory",
help="needed with `--handout` - should indicate directory with script file (cloze and solution)",
)
args = parser.parse_args()

if args.handout and not args.sample_directory:
print(
"ERROR: must indicate --sample-directory when writing handouts",
file=sys.stderr,
)

# the master tex needs to be without the 'slides' path, because
# on the tempfs, the relative path work without
args.master_tex = os.path.basename(args.master_tex)
Expand Down Expand Up @@ -260,9 +275,41 @@ if __name__ == "__main__":
to_adapt = os.path.join(tempdir, "slides", fname) + ".tex"
find_and_replace_sections(boundaries, section_estimate, to_adapt)
# now the typesetting needs to be triggered
run_pdflatex(fname=args.master_tex, path=os.path.join(tempdir, "slides"), handout=args.handout)
run_pdflatex(
fname=args.master_tex,
path=os.path.join(tempdir, "slides"),
handout=args.handout,
)
# re-run might be required
if args.no_rerun:
print("no rerun as requested")
sys.exit()
run_pdflatex(fname=args.master_tex, path=os.path.join(tempdir, "slides"))

# only to produce handouts (together with script bundles)
if args.handout:
handout_version = (
os.path.join("slides", os.path.splitext(args.master_tex)[0]) + ".pdf"
)

final_place = os.path.basename(handout_version)

file_list = [
(handout_version, final_place),
("handout/README.txt", "README.txt"),
]
opj = os.path.join

for root, dirs, files in os.walk(args.sample_directory):
for fname in files:
# restrict to sample files, no helper files
if "copy" in fname or "README" in fname:
continue
file_list.append(
(opj(root, fname), opj(*root.split("/")[1:], fname))
)
buildzipfname = "snakemake_intro_%s.zip" % edition_from_tag()
z = zipfile.ZipFile(buildzipfname, "w", compression=zipfile.ZIP_DEFLATED)
for item in file_list:
z.write(item[0], item[1])
z.close()
Loading