Show More
The requested changes are too big and content was truncated. Show full diff
@@ -0,0 +1,158 b'' | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | # -*- coding: utf-8 -*- | |||
|
3 | """Setup script for IPython. | |||
|
4 | ||||
|
5 | Under Posix environments it works like a typical setup.py script. | |||
|
6 | Under Windows, the command sdist is not supported, since IPython | |||
|
7 | requires utilities, which are not available under Windows.""" | |||
|
8 | ||||
|
9 | #***************************************************************************** | |||
|
10 | # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu> | |||
|
11 | # | |||
|
12 | # Distributed under the terms of the BSD License. The full license is in | |||
|
13 | # the file COPYING, distributed as part of this software. | |||
|
14 | #***************************************************************************** | |||
|
15 | ||||
|
16 | import sys, os | |||
|
17 | from glob import glob | |||
|
18 | from setupext import install_data_ext | |||
|
19 | isfile = os.path.isfile | |||
|
20 | ||||
|
21 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly | |||
|
22 | # update it when the contents of directories change. | |||
|
23 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') | |||
|
24 | ||||
|
25 | if os.name == 'posix': | |||
|
26 | os_name = 'posix' | |||
|
27 | elif os.name in ['nt','dos']: | |||
|
28 | os_name = 'windows' | |||
|
29 | else: | |||
|
30 | print 'Unsupported operating system:',os.name | |||
|
31 | sys.exit(1) | |||
|
32 | ||||
|
33 | # Under Windows, 'sdist' is not supported, since it requires lyxport (and | |||
|
34 | # hence lyx,perl,latex,pdflatex,latex2html,sh,...) | |||
|
35 | if os_name == 'windows' and sys.argv[1] == 'sdist': | |||
|
36 | print 'The sdist command is not available under Windows. Exiting.' | |||
|
37 | sys.exit(1) | |||
|
38 | ||||
|
39 | #from distutils.core import setup | |||
|
40 | from setuptools import setup | |||
|
41 | ||||
|
42 | # update the manuals when building a source dist | |||
|
43 | if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'): | |||
|
44 | from IPython.genutils import target_update | |||
|
45 | # list of things to be updated. Each entry is a triplet of args for | |||
|
46 | # target_update() | |||
|
47 | to_update = [('doc/magic.tex', | |||
|
48 | ['IPython/Magic.py'], | |||
|
49 | "cd doc && ./update_magic.sh" ), | |||
|
50 | ||||
|
51 | ('doc/manual.lyx', | |||
|
52 | ['IPython/Release.py','doc/manual_base.lyx'], | |||
|
53 | "cd doc && ./update_version.sh" ), | |||
|
54 | ||||
|
55 | ('doc/manual/manual.html', | |||
|
56 | ['doc/manual.lyx', | |||
|
57 | 'doc/magic.tex', | |||
|
58 | 'doc/examples/example-gnuplot.py', | |||
|
59 | 'doc/examples/example-magic.py', | |||
|
60 | 'doc/examples/example-embed.py', | |||
|
61 | 'doc/examples/example-embed-short.py', | |||
|
62 | 'IPython/UserConfig/ipythonrc', | |||
|
63 | ], | |||
|
64 | "cd doc && " | |||
|
65 | "lyxport -tt --leave --pdf " | |||
|
66 | "--html -o '-noinfo -split +1 -local_icons' manual.lyx"), | |||
|
67 | ||||
|
68 | ('doc/new_design.pdf', | |||
|
69 | ['doc/new_design.lyx'], | |||
|
70 | "cd doc && lyxport -tt --pdf new_design.lyx"), | |||
|
71 | ||||
|
72 | ('doc/ipython.1.gz', | |||
|
73 | ['doc/ipython.1'], | |||
|
74 | "cd doc && gzip -9c ipython.1 > ipython.1.gz"), | |||
|
75 | ||||
|
76 | ('doc/pycolor.1.gz', | |||
|
77 | ['doc/pycolor.1'], | |||
|
78 | "cd doc && gzip -9c pycolor.1 > pycolor.1.gz"), | |||
|
79 | ] | |||
|
80 | for target in to_update: | |||
|
81 | target_update(*target) | |||
|
82 | ||||
|
83 | # Release.py contains version, authors, license, url, keywords, etc. | |||
|
84 | execfile(os.path.join('IPython','Release.py')) | |||
|
85 | ||||
|
86 | # A little utility we'll need below, since glob() does NOT allow you to do | |||
|
87 | # exclusion on multiple endings! | |||
|
88 | def file_doesnt_endwith(test,endings): | |||
|
89 | """Return true if test is a file and its name does NOT end with any | |||
|
90 | of the strings listed in endings.""" | |||
|
91 | if not isfile(test): | |||
|
92 | return False | |||
|
93 | for e in endings: | |||
|
94 | if test.endswith(e): | |||
|
95 | return False | |||
|
96 | return True | |||
|
97 | ||||
|
98 | # I can't find how to make distutils create a nested dir. structure, so | |||
|
99 | # in the meantime do it manually. Butt ugly. | |||
|
100 | # Note that http://www.redbrick.dcu.ie/~noel/distutils.html, ex. 2/3, contain | |||
|
101 | # information on how to do this more cleanly once python 2.4 can be assumed. | |||
|
102 | # Thanks to Noel for the tip. | |||
|
103 | docdirbase = 'share/doc/ipython-%s' % version | |||
|
104 | manpagebase = 'share/man/man1' | |||
|
105 | ||||
|
106 | # We only need to exclude from this things NOT already excluded in the | |||
|
107 | # MANIFEST.in file. | |||
|
108 | exclude = ('.sh','.1.gz') | |||
|
109 | docfiles = filter(lambda f:file_doesnt_endwith(f,exclude),glob('doc/*')) | |||
|
110 | ||||
|
111 | examfiles = filter(isfile, glob('doc/examples/*.py')) | |||
|
112 | manfiles = filter(isfile, glob('doc/manual/*.html')) + \ | |||
|
113 | filter(isfile, glob('doc/manual/*.css')) + \ | |||
|
114 | filter(isfile, glob('doc/manual/*.png')) | |||
|
115 | manpages = filter(isfile, glob('doc/*.1.gz')) | |||
|
116 | cfgfiles = filter(isfile, glob('IPython/UserConfig/*')) | |||
|
117 | scriptfiles = filter(isfile, ['scripts/ipython','scripts/pycolor']) | |||
|
118 | ||||
|
119 | # Script to be run by the windows binary installer after the default setup | |||
|
120 | # routine, to add shortcuts and similar windows-only things. Windows | |||
|
121 | # post-install scripts MUST reside in the scripts/ dir, otherwise distutils | |||
|
122 | # doesn't find them. | |||
|
123 | if 'bdist_wininst' in sys.argv: | |||
|
124 | if len(sys.argv) > 2 and ('sdist' in sys.argv or 'bdist_rpm' in sys.argv): | |||
|
125 | print >> sys.stderr,"ERROR: bdist_wininst must be run alone. Exiting." | |||
|
126 | sys.exit(1) | |||
|
127 | scriptfiles.append('scripts/ipython_win_post_install.py') | |||
|
128 | ||||
|
129 | # Call the setup() routine which does most of the work | |||
|
130 | setup(name = name, | |||
|
131 | version = version, | |||
|
132 | description = description, | |||
|
133 | long_description = long_description, | |||
|
134 | author = authors['Fernando'][0], | |||
|
135 | author_email = authors['Fernando'][1], | |||
|
136 | url = url, | |||
|
137 | download_url = download_url, | |||
|
138 | license = license, | |||
|
139 | platforms = platforms, | |||
|
140 | keywords = keywords, | |||
|
141 | packages = ['IPython', 'IPython.Extensions'], | |||
|
142 | #scripts = scriptfiles, | |||
|
143 | cmdclass = {'install_data': install_data_ext}, | |||
|
144 | data_files = [('data', docdirbase, docfiles), | |||
|
145 | ('data', os.path.join(docdirbase, 'examples'), | |||
|
146 | examfiles), | |||
|
147 | ('data', os.path.join(docdirbase, 'manual'), | |||
|
148 | manfiles), | |||
|
149 | ('data', manpagebase, manpages), | |||
|
150 | ('lib', 'IPython/UserConfig', cfgfiles)], | |||
|
151 | # egg options | |||
|
152 | entry_points = { | |||
|
153 | 'console_scripts': [ | |||
|
154 | 'ipython = IPython.ipapi:launch_new_instance', | |||
|
155 | 'pycolor = IPython.PyColorize:main' | |||
|
156 | ], | |||
|
157 | } | |||
|
158 | ) |
@@ -1,143 +1,157 b'' | |||||
1 | ''' IPython customization API |
|
1 | ''' IPython customization API | |
2 |
|
2 | |||
3 | Your one-stop module for configuring & extending ipython |
|
3 | Your one-stop module for configuring & extending ipython | |
4 |
|
4 | |||
5 | The API will probably break when ipython 1.0 is released, but so |
|
5 | The API will probably break when ipython 1.0 is released, but so | |
6 | will the other configuration method (rc files). |
|
6 | will the other configuration method (rc files). | |
7 |
|
7 | |||
8 | All names prefixed by underscores are for internal use, not part |
|
8 | All names prefixed by underscores are for internal use, not part | |
9 | of the public api. |
|
9 | of the public api. | |
10 |
|
10 | |||
11 | Below is an example that you can just put to a module and import from ipython. |
|
11 | Below is an example that you can just put to a module and import from ipython. | |
12 |
|
12 | |||
13 | A good practice is to install the config script below as e.g. |
|
13 | A good practice is to install the config script below as e.g. | |
14 |
|
14 | |||
15 | ~/.ipython/my_private_conf.py |
|
15 | ~/.ipython/my_private_conf.py | |
16 |
|
16 | |||
17 | And do |
|
17 | And do | |
18 |
|
18 | |||
19 | import_mod my_private_conf |
|
19 | import_mod my_private_conf | |
20 |
|
20 | |||
21 | in ~/.ipython/ipythonrc |
|
21 | in ~/.ipython/ipythonrc | |
22 |
|
22 | |||
23 | That way the module is imported at startup and you can have all your |
|
23 | That way the module is imported at startup and you can have all your | |
24 | personal configuration (as opposed to boilerplate ipythonrc-PROFILENAME |
|
24 | personal configuration (as opposed to boilerplate ipythonrc-PROFILENAME | |
25 | stuff) in there. |
|
25 | stuff) in there. | |
26 |
|
26 | |||
27 | ----------------------------------------------- |
|
27 | ----------------------------------------------- | |
28 | import IPython.ipapi as ip |
|
28 | import IPython.ipapi as ip | |
29 |
|
29 | |||
30 | def ankka_f(self, arg): |
|
30 | def ankka_f(self, arg): | |
31 | print "Ankka",self,"says uppercase:",arg.upper() |
|
31 | print "Ankka",self,"says uppercase:",arg.upper() | |
32 |
|
32 | |||
33 | ip.expose_magic("ankka",ankka_f) |
|
33 | ip.expose_magic("ankka",ankka_f) | |
34 |
|
34 | |||
35 | ip.magic('alias sayhi echo "Testing, hi ok"') |
|
35 | ip.magic('alias sayhi echo "Testing, hi ok"') | |
36 | ip.magic('alias helloworld echo "Hello world"') |
|
36 | ip.magic('alias helloworld echo "Hello world"') | |
37 | ip.system('pwd') |
|
37 | ip.system('pwd') | |
38 |
|
38 | |||
39 | ip.ex('import re') |
|
39 | ip.ex('import re') | |
40 | ip.ex(""" |
|
40 | ip.ex(""" | |
41 | def funcci(a,b): |
|
41 | def funcci(a,b): | |
42 | print a+b |
|
42 | print a+b | |
43 | print funcci(3,4) |
|
43 | print funcci(3,4) | |
44 | """) |
|
44 | """) | |
45 | ip.ex("funcci(348,9)") |
|
45 | ip.ex("funcci(348,9)") | |
46 |
|
46 | |||
47 | def jed_editor(self,filename, linenum=None): |
|
47 | def jed_editor(self,filename, linenum=None): | |
48 | print "Calling my own editor, jed ... via hook!" |
|
48 | print "Calling my own editor, jed ... via hook!" | |
49 | import os |
|
49 | import os | |
50 | if linenum is None: linenum = 0 |
|
50 | if linenum is None: linenum = 0 | |
51 | os.system('jed +%d %s' % (linenum, filename)) |
|
51 | os.system('jed +%d %s' % (linenum, filename)) | |
52 | print "exiting jed" |
|
52 | print "exiting jed" | |
53 |
|
53 | |||
54 | ip.set_hook('editor',jed_editor) |
|
54 | ip.set_hook('editor',jed_editor) | |
55 |
|
55 | |||
56 | o = ip.options() |
|
56 | o = ip.options() | |
57 | o.autocall = 2 # FULL autocall mode |
|
57 | o.autocall = 2 # FULL autocall mode | |
58 |
|
58 | |||
59 | print "done!" |
|
59 | print "done!" | |
60 |
|
60 | |||
61 | ''' |
|
61 | ''' | |
62 |
|
62 | |||
63 | def _init_with_shell(ip): |
|
63 | def _init_with_shell(ip): | |
64 | global magic |
|
64 | global magic | |
65 | magic = ip.ipmagic |
|
65 | magic = ip.ipmagic | |
66 | global system |
|
66 | global system | |
67 | system = ip.ipsystem |
|
67 | system = ip.ipsystem | |
68 | global set_hook |
|
68 | global set_hook | |
69 | set_hook = ip.set_hook |
|
69 | set_hook = ip.set_hook | |
70 |
|
70 | |||
71 | global __IP |
|
71 | global __IP | |
72 | __IP = ip |
|
72 | __IP = ip | |
73 |
|
73 | |||
74 | def options(): |
|
74 | def options(): | |
75 | """ All configurable variables """ |
|
75 | """ All configurable variables """ | |
76 | return __IP.rc |
|
76 | return __IP.rc | |
77 |
|
77 | |||
78 | def user_ns(): |
|
78 | def user_ns(): | |
79 | return __IP.user_ns |
|
79 | return __IP.user_ns | |
80 |
|
80 | |||
81 | def expose_magic(magicname, func): |
|
81 | def expose_magic(magicname, func): | |
82 | ''' Expose own function as magic function for ipython |
|
82 | ''' Expose own function as magic function for ipython | |
83 |
|
83 | |||
84 | def foo_impl(self,parameter_s=''): |
|
84 | def foo_impl(self,parameter_s=''): | |
85 | """My very own magic!. (Use docstrings, IPython reads them).""" |
|
85 | """My very own magic!. (Use docstrings, IPython reads them).""" | |
86 | print 'Magic function. Passed parameter is between < >: <'+parameter_s+'>' |
|
86 | print 'Magic function. Passed parameter is between < >: <'+parameter_s+'>' | |
87 | print 'The self object is:',self |
|
87 | print 'The self object is:',self | |
88 |
|
88 | |||
89 | ipapi.expose_magic("foo",foo_impl) |
|
89 | ipapi.expose_magic("foo",foo_impl) | |
90 | ''' |
|
90 | ''' | |
91 |
|
91 | |||
92 | from IPython import Magic |
|
92 | from IPython import Magic | |
93 | import new |
|
93 | import new | |
94 | im = new.instancemethod(func,__IP, __IP.__class__) |
|
94 | im = new.instancemethod(func,__IP, __IP.__class__) | |
95 | setattr(__IP, "magic_" + magicname, im) |
|
95 | setattr(__IP, "magic_" + magicname, im) | |
96 |
|
96 | |||
97 | class asmagic: |
|
97 | class asmagic: | |
98 | """ Decorator for exposing magics in a friendly 2.4 decorator form |
|
98 | """ Decorator for exposing magics in a friendly 2.4 decorator form | |
99 |
|
99 | |||
100 | @ip.asmagic("foo") |
|
100 | @ip.asmagic("foo") | |
101 | def f(self,arg): |
|
101 | def f(self,arg): | |
102 | pring "arg given:",arg |
|
102 | pring "arg given:",arg | |
103 |
|
103 | |||
104 | After this, %foo is a magic function. |
|
104 | After this, %foo is a magic function. | |
105 | """ |
|
105 | """ | |
106 |
|
106 | |||
107 | def __init__(self,magicname): |
|
107 | def __init__(self,magicname): | |
108 | self.name = magicname |
|
108 | self.name = magicname | |
109 |
|
109 | |||
110 | def __call__(self,f): |
|
110 | def __call__(self,f): | |
111 | expose_magic(self.name, f) |
|
111 | expose_magic(self.name, f) | |
112 | return f |
|
112 | return f | |
113 |
|
113 | |||
114 | class ashook: |
|
114 | class ashook: | |
115 | """ Decorator for exposing magics in a friendly 2.4 decorator form |
|
115 | """ Decorator for exposing magics in a friendly 2.4 decorator form | |
116 |
|
116 | |||
117 | @ip.ashook("editor") |
|
117 | @ip.ashook("editor") | |
118 | def jed_editor(self,filename, linenum=None): |
|
118 | def jed_editor(self,filename, linenum=None): | |
119 | import os |
|
119 | import os | |
120 | if linenum is None: linenum = 0 |
|
120 | if linenum is None: linenum = 0 | |
121 | os.system('jed +%d %s' % (linenum, filename)) |
|
121 | os.system('jed +%d %s' % (linenum, filename)) | |
122 |
|
122 | |||
123 | """ |
|
123 | """ | |
124 |
|
124 | |||
125 | def __init__(self,name,priority=50): |
|
125 | def __init__(self,name,priority=50): | |
126 | self.name = name |
|
126 | self.name = name | |
127 | self.prio = priority |
|
127 | self.prio = priority | |
128 |
|
128 | |||
129 | def __call__(self,f): |
|
129 | def __call__(self,f): | |
130 | set_hook(self.name, f, self.prio) |
|
130 | set_hook(self.name, f, self.prio) | |
131 | return f |
|
131 | return f | |
132 |
|
132 | |||
133 |
|
133 | |||
134 | def ex(cmd): |
|
134 | def ex(cmd): | |
135 | """ Execute a normal python statement in user namespace """ |
|
135 | """ Execute a normal python statement in user namespace """ | |
136 | exec cmd in user_ns() |
|
136 | exec cmd in user_ns() | |
137 |
|
137 | |||
138 | def ev(expr): |
|
138 | def ev(expr): | |
139 | """ Evaluate python expression expr in user namespace |
|
139 | """ Evaluate python expression expr in user namespace | |
140 |
|
140 | |||
141 | Returns the result """ |
|
141 | Returns the result """ | |
142 | return eval(expr,user_ns()) |
|
142 | return eval(expr,user_ns()) | |
|
143 | ||||
|
144 | def launch_new_instance(): | |||
|
145 | """ Creata and start a new ipython instance. | |||
|
146 | ||||
|
147 | This can be called even without having an already initialized | |||
|
148 | ipython session running. | |||
|
149 | ||||
|
150 | """ | |||
|
151 | import IPython | |||
|
152 | ||||
|
153 | IPython.Shell.start().mainloop() | |||
|
154 | ||||
|
155 | ||||
|
156 | ||||
143 | No newline at end of file |
|
157 |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now