Automated code quality improvements - #5384
Conversation
There was a problem hiding this comment.
qlty found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
|
This is finding some nice little bits to check up on! The zip() strict thing seems really nice and useful, I have definitely fallen into that trap before |
|
On the |
|
The linter is setup to run on files being edited (with much weaker rules than what I'm running locally, or used to generate this PR). It's therefore picking up on a bunch of pre-existing issues (especially in the bin files, which haven't been checked until now). In short, the linter is definitely not going to pass here! However, it highlights that a bunch of low-hanging things to fix after this remains. We still ship binaries in a now nonstandard way, this doesn't change that, it just lets us run the code quality checks on the executables. In terms of rough breakdown of issues that this fixes:
|
|
The failure is not related to this, and seems to be an issue with |
|
What is zip strict ? |
zip strict enforces that both things being zipped are the same length |
|
I worry this would make it essentially impossible to backport PRs to existing active release branches (e.g. 2.11), though that could be hopefully addressed by merging a PR equivalent to this into the release branch first. |
|
With 507 files changed, how can we isolate actual changes in code (and possibly learn from them ..) rather than formatting conventions, etc.? |
|
Would it help to identify all the files that are not being touched by any currently open PRs, and apply the change only to those as a first step? Then, as the remaining PRs get merged over time, we can periodically go through this exercise again and slowly reformat all the remaining files. Too complicated? |
|
@tdent This PR is only formatting changes. There are some "actual changes in code" that would follow this, but I wanted to put this out first to gauge appetite for trying to improve "code quality" (and because following patches require a human to actually check them, this is advertised as "safe") |
|
The list I printed earlier is the full list of things being fixed here, if anyone wanted to learn from this, but the idea would be that once this is merged future PRs would complain if any of these issues are reintroduced. (I note though, that the majority of recent PRs are done using AI agents, in which case the agent is just fixing this and the user doesn't have to learn or care) |
|
@titodalcanton I could try and exclude files being edited, but we have 62 open PRs, so how far back do I go? ... And it still doesn't fix the issue of the PR that someone's about to put up or the issue of cherry-picking later commits onto diverging branches .... I note that for anyone writing PRs with coding agents (which is now very common) dealing with this will be easy though. |
|
The big table you pasted earlier has a lot of formatting fixes, but also what I would consider code changes, although they may be guaranteed to not change functionality: e.g. |
|
So I would argue that https://docs.astral.sh/ruff/rules/if-stmt-min-max/ is not a code change, it's just formatting. It is a safe code change though in that it's still doing the same thing. The |
|
But again, I can split some of these off as desired, but one commit per each of these issues would be worse than doing this in one block (both for me and for rebasing changes) |
|
The leading letter is indicative of the type of fix, so perhaps splitting this off by letter code would be one approach. e.g. "Q" type fixes, "D" type fixes etc. |
|
I am leaning towards accepting to merge this now, however could you please indicate exactly what command you ran to do this? We will need that reference for doing the same thing to active release branches. |
|
Ah, then don't know why Gareth mentioned zip(strict=True) earlier. The table of different codes/types of changes is incomplete (it says 62 more not displayed), so I don't know, if they were visible, whether there would be anything I would consider a code change in terms of. Is it possible to show the entire list of codes? |
Sorry for the confusion, I mistakenly thought that this was what is being fixed, it's actually what is coming up from the reviewer bot (e.g. here) |
|
Here's the full set of things fixed:
|
|
@titodalcanton Here's what was run: Here are the exact commands, in order:
Passing bin/ as a directory here only picked up the one .py-suffixed file in it (bin/plotting/pycbc_plot_Nth_loudest_coinc_omicron.py) — ruff's directory traversal filters by extension, so the 221 extensionless scripts weren't touched by this pass at all.
Since those scripts have no .py extension, ruff format bin//ruff check --fix bin/ silently see zero files (same extension-filtering issue). They had to be passed explicitly by path: Both passes used --fix only (not --unsafe-fixes), so only rules ruff itself marks safe were auto-applied PLEASE NOTE I then had to do a few small changes: after this. The first one are because this broke a monkeypatch we had for emcee_pt (so we need to use np.float here). The second one is a circular import, so bad form on our part, and should be fixed properly (we don't want the order of imports in the |
GarethCabournDavies
left a comment
There was a problem hiding this comment.
Approved, as I have been convinced that this is all safe
|
@spxiwh should |
|
…and I guess same for |
|
Is there a way to determine which files were affected by |
ruffthe new linter recently added has some tools for automatically changing code to match the formatting settings. These tools are "safe" in the sense that they don't/can't change functionality. This PR is the result of running that. We also extend the qlty configuration file such that we are picking up the files inbin(for the first time).Predictably, this is a lot of files! I don't expect anybody to look over each of these (though you can get a sense of what it is doing). I would be concerned about the issue of needing to rebase other ongoing work due to conflicts if people have edited code that this is touching.
Suggestions for what to do with this? ... There are still quite a few remaining things to address in the codebase in terms of code quality, but I might discuss that in a separate issue if this is okay to merge.
Standard information about the request
This is a: Code Quality PR
This change affects: No functionality.
This change changes: Code quality
This change: has appropriate unit tests, follows style guidelines (See e.g. PEP8), has been proposed using the contribution guidelines
Motivation
Wanting to improve code quality and
ruffoffers automated tools to do this.Contents
Many files edited
Links to any issues or associated PRs
N/A
Testing performed
We'll have to rely on the test CI for this.