Skip to content

Commit

Permalink
chore: Stricter linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkbac committed Nov 7, 2023
1 parent 16d16da commit 74f2b44
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.2"
rev: "v0.1.3"
hooks:
- id: ruff
args: ["--fix"]
Expand Down
29 changes: 2 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,13 @@ build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = [
"autopep8>=2.0.2",
]

[tool.hatch.version]
path = "src/kappe/__init__.py"

[tool.hatch.metadata]
allow-direct-references = true

[tool.autopep8]
aggressive = 3
recursive = true
max_line_length = 100

[tool.ruff]
line-length = 100
exclude = ['msgs']
Expand All @@ -66,25 +58,15 @@ ignore = [
'D', # pydocstyle
'EM101', # raw-string-in-exception
'EM102', # f-string-in-exception
'FIX002', # TODO
'PLR2004', # MagicValueComparisons
'S101', # AssertUsed
'TCH', # flake8-type-checking
'TCH', # flake8-type-checking
'TD', # TODO
'TRY003', # raise-vanilla-args
'TD',
'FIX002',


# formater
'W191', # tab-indentation
'Q000', # bad-quotes-inline-string
'Q001', # bad-quotes-multiline-string
'Q002', # bad-quotes-docstring
'Q003', # avoidable-escaped-quote
'COM812', # missing-trailing-comma
'COM819', # prohibited-trailing-comma
'ISC001', # single-line-implicit-string-concatenation
'E501', # line-too-long
]

src = ['src']
Expand All @@ -94,12 +76,5 @@ target-version = 'py310'
[tool.ruff.flake8-quotes]
inline-quotes = 'single'

[tool.ruff.flake8-annotations]
mypy-init-return = true
suppress-none-returning = true

[tool.ruff.pep8-naming]
classmethod-decorators = ["pydantic.validator"]

[tool.ruff.format]
quote-style = "single"
12 changes: 3 additions & 9 deletions src/kappe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class TqdmLoggingHandler(logging.Handler):
def emit(self, record: Any):
def emit(self, record: Any) -> None:
try:
msg = self.format(record)
tqdm.write(msg)
Expand All @@ -36,7 +36,7 @@ def emit(self, record: Any):
logger = logging.getLogger(__name__)


def convert_worker(arg: tuple[Path, Path, Settings, int]):
def convert_worker(arg: tuple[Path, Path, Settings, int]) -> None:
# TODO: dataclass
input_path, output_path, config, tqdm_idx = arg

