Show More
@@ -2,6 +2,7 b'' | |||||
2 |
|
2 | |||
3 |
|
3 | |||
4 | import argparse |
|
4 | import argparse | |
|
5 | import textwrap | |||
5 | import io |
|
6 | import io | |
6 | import sys |
|
7 | import sys | |
7 | from pprint import pformat |
|
8 | from pprint import pformat | |
@@ -17,7 +18,8 b' from logging import error' | |||||
17 |
|
18 | |||
18 |
|
19 | |||
19 | class MagicsDisplay(object): |
|
20 | class MagicsDisplay(object): | |
20 | def __init__(self, magics_manager): |
|
21 | def __init__(self, magics_manager, ignore=None): | |
|
22 | self.ignore = ignore if ignore else [] | |||
21 | self.magics_manager = magics_manager |
|
23 | self.magics_manager = magics_manager | |
22 |
|
24 | |||
23 | def _lsmagic(self): |
|
25 | def _lsmagic(self): | |
@@ -27,10 +29,10 b' class MagicsDisplay(object):' | |||||
27 | mman = self.magics_manager |
|
29 | mman = self.magics_manager | |
28 | magics = mman.lsmagic() |
|
30 | magics = mman.lsmagic() | |
29 | out = ['Available line magics:', |
|
31 | out = ['Available line magics:', | |
30 | mesc + (' '+mesc).join(sorted(magics['line'])), |
|
32 | mesc + (' '+mesc).join(sorted([m for m,v in magics['line'].items() if (v not in self.ignore)])), | |
31 | '', |
|
33 | '', | |
32 | 'Available cell magics:', |
|
34 | 'Available cell magics:', | |
33 | cesc + (' '+cesc).join(sorted(magics['cell'])), |
|
35 | cesc + (' '+cesc).join(sorted([m for m,v in magics['cell'].items() if (v not in self.ignore)])), | |
34 | '', |
|
36 | '', | |
35 | mman.auto_status()] |
|
37 | mman.auto_status()] | |
36 | return '\n'.join(out) |
|
38 | return '\n'.join(out) | |
@@ -160,7 +162,7 b' class BasicMagics(Magics):' | |||||
160 | @line_magic |
|
162 | @line_magic | |
161 | def lsmagic(self, parameter_s=''): |
|
163 | def lsmagic(self, parameter_s=''): | |
162 | """List currently available magic functions.""" |
|
164 | """List currently available magic functions.""" | |
163 | return MagicsDisplay(self.shell.magics_manager) |
|
165 | return MagicsDisplay(self.shell.magics_manager, ignore=[self.pip]) | |
164 |
|
166 | |||
165 | def _magic_docs(self, brief=False, rest=False): |
|
167 | def _magic_docs(self, brief=False, rest=False): | |
166 | """Return docstrings from magic functions.""" |
|
168 | """Return docstrings from magic functions.""" | |
@@ -377,7 +379,24 b' Currently the magic system has the following functions:""",' | |||||
377 | xmode_switch_err('user') |
|
379 | xmode_switch_err('user') | |
378 |
|
380 | |||
379 | @line_magic |
|
381 | @line_magic | |
380 |
def |
|
382 | def pip(self, args=''): | |
|
383 | """ | |||
|
384 | Intercept usage of ``pip`` in IPython and direct user to run command outside of IPython. | |||
|
385 | """ | |||
|
386 | print(textwrap.dedent(''' | |||
|
387 | The following command must be run outside of the IPython shell: | |||
|
388 | ||||
|
389 | $ pip {args} | |||
|
390 | ||||
|
391 | The Python package manager (pip) can only be used from outside of IPython. | |||
|
392 | Please reissue the `pip` command in a separate terminal or command prompt. | |||
|
393 | ||||
|
394 | See the Python documentation for more informations on how to install packages: | |||
|
395 | ||||
|
396 | https://docs.python.org/3/installing/'''.format(args=args))) | |||
|
397 | ||||
|
398 | @line_magic | |||
|
399 | def quickref(self, arg): | |||
381 | """ Show a quick reference sheet """ |
|
400 | """ Show a quick reference sheet """ | |
382 | from IPython.core.usage import quick_reference |
|
401 | from IPython.core.usage import quick_reference | |
383 | qr = quick_reference + self._magic_docs(brief=True) |
|
402 | qr = quick_reference + self._magic_docs(brief=True) |
General Comments 0
You need to be logged in to leave comments.
Login now