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

Using pyupgrade to convert string formatting to f-string. #3579

Merged
merged 6 commits into from
Dec 15, 2023

Conversation

prady0t
Copy link
Contributor

@prady0t prady0t commented Nov 30, 2023

Fixes #3496

Linked to PR #3551

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

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 for working on this, @prady0t!

  1. Not all pre-commit related changes were included in 41019cf, so you might have to reset the commits and include all the changes in a single commit.
  2. Some pre-commit suggestions must be resolved manually. These are visible here - https://results.pre-commit.ci/run/github/155538761/1701378735.92sVUq40SsSDBx8YpLEX4w. You can access this by scrolling to the bottom of your PR and clicking "details" on the pre-commit.ci job.
  3. There are a few typing fixes required for the pre-commit job to pass. Adding UP007 to the list of excluded checks in pyproject.toml with a small note should fix this for now. (@pipliggins could fix these and add the check back in Adds typing to expression tree #3578.)

@kratman kratman self-requested a review December 1, 2023 14:52
@prady0t
Copy link
Contributor Author

prady0t commented Dec 1, 2023

Thanks for working on this, @prady0t!

  1. Not all pre-commit related changes were included in 41019cf, so you might have to reset the commits and include all the changes in a single commit.
  2. Some pre-commit suggestions must be resolved manually. These are visible here - https://results.pre-commit.ci/run/github/155538761/1701378735.92sVUq40SsSDBx8YpLEX4w. You can access this by scrolling to the bottom of your PR and clicking "details" on the pre-commit.ci job.
  3. There are a few typing fixes required for the pre-commit job to pass. Adding UP007 to the list of excluded checks in pyproject.toml with a small note should fix this for now. (@pipliggins could fix these and add the check back in Adds typing to expression tree #3578.)

Am I supposed to add UP007 here?

ignore = [
also how do I add commit hash (mentioned earlier)?

@arjxn-py arjxn-py self-requested a review December 5, 2023 07:15
@Saransh-cpp
Copy link
Member

Am I supposed to add UP007 here?

Yes!

also how do I add commit hash (mentioned earlier)?

You can add the commit hash in the git-revs files.

You should roughly do the following -

git reset --hard HEAD~4  # hard reset all the pre-commit changes (the last 4 commits on this branch)
# merge the remote develop branch into your current branch
# ignore UP007, add, and commit with --no-verify
pre-commit run -a   # run pre-commit on all files, this will trigger the newly added pyupgrade rules
# most of the fixes will be automatic but some fixes will require manual intervention - make manual fixes wherever required
# add and commit, this time not with --no-verify, allowing pre-commit to pass
# add the previous commit's hash to .git-blame-ignore-revs
# push everything

@kratman
Copy link
Contributor

kratman commented Dec 14, 2023

@prady0t How is this coming along?

@prady0t
Copy link
Contributor Author

prady0t commented Dec 14, 2023

@prady0t How is this coming along?

Sorry for not being active. I had exams then had to travel back home. Was working on this just today, will complete this by EOD.

@kratman
Copy link
Contributor

kratman commented Dec 14, 2023

No rush, just curious since you were close

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@prady0t
Copy link
Contributor Author

prady0t commented Dec 14, 2023

Done! Please have a look.

@prady0t
Copy link
Contributor Author

prady0t commented Dec 14, 2023

Pretty sure I messed up something. 😨

@agriyakhetarpal
Copy link
Member

After you reset your branch locally you pulled the changes in it that were present on GitHub instead of a force push (I think). This is why 101 or so commits are showing up (probably due to a broken merge commit, the presence of which would have fixed it otherwise)

@prady0t
Copy link
Contributor Author

prady0t commented Dec 14, 2023

I might have to close this PR as well. What do you think?

@agriyakhetarpal
Copy link
Member

You can reset your branch and keep working on the same PR using the instructions posted above, no worries! Otherwise, you can undo your commits till 75b58bc is the last commit.

@kratman
Copy link
Contributor

kratman commented Dec 14, 2023

@prady0t You are so close. If you want I can post the full set of commands to do it with reset/cherry pick. The general procedure I would follow is

  • Reset to origin/main
  • Cherry pick your pre-commit config changes from this branch on your fork's origin (origin/new-format-fix)
  • Run pre-commit, commit formatting changes, copy the commit hash
  • Add the formatting changes hash to the ignored revs, and commit that change
  • Force push to this branch

@Saransh-cpp
Copy link
Member

Saransh-cpp commented Dec 14, 2023

You can also git log the hashes of your last 4 commits, reset everything in this branch, and then git cherry-pick those 4 commits using their hashes.

This would be a nice git exercise but please feel free to open a new PR if you feel that would be better.

Edit: Just saw @kratman's comment, haha!

@prady0t
Copy link
Contributor Author

prady0t commented Dec 14, 2023

Did this work? I basically just did this:

git reset --hard 75b58bc  
git push origin -f

@agriyakhetarpal
Copy link
Member

Yes, you are back on track. All that is left is to follow the instructions in #3579 (comment)

@prady0t
Copy link
Contributor Author

prady0t commented Dec 14, 2023

Yes, you are back on track. All that is left is to follow the instructions in #3579 (comment)

But all those commits are already there and ci test have passed as well. Do I have to do it again?

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.

We should be done, then – these changes look great! Thanks, @prady0t! Let's wait and see if @Saransh-cpp requires any extra changes here

pybamm/solvers/processed_variable.py Outdated Show resolved Hide resolved
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.

Looks good, thanks @prady0t! I could see some formatting issues but hopefully they'll be resolved once ruff format is added in. You can add all these changes in without having to worry about git blame.

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pybamm/discretisations/discretisation.py Show resolved Hide resolved
pybamm/discretisations/discretisation.py Outdated Show resolved Hide resolved
pybamm/models/full_battery_models/base_battery_model.py Outdated Show resolved Hide resolved
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
@prady0t
Copy link
Contributor Author

prady0t commented Dec 14, 2023

Thanks for being so supportive everyone 😄 .

@kratman
Copy link
Contributor

kratman commented Dec 14, 2023

@all-contributors please add @prady0t for infrastructure

Copy link
Contributor

@kratman

I've put up a pull request to add @prady0t! 🎉

Copy link

codecov bot commented Dec 14, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (903323e) 99.59% compared to head (6e9b373) 99.59%.

Files Patch % Lines
...bamm/expression_tree/operations/evaluate_python.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3579   +/-   ##
========================================
  Coverage    99.59%   99.59%           
========================================
  Files          258      258           
  Lines        20755    20755           
========================================
  Hits         20670    20670           
  Misses          85       85           

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

pyproject.toml Outdated Show resolved Hide resolved
Co-authored-by: Saransh Chopra <saransh0701@gmail.com>
@Saransh-cpp Saransh-cpp merged commit 031d9a5 into pybamm-team:develop Dec 15, 2023
33 of 35 checks passed
@prady0t prady0t deleted the new-format-fix branch December 17, 2023 07:16
pipliggins added a commit to pipliggins/PyBaMM that referenced this pull request Jan 19, 2024
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 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.

Use f-strings everywhere for string formatting/concatenation
4 participants