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

Migrate to ruff format #3656

Merged
merged 5 commits into from
Dec 24, 2023
Merged

Conversation

Saransh-cpp
Copy link
Member

Description

Sorry for creating this huge PR just before the holidays 😬

Fixes #3477
Also addresses #3489

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@agriyakhetarpal
Copy link
Member

Should we close #3492?

Copy link

codecov bot commented Dec 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7e72c38) 99.59% compared to head (d8eedf1) 99.59%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3656   +/-   ##
========================================
  Coverage    99.59%   99.59%           
========================================
  Files          258      258           
  Lines        20797    20797           
========================================
  Hits         20712    20712           
  Misses          85       85           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Thanks, @Saransh-cpp! Looks good and it is nice to get this tool working for notebooks. Is there a way to reduce the line length in the configuration just for the notebooks? See this notebook in the PR build for example – it would be great if we can set the line length to, say, 60 for notebooks, while keeping it at 88 or so for Python files. It reduces the amount of side scrolling required when browsing through the code cells for accessibility reasons.

In hindsight, we should have kept #3492 open since the contributor was active for a while and it had been just three weeks since they had not replied. Let's be more patient next time we encounter a delay and wait for at least two months, given that this was not a high priority issue to fix.


- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==22.12.0]
additional_dependencies: [black==23.*]
Copy link
Member

Choose a reason for hiding this comment

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

I recently got to know that ruff is now capable of formatting code blocks in documentation files (Markdown, reST, etc.) as well, should we consider removing blacken-docs? Feel free to convert this comment to an issue if yes

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think ruff can do that yet, see - astral-sh/ruff#8237 and astral-sh/ruff#3792

@Saransh-cpp
Copy link
Member Author

it would be great if we can set the line length to, say, 60 for notebooks, while keeping it at 88 or so for Python files

I went through ruff's config and I don't think they support such flexibility at the moment.

@agriyakhetarpal
Copy link
Member

How about temporarily setting it to 60 and linting the notebooks while ignoring the rest, then setting it back to the default and linting the rest ignoring the notebooks?

@Saransh-cpp
Copy link
Member Author

How about temporarily setting it to 60 and linting the notebooks while ignoring the rest, then setting it back to the default and linting the rest ignoring the notebooks?

ruff will automatically expand the lines with length = 60 to length = 88 whenever we run it again (that is, in the CI), it goes both ways - shrink as well as expand line lengths

@agriyakhetarpal
Copy link
Member

Ah I didn't know that, I will open up a feature request about this upstream and hope they find it reasonable

@Saransh-cpp Saransh-cpp merged commit 8dc0421 into pybamm-team:develop Dec 24, 2023
40 checks passed
@Saransh-cpp Saransh-cpp deleted the ruff-format branch December 24, 2023 09:47
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.

Switch to ruff format
2 participants