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

Fix switch to ruff format #3492

Closed

Conversation

Rjchauhan18
Copy link
Contributor

Description

  • Changes made in pre-commit-config.yaml file
      - id: ruff-format
        args: [--check]

Fixes # (issue)

This PR will fixes the issue #3477

Type of change

  • 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)

Further checks:

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

@Rjchauhan18
Copy link
Contributor Author

Hey @Saransh-cpp
I am interested to doing this but starting 3rd nov, 2023 my exams are starting so i might not able to spend time solving issue till 9th nov, 2023 .

so till then if someone solve this with you then fine otherwise i will come back on 9th still you can review it give me the comments what changes you want if i am quickly able to change those thing then i will otherwise i wll come on 9th nov .

@Rjchauhan18
Copy link
Contributor Author

Rjchauhan18 commented Oct 31, 2023

And one more thing do you want it to auto fix everything or just check?

@Saransh-cpp
Copy link
Member

Sounds good! We should autofix everything.

@Rjchauhan18
Copy link
Contributor Author

Now pre-commit bot will auto commit everything which can be change

@Saransh-cpp Saransh-cpp marked this pull request as draft November 1, 2023 16:17
Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

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

Thanks, @Rjchauhan18! You should also add pre-commit's commit's hash in https://github.com/pybamm-team/PyBaMM/blob/develop/.git-blame-ignore-revs

Comment on lines 12 to +13

- id: ruff-format
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- id: ruff-format
- id: ruff-format
types_or: [python, pyi, jupyter]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: "v0.1.3"
    hooks:
      - id: ruff
        args: [--fix, --show-fixes]
   

      - id: ruff-format
        types_or: [python, pyi, jupyter]

It is removing ; from .ipynb

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a lot of the semi-colons just stop output like:

<pybamm.solvers.solution.Solution at 0x13cc02f10>

This does not seem like a huge problem.

Another way to resolve that printing is to save output objects to a discarded variable:

_ = sim.solve()

instead of

sim.solve();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, _ = sim.solve() this is in the jupyter notebook

But for plotting graphs without line like this [<matplotlib.lines.Line2D at 0x7f4123ea7ac0>] we need semi-colons.


One Solution is to put # fmt: off and # fmt: on where semi-colons appear

# fmt: off
plt.plot(sol["Time [s]"].data, sol["Voltage [V]"].data);
# fmt: on

Should I use these comments or try to find something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I would prefer to avoid adding tool specific comments if there are other ways.

In this case:

_ = plt.plot(sol["Time [s]"].data, sol["Voltage [V]"].data)

works since plot() also has a return

Copy link
Contributor Author

@Rjchauhan18 Rjchauhan18 Nov 9, 2023

Choose a reason for hiding this comment

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

Hello @Saransh-cpp
which changes you prefer ?

Copy link
Member

Choose a reason for hiding this comment

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

The semicolon thing was fixed in ruff upstream. You might have to reset your commits and introduce ruff format in an entirely new commit, given that we want all the pre-commit related changes bundled in a single commit.

@Rjchauhan18 Rjchauhan18 marked this pull request as ready for review November 4, 2023 07:34
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d37a8f2) 99.58% compared to head (2ff87e1) 99.58%.
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3492   +/-   ##
========================================
  Coverage    99.58%   99.58%           
========================================
  Files          256      256           
  Lines        20048    20048           
========================================
  Hits         19965    19965           
  Misses          83       83           
Files Coverage Δ
pybamm/discretisations/discretisation.py 99.78% <ø> (ø)
pybamm/expression_tree/averages.py 100.00% <ø> (ø)
pybamm/expression_tree/binary_operators.py 100.00% <ø> (ø)
pybamm/expression_tree/concatenations.py 100.00% <ø> (ø)
pybamm/expression_tree/functions.py 100.00% <100.00%> (ø)
...mm/expression_tree/operations/convert_to_casadi.py 100.00% <ø> (ø)
pybamm/expression_tree/symbol.py 100.00% <ø> (ø)
pybamm/expression_tree/vector.py 100.00% <ø> (ø)
pybamm/input/parameters/lithium_ion/Ai2020.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lithium_ion/Chen2020.py 100.00% <100.00%> (ø)
... and 35 more

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

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

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

@Rjchauhan18 let us know if you need any help on this!

@Saransh-cpp
Copy link
Member

Closing this PR as it went stale, and taking up the work in #3656

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.

3 participants