Skip to content

Commit 354bd94

Browse files
committed
Deparse: remove --AST alias on deparse
1 parent 3542d2e commit 354bd94

File tree

3 files changed

+80
-49
lines changed

3 files changed

+80
-49
lines changed

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
trepan 1.1.0 2020-05-23 pyficache
2+
=================================
3+
4+
* Incorporate a major update of pyficache which removes the coverage dependency.
5+
* More Python source has been reformatted and imports revised along current thinking.
6+
* Some errors in termination messages have been fixed.
7+
* `--AST` renamed to `--tree` since that's what it is and `AST` it is not
8+
19
trepan 1.0.0 2020-04-27 One oh
210
==============================
311

admin-tools/how-to-make-a-release.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@
5454
# Make packages and tag
5555

5656
$ . ./admin-tools/make-dist-older.sh
57-
$ pyenv local 3.8.2
57+
$ pyenv local 3.8.3
5858
$ twine check dist/trepan2-$VERSION*
5959
$ git tag release-python-2.4-$VERSION
6060
$ . ./admin-tools/make-dist-newer.sh
6161
$ twine check dist/trepan2-$VERSION*
6262

6363

64-
# Upload
64+
# Release on github
6565

66-
$ twine upload dist/trepan2-${VERSION}*
66+
Goto https://github.com/rocky/python2-trepan/releases/new
6767

68+
# Get on PyPy
69+
70+
$ twine upload dist/trepan2-${VERSION}*
6871
# Push tags:
6972

7073
$ git push --tags

trepan/processor/command/deparse.py

Lines changed: 66 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2015-2018 Rocky Bernstein
2+
# Copyright (C) 2015-2018, 2020 Rocky Bernstein
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -13,23 +13,25 @@
1313
#
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
import os
16+
17+
import os.path as osp
1718
from getopt import getopt, GetoptError
1819
from uncompyle6.semantics.fragments import code_deparse
19-
from trepan.lib.deparse import (deparse_and_cache, deparse_offset)
20+
from trepan.lib.deparse import deparse_and_cache, deparse_offset
2021
from pyficache import highlight_string, getlines
2122

2223
# Our local modules
23-
from trepan.processor.command import base_cmd as Mbase_cmd
24+
from trepan.processor.command.base_cmd import DebuggerCommand
25+
2426

25-
class DeparseCommand(Mbase_cmd.DebuggerCommand):
27+
class DeparseCommand(DebuggerCommand):
2628
"""**deparse** [options] [ . ]
2729
2830
Options:
2931
------
3032
3133
-p | --parent show parent node
32-
-A | --tree | --AST show abstract syntax tree (AST)
34+
-t | --tree show parse tree
3335
-o | --offset [num] show deparse of offset NUM
3436
-h | --help give this help
3537
@@ -50,97 +52,106 @@ class DeparseCommand(Mbase_cmd.DebuggerCommand):
5052
deparse . # deparse current function or main
5153
deparse --offset 6 # deparse starting at offset 6
5254
deparse --offsets # show all exect deparsing offsets
53-
deparse --AST # deparse and show AST
55+
deparse --tree # deparse and show parse tree
5456
5557
See also:
5658
---------
5759
5860
`disassemble`, `list`, and `set highlight`
5961
"""
6062

61-
category = 'data'
62-
min_args = 0
63-
max_args = 10
64-
name = os.path.basename(__file__).split('.')[0]
65-
need_stack = True
66-
short_help = 'Deparse source via uncompyle6'
63+
category = "data"
64+
min_args = 0
65+
max_args = 10
66+
name = osp.basename(__file__).split(".")[0]
67+
need_stack = True
68+
short_help = "Deparse source via uncompyle6"
6769

6870
def print_text(self, text):
69-
if self.settings['highlight'] == 'plain':
71+
if self.settings["highlight"] == "plain":
7072
self.msg(text)
7173
return
72-
opts = {'bg': self.settings['highlight']}
74+
opts = {"bg": self.settings["highlight"]}
7375

74-
if 'style' in self.settings:
75-
opts['style'] = self.settings['style']
76+
if "style" in self.settings:
77+
opts["style"] = self.settings["style"]
7678
self.msg(highlight_string(text, opts).strip("\n"))
7779

7880
def run(self, args):
7981
co = self.proc.curframe.f_code
8082
name = co.co_name
8183

8284
try:
83-
opts, args = getopt(args[1:], "hpPAto:O",
84-
["help", "parent", "pretty", "AST",
85-
'tree', "offset=", "offsets"])
85+
opts, args = getopt(
86+
args[1:],
87+
"hpPto:O",
88+
["help", "parent", "pretty", "tree", "offset=", "offsets"],
89+
)
8690
except GetoptError as err:
8791
# print help information and exit:
88-
print(str(err)) # will print something like "option -a not recognized"
92+
self.errmsg(
93+
str(err)
94+
) # will print something like "option -a not recognized"
8995
return
9096

