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

&yarnabrina [MNT] switch to ruff as linting tool #6676

Merged
merged 33 commits into from
Jul 11, 2024
Merged

Conversation

fnhirwa
Copy link
Member

@fnhirwa fnhirwa commented Jun 27, 2024

This PR adds ruff as a linting tool and keeps black in our lint configuration.
Also did a run against all files and corrected the failures.
The main changes are due to the deprecation of usage of Tuple List Dict and Set as type annotations being replaced by tuple list dict and set respectively.

closes #6677
closes #5316
closes #6636

depends on #6331

@yarnabrina
Copy link
Member

Few comments

  1. if you are using ruff --fix, do we separately need ruff?

  2. have you run ruff over the entire code base? probably not, can you please do that?

  3. there's a lot of specific additions and disabling, I think you can reduce those a bit, e.g. instead of manually disabling different pydocstyle rules (D*), you can disable "D" overall. I haven't gone through all but this is something where opinions can be very different regarding what to enable and what to disable etc.

  4. ruff has a configuration target-version to specify what python version the resultant needs to comply to. We can use 3.8 there.

@fnhirwa
Copy link
Member Author

fnhirwa commented Jun 27, 2024

Few comments

  1. if you are using ruff --fix, do we separately need ruff?

I don't think so as ruff --fix will fix the files inplace, and the next check if for catching any failures that aren't fixed yet.

  1. have you run ruff over the entire code base? probably not, can you please do that?

I am running it locally and will get all failures fixed before marking this PR as ready for review.

  1. there's a lot of specific additions and disabling, I think you can reduce those a bit, e.g. instead of manually disabling different pydocstyle rules (D*), you can disable "D" overall. I haven't gone through all but this is something where opinions can be very different regarding what to enable and what to disable etc.

I agree with this I am getting it disabled and will also request a review on what to disable once the PR is in a good state.

  1. ruff has a configuration target-version to specify what python version the resultant needs to comply to. We can use 3.8 there.

Yeah going to add the target-version

@yarnabrina
Copy link
Member

yarnabrina commented Jun 29, 2024

I don't think so as ruff --fix will fix the files inplace, and the next check if for catching any failures that aren't fixed yet.

That's not necessary. ruff fixes the failures it can fix by default, and flags the result anyway, so second one is unnecessary. However, I think it makes sense to format first before linting, so you may want to consider switching.

Now here's a point of discussion: does it make sense to have both ruff and black as formatters? ruff linter has been for a while and it's quite standard now, but the formatter is quite new. Should we replace black with ruff? I am not sure if it's a direct one-to-one corresponence in rules.

@fkiraly
Copy link
Collaborator

fkiraly commented Jun 29, 2024

I am not sure if it's a direct one-to-one corresponence in rules.

Even if rules correspond, what I realize that we also need to think about downstream developer workflows. E.g., how will the instructions for linting change, see https://www.sktime.net/en/latest/developer_guide/coding_standards.html - and would we be breaking downstream environment setups? Cannot see how, but just putting this for discussion as a point of consideration.

@fnhirwa
Copy link
Member Author

fnhirwa commented Jul 2, 2024

I am not sure if it's a direct one-to-one corresponence in rules.

Even if rules correspond, what I realize that we also need to think about downstream developer workflows. E.g., how will the instructions for linting change, see https://www.sktime.net/en/latest/developer_guide/coding_standards.html - and would we be breaking downstream environment setups? Cannot see how, but just putting this for discussion as a point of consideration.

I propose that if we decide to completely use ruff we could also update the document for coding standards with our ruff configuration.

@fnhirwa fnhirwa changed the title [MNT][WIP]Adding ruff as the linting tool [MNT]Adding ruff as the linting tool Jul 2, 2024
@fnhirwa fnhirwa marked this pull request as ready for review July 2, 2024 18:15
@fkiraly
Copy link
Collaborator

fkiraly commented Jul 6, 2024

small note, I just switched to the PR and updated from main to resolve any merge conflicts.

I also noted that max line length is reduced to 79, I think we should leave it at 88 or we will have loads of code to reformat.

Copy link
Member

@yarnabrina yarnabrina left a comment

