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

Fixes for new mypy (Ubuntu 24.04) #1763

Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Is regeneration of Python stubs required?
run: |
rosbag2_path=$(colcon list -p --packages-select rosbag2)/..
sudo apt update && sudo apt -y install mypy=0.942-1ubuntu1
sudo apt update && sudo apt -y install mypy
source install/setup.sh
stubgen -p rosbag2_py -o ${rosbag2_path}/rosbag2_py
cd ${rosbag2_path}
Expand Down
7 changes: 6 additions & 1 deletion rosbag2_py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ source install/setup.sh
# Make sure rosbag2_py can be imported
python3 -c 'import rosbag2_py'
sudo apt update && sudo apt install mypy=0.942-1ubuntu1
# Ubuntu 24.04
sudo apt update && sudo apt install mypy
# Older Ubuntu
# sudo pip3 install -U --break-system-packages mypy==1.9
Comment on lines +20 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r7vme The problem is that on Ubuntu 22.04 the default pip3 version is 22.0.2 and python version is 3.10 and there is no --break-system-packages option for pip3 install on those versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another aspect of installing via pip3.
What if the user already has an old version of mypy installed with the

sudo apt update && sudo apt install mypy

What version of the mypy will be used? It seems like an undefined behavior that we would like to avoid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelOrlov

The problem is that on Ubuntu 22.04 the default pip3 version is 22.0.2 and python version is 3.10 and there is no --break-system-packages option for pip3 install on those versions.

My bad, --break-system-packages should be removed

What version of the mypy will be used? It seems like an undefined behavior that we would like to avoid.

I tested in docker container with ubuntu:jammy and after installing 1.9.0 via pip and 0.942 via apt. I got

root@f647688bc269:/# mypy --version
mypy 1.9.0 (compiled: yes)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r7vme Ok it works.
Only one concern is about sudo for pip3 install command.
It seems we can install mypy without sudo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without sudo mypy installing in the user local folder. e.g. /home/morlov/.local/bin/mypy

