-
Notifications
You must be signed in to change notification settings - Fork 188
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
Use Black for Formatting #94
Conversation
Hi, thanks for posting this it looks interesting. Can you say how I could enforce this kind of style during development, for example by using the git pre-commit hook? Also, have you changed the style checking process on the test machine to complain if people don't stick to this style or not, I didn't quite understand that. |
There are a number of options for this:
|
Also, this PR is likely to be conflicted by basically any other change, so let me know when/if you want it and I can freshen it :) |
And to answer your earlier question. This line will cause the CI to reject PR's that are not consistant with the formatting requirements. |
As a totally incidental side benefit, this takes the style check responsibility off the pi you are using to run tests :) |
This change seems reasonable, but there are a couple of things that I can see we need to address:
|
Signed-off-by: Matthew Goodman <[email protected]>
Apparently running on a diff has been a feature request for some time now (psf/black#830, psf/black#142, psf/black#245, psf/black#370, psf/black#511). Looks unlikely that this will be put into mainline. There are a few wrapper-of-sorts that does seem to do this - https://github.com/akaihola/darker and https://github.com/wbolster/black-macchiato. Perhaps it's worth looking to see if those could be used instead? In particular, darker looks very promising and might be pretty much a drop-in replacement for the existing script. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some comments on the formatting produced by Black. Of course, these preferences are entirely personal to my tastes.
) | ||
YUV2RGB_REC709 = np.array( | ||
[[1.164, 1.164, 1.164], [0.0, -0.213, 2.112], [1.793, -0.533, 0.0]] | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer the original formatting. Or possibly all 3 matrices to look something like:
YUV2RGB_REC709 = np.array(
[ [1.164, 1.164, 1.164],
[0.0, -0.213, 2.112],
[1.793, -0.533, 0.0] ]
)
return simplejpeg.encode_jpeg(array, quality=self.q, colorspace=self.colour_space) | ||
return simplejpeg.encode_jpeg( | ||
array, quality=self.q, colorspace=self.colour_space | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I feel about the formatting here and in all the other places where the function arguments are put on the next line. The original reads easier to me.
self.lock = threading.Lock() # protects the functions and completed_requests fields | ||
self.lock = ( | ||
threading.Lock() | ||
) # protects the functions and completed_requests fields | ||
self.have_event_loop = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original looks better and more concise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was just trying to maintain the comment on the same line here...
if not isinstance(camera_config["colour_space"], libcamera._libcamera.ColorSpace): | ||
if not isinstance( | ||
camera_config["colour_space"], libcamera._libcamera.ColorSpace | ||
): | ||
raise RuntimeError("Colour space has incorrect type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer the original.
"YUYV", | ||
"UYVY", | ||
"VYUY", | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original single line version looks better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concur.
pointer, | ||
CFUNCTYPE, | ||
c_bool, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original single line version looks better.
EGL_ALPHA_SIZE, | ||
0, | ||
EGL_RENDERABLE_TYPE, | ||
EGL_OPENGL_ES2_BIT, | ||
EGL_NONE, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original looks better as you can associate the key-value pairs on one line. Ditto for the instances below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that is kinda and uglee tranform. Maybe these want to be a dict
then tranformed at the call site?
Seems like this isn't a real improvement here. |
A quick demo of how to make
black
auto-format everything. This also shifts format checking to gh infrastructure.All I did to generate a bulk of the changes in this PR was:
black picamera2
which in turn output the reformatted code:This has the side benefit of killing a lot of diff noise between PR's
Signed-off-by: Matthew Goodman [email protected]