Skip to content

pre-commit: Add Artistic Style 3.1 formatter using astyle_py#32566

Closed
cclauss wants to merge 5 commits intoArduPilot:masterfrom
cclauss:pre-commit-astyle
Closed

pre-commit: Add Artistic Style 3.1 formatter using astyle_py#32566
cclauss wants to merge 5 commits intoArduPilot:masterfrom
cclauss:pre-commit-astyle

Conversation

@cclauss
Copy link
Copy Markdown
Contributor

@cclauss cclauss commented Mar 26, 2026

Summary

pre-commit: Add Artistic Style 3.1 formatter using astyle_py

Testing (more checks increase the chance of being merged)

  • Checked by a human programmer
  • Tested in SITL
  • Tested on hardware
  • Logs attached
  • Logs available on request
  • Autotest included

Description

I know nothing about astyle, so please try it out.

I copied the directories and files from:
https://github.com/ArduPilot/ardupilot/blob/master/Tools/scripts/run_astyle.py#L22-L36
and pasted them into a really scary-looking regex (please verify that syntax!).

% git add .pre-commit-config.yaml
% pre-commit run astyle_py --all-files --verbose

astyle formatter.........................................................Passed
- hook id: astyle_py
- duration: 0.14s

% pre-commit run --all-files

How was this tested?

  1. code ArduCopter/AP_ExternalControl_Copter.cpp libraries/AP_DDS/AP_DDS_ExternalControl.cpp
  2. Make similar leading and trailing whitespace changes to both files.
  3. pre-commit run astyle_py --all-files --verbose

The first file (which was directly named in the regex) was fixed, but the second file (which was in a named directory) was not fixed, so the regex must not be correct for directories.


Fix the regex so files in directories are now formatted.

Added --options=Tools/CodeStyle/astylerc, but the system errors on suffix=none and lineend=linux in that file so I commented them out.


Artistic Style version info: https://astyle.sourceforge.net/news.html and https://astyle.sourceforge.net/notes.html

% docker run -it ubuntu:24.04 # Artistic Style 3.1 (January 2018) -- 3.1-3build1
# astyle --version ; apt update && apt install astyle && astyle --version

Artistic Style Version 3.1

% docker run -it ubuntu:26.04 # Artistic Style 3.6 (August 2024) -- 3.6.12-1
# astyle --version ; apt update && apt install astyle && astyle --version

Artistic Style Version 3.6.12

@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Mar 26, 2026

Pre-commit file changes do not change the builds, so should we add .pre-commit-config.yaml to the

on:
  push: | pull_request:
    paths-ignore:

blocks of all the files listed in the command:
% git grep Vagrantfile .github/workflows

@cclauss cclauss force-pushed the pre-commit-astyle branch 2 times, most recently from 87a8c63 to dd9f7d0 Compare March 26, 2026 22:44
@peterbarker
Copy link
Copy Markdown
Contributor

Pre-commit file changes do not change the builds, so should we add .pre-commit-config.yaml to the

on:
  push: | pull_request:
    paths-ignore:

blocks of all the files listed in the command: % git grep Vagrantfile .github/workflows

So long as we don't skip any checks that are actually dependent on that file, it's a good idea. And I don't see anything in that list which is dependent.

Copy link
Copy Markdown
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

@Ryanf55 has to be happy

Comment thread .pre-commit-config.yaml
Copy link
Copy Markdown
Contributor

@Ryanf55 Ryanf55 left a comment

Choose a reason for hiding this comment

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

Using pre-commit to run our linters is really great.
Last time I asked to do this, a PR similar to this was rejected because astyle is not available on windows and thus pre-commit users on windows would no longer work.

Can we validate that this new approach works on windows?

Comment thread libraries/AP_DDS/tests/test_ap_dds_type_conversions.cpp
@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Mar 27, 2026

Can we validate that this new approach works on Windows?

https://github.com/igrr/astyle_py?tab=readme-ov-file#implementation-notes confirms:

  • x86_64 (amd64) Windows, Linux, macOS
  • aarch64 (arm64) Linux and macOS

@cclauss cclauss force-pushed the pre-commit-astyle branch from dd9f7d0 to 19ccf31 Compare March 30, 2026 16:20
@cclauss cclauss force-pushed the pre-commit-astyle branch from 19ccf31 to adeeafd Compare April 3, 2026 03:56
@cclauss cclauss changed the title pre-commit: Add astyle formatter using astyle_py pre-commit: Add Artistic Style 3.1 formatter using astyle_py Apr 3, 2026
@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Apr 3, 2026

Artistic Style version info: https://astyle.sourceforge.net/news.html and https://astyle.sourceforge.net/notes.html

Rebased to use the Ubuntu 24.04 default Artistic Style 3.1 (January 2018).

This month's Ubuntu 26.04 defaults to Artistic Style 3.6 (August 2024).

Copy link
Copy Markdown
Contributor

@hunt0r hunt0r left a comment

Choose a reason for hiding this comment

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

Good work.

All my feedback is optional suggestion(s), feel free to resolve any/all without response.

Did you consider simultaneously deleting or rewriting Tools/scripts/run_astyle.py to run this instead? Since these are intended to be equivalent, seem logical to DRY them to be exactly so.
(If you'd like a volunteer to contribute this, I'm willing.)

Comment thread Tools/CodeStyle/astylerc Outdated
Comment thread .pre-commit-config.yaml
Comment thread .pre-commit-config.yaml Outdated
Comment thread .pre-commit-config.yaml Outdated
Comment thread .pre-commit-config.yaml
Comment thread .pre-commit-config.yaml Outdated
@cclauss cclauss force-pushed the pre-commit-astyle branch from adeeafd to 77b8164 Compare April 3, 2026 16:34
@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Apr 3, 2026

@hunt0r Thanks for your excellent suggestions. Much better.

@cclauss cclauss force-pushed the pre-commit-astyle branch from 77b8164 to e7e8e80 Compare April 4, 2026 06:40
@cclauss cclauss force-pushed the pre-commit-astyle branch from e7e8e80 to f68166f Compare April 5, 2026 05:18
@cclauss cclauss force-pushed the pre-commit-astyle branch from f68166f to 37a2046 Compare April 5, 2026 11:49
@LuciferK47
Copy link
Copy Markdown

Hey @Ryanf55, I just pulled this branch locally to test it out on Windows and can confirm it works perfectly.

I ran pre-commit run astyle_py --all-files on my Windows x64 machine. astyle_py automatically downloaded its pre-compiled wheel and ran successfully. I didn't have to manually install or configure a native astyle.exe binary or mess with my PATH at all.

Not sure if you guys are still looking into it, but since I saw the PR was still open I just wanted to pitch in.
Here's the output from my run:

> pre-commit run astyle_py --all-files --verbose
[INFO] Initializing environment for https://github.com/igrr/astyle_py.
[INFO] Installing environment for https://github.com/igrr/astyle_py.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
astyle formatter.........................................................Passed
- hook id: astyle_py
- duration: 3.11s

@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Apr 14, 2026

Closing in favor of:

@cclauss cclauss closed this Apr 14, 2026
@cclauss cclauss deleted the pre-commit-astyle branch April 14, 2026 11:40
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.

5 participants