Skip to content

Commit 6726269

Browse files
committed
Polish the various utility scripts
Use argparse for more friendly argument parsing. Also, add a `sagetex-tool` script that can be installed on PATH (unlike makestatic.py etc. whose names are not suitable for that). Bundle the script files in the sagetex python package. Do it in a way they remain runnable standalone, as previously.
1 parent bf38e72 commit 6726269

File tree

6 files changed

+312
-185
lines changed

6 files changed

+312
-185
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ sagetex.py
2929
sagetex.pyc
3030
sagetex.sty
3131
sagetexparse.py
32+
__init__.py
33+
__main__.py
34+
run_if_necessary.py
35+
sagetex-tool
36+
sagetex/*.py
37+
__pycache__
3238
.*.sage-history
3339
.*.sage-chat
3440
MANIFEST

Makefile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ pkg=sagetex
22
dtxs=$(wildcard *.dtx)
33
# the subdir stuff makes the tarball have the directory correct
44
srcs=example.tex README sagetex.ins
5+
pyscripts=run-sagetex-if-necessary.py sagetex-tool
6+
pypkgfiles=__init__.py __main__.py sagetex.py makestatic.py extractsagecode.py sagetexparse.py run_if_necessary.py
7+
pypkg=$(addprefix sagetex/,$(pypkgfiles))
58

69
.SUFFIXES:
710

8-
all: sagetex.sty sagetex.py example.pdf $(pkg).pdf
11+
all: sagetex.sty $(pypkg) $(pyscripts) remote-sagetex.py $(pkg).pdf example.pdf
912

1013
# just depend on the .ind file, since we'll make the .gls and .ind together;
1114
# TEXOPTS is used by spkg-install to specify nonstopmode when building docs
@@ -32,17 +35,20 @@ example.pdf: example.tex sagetex.sty sagetex.py
3235
sagetex.sty: py-and-sty.dtx $(pkg).dtx
3336
yes | latex $(TEXOPTS) $(pkg).ins
3437

35-
sagetex.py: py-and-sty.dtx $(pkg).dtx
36-
yes | latex $(TEXOPTS) $(pkg).ins
37-
3838
remote-sagetex.py: remote-sagetex.dtx
3939
yes | latex $(TEXOPTS) $(pkg).ins
4040

41-
run-sagetex-if-necessary.py makestatic.py extractsagecode.py sagetexparse.py: scripts.dtx
41+
$(pypkgfiles) $(pyscripts): py-and-sty.dtx scripts.dtx
4242
yes | latex $(TEXOPTS) $(pkg).ins
43+
mv -f sagetex-tool.py sagetex-tool
44+
chmod +x sagetex-tool
45+
46+
$(pypkg): $(pypkgfiles)
47+
install -d sagetex
48+
cp -f $(notdir $@) sagetex/
4349

4450
clean: auxclean
45-
rm -fr sage-plots-for-* E2.sobj *.pyc sagetex.tar.gz sagetex.py sagetex.pyc sagetex.sty makestatic.py sagetexparse.py extractsagecode.py dist MANIFEST remote-sagetex.py auto *_doctest.sage *_doctest.sage.py example-*.table run-sagetex-if-necessary.py __pycache__
51+
rm -fr sage-plots-for-* E2.sobj *.pyc sagetex.tar.gz $(pypkg) $(pypkgfiles) $(pyscripts) sagetex.sty dist MANIFEST remote-sagetex.py auto *_doctest.sage *_doctest.sage.py example-*.table __pycache__ sagetex/
4652

4753
auxclean:
4854
/bin/bash -c "rm -f {$(pkg),example}.{glo,gls,aux,out,toc,dvi,pdf,ps,log,ilg,ind,idx,fdb_latexmk,sagetex.*}"
@@ -54,5 +60,5 @@ test:
5460
./test
5561

5662
# make a source distribution, used for building the spkg
57-
dist: sagetex.sty
63+
dist: sagetex.sty $(pypkg) $(pyscripts)
5864
python setup.py sdist --formats=gztar

py-and-sty.dtx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@
145145
# -*- encoding: utf-8 -*-^^J%
146146
# This file (\jobname.sagetex.sage) was *autogenerated* from \jobname.tex with
147147
sagetex.sty version \ST@ver.^^J%
148-
import sagetex^^J%
148+
% \end{macrocode}
149+
% We here allow installing |sagetex.py| either as a single Python module,
150+
% or as |sagetex.sagetex| inside a Python package.
151+
% \begin{macrocode}
152+
try: import sagetex.sagetex as sagetex^^J%
153+
except ImportError: import sagetex^^J%
149154
_st_ = sagetex.SageTeXProcessor('\jobname', version='\ST@ver', version_check=\ST@versioncheck)}}%
150155
% \end{macrocode}
151156
% On the other hand, if the |ST@final| flag is set, don't bother with
@@ -828,7 +833,7 @@ again}}
828833
% \end{macrocode}
829834
%
830835
%
831-
% \subsection{The Python module}
836+
% \subsection{The Python package}
832837
% \label{sec:py-file}
833838
%
834839
% \iffalse
@@ -1570,9 +1575,22 @@ SAGE_ROOT/local/share/doc/sagetex.""")
15701575
% % \changes{v2.1.1}{2009/05/14}{Fix bug in finding md5 sum introduced by
15711576
% pause facility}
15721577
% \end{macro}
1578+
% \iffalse
1579+
%</python>
1580+
% \fi
1581+
1582+
% \paragraph{Package \_\_init\_\_.py}
1583+
%
1584+
% We'll also create an empty |__init__.py| for including the above in a
1585+
% Python package, containing also the scripts.
1586+
%
1587+
% \iffalse
1588+
%<*initpy>
1589+
%</initpy>
1590+
% \fi
15731591

15741592
% \endinput
1575-
%</python>
1593+
15761594
% Local Variables:
15771595
% mode: doctex
15781596
% TeX-master: "sagetex.dtx"

sagetex.ins

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
8282

8383
\generate{\file{sagetex.py}{\from{sagetex.dtx}{python}
8484
\from{py-and-sty.dtx}{python}}}
85+
\generate{\file{__init__.py}{\from{py-and-sty.dtx}{initpy}}}
8586
\generate{\file{sagetexparse.py}{\from{scripts.dtx}{parsermod}}}
8687

8788

@@ -92,19 +93,22 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
9293
\def\envpypreamble{\hash!/usr/bin/env python^^J\pypreamble}
9394
\usepreamble\envpypreamble
9495

96+
\generate{\file{sagetex-tool.py}{\from{scripts.dtx}{sagetextool}}}
97+
\generate{\file{__main__.py}{\from{scripts.dtx}{mainpy}}}
9598
\generate{\file{run-sagetex-if-necessary.py}{\from{scripts.dtx}{ifnecessaryscript}}}
99+
\generate{\file{run_if_necessary.py}{\from{scripts.dtx}{ifnecessaryscript}}}
96100
\generate{\file{makestatic.py}{\from{scripts.dtx}{staticscript}}}
97101
\generate{\file{extractsagecode.py}{\from{scripts.dtx}{extractscript}}}
98102
\generate{\file{remote-sagetex.py}{\from{remote-sagetex.dtx}{remotesagetex}}}
99103

100104
\obeyspaces
101105
\Msg{******************************************************************}
102106
\Msg{* *}
103-
\Msg{* To finish the installation, move the following files *}
107+
\Msg{* To finish the installation, move the following file/package *}
104108
\Msg{* into directories searched by TeX and Sage, respectively: *}
105109
\Msg{* *}
106110
\Msg{* sagetex.sty *}
107-
\Msg{* sagetex.py *}
111+
\Msg{* sagetex/ *}
108112
\Msg{* *}
109113
\Msg{* See the documentation for complete installation details. *}
110114
\Msg{* *}

0 commit comments

Comments
 (0)