-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
33 lines (25 loc) · 1.06 KB
/
__main__.py
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
import argparse
import os
try:
import importlib.machinery
import importlib.util
def load_module(name, filepath):
loader = importlib.machinery.SourceFileLoader(name, filepath)
spec = importlib.util.spec_from_loader(loader.name, loader)
mod = importlib.util.module_from_spec(spec)
loader.exec_module(mod)
except ImportError:
import imp
def load_module(name, filepath):
with open(filepath, 'r') as fd:
imp.load_module('a_b', fd, filepath, ('.py', 'U', imp.PY_SOURCE))
from ng_exceptions import interact, hook
hook()
parser = argparse.ArgumentParser(description='A Python REPL with ng exceptions enabled', prog='python -m ng_exceptions')
parser.add_argument('-q', '--quiet', help="don't show a banner", action='store_true')
parser.add_argument('-i', '--no-init', dest='no_init', help="don't load ~/.pyinit", action='store_true')
args = parser.parse_args()
startup_file = os.getenv('PYTHONSTARTUP')
if not args.no_init and startup_file is not None:
load_module('pystartup', startup_file)
interact(args.quiet)