Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .github/workflows/ruff.yml

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
env:
MESSAGE: |
Your code is not formatted!
Please setup your development environment and run the formatting command.
https://icalendar.readthedocs.io/en/stable/contribute/development.html#code-format
steps:
- uses: actions/checkout@v6
- name: Set up Python
Expand All @@ -15,10 +20,17 @@ jobs:
python -m pip install --upgrade pip
pip install . --group formatting
- name: Run the ruff formatter to change files
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.

- name: Fail if we detect any changes on the file system
run: |
git status
git diff --exit-code
if ! git diff --exit-code; then
echo "$MESSAGE"
exit 1;
fi
- name: Run ruff checks on the files
run: |
if ! ruff check; then
echo "$MESSAGE"
exit 1;
fi
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ We still recommend checking out the new features and giving feedback in the repo
Minor changes
~~~~~~~~~~~~~

- Show required code changes in the CI output to help contributors solve the formatting issues. :pr:`1216`
- Use ruff 0.15.0 for code formatting in :file:`tox.ini`. :pr:`1215`

Breaking changes
Expand Down