cd <rosbag2 git repo>
stubgen -p rosbag2_py -o rosbag2_py
```
2 changes: 2 additions & 0 deletions rosbag2_py/rosbag2_py/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ from rosbag2_py._reindexer import Reindexer as Reindexer
from rosbag2_py._storage import BagMetadata as BagMetadata, ConverterOptions as ConverterOptions, FileInformation as FileInformation, MessageDefinition as MessageDefinition, MetadataIo as MetadataIo, ReadOrder as ReadOrder, ReadOrderSortBy as ReadOrderSortBy, StorageFilter as StorageFilter, StorageOptions as StorageOptions, TopicInformation as TopicInformation, TopicMetadata as TopicMetadata, get_default_storage_id as get_default_storage_id, to_rclcpp_qos_vector as to_rclcpp_qos_vector
from rosbag2_py._transport import PlayOptions as PlayOptions, Player as Player, RecordOptions as RecordOptions, Recorder as Recorder, ServiceRequestsSource as ServiceRequestsSource, bag_rewrite as bag_rewrite
from rosbag2_py._writer import SequentialCompressionWriter as SequentialCompressionWriter, SequentialWriter as SequentialWriter, get_registered_compressors as get_registered_compressors, get_registered_serializers as get_registered_serializers, get_registered_writers as get_registered_writers

__all__ = ['bag_rewrite', 'CompressionMode', 'CompressionOptions', 'compression_mode_from_string', 'compression_mode_to_string', 'ConverterOptions', 'FileInformation', 'get_default_storage_id', 'get_registered_readers', 'get_registered_writers', 'get_registered_compressors', 'get_registered_serializers', 'to_rclcpp_qos_vector', 'ReadOrder', 'ReadOrderSortBy', 'Reindexer', 'SequentialCompressionReader', 'SequentialCompressionWriter', 'SequentialReader', 'SequentialWriter', 'StorageFilter', 'StorageOptions', 'TopicMetadata', 'TopicInformation', 'BagMetadata', 'MessageDefinition', 'MetadataIo', 'Info', 'Player', 'PlayOptions', 'ServiceRequestsSource', 'Recorder', 'RecordOptions', 'LocalMessageDefinitionSource']
3 changes: 0 additions & 3 deletions rosbag2_py/rosbag2_py/_compression_options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ MESSAGE: CompressionMode
NONE: CompressionMode

class CompressionMode:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
FILE: ClassVar[CompressionMode] = ...
MESSAGE: ClassVar[CompressionMode] = ...
NONE: ClassVar[CompressionMode] = ...
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
Expand Down
4 changes: 1 addition & 3 deletions rosbag2_py/rosbag2_py/_message_definitions.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

class LocalMessageDefinitionSource:
def __init__(self) -> None: ...
def get_full_text(self, *args, **kwargs) -> Any: ...
def get_full_text(self, *args, **kwargs): ...
14 changes: 6 additions & 8 deletions rosbag2_py/rosbag2_py/_reader.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Any

class SequentialCompressionReader:
def __init__(self) -> None: ...
def get_all_message_definitions(self, *args, **kwargs) -> Any: ...
def get_all_topics_and_types(self, *args, **kwargs) -> Any: ...
def get_metadata(self, *args, **kwargs) -> Any: ...
def get_all_message_definitions(self, *args, **kwargs): ...
def get_all_topics_and_types(self, *args, **kwargs): ...
def get_metadata(self, *args, **kwargs): ...
def has_next(self) -> bool: ...
def open(self, arg0, arg1) -> None: ...
def open_uri(self, arg0: str) -> None: ...
Expand All @@ -16,9 +14,9 @@ class SequentialCompressionReader:

class SequentialReader:
def __init__(self) -> None: ...
def get_all_message_definitions(self, *args, **kwargs) -> Any: ...
def get_all_topics_and_types(self, *args, **kwargs) -> Any: ...
def get_metadata(self, *args, **kwargs) -> Any: ...
def get_all_message_definitions(self, *args, **kwargs): ...
def get_all_topics_and_types(self, *args, **kwargs): ...
def get_metadata(self, *args, **kwargs): ...
def has_next(self) -> bool: ...
def open(self, arg0, arg1) -> None: ...
def open_uri(self, arg0: str) -> None: ...
Expand Down
26 changes: 5 additions & 21 deletions rosbag2_py/rosbag2_py/_storage.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import ClassVar, Dict, List

import datetime
from typing import ClassVar, Dict, List

class BagMetadata:
bag_size: int
compression_format: str
compression_mode: str
custom_data: Dict[str,str]
custom_data: Dict[str, str]
duration: object
files: List[FileInformation]
message_count: int
Expand All @@ -16,7 +15,7 @@ class BagMetadata:
storage_identifier: str
topics_with_message_count: List[TopicInformation]
version: int
def __init__(self, version: int = ..., bag_size: int = ..., storage_identifier: str = ..., relative_file_paths: List[str] = ..., files: List[FileInformation] = ..., duration: object = ..., starting_time: object = ..., message_count: int = ..., topics_with_message_count: List[TopicInformation] = ..., compression_format: str = ..., compression_mode: str = ..., custom_data: Dict[str,str] = ..., ros_distro: str = ...) -> None: ...
def __init__(self, version: int = ..., bag_size: int = ..., storage_identifier: str = ..., relative_file_paths: List[str] = ..., files: List[FileInformation] = ..., duration: object = ..., starting_time: object = ..., message_count: int = ..., topics_with_message_count: List[TopicInformation] = ..., compression_format: str = ..., compression_mode: str = ..., custom_data: Dict[str, str] = ..., ros_distro: str = ...) -> None: ...

class ConverterOptions:
input_serialization_format: str
Expand Down Expand Up @@ -71,20 +70,17 @@ class ReadOrder:
def __init__(self, sort_by: ReadOrderSortBy = ..., reverse: bool = ...) -> None: ...

class ReadOrderSortBy:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
File: ClassVar[ReadOrderSortBy] = ...
PublishedTimestamp: ClassVar[ReadOrderSortBy] = ...
ReceivedTimestamp: ClassVar[ReadOrderSortBy] = ...
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
Expand All @@ -100,7 +96,7 @@ class StorageFilter:
def __init__(self, topics: List[str] = ..., services_events: List[str] = ..., regex: str = ..., exclude_topics: List[str] = ..., exclude_service_events: List[str] = ..., regex_to_exclude: str = ...) -> None: ...

class StorageOptions:
custom_data: Dict[str,str]
custom_data: Dict[str, str]
end_time_ns: int
max_bagfile_duration: int
max_bagfile_size: int
Expand All @@ -111,7 +107,7 @@ class StorageOptions:
storage_id: str
storage_preset_profile: str
uri: str
def __init__(self, uri: str, storage_id: str = ..., max_bagfile_size: int = ..., max_bagfile_duration: int = ..., max_cache_size: int = ..., storage_preset_profile: str = ..., storage_config_uri: str = ..., snapshot_mode: bool = ..., start_time_ns: int = ..., end_time_ns: int = ..., custom_data: Dict[str,str] = ...) -> None: ...
def __init__(self, uri: str, storage_id: str = ..., max_bagfile_size: int = ..., max_bagfile_duration: int = ..., max_cache_size: int = ..., storage_preset_profile: str = ..., storage_config_uri: str = ..., snapshot_mode: bool = ..., start_time_ns: int = ..., end_time_ns: int = ..., custom_data: Dict[str, str] = ...) -> None: ...

class TopicInformation:
message_count: int
Expand All @@ -129,7 +125,6 @@ class TopicMetadata:
def equals(self, arg0: TopicMetadata) -> bool: ...

class rmw_qos_durability_policy_t:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT: ClassVar[rmw_qos_durability_policy_t] = ...
RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL: ClassVar[rmw_qos_durability_policy_t] = ...
Expand All @@ -138,19 +133,16 @@ class rmw_qos_durability_policy_t:
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
def value(self) -> int: ...

class rmw_qos_history_policy_t:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
RMW_QOS_POLICY_HISTORY_KEEP_ALL: ClassVar[rmw_qos_history_policy_t] = ...
RMW_QOS_POLICY_HISTORY_KEEP_LAST: ClassVar[rmw_qos_history_policy_t] = ...
Expand All @@ -159,19 +151,16 @@ class rmw_qos_history_policy_t:
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
def value(self) -> int: ...

class rmw_qos_liveliness_policy_t:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
RMW_QOS_POLICY_LIVELINESS_AUTOMATIC: ClassVar[rmw_qos_liveliness_policy_t] = ...
RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC: ClassVar[rmw_qos_liveliness_policy_t] = ...
Expand All @@ -180,19 +169,16 @@ class rmw_qos_liveliness_policy_t:
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
def value(self) -> int: ...

class rmw_qos_reliability_policy_t:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT: ClassVar[rmw_qos_reliability_policy_t] = ...
RMW_QOS_POLICY_RELIABILITY_RELIABLE: ClassVar[rmw_qos_reliability_policy_t] = ...
Expand All @@ -201,12 +187,10 @@ class rmw_qos_reliability_policy_t:
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
Expand Down
16 changes: 7 additions & 9 deletions rosbag2_py/rosbag2_py/_transport.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Any, ClassVar, List

from typing import overload
import datetime
import rosbag2_py._storage
from _typeshed import Incomplete
from typing import ClassVar, List, overload

class PlayOptions:
clock_publish_frequency: float
Expand All @@ -22,7 +21,7 @@ class PlayOptions:
rate: float
read_ahead_queue_size: int
regex_to_filter: str
service_requests_source: Any
service_requests_source: Incomplete
services_to_filter: List[str]
start_offset: float
start_paused: bool
Expand All @@ -38,7 +37,8 @@ class Player:
@overload
def __init__(self, arg0: str) -> None: ...
def burst(self, storage_options: rosbag2_py._storage.StorageOptions, play_options: PlayOptions, num_messages: int) -> None: ...
def cancel(self, *args, **kwargs) -> Any: ...
@staticmethod
def cancel() -> None: ...
def play(self, storage_options: rosbag2_py._storage.StorageOptions, play_options: PlayOptions) -> None: ...

class RecordOptions:
Expand Down Expand Up @@ -74,23 +74,21 @@ class Recorder:
def __init__(self) -> None: ...
@overload
def __init__(self, arg0: str) -> None: ...
def cancel(self, *args, **kwargs) -> Any: ...
@staticmethod
def cancel() -> None: ...
def record(self, storage_options: rosbag2_py._storage.StorageOptions, record_options: RecordOptions, node_name: str = ...) -> None: ...

class ServiceRequestsSource:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
CLIENT_INTROSPECTION: ClassVar[ServiceRequestsSource] = ...
SERVICE_INTROSPECTION: ClassVar[ServiceRequestsSource] = ...
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
Expand Down
2 changes: 1 addition & 1 deletion rosbag2_py/rosbag2_py/_writer.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import overload
import rosbag2_py._compression_options
import rosbag2_py._storage
from typing import overload

class SequentialCompressionWriter:
def __init__(self, arg0: rosbag2_py._compression_options.CompressionOptions) -> None: ...
Expand Down
Loading