Skip to content

Commit 7a04c9c

Browse files
committed
Blaken some files
1 parent 3d2db48 commit 7a04c9c

4 files changed

Lines changed: 175 additions & 110 deletions

File tree

trepan/cli.py

Lines changed: 100 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#
1616
# You should have received a copy of the GNU General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18-
'''The command-line interface to the debugger.
19-
'''
18+
"""The command-line interface to the debugger.
19+
"""
2020
from __future__ import print_function
2121
import pyficache, os, sys, tempfile
2222
import os.path as osp
@@ -31,7 +31,7 @@
3131
from trepan import misc as Mmisc
3232

3333
# The name of the debugger we are currently going by.
34-
__title__ = 'trepan2'
34+
__title__ = "trepan2"
3535

3636
# VERSION.py sets variable VERSION.
3737
from trepan.version import VERSION as __version__
@@ -42,24 +42,23 @@ def main(dbg=None, sys_argv=list(sys.argv)):
4242

4343
# Save the original just for use in the restart that works via exec.
4444
orig_sys_argv = list(sys_argv)
45-
opts, dbg_opts, sys_argv = Moptions.process_options(__title__,
46-
__version__,
47-
sys_argv)
45+
opts, dbg_opts, sys_argv = Moptions.process_options(
46+
__title__, __version__, sys_argv
47+
)
4848
if opts.server:
49-
connection_opts={'IO': 'TCP', 'PORT': opts.port}
49+
connection_opts = {"IO": "TCP", "PORT": opts.port}
5050
intf = Mserver.ServerInterface(connection_opts=connection_opts)
51-
dbg_opts['interface'] = intf
52-
if 'FIFO' == intf.server_type:
53-
print('Starting FIFO server for process %s.' % os.getpid())
54-
elif 'TCP' == intf.server_type:
55-
print('Starting TCP server listening on port %s.' %
56-
intf.inout.PORT)
51+
dbg_opts["interface"] = intf
52+
if "FIFO" == intf.server_type:
53+
print("Starting FIFO server for process %s." % os.getpid())
54+
elif "TCP" == intf.server_type:
55+
print("Starting TCP server listening on port %s." % intf.inout.PORT)
5756
pass
5857
elif opts.client:
5958
Mclient.main(opts, sys_argv)
6059
return
6160

62-
dbg_opts['orig_sys_argv'] = orig_sys_argv
61+
dbg_opts["orig_sys_argv"] = orig_sys_argv
6362

6463
if dbg is None:
6564
dbg = Mdebugger.Debugger(dbg_opts)
@@ -78,65 +77,97 @@ def main(dbg=None, sys_argv=list(sys.argv)):
7877
else:
7978
mainpyfile = sys_argv[0] # Get script filename.
8079
if not osp.isfile(mainpyfile):
81-
mainpyfile=Mclifns.whence_file(mainpyfile)
80+
mainpyfile = Mclifns.whence_file(mainpyfile)
8281
is_readable = Mfile.readable(mainpyfile)
8382
if is_readable is None:
84-
print("%s: Python script file '%s' does not exist"
85-
% (__title__, mainpyfile,), file=sys.stderr)
83+
print(
84+
"%s: Python script file '%s' does not exist"
85+
% (
86+
__title__,
87+
mainpyfile,
88+
),
89+
file=sys.stderr,
90+
)
8691
sys.exit(1)
8792
elif not is_readable:
88-
print("%s: Can't read Python script file '%s'"
89-
% (__title__, mainpyfile, ), file=sys.stderr)
93+
print(
94+
"%s: Can't read Python script file '%s'"
95+
% (
96+
__title__,
97+
mainpyfile,
98+
),
99+
file=sys.stderr,
100+
)
90101
sys.exit(1)
91102
return
92103

93104
if Mfile.is_compiled_py(mainpyfile):
94105
try:
95106
from xdis import load_module, PYTHON_VERSION, IS_PYPY
96-
(python_version, timestamp, magic_int, co, is_pypy,
97-
source_size) = load_module(mainpyfile, code_objects=None,
98-
fast_load=True)
107+
108+
(
109+
python_version,
110+
timestamp,
111+
magic_int,
112+
co,
113+
is_pypy,
114+
source_size,
115+
) = load_module(mainpyfile, code_objects=None, fast_load=True)
99116
assert is_pypy == IS_PYPY
100-
assert python_version == PYTHON_VERSION, \
101-
"bytecode is for version %s but we are version %s" % (
102-
python_version, PYTHON_VERSION)
117+
assert (
118+
python_version == PYTHON_VERSION
119+
), "bytecode is for version %s but we are version %s" % (
120+
python_version,
121+
PYTHON_VERSION,
122+
)
103123
# We should we check version magic_int
104124

105125
py_file = co.co_filename
106126
if osp.isabs(py_file):
107127
try_file = py_file
108128
else:
109129
mainpydir = osp.dirname(mainpyfile)
110-
dirnames = [mainpydir] + os.environ['PATH'].split(os.pathsep) + ['.']
130+
dirnames = (
131+
[mainpydir] + os.environ["PATH"].split(os.pathsep) + ["."]
132+
)
111133
try_file = Mclifns.whence_file(py_file, dirnames)
112134

113135
if osp.isfile(try_file):
114136
mainpyfile = try_file
115137
pass
116138
else:
117139
# Move onto the except branch
118-
raise IOError("Python file name embedded in code %s not found" % try_file)
140+
raise IOError(
141+
"Python file name embedded in code %s not found" % try_file
142+
)
119143
except:
120144
try:
121145
from uncompyle6 import decompile_file
122146
except ImportError:
123-
print("%s: Compiled python file '%s', but uncompyle6 not found"
124-
% (__title__, mainpyfile), file=sys.stderr)
147+
print(
148+
"%s: Compiled python file '%s', but uncompyle6 not found"
149+
% (__title__, mainpyfile),
150+
file=sys.stderr,
151+
)
125152
sys.exit(1)
126153
return
127154

