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

Ruff #175

Merged
merged 7 commits into from
Feb 7, 2024
Merged

Ruff #175

merged 7 commits into from
Feb 7, 2024

Conversation

dogversioning
Copy link
Contributor

This PR makes the following changes:

  • Swapped out black & manual linting for ruff
  • Global linting/formatting pass
    • About %50 of this is just backing out the pre-3.10 Typing module

Checklist

  • Consider if documentation (like in docs/) needs to be updated
  • Consider if tests should be added
  • Update template repo if there are changes to study configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the noqa statements in this file are just 'PsmPy is doing something under the hood I don't want to debug unless I can open a PR against it to fix it'. Still waiting on that.

.github/workflows/ci.yaml Outdated Show resolved Hide resolved
Comment on lines 5 to 6
- id: ruff
args: [--fix]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah here's the philosophical rub. We've talked about how appropriate it is to automatically fix bad code for the developer in a way that they aren't brought into the loop so they can learn to be better.

This does bring them into the loop a little bit, by not auto-committing the results at least. So I'd like to keep it that way, if/when we make the auto-formatting auto-committed.

I'd personally prefer to keep such checks out of the commit hooks altogether because of my WIP-commit-heavy workflow. I assume your workflow is different.

Anyway, we don't need to agree on this kind of thing. Just raising the point again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, per this and our chat off PR about this last night, I did some digging and found that pre-commit supports hooks at basically every lifecycle stage, so i've moved this check to pre-push. It didn't look like it is installed normally, so you have to specify the stage with pre-commit install --hook-type pre-push, but it then does the linting only on push to remote.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting... OK - we have the pre-commit instructions in our CONTRIBUTING.md docs usually (I think that's what we named them). - maybe those need updating.

It's annoying that pre-commit isn't more turnkey, but fine 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yep, meant to do that and spaced out - bumped the docs.

language_version: python3.9
- id: ruff
args: [--fix]
- id: ruff-format
Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand, formatting I find it awkward to push in front of the dev - they didn't do anything wrong really. So this I'd like to see return to auto-commit status at some point, once we trust it (which off-PR we talked about as the reason for this change).

cumulus_library/base_table_builder.py Outdated Show resolved Hide resolved
cumulus_library/cli.py Outdated Show resolved Hide resolved
@@ -29,7 +27,8 @@ def open(self, *args, **kwargs):
if str(args[0]).endswith(".bsv"):
args = (
Path(
f"./tests/test_data/mock_bsvs/{str(args[0]).rsplit('/', maxsplit=1)[-1]}"
"./tests/test_data/mock_bsvs/",
f"{str(args[0]).rsplit('/', maxsplit=1)[-1]}",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think you can drop the surrounding f-string if you're breaking it off to its own Path() arg

def test_cli_path_mapping(
mock_load_json, mock_path, tmp_path, args, raises, expected
): # pylint: disable=unused-argument
def test_cli_path_mapping(mock_load_json, mock_path, tmp_path, args, raises, expected): # pylint: disable=unused-argument
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like a long line for ruff - curious why it allows it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#noqa/pylint codes seem to be allowed to break line length restricitions. i dont hate it.

tests/test_cli.py Outdated Show resolved Hide resolved
Comment on lines +17 to +18
*_, last_new = f
last_new = json.loads(last_new)
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 OK...

Comment on lines 26 to 27
except Exception:
last_ref = first_ref
Copy link
Contributor

Choose a reason for hiding this comment

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

What's with this exception here? That's new behavior yeah? Is there a more specific exception class to reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you try to unpack an iterator and its empty, you get an error - the docs didn't specify which. I can do some research.

Copy link
Contributor

Choose a reason for hiding this comment

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

Speaking of, it's interesting to me that ruff doesn't complain about a loose Exception catch. Which... I don't mind. There are plenty of valid reasons for it.

Can you check if it would complain about a bare except? Like if you did except: just alone -- I would want it to treat that as a flaggable error (and probably not an auto-fix one).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it did, that's how we ended up here in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

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

There wasn't a bare-except here before. But maybe during PR work you had one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it happened midstream

@dogversioning dogversioning merged commit becfbad into main Feb 7, 2024
3 checks passed
@dogversioning dogversioning deleted the mg/ruff branch February 7, 2024 16:21
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