-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.pythonrc
More file actions
72 lines (59 loc) · 1.83 KB
/
.pythonrc
File metadata and controls
72 lines (59 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#######################
# IMPORTS & CONSTANTS #
#######################
import imp
import os
import sys
import re
import threading
import time
VIRTUAL_ENV = os.environ.get('VIRTUAL_ENV', None)
HOME = VIRTUAL_ENV or os.environ.get('WORKON_HOME', None) or os.environ['HOME']
#################################
# SAVE & RESTORE HISTORY STATES #
#################################
try:
import readline
except ImportError:
pass
else:
##################
# TAB COMPLETION #
##################
try:
import rlcompleter
except ImportError:
print('readline module not available. History disabled')
pass
else:
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
######################
# PERSISTENT HISTORY #
######################
# Use separate history files for each virtual environment.
HISTFILE = os.path.join(HOME, '.pyhistory')
# Read the existing history if there is one.
if os.path.exists(HISTFILE):
try:
readline.read_history_file(HISTFILE)
except:
# If there was a problem reading the history file then it may have
# become corrupted, so we just delete it.
os.remove(HISTFILE)
# Set maximum number of commands written to the history file.
readline.set_history_length(256)
def savehist():
try:
readline.write_history_file(HISTFILE)
except NameError:
pass
except Exception as err:
print("Unable to save history file due to the following error: %s"
% err)
# Register the ``savehist`` function to run when the user exits the shell.
import atexit
atexit.register(savehist)
print('Loaded .pythonrc')