Skip to content

Commit 3d5afa3

Browse files
committed
blacked!
1 parent a2f7ff7 commit 3d5afa3

File tree

1 file changed

+78
-52
lines changed

1 file changed

+78
-52
lines changed

roboticstoolbox/bin/rtbtool

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ from IPython.terminal.prompts import ClassicPrompts
1919
from traitlets.config import Config
2020
import IPython
2121
import argparse
22-
from math import pi # lgtm [py/unused-import]
22+
from math import pi # lgtm [py/unused-import]
2323
import numpy as np
2424
import scipy as sp
2525
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]
3030
from spatialmath.base import sym
3131
import matplotlib as mpl
3232
from pathlib import Path
@@ -35,6 +35,7 @@ from importlib.metadata import version
3535

3636
try:
3737
from colored import fg, bg, attr
38+
3839
_colored = True
3940
# print('using colored output')
4041
except ImportError:
@@ -43,38 +44,57 @@ except ImportError:
4344

4445
# setup defaults
4546
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")
5454
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")
6362
parser.add_argument(
64-
'--resultprefix',
65-
'-r',
63+
"--resultprefix",
64+
"-r",
6665
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+
)
7898
args = parser.parse_args()
7999

80100
# TODO more options
@@ -85,8 +105,8 @@ sys.argv = [sys.argv[0]]
85105

86106
if args.book:
87107
# set book options
88-
args.resultprefix = ''
89-
args.prompt = '>>> '
108+
args.resultprefix = ""
109+
args.prompt = ">>> "
90110
args.showassign = True
91111
args.ansi = False
92112
args.examples = True
@@ -110,12 +130,14 @@ panda = models.DH.Panda()
110130
# print the banner
111131
# https://patorjk.com/software/taag/#p=display&f=Cybermedium&t=Robotics%20Toolbox%0A
112132

113-
banner = fg('yellow') + r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
133+
banner = (
134+
fg("yellow")
135+
+ r"""____ ____ ___ ____ ___ _ ____ ____ ___ ____ ____ _ ___ ____ _ _
114136
|__/ | | |__] | | | | | [__ | | | | | | |__] | | \/
115137
| \ |__| |__] |__| | | |___ ___] | |__| |__| |___ |__] |__| _/\_
116138
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')})"
119141
+ r"""
120142
121143
from roboticstoolbox import *
@@ -127,17 +149,20 @@ func/object? - show brief help
127149
help(func/object) - show detailed help
128150
func/object?? - show source code
129151
130-
""" + attr(0)
152+
"""
153+
+ attr(0)
154+
)
131155

132156
print(banner)
133157

134158
if args.showassign:
135159
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
138162
139163
""",
140-
attr(0))
164+
attr(0),
165+
)
141166

142167
# drop into IPython
143168
class MyPrompt(Prompts):
@@ -148,13 +173,14 @@ class MyPrompt(Prompts):
148173
if args.resultprefix is None:
149174
# traditional behaviour
150175
return [
151-
(Token.OutPrompt, 'Out['),
176+
(Token.OutPrompt, "Out["),
152177
(Token.OutPromptNum, str(self.shell.execution_count)),
153-
(Token.OutPrompt, ']: '),
178+
(Token.OutPrompt, "]: "),
154179
]
155180
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+
]
158184

159185

160186
# set configuration options, there are lots, see
@@ -165,7 +191,7 @@ c.InteractiveShell.confirm_exit = args.confirmexit
165191
# c.InteractiveShell.prompts_class = ClassicPrompts
166192
c.InteractiveShell.prompts_class = MyPrompt
167193
if args.showassign:
168-
c.InteractiveShell.ast_node_interactivity = 'last_expr_or_assign'
194+
c.InteractiveShell.ast_node_interactivity = "last_expr_or_assign"
169195

170196
# set precision, same as %precision
171197
c.PlainTextFormatter.float_precision = "%.3f"
@@ -176,13 +202,13 @@ if args.script is not None:
176202
path = Path(args.script)
177203
if not path.exists():
178204
raise ValueError(f"script does not exist: {args.script}")
179-
code = path.open('r').readlines()
205+
code = path.open("r").readlines()
180206
if code is None:
181207
code = [
182208
"plt.ion()",
183-
]
184-
209+
]
210+
185211
else:
186212
code.append("plt.ion()")
187213
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

Comments
 (0)