From 1e4f46feabe3c96fa63dcb6c34c5e5ae21d67c2a Mon Sep 17 00:00:00 2001 From: Chuyang Wang Date: Mon, 18 Mar 2024 18:24:18 +0100 Subject: [PATCH 1/3] chore(asymptote)!: drop support for asymptote BREAKING CHANGE: draw pictures using Asymptote is no longer avaliable and will result in error during compilation. Use TikZ instead. See also: #47, #51 --- cmscontrib/gerpythonformat/CommonConfig.py | 43 ++++--------------- cmscontrib/gerpythonformat/ContestConfig.py | 11 +---- cmscontrib/gerpythonformat/Executable.py | 10 ----- cmscontrib/gerpythonformat/Supplement.py | 20 +-------- .../templates/lg/LgTemplate.py | 6 --- 5 files changed, 10 insertions(+), 80 deletions(-) diff --git a/cmscontrib/gerpythonformat/CommonConfig.py b/cmscontrib/gerpythonformat/CommonConfig.py index 76d62629bf..56d8dd1203 100644 --- a/cmscontrib/gerpythonformat/CommonConfig.py +++ b/cmscontrib/gerpythonformat/CommonConfig.py @@ -23,16 +23,16 @@ from __future__ import unicode_literals from cmscontrib.gerpythonformat.Messenger import print_msg, print_block, \ - header, box, yellow, highlight_latex + header, box, red, highlight_latex from cmscontrib.gerpythonformat.Executable import CPPProgram, InternalPython, ExternalScript, \ - ExternalPython, asy_keyword_list + ExternalPython from cms.rules.Rule import LaTeXRule, SafeLaTeXRule, CommandRule, ZipRule from cms.grading.languages.c11_gcc import C11Gcc from cms.grading.languages.cpp17_gpp import Cpp17Gpp from cms.grading.languages.java_jdk import JavaJDK from cms.grading.languages.pascal_fpc import PascalFpc from cms.grading.languages.python3_pypy import Python3PyPy -from cmscontrib.gerpythonformat.Supplement import easycall, def_latex, escape_latex, def_asy, escape_asy +from cmscontrib.gerpythonformat.Supplement import easycall, def_latex, escape_latex import inspect import io import os @@ -113,8 +113,6 @@ def __init__(self, rules, ignore_latex=False, verbose_latex=False, self.exported["timedelta"] = timedelta - self.asy_warnings = 0 - # Run the configuration file def _readconfig(self, filename): @@ -185,10 +183,6 @@ def supply(self, key, f): def supply_latex(self, name, f): self.supply("latex", def_latex(name, escape_latex(f))) - @exported_function - def supply_asy(self, name, f): - self.supply("asy", def_asy(name, escape_asy(f))) - @exported_function def register_supplement(self, key, extension): """ @@ -376,6 +370,8 @@ def compilelatex(self, basename, safe=None, ignore=set(), @exported_function def compileasy(self, basename, stdin=None, output=None, **kwargs): """ + DEPRECATED: Asymptote support is deprecated and removed. + Compile and run an asymptote file to generate a pdf file. basename (string): base of the asymptote file name: basename.asy @@ -389,34 +385,11 @@ def compileasy(self, basename, stdin=None, output=None, **kwargs): arguments. """ - source = basename + ".asy" - if output is None: - output = basename + ".pdf" - - with header("Compile {} to {} using Asymptote" - .format(self.short_path(source), self.short_path(output)), - depth=10): - box(" WARNING ", yellow("Asymptote support will be removed from " - "our task format in the near future.") + - "\n" + yellow("Please consider using TikZ for pictures.")) - self.asy_warnings += 1 + box(" ERROR ", red("Asymptote support is removed from our task format." + "\n") + red("Please use TikZ for pictures instead.")) + raise Exception("Compilation failed") - self._build_supplements("asy") - - # Asymptote does not tell us the dependencies, so we have to guess - dep = [source] + self._get_supplement_extension_files("asy") - - r = CommandRule(self.rules, - ["asy"] + ["-tex", "lualatex"] + - ["-o", output] + asy_keyword_list(kwargs) + - [source], stdin=stdin, dependencies=dep, - outputs=[output], dependonexe=False).ensure() - print_block(r.out) - print_block(r.err) - if r.code != 0: - raise Exception("Compilation failed") - return output @exported_function def compile(self, filename, **kwargs): diff --git a/cmscontrib/gerpythonformat/ContestConfig.py b/cmscontrib/gerpythonformat/ContestConfig.py index 331bf470cc..fcfc587890 100644 --- a/cmscontrib/gerpythonformat/ContestConfig.py +++ b/cmscontrib/gerpythonformat/ContestConfig.py @@ -188,16 +188,7 @@ def _readconfig(self, filename): self._initialize_ranking() def finish(self): - asy_cnt = self.asy_warnings + sum(t.asy_warnings - for t in self.tasks.values()) - - if asy_cnt != 0: - box(" WARNING ", yellow("You compiled %d Asymptote file(s)." - % asy_cnt) + "\n" + - yellow("However, Asymptote support will be removed") + "\n" + - yellow("from our task format in the near future") + "\n" + - yellow("Please consider using TikZ for pictures."), - double=True) + pass def _token_feedback(self, gen_initial, gen_number, gen_interval=timedelta(minutes=30), gen_max=None, diff --git a/cmscontrib/gerpythonformat/Executable.py b/cmscontrib/gerpythonformat/Executable.py index d9b87bc6d5..b19856776f 100644 --- a/cmscontrib/gerpythonformat/Executable.py +++ b/cmscontrib/gerpythonformat/Executable.py @@ -270,16 +270,6 @@ def keyword_list(kwords): return L -def asy_keyword_list(kwords): - """ Convert a keyword dictionary to something readable by - asymptote on the command line - """ - def encode(key, val): - return ("-" if val else "-no") + str(key) - - return [encode(key, val) for key, val in kwords.items()] - - class CPPProgram(Executable): """An Executable which is the binary resulting from compiling some c++ source files. diff --git a/cmscontrib/gerpythonformat/Supplement.py b/cmscontrib/gerpythonformat/Supplement.py index 47af11f359..30c96cb2f5 100644 --- a/cmscontrib/gerpythonformat/Supplement.py +++ b/cmscontrib/gerpythonformat/Supplement.py @@ -60,22 +60,4 @@ def f(): return f -def escape_asy(x): - """Return a function returning the result of f escaped for asymptote. - """ - def f(): - return str(easycall(x)).replace("\\", "\\\\").replace("\n", "\\n") - return f - - -def def_asy(name, x): - """Return a function returning an asymptote command defining name to be - the result of f (where the result of f is a string). - """ - # TODO automatically guess type of variable - def f(): - return 'string %s = "%s";\n' % (name, easycall(x)) - return f - - -__all__ = ["escape_latex", "def_latex", "input_latex", "escape_asy", "def_asy"] +__all__ = ["escape_latex", "def_latex", "input_latex"] diff --git a/cmscontrib/gerpythonformat/templates/lg/LgTemplate.py b/cmscontrib/gerpythonformat/templates/lg/LgTemplate.py index 4fce142743..77970906af 100644 --- a/cmscontrib/gerpythonformat/templates/lg/LgTemplate.py +++ b/cmscontrib/gerpythonformat/templates/lg/LgTemplate.py @@ -86,12 +86,6 @@ def ontask(self, task): "translation-en.tex"), os.path.join(task.wdir, "translation-en.tex")) - # Provide common asy files - shutil.copyfile(os.path.join(os.path.dirname(__file__), "graphics.cfg"), - "graphics.cfg") - shutil.copyfile(os.path.join(os.path.dirname(__file__), "mystyle.asy"), - "mystyle.asy") - task.supply("latex", def_latex("feedback", task.feedback)) score_mode = task.score_mode() From 64f056551180548d2154d980b6bb3a3a555e8194 Mon Sep 17 00:00:00 2001 From: Chuyang Wang Date: Mon, 18 Mar 2024 18:53:43 +0100 Subject: [PATCH 2/3] doc(asymptote): remove asympote from dependencies list in docs --- docs/External contest formats.rst | 2 +- docs/Installation.rst | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/External contest formats.rst b/docs/External contest formats.rst index de6eb72000..76a1957c8c 100644 --- a/docs/External contest formats.rst +++ b/docs/External contest formats.rst @@ -220,7 +220,7 @@ Subsequently (in :samp:`Rule.ensure()`), we check if the last result (:samp:`Rul Compiling --------- -You can compile c++, latex and asymptote files using the commands :py:meth:`.compilecpp`, :py:meth:`.compilelatex`, :py:meth:`.compileasy`. Call them with the base name of the file you want to compile (e.g. :samp:`gen` if you want to compile :samp:`gen.cpp` or :samp:`statement` if you want to compile :samp:`statement.tex`). For convenience, you can use the :py:meth:`.compile` function which automatically figures out the corresponding extension. +You can compile c++ and latex files using the commands :py:meth:`.compilecpp` and :py:meth:`.compilelatex`. Call them with the base name of the file you want to compile (e.g. :samp:`gen` if you want to compile :samp:`gen.cpp` or :samp:`statement` if you want to compile :samp:`statement.tex`). For convenience, you can use the :py:meth:`.compile` function which automatically figures out the corresponding extension. Supplements ^^^^^^^^^^^ diff --git a/docs/Installation.rst b/docs/Installation.rst index f2afafb1df..c945fa3e97 100644 --- a/docs/Installation.rst +++ b/docs/Installation.rst @@ -30,8 +30,6 @@ These are our requirements (in particular we highlight those that are not usuall * `a2ps `_ (only for printing). -* `asymptote `_ (for German task format; usage now deprecated) - * `latexmk `_ (for German task format) * `ttf-fira-go `_ (for German task format + Hebrew) @@ -281,7 +279,7 @@ To install CMS python dependencies on Arch Linux (again: assuming you did not us # Optional. # sudo pacman -S --needed python-yaml python-sphinx python-pycups \ - # asymptote texlive-core + # texlive-core # Optionally install the following from AUR. # https://aur.archlinux.org/packages/python-pypdf2/ From b938e42824a3ed1a28339f60ed6e35f9d7fe20c2 Mon Sep 17 00:00:00 2001 From: Chuyang Wang Date: Mon, 18 Mar 2024 20:58:42 +0100 Subject: [PATCH 3/3] chore(asymptote): delete unused template style files --- .../gerpythonformat/templates/lg/graphics.cfg | 1 - .../gerpythonformat/templates/lg/mystyle.asy | 15 --------------- 2 files changed, 16 deletions(-) delete mode 100644 cmscontrib/gerpythonformat/templates/lg/graphics.cfg delete mode 100644 cmscontrib/gerpythonformat/templates/lg/mystyle.asy diff --git a/cmscontrib/gerpythonformat/templates/lg/graphics.cfg b/cmscontrib/gerpythonformat/templates/lg/graphics.cfg deleted file mode 100644 index 6a762a7012..0000000000 --- a/cmscontrib/gerpythonformat/templates/lg/graphics.cfg +++ /dev/null @@ -1 +0,0 @@ -\ExecuteOptions{luatex} diff --git a/cmscontrib/gerpythonformat/templates/lg/mystyle.asy b/cmscontrib/gerpythonformat/templates/lg/mystyle.asy deleted file mode 100644 index c021c31f1a..0000000000 --- a/cmscontrib/gerpythonformat/templates/lg/mystyle.asy +++ /dev/null @@ -1,15 +0,0 @@ -pen darkgray = .4 * white; -pen lightgray = .8 * white; - -pen myred = .761 * red + .055 * green + .102 * blue; -pen mygreen = .055 * red + .761 * green + .102 * blue; -pen myblue = .055 * red + .102 * green + .761 * blue; - -pen highlight = myred; - -usepackage("FiraSans", "sfdefault,tabular,scaled=.9"); -usepackage("FiraMono", "lining,scaled=.9"); -usepackage("unicode-math", "mathrm=sym"); -usepackage("firamath-otf", "Scale=.9"); - -defaultpen(fontsize(10pt)+.6pt);