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

Add black formatter #392

Merged
merged 2 commits into from
Mar 23, 2021
Merged

Add black formatter #392

merged 2 commits into from
Mar 23, 2021

Conversation

tylerjw
Copy link
Member

@tylerjw tylerjw commented Mar 20, 2021

Description

This adds the black python formatter to CI. This formatter is like clang-format in that it will automatically reformat all code to match a pre-defined style. This makes reading the code much nicer. It will also enforce that all the python code is python3.

I know this is a large reformatting PR. I will make the same PR against the ros1 moveit repo to add the same functionality there for this and the other pre-commit tests. That way this will not impact being able to sync between the two repos.

@codecov
Copy link

codecov bot commented Mar 20, 2021

Codecov Report

Merging #392 (c10e52a) into main (cc557b4) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #392      +/-   ##
==========================================
+ Coverage   53.33%   53.33%   +0.01%     
==========================================
  Files         210      210              
  Lines       18814    18814              
==========================================
+ Hits        10032    10033       +1     
+ Misses       8782     8781       -1     
Impacted Files Coverage Δ
...raint_samplers/src/default_constraint_samplers.cpp 77.54% <0.00%> (-0.36%) ⬇️
...meterization/work_space/pose_model_state_space.cpp 84.56% <0.00%> (+1.48%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc557b4...c10e52a. Read the comment docs.

@tylerjw tylerjw added this to In progress in Sprint 00 via automation Mar 20, 2021
Copy link
Contributor

@felixvd felixvd left a comment

Choose a reason for hiding this comment

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

I just had a quick scan through this. Looks good overall though.

Could you check if there's a setting to delete the trailing comma in a list of arguments? I think that's just atrocious.

action="store_true",
dest="interactive",
default=True,
help="Run the command processing script in interactive mode (default)",
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know ending a list of arguments with an open comma like this wasn't a syntax error. I guess it's just hideous. The more you know.

There's no setting for this in black, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

there is a good reason for this: it avoids syntax errors when (named) arguments get shuffled around -- and the person doing that forgets to add the comma and then spends I-don't-know-how-long figuring out where the syntax error is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess. Although when I see a comma followed by a closed bracket I look like this:

Screen Shot 2021-03-23 at 12 40 13

I also don't know how often people reorder arguments vs how often code is read, but it doesn't matter. It's the setting in black and I don't have strong objections.

self.assertTrue(len(retimed_plan.joint_trajectory.points) > 0, "Retimed plan is invalid")
retimed_plan = self.time_parameterization(plan, "time_optimal_trajectory_generation")
self.assertTrue(len(retimed_plan.joint_trajectory.points) > 0, "Retimed plan is invalid")
retimed_plan = self.time_parameterization(
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of a lot of lines, but it's not critical.

Copy link
Member

@henningkayser henningkayser left a comment

Choose a reason for hiding this comment

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

Really nice! Comments are mostly nits, maybe the config could be tweaked a little

@@ -33,7 +37,9 @@ def test(self):
error_code1, plan, time = self.plan(target)
error_code = MoveItErrorCodes()
error_code.deserialize(error_code1)
if (error_code.val == MoveItErrorCodes.SUCCESS) and self.group.execute(plan):
if (error_code.val == MoveItErrorCodes.SUCCESS) and self.group.execute(
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit out of place

line += ' | '
print(' {}: {} {}'.format(ros, response, params['url']), file=sys.stderr)
line += " | "
print(
Copy link
Member

Choose a reason for hiding this comment

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

also a bit odd

@@ -119,7 +129,9 @@ def add_plane(self, name, pose, normal=(0, 0, 1), offset=0):
co.plane_poses = [pose.pose]
self.__submit(co, attach=False)

def attach_mesh(self, link, name, pose=None, filename='', size=(1, 1, 1), touch_links=[]):
def attach_mesh(
Copy link
Member

Choose a reason for hiding this comment

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

should we change the max time length?

@@ -6,7 +6,9 @@
import rostest
import os

from moveit_ros_planning_interface._moveit_move_group_interface import MoveGroupInterface
from moveit_ros_planning_interface._moveit_move_group_interface import (
Copy link
Member

Choose a reason for hiding this comment

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

not sure, this also seems like a weird rule for a single import.

Sprint 00 automation moved this from In progress to Reviewer approved Mar 22, 2021
@rhaschke
Copy link
Contributor

black - by design - "is not configurable". I think the only option is --line-length. It's configured like this:

  - repo: https://github.com/psf/black
    rev: 20.8b1
    hooks:
      - id: black
        args: ["--line-length", "100"]

@tylerjw
Copy link
Member Author

tylerjw commented Mar 22, 2021

black - by design - "is not configurable". I think the only option is --line-length. It's configured like this:

  - repo: https://github.com/psf/black
    rev: 20.8b1
    hooks:
      - id: black
        args: ["--line-length", "100"]

@henningkayser imo we should just take black the way it is. The line length setting included. One thing that's great about black is if you install pre-commit locally you can just stop trying to edit the formatting of your python code and it'll do it for you and we'll all have a nice consistent style. I honestly wish clang-format only had --style options and not a config file.

Copy link
Contributor

@felixvd felixvd left a comment

Choose a reason for hiding this comment

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

LGTM even with the idiosyncrasies.

@henningkayser henningkayser merged commit 6b2ad23 into moveit:main Mar 23, 2021
Sprint 00 automation moved this from Reviewer approved to Done Mar 23, 2021
@tylerjw tylerjw deleted the add-black-formatter branch March 23, 2021 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants