Update code for current linter
This commit is contained in:
parent
53e3209cd5
commit
56df6c40f6
@ -366,7 +366,7 @@ class Reader:
|
|||||||
def open(self) -> None:
|
def open(self) -> None:
|
||||||
"""Open rosbag and read metadata."""
|
"""Open rosbag and read metadata."""
|
||||||
try:
|
try:
|
||||||
self.bio = self.path.open('rb')
|
self.bio = self.path.open('rb') # pylint: disable=consider-using-with
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
raise ReaderError(f'Could not open file {str(self.path)!r}: {err.strerror}.') from err
|
raise ReaderError(f'Could not open file {str(self.path)!r}: {err.strerror}.') from err
|
||||||
|
|
||||||
|
|||||||
@ -192,7 +192,7 @@ class Writer:
|
|||||||
def open(self) -> None:
|
def open(self) -> None:
|
||||||
"""Open rosbag1 for writing."""
|
"""Open rosbag1 for writing."""
|
||||||
try:
|
try:
|
||||||
self.bio = self.path.open('xb')
|
self.bio = self.path.open('xb') # pylint: disable=consider-using-with
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
raise WriterError(f'{self.path} exists already, not overwriting.') from None
|
raise WriterError(f'{self.path} exists already, not overwriting.') from None
|
||||||
|
|
||||||
|
|||||||
@ -138,7 +138,7 @@ class Reader:
|
|||||||
self.files: list[FileInformation] = self.metadata.get('files', [])[:]
|
self.files: list[FileInformation] = self.metadata.get('files', [])[:]
|
||||||
self.custom_data: dict[str, str] = self.metadata.get('custom_data', {})
|
self.custom_data: dict[str, str] = self.metadata.get('custom_data', {})
|
||||||
|
|
||||||
self.tmpdir: Optional[TemporaryDirectory] = None
|
self.tmpdir: Optional[TemporaryDirectory[str]] = None
|
||||||
self.storage: Optional[StorageProtocol] = None
|
self.storage: Optional[StorageProtocol] = None
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
raise ReaderError(f'A metadata key is missing {exc!r}.') from None
|
raise ReaderError(f'A metadata key is missing {exc!r}.') from None
|
||||||
|
|||||||
@ -38,7 +38,7 @@ def generate_getsize_cdr(fields: list[Field]) -> tuple[CDRSerSize, int]:
|
|||||||
|
|
||||||
aligned = 8
|
aligned = 8
|
||||||
iterators = tee([*fields, None])
|
iterators = tee([*fields, None])
|
||||||
icurr = cast(Iterator[Field], iterators[0])
|
icurr = cast('Iterator[Field]', iterators[0])
|
||||||
inext = iterators[1]
|
inext = iterators[1]
|
||||||
next(inext)
|
next(inext)
|
||||||
lines = [
|
lines = [
|
||||||
@ -178,7 +178,7 @@ def generate_serialize_cdr(fields: list[Field], endianess: str) -> CDRSer:
|
|||||||
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
|
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
|
||||||
aligned = 8
|
aligned = 8
|
||||||
iterators = tee([*fields, None])
|
iterators = tee([*fields, None])
|
||||||
icurr = cast(Iterator[Field], iterators[0])
|
icurr = cast('Iterator[Field]', iterators[0])
|
||||||
inext = iterators[1]
|
inext = iterators[1]
|
||||||
next(inext)
|
next(inext)
|
||||||
lines = [
|
lines = [
|
||||||
@ -317,7 +317,7 @@ def generate_deserialize_cdr(fields: list[Field], endianess: str) -> CDRDeser:
|
|||||||
# pylint: disable=too-many-branches,too-many-locals,too-many-nested-blocks,too-many-statements
|
# pylint: disable=too-many-branches,too-many-locals,too-many-nested-blocks,too-many-statements
|
||||||
aligned = 8
|
aligned = 8
|
||||||
iterators = tee([*fields, None])
|
iterators = tee([*fields, None])
|
||||||
icurr = cast(Iterator[Field], iterators[0])
|
icurr = cast('Iterator[Field]', iterators[0])
|
||||||
inext = iterators[1]
|
inext = iterators[1]
|
||||||
next(inext)
|
next(inext)
|
||||||
lines = [
|
lines = [
|
||||||
|
|||||||
@ -43,7 +43,7 @@ def generate_ros1_to_cdr(
|
|||||||
# pylint: disable=too-many-branches,too-many-locals,too-many-nested-blocks,too-many-statements
|
# pylint: disable=too-many-branches,too-many-locals,too-many-nested-blocks,too-many-statements
|
||||||
aligned = 8
|
aligned = 8
|
||||||
iterators = tee([*fields, None])
|
iterators = tee([*fields, None])
|
||||||
icurr = cast(Iterator[Field], iterators[0])
|
icurr = cast('Iterator[Field]', iterators[0])
|
||||||
inext = iterators[1]
|
inext = iterators[1]
|
||||||
next(inext)
|
next(inext)
|
||||||
funcname = 'ros1_to_cdr' if copy else 'getsize_ros1_to_cdr'
|
funcname = 'ros1_to_cdr' if copy else 'getsize_ros1_to_cdr'
|
||||||
@ -199,7 +199,7 @@ def generate_cdr_to_ros1(
|
|||||||
# pylint: disable=too-many-branches,too-many-locals,too-many-nested-blocks,too-many-statements
|
# pylint: disable=too-many-branches,too-many-locals,too-many-nested-blocks,too-many-statements
|
||||||
aligned = 8
|
aligned = 8
|
||||||
iterators = tee([*fields, None])
|
iterators = tee([*fields, None])
|
||||||
icurr = cast(Iterator[Field], iterators[0])
|
icurr = cast('Iterator[Field]', iterators[0])
|
||||||
inext = iterators[1]
|
inext = iterators[1]
|
||||||
next(inext)
|
next(inext)
|
||||||
funcname = 'cdr_to_ros1' if copy else 'getsize_cdr_to_ros1'
|
funcname = 'cdr_to_ros1' if copy else 'getsize_cdr_to_ros1'
|
||||||
|
|||||||
@ -46,7 +46,7 @@ def get_typehint(desc: tuple[int, Union[str, tuple[tuple[int, str], Optional[int
|
|||||||
|
|
||||||
sub = desc[1][0]
|
sub = desc[1][0]
|
||||||
if INTLIKE.match(sub[1]):
|
if INTLIKE.match(sub[1]):
|
||||||
typ = 'bool8' if sub[1] == 'bool' else sub[1]
|
typ = 'bool_' if sub[1] == 'bool' else sub[1]
|
||||||
return f'numpy.ndarray[Any, numpy.dtype[numpy.{typ}]]'
|
return f'numpy.ndarray[Any, numpy.dtype[numpy.{typ}]]'
|
||||||
assert isinstance(sub, tuple)
|
assert isinstance(sub, tuple)
|
||||||
return f'list[{get_typehint(sub)}]'
|
return f'list[{get_typehint(sub)}]'
|
||||||
@ -71,7 +71,6 @@ def generate_python_code(typs: Typesdict) -> str:
|
|||||||
'',
|
'',
|
||||||
'# flake8: noqa N801',
|
'# flake8: noqa N801',
|
||||||
'# pylint: disable=invalid-name,too-many-instance-attributes,too-many-lines',
|
'# pylint: disable=invalid-name,too-many-instance-attributes,too-many-lines',
|
||||||
'# pylint: disable=unsubscriptable-object',
|
|
||||||
'',
|
'',
|
||||||
'from __future__ import annotations',
|
'from __future__ import annotations',
|
||||||
'',
|
'',
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
# flake8: noqa N801
|
# flake8: noqa N801
|
||||||
# pylint: disable=invalid-name,too-many-instance-attributes,too-many-lines
|
# pylint: disable=invalid-name,too-many-instance-attributes,too-many-lines
|
||||||
# pylint: disable=unsubscriptable-object
|
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@ -608,7 +607,7 @@ class rcl_interfaces__msg__ParameterValue:
|
|||||||
double_value: float
|
double_value: float
|
||||||
string_value: str
|
string_value: str
|
||||||
byte_array_value: numpy.ndarray[Any, numpy.dtype[numpy.uint8]]
|
byte_array_value: numpy.ndarray[Any, numpy.dtype[numpy.uint8]]
|
||||||
bool_array_value: numpy.ndarray[Any, numpy.dtype[numpy.bool8]]
|
bool_array_value: numpy.ndarray[Any, numpy.dtype[numpy.bool_]]
|
||||||
integer_array_value: numpy.ndarray[Any, numpy.dtype[numpy.int64]]
|
integer_array_value: numpy.ndarray[Any, numpy.dtype[numpy.int64]]
|
||||||
double_array_value: numpy.ndarray[Any, numpy.dtype[numpy.float64]]
|
double_array_value: numpy.ndarray[Any, numpy.dtype[numpy.float64]]
|
||||||
string_array_value: list[str]
|
string_array_value: list[str]
|
||||||
|
|||||||
@ -274,13 +274,13 @@ def serialize_array(
|
|||||||
if desc.valtype == Valtype.BASE:
|
if desc.valtype == Valtype.BASE:
|
||||||
if desc.args == 'string':
|
if desc.args == 'string':
|
||||||
for item in val:
|
for item in val:
|
||||||
pos = serialize_string(rawdata, bmap, pos, cast(str, item))
|
pos = serialize_string(rawdata, bmap, pos, cast('str', item))
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
size = SIZEMAP[desc.args]
|
size = SIZEMAP[desc.args]
|
||||||
pos = (pos + size - 1) & -size
|
pos = (pos + size - 1) & -size
|
||||||
size *= len(val)
|
size *= len(val)
|
||||||
val = cast(NDArray[numpy.int_], val)
|
val = cast('NDArray[numpy.int_]', val)
|
||||||
if (bmap is BASETYPEMAP_LE) != (sys.byteorder == 'little'):
|
if (bmap is BASETYPEMAP_LE) != (sys.byteorder == 'little'):
|
||||||
val = val.byteswap() # no inplace on readonly array
|
val = val.byteswap() # no inplace on readonly array
|
||||||
rawdata[pos:pos + size] = memoryview(val.tobytes())
|
rawdata[pos:pos + size] = memoryview(val.tobytes())
|
||||||
|
|||||||
@ -87,7 +87,7 @@ def test_anyreader1(bags1: Sequence[Path]) -> None: # pylint: disable=redefined
|
|||||||
reader = AnyReader(bags1)
|
reader = AnyReader(bags1)
|
||||||
with pytest.raises(AnyReaderError, match='seems to be empty'):
|
with pytest.raises(AnyReaderError, match='seems to be empty'):
|
||||||
reader.open()
|
reader.open()
|
||||||
assert all(not x.bio for x in reader.readers)
|
assert all(not x.bio for x in reader.readers) # type: ignore[union-attr]
|
||||||
|
|
||||||
with AnyReader(bags1[:3]) as reader:
|
with AnyReader(bags1[:3]) as reader:
|
||||||
assert reader.duration == 15
|
assert reader.duration == 15
|
||||||
|
|||||||
@ -69,8 +69,7 @@ def create_message(
|
|||||||
}, f'MSGCONTENT{msg}'.encode()
|
}, f'MSGCONTENT{msg}'.encode()
|
||||||
|
|
||||||
|
|
||||||
def write_bag( # pylint: disable=too-many-locals,too-many-statements
|
def write_bag( # pylint: disable=too-many-locals
|
||||||
|
|
||||||
bag: Path,
|
bag: Path,
|
||||||
header: dict[str, bytes],
|
header: dict[str, bytes],
|
||||||
chunks: Sequence[Any] = (),
|
chunks: Sequence[Any] = (),
|
||||||
@ -129,8 +128,8 @@ def write_bag( # pylint: disable=too-many-locals,too-many-statements
|
|||||||
{
|
{
|
||||||
'op': b'\x05',
|
'op': b'\x05',
|
||||||
'compression': b'none',
|
'compression': b'none',
|
||||||
'size': pack('<L', len(chunk_bytes))
|
'size': pack('<L', len(chunk_bytes)),
|
||||||
}
|
},
|
||||||
) + ser(chunk_bytes)
|
) + ser(chunk_bytes)
|
||||||
for conn, data in index.items():
|
for conn, data in index.items():
|
||||||
chunk_bytes += ser(
|
chunk_bytes += ser(
|
||||||
@ -139,7 +138,7 @@ def write_bag( # pylint: disable=too-many-locals,too-many-statements
|
|||||||
'ver': pack('<L', 1),
|
'ver': pack('<L', 1),
|
||||||
'conn': pack('<L', conn),
|
'conn': pack('<L', conn),
|
||||||
'count': pack('<L', data['count']),
|
'count': pack('<L', data['count']),
|
||||||
}
|
},
|
||||||
) + ser(data['msgs'])
|
) + ser(data['msgs'])
|
||||||
|
|
||||||
chunks_bytes += chunk_bytes
|
chunks_bytes += chunk_bytes
|
||||||
@ -151,7 +150,7 @@ def write_bag( # pylint: disable=too-many-locals,too-many-statements
|
|||||||
'start_time': pack('<LL', start_time, 0),
|
'start_time': pack('<LL', start_time, 0),
|
||||||
'end_time': pack('<LL', end_time, 0),
|
'end_time': pack('<LL', end_time, 0),
|
||||||
'count': pack('<L', len(counts.keys())),
|
'count': pack('<L', len(counts.keys())),
|
||||||
}
|
},
|
||||||
) + ser(b''.join([pack('<LL', x, y) for x, y in counts.items()]))
|
) + ser(b''.join([pack('<LL', x, y) for x, y in counts.items()]))
|
||||||
pos += len(chunk_bytes)
|
pos += len(chunk_bytes)
|
||||||
|
|
||||||
@ -178,18 +177,16 @@ def test_indexdata() -> None:
|
|||||||
x42_2_0 = IndexData(42, 2, 0)
|
x42_2_0 = IndexData(42, 2, 0)
|
||||||
x43_3_0 = IndexData(43, 3, 0)
|
x43_3_0 = IndexData(43, 3, 0)
|
||||||
|
|
||||||
# flake8: noqa
|
|
||||||
# pylint: disable=unneeded-not
|
|
||||||
assert not x42_1_0 < x42_2_0
|
assert not x42_1_0 < x42_2_0
|
||||||
assert x42_1_0 <= x42_2_0
|
assert x42_1_0 <= x42_2_0
|
||||||
assert x42_1_0 == x42_2_0
|
assert x42_1_0 == x42_2_0
|
||||||
assert not x42_1_0 != x42_2_0
|
assert not x42_1_0 != x42_2_0 # noqa
|
||||||
assert x42_1_0 >= x42_2_0
|
assert x42_1_0 >= x42_2_0
|
||||||
assert not x42_1_0 > x42_2_0
|
assert not x42_1_0 > x42_2_0
|
||||||
|
|
||||||
assert x42_1_0 < x43_3_0
|
assert x42_1_0 < x43_3_0
|
||||||
assert x42_1_0 <= x43_3_0
|
assert x42_1_0 <= x43_3_0
|
||||||
assert not x42_1_0 == x43_3_0
|
assert not x42_1_0 == x43_3_0 # noqa
|
||||||
assert x42_1_0 != x43_3_0
|
assert x42_1_0 != x43_3_0
|
||||||
assert not x42_1_0 >= x43_3_0
|
assert not x42_1_0 >= x43_3_0
|
||||||
assert not x42_1_0 > x43_3_0
|
assert not x42_1_0 > x43_3_0
|
||||||
@ -215,10 +212,12 @@ def test_reader(tmp_path: Path) -> None: # pylint: disable=too-many-statements
|
|||||||
|
|
||||||
# single message
|
# single message
|
||||||
write_bag(
|
write_bag(
|
||||||
bag, create_default_header(), chunks=[[
|
bag,
|
||||||
|
create_default_header(),
|
||||||
|
chunks=[[
|
||||||
create_connection(),
|
create_connection(),
|
||||||
create_message(time=42),
|
create_message(time=42),
|
||||||
]]
|
]],
|
||||||
)
|
)
|
||||||
with Reader(bag) as reader:
|
with Reader(bag) as reader:
|
||||||
assert reader.message_count == 1
|
assert reader.message_count == 1
|
||||||
@ -239,8 +238,8 @@ def test_reader(tmp_path: Path) -> None: # pylint: disable=too-many-statements
|
|||||||
create_connection(),
|
create_connection(),
|
||||||
create_message(time=10, msg=10),
|
create_message(time=10, msg=10),
|
||||||
create_message(time=5, msg=5),
|
create_message(time=5, msg=5),
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
with Reader(bag) as reader:
|
with Reader(bag) as reader:
|
||||||
assert reader.message_count == 2
|
assert reader.message_count == 2
|
||||||
@ -266,8 +265,8 @@ def test_reader(tmp_path: Path) -> None: # pylint: disable=too-many-statements
|
|||||||
create_message(time=10, msg=10),
|
create_message(time=10, msg=10),
|
||||||
create_connection(cid=2, topic=2),
|
create_connection(cid=2, topic=2),
|
||||||
create_message(cid=2, time=5, msg=5),
|
create_message(cid=2, time=5, msg=5),
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
with Reader(bag) as reader:
|
with Reader(bag) as reader:
|
||||||
assert len(reader.topics.keys()) == 2
|
assert len(reader.topics.keys()) == 2
|
||||||
@ -398,11 +397,13 @@ def test_failure_cases(tmp_path: Path) -> None: # pylint: disable=too-many-stat
|
|||||||
|
|
||||||
# bad uint8 field
|
# bad uint8 field
|
||||||
write_bag(
|
write_bag(
|
||||||
bag, create_default_header(), chunks=[[
|
bag,
|
||||||
|
create_default_header(),
|
||||||
|
chunks=[[
|
||||||
({}, {}),
|
({}, {}),
|
||||||
create_connection(),
|
create_connection(),
|
||||||
create_message(),
|
create_message(),
|
||||||
]]
|
]],
|
||||||
)
|
)
|
||||||
with Reader(bag) as reader, \
|
with Reader(bag) as reader, \
|
||||||
pytest.raises(ReaderError, match='field \'op\''):
|
pytest.raises(ReaderError, match='field \'op\''):
|
||||||
|
|||||||
@ -17,7 +17,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
def test_writer(tmp_path: Path) -> None:
|
def test_writer(tmp_path: Path) -> None:
|
||||||
"""Test Writer."""
|
"""Test Writer."""
|
||||||
path = (tmp_path / 'rosbag2')
|
path = tmp_path / 'rosbag2'
|
||||||
with Writer(path) as bag:
|
with Writer(path) as bag:
|
||||||
connection = bag.add_connection('/test', 'std_msgs/msg/Int8')
|
connection = bag.add_connection('/test', 'std_msgs/msg/Int8')
|
||||||
bag.write(connection, 42, b'\x00')
|
bag.write(connection, 42, b'\x00')
|
||||||
@ -26,7 +26,7 @@ def test_writer(tmp_path: Path) -> None:
|
|||||||
assert (path / 'rosbag2.db3').exists()
|
assert (path / 'rosbag2.db3').exists()
|
||||||
size = (path / 'rosbag2.db3').stat().st_size
|
size = (path / 'rosbag2.db3').stat().st_size
|
||||||
|
|
||||||
path = (tmp_path / 'compress_none')
|
path = tmp_path / 'compress_none'
|
||||||
bag = Writer(path)
|
bag = Writer(path)
|
||||||
bag.set_compression(bag.CompressionMode.NONE, bag.CompressionFormat.ZSTD)
|
bag.set_compression(bag.CompressionMode.NONE, bag.CompressionFormat.ZSTD)
|
||||||
with bag:
|
with bag:
|
||||||
@ -37,7 +37,7 @@ def test_writer(tmp_path: Path) -> None:
|
|||||||
assert (path / 'compress_none.db3').exists()
|
assert (path / 'compress_none.db3').exists()
|
||||||
assert size == (path / 'compress_none.db3').stat().st_size
|
assert size == (path / 'compress_none.db3').stat().st_size
|
||||||
|
|
||||||
path = (tmp_path / 'compress_file')
|
path = tmp_path / 'compress_file'
|
||||||
bag = Writer(path)
|
bag = Writer(path)
|
||||||
bag.set_compression(bag.CompressionMode.FILE, bag.CompressionFormat.ZSTD)
|
bag.set_compression(bag.CompressionMode.FILE, bag.CompressionFormat.ZSTD)
|
||||||
with bag:
|
with bag:
|
||||||
@ -48,7 +48,7 @@ def test_writer(tmp_path: Path) -> None:
|
|||||||
assert not (path / 'compress_file.db3').exists()
|
assert not (path / 'compress_file.db3').exists()
|
||||||
assert (path / 'compress_file.db3.zstd').exists()
|
assert (path / 'compress_file.db3.zstd').exists()
|
||||||
|
|
||||||
path = (tmp_path / 'compress_message')
|
path = tmp_path / 'compress_message'
|
||||||
bag = Writer(path)
|
bag = Writer(path)
|
||||||
bag.set_compression(bag.CompressionMode.MESSAGE, bag.CompressionFormat.ZSTD)
|
bag.set_compression(bag.CompressionMode.MESSAGE, bag.CompressionFormat.ZSTD)
|
||||||
with bag:
|
with bag:
|
||||||
@ -59,7 +59,7 @@ def test_writer(tmp_path: Path) -> None:
|
|||||||
assert (path / 'compress_message.db3').exists()
|
assert (path / 'compress_message.db3').exists()
|
||||||
assert size > (path / 'compress_message.db3').stat().st_size
|
assert size > (path / 'compress_message.db3').stat().st_size
|
||||||
|
|
||||||
path = (tmp_path / 'with_custom_data')
|
path = tmp_path / 'with_custom_data'
|
||||||
bag = Writer(path)
|
bag = Writer(path)
|
||||||
bag.open()
|
bag.open()
|
||||||
bag.set_custom_data('key1', 'value1')
|
bag.set_custom_data('key1', 'value1')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user