-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpythonrc
More file actions
50 lines (40 loc) · 1.44 KB
/
pythonrc
File metadata and controls
50 lines (40 loc) · 1.44 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
# -*- python -*-
"""Python REPL startup file."""
##############################################################################
# Python imports.
import atexit
import logging
import os
import readline
import sys
try:
# If rich is in the current venv/whatever...
from rich import pretty
# ...install its pretty printer.
pretty.install()
except ModuleNotFoundError:
# Just carry on if rich isn't installed.
pass
##############################################################################
def davep_log_all():
"""Set up the REPL to log everything down to DEBUG level."""
log = logging.getLogger()
log.setLevel(logging.DEBUG)
stream = logging.StreamHandler(sys.stdout)
stream.setLevel(logging.DEBUG)
log.addHandler(stream)
##############################################################################
# Get history going when in Python 3+ and inside a virtual environment.
if sys.version_info >= (3, 0) and os.getenv("VIRTUAL_ENV"):
# Ensure python knows where to save the history.
PYTHON_HISTORY_FILE = os.path.join(os.environ["HOME"], ".python_history")
# If there is a history file to be had...
if os.path.exists(PYTHON_HISTORY_FILE):
# ...read it in.
try:
readline.read_history_file(PYTHON_HISTORY_FILE)
except OSError:
pass
# Write the history at exit.
atexit.register(readline.write_history_file, PYTHON_HISTORY_FILE)
### pythonrc ends here