128155
short_name = osp.basename(mainpyfile).strip(".pyc")
129-
fd = tempfile.NamedTemporaryFile(suffix='.py',
130-
prefix=short_name + "_",
131-
dir=dbg.settings["tempdir"],
132-
delete=False)
156+
fd = tempfile.NamedTemporaryFile(
157+
suffix=".py",
158+
prefix=short_name + "_",
159+
dir=dbg.settings["tempdir"],
160+
delete=False,
161+
)
133162
try:
134163
decompile_file(mainpyfile, outstream=fd)
135164
mainpyfile = fd.name
136165
fd.close()
137166
except:
138-
print("%s: error uncompiling '%s'"
139-
% (__title__, mainpyfile), file=sys.stderr)
167+
print(
168+
"%s: error uncompiling '%s'" % (__title__, mainpyfile),
169+
file=sys.stderr,
170+
)
140171
fd.close()
141172
os.unlink(fd.name)
142173
# FIXME: remove the below line and continue with just the
@@ -147,12 +178,19 @@ def main(dbg=None, sys_argv=list(sys.argv)):
147178
# If mainpyfile is an optimized Python script try to find and
148179
# use non-optimized alternative.
149180
mainpyfile_noopt = pyficache.resolve_name_to_path(mainpyfile)
150-
if mainpyfile != mainpyfile_noopt \
151-
and Mfile.readable(mainpyfile_noopt):
152-
print("%s: Compiled Python script given and we can't use that."
153-
% __title__, file=sys.stderr)
154-
print("%s: Substituting non-compiled name: %s" % (
155-
__title__, mainpyfile_noopt,), file=sys.stderr)
181+
if mainpyfile != mainpyfile_noopt and Mfile.readable(mainpyfile_noopt):
182+
print(
183+
"%s: Compiled Python script given and we can't use that." % __title__,
184+
file=sys.stderr,
185+
)
186+
print(
187+
"%s: Substituting non-compiled name: %s"
188+
% (
189+
__title__,
190+
mainpyfile_noopt,
191+
),
192+
file=sys.stderr,
193+
)
156194
mainpyfile = mainpyfile_noopt
157195
pass
158196

@@ -177,27 +215,29 @@ def main(dbg=None, sys_argv=list(sys.argv)):
177215
try:
178216
if dbg.program_sys_argv and mainpyfile:
179217
normal_termination = dbg.run_script(mainpyfile)
180-
if not normal_termination: break
218+
if not normal_termination:
219+
break
181220
else:
182-
dbg.core.execution_status = 'No program'
221+
dbg.core.execution_status = "No program"
183222
dbg.core.processor.process_commands()
184223
pass
185224

186-
dbg.core.execution_status = 'Terminated'
225+
dbg.core.execution_status = "Terminated"
187226
dbg.intf[-1].msg("The program finished - quit or restart")
188227
dbg.core.processor.process_commands()
189228
except Mexcept.DebuggerQuit:
190229
break
191230
except Mexcept.DebuggerRestart:
192-
dbg.core.execution_status = 'Restart requested'
231+
dbg.core.execution_status = "Restart requested"
193232
if dbg.program_sys_argv:
194233
sys.argv = list(dbg.program_sys_argv)
195-
part1 = ('Restarting %s with arguments:' %
196-
dbg.core.filename(mainpyfile))
197-
args = ' '.join(dbg.program_sys_argv[1:])
198-
dbg.intf[-1].msg(Mmisc.wrapped_lines(part1, args,
199-
dbg.settings['width']))
200-
else: break
234+
part1 = "Restarting %s with arguments:" % dbg.core.filename(mainpyfile)
235+
args = " ".join(dbg.program_sys_argv[1:])
236+
dbg.intf[-1].msg(
237+
Mmisc.wrapped_lines(part1, args, dbg.settings["width"])
238+
)
239+
else:
240+
break
201241
except SystemExit:
202242
# In most cases SystemExit does not warrant a post-mortem session.
203243
break
@@ -207,15 +247,16 @@ def main(dbg=None, sys_argv=list(sys.argv)):
207247
if exception_name == str(Mexcept.DebuggerQuit):
208248
break
209249
elif exception_name == str(Mexcept.DebuggerRestart):
210-
dbg.core.execution_status = 'Restart requested'
250+
dbg.core.execution_status = "Restart requested"
211251
if dbg.program_sys_argv:
212252
sys.argv = list(dbg.program_sys_argv)
213-
part1 = ('Restarting %s with arguments:' %
214-
dbg.core.filename(mainpyfile))
215-
args = ' '.join(dbg.program_sys_argv[1:])
253+
part1 = "Restarting %s with arguments:" % dbg.core.filename(
254+
mainpyfile
255+
)
256+
args = " ".join(dbg.program_sys_argv[1:])
216257
dbg.intf[-1].msg(
217-
Mmisc.wrapped_lines(part1, args,
218-
dbg.settings['width']))
258+
Mmisc.wrapped_lines(part1, args, dbg.settings["width"])
259+
)
219260
pass
220261
else:
221262
raise
@@ -225,7 +266,8 @@ def main(dbg=None, sys_argv=list(sys.argv)):
225266
sys.argv = orig_sys_argv
226267
return
227268

269+
228270
# When invoked as main program, invoke the debugger on a script
229-
if __name__=='__main__':
271+
if __name__ == "__main__":
230272
main()
231273
pass

0 commit comments

Comments
 (0)