Opinioned code formatter, just like Python's black code formatter but for Beancount
Project description
beancount-black ![CircleCI](https://pypi-camo.freetls.fastly.net/f37d3d6f048113002e54bdf498b0c28e64ea5b1f/68747470733a2f2f636972636c6563692e636f6d2f67682f4c61756e6368506c6174666f726d2f6265616e636f756e742d626c61636b2f747265652f6d61737465722e7376673f7374796c653d737667)
Opinionated code formatter, just like Python's black code formatter but for Beancount
Features
- MIT licensed - based on beancount-parser, a Lark based LALR(1) Beancount syntax parser
- Extremely fast - 5K+ lines file generated by
bean-example
can be formatted in around 1 second - Section awareness - entries separated by Emac org symbol mark
*
will be formatted in groups without changing the overall structure - Comment preserving - comments are preserved and will be formatted as well
Sponsor
The original project beancount-black was meant to be an internal tool built by Launch Platform LLC for
A modern accounting book service based on the most popular open source version control system Git and text-based double entry accounting book software Beancount. While SaaS businesses won't be required to open source an internal tool like this, we still love that the service is only possible because of the open-source tool we are using. We think it would be greatly beneficial for the community to access a tool like this, so we've decided to open source it under MIT license, hope you find this tool useful 😄
Install
To install the formatter, simply run
pip install beancount-black
Usage
Run
bean-black /path/to/the/file.bean
Then the file will be formatted.
Since this tool is still in its early stage, a backup file at <filepath>.backup
will be created automatically by default just in case.
The creation of backup files can be disabled by passing -n
or --no-backup
like this
bean-black -n /path/to/the/file.bean
It's highly recommended to use BeanHub, Git or other version control system to track your Beancount book files before running the formatter against them without a backup.
If you want to run the formatter programmatically, you can do this
import io
from beancount_parser.parser import make_parser
from beancount_black.formatter import Formatter
parser = make_parser()
formatter = Formatter()
tree = parser.parse(beancount_content)
output_file = io.StringIO()
formatter.format(tree, output_file)
Future features
- Add argument for renaming account and commodity
- Add argument for following other files from
include
statements and also format those files
Feedbacks, bugs reporting or feature requests are welcome 🙌, just please open an issue. No guarantee we have time to deal with them, but will see what we can do.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for beancount_black-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5589276ff86547a7c640ec3d86f045dcab1f9059116ace4c644998bb93ae2a0 |
|
MD5 | 04df7496f16d208cf1d091fc9f9ffa07 |
|
BLAKE2b-256 | 8155f2197d34147fbdbeced93512e57fe4494fdf2af275a5590539c7fe64bc3d |