amol- / linetable Goto Github PK
View Code? Open in Web Editor NEWLibrary to parse and generate co_linetable attributes in Python code objects
License: MIT License
Library to parse and generate co_linetable attributes in Python code objects
License: MIT License
Because this package is needed for kajiki, I need to build a Fedora package. Please make a release to make this easier. Thank you.
I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.
python3 -sBm build -w --no-isolation
build
with --no-isolation
I'm using during all processes only locally installed modulesHere is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/linetable-0.0.2
plugins: xdist-3.0.2
collected 6 items
tests/test_linetable.py ..FFFF [100%]
================================================================================= FAILURES =================================================================================
______________________________________________________________________________ test_linetable ______________________________________________________________________________
def test_linetable():
pairs = [
# length, start_line, end_line, start_col, end_col
(1, 1, 1, 0, 0),
(1, 2, 2, 6, 7),
(1, 2, 2, 2, 3),
(1, 3, 3, 6, 7),
(1, 3, 3, 10, 11),
(2, 3, 3, 6, 11),
(1, 3, 3, 2, 3),
(1, 4, 4, 9, 10),
(1, 4, 4, 2, 10),
]
expected = b"\x80\x00\xd8\x06\x07\x80!\xd8\x06\x07\x88!\x81e\x80!\xd8\t\n\x80("
> assert generate_linetable(pairs, use_bytecode_offset=False) == expected
tests/test_linetable.py:52:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib/python3.8/site-packages/linetable/linetable.py:5: in generate_linetable
return b"".join(_generate_linetable(pairs, firstlineno, use_bytecode_offset))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pairs = <list_iterator object at 0x7f5a3495ce50>, firstlineno = 1, use_bytecode_offset = False
def _generate_linetable(pairs, firstlineno, use_bytecode_offset):
pairs = iter(pairs) # will do nothing if it's already an iterator.
cur_line = firstlineno
cur_entry = next(pairs)
while cur_entry:
try:
next_entry = next(pairs)
except StopIteration:
next_entry = None
length, start_line, *more = cur_entry
if more:
end_line, start_col, end_col = more
else:
end_line, start_col, end_col = start_line, None, None
if use_bytecode_offset:
# We don't have the length,
# but we have the byte code offsets from dis.findlinestarts()
length = _linetable_length(length, next_entry)
if start_line is not None:
line_delta = start_line - cur_line
cur_line = end_line
if start_line is None:
code = 15
yield _new_linetable_entry(code, length).to_bytes(1)
elif start_col is None:
code = 13
yield _new_linetable_entry(code, length).to_bytes(1)
for b in generate_signed_varint(line_delta):
yield b.to_bytes(1)
elif line_delta == 0 and (end_col - start_col) < 15:
# short form, same line as before and near columns.
code = start_col // 8
> yield _new_linetable_entry(code, length).to_bytes(1)
E TypeError: to_bytes() missing required argument 'byteorder' (pos 2)
../../BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib/python3.8/site-packages/linetable/linetable.py:45: TypeError
__________________________________________________________________________ test_linetable_offsets __________________________________________________________________________
def test_linetable_offsets():
pairs = [
# bytecode_offset, start_line, end_line, start_col, end_col
(0, 1, 1, 0, 0),
(2, 2, 2, 6, 7),
(4, 2, 2, 2, 3),
(6, 3, 3, 6, 7),
(8, 3, 3, 10, 11),
(10, 3, 3, 6, 11),
(14, 3, 3, 2, 3),
(16, 4, 4, 9, 10),
(18, 4, 4, 2, 10),
]
expected = b"\x80\x00\xd8\x06\x07\x80!\xd8\x06\x07\x88!\x81e\x80!\xd8\t\n\x80("
> assert generate_linetable(pairs, use_bytecode_offset=True) == expected
tests/test_linetable.py:69:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib/python3.8/site-packages/linetable/linetable.py:5: in generate_linetable
return b"".join(_generate_linetable(pairs, firstlineno, use_bytecode_offset))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pairs = <list_iterator object at 0x7f5a348f5220>, firstlineno = 1, use_bytecode_offset = True
def _generate_linetable(pairs, firstlineno, use_bytecode_offset):
pairs = iter(pairs) # will do nothing if it's already an iterator.
cur_line = firstlineno
cur_entry = next(pairs)
while cur_entry:
try:
next_entry = next(pairs)
except StopIteration:
next_entry = None
length, start_line, *more = cur_entry
if more:
end_line, start_col, end_col = more
else:
end_line, start_col, end_col = start_line, None, None
if use_bytecode_offset:
# We don't have the length,
# but we have the byte code offsets from dis.findlinestarts()
length = _linetable_length(length, next_entry)
if start_line is not None:
line_delta = start_line - cur_line
cur_line = end_line
if start_line is None:
code = 15
yield _new_linetable_entry(code, length).to_bytes(1)
elif start_col is None:
code = 13
yield _new_linetable_entry(code, length).to_bytes(1)
for b in generate_signed_varint(line_delta):
yield b.to_bytes(1)
elif line_delta == 0 and (end_col - start_col) < 15:
# short form, same line as before and near columns.
code = start_col // 8
> yield _new_linetable_entry(code, length).to_bytes(1)
E TypeError: to_bytes() missing required argument 'byteorder' (pos 2)
../../BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib/python3.8/site-packages/linetable/linetable.py:45: TypeError
_______________________________________________________________________ test_linetable_offsets_short _______________________________________________________________________
def test_linetable_offsets_short():
pairs = [
# bytecode_offset, linenum
(0, 1),
(2, 2),
(4, 2),
(6, 3),
(8, 3),
(10, 3),
(14, 3),
(16, 4),
(18, 4),
]
expected = (
b"\xe8\x00\xe8\x02\xe8\x00\xe8\x02\xe8\x00\xe9\x00\xe8\x00\xe8\x02\xe8\x00"
)
> assert generate_linetable(pairs, use_bytecode_offset=True) == expected
tests/test_linetable.py:88:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib/python3.8/site-packages/linetable/linetable.py:5: in generate_linetable
return b"".join(_generate_linetable(pairs, firstlineno, use_bytecode_offset))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pairs = <list_iterator object at 0x7f5a34953f70>, firstlineno = 1, use_bytecode_offset = True
def _generate_linetable(pairs, firstlineno, use_bytecode_offset):
pairs = iter(pairs) # will do nothing if it's already an iterator.
cur_line = firstlineno
cur_entry = next(pairs)
while cur_entry:
try:
next_entry = next(pairs)
except StopIteration:
next_entry = None
length, start_line, *more = cur_entry
if more:
end_line, start_col, end_col = more
else:
end_line, start_col, end_col = start_line, None, None
if use_bytecode_offset:
# We don't have the length,
# but we have the byte code offsets from dis.findlinestarts()
length = _linetable_length(length, next_entry)
if start_line is not None:
line_delta = start_line - cur_line
cur_line = end_line
if start_line is None:
code = 15
yield _new_linetable_entry(code, length).to_bytes(1)
elif start_col is None:
code = 13
> yield _new_linetable_entry(code, length).to_bytes(1)
E TypeError: to_bytes() missing required argument 'byteorder' (pos 2)
../../BUILDROOT/python-linetable-0.0.2-2.fc35.x86_64/usr/lib/python3.8/site-packages/linetable/linetable.py:39: TypeError
______________________________________________________________________________ test_roundtrip ______________________________________________________________________________
def test_roundtrip():
def _test_function():
x = 13
y = x * 2 + 7 + 8 + 9 - 3 - 1 - 5
z = y**2
return z
> co_linetable = _test_function.__code__.co_linetable
E AttributeError: 'code' object has no attribute 'co_linetable'
tests/test_linetable.py:98: AttributeError
========================================================================= short test summary info ==========================================================================
FAILED tests/test_linetable.py::test_linetable - TypeError: to_bytes() missing required argument 'byteorder' (pos 2)
FAILED tests/test_linetable.py::test_linetable_offsets - TypeError: to_bytes() missing required argument 'byteorder' (pos 2)
FAILED tests/test_linetable.py::test_linetable_offsets_short - TypeError: to_bytes() missing required argument 'byteorder' (pos 2)
FAILED tests/test_linetable.py::test_roundtrip - AttributeError: 'code' object has no attribute 'co_linetable'
======================================================================= 4 failed, 2 passed in 0.07s ========================================================================
Here is list of installed modules in build env
Package Version
----------------- --------------
appdirs 1.4.4
attrs 22.1.0
Brlapi 0.8.3
build 0.9.0
contourpy 1.0.6
cssselect 1.1.0
cycler 0.11.0
distro 1.8.0
dnspython 2.2.1
exceptiongroup 1.0.0
execnet 1.9.0
extras 1.0.0
filelock 3.8.0
fixtures 4.0.0
fonttools 4.38.0
gpg 1.17.1-unknown
iniconfig 1.1.1
kiwisolver 1.4.4
libcomps 0.1.19
louis 3.23.0
lxml 4.9.1
matplotlib 3.6.2
mypy 0.990
mypy-extensions 0.4.3
numpy 1.23.1
olefile 0.46
packaging 21.3
pbr 5.9.0
pep517 0.13.0
pexpect 4.8.0
Pillow 9.3.0
pip 22.3.1
pluggy 1.0.0
ptyprocess 0.7.0
PyGObject 3.42.2
pyparsing 3.0.9
pytest 7.2.0
pytest-xdist 3.0.2
python-dateutil 2.8.2
rpm 4.17.0
scour 0.38.2
setuptools 65.6.3
setuptools-scm 7.0.5
six 1.16.0
testtools 2.5.0
tomli 2.0.1
typing_extensions 4.3.0
wheel 0.38.4
See https://github.com/python/cpython/blob/main/Objects/locations.md#location-entries
Having to generate a Long Form entry will currently throw an NotImplementedError
( https://github.com/amol-/linetable/blob/main/linetable/linetable.py#L34-L54 )
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.