Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bytecode to 0.13.0 and simplify patch #225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 3 additions & 1 deletion _pydevd_frame_eval/pydevd_modify_bytecode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import namedtuple
import contextlib
import dis
from functools import partial
import itertools
Expand Down Expand Up @@ -36,7 +37,8 @@ def _get_filename(self, op_number=None, prefix=''):
def write_bytecode(self, b, op_number=None, prefix=''):
filename, op_number = self._get_filename(op_number, prefix)
with open(filename, 'w') as stream:
bytecode.dump_bytecode(b, stream=stream, lineno=True)
with contextlib.redirect_stdout(stream):
bytecode.dump_bytecode(b, lineno=True)
return op_number

def write_dis(self, code_to_modify, op_number=None, prefix=''):
Expand Down
6 changes: 4 additions & 2 deletions _pydevd_frame_eval/vendored/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ python -m pip install https://github.com/MatthieuDartiailh/bytecode/archive/main
Then run 'pydevd_fix_code.py' to fix the imports on the vendored file, run its tests (to see
if things are still ok) and commit.

Then, to finish, apply the patch to add the offset to the instructions (bcb8a28669e9178f96f5d71af7259e0674acc47c)
Then, to finish, apply the patch to add the offset to the instructions
found in the file pydevd_offset_patch.diff; this applies to version
0.13.0 of the 'bytecode' library.

Note: commit the egg-info as a note of the license (force if needed).
Note: commit the egg-info as a note of the license (force if needed).
21 changes: 0 additions & 21 deletions _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/COPYING

This file was deleted.

This file was deleted.

This file was deleted.

42 changes: 0 additions & 42 deletions _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/RECORD

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

76 changes: 76 additions & 0 deletions _pydevd_frame_eval/vendored/bytecode.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Metadata-Version: 1.2
Name: bytecode
Version: 0.13.0
Summary: Python module to generate and modify bytecode
Home-page: https://github.com/MatthieuDartiailh/bytecode
Author: Victor Stinner
Author-email: [email protected]
Maintainer: Matthieu C. Dartiailh
Maintainer-email: [email protected]
License: MIT license
Description: ********
bytecode
********

.. image:: https://img.shields.io/pypi/v/bytecode.svg
:alt: Latest release on the Python Cheeseshop (PyPI)
:target: https://pypi.python.org/pypi/bytecode

.. image:: https://github.com/MatthieuDartiailh/bytecode/workflows/Continuous%20Integration/badge.svg
:target: https://github.com/MatthieuDartiailh/bytecode/actions
:alt: Continuous integration

.. image:: https://github.com/MatthieuDartiailh/bytecode/workflows/Documentation%20building/badge.svg
:target: https://github.com/MatthieuDartiailh/bytecode/actions
:alt: Documentation building

.. image:: https://img.shields.io/codecov/c/github/MatthieuDartiailh/bytecode/master.svg
:alt: Code coverage of bytecode on codecov.io
:target: https://codecov.io/github/MatthieuDartiailh/bytecode

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:alt: Code formatted using Black
:target: https://github.com/psf/black

``bytecode`` is a Python module to generate and modify bytecode.

* `bytecode project homepage at GitHub
<https://github.com/MatthieuDartiailh/bytecode>`_ (code, bugs)
* `bytecode documentation
<https://bytecode.readthedocs.io/>`_
* `Download latest bytecode release at the Python Cheeseshop (PyPI)
<https://pypi.python.org/pypi/bytecode>`_

Install bytecode: ``python3 -m pip install bytecode``. It requires Python 3.6
or newer. The latest release that supports Python 3.5 is 0.12.0. For Python 2.7
support, have a look at `dead-bytecode
<https://github.com/p403n1x87/dead-bytecode>`_ instead.

Example executing ``print('Hello World!')``:

.. code:: python

from bytecode import Instr, Bytecode

bytecode = Bytecode([Instr("LOAD_NAME", 'print'),
Instr("LOAD_CONST", 'Hello World!'),
Instr("CALL_FUNCTION", 1),
Instr("POP_TOP"),
Instr("LOAD_CONST", None),
Instr("RETURN_VALUE")])
code = bytecode.to_code()
exec(code)
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.6
38 changes: 38 additions & 0 deletions _pydevd_frame_eval/vendored/bytecode.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
COPYING
MANIFEST.in
README.rst
setup.py
tox.ini
bytecode/__init__.py
bytecode/bytecode.py
bytecode/cfg.py
bytecode/concrete.py
bytecode/flags.py
bytecode/instr.py
bytecode/peephole_opt.py
bytecode.egg-info/PKG-INFO
bytecode.egg-info/SOURCES.txt
bytecode.egg-info/dependency_links.txt
bytecode.egg-info/top_level.txt
bytecode/tests/__init__.py
bytecode/tests/long_lines_example.py
bytecode/tests/test_bytecode.py
bytecode/tests/test_cfg.py
bytecode/tests/test_code.py
bytecode/tests/test_concrete.py
bytecode/tests/test_flags.py
bytecode/tests/test_instr.py
bytecode/tests/test_misc.py
bytecode/tests/test_peephole_opt.py
bytecode/tests/util_annotation.py
doc/Makefile
doc/api.rst
doc/byteplay_codetransformer.rst
doc/cfg.rst
doc/changelog.rst
doc/conf.py
doc/index.rst
doc/make.bat
doc/peephole.rst
doc/todo.rst
doc/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

22 changes: 11 additions & 11 deletions _pydevd_frame_eval/vendored/bytecode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.13.0.dev"
__version__ = "0.13.0"

__all__ = [
"Label",
Expand Down Expand Up @@ -35,9 +35,9 @@
_ConvertBytecodeToConcrete,
)
from _pydevd_frame_eval.vendored.bytecode.cfg import BasicBlock, ControlFlowGraph # noqa
import sys

def dump_bytecode(bytecode, *, lineno=False, stream=sys.stdout):

def dump_bytecode(bytecode, *, lineno=False):
def format_line(index, line):
nonlocal cur_lineno, prev_lineno
if lineno:
Expand Down Expand Up @@ -87,7 +87,7 @@ def format_instr(instr, labels=None):
else:
fields.append("% 3s %s" % (offset, format_instr(instr)))
line = "".join(fields)
print(line, file=stream)
print(line)

offset += instr.size
elif isinstance(bytecode, Bytecode):
Expand All @@ -101,30 +101,30 @@ def format_instr(instr, labels=None):
label = labels[instr]
line = "%s:" % label
if index != 0:
print(file=stream)
print()
else:
if instr.lineno is not None:
cur_lineno = instr.lineno
line = format_instr(instr, labels)
line = indent + format_line(index, line)
print(line, file=stream)
print(file=stream)
print(line)
print()
elif isinstance(bytecode, ControlFlowGraph):
labels = {}
for block_index, block in enumerate(bytecode, 1):
labels[id(block)] = "block%s" % block_index

for block_index, block in enumerate(bytecode, 1):
print("%s:" % labels[id(block)], file=stream)
print("%s:" % labels[id(block)])
prev_lineno = None
for index, instr in enumerate(block):
if instr.lineno is not None:
cur_lineno = instr.lineno
line = format_instr(instr, labels)
line = indent + format_line(index, line)
print(line, file=stream)
print(line)
if block.next_block is not None:
print(indent + "-> %s" % labels[id(block.next_block)], file=stream)
print(file=stream)
print(indent + "-> %s" % labels[id(block.next_block)])
print()
else:
raise TypeError("unknown bytecode class")
Loading