Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ check-3.0 check-3.1 check-3.2 check-3.6:
check-3.7: pytest
$(MAKE) -C test check

check-3.8:
$(MAKE) -C test check
check-3.8 check-3.9 check-3.10 check-3.11 check-3.12 check-3.13:
$(MAKE) -C test check-3.8

#:PyPy 2.6.1 PyPy 5.0.1, or PyPy 5.8.0-beta0
# Skip for now
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
[build-system]
requires = [
"setuptools",
# "setuptools>=59.6.0", # for 3.6
]

requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -44,6 +40,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dynamic = ["version"]

Expand All @@ -63,3 +60,6 @@ uncompyle6-tokenize = "uncompyle6.bin.pydisassemble:main"

[tool.setuptools.dynamic]
version = {attr = "uncompyle6.version.__version__"}

[tool.setuptools.packages.find]
include = ["uncompyle6*"] # Include all subpackages
6 changes: 0 additions & 6 deletions setup.py

This file was deleted.

35 changes: 17 additions & 18 deletions uncompyle6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,26 @@

__docformat__ = "restructuredtext"

from uncompyle6.version import __version__ # noqa
# from uncompyle6.version import __version__ # noqa

if hasattr(sys, "setrecursionlimit"):
# pyston doesn't have setrecursionlimit
sys.setrecursionlimit(5000)
# if hasattr(sys, "setrecursionlimit"):
# # pyston doesn't have setrecursionlimit
# sys.setrecursionlimit(5000)

from uncompyle6.semantics import fragments, pysource
# from uncompyle6.semantics import semantics

# Export some functions
from uncompyle6.main import decompile_file # noqa
# # Export some functions
# from uncompyle6.main import decompile_file # noqa

# Convenience functions so you can say:
# from uncompyle6 import (code_deparse, deparse_code2str)
# # Convenience functions so you can say:
# # from uncompyle6 import (code_deparse, deparse_code2str)

from uncompyle6.semantics.pysource import code_deparse, deparse_code2str
# from uncompyle6.semantics.pysource import code_deparse, deparse_code2str

__all__ = [
"__version__",
"code_deparse",
"decompile_file",
"deparse_code2str",
"fragments",
"pysource",
]
# # __all__ = [
# # "__version__",
# # "code_deparse",
# # "decompile_file",
# # "deparse_code2str",
# # "semantics",
# # ]
13 changes: 8 additions & 5 deletions uncompyle6/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@

from uncompyle6.code_fns import check_object_path
from uncompyle6.parser import ParserError
from uncompyle6.semantics import pysource
from uncompyle6.semantics.fragments import code_deparse as code_deparse_fragments
from uncompyle6.semantics.linemap import deparse_code_with_map
from uncompyle6.semantics.pysource import PARSER_DEFAULT_DEBUG, code_deparse
from uncompyle6.semantics.pysource import (
PARSER_DEFAULT_DEBUG,
SourceWalkerError,
code_deparse,
)
from uncompyle6.version import __version__

# from uncompyle6.linenumbers import line_number_mapping
Expand Down Expand Up @@ -173,9 +176,9 @@ def write(s):
pass
real_out.write("\n")
return deparsed
except pysource.SourceWalkerError as e:
except SourceWalkerError as e:
# deparsing failed
raise pysource.SourceWalkerError(str(e))
raise SourceWalkerError(str(e))


