Skip to content

Commit

Permalink
Trac #23712: support tachyon >= 0.99.2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tornaria committed Feb 8, 2023
1 parent 104dde9 commit 749b68c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/sage/interfaces/tachyon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 749b68c

Please sign in to comment.