forked from sympy/sympy
/
isympy
executable file
·153 lines (112 loc) · 4.13 KB
/
isympy
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
#! /usr/bin/env python
"""Python shell for SymPy.
This is just a normal Python shell (IPython shell if you have the
IPython package installed), that executes the following commands
for the user:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z = symbols("xyz")
>>> k, m, n = symbols("kmn", integer=True)
>>> f, g, h = map(Function, 'fgh')
So starting 'isympy' is equivalent to starting Python (or IPython)
and executing the above commands by hand. It is intended for easy
and quick experimentation with SymPy.
COMMAND LINE OPTIONS
--------------------
-c CONSOLE, --console=CONSOLE
Use the specified Python or IPython shell as console backend instead
of the default one (IPython if present or Python otherwise), e.g.:
isympy -c python
-p PRETTY, --pretty PRETTY
Setup pretty printing in SymPy. By default the most pretty, Unicode
printing is enabled. User can use less pretty ASCII printing instead
or no pretty printing at all, e.g.:
-q, --quiet
Print only Python's and SymPy's versions to stdout at startup.
-- IPython's options
Additionally you can pass command line options directly to IPython
interpreter (standard Python shell is not supported). However you
need to add '--' separator between two types of options. To run
SymPy without startup banner and colors, for example, issue:
isympy -q -- -colors NoColor
"""
import os, sys
# hook in-tree SymPy into Python path, if possible
isympy_dir = os.path.dirname(__file__) # bin/isympy
sympy_top = os.path.split(isympy_dir)[0] # ../
sympy_dir = os.path.join(sympy_top, 'sympy') # ../sympy/
if os.path.isdir(sympy_dir):
sys.path.insert(0, sympy_top)
# some longer messages
long_message = """\
These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z = symbols('xyz')
>>> k, m, n = symbols('kmn', integer=True)
>>> f, g, h = map(Function, 'fgh')
Documentation can be found at http://sympy.org/
"""
no_ipython = """\
Couldn't locate IPython. Having IPython installed is greatly recommended.
See http://ipython.scipy.org for more details. If you use Debian/Ubuntu,
just install the 'ipython' package and start isympy again.
"""
from sympy.interactive import init_session
def main():
from sympy import __version__ as sympy_version
py_version = "%d.%d.%d" % sys.version_info[:3]
from optparse import OptionParser
usage = 'usage: isympy [options] -- [ipython options]'
parser = OptionParser(usage, version=sympy_version)
parser.add_option(
'-c', '--console',
dest='console',
action='store',
default=None,
help='select type of interactive session: IPython | Python')
parser.add_option(
'-p', '--pretty',
dest='pretty',
action='store',
default="any",
help='setup pretty printing: Unicode | ASCII | any | no')
parser.add_option(
'-q', '--quiet',
dest='quiet',
action='store_true',
default=False,
help='print only version information at startup')
(options, ipy_args) = parser.parse_args()
session = options.console
if session is not None:
session = session.lower()
args = {
'argv' : ipy_args,
'pretty' : True,
'use_unicode' : None,
}
pretty = options.pretty.lower()
if pretty != 'any':
if pretty == 'unicode':
args['use_unicode'] = True
else:
args['use_unicode'] = False
if pretty != 'ascii':
if pretty == 'no':
args['pretty'] = False
else:
raise ValueError("Unknown pretty" \
" printing setup: " + options.pretty)
if not options.quiet:
args['message'] = long_message
try:
init_session(session, **args)
except ValueError:
try:
init_session('ipython', **args)
except ImportError:
print no_ipython
init_session('python', **args)
if __name__ == "__main__":
main()