~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/core/management/commands/shell.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    option_list = NoArgsCommand.option_list + (
10
10
        make_option('--plain', action='store_true', dest='plain',
11
11
            help='Tells Django to use plain Python, not IPython or bpython.'),
 
12
        make_option('--no-startup', action='store_true', dest='no_startup',
 
13
            help='When using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.'),
12
14
        make_option('-i', '--interface', action='store', type='choice', choices=shells,
13
15
                    dest='interface',
14
16
            help='Specify an interactive interpreter interface. Available options: "ipython" and "bpython"'),
17
19
    help = "Runs a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available."
18
20
    requires_model_validation = False
19
21
 
 
22
    def _ipython_pre_011(self):
 
23
        """Start IPython pre-0.11"""
 
24
        from IPython.Shell import IPShell
 
25
        shell = IPShell(argv=[])
 
26
        shell.mainloop()
 
27
 
 
28
    def _ipython_pre_100(self):
 
29
        """Start IPython pre-1.0.0"""
 
30
        from IPython.frontend.terminal.ipapp import TerminalIPythonApp
 
31
        app = TerminalIPythonApp.instance()
 
32
        app.initialize(argv=[])
 
33
        app.start()
 
34
 
 
35
    def _ipython(self):
 
36
        """Start IPython >= 1.0"""
 
37
        from IPython import start_ipython
 
38
        start_ipython(argv=[])
 
39
 
20
40
    def ipython(self):
21
 
        try:
22
 
            from IPython import embed
23
 
            embed()
24
 
        except ImportError:
25
 
            # IPython < 0.11
26
 
            # Explicitly pass an empty list as arguments, because otherwise
27
 
            # IPython would use sys.argv from this script.
 
41
        """Start any version of IPython"""
 
42
        for ip in (self._ipython, self._ipython_pre_100, self._ipython_pre_011):
28
43
            try:
29
 
                from IPython.Shell import IPShell
30
 
                shell = IPShell(argv=[])
31
 
                shell.mainloop()
 
44
                ip()
32
45
            except ImportError:
33
 
                # IPython not found at all, raise ImportError
34
 
                raise
 
46
                pass
 
47
            else:
 
48
                return
 
49
        # no IPython, raise ImportError
 
50
        raise ImportError("No IPython")
35
51
 
36
52
    def bpython(self):
37
53
        import bpython
54
70
        get_models()
55
71
 
56
72
        use_plain = options.get('plain', False)
 
73
        no_startup = options.get('no_startup', False)
57
74
        interface = options.get('interface', None)
58
75
 
59
76
        try:
81
98
 
82
99
            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
83
100
            # conventions and get $PYTHONSTARTUP first then .pythonrc.py.
84
 
            if not use_plain:
85
 
                for pythonrc in (os.environ.get("PYTHONSTARTUP"),
86
 
                                 os.path.expanduser('~/.pythonrc.py')):
87
 
                    if pythonrc and os.path.isfile(pythonrc):
88
 
                        try:
89
 
                            with open(pythonrc) as handle:
90
 
                                exec(compile(handle.read(), pythonrc, 'exec'))
91
 
                        except NameError:
92
 
                            pass
 
101
            if not no_startup:
 
102
                for pythonrc in (os.environ.get("PYTHONSTARTUP"), '~/.pythonrc.py'):
 
103
                    if not pythonrc:
 
104
                        continue
 
105
                    pythonrc = os.path.expanduser(pythonrc)
 
106
                    if not os.path.isfile(pythonrc):
 
107
                        continue
 
108
                    try:
 
109
                        with open(pythonrc) as handle:
 
110
                            exec(compile(handle.read(), pythonrc, 'exec'), imported_objects)
 
111
                    except NameError:
 
112
                        pass
93
113
            code.interact(local=imported_objects)