def compile_file(source_path: str) -> str:
Expand Down Expand Up @@ -412,7 +415,7 @@ def main(
# sys.stderr.write(f"Ran {deparsed_object.f.name}\n")
pass
tot_files += 1
except (ValueError, SyntaxError, ParserError, pysource.SourceWalkerError) as e:
except (ValueError, SyntaxError, ParserError, SourceWalkerError) as e:
sys.stdout.write("\n")
sys.stderr.write(f"\n# file {infile}\n# {e}\n")
failed_files += 1
Expand Down
11 changes: 6 additions & 5 deletions uncompyle6/scanner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2016, 2018-2024 by Rocky Bernstein
# Copyright (c) 2016, 2018-2025 by Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock
Expand All @@ -21,6 +21,7 @@
scanners, e.g. for Python 2.7 or 3.4.
"""

import importlib
from abc import ABC
from array import array
from collections import namedtuple
Expand Down Expand Up @@ -115,15 +116,15 @@ def __init__(self, version: tuple, show_asm=None, is_pypy=False):
self.show_asm = show_asm
self.is_pypy = is_pypy

# Temoorary initialization.
# Temporary initialization.
self.opc = ModuleType("uninitialized")

if version[:2] in PYTHON_VERSIONS:
v_str = f"""opcode_{version_tuple_to_str(version, start=0, end=2, delimiter="")}"""
module_name = f"xdis.opcodes.{v_str}"
if is_pypy:
v_str += "pypy"
exec(f"""from xdis.opcodes import {v_str}""")
exec("self.opc = %s" % v_str)
module_name += "pypy"
self.opc = importlib.import_module(module_name)
else:
raise TypeError(
"%s is not a Python version I know about"
Expand Down
26 changes: 13 additions & 13 deletions uncompyle6/semantics/fragments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2019, 2021-2024 by Rocky Bernstein
# Copyright (c) 2015-2019, 2021-2025 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -73,10 +73,9 @@
from xdis import iscode
from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE

import uncompyle6.parser as python_parser
from uncompyle6.parser import ParserError as ParserError, parse
from uncompyle6.parsers.treenode import SyntaxTree
from uncompyle6.scanner import Code, Token, get_scanner
from uncompyle6.semantics import pysource
from uncompyle6.semantics.check_ast import checker
from uncompyle6.semantics.consts import (
INDENT_PER_LEVEL,
Expand All @@ -90,8 +89,9 @@
from uncompyle6.semantics.pysource import (
DEFAULT_DEBUG_OPTS,
TREE_DEFAULT_DEBUG,
ParserError,
SourceWalker,
StringIO,
find_globals_and_nonlocals,
)
from uncompyle6.show import maybe_show_asm, maybe_show_tree

Expand Down Expand Up @@ -147,7 +147,7 @@
}


class FragmentsWalker(pysource.SourceWalker, object):
class FragmentsWalker(SourceWalker, object):
MAP_DIRECT_FRAGMENT = ()

stacked_params = ("f", "indent", "is_lambda", "_globals")
Expand All @@ -163,7 +163,7 @@ def __init__(
linestarts={},
tolerate_errors=True,
):
pysource.SourceWalker.__init__(
SourceWalker.__init__(
self,
version=version,
out=StringIO(),
Expand Down Expand Up @@ -237,7 +237,7 @@ def set_pos_info(self, node, start, finish, name=None):

def preorder(self, node=None):
start = len(self.f.getvalue())
super(pysource.SourceWalker, self).preorder(node)
super(SourceWalker, self).preorder(node)
self.set_pos_info(node, start, len(self.f.getvalue()))

return
Expand Down Expand Up @@ -1177,11 +1177,11 @@ def build_ast(
p_insts = self.p.insts
self.p.insts = self.scanner.insts
self.p.offset2inst_index = self.scanner.offset2inst_index
ast = python_parser.parse(self.p, tokens, customize, code)
ast = parse(self.p, tokens, customize, code)
self.customize(customize)
self.p.insts = p_insts

except (python_parser.ParserError, AssertionError) as e:
except (ParserError, AssertionError) as e:
raise ParserError(e, tokens)
transform_tree = self.treeTransform.transform(ast, code)
maybe_show_tree(self, ast)
Expand Down Expand Up @@ -1219,9 +1219,9 @@ def build_ast(
self.p.insts = self.scanner.insts
self.p.offset2inst_index = self.scanner.offset2inst_index
self.p.opc = self.scanner.opc
ast = python_parser.parse(self.p, tokens, customize, code)
ast = parse(self.p, tokens, customize, code)
self.p.insts = p_insts
except (python_parser.ParserError, AssertionError) as e:
except (ParserError, AssertionError) as e:
raise ParserError(e, tokens, {})

checker(ast, False, self.ast_errors)
Expand Down Expand Up @@ -2116,7 +2116,7 @@ def code_deparse(
debug_parser["errorstack"] = True

# Build Syntax Tree from tokenized and massaged disassembly.
# deparsed = pysource.FragmentsWalker(out, scanner, showast=showast)
# deparsed = FragmentsWalker(out, scanner, showast=showast)
show_tree = debug_opts.get("tree", False)
linestarts = dict(scanner.opc.findlinestarts(co))
deparsed = walker(
Expand All @@ -2142,7 +2142,7 @@ def code_deparse(
# convert leading '__doc__ = "..." into doc string
assert deparsed.ast == "stmts"

(deparsed.mod_globs, _) = pysource.find_globals_and_nonlocals(
(deparsed.mod_globs, _) = find_globals_and_nonlocals(
deparsed.ast, set(), set(), co, version
)

Expand Down
Loading