Package: astyle-py
astyle_py — Python wrapper aroundastyleArtistic Style (astyle)is a source code indenter, formatter, and beautifier for the C, C++, C++/CLI, Objective‑C, C# and Java programming languages.This project wrapsastylein a Python package. The package can be used:as a pre-commit hookcompatible with thepre-commitframework,as a console program,as a library, from other Python packages.The main reason to use this Python wrapper, rather than nativeastylebinaries, is that makes it easy for developers working on a project to have exactly the same version of astyle, regardless of their operating system. This prevents formatting differences which sometimes occur between different versions of astyle.Using withpre-commitSet uppre-commitfor your project as described inhttps://pre-commit.com/#install.Addastyle_pyto your.pre-commit-config.yamlfile as follows.Note: avoid usingmainas the revision.repos:-repo:https://github.com/igrr/astyle_py.gitrev:v1.0.5hooks:-id:astyle_pyargs:[--astyle-version=3.4.7 --style=linux]Place the required astyle formatting options to theargsarray. See the next section for details.Use--dry-runargument if you only want the pre-commit hook to report the formatting errors, and not fix them automatically.If necessary, addverbose: trueoption to see the output.Usefiles:option to configure the regex pattern used to match the files to be formatted. The default pattern is'^.*\.(c|cpp|cxx|h|hpp|inc)$'. You can exclude certain files via additional arguments, as described in the next section.Using from the command lineInstall the package from PyPI:pip install astyle-pyUsage:astyle_py [options] <files to format><files>— list of files to process. By default,astyle_pyformats the files, modifying them in-place.[options]— can be any of theformatting options, plus the following options are accepted:Common options--version— print the version and exit.--astyle-version=<VER>— choose the version of Astyle to use.--quiet— don't print diagnostic messages; by default, the list of files which are formatted is printed tostderr.--dry-run— don't format the files, only check the formatting. Returns non-zero exit code if any file would change after formatting.Specifying additional options and excluded files--options=<file>— read more formatting options from the specified file. Empty lines and lines starting with#are ignored.--exclude=<pattern>— skip files matching the given pattern. Note that patterns use the syntax ofGitlab CODEOWNERS files.--exclude-list=<file>— skip files matching the list of patterns specified in a file. Empty lines and lines starting with#are ignored.Specifying the rules file--rules=<file>— read the formatting rules from the specified rules file. SeeRules filessection for details. This option is incompatible with--options,--exclude,--exclude-list.Using as a libraryThis package can be used as a library to implement custom formatting tools. Seesample.pyfor an example.Formatting optionsSeehttp://astyle.sourceforge.net/astyle.htmlfor the details on Astyle formatting options.Note that this wrapper doesn't implement the options from"Other options"and"Command Line Only"categories, except for those listedabove.Rules filesOption--rules=<file>allows loading the formatting options from arules filein YAML format. The rules file can specify different formatting rules for different parts of the project. This can be useful for monorepos which contain libraries written with different formatting conventions.The rules file consists of sections (rules). For each section the following keywords may be specified:version:Version of Astyle to useinclude:List of files name patterns to include in this rule. Pattern syntax ofGitlab CODEOWNERS filesis used. Required.check:If set tofalse, the files covered by this rule will be ignored and not checked/formatted. Optional, default istrue.options:A string specifying theformatting optionsfor files covered by this rule.If the file path matches multiple rules, the latest rule is applied. If the file path doesn't match any rule, the options from the specialDEFAULTrule are used.Here is an example of a rules file:DEFAULT:
    # These formatting options will be used by default
    options: "--style=otbs --indent=spaces=4 --convert-tabs"

thirdparty_lib_1:   # The section name is arbitrary
    # Override formatting rules for the files in a certain directory
    options: "--style=linux"
    include:
        - "/thirdparty/lib1/"

code_to_ignore_for_now:
    # Ignore files in some other directories
    check: false
    include:
        - "/src/component1/"
        - "/src/component2/"
        - "tests/"     # matches a subdirectory 'tests' anywhere in the source treeSupported Astyle versionsThis python wrapper bundles multiple copies of Astyle, you can choose which one to use:In the CLI: via--astyle-version=VERSIONargumentWhen using astyle_py as a library: by passing the version toAstyle()constructorThe following versions are supported:3.1 — used by default, unless a different version is specified3.4.7Implementation notesTo simplify distribution of astyle, it is compiled to WebAssembly (astyle_py/libastyle.wasm) and executed usingwasmtime runtimevia itsPython bindings. This package should work on all operating systems supported by wasmtime — at the time of writing these are:x86_64 (amd64) Windows, Linux, macOSaarch64 (arm64) Linux and macOSOther project which wraps astyle into a Python package include:https://github.com/timonwong/pyastyle— unmaintained at the time of writing, uses native Astyle binarieshttps://github.com/Freed-Wu/astyle-wheel/— actively maintained, uses native Astyle binariesContributingPlease seeCONTRIBUTING.mdfor details.Copyright and LicenseThe source code in this repository is Copyright (c) 2020-2022 Ivan Grokhotkov and licensed under theMIT license.libastyle.wasmbinaries bundled underastyle_py/libdirectory are built fromArtistic Style project, Copyright (c) 2018 by Jim Patteejimp03@email.com, also licensed under the MIT license. Seehttp://astyle.sourceforge.net/for details.Thanks to André Simon for maintaining Astyle project!