-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathshell.py
More file actions
78 lines (59 loc) · 1.78 KB
/
Copy pathshell.py
File metadata and controls
78 lines (59 loc) · 1.78 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
73
74
75
76
77
78
__author__ = "Vanessa Sochat"
__copyright__ = "Copyright 2021-2024, Vanessa Sochat"
__license__ = "MPL 2.0"
import shpc.utils
def main(args, parser, extra, subparser):
shpc.utils.ensure_no_extra(extra)
lookup = {"ipython": ipython, "python": python, "bpython": bpython}
shells = ["ipython", "python", "bpython"]
# Case 1. shell into a container
if args.module_name:
client = create_client(args)
return client.shell(args.module_name)
# The default shell determined by the command line client
shell = args.interpreter
if shell is not None:
shell = shell.lower()
if shell in lookup:
try:
return lookup[shell](args)
except ImportError:
pass
# Otherwise present order of likelihood to have on system
for shell in shells:
try:
return lookup[shell](args)
except ImportError:
pass
def create_client(args):
from shpc.main import get_client
cli = get_client(
quiet=args.quiet,
settings_file=args.settings_file,
module_sys=args.module_sys,
container_tech=args.container_tech,
)
# Update config settings on the fly
cli.settings.update_params(args.config_params)
return cli
def ipython(args):
"""
Generate an IPython shell with the client.
"""
client = create_client(args) # noqa
from IPython import embed
embed()
def bpython(args):
"""
Generate an bpython shell with the client.
"""
import bpython
client = create_client(args)
bpython.embed(locals_={"client": client})
def python(args):
"""
Generate an python shell with the client.
"""
import code
client = create_client(args)
code.interact(local={"client": client})