formart thrift file
Project description
thrift-fmt
thrift formatter
the parser is https://github.com/alingse/thrift-parser
Usage
install
pip install thrift-fmt
run
single file
thrift-fmt mythrift.thrift
thrift-fmt mythrift.thrift -w
or directory (this will overwrite the origin file, please keep in track)
thrift-fmt -d ./thrift_files
or more options see help
thrift-fmt --help
Use in Code
from thrift_fmt import ThriftFormatter, PureThriftFormatter
from thrift_parser import ThriftData
data = '''
include "shared.thrift" // a
// work info
struct Work {
1: i32 num1 = 0,
2: required i32 num2, // num2 for
3: Operation op, // op is Operation
4: optional string comment,
5: map<string,list<string>> tags, //hello
}
'''
# thrift = ThriftData.from_file('simple.thrift')
thrift = ThriftData.from_str(data)
out = ThriftFormatter(thrift).format()
assert out == '''
include "shared.thrift" // a
// work info
struct Work {
1: required i32 num1 = 0,
2: required i32 num2, // num2 for
3: required Operation op, // op is Operation
4: optional string comment,
5: required map<string, list<string>> tags, //hello
}
'''.strip()
# or only a single node
header = PureThriftFormatter().format_node(thrift.document.children[0])
assert header == 'include "shared.thrift"'
LICENSE
fixtures 中部分thrift 是来自于 https://github.com/apache/thrift/blob/master/tutorial/ 是 Apache 证书的
thrift-parser 中使用的 Thrift.g4 是来自于 https://github.com/antlr/grammars-v4
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
thrift-fmt-0.2.0.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for thrift_fmt-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f8ea817fdb889f0544e15ba87c313248b8aeffd5dc234386f7205eee625cd13 |
|
MD5 | 864edaf97e11d0edcb555fe9ec2a67e5 |
|
BLAKE2b-256 | 8b0da229abe79fa47512de2ce5f2afa8cf831b735d610c28d7c3d21fc9a5dcd6 |