Skip to content

Commit 5734d2a

Browse files
committed
#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.
1 parent 104dde9 commit 5734d2a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/sage/interfaces/tachyon.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,14 @@
683683
#*****************************************************************************
684684

685685
import os
686+
import re
686687

687688
from sage.cpython.string import bytes_to_str
688689
from sage.misc.pager import pager
689690
from sage.misc.superseded import deprecation
690691
from sage.misc.temporary_file import tmp_filename
691692
from sage.structure.sage_object import SageObject
693+
from sage.misc.cachefunc import cached_method
692694

693695

694696
class TachyonRT(SageObject):
@@ -799,6 +801,11 @@ def __call__(self, model, outfile='sage.png', verbose=1, extra_opts=''):
799801
Parser failed due to an input file syntax error.
800802
Aborting render.
801803
"""
804+
if self.version() >= '0.99.2':
805+
# this keyword was changed in 0.99.2
806+
model = model.replace(
807+
" focallength ",
808+
" focaldist ")
802809
modelfile = tmp_filename(ext='.dat')
803810
with open(modelfile, 'w') as file:
804811
file.write(model)
@@ -851,6 +858,22 @@ def usage(self, use_pager=True):
851858
else:
852859
print(r)
853860

861+
@cached_method
862+
def version(self):
863+
"""
864+
Returns the version of the Tachyon raytracer being used.
865+
866+
TESTS::
867+
868+
sage: tachyon_rt.version() # not tested
869+
0.98.9
870+
sage: tachyon_rt.version() >= '0.98.9'
871+
True
872+
"""
873+
with os.popen('tachyon') as f:
874+
r = f.read()
875+
return re.search(r"Version ([\d.]*)", r)[1]
876+
854877
def help(self, use_pager=True):
855878
"""
856879
Deprecated: type 'sage.interfaces.tachyon?' for help

0 commit comments

Comments
 (0)