Skip to content

Commit

Permalink
gh-34995: Support for tachyon >= 0.99.2
Browse files Browse the repository at this point in the history
    
Taken from #23712.

This is necessary to support tachyon >= 0.99.2, without losing support
for older versions of tachyon.

In case #23712 gets delayed, it'd be nice to include this so nothing
breaks if system tachyon is updated. This is the first commit from the
branch there which already had positive review (the actual update of
tachyon has an issue mentioned in
#23712 (comment).)

_From the commit log:_

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.
    
URL: #34995
Reported by: Gonzalo Tornaría
Reviewer(s): Matthias Köppe, Mauricio Collares
  • Loading branch information
Release Manager committed Feb 26, 2023
2 parents 23ab380 + 2252d38 commit bf6c233
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 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,25 @@ 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() # random
0.98.9
sage: tachyon_rt.version() >= '0.98.9'
True
"""
with os.popen('tachyon') as f:
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):
"""
Deprecated: type 'sage.interfaces.tachyon?' for help
Expand Down

0 comments on commit bf6c233

Please sign in to comment.