Anonymous avatar Anonymous committed 5ec45d5

first go at version-match checking. Needs documentation.

Comments (0)

Files changed (2)

 \immediate\openout\ST@sf=\jobname.sage%
 %    \end{macrocode}
 % \begin{macro}{\ST@wsf}
-% We will write a lot of stuff to that file, so make a convenient
-% abbreviation, then use it to put the initial commands into the
-% |.sage| file. The hash mark below gets doubled when written to the
-% file, for some obscure reason related to parameter expansion. It's
-% valid Python, though, so I haven't bothered figuring out how to get
-% a single hash. We are assuming that the extension is |.tex|; see the
-% |initplot| documentation on page~\pageref{initplot} for discussion
-% of file extensions. The ``|(\jobname.sage)|'' business is there
-% because the comment below will get pulled into the autogenerated
-% |.py| file (second order autogeneration!) and I'd like to reduce
-% possible confusion if someone is looking around in those files.
+%   We will write a lot of stuff to that file, so make a convenient
+%   abbreviation, then use it to put the initial commands into the
+%   |.sage| file. The hash mark below gets doubled when written to the
+%   file, for some obscure reason related to parameter expansion. It's
+%   valid Python, though, so I haven't bothered figuring out how to get
+%   a single hash. We are assuming that the extension is |.tex|; see the
+%   |initplot| documentation on page~\pageref{initplot} for discussion
+%   of file extensions. The ``|(\jobname.sage)|'' business is there
+%   because the comment below will get pulled into the autogenerated
+%   |.py| file (second order autogeneration!) and I'd like to reduce
+%   possible confusion if someone is looking around in those files.
+%   Finally, we check for version mismatch and bail if the .py and .sty
+%   versions don't match and the user hasn't disabled checking.
+%   \changes{v2.2.4}{2010/02/15}{Add version mismatch checking.}
 %    \begin{macrocode}
 \newcommand{\ST@wsf}[1]{\immediate\write\ST@sf{#1}}%
-\ST@wsf{# This file (\jobname.sage) was *autogenerated* from the file \jobname.tex.}%
+\ST@wsf{# This file (\jobname.sage) was *autogenerated* from the file
+  \jobname.tex with sagetex.sty version \ST@ver.}%
 \ST@wsf{import sagetex}%
-\ST@wsf{_st_ = sagetex.SageTeXProcessor('\jobname')}}%
+\ST@wsf{_st_ = sagetex.SageTeXProcessor('\jobname')}%
+\ST@wsf{_do_ver_check_ = \ST@versioncheck}%
+\ST@wsf{if _do_ver_check_ and sagetex.__version__.find('\ST@ver') == -1:}%
+\ST@wsf{ import sys}%
+\ST@wsf{ print '{0}.sage was generated with sagetex.sty version \ST@ver,'.format(sys.argv[0].split('.')[0])}%
+\ST@wsf{ print 'but is being processed by sagetex.py version {0}.'.format(join(sagetex.__version__.strip().strip('[').split()[0:2]))}%
+\ST@wsf{ print 'SageTeX version mismatch! Exiting.'}%
+\ST@wsf{ sys.exit(int(1))}}%
 %    \end{macrocode}
+% \iffalse
+%   Note for those whose editor highlights matching parens, etc: the '['
+%   in the ``being processed by'' line up there confuses both emacs and
+%   vim. To keep your sanity, try momentarily changing the [ to, say, x.
+% \fi
 % 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.
 %    \begin{macrocode}
   \@ifundefined{ST@final}{%
     \ST@wsf{_st_.useimagemagick = True}}{}}}
 %    \end{macrocode}
-% For |epstopdf|, we just set a flag for Sage. Then, process the options.
+% For |epstopdf|, we just set a flag for Sage.
 %    \begin{macrocode}
 \DeclareOption{epstopdf}{%
 \AtBeginDocument{%
 \@ifundefined{ST@final}{%
   \ST@wsf{_st_.useepstopdf = True}}{}}}
+%    \end{macrocode}
+% By default, we check to see if the .py and .sty file versions match.
+% But we let the user disable this.
+%    \begin{macrocode}
+\newcommand{\ST@versioncheck}{True}
+\DeclareOption{noversioncheck}{%
+  \renewcommand{\ST@versioncheck}{False}}
 \ProcessOptions\relax
 %    \end{macrocode}
 % The |\relax| is a little incantation suggested by the ``\LaTeXe{} for

sagetexpackage.dtx

 % \iffalse meta-comment
 %
-% Copyright (C) 2009 by Dan Drake <ddrake (at) member (dot) ams (dot) org>
+% Copyright (C) 2010 by Dan Drake <ddrake (at) member (dot) ams (dot) org>
 % -------------------------------------------------------
 %
 % See the "Copying and licenses" section in this file for the terms
 %<latex>\ProvidesPackage{sagetex}
 %<python>__version__ = """
 %<*latex|python>
-  [2009/12/30 v2.2.3 embedding Sage into LaTeX documents]
+  [2010/02/15 v2.2.4 embedding Sage into LaTeX documents]
 %</latex|python>
 %<python>"""
+%<latex>\newcommand{\ST@ver}{2010/02/15 v2.2.4}
 %<*driver>
 \documentclass{ltxdoc}
 \usepackage{sagetex}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.