9197
show_parent = False
92-
show_ast = False
98+
show_tree = False
9399
offset = None
94100
show_offsets = False
95101
for o, a in opts:
96102
if o in ("-h", "--help"):
97-
self.proc.commands['help'].run(['help', 'deparse'])
103+
self.proc.commands["help"].run(["help", "deparse"])
98104
return
99105
elif o in ("-O", "--offsets"):
100106
show_offsets = True
101107
elif o in ("-p", "--parent"):
102108
show_parent = True
103-
elif o in ("-A", "--tree", '--AST'):
104-
show_ast = True
105-
elif o in ("-o", '--offset'):
109+
elif o in ("-t", "--tree",):
110+
show_tree = True
111+
elif o in ("-o", "--offset"):
106112
offset = a
107113
else:
108114
self.errmsg("unhandled option '%s'" % o)
109115
pass
110116
pass
111117
nodeInfo = None
112118

113-
if len(args) >= 1 and args[0] == '.':
119+
if len(args) >= 1 and args[0] == ".":
114120
temp_filename, name_for_code = deparse_and_cache(co, self.errmsg)
115121
if not temp_filename:
116122
return
117-
self.print_text(''.join(getlines(temp_filename)))
123+
self.print_text("".join(getlines(temp_filename)))
118124
return
119125
elif show_offsets:
120126
deparsed = code_deparse(co)
121127
self.section("Offsets known:")
122-
m = self.columnize_commands(list(sorted(deparsed.offsets.keys(),
123-
key=lambda x: str(x[0]))))
128+
m = self.columnize_commands(
129+
list(sorted(deparsed.offsets.keys(), key=lambda x: str(x[0])))
130+
)
124131
self.msg_nocr(m)
125132
return
126133
elif offset is not None:
127-
mess = ("The 'deparse' command when given an argument requires an"
128-
" instruction offset. Got: '%s'" % offset)
134+
mess = (
135+
"The 'deparse' command when given an argument requires an"
136+
" instruction offset. Got: '%s'" % offset
137+
)
129138
last_i = self.proc.get_an_int(offset, mess)
130139
if last_i is None:
131140
return
132141
else:
133142
last_i = self.proc.curframe.f_lasti
134-
if last_i == -1: last_i = 0
143+
if last_i == -1:
144+
last_i = 0
135145

136146
deparsed, nodeInfo = deparse_offset(co, name, last_i, self.errmsg)
137147
if not deparsed:
138148
return
149+
139150
if nodeInfo:
140151
extractInfo = deparsed.extract_node_info(nodeInfo)
141152
parentInfo = None
142153
# print extractInfo
143-
if show_ast:
154+
if show_tree:
144155
p = deparsed.ast
145156
if show_parent:
146157
parentInfo, p = deparsed.extract_parent_info(nodeInfo.node)
@@ -168,20 +179,29 @@ def run(self, args):
168179
else:
169180
self.msg("At beginning")
170181
else:
171-
self.errmsg("haven't recorded info for offset %d. Offsets I know are:"
172-
% last_i)
173-
offsets = [key[1] for key in deparsed.offsets.keys() if isinstance(key[1], int)]
182+
self.errmsg(
183+
"haven't recorded info for offset %d. Offsets I know are:" % last_i
184+
)
185+
offsets = [
186+
key[1] for key in deparsed.offsets.keys() if isinstance(key[1], int)
187+
]
174188
m = self.columnize_commands(list(sorted(offsets)))
175189
self.msg_nocr(m)
176190
return
191+
177192
pass
178193

179-
# if __name__ == '__main__':
180-
# from trepan import debugger
181-
# d = debugger.Trepan()
182-
# cp = d.core.processor
183-
# command = DeparseCommand(d.core.processor)
184-
# command.proc.frame = sys._getframe()
185-
# command.proc.setup()
186-
# command.run(['deparse'])
187-
# pass
194+
195+
if __name__ == "__main__":
196+
import sys
197+
from trepan import debugger
198+
199+
d = debugger.Debugger()
200+
cp = d.core.processor
201+
command = DeparseCommand(d.core.processor)
202+
command.proc.frame = sys._getframe()
203+
command.proc.setup()
204+
command.run(["deparse", "--bad"])
205+
command.run(["deparse"])
206+
command.run(["deparse", "--help"])
207+
pass

0 commit comments

Comments
 (0)