Expand Down Expand Up @@ -243,15 +243,9 @@ def cut( # noqa: PLR0913

cutter(mcap, output, config)

def version(self) -> None:
"""
Print version.
"""
logger.info('kappe %s', __version__)


def main() -> None:
CLI(KappeCLI)
CLI(KappeCLI, version=__version__)


if __name__ == '__main__':
Expand Down
21 changes: 13 additions & 8 deletions src/kappe/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from collections.abc import Iterable, Iterator
from datetime import datetime, timezone
from pathlib import Path
from typing import TYPE_CHECKING

import strictyaml
from mcap.reader import DecodedMessageTuple, make_reader
from mcap.records import Schema, Statistics
from mcap.summary import Summary
from mcap.well_known import Profile, SchemaEncoding
from mcap_ros1.decoder import DecoderFactory as Ros1DecoderFactory
from mcap_ros2.decoder import DecoderFactory as Ros2DecoderFactory
Expand All @@ -23,6 +22,10 @@
from kappe.settings import Settings
from kappe.utils.msg_def import get_message_definition

if TYPE_CHECKING:
from mcap.records import Schema, Statistics
from mcap.summary import Summary

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -51,7 +54,9 @@ def generate_qos(config: dict) -> str:


class Converter:
def __init__(self, config: Settings, input_path: Path, output_path: Path, raw_config: str = ''):
def __init__(
self, config: Settings, input_path: Path, output_path: Path, raw_config: str = ''
) -> None:
self.config = config
self.input_path = input_path
self.output_path = output_path
Expand Down Expand Up @@ -103,7 +108,7 @@ def __init__(self, config: Settings, input_path: Path, output_path: Path, raw_co

self.init_channel()

def init_schema(self):
def init_schema(self) -> None:
for schema in self.summary.schemas.values():
if schema.encoding not in [SchemaEncoding.ROS1, SchemaEncoding.ROS2]:
logger.warning(
Expand Down Expand Up @@ -159,7 +164,7 @@ def init_schema(self):
TF_SCHEMA_TEXT,
)

def init_channel(self):
def init_channel(self) -> None:
for channel in self.summary.channels.values():
metadata = channel.metadata
topic = channel.topic
Expand Down Expand Up @@ -272,7 +277,7 @@ def read_ros_messaged(
end_time=int(end_time * 1e9) if end_time else None,
)

def process_message(self, msg: DecodedMessageTuple):
def process_message(self, msg: DecodedMessageTuple) -> None:
schema, channel, message, ros_msg = msg
schema_name = schema.name
topic = channel.topic
Expand Down Expand Up @@ -337,7 +342,7 @@ def process_message(self, msg: DecodedMessageTuple):
sequence=message.sequence,
)

def process_file(self, tqdm_idx: int = 0):
def process_file(self, tqdm_idx: int = 0) -> None:
start_time = self.statistics.message_start_time / 1e9
if self.config.time_start is not None:
start_time = max(start_time, self.config.time_start)
Expand Down Expand Up @@ -440,7 +445,7 @@ def process_file(self, tqdm_idx: int = 0):
pbar.update((message.log_time / 1e9 - start_time) - pbar.n)
self.process_message(msg)

def finish(self):
def finish(self) -> None:
# save used convert config
self.writer._writer.add_attachment( # noqa: SLF001
create_time=time.time_ns(),
Expand Down
2 changes: 1 addition & 1 deletion src/kappe/cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, path: str, profile: str) -> None:
self._writer = Writer(path)
self._writer.start(profile=profile)

def set_static_tf(self, schema: Schema, channel: Channel, data: list[bytes]):
def set_static_tf(self, schema: Schema, channel: Channel, data: list[bytes]) -> None:
self.static_tf_set = True
self.static_tf_channel_id = self.register_channel(schema, channel)
self.static_tf = data
Expand Down
2 changes: 1 addition & 1 deletion src/kappe/module/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SettingPointCloud(BaseModel):
field_mapping: dict[str, str] | None = None


def point_cloud(cfg: SettingPointCloud, msg: DecodedMessageTuple):
def point_cloud(cfg: SettingPointCloud, msg: DecodedMessageTuple) -> None:
ros_msg = msg.decoded_message

if cfg.field_mapping is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/kappe/module/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def tf_static_insert(cfg: SettingTF, stamp_ns: int) -> None | Any:
return {'transforms': transforms}


def tf_remove(cfg: SettingTF, msg: DecodedMessageTuple):
def tf_remove(cfg: SettingTF, msg: DecodedMessageTuple) -> None:
schema, channel, message, ros_msg = msg

if cfg.remove:
Expand Down
8 changes: 4 additions & 4 deletions src/kappe/module/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SettingTimeOffset(BaseModel):
update_publish_time: bool = False


def time_offset_stamp(cfg: SettingTimeOffset, message: Message, stamp: TimeMsg):
def time_offset_stamp(cfg: SettingTimeOffset, message: Message, stamp: TimeMsg) -> None:
if cfg.pub_time:
stamp_nano = message.publish_time
else:
Expand All @@ -62,7 +62,7 @@ def time_offset_stamp(cfg: SettingTimeOffset, message: Message, stamp: TimeMsg):
message.log_time = stamp_nano


def time_offset_rec(cfg: SettingTimeOffset, message: Message, msg: Any):
def time_offset_rec(cfg: SettingTimeOffset, message: Message, msg: Any) -> None:
if not hasattr(msg, '__slots__'):
return

Expand All @@ -79,15 +79,15 @@ def time_offset_rec(cfg: SettingTimeOffset, message: Message, msg: Any):
time_offset_rec(cfg, message, attr)


def time_offset(cfg: SettingTimeOffset, msg: DecodedMessageTuple):
def time_offset(cfg: SettingTimeOffset, msg: DecodedMessageTuple) -> None:
"""Apply time offset to the message."""
ros_msg = msg.decoded_message
if not hasattr(msg, '__slots__'):
return
time_offset_rec(cfg, msg.message, ros_msg)


def fix_ros1_time(msg: Any):
def fix_ros1_time(msg: Any) -> None:
"""
Fix ROS1 time and duration types, recursively inplace.
Expand Down
2 changes: 1 addition & 1 deletion src/kappe/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class ConverterPlugin(ABC):
def __init__(self, **_kwargs: Any):
def __init__(self, **_kwargs: Any) -> None:
self.logger = logging.getLogger(self.__class__.__name__)

@property
Expand Down
6 changes: 3 additions & 3 deletions src/kappe/plugins/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class CompressImage(ConverterPlugin):
def __init__(self, *, quality: int = 95):
def __init__(self, *, quality: int = 95) -> None:
super().__init__()
self.quality = quality
self.logger.debug('quality=%d', quality)
Expand All @@ -36,7 +36,7 @@ def output_schema(self) -> str:


class ReCompress(ConverterPlugin):
def __init__(self, *, quality: int = 10):
def __init__(self, *, quality: int = 10) -> None:
self.quality = quality

def convert(self, ros_msg: Any) -> Any:
Expand All @@ -56,7 +56,7 @@ def output_schema(self) -> str:


class SaveCompress(ConverterPlugin):
def __init__(self, *, quality: int = 10):
def __init__(self, *, quality: int = 10) -> None:
self.quality = quality
self.counter = 0

Expand Down

0 comments on commit 74f2b44

Please sign in to comment.