strands-project / mongodb_store

MongoDB tools for storing and analysing runs of ROS systems.
BSD 3-Clause "New" or "Revised" License
49 stars 72 forks source link

Fix Python 3 bugs in mongodb_store #272

Closed ggorjup closed 2 years ago

ggorjup commented 2 years ago

After some experimentation in ROS Noetic, a couple of bugs related to Python 3 were found. This PR addresses those bugs:

  1. Install Python scripts with catkin_install_python in CMakeLists.txt: This makes sure we can run the nodes with #!/usr/bin/env python shebangs in ROS Noetic.
  2. Explicitly cast map and zip to list: In Python 3, map() and zip() do not return list object types (like they do in Python 2). Some other functions in mongodb_store assume the list type, so we cast them to list explicitly.
  3. Change buffer type for message serialization in Python 3: In Python 2, StringIO can handle bytes. In Python 3, we need to use a different IO in message serialization.
  4. Remove explicit string encoding in Python 3: In Python 2, strings and byte strings are both of type str. In Python 3, str and bytes are different, incompatible types. This means that it is an error if we try to (re-)encode a str: str('a', 'utf-8').
  5. Fix indentation, spaces, and types in the test file: The test file had some issues like inconsistent indentation, print statements with spaces, and a range object treated as a list.

The applied changes should have no effect on mongodb_store in Python 2.

I'm making this PR into melodic-devel, since noetic-devel does not exist yet (and as far as I know it's not possible to make a PR for a non-existing branch).