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

Refactor utility functions in ros2bag #358

Merged
merged 10 commits into from
Apr 10, 2020

Conversation

piraka9011
Copy link
Contributor

  • Move utility function to ros2bag's API module.
  • Rename tests to be more descriptive

Signed-off-by: Anas Abou Allaban [email protected]

@piraka9011
Copy link
Contributor Author

@ros2/aws-oncall - please run this CI job
Gist: https://gist.githubusercontent.com/piraka9011/b7b7b3b22274d37cd1342ad0523974a7/raw/3d6ecc423d7c495ec16fa2c48c92275268b2606f/ros2.repos
BUILD args: --packages-up-to ros2bag
TEST args: --packages-select ros2bag
Job: ci_launcher

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

def create_bag_directory(uri: str) -> str:
"""Create a directory."""
try:
os.makedirs(uri)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see the exception-case return value used anywhere.

In the successful case this function hits end of scope without returning a value.

Is the intended return type None (and supposed to log) or is it Optional[str]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this from the play verb and I believe it's intention is to simply log the result.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM'd the PR, but the returned value here doesn't actually ever get printed. You can move forward though, if this is maintaining previous behavior

@piraka9011 piraka9011 requested a review from emersonknapp April 8, 2020 16:31
Signed-off-by: Anas Abou Allaban <[email protected]>
Signed-off-by: Anas Abou Allaban <[email protected]>
Signed-off-by: Anas Abou Allaban <[email protected]>
Signed-off-by: Anas Abou Allaban <[email protected]>
Signed-off-by: Anas Abou Allaban <[email protected]>
Signed-off-by: Anas Abou Allaban <[email protected]>
Signed-off-by: Anas Abou Allaban <[email protected]>
@piraka9011
Copy link
Contributor Author

piraka9011 commented Apr 8, 2020

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Edit: Rebuilt with bionic...
Edit2: Still failing with pluginlib... not sure why.

@piraka9011
Copy link
Contributor Author

Another round with new config and gist

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status



def print_error(string: str) -> str:
return '[ERROR] [ros2bag]: {}'.format(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why reimplementing logging.error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was debating between using logging vs print statements and it appears that the ros2 verb extension needs to return when something goes wrong/finishes.
If we use logging, we'd need to log followed by a return with the same statement which is duplicate work.
If there's a proper approach for returning from a ros2 verb lmk (I'm following what other packages did).

def check_positive_float(value: float) -> float:
"""Argparse validator to verify that a value is a float and positive."""
try:
fvalue = float(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems to contradict your typing? (value is a floating-point value)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure what to put the type as since this is supposed to be used as an argparse validator. (Is Any valid?)


uri = args.output or datetime.datetime.now().strftime('rosbag2_%Y_%m_%d-%H_%M_%S')

if os.path.isdir(uri):
return "[ERROR] [ros2bag]: Output folder '{}' already exists.".format(uri)
return print_error("Output folder '{}' already exists.".format(uri))
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving the argument validation in the arpgarse logic if you keep modifying this code. This will take care for you of reporting errors to the users the "proper way". You could just create a function checking if the directory exists, and call strftime to pass a default value as it's built here.

Signed-off-by: Anas Abou Allaban <[email protected]>
@piraka9011
Copy link
Contributor Author

piraka9011 commented Apr 9, 2020

One more round ...

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Anas Abou Allaban <[email protected]>
@piraka9011
Copy link
Contributor Author

piraka9011 commented Apr 9, 2020

There's an unrelated warning:

ament_export_interfaces() is deprecated, use ament_export_targets() instead

I will address this in a follow up PR.

NVM, this was addressed in #360

@piraka9011 piraka9011 merged commit e05ea4f into ros2:master Apr 10, 2020
@piraka9011 piraka9011 deleted the refactor-ros2bag branch April 10, 2020 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants