Anonymous avatar Anonymous committed 20bc39c

Get version info into autogenerated .sout file.

Comments (0)

Files changed (2)

 %   |.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.
+%   versions don't match and the user hasn't disabled checking. Note
+%   that we use |^^J| and not |^^J%| when we need indented lines. Also,
+%   |sagetex.py| now includes a |version| variable which eliminates all
+%   the irritating string munging below, and later we can remove this
+%   stuff and just use |sagetex.version|.
 %   \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 with sagetex.sty version \ST@ver.}%
-\ST@wsf{import sagetex}%
-\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('[').split()[0:2]))}%
-\ST@wsf{ print 'SageTeX version mismatch! Exiting.'}%
-\ST@wsf{ sys.exit(int(1))}}%
+\ST@wsf{%
+# This file (\jobname.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}.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))}}%
 %    \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}
 % try/except around the function call so that we can provide a more
 % helpful error message in case something goes wrong. (In particular, we
 % can tell the user which line of the |.tex| file contains the offending
-% code.) We can use |^^J| to put linebreaks into the |.sage| file, but
-% \LTX wants to put a space after that, which is why we don't put the
-% ``except'' on its own line here in the source.
+% code.) Note the difference between |^^J| and |^^J%|: the newline
+% immediately after the former puts a space into the output, and the
+% percent sign in the latter supresses this.
 %    \begin{macrocode}
 \newcommand{\ST@sage}[1]{\ST@wsf{%
 try:^^J
- _st_.inline(\theST@inline, #1)^^Jexcept:^^J
+ _st_.inline(\theST@inline, #1)^^J%
+except:^^J
  _st_.goboom(\the\inputlineno)}%
 %    \end{macrocode}
 % The |inline| function of the Python module is documented on page
 % someone does that, warn them. We do this right away so that we print
 % this and exit before trying to import any Sage modules; that way, this
 % error message gets printed whether you run the script with Sage or
-% with Python.
+% with Python. Since \ST is now distributed with Sage and |sagetex.py|
+% now lives almost exclusively deep within the Sage ecosystem, this
+% check is not so necessary and will be removed sometime soon.
 %    \begin{macrocode}
 import sys
 if __name__ == "__main__":
 LaTeX document using the SageTeX package.""")
   sys.exit()
 %    \end{macrocode}
-% Import what we need:
+% Munge the version string (which we get from
+% \texttt{sagetexpackage.dtx}) to extract what we want, then import what
+% we need:
 %    \begin{macrocode}
+version = ' '.join(__version__.strip('[').split()[0:2])
 from sage.misc.latex import latex
 import os
 import os.path
 % we're done, we move that to |.sout|. The ``autogenerated'' line is
 % basically the same as the lines that get put at the top of preparsed
 % Sage files; we are automatically generating a file with Sage, so it
-% seems reasonable to add it.
+% seems reasonable to add it. Add in the version to help debugging
+% version mismatch problems.
 %    \begin{macrocode}
     self.souttmp = open(self.filename + '.sout.tmp', 'w')
-    s = '% This file was *autogenerated* from the file ' + \
-        os.path.splitext(jobname)[0] + '.sage.\n'
-    self.souttmp.write(s)
+    self.souttmp.write("""% This file was *autogenerated* from {0}.sage with
+ % sagetex.py version {1}\n""".format(os.path.splitext(jobname)[0], version))
 %    \end{macrocode}
+% Don't remove the space before the percent sign above!
 %
 % \begin{macro}{progress}
 % This function just prints stuff. It allows us to not print a

sagetexpackage.dtx

 %</driver>
 % \fi
 %
-% \CheckSum{357}
+% \CheckSum{347}
 %
 % \CharacterTable
 %  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
 % Because of this, I strongly recommend using \ST only from what is
 % included with Sage and ignoring what's included with \TeX Live.
 %
-% \paragraph{The noversioncheck option}
+% \subsection{The noversioncheck option}
+% \label{sec:noversioncheck}
 %
 % As of version 2.2.4, \ST automatically checks to see if the versions
 % of the style file and Python module match. This is intended to prevent
 %
 % If you are considering using this option because the Sage script
 % complained and exited, you really should just get the \LTX and Python
-% modules synchronized. Every copy of Sage starting with version 4.3.2
-% comes with a copy of |sagetex.sty| that is matched up to Sage's
-% baked-in \ST support, so you can always use that. See the
+% modules synchronized. Every copy of Sage since version 4.3.2 comes
+% with a copy of |sagetex.sty| that is matched up to Sage's baked-in \ST
+% support, so you can always use that. See the
 % \href{http://sagemath.org/doc/installation/}{\ST section of the Sage
 %   installation guide}.
 %
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.