-
-
Notifications
You must be signed in to change notification settings - Fork 838
Expand file tree
/
Copy pathsage
More file actions
executable file
·1123 lines (1006 loc) · 41.6 KB
/
sage
File metadata and controls
executable file
·1123 lines (1006 loc) · 41.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# WARNING: this function is copy/pasted from both src/bin/sage-env and
# the top-level "sage" script. Please keep them synchronized.
resolvelinks() {
# $in is what still needs to be converted (normally has no starting slash)
in="$1"
# $out is the part which is converted (normally ends with trailing slash)
out="./"
# Move stuff from $in to $out
while [ -n "$in" ]; do
# Normalize $in by replacing consecutive slashes by one slash
in=$(echo "${in}" | sed 's://*:/:g')
# If $in starts with a slash, remove it and set $out to the root
in_without_slash=${in#/}
if [ "$in" != "$in_without_slash" ]; then
in=$in_without_slash
out="/"
continue
fi
# Check that the directory $out exists by trying to cd to it.
# If this fails, then cd will show an error message (unlike
# test -d "$out"), so no need to be more verbose.
( cd "$out" ) || return $?
# Get the first component of $in
f=${in%%/*}
# If it is not a symbolic link, simply move it to $out
if [ ! -L "$out$f" ]; then
in=${in#"$f"}
out="$out$f"
# If the new $in starts with a slash, move it to $out
in_without_slash=${in#/}
if [ "$in" != "$in_without_slash" ]; then
in=$in_without_slash
out="$out/"
fi
continue
fi
# Now resolve the symbolic link "$f"
f_resolved=`readlink -n "$out$f" 2>/dev/null`
status=$?
# status 127 means readlink could not be found.
if [ $status -eq 127 ]; then
# We don't have "readlink", try a stupid "ls" hack instead.
# This will fail if we have filenames like "a -> b".
fls=`ls -l "$out$f" 2>/dev/null`
status=$?
f_resolved=${fls##*-> }
# If $fls equals $f_resolved, then certainly
# something is wrong
if [ $status -eq 0 -a "$fls" = "$f_resolved" ]; then
echo >&2 "Cannot parse output from ls -l '$out$f'"
return 1
fi
fi
if [ $status -ne 0 ]; then
echo >&2 "Cannot read symbolic link '$out$f'"
return $status
fi
# In $in, replace $f by $f_resolved (leave $out alone)
in="${in#${f}}"
in="${f_resolved}${in}"
done
# Return $out
echo "$out"
}
# Resolve the links in $0 so that local/bin/sage can be executed from
# a symlink (Issue #30888).
SELF=$(resolvelinks "${0}")
# Display the current version of Sage
# usage: sage_version [-v]
# -v display the full version banner including release date
sage_version() {
if [ -f "${SELF}-version.sh" ]; then
. "${SELF}-version.sh"
else
. "$SAGE_ROOT/src/bin/sage-version.sh"
fi
if [ "$1" = "-v" ]; then
echo "${SAGE_VERSION_BANNER}"
else
echo "${SAGE_VERSION}"
fi
}
usage() {
sage_version -v
#### 1.......................26..................................................78
#### |.....................--.|...................................................|
echo
echo "Running Sage:"
echo
echo " file.[sage|py|spyx] -- run given .sage, .py or .spyx file"
echo " -c <cmd> -- evaluate cmd as sage code"
echo " --notebook=[...] -- start the Sage notebook (valid options are"
echo " 'default', 'jupyter', 'jupyterlab', and 'export')"
echo " Current default is 'jupyter'"
echo " -n, --notebook -- shortcut for --notebook=default"
echo " --nodotsage -- run Sage without using the user's .sage directory:"
echo " create and use a temporary .sage directory instead"
echo " -t [options] <--all|files|dir>"
echo " -- test examples in .py, .pyx, .sage, .tex or .rst files"
echo " selected options:"
echo " --long - include lines with the phrase 'long time'"
echo " --verbose - print debugging output during the test"
echo " --optional - controls which optional tests are run"
echo " --help - show all testing options"
echo
echo "Running external programs:"
echo
command -v gap &>/dev/null && \
echo " --gap [...] -- run Sage's Gap with given arguments"
command -v gp &>/dev/null && \
echo " --gp [...] -- run Sage's PARI/GP calculator with given arguments"
echo " --pip [...] -- invoke pip, the Python package manager"
command -v maxima &>/dev/null && \
echo " --maxima [...] -- run Sage's Maxima with given arguments"
command -v mwrank &>/dev/null && \
echo " --mwrank [...] -- run Sage's mwrank with given arguments"
echo " --python [...], --python3 [...] -- run the Python 3 interpreter"
command -v R &>/dev/null && \
echo " -R [...] -- run Sage's R with given arguments"
command -v singular &>/dev/null && \
echo " --singular [...] -- run Sage's singular with given arguments"
echo
echo "Getting help:"
echo
echo " -v, --version -- display Sage version information"
echo " -h, -?, --help -- print this help message"
echo " --advanced -- list all command line options"
if [ -d "$SAGE_ROOT" ]; then
exec "$SAGE_ROOT/build/bin/sage-site" "-h"
fi
exit 0
}
# 'usage_advanced', which prints a longer help message, is defined
# below, after sourcing sage-env.
# Determine SAGE_ROOT, SAGE_LOCAL, and SAGE_VENV.
unset SAGE_VENV
if [ -f "${SELF}-src-env-config" ]; then
# Not installed script, present only in src/bin/
. "${SELF}-src-env-config" >&2
fi
if [ -z "$SAGE_VENV" -a -x "${SELF}-venv-config" ]; then
# installed by setup.py
export SAGE_VENV=$("${SELF}-venv-config" SAGE_VENV)
fi
if [ -f "${SELF}-env-config" ]; then
# As of Issue #22731, sage-env-config is optional.
. "${SELF}-env-config" >&2
fi
#####################################################################
# Special options to be processed without sage-env
#####################################################################
# Check for '--nodotsage' before sourcing sage-env; otherwise sage-env
# will already have set some environment variables with the old
# setting for DOT_SAGE.
if [ "$1" = '--nodotsage' ]; then
export DOT_SAGE=`mktemp -d ${TMPDIR:-/tmp}/dotsageXXXXXX`
shift
command "${SELF}" "$@"
status=$?
rm -rf "$DOT_SAGE"
exit $status
fi
# build_sage, sage -b, sage -br, etc. could also be moved to
# build/bin/sage-site. See #29111; but OTOH #34627.
build_sage() {
# Check for the expected editable meson build directory
SCRIPT=$(readlink -f "$0") # this shell script
SAGE_ROOT=$(dirname "$SCRIPT")/../..
if [ -f "$SAGE_ROOT/build/sage-distro/build.ninja" ]; then
echo "Building Sage with ninja..."
ninja -C $SAGE_ROOT/build/sage-distro || exit $?
else
echo "Error: 'sage -b' is for editable sage-distro developer builds." >&2
echo "Please use 'make' or 'meson' directly for other builds." >&2
exit 1
fi
}
# Check for '-i' etc. before sourcing sage-env: running "make"
# should be run outside of the Sage shell.
case "$1" in
-i|-f|-p)
echo "\"sage -i\" is obsolete, and might not work." >&2
echo "Please use \"./configure --with-<package name>\" followed by \"make\" to update/install Sage's spkg," >&2
echo "and \"./sage --pip install <package name>\" to install external packages." >&2
if [ -n "$CONDA_PREFIX" ]; then
echo "Error: 'sage $1' is not supported in Conda environments." >&2
echo "Please use 'conda install' to install packages." >&2
exit 1
fi
# Delegate further option handling to the non-installed sage-site script.
# (These options become unavailable if the directory $SAGE_ROOT is removed.)
if [ -d "$SAGE_ROOT" ]; then
exec "$SAGE_ROOT/build/bin/sage-site" "$@"
# fallthrough if there is no sage-site script
fi
echo >&2 "Error: unknown option: $1"
exit 1
;;
-b)
build_sage
exit 0
;;
-br|--br)
echo "Warning: 'sage -br' is deprecated." >&2
echo "In an editable install, just run './sage' to use the latest built code." >&2
build_sage
shift; set -- -r "$@"
;;
-bn|--build-and-notebook)
build_sage
shift; set -- -n "$@" # delegate to handling of "-n" below, after sourcing sage-env
;;
-ba)
( cd "$SAGE_ROOT" && make sagelib-clean )
build_sage
exit 0
;;
-bt*)
build_sage
switch_without_b=-${1#-b}
shift; set -- $switch_without_b "$@" # delegate to handling of "-t...." below, after sourcing sage-env
;;
esac
#####################################################################
# Report information about the Sage environment
#####################################################################
if [ "$1" = '-dumpversion' -o "$1" = '--dumpversion' ]; then
sage_version
exit 0
fi
if [ "$1" = '-v' -o "$1" = '-version' -o "$1" = '--version' ]; then
sage_version -v
exit 0
fi
if [ "$1" = '-root' -o "$1" = '--root' ]; then
echo "$SAGE_ROOT"
exit 0
fi
#####################################################################
# Source sage-env ($SELF is the name of this "sage" script, so we can just
# append -env to that). We redirect stdout to stderr, which is safer
# for scripts.
#####################################################################
if [ -f "${SELF}-env" ]; then
. "${SELF}-env" >&2
if [ $? -ne 0 ]; then
echo >&2 "Error setting environment variables by sourcing '${SELF}-env';"
echo >&2 "possibly contact sage-devel (see http://groups.google.com/group/sage-devel)."
exit 1
fi
fi
if [ -f "${SELF}-src-env-config.in" ]; then
# The sage script is being run out of SAGE_ROOT/src/bin.
# In this case, put this directory in the front of the PATH.
export PATH="$SAGE_SRC/bin:$PATH"
fi
if [ -z "$DOT_SAGE" ]; then
export DOT_SAGE="$HOME/.sage"
fi
#####################################################################
# Helper functions
#####################################################################
# Prepare for running Sage, either interactively or non-interactively.
sage_setup() {
# Check that we're not in a source tarball which hasn't been built yet (#13561).
if [ "$SAGE_SRC_ENV_CONFIG" = 1 ] && [ ! -z "$SAGE_VENV" ] && [ ! -x "$SAGE_VENV/bin/sage" ]; then
echo >&2 '************************************************************************'
echo >&2 'It seems that you are attempting to run Sage from an unpacked source'
echo >&2 'tarball, but you have not compiled it yet (or maybe the build has not'
echo >&2 'finished). You should run `make` in the SAGE_ROOT directory first.'
echo >&2 'If you did not intend to build Sage from source, you should read'
echo >&2 'README.md for more information on available installation methods.'
echo >&2 '************************************************************************'
exit 1
fi
if [ ! -d "$IPYTHONDIR" ]; then
# make sure that $DOT_SAGE exists so that ipython will happily
# create its config directories there. If DOT_SAGE doesn't
# exist, ipython complains.
mkdir -p -m 700 "$DOT_SAGE"
fi
sage-cleaner &>/dev/null &
}
# Start an interactive Sage session, this function never returns.
interactive_sage() {
sage_setup
exec sage-ipython "$@" -i
}
#####################################################################
# sage --advanced
#####################################################################
usage_advanced() {
sage_version -v
#### 1.......................26..................................................78
#### |.....................--.|...................................................|
echo
if command -v sage-ipython &>/dev/null; then
echo "Running Sage, the most common options:"
echo
echo " file.[sage|py|spyx] -- run given .sage, .py or .spyx file"
echo " -c cmd -- evaluate cmd as sage code. For example,"
echo " \"sage -c 'print(factor(35))'\" will"
echo " print \"5 * 7\"."
echo
echo "Running Sage, other options:"
echo
echo " --preparse file.sage -- preparse \"file.sage\", and produce"
echo " the corresponding Python file"
echo " \"file.sage.py\""
echo " -q -- quiet; start with no banner"
echo " --min -- do not populate global namespace"
echo " (must be first option)"
echo " --nodotsage -- run Sage without using the user's"
echo " .sage directory: create and use a temporary"
echo " .sage directory instead."
echo " --gthread, --qthread, --q4thread, --wthread, --pylab"
echo " -- pass the option through to IPython"
echo " --simple-prompt -- pass the option through to IPython: use"
echo " this option with sage-shell mode in emacs"
echo " --gdb -- run Sage under the control of gdb"
echo " --lldb -- run Sage under the control of lldb"
else
echo "Running Sage:"
echo " (not installed currently, "
echo " to install, run sage --pip install sagemath-repl)"
fi
echo
echo "Running external programs:"
echo
echo " --cython [...] -- run Cython with the given arguments"
command -v cython &>/dev/null || \
echo " (not installed, run sage --pip install cython)"
echo " --ecl [...], --lisp [...] -- run Sage's copy of ECL (Embeddable"
echo " Common Lisp) with the given arguments"
echo " --gap [...] -- run Sage's Gap with the given arguments"
echo " --gap3 [...] -- run Sage's Gap3 with the given arguments"
command -v gap3 &>/dev/null || \
echo " (not installed currently, run sage -i gap3)"
echo " --git [...] -- run Sage's Git with the given arguments"
echo " --gp [...] -- run Sage's PARI/GP calculator with the"
echo " given arguments"
echo " --ipython [...], --ipython3 [...]"
echo " -- run Sage's IPython using the default"
echo " environment (not Sage), passing additional"
echo " additional options to IPython"
echo " --jupyter [...] -- run Sage's Jupyter with given arguments"
echo " --kash [...] -- run Sage's Kash with the given arguments"
command -v kash &>/dev/null || \
echo " (not installed currently, run sage -i kash)"
echo " --M2 [...] -- run Sage's Macaulay2 with the given arguments"
command -v M2 &>/dev/null || \
echo " (not installed currently, run sage -i macaulay2)"
echo " --maxima [...] -- run Sage's Maxima with the given arguments"
echo " --mwrank [...] -- run Sage's mwrank with the given arguments"
echo " --pip [...] -- invoke pip, the Python package manager"
echo " --polymake [...] -- run Sage's Polymake with given arguments"
command -v polymake &>/dev/null || \
echo " (not installed currently, run sage -i polymake)"
echo " --python [...], --python3 [...]"
echo " -- run the Python 3 interpreter"
echo " -R [...] -- run Sage's R with the given arguments"
echo " --singular [...] -- run Sage's singular with the given arguments"
echo " --sqlite3 [...] -- run Sage's sqlite3 with given arguments"
echo
echo "Running the notebook:"
echo
echo " -n [...], --notebook=[...]"
echo " -- start the notebook; valid options include"
echo " 'default', 'jupyter', 'jupyterlab', and 'export'."
echo " Current default is 'jupyter'."
echo " Run \"sage --notebook --help\" for more details."
echo
#### 1.......................26..................................................78
#### |.....................--.|...................................................|
echo "Testing files:"
echo
if command -v sage-runtests &>/dev/null; then
echo " -t [options] <files|dir> -- test examples in .py, .pyx, .sage"
echo " or .tex files. Options:"
echo " --long -- include lines with the phrase 'long time'"
echo " --verbose -- print debugging output during the test"
echo " --all -- test all files"
echo " --optional -- also test all examples labeled \"# optional\""
echo " --only-optional[=tags]"
echo " -- if no 'tags' are specified, only run"
echo " blocks of tests containing a line labeled"
echo " \"# optional\". If a comma-separated"
echo " list of tags is specified, only run block"
echo " containing a line labeled \"# optional tag\""
echo " for any of the tags given, and in these blocks"
echo " only run the lines which are unlabeled or"
echo " labeled \"# optional\" or labeled"
echo " \"# optional tag\" for any of the tags given."
echo " --randorder[=seed] -- randomize order of tests"
echo " --random-seed[=seed] -- random seed (integer) for fuzzing doctests"
echo " --new -- only test files modified since last commit"
echo " --initial -- only show the first failure per block"
echo " --debug -- drop into PDB after an unexpected error"
echo " --failed -- only test files that failed last test"
echo " --warn-long [timeout] -- warn if tests take too much CPU time"
echo " --only-errors -- only output failures, not successes"
echo " --gc=GC -- control garbage collection (ALWAYS:"
echo " collect garbage before every test; NEVER:"
echo " disable gc; DEFAULT: Python default)"
echo " --short[=secs] -- run as many doctests as possible in about 300"
echo " seconds (or the number of seconds given.) This runs"
echo " the tests for each module from the top of the file"
echo " and skips tests once it exceeds the budget"
echo " allocated for that file."
echo " --help -- show all doctesting options"
echo " --tnew [...] -- equivalent to -t --new"
echo " -tp <N> [...] -- like -t above, but tests in parallel using"
echo " N threads, with 0 interpreted as min(8, cpu_count())"
echo " --testall [options] -- equivalent to -t --all"
echo
echo " --coverage <files> -- give information about doctest coverage of files"
echo " --coverageall -- give summary info about doctest coverage of"
echo " all files in the Sage library"
echo " --startuptime [module] -- display how long each component of Sage takes to"
echo " start up; optionally specify a module to get more"
echo " details about that particular module"
else
echo " -t [options] <files|dir> -- test examples in .py, .pyx, .sage"
echo " or .tex files."
echo " (not installed currently, to install,"
echo " run sage --pip install sagemath-repl)"
fi
if [ -n "$SAGE_SRC" -a -f "$SAGE_SRC/tox.ini" ]; then
echo " --tox [options] <files|dirs> -- general entry point for testing"
echo " and linting of the Sage library"
echo " -e <envlist> -- run specific test environments; default:"
echo " $(echo $(tox -c "$SAGE_SRC" --listenvs 2>/dev/null) | sed 's/ /,/g;')"
tox -c "$SAGE_SRC" --listenvs-all -v 2>/dev/null | sed -n '/->/s/^/ /;s/(/\
(/;s/->/ --/p;'
echo " -p auto -- run test environments in parallel"
echo " --help -- show tox help"
command -v tox &>/dev/null || \
echo " (not installed currently, run sage -i tox)"
echo " --pytest [options] <files|dirs> -- run pytest on the Sage library"
command -v pytest &>/dev/null || \
echo " (not installed currently, run sage -i pytest)"
echo " --help -- show pytest help"
fi
echo
echo "Some developer utilities:"
echo
if [ -n "$SAGE_SRC" -a -d "$SAGE_SRC" ]; then
echo " --grep [options] <string>"
echo " -- regular expression search through the Sage"
echo " library for \"string\". Any options will"
echo " get passed to the \"grep\" command."
echo " --grepdoc [options] <string>"
echo " -- regular expression search through the"
echo " Sage documentation for \"string\"."
echo " --search_src ... -- same as --grep"
echo " --search_doc ... -- same as --grepdoc"
echo " --fixdoctests file.py"
echo " -- Run doctests and replace output of failing doctests"
echo " with actual output."
fi
echo " --sh [...] -- run a shell with Sage environment variables"
echo " as they are set in the runtime of Sage"
echo " --cleaner -- run the Sage cleaner. This cleans up after Sage,"
echo " removing temporary directories and spawned processes."
echo " (This gets run by Sage automatically, so it is usually"
echo " not necessary to run it separately.)"
#### 1.......................26..................................................78
#### |.....................--.|...................................................|
echo "File conversion:"
echo
echo " --rst2ipynb [...] -- Generates Jupyter notebook (.ipynb) from standalone"
echo " reStructuredText source."
command -v rst2ipynb &>/dev/null || \
echo " (not installed currently, run sage -i rst2ipynb)"
echo " --ipynb2rst [...] -- Generates a reStructuredText source file from"
echo " a Jupyter notebook (.ipynb)."
echo
#### 1.......................26..................................................78
#### |.....................--.|...................................................|
echo "Valgrind memory debugging:"
echo
echo " --cachegrind -- run Sage using Valgrind's cachegrind tool. The log"
echo " files are named sage-cachegrind.PID can be found in"
echo " \$DOT_SAGE"
echo " --callgrind -- run Sage using Valgrind's callgrind tool. The log"
echo " files are named sage-callgrind.PID can be found in"
echo " \$DOT_SAGE"
echo " --massif -- run Sage using Valgrind's massif tool. The log"
echo " files are named sage-massif.PID can be found in"
echo " \$DOT_SAGE"
echo " --memcheck -- run Sage using Valgrind's memcheck tool. The log"
echo " files are named sage-memcheck.PID can be found in"
echo " \$DOT_SAGE"
echo " --omega -- run Sage using Valgrind's omega tool. The log"
echo " files are named sage-omega.PID can be found in"
echo " \$DOT_SAGE"
echo " --valgrind -- this is an alias for --memcheck"
echo
echo "Getting help:"
echo
echo " -v, --version -- display Sage version information"
echo " --dumpversion -- print brief Sage version"
echo " -h, -?, --help -- print a short help message"
echo " --advanced -- list all command line options"
if [ -d "$SAGE_ROOT" ]; then
exec "$SAGE_ROOT/build/bin/sage-site" "--advanced"
fi
echo
exit 0
}
if [ $# -gt 0 ]; then
if [ "$1" = '-h' -o "$1" = '-?' -o "$1" = '-help' -o "$1" = '--help' ]; then
usage
fi
if [ "$1" = "-advanced" -o "$1" = "--advanced" ]; then
usage_advanced
fi
fi
#####################################################################
# Running Sage
#####################################################################
if [ "$1" = '-min' -o "$1" = '--min' ]; then
shift
export SAGE_IMPORTALL=no
fi
if [ "$1" = '-q' ]; then
shift
export SAGE_BANNER=no
fi
if [ $# -eq 0 ]; then
interactive_sage
fi
#####################################################################
# Other basic options
#####################################################################
if [ "$1" = '-c' ]; then
shift
sage_setup
exec sage-eval "$@"
fi
if [ "$1" = '-preparse' -o "$1" = "--preparse" ]; then
shift
exec sage-preparse "$@"
fi
if [ "$1" = '-cleaner' -o "$1" = '--cleaner' ]; then
exec sage-cleaner
fi
#####################################################################
# Run Sage's versions of Python, pip, IPython, Jupyter.
#####################################################################
if [ "$1" = '-pip' -o "$1" = '--pip' -o "$1" = "--pip3" ]; then
shift
exec python3 -m pip --disable-pip-version-check "$@"
fi
if [ "$1" = '-python' -o "$1" = '--python' -o "$1" = '-python3' -o "$1" = '--python3' ]; then
shift
exec python3 "$@"
fi
if [ "$1" = '-ipython' -o "$1" = '--ipython' -o "$1" = '-ipython3' -o "$1" = '--ipython3' ]; then
shift
exec ipython3 "$@"
fi
if [ "$1" = '-jupyter' -o "$1" = '--jupyter' ]; then
shift
exec jupyter "$@"
fi
#####################################################################
# Run Sage's versions of its component packages
#####################################################################
if [ "$1" = "-cython" -o "$1" = '--cython' -o "$1" = '-pyrex' -o "$1" = "--pyrex" ]; then
shift
exec cython "$@"
fi
if [ "$1" = '-gap' -o "$1" = '--gap' ]; then
shift
# Use "-A" to avoid warnings about missing packages. The gap
# interface and libgap within sage both already do this.
exec gap -A "$@"
fi
if [ "$1" = '-gap3' -o "$1" = '--gap3' ]; then
shift
exec gap3 "$@"
fi
if [ "$1" = '-gp' -o "$1" = '--gp' ]; then
shift
exec gp "$@"
fi
if [ "$1" = '-polymake' -o "$1" = '--polymake' ]; then
shift
exec polymake "$@"
fi
if [ "$1" = '-singular' -o "$1" = '--singular' ]; then
shift
exec Singular "$@"
fi
if [ "$1" = '-sqlite3' -o "$1" = '--sqlite3' ]; then
shift
exec sqlite3 "$@"
fi
if [ "$1" = '-ecl' -o "$1" = '--ecl' ]; then
shift
exec ecl "$@"
fi
if [ "$1" = '-lisp' -o "$1" = '--lisp' ]; then
shift
exec ecl "$@"
fi
if [ "$1" = '-kash' -o "$1" = '--kash' ]; then
shift
exec kash "$@"
fi
if [ "$1" = '-maxima' -o "$1" = '--maxima' ]; then
shift
maxima_cmd=$(sage-config MAXIMA 2>/dev/null)
if [ -z "${maxima_cmd}" ]; then
maxima_cmd="maxima"
fi
exec $maxima_cmd "$@"
fi
if [ "$1" = '-mwrank' -o "$1" = '--mwrank' ]; then
shift
exec mwrank "$@"
fi
if [ "$1" = '-M2' -o "$1" = '--M2' ]; then
shift
exec M2 "$@"
fi
if [ "$1" = '-R' -o "$1" = '--R' ]; then
shift
exec R "$@"
fi
if [ "$1" = '-git' -o "$1" = '--git' ]; then
shift
exec git "$@"
fi
#####################################################################
# sage --sh and sage --buildsh
#####################################################################
if [ "$1" = '-sh' -o "$1" = '--sh' -o "$1" = '-buildsh' -o "$1" = '--buildsh' ]; then
# AUTHORS:
# - Carl Witty and William Stein: initial version
# - Craig Citro: add options for not loading profile
# - Martin Albrecht: fix zshell prompt (#11866)
# - John Palmieri: shorten the prompts, and don't print messages if
# there are more arguments to 'sage -sh' (#11790)
if [ -z "$SAGE_SHPROMPT_PREFIX" ]; then
SAGE_SHPROMPT_PREFIX=sage-sh
fi
if [ "$1" = '-buildsh' -o "$1" = '--buildsh' ]; then
if [ ! -r "$SAGE_ROOT"/build/bin/sage-build-env-config ]; then
echo "error: '$SAGE_ROOT' does not contain build/bin/sage-build-env-config. Run configure first."
exit 1
fi
. "$SAGE_ROOT"/build/bin/sage-build-env-config || (echo "error: Error sourcing $SAGE_ROOT/build/bin/sage-build-env-config"; exit 1)
. "$SAGE_ROOT"/build/bin/sage-build-env || (echo "error: Error sourcing $SAGE_ROOT/build/bin/sage-build-env"; exit 1)
export SAGE_SHPROMPT_PREFIX=sage-buildsh
# We export it so that recursive invocation of 'sage-sh' from a sage-buildsh shows the sage-buildsh prompt;
# this makes sense because all environment variables set in build/bin/sage-build-env-config
# and build/bin/sage-build-env are exported.
fi
shift
# If $SHELL is unset, default to bash
if [ -z "$SHELL" ]; then
export SHELL=bash
fi
# We must start a new shell with no .profile or .bashrc files
# processed, so that we know our path is correct
SHELL_NAME=`basename "$SHELL"`
# Check for SAGE_SHPROMPT. If defined, use for the prompt. If
# not, check for already-defined $PS1, and if defined use that.
# $PS1 should only be available if it is defined in
# $DOT_SAGE/sagerc.
if [ -n "$SAGE_SHPROMPT" ]; then
oldPS1=$SAGE_SHPROMPT
elif [ -n "$PS1" ]; then
oldPS1=$PS1
fi
# Set the default prompt. If available, use reverse video to
# highlight the string "(sage-sh)".
if tput rev &>/dev/null; then
color_prompt=yes
fi
case "$SHELL_NAME" in
bash)
SHELL_OPTS="--norc"
if [ "$color_prompt" = yes ]; then
PS1="\[$(tput rev)\]($SAGE_SHPROMPT_PREFIX)\[$(tput sgr0)\] \u@\h:\W\$ "
else
PS1="($SAGE_SHPROMPT_PREFIX) \u@\h:\w\$ "
fi
export PS1
;;
csh)
# csh doesn't seem to allow the specification of a different
# .cshrc file, and the prompt can only be set in this file, so
# don't bother changing the prompt.
SHELL_OPTS="-f"
;;
ksh)
SHELL_OPTS="-p"
if [ "$color_prompt" = yes ] ; then
PS1="$(tput rev)($SAGE_SHPROMPT_PREFIX)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
else
PS1="($SAGE_SHPROMPT_PREFIX) $USER@`hostname -s`:\${PWD##*/}$ "
fi
export PS1
;;
sh)
# We don't really know which shell "sh" is (it could be
# bash, but this is not guaranteed), so we don't set
# SHELL_OPTS.
if [ "$color_prompt" = yes ] ; then
PS1="$(tput rev)($SAGE_SHPROMPT_PREFIX)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
else
PS1="($SAGE_SHPROMPT_PREFIX) $USER@`hostname -s`:\${PWD}$ "
fi
export PS1
;;
tcsh)
# tcsh doesn't seem to allow the specification of a different
# .tcshrc file, and the prompt can only be set in this file, so
# don't bother changing the prompt.
SHELL_OPTS="-f"
;;
zsh)
PS1="%S($SAGE_SHPROMPT_PREFIX)%s %n@%m:%~$ "
# In zsh, the system /etc/zshenv is *always* run,
# and this may change the path (like on OSX), so we'll
# create a temporary .zshenv to reset the path
ZDOTDIR=$DOT_SAGE && export ZDOTDIR
cat >"$ZDOTDIR/.zshenv" <<EOF
PATH="$PATH" && export PATH
EOF
SHELL_OPTS=" -d"
export PS1
;;
*)
export PS1='($SAGE_SHPROMPT_PREFIX) $ '
;;
esac
if [ -n "$oldPS1" ]; then
PS1="$oldPS1"
export PS1
fi
if [ $# -eq 0 ]; then
# No arguments, so print informative message...
echo >&2
echo >&2 "Starting subshell with Sage environment variables set. Don't forget"
echo >&2 "to exit when you are done. Beware:"
echo >&2 " * Do not do anything with other copies of Sage on your system."
echo >&2 " * Do not use this for installing Sage packages using \"sage -i\" or for"
echo >&2 " running \"make\" at Sage's root directory. These should be done"
echo >&2 " outside the Sage shell."
echo >&2
if [ -n "$SHELL_OPTS" ]; then
echo >&2 "Bypassing shell configuration files..."
echo >&2
fi
echo >&2 "Note: SAGE_ROOT=$SAGE_ROOT"
"$SHELL" $SHELL_OPTS "$@"
status=$?
echo "Exited Sage subshell." 1>&2
else
exec "$SHELL" $SHELL_OPTS "$@"
# If 'exec' returns, an error occurred:
status=$?
echo >&2 "Fatal error: 'exec \"$SHELL\" \"$@\"' failed!"
fi
exit $status
fi
#####################################################################
# File conversion
#####################################################################
if [ "$1" = '-rst2ipynb' -o "$1" = '--rst2ipynb' ]; then
shift
rst2ipynb --kernel=sagemath "$@"
status="${?}"
if [ "${status}" -eq "127" ] ; then echo 'rst2ipynb is not installed, please run "sage -i rst2ipynb"' ; fi
exit ${status}
fi
if [ "$1" = '-ipynb2rst' -o "$1" = '--ipynb2rst' ]; then
shift
exec sage-ipynb2rst "$@"
fi
#####################################################################
# The notebook, grep, building Sage, testing Sage
#####################################################################
if [[ "$1" =~ ^--notebook=.* || "$1" =~ ^-n=.* || "$1" =~ ^-notebook=.* ]] ; then
sage-cleaner &>/dev/null &
exec sage-notebook "$@"
fi
if [ "$1" = "-notebook" -o "$1" = '--notebook' -o "$1" = '-n' ]; then
sage-cleaner &>/dev/null &
exec sage-notebook "$@"
fi
if [ "$1" = "-bn" -o "$1" = "--build-and-notebook" ]; then
shift
build_sage
sage-cleaner &>/dev/null &
exec sage-notebook --notebook=default "$@"
fi
if [ -n "$SAGE_SRC" -a -d "$SAGE_SRC" ]; then
# Source inspection facilities, supported on sage-the-distribution and on distributions
# that package the Sage sources.
if [ "$1" = '-grep' -o "$1" = "--grep" -o "$1" = "-search_src" -o "$1" = "--search_src" ]; then
shift
sage-grep "$@"
exit 0
fi
if [ "$1" = '-grepdoc' -o "$1" = "--grepdoc" -o "$1" = "-search_doc" -o "$1" = "--search_doc" ]; then
shift
sage-grepdoc "$@"
exit 0
fi
fi
if [ "$1" = '-r' ]; then
shift
interactive_sage
fi
exec-runtests() {
sage_setup
export PYTHONIOENCODING="utf-8" # Fix encoding for doctests
exec sage-runtests "$@"
}
if [ "$1" = '-t' -o "$1" = '-tp' ]; then
if [ "$1" = '-tp' ]; then
shift
exec-runtests -p "$@"
else
shift
exec-runtests "$@"
fi
fi
if [ "$1" = '-tnew' ]; then
shift
exec-runtests --new "$@"
fi
if [ "$1" = '-testall' -o "$1" = "--testall" ]; then
shift
exec-runtests -a "$@"
fi
if [ "$1" = '-fixdoctests' -o "$1" = '--fixdoctests' ]; then
shift
exec sage-fixdoctests "$@"
fi
if [ "$1" = "-coverage" -o "$1" = "--coverage" ]; then
shift
exec sage-coverage "$@"
fi
if [ "$1" = "-coverageall" -o "$1" = "--coverageall" ]; then
shift
exec sage-coverage --all "$@"
fi
if [ "$1" = '-startuptime' -o "$1" = '--startuptime' ]; then
exec sage-startuptime.py "$@"
fi
if [ "$1" = '-tox' -o "$1" = '--tox' ]; then
shift
if [ -n "$SAGE_SRC" -a -f "$SAGE_SRC/tox.ini" ]; then
if command -v tox >/dev/null ; then
exec tox -c "$SAGE_SRC" "$@"
else
echo "Run 'sage -i tox' to install"
exit 1
fi
else
echo >&2 "error: Sage source directory or tox.ini not available"
exit 1
fi
fi
if [ "$1" = '-pytest' -o "$1" = '--pytest' ]; then
shift
if [ -n "$SAGE_SRC" -a -f "$SAGE_SRC/tox.ini" ]; then
if command -v pytest >/dev/null ; then
# If no non-option arguments are given, provide one
for a in $*; do
case $a in
-*) ;;
*) exec pytest --rootdir="$SAGE_SRC" --doctest "$@"
esac
done
exec pytest --rootdir="$SAGE_SRC" --doctest "$@" "$SAGE_SRC"
else
echo "Run 'sage -i pytest' to install"
exit 1
fi
else
echo >&2 "error: Sage source directory or tox.ini not available"
exit 1
fi
fi
#####################################################################
# Building the Sage documentation
#####################################################################
if [ "$1" = "-docbuild" -o "$1" = "--docbuild" ]; then
shift
# Issue #30002: ensure an English locale so that it is possible to
# scrape out warnings by pattern matching.
export LANG=C
export LANGUAGE=C