Show More
@@ -1,229 +1,229 b'' | |||
|
1 | 1 | """Hooks for IPython. |
|
2 | 2 | |
|
3 | 3 | In Python, it is possible to overwrite any method of any object if you really |
|
4 | 4 | want to. But IPython exposes a few 'hooks', methods which are *designed* to |
|
5 | 5 | be overwritten by users for customization purposes. This module defines the |
|
6 | 6 | default versions of all such hooks, which get used by IPython if not |
|
7 | 7 | overridden by the user. |
|
8 | 8 | |
|
9 | 9 | Hooks are simple functions, but they should be declared with ``self`` as their |
|
10 | 10 | first argument, because when activated they are registered into IPython as |
|
11 | 11 | instance methods. The self argument will be the IPython running instance |
|
12 | 12 | itself, so hooks have full access to the entire IPython object. |
|
13 | 13 | |
|
14 | 14 | If you wish to define a new hook and activate it, you can make an :doc:`extension |
|
15 | 15 | </config/extensions/index>` or a :ref:`startup script <startup_files>`. For |
|
16 | 16 | example, you could use a startup file like this:: |
|
17 | 17 | |
|
18 | 18 | import os |
|
19 | 19 | |
|
20 | 20 | def calljed(self,filename, linenum): |
|
21 | 21 | "My editor hook calls the jed editor directly." |
|
22 | 22 | print "Calling my own editor, jed ..." |
|
23 | 23 | if os.system('jed +%d %s' % (linenum,filename)) != 0: |
|
24 | 24 | raise TryNext() |
|
25 | 25 | |
|
26 | 26 | def load_ipython_extension(ip): |
|
27 | 27 | ip.set_hook('editor', calljed) |
|
28 | 28 | |
|
29 | 29 | """ |
|
30 | 30 | |
|
31 | 31 | #***************************************************************************** |
|
32 | 32 | # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu> |
|
33 | 33 | # |
|
34 | 34 | # Distributed under the terms of the BSD License. The full license is in |
|
35 | 35 | # the file COPYING, distributed as part of this software. |
|
36 | 36 | #***************************************************************************** |
|
37 | 37 | |
|
38 | 38 | import os |
|
39 | 39 | import subprocess |
|
40 | 40 | import warnings |
|
41 | 41 | import sys |
|
42 | 42 | |
|
43 | 43 | from IPython.core.error import TryNext |
|
44 | 44 | |
|
45 | 45 | # List here all the default hooks. For now it's just the editor functions |
|
46 | 46 | # but over time we'll move here all the public API for user-accessible things. |
|
47 | 47 | |
|
48 | 48 | __all__ = ['editor', 'synchronize_with_editor', |
|
49 | 49 | 'shutdown_hook', 'late_startup_hook', |
|
50 | 50 | 'show_in_pager','pre_prompt_hook', |
|
51 | 51 | 'pre_run_code_hook', 'clipboard_get'] |
|
52 | 52 | |
|
53 | 53 | deprecated = {'pre_run_code_hook': "a callback for the 'pre_execute' or 'pre_run_cell' event", |
|
54 | 54 | 'late_startup_hook': "a callback for the 'shell_initialized' event", |
|
55 | 55 | 'shutdown_hook': "the atexit module", |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | def editor(self, filename, linenum=None, wait=True): |
|
59 | 59 | """Open the default editor at the given filename and linenumber. |
|
60 | 60 | |
|
61 | 61 | This is IPython's default editor hook, you can use it as an example to |
|
62 | 62 | write your own modified one. To set your own editor function as the |
|
63 | 63 | new editor hook, call ip.set_hook('editor',yourfunc).""" |
|
64 | 64 | |
|
65 | 65 | # IPython configures a default editor at startup by reading $EDITOR from |
|
66 | 66 | # the environment, and falling back on vi (unix) or notepad (win32). |
|
67 | 67 | editor = self.editor |
|
68 | 68 | |
|
69 | 69 | # marker for at which line to open the file (for existing objects) |
|
70 | 70 | if linenum is None or editor=='notepad': |
|
71 | 71 | linemark = '' |
|
72 | 72 | else: |
|
73 | 73 | linemark = '+%d' % int(linenum) |
|
74 | 74 | |
|
75 | 75 | # Enclose in quotes if necessary and legal |
|
76 | 76 | if ' ' in editor and os.path.isfile(editor) and editor[0] != '"': |
|
77 | 77 | editor = '"%s"' % editor |
|
78 | 78 | |
|
79 | 79 | # Call the actual editor |
|
80 | 80 | proc = subprocess.Popen('%s %s %s' % (editor, linemark, filename), |
|
81 | 81 | shell=True) |
|
82 | 82 | if wait and proc.wait() != 0: |
|
83 | 83 | raise TryNext() |
|
84 | 84 | |
|
85 | 85 | import tempfile |
|
86 | 86 | from IPython.utils.decorators import undoc |
|
87 | 87 | |
|
88 | 88 | @undoc |
|
89 | 89 | def fix_error_editor(self,filename,linenum,column,msg): |
|
90 | 90 | """DEPRECATED |
|
91 | 91 | |
|
92 | 92 | Open the editor at the given filename, linenumber, column and |
|
93 | 93 | show an error message. This is used for correcting syntax errors. |
|
94 | 94 | The current implementation only has special support for the VIM editor, |
|
95 | 95 | and falls back on the 'editor' hook if VIM is not used. |
|
96 | 96 | |
|
97 | 97 | Call ip.set_hook('fix_error_editor',yourfunc) to use your own function, |
|
98 | 98 | """ |
|
99 | 99 | |
|
100 | 100 | warnings.warn(""" |
|
101 | 101 | `fix_error_editor` is deprecated as of IPython 6.0 and will be removed |
|
102 | 102 | in future versions. It appears to be used only for automatically fixing syntax |
|
103 | 103 | error that has been broken for a few years and has thus been removed. If you |
|
104 | 104 | happend to use this function and still need it please make your voice heard on |
|
105 |
the mailing list ipython-dev@ |
|
|
105 | the mailing list ipython-dev@python.org , or on the GitHub Issue tracker: | |
|
106 | 106 | https://github.com/ipython/ipython/issues/9649 """, UserWarning) |
|
107 | 107 | |
|
108 | 108 | def vim_quickfix_file(): |
|
109 | 109 | t = tempfile.NamedTemporaryFile() |
|
110 | 110 | t.write('%s:%d:%d:%s\n' % (filename,linenum,column,msg)) |
|
111 | 111 | t.flush() |
|
112 | 112 | return t |
|
113 | 113 | if os.path.basename(self.editor) != 'vim': |
|
114 | 114 | self.hooks.editor(filename,linenum) |
|
115 | 115 | return |
|
116 | 116 | t = vim_quickfix_file() |
|
117 | 117 | try: |
|
118 | 118 | if os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name): |
|
119 | 119 | raise TryNext() |
|
120 | 120 | finally: |
|
121 | 121 | t.close() |
|
122 | 122 | |
|
123 | 123 | |
|
124 | 124 | def synchronize_with_editor(self, filename, linenum, column): |
|
125 | 125 | pass |
|
126 | 126 | |
|
127 | 127 | |
|
128 | 128 | class CommandChainDispatcher: |
|
129 | 129 | """ Dispatch calls to a chain of commands until some func can handle it |
|
130 | 130 | |
|
131 | 131 | Usage: instantiate, execute "add" to add commands (with optional |
|
132 | 132 | priority), execute normally via f() calling mechanism. |
|
133 | 133 | |
|
134 | 134 | """ |
|
135 | 135 | def __init__(self,commands=None): |
|
136 | 136 | if commands is None: |
|
137 | 137 | self.chain = [] |
|
138 | 138 | else: |
|
139 | 139 | self.chain = commands |
|
140 | 140 | |
|
141 | 141 | |
|
142 | 142 | def __call__(self,*args, **kw): |
|
143 | 143 | """ Command chain is called just like normal func. |
|
144 | 144 | |
|
145 | 145 | This will call all funcs in chain with the same args as were given to |
|
146 | 146 | this function, and return the result of first func that didn't raise |
|
147 | 147 | TryNext""" |
|
148 | 148 | last_exc = TryNext() |
|
149 | 149 | for prio,cmd in self.chain: |
|
150 | 150 | #print "prio",prio,"cmd",cmd #dbg |
|
151 | 151 | try: |
|
152 | 152 | return cmd(*args, **kw) |
|
153 | 153 | except TryNext as exc: |
|
154 | 154 | last_exc = exc |
|
155 | 155 | # if no function will accept it, raise TryNext up to the caller |
|
156 | 156 | raise last_exc |
|
157 | 157 | |
|
158 | 158 | def __str__(self): |
|
159 | 159 | return str(self.chain) |
|
160 | 160 | |
|
161 | 161 | def add(self, func, priority=0): |
|
162 | 162 | """ Add a func to the cmd chain with given priority """ |
|
163 | 163 | self.chain.append((priority, func)) |
|
164 | 164 | self.chain.sort(key=lambda x: x[0]) |
|
165 | 165 | |
|
166 | 166 | def __iter__(self): |
|
167 | 167 | """ Return all objects in chain. |
|
168 | 168 | |
|
169 | 169 | Handy if the objects are not callable. |
|
170 | 170 | """ |
|
171 | 171 | return iter(self.chain) |
|
172 | 172 | |
|
173 | 173 | |
|
174 | 174 | def shutdown_hook(self): |
|
175 | 175 | """ default shutdown hook |
|
176 | 176 | |
|
177 | 177 | Typically, shotdown hooks should raise TryNext so all shutdown ops are done |
|
178 | 178 | """ |
|
179 | 179 | |
|
180 | 180 | #print "default shutdown hook ok" # dbg |
|
181 | 181 | return |
|
182 | 182 | |
|
183 | 183 | |
|
184 | 184 | def late_startup_hook(self): |
|
185 | 185 | """ Executed after ipython has been constructed and configured |
|
186 | 186 | |
|
187 | 187 | """ |
|
188 | 188 | #print "default startup hook ok" # dbg |
|
189 | 189 | |
|
190 | 190 | |
|
191 | 191 | def show_in_pager(self, data, start, screen_lines): |
|
192 | 192 | """ Run a string through pager """ |
|
193 | 193 | # raising TryNext here will use the default paging functionality |
|
194 | 194 | raise TryNext |
|
195 | 195 | |
|
196 | 196 | |
|
197 | 197 | def pre_prompt_hook(self): |
|
198 | 198 | """ Run before displaying the next prompt |
|
199 | 199 | |
|
200 | 200 | Use this e.g. to display output from asynchronous operations (in order |
|
201 | 201 | to not mess up text entry) |
|
202 | 202 | """ |
|
203 | 203 | |
|
204 | 204 | return None |
|
205 | 205 | |
|
206 | 206 | |
|
207 | 207 | def pre_run_code_hook(self): |
|
208 | 208 | """ Executed before running the (prefiltered) code in IPython """ |
|
209 | 209 | return None |
|
210 | 210 | |
|
211 | 211 | |
|
212 | 212 | def clipboard_get(self): |
|
213 | 213 | """ Get text from the clipboard. |
|
214 | 214 | """ |
|
215 | 215 | from IPython.lib.clipboard import ( |
|
216 | 216 | osx_clipboard_get, tkinter_clipboard_get, |
|
217 | 217 | win32_clipboard_get |
|
218 | 218 | ) |
|
219 | 219 | if sys.platform == 'win32': |
|
220 | 220 | chain = [win32_clipboard_get, tkinter_clipboard_get] |
|
221 | 221 | elif sys.platform == 'darwin': |
|
222 | 222 | chain = [osx_clipboard_get, tkinter_clipboard_get] |
|
223 | 223 | else: |
|
224 | 224 | chain = [tkinter_clipboard_get] |
|
225 | 225 | dispatcher = CommandChainDispatcher() |
|
226 | 226 | for func in chain: |
|
227 | 227 | dispatcher.add(func) |
|
228 | 228 | text = dispatcher() |
|
229 | 229 | return text |
@@ -1,118 +1,118 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Release data for the IPython project.""" |
|
3 | 3 | |
|
4 | 4 | #----------------------------------------------------------------------------- |
|
5 | 5 | # Copyright (c) 2008, IPython Development Team. |
|
6 | 6 | # Copyright (c) 2001, Fernando Perez <fernando.perez@colorado.edu> |
|
7 | 7 | # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de> |
|
8 | 8 | # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu> |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the Modified BSD License. |
|
11 | 11 | # |
|
12 | 12 | # The full license is in the file COPYING.txt, distributed with this software. |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | # Name of the package for release purposes. This is the name which labels |
|
16 | 16 | # the tarballs and RPMs made by distutils, so it's best to lowercase it. |
|
17 | 17 | name = 'ipython' |
|
18 | 18 | |
|
19 | 19 | # IPython version information. An empty _version_extra corresponds to a full |
|
20 | 20 | # release. 'dev' as a _version_extra string means this is a development |
|
21 | 21 | # version |
|
22 | 22 | _version_major = 6 |
|
23 | 23 | _version_minor = 0 |
|
24 | 24 | _version_patch = 0 |
|
25 | 25 | _version_extra = '.dev' |
|
26 | 26 | # _version_extra = 'rc1' |
|
27 | 27 | # _version_extra = '' # Uncomment this for full releases |
|
28 | 28 | |
|
29 | 29 | # Construct full version string from these. |
|
30 | 30 | _ver = [_version_major, _version_minor, _version_patch] |
|
31 | 31 | |
|
32 | 32 | __version__ = '.'.join(map(str, _ver)) |
|
33 | 33 | if _version_extra: |
|
34 | 34 | __version__ = __version__ + _version_extra |
|
35 | 35 | |
|
36 | 36 | version = __version__ # backwards compatibility name |
|
37 | 37 | version_info = (_version_major, _version_minor, _version_patch, _version_extra) |
|
38 | 38 | |
|
39 | 39 | # Change this when incrementing the kernel protocol version |
|
40 | 40 | kernel_protocol_version_info = (5, 0) |
|
41 | 41 | kernel_protocol_version = "%i.%i" % kernel_protocol_version_info |
|
42 | 42 | |
|
43 | 43 | description = "IPython: Productive Interactive Computing" |
|
44 | 44 | |
|
45 | 45 | long_description = \ |
|
46 | 46 | """ |
|
47 | 47 | IPython provides a rich toolkit to help you make the most out of using Python |
|
48 | 48 | interactively. Its main components are: |
|
49 | 49 | |
|
50 | 50 | * A powerful interactive Python shell |
|
51 | 51 | * A `Jupyter <http://jupyter.org/>`_ kernel to work with Python code in Jupyter |
|
52 | 52 | notebooks and other interactive frontends. |
|
53 | 53 | |
|
54 | 54 | The enhanced interactive Python shells have the following main features: |
|
55 | 55 | |
|
56 | 56 | * Comprehensive object introspection. |
|
57 | 57 | |
|
58 | 58 | * Input history, persistent across sessions. |
|
59 | 59 | |
|
60 | 60 | * Caching of output results during a session with automatically generated |
|
61 | 61 | references. |
|
62 | 62 | |
|
63 | 63 | * Extensible tab completion, with support by default for completion of python |
|
64 | 64 | variables and keywords, filenames and function keywords. |
|
65 | 65 | |
|
66 | 66 | * Extensible system of 'magic' commands for controlling the environment and |
|
67 | 67 | performing many tasks related either to IPython or the operating system. |
|
68 | 68 | |
|
69 | 69 | * A rich configuration system with easy switching between different setups |
|
70 | 70 | (simpler than changing $PYTHONSTARTUP environment variables every time). |
|
71 | 71 | |
|
72 | 72 | * Session logging and reloading. |
|
73 | 73 | |
|
74 | 74 | * Extensible syntax processing for special purpose situations. |
|
75 | 75 | |
|
76 | 76 | * Access to the system shell with user-extensible alias system. |
|
77 | 77 | |
|
78 | 78 | * Easily embeddable in other Python programs and GUIs. |
|
79 | 79 | |
|
80 | 80 | * Integrated access to the pdb debugger and the Python profiler. |
|
81 | 81 | |
|
82 | 82 | The latest development version is always available from IPython's `GitHub |
|
83 | 83 | site <http://github.com/ipython>`_. |
|
84 | 84 | """ |
|
85 | 85 | |
|
86 | 86 | license = 'BSD' |
|
87 | 87 | |
|
88 | 88 | authors = {'Fernando' : ('Fernando Perez','fperez.net@gmail.com'), |
|
89 | 89 | 'Janko' : ('Janko Hauser','jhauser@zscout.de'), |
|
90 | 90 | 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu'), |
|
91 | 91 | 'Ville' : ('Ville Vainio','vivainio@gmail.com'), |
|
92 | 92 | 'Brian' : ('Brian E Granger', 'ellisonbg@gmail.com'), |
|
93 | 93 | 'Min' : ('Min Ragan-Kelley', 'benjaminrk@gmail.com'), |
|
94 | 94 | 'Thomas' : ('Thomas A. Kluyver', 'takowl@gmail.com'), |
|
95 | 95 | 'Jorgen' : ('Jorgen Stenarson', 'jorgen.stenarson@bostream.nu'), |
|
96 | 96 | 'Matthias' : ('Matthias Bussonnier', 'bussonniermatthias@gmail.com'), |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | author = 'The IPython Development Team' |
|
100 | 100 | |
|
101 |
author_email = 'ipython-dev@ |
|
|
101 | author_email = 'ipython-dev@python.org' | |
|
102 | 102 | |
|
103 | url = 'http://ipython.org' | |
|
103 | url = 'https://ipython.org' | |
|
104 | 104 | |
|
105 | 105 | |
|
106 | 106 | platforms = ['Linux','Mac OSX','Windows'] |
|
107 | 107 | |
|
108 | 108 | keywords = ['Interactive','Interpreter','Shell', 'Embedding'] |
|
109 | 109 | |
|
110 | 110 | classifiers = [ |
|
111 | 111 | 'Framework :: IPython', |
|
112 | 112 | 'Intended Audience :: Developers', |
|
113 | 113 | 'Intended Audience :: Science/Research', |
|
114 | 114 | 'License :: OSI Approved :: BSD License', |
|
115 | 115 | 'Programming Language :: Python', |
|
116 | 116 | 'Programming Language :: Python :: 3', |
|
117 | 117 | 'Topic :: System :: Shells' |
|
118 | 118 | ] |
General Comments 0
You need to be logged in to leave comments.
Login now