~ubuntu-branches/ubuntu/trusty/spyder/trusty-proposed

« back to all changes in this revision

Viewing changes to spyderlib/widgets/externalshell/startup.py

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Aubry
  • Date: 2010-06-28 23:43:02 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100628234302-3xnz0gcu0w83282r
Tags: 1.1.1-1
* New upstream release
* New maintainer address (Closes: #586833)
* Build with python 2.6 (Closes: #586824)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    import os
17
17
    return os.environ.get('PYTHONINITCOMMANDS')
18
18
 
 
19
def __is_ipython():
 
20
    import os
 
21
    return os.environ.get('IPYTHON')
 
22
 
 
23
def __patching_matplotlib__():
 
24
    try:
 
25
        from spyderlib import mpl_patch
 
26
        mpl_patch.apply()
 
27
    except ImportError:
 
28
        return
 
29
 
19
30
def __create_banner():
20
31
    """Create shell banner"""
21
32
    import sys
22
33
    print 'Python %s on %s\nType "copyright", "credits" or "license" ' \
23
34
          'for more information.'  % (sys.version, sys.platform)
24
35
 
 
36
def __remove_sys_argv__():
 
37
    """Remove arguments from sys.argv"""
 
38
    import sys
 
39
    sys.argv = ['']
 
40
 
25
41
if __name__ == "__main__":
26
 
    __create_banner()
 
42
    if not __is_ipython():
 
43
        __remove_sys_argv__()
 
44
        __create_banner()
27
45
    __commands__ = __run_init_commands()
28
46
    if __commands__:
29
47
        for command in __commands__.split(';'):
31
49
    else:
32
50
        __run_pythonstartup_script()
33
51
 
34
 
    for name in ('__run_pythonstartup_script', '__run_init_commands', 'name',
35
 
                 '__create_banner', '__commands__', 'command', '__file__'):
36
 
        locals().pop(name)
 
52
    __patching_matplotlib__()
 
53
 
 
54
    for _name in ['__run_pythonstartup_script', '__run_init_commands',
 
55
                  '__create_banner', '__commands__', 'command', '__file__',
 
56
                  '__remove_sys_argv__', '__patching_matplotlib__']+['_name']:
 
57
        if _name in locals():
 
58
            locals().pop(_name)
37
59
 
38
60
    __doc__ = ''
39
61
    __name__ = '__main__'
 
62
 
 
63
    if __is_ipython():
 
64
        import sys
 
65
        __real_platform__ = sys.platform
 
66
        if sys.platform == 'win32':
 
67
            # Patching readline to avoid any error
 
68
            from pyreadline import unicode_helper
 
69
            unicode_helper.pyreadline_codepage = "ascii"
 
70
            # Faking non-win32 to avoid any IPython error
 
71
            sys.platform = 'fake'
 
72
        import IPython.Shell
 
73
        sys.platform = __real_platform__
 
74
        del __real_platform__, __is_ipython
 
75
        __ipythonshell__ = IPython.Shell.start()
 
76
        __ipythonshell__.mainloop()