Skip to content

Ruff#1375

Open
naushir wants to merge 3 commits intonextfrom
ruff
Open

Ruff#1375
naushir wants to merge 3 commits intonextfrom
ruff

Conversation

@naushir
Copy link
Copy Markdown
Collaborator

@naushir naushir commented Apr 2, 2026

No description provided.

@naushir naushir force-pushed the ruff branch 4 times, most recently from 6aee5f8 to fb1afdb Compare April 2, 2026 12:07
@naushir
Copy link
Copy Markdown
Collaborator Author

naushir commented Apr 2, 2026

@davidplowman here's a first pass to look at.

Comment thread apps/app_full.py
QVBoxLayout,
QWidget,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This shows some of the obvious differences. It will break right at an open bracket (, and not after the next token or parameter. Then it will put every subsequent item one-per-line. Finally, the last item will have a trailing comma ,.

I don't think I mind any of this too much, the most important thing is that it's legible and easy to follow. Sometimes the one-item-per-line thing seems a bit extreme and it might be nicer to be able to group things.

Comment thread examples/stack_raw.py
black_level = metadata["SensorBlackLevels"][0] / 2 ** (16 - raw_format.bit_depth)
accumulated -= (num_frames - 1) * int(black_level)
accumulated = accumulated.clip(0, 2 ** raw_format.bit_depth - 1).astype(np.uint16)
accumulated = accumulated.clip(0, 2**raw_format.bit_depth - 1).astype(np.uint16)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It does seem a bit confused by the power ** operator. When not followed by a bracket, it wants to remove spaces. But when followed by a bracket, it adds them!

Don't mind terribly, but consistency would probably be easier to live with!

Comment thread examples/hailo/pose.py
R_KNEE,
L_ANKLE,
R_ANKLE,
) = range(17)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suspect rolling some of these lines together would be better?

while True:
buffer = picam2.capture_buffer("lores")
grey = buffer[:stride * lowresSize[1]].reshape((lowresSize[1], stride))
grey = buffer[: stride * lowresSize[1]].reshape((lowresSize[1], stride))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adding spaces round : seems a bit strange to me, but I guess it doesn't particularly matter.

picam2.start_preview(Preview.QTGL)
config = picam2.create_preview_configuration(main={"size": normalSize},
lores={"size": lowresSize, "format": "YUV420"})
config = picam2.create_preview_configuration(main={"size": normalSize}, lores={"size": lowresSize, "format": "YUV420"})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sometimes I quite like to put longer parameters on separate lines. I'd be OK with it splitting immediately after the (, but could we get it to accept the split line version even when the line isn't technically too long?

video_config = picam2.create_video_configuration(
main={"size": (1280, 720), "format": "RGB888"}, lores={"size": (640, 480), "format": "YUV420"}
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm surprised it puts both parameters on one line here. I'd have preferred to separate them, I think.

Comment thread picamera2/devices/imx500/postprocess.py Outdated
[11, 13],
[12, 14],
[13, 15],
[14, 16], # Legs
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, would prefer to group more like the original?

87,
88,
89,
90,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not particularly liking the one-item-per-line here!

Comment thread picamera2/outputs/ffmpegoutput.py Outdated
'-c:a', self.audio_codec]
audio_input = [
'-itsoffset',
str(self.audio_sync),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Quite a lot of these are actually option + value pairs, so it would be nice to be able to keep them like that.

0,
EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT,
EGL_NONE,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, all parameter name + value pairs, so would be nice to group them in pairs?

Comment thread picamera2/previews/q_gl_picamera2.py Outdated
1.0, 1.0,
0.0, 1.0
]
vertPositions = [0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Preferred the one coord (2 numbers) per line version.

h * cfg.stride + h2 * stride2,
EGL_DMA_BUF_PLANE2_PITCH_EXT,
stride2,
EGL_NONE,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, nicer in pairs (ditto below).

Comment thread picamera2/converters.py Outdated
YUV2RGB_REC709 = np.array([[1.164, 1.164, 1.164], [0.0, -0.213, 2.112], [1.793, -0.533, 0.0]]) # noqa
YUV2RGB_JPEG = np.array([[1.0, 1.0, 1.0], [0.0, -0.344, 1.772], [1.402, -0.714, 0.0]]) # noqa
YUV2RGB_SMPTE170M = np.array([[1.164, 1.164, 1.164], [0.0, -0.392, 2.017], [1.596, -0.813, 0.0]]) # noqa
YUV2RGB_REC709 = np.array([[1.164, 1.164, 1.164], [0.0, -0.213, 2.112], [1.793, -0.533, 0.0]]) # noqa
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Quite like being able to add spaces so as to line up the matrix columns...

Replace flake8 (plus 10 plugins) and pylint with ruff for both CI and
pre-commit hooks. The new CI workflow uses astral-sh/ruff-action and no
longer needs to build libcamera/kmsxx since ruff doesn't import project
code.

- Add pyproject.toml with ruff configuration
- Add .github/workflows/ruff.yml (replaces flake8.yml)
- Update .pre-commit-config.yaml to use ruff hooks
- Update requirements-test.txt (11 deps removed, ruff added)
- Delete .flake8, .pylintrc, .github/workflows/flake8.yml
- Add .ruff_cache/ to .gitignore

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Comment thread picamera2/encoders/h264_encoder.py Outdated
Quality.MEDIUM: 6,
Quality.HIGH: 9,
Quality.VERY_HIGH: 15}
BITRATE_TABLE = {Quality.VERY_LOW: 2, Quality.LOW: 4, Quality.MEDIUM: 6, Quality.HIGH: 9, Quality.VERY_HIGH: 15}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think I preferred it with the extra line breaks?

naushir added 2 commits April 7, 2026 11:55
Run ruff format across the entire codebase and fix lint violations
that ruff catches but flake8 did not:

- B904: Add 'from err' to re-raises in except blocks
- E721: Use 'is' instead of '==' for type comparisons
- E741: Rename ambiguous variable name 'l' to 'lo'
- I001: Sort import blocks

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Move all package metadata from setup.py to pyproject.toml using
PEP 621 declarative format. Use setuptools as the build backend
with automatic package discovery for picamera2*.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
@davidplowman
Copy link
Copy Markdown
Collaborator

Overall, mostly I don't mind the changes and am happy to go with them.

The only general feeling I got was that it was quite opinionated on when to break lines, and how to break them. Often creating very many single entry lines, and sometimes even rolling lines together that were initially separated. Mostly I feel I wanted it to be less dictatorial here - either with hints that you could give, or even as a more general setting.

Most of the other stuff, .e.g. spaces around :, and so on, even if I wasn't particularly convinced, I was OK with.

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.

2 participants