62 | | try: # Try activating rlcompleter, because it's handy. |
63 | | import readline |
64 | | except ImportError: |
65 | | pass |
66 | | else: |
67 | | # We don't have to wrap the following import in a 'try', because |
68 | | # we already know 'readline' was imported successfully. |
69 | | import rlcompleter |
70 | | readline.set_completer(rlcompleter.Completer(imported_objects).complete) |
71 | | readline.parse_and_bind("tab:complete") |
72 | | |
73 | | # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system |
74 | | # conventions and get $PYTHONSTARTUP first then import user. |
75 | | if not use_plain: |
76 | | pythonrc = os.environ.get("PYTHONSTARTUP") |
77 | | if pythonrc and os.path.isfile(pythonrc): |
78 | | try: |
79 | | execfile(pythonrc) |
80 | | except NameError: |
81 | | pass |
82 | | # This will import .pythonrc.py as a side-effect |
83 | | import user |
| 70 | |
| 71 | # ticket #9990 : |
| 72 | # We want to first load pythonrc then test if it already defines a |
| 73 | # completion, and only add our one if necessary. |
| 74 | # NB : We honor the pythonrc without checking for 'use_plain' because that's |
| 75 | # how the 'plain' shell would work |
| 76 | pythonrc = os.environ.get("PYTHONSTARTUP") |
| 77 | if pythonrc and os.path.isfile(pythonrc): |
| 78 | try: |
| 79 | execfile(pythonrc, imported_objects) |
| 80 | except NameError: |
| 81 | pass |
| 82 | |
| 83 | # This will import .pythonrc.py as a side-effect |
| 84 | import user |
| 85 | |
| 86 | if readline and not use_plain: |
| 87 | # Try activating rlcompleter, because it's handy - but only |
| 88 | # if the pythonrc didn't already took care of this |
| 89 | if not readline.get_completer(): |
| 90 | # We don't have to wrap the following import in a 'try', because |
| 91 | # we already know 'readline' was imported successfully. |
| 92 | import rlcompleter |
| 93 | readline.set_completer(rlcompleter.Completer(imported_objects).complete) |
| 94 | readline.parse_and_bind("tab:complete") |
| 95 | |