@@ -19,14 +19,14 @@ from IPython.terminal.prompts import ClassicPrompts
19
19
from traitlets .config import Config
20
20
import IPython
21
21
import argparse
22
- from math import pi # lgtm [py/unused-import]
22
+ from math import pi # lgtm [py/unused-import]
23
23
import numpy as np
24
24
import scipy as sp
25
25
import matplotlib .pyplot as plt # lgtm [py/unused-import]
26
- from roboticstoolbox import * # lgtm [py/unused-import]
27
- from spatialmath import * # lgtm [py/polluting-import]
28
- from spatialgeometry import * # lgtm [py/polluting-import]
29
- from spatialmath .base import * # lgtm [py/polluting-import]
26
+ from roboticstoolbox import * # lgtm [py/unused-import]
27
+ from spatialmath import * # lgtm [py/polluting-import]
28
+ from spatialgeometry import * # lgtm [py/polluting-import]
29
+ from spatialmath .base import * # lgtm [py/polluting-import]
30
30
from spatialmath .base import sym
31
31
import matplotlib as mpl
32
32
from pathlib import Path
@@ -35,6 +35,7 @@ from importlib.metadata import version
35
35
36
36
try :
37
37
from colored import fg , bg , attr
38
+
38
39
_colored = True
39
40
# print('using colored output')
40
41
except ImportError :
@@ -43,38 +44,57 @@ except ImportError:
43
44
44
45
# setup defaults
45
46
np .set_printoptions (
46
- linewidth = 120 , formatter = {
47
- 'float' : lambda x : f"{ x :8.4g} " if abs (x ) > 1e-10 else f"{ 0 :8.4g} " })
48
-
49
- parser = argparse .ArgumentParser ('Robotics Toolbox shell' )
50
- parser .add_argument ('script' , default = None , nargs = '?' ,
51
- help = 'specify script to run' )
52
- parser .add_argument ('--backend' , '-b' , default = None ,
53
- help = 'specify graphics backend' )
47
+ linewidth = 120 ,
48
+ formatter = {"float" : lambda x : f"{ x :8.4g} " if abs (x ) > 1e-10 else f"{ 0 :8.4g} " },
49
+ )
50
+
51
+ parser = argparse .ArgumentParser ("Robotics Toolbox shell" )
52
+ parser .add_argument ("script" , default = None , nargs = "?" , help = "specify script to run" )
53
+ parser .add_argument ("--backend" , "-b" , default = None , help = "specify graphics backend" )
54
54
parser .add_argument (
55
- '--color' ,
56
- '-c' ,
57
- default = 'neutral' ,
58
- help = 'specify terminal color scheme (neutral, lightbg, nocolor, linux), linux is for dark mode' )
59
- parser .add_argument ('--confirmexit' , '-x' , default = False ,
60
- help = 'confirm exit' )
61
- parser .add_argument ('--prompt' , '-p' , default = '(rtb) >>> ' ,
62
- help = 'input prompt' )
55
+ "--color" ,
56
+ "-c" ,
57
+ default = "neutral" ,
58
+ help = "specify terminal color scheme (neutral, lightbg, nocolor, linux), linux is for dark mode" ,
59
+ )
60
+ parser .add_argument ("--confirmexit" , "-x" , default = False , help = "confirm exit" )
61
+ parser .add_argument ("--prompt" , "-p" , default = "(rtb) >>> " , help = "input prompt" )
63
62
parser .add_argument (
64
- ' --resultprefix' ,
65
- '-r' ,
63
+ " --resultprefix" ,
64
+ "-r" ,
66
65
default = None ,
67
- help = 'execution result prefix, include {} for execution count number' )
68
- parser .add_argument ('--showassign' , '-a' , default = False , action = 'store_true' ,
69
- help = 'do not display the result of assignments' )
70
- parser .add_argument ('--book' , default = False , action = 'store_true' ,
71
- help = 'use defaults as per RVC book' )
72
- parser .add_argument ('--ansi' , default = False , action = 'store_true' ,
73
- help = 'use ANSImatrix to display matrices' )
74
- parser .add_argument ('--examples' , '-e' , default = False , action = 'store_true' ,
75
- help = 'change working directory to shipped examples' )
76
- parser .add_argument ('--swift' , '-s' , default = False , action = 'store_true' ,
77
- help = 'use Swift as default backend' )
66
+ help = "execution result prefix, include {} for execution count number" ,
67
+ )
68
+ parser .add_argument (
69
+ "--showassign" ,
70
+ "-a" ,
71
+ default = False ,
72
+ action = "store_true" ,
73
+ help = "do not display the result of assignments" ,
74
+ )
75
+ parser .add_argument (
76
+ "--book" , default = False , action = "store_true" , help = "use defaults as per RVC book"
77
+ )
78
+ parser .add_argument (
79
+ "--ansi" ,
80
+ default = False ,
81
+ action = "store_true" ,
82
+ help = "use ANSImatrix to display matrices" ,
83
+ )
84
+ parser .add_argument (
85
+ "--examples" ,
86
+ "-e" ,
87
+ default = False ,
88
+ action = "store_true" ,
89
+ help = "change working directory to shipped examples" ,
90
+ )
91
+ parser .add_argument (
92
+ "--swift" ,
93
+ "-s" ,
94
+ default = False ,
95
+ action = "store_true" ,
96
+ help = "use Swift as default backend" ,
97
+ )
78
98
args = parser .parse_args ()
79
99
80
100
# TODO more options
@@ -85,8 +105,8 @@ sys.argv = [sys.argv[0]]
85
105
86
106
if args .book :
87
107
# set book options
88
- args .resultprefix = ''
89
- args .prompt = ' >>> '
108
+ args .resultprefix = ""
109
+ args .prompt = " >>> "
90
110
args .showassign = True
91
111
args .ansi = False
92
112
args .examples = True
@@ -110,12 +130,14 @@ panda = models.DH.Panda()
110
130
# print the banner
111
131
# https://patorjk.com/software/taag/#p=display&f=Cybermedium&t=Robotics%20Toolbox%0A
112
132
113
- banner = fg ('yellow' ) + r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
133
+ banner = (
134
+ fg ("yellow" )
135
+ + r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
114
136
|__/ | | |__] | | | | | [__ | | | | | | |__] | | \/
115
137
| \ |__| |__] |__| | | |___ ___] | |__| |__| |___ |__] |__| _/\_
116
138
117
- for Python""" \
118
- + f" (RTB=={ version ('roboticstoolbox-python' )} , SMTB=={ version ('spatialmath-python' )} )" \
139
+ for Python"""
140
+ + f" (RTB=={ version ('roboticstoolbox-python' )} , SMTB=={ version ('spatialmath-python' )} )"
119
141
+ r"""
120
142
121
143
from roboticstoolbox import *
@@ -127,17 +149,20 @@ func/object? - show brief help
127
149
help(func/object) - show detailed help
128
150
func/object?? - show source code
129
151
130
- """ + attr (0 )
152
+ """
153
+ + attr (0 )
154
+ )
131
155
132
156
print (banner )
133
157
134
158
if args .showassign :
135
159
print (
136
- fg (' red' ) +
137
- """Results of assignments will be displayed, use trailing ; to suppress
160
+ fg (" red" )
161
+ + """Results of assignments will be displayed, use trailing ; to suppress
138
162
139
163
""" ,
140
- attr (0 ))
164
+ attr (0 ),
165
+ )
141
166
142
167
# drop into IPython
143
168
class MyPrompt (Prompts ):
@@ -148,13 +173,14 @@ class MyPrompt(Prompts):
148
173
if args .resultprefix is None :
149
174
# traditional behaviour
150
175
return [
151
- (Token .OutPrompt , ' Out[' ),
176
+ (Token .OutPrompt , " Out[" ),
152
177
(Token .OutPromptNum , str (self .shell .execution_count )),
153
- (Token .OutPrompt , ' ]: ' ),
178
+ (Token .OutPrompt , " ]: " ),
154
179
]
155
180
else :
156
- return [(Token .Prompt , args .resultprefix .format (
157
- self .shell .execution_count ))]
181
+ return [
182
+ (Token .Prompt , args .resultprefix .format (self .shell .execution_count ))
183
+ ]
158
184
159
185
160
186
# set configuration options, there are lots, see
@@ -165,7 +191,7 @@ c.InteractiveShell.confirm_exit = args.confirmexit
165
191
# c.InteractiveShell.prompts_class = ClassicPrompts
166
192
c .InteractiveShell .prompts_class = MyPrompt
167
193
if args .showassign :
168
- c .InteractiveShell .ast_node_interactivity = ' last_expr_or_assign'
194
+ c .InteractiveShell .ast_node_interactivity = " last_expr_or_assign"
169
195
170
196
# set precision, same as %precision
171
197
c .PlainTextFormatter .float_precision = "%.3f"
@@ -176,13 +202,13 @@ if args.script is not None:
176
202
path = Path (args .script )
177
203
if not path .exists ():
178
204
raise ValueError (f"script does not exist: { args .script } " )
179
- code = path .open ('r' ).readlines ()
205
+ code = path .open ("r" ).readlines ()
180
206
if code is None :
181
207
code = [
182
208
"plt.ion()" ,
183
- ]
184
-
209
+ ]
210
+
185
211
else :
186
212
code .append ("plt.ion()" )
187
213
c .InteractiveShellApp .exec_lines = code
188
- IPython .start_ipython (config = c , user_ns = globals ())
214
+ IPython .start_ipython (config = c , user_ns = globals ())
0 commit comments