Skip to content

Commit 2d4259e

Browse files
committed
Try using decompyle3 on 3.7 and 3.8
1 parent 2fd7354 commit 2d4259e

6 files changed

Lines changed: 44 additions & 15 deletions

File tree

__pkginfo__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323

2424
import sys
2525

26+
decompiler = "uncompyle6 >= 3.7.4"
27+
2628
SYS_VERSION = sys.version_info[0:2]
2729
if SYS_VERSION <= (3, 2):
2830
pygments_version = "== 1.6"
2931
else:
3032
pygments_version = ">= 2.2.0"
33+
if (3, 7) <= SYS_VERSION <= (3, 8):
34+
decompiler = "decompyle3 >= 3.7.4"
35+
3136

3237
# Python-version | package | last-version |
3338
# ------------------------------------------
@@ -78,7 +83,7 @@
7883
"spark_parser >= 1.8.9, <1.9.0",
7984
"tracer >= 0.3.2",
8085
"term-background >= 1.0.1",
81-
"uncompyle6 >= 3.7.4",
86+
decompiler,
8287
]
8388
license = "GPL3"
8489
mailing_list = "python-debugger@googlegroups.com"

trepan/__main__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,18 @@ def main(dbg=None, sys_argv=list(sys.argv)):
145145
"Python file name embedded in code %s not found" % try_file
146146
)
147147
except IOError:
148+
decompiler = "uncompyle6"
148149
try:
149-
from uncompyle6 import decompile_file
150+
if 3.7 <= PYTHON_VERSION <= 3.8:
151+
from uncompyle6 import decompile_file
152+
else:
153+
from decompyle3 import decompile_file
154+
155+
decompiler = "decompyle3"
150156
except ImportError:
151157
print(
152-
"%s: Compiled python file '%s', but uncompyle6 not found"
153-
% (__title__, mainpyfile),
158+
"%s: Compiled python file '%s', but %s not found"
159+
% (__title__, mainpyfile, decompiler),
154160
file=sys.stderr,
155161
)
156162
sys.exit(1)

trepan/lib/deparse.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
import sys, tempfile
55
from io import StringIO
66
from hashlib import sha1
7-
from uncompyle6.semantics.linemap import code_deparse_with_map
8-
from uncompyle6.semantics.fragments import deparsed_find, code_deparse
7+
from xdis import PYTHON_VERSION
8+
9+
if 3.7 <= PYTHON_VERSION <= 3.8:
10+
from decompyle3.semantics.linemap import code_deparse_with_map
11+
from decompyle3.semantics.fragments import deparsed_find, code_deparse
12+
else:
13+
from uncompyle6.semantics.linemap import code_deparse_with_map
14+
from uncompyle6.semantics.fragments import deparsed_find, code_deparse
15+
916
import pyficache
1017

1118
# FIXME remap filename to a short name.

trepan/processor/cmdfns.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"""
2020
import os, sys, tempfile
2121
import pyficache
22-
from xdis import IS_PYPY
22+
from xdis import IS_PYPY, PYTHON_VERSION
2323

2424

2525
def source_tempfile_remap(prefix, text, tempdir=None):
@@ -35,9 +35,15 @@ def source_tempfile_remap(prefix, text, tempdir=None):
3535

3636
def deparse_fn(code):
3737
try:
38-
from uncompyle6.semanitcs.linemap import (
39-
deparse_code_with_fragments_and_map as deparse_code,
40-
)
38+
if 3.7 <= PYTHON_VERSION <= 3.8:
39+
from uncompyle6.semantics.linemap import (
40+
deparse_code_with_fragments_and_map as deparse_code,
41+
)
42+
else:
43+
from decompile3.semantics.linemap import (
44+
deparse_code_with_fragments_and_map as deparse_code,
45+
)
46+
4147
except ImportError:
4248
return None
4349
sys_version = sys.version[:5]

trepan/processor/command/deparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DeparseCommand(DebuggerCommand):
5959
`disassemble`, `list`, and `set highlight`
6060
"""
6161

62-
short_help = "Deparse source via uncompyle6"
62+
short_help = "Deparse source via uncompyle6/decompyle3"
6363
DebuggerCommand.setup(locals(), category="data", max_args=10, need_stack=True)
6464

6565
def print_text(self, text):

trepan/processor/command/deval.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2017-2018, 2020 Rocky Bernstein
2+
# Copyright (C) 2017-2018, 2020-2021 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
@@ -16,10 +16,15 @@
1616

1717
# Our local modules
1818
from sys import version_info
19+
from xdis import IS_PYPY, PYTHON_VERSION
1920
from trepan.processor.command.base_cmd import DebuggerCommand
20-
from uncompyle6.semantics.fragments import deparse_code
21-
from xdis import IS_PYPY
22-
from uncompyle6.semantics.fragments import deparsed_find
21+
22+
if 3.7 <= PYTHON_VERSION <= 3.8:
23+
from decompyle3.semantics.fragments import deparse_code
24+
from decompyle3.semantics.fragments import deparsed_find
25+
else:
26+
from uncompyle6.semantics.fragments import deparse_code
27+
from uncompyle6.semantics.fragments import deparsed_find
2328

2429

2530
class DEvalCommand(DebuggerCommand):

0 commit comments

Comments
 (0)