{"id":16826020,"url":"https://github.com/igrr/astyle_py","last_synced_at":"2025-03-22T04:30:22.447Z","repository":{"id":58315057,"uuid":"308785137","full_name":"igrr/astyle_py","owner":"igrr","description":"Python wrapper and pre-commit hook for Astyle formatter (http://astyle.sourceforge.net/)","archived":false,"fork":false,"pushed_at":"2025-03-04T15:36:15.000Z","size":406,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T07:51:42.150Z","etag":null,"topics":["formatter","pre-commit","pre-commit-hook"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/igrr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-31T02:05:56.000Z","updated_at":"2025-03-05T08:00:36.000Z","dependencies_parsed_at":"2022-09-01T02:01:37.288Z","dependency_job_id":"613a9367-e545-4319-a752-445a2276f15a","html_url":"https://github.com/igrr/astyle_py","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"c0013808882a15a0c0c2c1a9b5c903866c53a653"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrr%2Fastyle_py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrr%2Fastyle_py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrr%2Fastyle_py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrr%2Fastyle_py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igrr","download_url":"https://codeload.github.com/igrr/astyle_py/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244907420,"owners_count":20529850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","pre-commit","pre-commit-hook"],"created_at":"2024-10-13T11:16:07.989Z","updated_at":"2025-03-22T04:30:22.426Z","avatar_url":"https://github.com/igrr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# astyle_py — Python wrapper around [astyle](http://astyle.sourceforge.net/)\n\n![PyPI - Version](https://img.shields.io/pypi/v/astyle-py?labelColor=383838)\n [![CI](https://github.com/igrr/astyle_py/actions/workflows/main.yml/badge.svg)](https://github.com/igrr/astyle_py/actions/workflows/main.yml) ![Python](https://img.shields.io/badge/dynamic/yaml?url=https://raw.githubusercontent.com/igrr/astyle_py/main/.github/workflows/main.yml\u0026query=$.jobs['test'].strategy.matrix['python-version']\u0026label=Python\u0026logo=python\u0026color=3366ff\u0026logoColor=ffcc00\u0026labelColor=383838)\n\n[Artistic Style (astyle)](http://astyle.sourceforge.net/) is a source code indenter, formatter, and beautifier for the C, C++, C++/CLI, Objective‑C, C# and Java programming languages.\n\nThis project wraps `astyle` in a Python package. The package can be used:\n- [as a pre-commit hook](#using-with-pre-commit) compatible with the [pre-commit](https://pre-commit.com/) framework,\n- [as a console program](#using-from-the-command-line),\n- [as a library](#using-as-a-library), from other Python packages.\n\nThe main reason to use this Python wrapper, rather than native `astyle` binaries, 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.\n\n## Using with `pre-commit`\n\n1. Set up `pre-commit` for your project as described in https://pre-commit.com/#install.\n2. Add `astyle_py` to your `.pre-commit-config.yaml` file as follows. **Note: avoid using `main` as the revision.**\n   ```yaml\n   repos:\n   -   repo: https://github.com/igrr/astyle_py.git\n       rev: v1.1.0\n       hooks:\n       -   id: astyle_py\n           args: [--astyle-version=3.4.7 --style=linux]\n   ```\n\nPlace the required astyle formatting options to the `args` array. See the next section for details.\n\nUse `--dry-run` argument if you only want the pre-commit hook to report the formatting errors, and not fix them automatically.\n\nIf necessary, add `verbose: true` option to see the output.\n\nUse `files:` 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.\n\n## Using from the command line\n\nInstall the package from PyPI:\n```\npip install astyle-py\n```\n\nUsage:\n```\nastyle_py [options] \u003cfiles to format\u003e\n```\n\n* `\u003cfiles\u003e` — list of files to process. By default, `astyle_py` formats the files, modifying them in-place.\n* `[options]` — can be any of the [formatting options](#formatting-options), plus the following options are accepted:\n\n### Common options\n\n* `--version` — print the version and exit.\n* `--astyle-version=\u003cVER\u003e` — choose the version of Astyle to use.\n* `--quiet` — don't print diagnostic messages; by default, the list of files which are formatted is printed to `stderr`.\n* `--dry-run` — don't format the files, only check the formatting. Returns non-zero exit code if any file would change after formatting.\n\n### Specifying additional options and excluded files\n\n* `--options=\u003cfile\u003e` — read more formatting options from the specified file. Empty lines and lines starting with `#` are ignored.\n* `--exclude=\u003cpattern\u003e` — skip files matching the given pattern. Note that patterns use the syntax of [Gitlab CODEOWNERS files](https://docs.gitlab.com/ee/user/project/code_owners.html#the-syntax-of-code-owners-files).\n* `--exclude-list=\u003cfile\u003e` — skip files matching the list of patterns specified in a file. Empty lines and lines starting with `#` are ignored.\n\n### Specifying the rules file\n\n* `--rules=\u003cfile\u003e` — read the formatting rules from the specified rules file. See [Rules files](#rules-files) section for details. This option is incompatible with `--options`, `--exclude`, `--exclude-list`.\n\n## Using as a library\n\nThis package can be used as a library to implement custom formatting tools. See [sample.py](sample.py) for an example.\n\n## Formatting options\n\nSee http://astyle.sourceforge.net/astyle.html for the details on Astyle formatting options.\n\nNote that this wrapper doesn't implement the options from [\"Other options\"](http://astyle.sourceforge.net/astyle.html#_Other_Options) and [\"Command Line Only\"](http://astyle.sourceforge.net/astyle.html#_Command_Line_Only) categories, except for those listed [above](#using-from-the-command-line).\n\n## Rules files\n\nOption `--rules=\u003cfile\u003e` allows loading the formatting options from a _rules file_ in 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.\n\nThe rules file consists of sections (rules). For each section the following keywords may be specified:\n- `version:` Version of Astyle to use\n- `include:` List of files name patterns to include in this rule. Pattern syntax of [Gitlab CODEOWNERS files](https://docs.gitlab.com/ee/user/project/code_owners.html#the-syntax-of-code-owners-files) is used. Required.\n- `check:` If set to `false`, the files covered by this rule will be ignored and not checked/formatted. Optional, default is `true`.\n- `options:` A string specifying the [formatting options](#formatting-options) for files covered by this rule.\n\nIf the file path matches multiple rules, the latest rule is applied. If the file path doesn't match any rule, the options from the special `DEFAULT` rule are used.\n\nHere is an example of a rules file:\n```yml\n\nDEFAULT:\n    # These formatting options will be used by default\n    options: \"--style=otbs --indent=spaces=4 --convert-tabs\"\n\nthirdparty_lib_1:   # The section name is arbitrary\n    # Override formatting rules for the files in a certain directory\n    options: \"--style=linux\"\n    include:\n        - \"/thirdparty/lib1/\"\n\ncode_to_ignore_for_now:\n    # Ignore files in some other directories\n    check: false\n    include:\n        - \"/src/component1/\"\n        - \"/src/component2/\"\n        - \"tests/\"     # matches a subdirectory 'tests' anywhere in the source tree\n```\n\n## Supported Astyle versions\n\nThis python wrapper bundles multiple copies of Astyle, you can choose which one to use:\n- In the CLI: via `--astyle-version=VERSION` argument\n- When using astyle_py as a library: by passing the version to `Astyle()` constructor\n\nThe following versions are supported:\n\n- 3.1 — used by default, unless a different version is specified\n- 3.4.7\n\n## Implementation notes\n\nTo simplify distribution of astyle, it is compiled to WebAssembly ([astyle_py/libastyle.wasm](astyle_py/libastyle.wasm)) and executed using [wasmtime runtime](https://github.com/bytecodealliance/wasmtime) via its [Python bindings](https://github.com/bytecodealliance/wasmtime-py). This package should work on all operating systems supported by wasmtime — at the time of writing these are:\n- x86_64 (amd64) Windows, Linux, macOS\n- aarch64 (arm64) Linux and macOS\n\nOther project which wraps astyle into a Python package include:\n- https://github.com/timonwong/pyastyle — unmaintained at the time of writing, uses native Astyle binaries\n- https://github.com/Freed-Wu/astyle-wheel/ — actively maintained, uses native Astyle binaries\n\n## Contributing\n\nPlease see [CONTRIBUTING.md](CONTRIBUTING.md) for details.\n\n## Copyright and License\n\n* The source code in this repository is Copyright (c) 2020-2022 Ivan Grokhotkov and licensed under the [MIT license](LICENSE).\n* `libastyle.wasm` binaries bundled under [astyle_py/lib](astyle_py/lib) directory are built from [Artistic Style project](https://gitlab.com/saalen/astyle), Copyright (c) 2018 by Jim Pattee \u003cjimp03@email.com\u003e, also licensed under the MIT license. See http://astyle.sourceforge.net/ for details.\n\nThanks to André Simon for maintaining Astyle project!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrr%2Fastyle_py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figrr%2Fastyle_py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrr%2Fastyle_py/lists"}