Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

drop support for Asymptote #52

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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
1 change: 0 additions & 1 deletion cmscontrib/gerpythonformat/templates/lg/graphics.cfg

This file was deleted.

15 changes: 0 additions & 15 deletions cmscontrib/gerpythonformat/templates/lg/mystyle.asy

This file was deleted.

2 changes: 1 addition & 1 deletion docs/External contest formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^
Expand Down
4 changes: 1 addition & 3 deletions docs/Installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ These are our requirements (in particular we highlight those that are not usuall

* `a2ps <https://www.gnu.org/software/a2ps/>`_ (only for printing).

* `asymptote <http://asymptote.sourceforge.net/>`_ (for German task format; usage now deprecated)

* `latexmk <http://www.ctan.org/pkg/latexmk/>`_ (for German task format)

* `ttf-fira-go <https://github.com/bBoxType/FiraGO>`_ (for German task format + Hebrew)
Expand Down Expand Up @@ -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/

Expand Down
Loading