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

Switch to ruff linting #2952

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Switch to ruff linting #2952

wants to merge 1 commit into from

Conversation

benjeffery
Copy link
Member

For numpy2 checks etc.

Copy link

codecov bot commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.65%. Comparing base (998d710) to head (54dabad).

Current head 54dabad differs from pull request most recent head 872880c

Please upload reports for the commit 872880c to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2952      +/-   ##
==========================================
- Coverage   89.63%   86.65%   -2.99%     
==========================================
  Files          29       11      -18     
  Lines       30189    22932    -7257     
  Branches     5877     4254    -1623     
==========================================
- Hits        27061    19872    -7189     
+ Misses       1789     1754      -35     
+ Partials     1339     1306      -33     
Flag Coverage Δ
c-tests 86.20% <ø> (ø)
lwt-tests 80.78% <ø> (ø)
python-c-tests 88.72% <ø> (ø)
python-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

see 18 files with indirect coverage changes

@benjeffery benjeffery force-pushed the ruff branch 4 times, most recently from bd43a25 to 17706a7 Compare May 23, 2024 23:17
@codecov-commenter
Copy link

codecov-commenter commented May 23, 2024

Codecov Report

Attention: Patch coverage is 98.95833% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 89.63%. Comparing base (998d710) to head (d9256d9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2952      +/-   ##
==========================================
- Coverage   89.63%   89.63%   -0.01%     
==========================================
  Files          29       29              
  Lines       30189    30173      -16     
  Branches     5877     5877              
==========================================
- Hits        27061    27045      -16     
  Misses       1789     1789              
  Partials     1339     1339              
Flag Coverage Δ
c-tests 86.20% <ø> (ø)
lwt-tests 80.78% <ø> (ø)
python-c-tests 88.72% <ø> (ø)
python-tests 99.03% <98.95%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
python/tskit/cli.py 96.96% <100.00%> (ø)
python/tskit/combinatorics.py 99.36% <100.00%> (ø)
python/tskit/drawing.py 99.23% <100.00%> (-0.01%) ⬇️
python/tskit/exceptions.py 100.00% <100.00%> (ø)
python/tskit/formats.py 99.46% <100.00%> (ø)
python/tskit/genotypes.py 99.07% <100.00%> (ø)
python/tskit/intervals.py 100.00% <100.00%> (ø)
python/tskit/metadata.py 99.04% <100.00%> (-0.01%) ⬇️
python/tskit/provenance.py 100.00% <ø> (ø)
python/tskit/stats.py 100.00% <100.00%> (ø)
... and 5 more

@benjeffery benjeffery force-pushed the ruff branch 2 times, most recently from cfd0171 to 1bd604c Compare May 23, 2024 23:50
@benjeffery benjeffery marked this pull request as ready for review May 24, 2024 00:07
@benjeffery
Copy link
Member Author

Well this was a lot noisier than I was expecting, although it did show up a couple of actual errors.

@jeromekelleher
Copy link
Member

Ruff is quite opinionated about getting people to use f strings etc isn't it?

What were the errors?

LGTM though, happy to switch.

Given the noisiness we may want to try and flush a few open PRs through first.

@benjeffery
Copy link
Member Author

If we don't want to enforce f-strings we can switch that off - they do generally read better though.

The errors were:
A test where a subsequent pytest.raises was nested inside the first, such that the second didn't run.
An ibd test that was missing an assert so the value was evaluated, but not checked.

],
)
@pytest.mark.parametrize("mode", DIVMAT_MODES)
@pytest.mark.parametrize("span_normalise", [True, False])
def test_all_trees_windows(self, windows, mode, span_normalise):
print(windows)
Copy link
Member

Choose a reason for hiding this comment

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

stray print?

Copy link
Member

@hyanwong hyanwong left a comment

Choose a reason for hiding this comment

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

I only had a brief look through, but apart from a stray print, everything LGTM. Setting the line length to 90 rather than 89 has made a few lines more readable too.

Is it worth running a perf test, as there have been a few changes involving changing lists to tuples (I assume this should make things a smidge faster, although not noticeably)

- (n + 2) / (h * n)
+ g / h**2
)
b = 2 * (n**2 + n + 3) / (9 * n * (n - 1)) - (n + 2) / (h * n) + g / h**2
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like this change - the previous version was written out on multiple lines so it's easier to parse by eye. However, most of these many lines -> one line changes I do like, so maybe it's okay?

Copy link
Member

Choose a reason for hiding this comment

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

In this one case you could #noqa the line, I guess?

f"Valid options are {str(list(codec_registry.keys()))}."
)
f"Valid options are {list(codec_registry.keys())!s}."
) from None
Copy link
Contributor

Choose a reason for hiding this comment

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

This raise from None thing is going to be a bit opaque to new people.

Copy link
Member

Choose a reason for hiding this comment

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

I fail to see the value of that one too

Copy link
Member

Choose a reason for hiding this comment

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

It makes the output easier to read when exceptions occur, although developers may prefer to see the entire context chain of raised errors.

@petrelharp
Copy link
Contributor

I'm happy with whatevery you all think, but I did find two places I wished it was less opinionated (see comments).

@hyanwong
Copy link
Member

hyanwong commented Jul 8, 2024

I've been using ruff and it's much quicker than our previous linter, which makes development a little slicker and more palatable, so I would be happy with switching over.

@benjeffery
Copy link
Member Author

Still planning to do this - waiting till the number of in-flight PRs is a bit lower.

@benjeffery benjeffery added this to the Python 0.5.9 milestone Sep 23, 2024
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.

6 participants