From 5734d2add8dc0223a612f1e66a50e4690b0ffe23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Wed, 21 Dec 2022 19:43:02 -0300 Subject: [PATCH 1/2] #34995 (trac #23712): support tachyon >= 0.99.2 In tachyon 0.99.2 the keyword `focallength` was changed to `focaldist`. To support it, when running on version >= 0.99.2 we "patch" the model as constructed by class `sage.plot.plot3d.tachyon.Tachyon`. In the future (possibly when tachyon in sage gets upgraded), all the focallength occurences in sage.plot.plot3d.tachyon can be replaced by focaldist for consistency with new tachyon, and the logic here can be reversed (i.e. patch the model when self.version() < '0.99.2') or just drop support for old versions. --- src/sage/interfaces/tachyon.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/sage/interfaces/tachyon.py b/src/sage/interfaces/tachyon.py index 23671e50892..21cc1db65ac 100644 --- a/src/sage/interfaces/tachyon.py +++ b/src/sage/interfaces/tachyon.py @@ -683,12 +683,14 @@ #***************************************************************************** import os +import re from sage.cpython.string import bytes_to_str from sage.misc.pager import pager from sage.misc.superseded import deprecation from sage.misc.temporary_file import tmp_filename from sage.structure.sage_object import SageObject +from sage.misc.cachefunc import cached_method class TachyonRT(SageObject): @@ -799,6 +801,11 @@ def __call__(self, model, outfile='sage.png', verbose=1, extra_opts=''): Parser failed due to an input file syntax error. Aborting render. """ + if self.version() >= '0.99.2': + # this keyword was changed in 0.99.2 + model = model.replace( + " focallength ", + " focaldist ") modelfile = tmp_filename(ext='.dat') with open(modelfile, 'w') as file: file.write(model) @@ -851,6 +858,22 @@ def usage(self, use_pager=True): else: print(r) + @cached_method + def version(self): + """ + Returns the version of the Tachyon raytracer being used. + + TESTS:: + + sage: tachyon_rt.version() # not tested + 0.98.9 + sage: tachyon_rt.version() >= '0.98.9' + True + """ + with os.popen('tachyon') as f: + r = f.read() + return re.search(r"Version ([\d.]*)", r)[1] + def help(self, use_pager=True): """ Deprecated: type 'sage.interfaces.tachyon?' for help From 2252d382ff0662bd3c94d66e71439af40219970c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Wed, 8 Feb 2023 23:34:44 -0300 Subject: [PATCH 2/2] #34995: support debian version of tachyon Debian patches tachyon so it won't report the version. We hardcode '0.99' since that's the version they ship. --- src/sage/interfaces/tachyon.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sage/interfaces/tachyon.py b/src/sage/interfaces/tachyon.py index 21cc1db65ac..ce1d50f71bc 100644 --- a/src/sage/interfaces/tachyon.py +++ b/src/sage/interfaces/tachyon.py @@ -865,14 +865,17 @@ def version(self): TESTS:: - sage: tachyon_rt.version() # not tested + sage: tachyon_rt.version() # random 0.98.9 sage: tachyon_rt.version() >= '0.98.9' True """ with os.popen('tachyon') as f: - r = f.read() - return re.search(r"Version ([\d.]*)", r)[1] + r = f.readline() + res = re.search(r"Version ([\d.]*)", r) + # debian patches tachyon so it won't report the version + # we hardcode '0.99' since that's indeed the version they ship + return res[1] if res else '0.99' def help(self, use_pager=True): """