1. Dan Drake
  2. SageTeX


Dan Drake  committed 38ad591

change version check to be more robust; include hg rev in version info

  • Participants
  • Parent commits 6cc763c
  • Branches default
  • Tags v2.3.2

Comments (0)

Files changed (2)

File py-and-sty.dtx

View file
  • Ignore whitespace
 # This file (\jobname.sagetex.sage) was *autogenerated* from \jobname.tex with
 sagetex.sty version \ST@ver.^^J%
 import sagetex^^J%
-_st_ = sagetex.SageTeXProcessor('\jobname')^^J%
-_do_ver_check_ = \ST@versioncheck^^J%
-if _do_ver_check_ and sagetex.__version__.find('\ST@ver') == -1:^^J
-  import sys^^J
-  print '{0}.sagetex.sage was generated with sagetex.sty version \ST@ver,'.format(
-    sys.argv[0].split('.')[0])^^J
-  print 'but is being processed by sagetex.py version {0}.'.format(
-    ' '.join(sagetex.__version__.strip().strip('[').split()[0:2]))^^J
-  print 'SageTeX version mismatch! Exiting.'^^J
-  sys.exit(int(1))}}%
+_st_ = sagetex.SageTeXProcessor('\jobname', version='\ST@ver', version_check=\ST@versioncheck)}}%
 %    \end{macrocode}
 % On the other hand, if the |ST@final| flag is set, don't bother with
 % any of the file stuff, and make |\ST@wsf| a no-op.
 % \texttt{sagetex.dtx}) to extract what we want, then import what
 % we need:
 %    \begin{macrocode}
-version = ' '.join(__version__.strip('[').split()[0:2])
+pyversion = ' '.join(__version__.strip('[').split()[0:4])
 from sage.misc.latex import latex
 from sage.misc.preparser import preparse
 import os
 import subprocess
 import shutil
 %    \end{macrocode}
+% Define an exception class for version mismatches. I suppose I could
+% just use |ValueError|, but this is easy enough:
+%    \begin{macrocode}
+class VersionError(Exception):
+    pass
+%    \end{macrocode}
 % We define a class so that it's a bit easier to carry around internal
 % state. We used to just have some global variables and a bunch of
 % functions, but this seems a bit nicer and easier.
 % \changes{v2.3.1}{2011/02/02}{Handle filenames with
 % spaces in SageTeXProcessor and sagecommandline env.}
 %    \begin{macrocode}
-  def __init__(self, jobname):
+  def __init__(self, jobname, version=None, version_check=True):
+    if version_check and version != pyversion:
+      raise VersionError, """versions of .sty and .py files do not match.
+{0}.sagetex.sage was generated by sagetex.sty version "{1}", but
+is being processed by sagetex.py version "{2}".
+Please make sure that TeX is using the sagetex.sty 
+from your current version of Sage; see
+  version, pyversion)
     if ' ' in jobname:
       jobname = jobname.strip('"')
     self.progress('Processing Sage code for {0}.tex...'.format(jobname))

File sagetex.dtx

View file
  • Ignore whitespace
 %<python>__version__ = """
-  [2011/05/27 v2.3.1 embedding Sage into LaTeX documents]
+  [2012/01/13 v2.3.2 rev 6cc763c2b649 embedding Sage into LaTeX documents]
-%<latex>\newcommand{\ST@ver}{2011/05/27 v2.3.1}
+%<latex>\newcommand{\ST@ver}{2012/01/13 v2.3.2 rev 6cc763c2b649}