Skip to content

Commit

Permalink
chore(asymptote)!: drop support for asymptote
Browse files Browse the repository at this point in the history
BREAKING CHANGE: draw pictures using Asymptote is no longer avaliable and will result in error during compilation. Use TikZ instead.

See also: #47, #51
  • Loading branch information
chuyang-wang-dev committed Mar 18, 2024
1 parent f8fd899 commit 1e4f46f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 80 deletions.
43 changes: 8 additions & 35 deletions cmscontrib/gerpythonformat/CommonConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
11 changes: 1 addition & 10 deletions cmscontrib/gerpythonformat/ContestConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions cmscontrib/gerpythonformat/Executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 1 addition & 19 deletions cmscontrib/gerpythonformat/Supplement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 0 additions & 6 deletions cmscontrib/gerpythonformat/templates/lg/LgTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1e4f46f

Please sign in to comment.