Choose a reason for hiding this comment

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

ruff supports notebooks as well (reference https://docs.astral.sh/ruff/faq/#does-ruff-support-jupyter-notebooks), so we should consider whether to replace nbqa linting hooks as well.

I am not sure what is the difference between using ruff directly on *.ipynb files and using with nbqa, may be you know @fnhirwa @sktime/core-developers ?

@fnhirwa
Copy link
Member Author

fnhirwa commented Jul 8, 2024

ruff supports notebooks as well (reference https://docs.astral.sh/ruff/faq/#does-ruff-support-jupyter-notebooks), so we should consider whether to replace nbqa linting hooks as well.

I am not sure what is the difference between using ruff directly on *.ipynb files and using with nbqa, may be you know @fnhirwa @sktime/core-developers ?

Yeah I read that ruff support .ipynb as well dropping nbqa.

@fnhirwa
Copy link
Member Author

fnhirwa commented Jul 8, 2024

If this is approved then I would start to update the developer Coding standards sections of the documentation for ruff clarification.

@yarnabrina
Copy link
Member

I rebased your branch and was about to force push some commits, but it seems you pushed more. I'll wait it out in case CI starts passing.

If this is approved then I would start to update the developer Coding standards sections of the documentation for ruff clarification.

Please start, I'll review if CI passes. Main review is of course the suppressed messages, as I assume there are no/little manual changes.

If you made some manual changes that affect logic or can be considered subjective, can you point out those please?

.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
sktime/utils/_testing/hierarchical.py Outdated Show resolved Hide resolved
.pre-commit-config.yaml Show resolved Hide resolved
docs/source/conf.py Outdated Show resolved Hide resolved
docs/source/developer_guide/coding_standards.rst Outdated Show resolved Hide resolved
sktime/classification/ensemble/_ctsf.py Outdated Show resolved Hide resolved
sktime/datasets/_readers_writers/arff.py Outdated Show resolved Hide resolved
sktime/forecasting/model_selection/_tune.py Outdated Show resolved Hide resolved
sktime/forecasting/tests/test_all_forecasters.py Outdated Show resolved Hide resolved
sktime/utils/tests/test_check_estimator.py Outdated Show resolved Hide resolved
@yarnabrina
Copy link
Member

Any idea why this CI is stuck for so long?

@fnhirwa
Copy link
Member Author

fnhirwa commented Jul 10, 2024

Any idea why this CI is stuck for so long?

This is something common for macOS runners I recall to see this on many PRs

@fkiraly
Copy link
Collaborator

fkiraly commented Jul 10, 2024

Any idea why this CI is stuck for so long?

This is something common for macOS runners I recall to see this on many PRs

Yes, I think macos runners are weaker in resources:
https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
and there´s also a concurrency limit across the org.

As a consequence, they tend to be "behind" the other operating systems when there are multiple CI jobs in the queue.

With the new test setup, I think the tests run faster than PR are being created, but not on macos, so I have to regularly skip/cancel and test merged batches at once, around releases.

@fkiraly
Copy link
Collaborator

fkiraly commented Jul 10, 2024

Is this ready? Assuming the macos tests pass.

@fnhirwa
Copy link
Member Author

fnhirwa commented Jul 10, 2024

Is this ready? Assuming the macos tests pass.

from my end it is, I would like to wait for @yarnabrina confirmation

@yarnabrina
Copy link
Member

I don't have any major feedbacks. Few choices of configurations and skips I'm slightly unhappy about, but overall looks good to me.

(Subject to successful CI, of course)

@fkiraly
Copy link
Collaborator

fkiraly commented Jul 11, 2024

ok - failures are all sporadic or timeout related (known and unrelated to this PR).

I see the docs are included here, so good from my side.

@fkiraly fkiraly changed the title [MNT] switch to ruff as linting tool &yarnabrina [MNT] switch to ruff as linting tool Jul 11, 2024
@fkiraly fkiraly merged commit 570548d into sktime:main Jul 11, 2024
177 of 186 checks passed
@fnhirwa fnhirwa deleted the ruff branch July 23, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Continuous integration, unit testing & package distribution
Projects
Status: Done
3 participants