From d301e28ae148f58fa1b7d6204f1fea4d49c7dc7c Mon Sep 17 00:00:00 2001 From: Tue Herlau <tuhe@dtu.dk> Date: Mon, 29 Jan 2024 14:02:21 +0100 Subject: [PATCH] updates --- setup.py | 2 +- src/coursebox.egg-info/PKG-INFO | 2 +- src/coursebox/core/info.py | 27 ++++++++----- src/coursebox/core/info_paths.py | 2 +- src/coursebox/material/documentation.py | 1 - .../material/homepage_lectures_exercises.py | 26 ++++++------ src/coursebox/student_files/student_files.py | 40 ++++++++++++------- 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/setup.py b/setup.py index f50928f..b8728b1 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setuptools.setup( name="coursebox", - version="0.1.18.21", + version="0.1.19.6", author="Tue Herlau", author_email="tuhe@dtu.dk", description="A course management system currently used at DTU", diff --git a/src/coursebox.egg-info/PKG-INFO b/src/coursebox.egg-info/PKG-INFO index ce04bbe..9308c52 100644 --- a/src/coursebox.egg-info/PKG-INFO +++ b/src/coursebox.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: coursebox -Version: 0.1.18.21 +Version: 0.1.19.5 Summary: A course management system currently used at DTU Home-page: https://lab.compute.dtu.dk/tuhe/coursebox Author: Tue Herlau diff --git a/src/coursebox/core/info.py b/src/coursebox/core/info.py index cfbf74d..9ccfaf1 100644 --- a/src/coursebox/core/info.py +++ b/src/coursebox/core/info.py @@ -202,7 +202,7 @@ def lectures(info, pensum=None): linfo['reading_long'] = ir.replace("C", "Chapter ") if ir else "" hwp = linfo['homework_problems'] - linfo['homework_problems_long'] = hwp.replace("P", "Problem ") if hwp else "" + linfo['homework_problems_long'] = str(hwp) if isinstance(hwp, int) else (hwp.replace("P", "Problem ") if hwp else "") if linfo["learning_objectives"]: linfo["learning_objectives"] = [s.strip() for s in linfo["learning_objectives"].split("\n")] linfo['reading_rst'] = bib2rst(linfo['reading']) @@ -214,15 +214,22 @@ def bib2rst(bib): if bib is None or 'cite' not in bib: return bib - bib = bib.split("cite")[1] - where = None - if "[" in bib: - where = bib.split("[")[1].split("]")[0] - what = bib.split("{")[1].split("}")[0] - if where is None: - return f":cite:p:`{what}`" - else: - return f"{where}, :cite:p:`{what}`" + + bibs = bib.strip().split(r"\cite") + b_rst = [] + for bib in bibs: + if '{' not in bib: + continue + # b_rst = "" + where = None + if "[" in bib: + where = bib.split("[")[1].split("]")[0] + what = bib.split("{")[1].split("}")[0] + if where is None: + b_rst.append(f":cite:p:`{what}`") + else: + b_rst.append(f"{where}, :cite:p:`{what}`") + return ", ".join(b_rst) # return "" pass diff --git a/src/coursebox/core/info_paths.py b/src/coursebox/core/info_paths.py index c3e63f4..23306c7 100644 --- a/src/coursebox/core/info_paths.py +++ b/src/coursebox/core/info_paths.py @@ -55,7 +55,7 @@ def get_paths(): 'course_number': course_number, 'semester': semester_path, 'information.xlsx': main_conf, - 'homepage_template': "%s/WEB/index_partial.html"%root_02450public, + 'homepage_template': "%s/WEB/index_partial23.html"%root_02450public, 'homepage_out': "%s/WEB/%sindex.html"%(root_02450public, sCE), 'pdf_out': "%s/%spdf_out"%(root_02450public, sCE), 'exercises': root_02450public + "/Exercises", # this does not seem correct. diff --git a/src/coursebox/material/documentation.py b/src/coursebox/material/documentation.py index e75c691..9b9dff5 100644 --- a/src/coursebox/material/documentation.py +++ b/src/coursebox/material/documentation.py @@ -55,7 +55,6 @@ def build_sphinx_documentation(cut_files=False, open_browser=True, build_and_cop # from coursebox.material.homepage_lectures_exercises import set from coursebox.student_files.student_files import setup_student_files - if os.path.isfile(d_ := f"{paths['book']}/{paths['course_number']}_Notes.pdf"): book_frontpage_png = paths['shared']+"/figures/book.png" slide_to_image(d_, book_frontpage_png, page_to_take=1) diff --git a/src/coursebox/material/homepage_lectures_exercises.py b/src/coursebox/material/homepage_lectures_exercises.py index 1794b51..f6a5396 100644 --- a/src/coursebox/material/homepage_lectures_exercises.py +++ b/src/coursebox/material/homepage_lectures_exercises.py @@ -325,7 +325,7 @@ def compile_simple_files(paths, info, template_file_list, verbose=False): if file.endswith("_template.tex"): file = file.replace("_template.tex", ".tex") tex_out = paths['shared_latex_compilation_dir'] + "/" + file - jinjafy_template(data=d2, file_in=fname, file_out=tex_out, filters=get_filters(), template_searchpath=paths['instructor']) + jinjafy_template(data=d2, file_in=fname, file_out=tex_out, filters=get_filters(), template_searchpath=paths['exercises']) latexmk(tex_out, pdf_out= paths['pdf_out'] + "/" + os.path.basename(tex_out)[:-4]+".pdf") # rec_fix_shared(shared_base=paths['shared'], output_dir=output_dir) @@ -333,9 +333,6 @@ def compile_simple_files(paths, info, template_file_list, verbose=False): # import dirsync # dirsync.sync(paths['shared'], output_dir, 'diff') # Do smarter fixin' -from pathlib import Path - - # @profile def get_hash_from_base(base): @@ -471,11 +468,11 @@ def make_exercises_projects_tutors(week=None, only_exercises=False, make_exercis info['lecture_handin'] = info['lectures'][handin_week-1] if info['CE']: - proj_base = paths['02450instructors'] + "/ExercisesShared/%sprojectCE_Base.tex"%(course_number, ) - proj_tex_out = paths['02450instructors'] + "/Project/latex%i/%sprojectCE.tex" % (1,course_number,) + proj_base = paths['exercises'] + "/ExercisesShared/%sprojectCE_Base.tex"%(course_number, ) + proj_tex_out = paths['exercises'] + "/Project/latex%i/%sprojectCE.tex" % (1,course_number,) else: - proj_base = paths['02450instructors'] + "/ExercisesShared/%sproject%i_Base.tex" % (course_number,proj+1,) - proj_tex_out = paths['02450instructors'] + "/Project/latex%i/%sproject%i.tex" % (proj+1, course_number, proj+1) + proj_base = paths['exercises'] + "/ExercisesShared/%sproject%i_Base.tex" % (course_number,proj+1,) + proj_tex_out = paths['exercises'] + "/Project/latex%i/%sproject%i.tex" % (proj+1, course_number, proj+1) info['week'] = -1 if not os.path.exists(proj_base): @@ -533,18 +530,19 @@ def make_exercises_projects_tutors(week=None, only_exercises=False, make_exercis } # get lang dir - if not os.path.exists("%s/Exercises%s"%(paths['instructors'], lang)): + if not os.path.exists("%s/Exercises%s"%(paths['exercises'], lang)): continue info.update(tv) - ex_base = "%s/ExercisesShared/%sex%i_Base.tex"%(paths['instructors'], course_number, w) - ex_tex_out = "%s/Exercises%s/Exercise%i/latex/%sex%i_%s.tex" % ( paths['instructors'], lang, w, course_number, w, lang) + ex_base = "%s/ExercisesShared/%sex%i_Base.tex"%(paths['exercises'], course_number, w) + ex_tex_out = "%s/Exercises%s/Exercise%i/latex/%sex%i_%s.tex" % ( paths['exercises'], lang, w, course_number, w, lang) # fbody = os.path.dirname(ex_tex_out) +f"/ex{w}_body.tex" if os.path.exists(ex_base): - jinjafy_template(info, ex_base, file_out=ex_tex_out, filters=filters, template_searchpath=paths['instructor']) + jinjafy_template(info, ex_base, file_out=ex_tex_out, filters=filters, template_searchpath=paths['exercises']) fix_shared(paths, output_dir=os.path.dirname(ex_tex_out), dosvg=dosvg) # mvfiles(shared_tex, os.path.dirname(ex_tex_out)+"/") + # if w != 0: latexmk(ex_tex_out, pdf_out=paths['pdf_out']+"/" + os.path.basename(ex_tex_out)[:-4] + ".pdf") def mvfiles(source_dir, dest_dir): @@ -575,9 +573,11 @@ def make_webpage(dosvg=True, upload=True): if os.path.exists( blrb): jinjafy_template(cinfo, file_in=blrb, file_out=blrb.replace("_template.html", ".html")) + cmd = f"cd {os.path.dirname(paths['homepage_template'] )} && rsync --delete --rsh=ssh -av ./ tuhe@thinlinc.compute.dtu.dk:/www/docs/courses/02465/" + print("> Run this command in the terminal to sync", cmd) + if upload: import subprocess - cmd = f"cd {os.path.dirname(paths['homepage_template'] )} && rsync --delete --rsh=ssh -av ./ tuhe@thinlinc.compute.dtu.dk:/www/docs/courses/02465/" subprocess.run([cmd], shell=True) # This should probably be moved into jinjafy diff --git a/src/coursebox/student_files/student_files.py b/src/coursebox/student_files/student_files.py index c5ba8d6..ef310ac 100644 --- a/src/coursebox/student_files/student_files.py +++ b/src/coursebox/student_files/student_files.py @@ -36,7 +36,8 @@ def setup_student_files(run_files=True, PACKAGE = list(core_conf['projects_all'].values()).pop()['module_public'].split(".")[0] - + if censor_files: + assert not run_files, "You cannot run files while you are censoring them -- your scripts will crash. Call with run_files=False." week = [week] if isinstance(week, int) else week if verbose: @@ -62,6 +63,9 @@ def setup_student_files(run_files=True, init_dest = students_irlc_tools+"/__init__.py" shutil.copy(public_irlc_tools + "/__init__.py", init_dest) + for fpy in glob.glob(public_irlc_tools + "/*.py"): + shutil.copy(fpy, students_irlc_tools + "/" + os.path.basename(fpy)) + if os.path.isfile(public_irlc_tools + "/../.coveragerc"): shutil.copy(public_irlc_tools + "/../.coveragerc", students_irlc_tools+ "/../.coveragerc") # assert False @@ -69,7 +73,10 @@ def setup_student_files(run_files=True, # Check for exclusion mask. exclude = info_paths.core_conf.get('student_files', {}).get('exclude', []) + if extra_dirs is None: + extra_dirs = info_paths.core_conf.get('student_files', {}).get('extra_dirs', []) + print("Extra dirs are", extra_dirs) exclude += [f'tests_week{w if w >= 10 else f"0{w}"}.py' for w in range(0,14) if w not in week] exclude = exclude + ["**/" + ex for ex in exclude] if not include_exam_examples: @@ -84,7 +91,8 @@ def setup_student_files(run_files=True, print(m) if extra_dirs is None: - + # extra_dirs = [] + extra_dirs = ['utils', 'tests', 'exam/exam2023spring', 'pacman', 'gridworld', 'car'] # 'assignments', for m in midterms: if m == 0: @@ -94,15 +102,15 @@ def setup_student_files(run_files=True, # if include_exam_examples: # extra_dirs += ['exam_tabular_examples'] - if setup_lectures: - extra_dirs += [ - # 'lectures/chapter0pythonC', - # 'lectures/chapter0pythonA', - # 'lectures/chapter0pythonB', - # 'lectures/chapter1', - 'lectures', - # 'workshop' - ] + if setup_lectures: + extra_dirs += [ + # 'lectures/chapter0pythonC', + # 'lectures/chapter0pythonA', + # 'lectures/chapter0pythonB', + # 'lectures/chapter1', + 'lectures', + # 'workshop' + ] import coursebox.core.info @@ -154,15 +162,17 @@ def setup_student_files(run_files=True, else: info = None for hw in hws: - if "ex08" in hw['out']: - print("ex08") + # if "ex08" in hw['out']: + # print("ex08") + print("Fixing hw", hw['out']) n = fix_hw(paths=paths, info=info, hw=hw, out= hw['out'], output_dir=paths['shared'] +"/output", run_files=run_files, cut_files=cut_files, package_base_dir=os.path.dirname(students_irlc_tools), censor_files=censor_files, strict=strict, include_solutions=hw.get('include_solutions', False), verbose=verbose) - with open(paths['shared'] + f"/output/lines_{hw['week']}.txt", 'w') as f: - f.write(str(n)) + if censor_files: + with open(paths['shared'] + f"/output/lines_{hw['week']}.txt", 'w') as f: + f.write(str(n)) if fix_shared_files: -- GitLab