Skip to content

Output the required formatting changes - #1216

Merged
niccokunzmann merged 5 commits into
PyCalendar:mainfrom
niccokunzmann:ruff-show-difference-ci
Feb 24, 2026
Merged

niccokunzmann merged 5 commits into
PyCalendar:mainfrom
niccokunzmann:ruff-show-difference-ci

Conversation

@niccokunzmann

Copy link
Copy Markdown
Member

Closes issue

When the formatting CI runs, it does not show what needs to be done to pass.

Description

This runs the ruff commands in a way that shows what needs changing.

Checklist

  • I've added a change log entry to CHANGES.rst.
  • I've added or updated tests if applicable.
  • I've run and ensured all tests pass locally by following Run tests.
  • I've added or edited documentation, both as docstrings to be rendered in the API documentation and narrative documentation, as necessary.
grafik grafik

run: ruff format --check .
- name: Run ruff checks on the files
run: ruff check --fix
run: ruff format .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like automatic rewrites of PRs. Please don't do this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This does not rewrite a PR.

ruff format --check .

does not output anything.
In the end, the git diff prints the differences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You replaced that with:

        run: ruff format .

which most certainly rewrites the PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The next step will fail if the files have been formatted - not with a one-liner but with a more elaborate message for which a screenshot can be found in the PR head.

      git status
      git diff --exit-code

Even if the topic is charged in the other PR, it is ok to ask questions for understanding.
Since RUFF formatting is now required, I want to ease the development through proper error messages.

@github-actions

Copy link
Copy Markdown
Contributor

Pull Request Test Coverage Report for Build 22277536764

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.081%

Totals Coverage Status
Change from base Build 22274921870: 0.0%
Covered Lines: 11418
Relevant Lines: 11635

💛 - Coveralls

@niccokunzmann

niccokunzmann commented Feb 23, 2026 •

Copy link
Copy Markdown
Member Author

I think, this could well solve some of the issues of the other PR #1208

DONE: Add a comment in the CI failure to

  • setup the repo according to the docs
  • run the formatting commands

@niccokunzmann

Copy link
Copy Markdown
Member Author

When the CI fails, now it outputs what should be done.
grafik

SashankBhamidi
SashankBhamidi previously approved these changes Feb 24, 2026

@SashankBhamidi SashankBhamidi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can be merged after changelog fix, thanks!

Also, see comment about ruff.

Comment thread CHANGES.rst Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Most projects in the ecosystem use the simpler standard pattern:

ruff format --check .
ruff check .

Adding --output-format=github to both gives inline PR annotations, which may be better UX than the git diff approach:

- name: Run ruff formatter check
  run: ruff format --check --output-format=github .

- name: Run ruff lint check
  run: ruff check --output-format=github .

The current ruff format . + git diff approach works and the diff is helpful, but it's non-standard. Worth considering whether the GitHub annotations would serve contributors better.

@niccokunzmann niccokunzmann Feb 24, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm. Thanks for suggesting this.

I don't think that will help e.g. know that a newline should be added:

$ ruff format --check --output-format=github --preview .
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/__init__.py,line=181,endLine=183::src/icalendar/__init__.py:181:1: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/parser/string.py,line=35,endLine=175::src/icalendar/parser/string.py:35:13: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/prop/categories.py,line=29,endLine=34::src/icalendar/prop/categories.py:29:26: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/prop/factory.py,line=114,endLine=214::src/icalendar/prop/factory.py:114:30: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/prop/image.py,line=66,endLine=72::src/icalendar/prop/image.py:66:23: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/prop/recur/frequency.py,line=18,endLine=28::src/icalendar/prop/recur/frequency.py:18:32: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/prop/recur/recur.py,line=138,endLine=158::src/icalendar/prop/recur/recur.py:138:26: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/prop/recur/weekday.py,line=49,endLine=59::src/icalendar/prop/recur/weekday.py:49:30: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/attr/test_rdate.py,line=37,endLine=42::src/icalendar/tests/attr/test_rdate.py:37:22: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/prop/test_unit.py,line=126,endLine=133::src/icalendar/tests/prop/test_unit.py:126:18: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/prop/test_vPeriod.py,line=45,endLine=47::src/icalendar/tests/prop/test_vPeriod.py:45:17: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/rfc_6350_vcard/test_vAdr.py,line=50,endLine=95::src/icalendar/tests/rfc_6350_vcard/test_vAdr.py:50:20: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/rfc_7265_jcal/test_invalid_jcal.py,line=124,endLine=352::src/icalendar/tests/rfc_7265_jcal/test_invalid_jcal.py:124:29: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/rfc_7265_jcal/test_section_3_6_values.py,line=112,endLine=119::src/icalendar/tests/rfc_7265_jcal/test_section_3_6_values.py:112:16: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/test_cli_tool.py,line=43,col=17,endLine=43,endColumn=17::src/icalendar/tests/test_cli_tool.py:43:17: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/test_icalendar.py,line=154,endLine=228::src/icalendar/tests/test_icalendar.py:154:49: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/test_issue_821_stdin_parse.py,line=54,col=17,endLine=54,endColumn=17::src/icalendar/tests/test_issue_821_stdin_parse.py:54:17: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/test_period.py,line=45,endLine=67::src/icalendar/tests/test_period.py:45:36: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/test_property_params.py,line=26,endLine=64::src/icalendar/tests/test_property_params.py:26:24: unformatted: File would be reformatted
::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/test_unit_cal.py,line=31,endLine=183::src/icalendar/tests/test_unit_cal.py:31:43: unformatted: File would be reformatted

If you have improvement ideas, could you open an issue for those?

test:

::error title=Ruff (unformatted),file=/home/nicco/icalendar/src/icalendar/tests/test_issue_821_stdin_parse.py,line=54,col=17,endLine=54,endColumn=17::src/icalendar/tests/test_issue_821_stdin_parse.py:54:17: unformatted: File would be reformatted

Co-authored-by: Sashank <hello@sashank.wiki>
@niccokunzmann
niccokunzmann merged commit c88c1bd into PyCalendar:main Feb 24, 2026
17 checks passed
@niccokunzmann
niccokunzmann deleted the ruff-show-difference-ci branch February 24, 2026 11:14
@niccokunzmann

Copy link
Copy Markdown
Member Author

Thanks for the review - from now on, it should be easier to guide newcomers to format their PRs.

@niccokunzmann

Copy link
Copy Markdown
Member Author

Yay! First PR and it is already useful:
#1223 (comment)

stevepiercy added a commit that referenced this pull request Feb 26, 2026
This PR cleans up the message from #1216. No change log needed.
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